Merge branch 'develop' of https://github.com/pocoproject/poco into develop

This commit is contained in:
Mathäus Mendel 2012-12-16 14:40:30 -02:00
commit c1c01feef4
2 changed files with 74 additions and 0 deletions

View File

@ -148,6 +148,11 @@ public:
/// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure.
void sendMessage(std::istream& istr);
/// Sends the mail message from the supplied stream. Content of the stream
/// is copied without any checking. Only the completion status is checked and,
/// if not valid, SMTPExcpetion is thrown.
int sendCommand(const std::string& command, std::string& response);
/// Sends the given command verbatim to the server
/// and waits for a response.
@ -162,6 +167,19 @@ public:
/// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure.
void sendAddresses(const std::string& from, const Recipients& recipients);
/// Sends the message preamble by sending a MAIL FROM command,
/// and a RCPT TO command for every recipient.
///
/// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure.
void sendData();
/// Sends the message preamble by sending a DATA command.
///
/// Throws a SMTPException in case of a SMTP-specific error, or a
/// NetException in case of a general network communication failure.
protected:
enum StatusClass
{

View File

@ -360,6 +360,47 @@ void SMTPClientSession::sendCommands(const MailMessage& message, const Recipient
}
void SMTPClientSession::sendAddresses(const std::string& from, const Recipients& recipients)
{
std::string response;
int status = 0;
std::string::size_type emailPos = from.find('<');
if (emailPos == std::string::npos)
{
std::string sender("<");
sender.append(from);
sender.append(">");
status = sendCommand("MAIL FROM:", sender, response);
}
else
{
status = sendCommand("MAIL FROM:", from.substr(emailPos, from.size() - emailPos), response);
}
if (!isPositiveCompletion(status)) throw SMTPException("Cannot send message", response, status);
std::ostringstream recipient;
for (Recipients::const_iterator it = recipients.begin(); it != recipients.end(); ++it)
{
recipient << '<' << *it << '>';
int status = sendCommand("RCPT TO:", recipient.str(), response);
if (!isPositiveCompletion(status)) throw SMTPException(std::string("Recipient rejected: ") + recipient.str(), response, status);
recipient.str("");
}
}
void SMTPClientSession::sendData()
{
std::string response;
int status = sendCommand("DATA", response);
if (!isPositiveIntermediate(status)) throw SMTPException("Cannot send message data", response, status);
}
void SMTPClientSession::sendMessage(const MailMessage& message)
{
sendCommands(message);
@ -402,4 +443,19 @@ int SMTPClientSession::sendCommand(const std::string& command, const std::string
}
void SMTPClientSession::sendMessage(std::istream& istr)
{
std::string response;
int status = 0;
SocketOutputStream socketStream(_socket);
MailOutputStream mailStream(socketStream);
StreamCopier::copyStream(istr, mailStream);
mailStream.close();
socketStream.flush();
status = _socket.receiveStatusMessage(response);
if (!isPositiveCompletion(status)) throw SMTPException("The server rejected the message", response, status);
}
} } // namespace Poco::Net