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); } diff --git a/vmime/net/sendmail/sendmailTransport.hpp b/vmime/net/sendmail/sendmailTransport.hpp index 876db6ea..7f8e4d77 100644 --- a/vmime/net/sendmail/sendmailTransport.hpp +++ b/vmime/net/sendmail/sendmailTransport.hpp @@ -64,7 +64,13 @@ public: void noop(); - void send(const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, const utility::stream::size_type size, utility::progressListener* progress = NULL); + void send + (const mailbox& expeditor, + const mailboxList& recipients, + utility::inputStream& is, + const utility::stream::size_type size, + utility::progressListener* progress = NULL, + const mailbox& sender = mailbox()); bool isSecuredConnection() const; ref getConnectionInfos() const; diff --git a/vmime/net/smtp/SMTPTransport.hpp b/vmime/net/smtp/SMTPTransport.hpp index 20f4bc52..435aff39 100644 --- a/vmime/net/smtp/SMTPTransport.hpp +++ b/vmime/net/smtp/SMTPTransport.hpp @@ -68,7 +68,13 @@ public: void noop(); - void send(const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, const utility::stream::size_type size, utility::progressListener* progress = NULL); + void send + (const mailbox& expeditor, + const mailboxList& recipients, + utility::inputStream& is, + const utility::stream::size_type size, + utility::progressListener* progress = NULL, + const mailbox& sender = mailbox()); bool isSecuredConnection() const; ref getConnectionInfos() const; diff --git a/vmime/net/transport.hpp b/vmime/net/transport.hpp index e39e3fd1..cadde20f 100644 --- a/vmime/net/transport.hpp +++ b/vmime/net/transport.hpp @@ -74,8 +74,15 @@ public: * @param is input stream provding message data (header + body) * @param size size of the message data * @param progress progress listener, or NULL if not used + * @param sender envelope sender (if empty, expeditor will be used) */ - virtual void send(const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, const utility::stream::size_type size, utility::progressListener* progress = NULL) = 0; + virtual void send + (const mailbox& expeditor, + const mailboxList& recipients, + utility::inputStream& is, + const utility::stream::size_type size, + utility::progressListener* progress = NULL, + const mailbox& sender = mailbox()) = 0; Type getType() const;