From ff8827bdd33da077d4677cc7589449cfa36d8b87 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Wed, 3 Apr 2013 09:02:15 +0200 Subject: Issue #4: set envelope sender. --- src/net/sendmail/sendmailTransport.cpp | 9 +++++++-- src/net/smtp/SMTPTransport.cpp | 12 ++++++++---- src/net/transport.cpp | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/net/sendmail/sendmailTransport.cpp b/src/net/sendmail/sendmailTransport.cpp index dbbb55a8..82501575 100644 --- a/src/net/sendmail/sendmailTransport.cpp +++ b/src/net/sendmail/sendmailTransport.cpp @@ -139,7 +139,7 @@ void sendmailTransport::noop() void sendmailTransport::send (const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, const utility::stream::size_type size, - utility::progressListener* progress) + utility::progressListener* progress, const mailbox& sender) { // If no recipient/expeditor was found, throw an exception if (recipients.isEmpty()) @@ -152,7 +152,12 @@ void sendmailTransport::send args.push_back("-i"); args.push_back("-f"); - args.push_back(expeditor.getEmail().generate()); + + if (!sender.isEmpty()) + args.push_back(expeditor.getEmail().generate()); + else + args.push_back(sender.getEmail().generate()); + args.push_back("--"); for (int i = 0 ; i < recipients.getMailboxCount() ; ++i) diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp index b95321f9..853ffe35 100644 --- a/src/net/smtp/SMTPTransport.cpp +++ b/src/net/smtp/SMTPTransport.cpp @@ -560,9 +560,10 @@ void SMTPTransport::noop() } -void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients, - utility::inputStream& is, const utility::stream::size_type size, - utility::progressListener* progress) +void SMTPTransport::send + (const mailbox& expeditor, const mailboxList& recipients, + utility::inputStream& is, const utility::stream::size_type size, + utility::progressListener* progress, const mailbox& sender) { if (!isConnected()) throw exceptions::not_connected(); @@ -586,7 +587,10 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients commands->addCommand(SMTPCommand::RSET()); // Emit the "MAIL" command - commands->addCommand(SMTPCommand::MAIL(expeditor)); + if (!sender.isEmpty()) + commands->addCommand(SMTPCommand::MAIL(sender)); + else + commands->addCommand(SMTPCommand::MAIL(expeditor)); // Now, we will need to reset next time m_needReset = true; diff --git a/src/net/transport.cpp b/src/net/transport.cpp index 1e2936ce..923441b7 100644 --- a/src/net/transport.cpp +++ b/src/net/transport.cpp @@ -139,6 +139,21 @@ void transport::send(ref msg, utility::progressListener* progre throw exceptions::no_expeditor(); } + // Extract sender + mailbox sender; + + try + { + const mailbox& mbox = *msg->getHeader()->findField(fields::SENDER)-> + getValue().dynamicCast (); + + sender = mbox; + } + catch (exceptions::no_such_field&) + { + sender = expeditor; + } + // Extract recipients mailboxList recipients; @@ -211,7 +226,7 @@ void transport::send(ref msg, utility::progressListener* progre utility::inputStreamStringAdapter isAdapter(str); - send(expeditor, recipients, isAdapter, str.length(), progress); + send(expeditor, recipients, isAdapter, str.length(), progress, sender); } -- cgit