diff options
author | Vincent Richard <[email protected]> | 2013-02-17 17:07:23 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2013-02-17 17:07:23 +0000 |
commit | 0757efad0d0669766236eefbedad98ee8541a5f5 (patch) | |
tree | cd157a402a5f0c6d9bc3da37a33987981d708b0c /src/net/smtp/SMTPTransport.cpp | |
parent | Always throw std exceptions (eg. bad_alloc) and VMime time out exceptions. (diff) | |
download | vmime-0757efad0d0669766236eefbedad98ee8541a5f5.tar.gz vmime-0757efad0d0669766236eefbedad98ee8541a5f5.zip |
Reset SMTP session state (using RSET command) if transport is being reused.
Diffstat (limited to '')
-rw-r--r-- | src/net/smtp/SMTPTransport.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp index 8a3362e2..f1fa76aa 100644 --- a/src/net/smtp/SMTPTransport.cpp +++ b/src/net/smtp/SMTPTransport.cpp @@ -70,7 +70,7 @@ namespace smtp { SMTPTransport::SMTPTransport(ref <session> sess, ref <security::authenticator> auth, const bool secured) : transport(sess, getInfosInstance(), auth), m_socket(NULL), m_authentified(false), m_extendedSMTP(false), m_timeoutHandler(NULL), - m_isSMTPS(secured), m_secured(false) + m_isSMTPS(secured), m_secured(false), m_needReset(false) { } @@ -574,15 +574,23 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients throw exceptions::no_expeditor(); + const bool needReset = m_needReset; const bool hasPipelining = m_extensions.find("PIPELINING") != m_extensions.end(); ref <SMTPResponse> resp; ref <SMTPCommandSet> commands = SMTPCommandSet::create(hasPipelining); + // Emit a "RSET" command if we previously sent a message on this connection + if (needReset) + commands->addCommand(SMTPCommand::RSET()); + // Emit the "MAIL" command commands->addCommand(SMTPCommand::MAIL(expeditor)); + // Now, we will need to reset next time + m_needReset = true; + // Emit a "RCPT TO" command for each recipient for (size_t i = 0 ; i < recipients.getMailboxCount() ; ++i) { @@ -593,6 +601,18 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients // Prepare sending of message data commands->addCommand(SMTPCommand::DATA()); + // Read response for "RSET" command + if (needReset) + { + commands->writeToSocket(m_socket); + + if ((resp = readResponse())->getCode() != 250) + { + internalDisconnect(); + throw exceptions::command_error(commands->getLastCommandSent()->getText(), resp->getText()); + } + } + // Read response for "MAIL" command commands->writeToSocket(m_socket); |