Issue #4: set envelope sender.

This commit is contained in:
Vincent Richard 2013-04-03 09:02:15 +02:00
parent 251cf21cee
commit ff8827bdd3
6 changed files with 53 additions and 10 deletions

View File

@ -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)

View File

@ -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;

View File

@ -139,6 +139,21 @@ void transport::send(ref <vmime::message> msg, utility::progressListener* progre
throw exceptions::no_expeditor();
}
// Extract sender
mailbox sender;
try
{
const mailbox& mbox = *msg->getHeader()->findField(fields::SENDER)->
getValue().dynamicCast <const mailbox>();
sender = mbox;
}
catch (exceptions::no_such_field&)
{
sender = expeditor;
}
// Extract recipients
mailboxList recipients;
@ -211,7 +226,7 @@ void transport::send(ref <vmime::message> msg, utility::progressListener* progre
utility::inputStreamStringAdapter isAdapter(str);
send(expeditor, recipients, isAdapter, str.length(), progress);
send(expeditor, recipients, isAdapter, str.length(), progress, sender);
}

View File

@ -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 <connectionInfos> getConnectionInfos() const;

View File

@ -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 <connectionInfos> getConnectionInfos() const;

View File

@ -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;