SMTP/DSN refactoring.
This commit is contained in:
parent
a6226e8cbc
commit
c6904bd7cf
@ -149,7 +149,7 @@ void sendmailTransport::send(
|
||||
const size_t size,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const dsnAttributes& /*dsnAttrs*/
|
||||
const sendOptions& /* options */
|
||||
) {
|
||||
|
||||
// If no recipient/expeditor was found, throw an exception
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
const size_t size,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
const sendOptions& options = sendOptions()
|
||||
);
|
||||
|
||||
bool isSecuredConnection() const;
|
||||
|
@ -27,43 +27,45 @@
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include "vmime/net/dsnAttributes.hpp"
|
||||
#include "vmime/net/smtp/DSNAttributes.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
namespace smtp {
|
||||
|
||||
|
||||
dsnAttributes::dsnAttributes(const string& dsnNotify, const string& dsnRet, const string& dsnEnvelopId)
|
||||
DSNAttributes::DSNAttributes(const string& dsnNotify, const string& dsnRet, const string& dsnEnvelopId)
|
||||
: m_notifications(dsnNotify), m_returnFormat(dsnRet), m_envelopId(dsnEnvelopId) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
string dsnAttributes::getNotificationConditions() const {
|
||||
string DSNAttributes::getNotificationConditions() const {
|
||||
|
||||
return m_notifications;
|
||||
}
|
||||
|
||||
|
||||
string dsnAttributes::getReturnFormat() const {
|
||||
string DSNAttributes::getReturnFormat() const {
|
||||
|
||||
return m_returnFormat;
|
||||
}
|
||||
|
||||
|
||||
string dsnAttributes::getEnvelopId() const {
|
||||
string DSNAttributes::getEnvelopId() const {
|
||||
|
||||
return m_envelopId;
|
||||
}
|
||||
|
||||
|
||||
bool dsnAttributes::isEmpty() const {
|
||||
bool DSNAttributes::isEmpty() const {
|
||||
|
||||
return m_notifications.empty() && m_returnFormat.empty() && m_envelopId.empty();
|
||||
}
|
||||
|
||||
|
||||
} // smtp
|
||||
} // net
|
||||
} // vmime
|
||||
|
@ -21,8 +21,8 @@
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_NET_DSNATTRIBUTES_HPP_INCLUDED
|
||||
#define VMIME_NET_DSNATTRIBUTES_HPP_INCLUDED
|
||||
#ifndef VMIME_NET_SMTP_DSNATTRIBUTES_HPP_INCLUDED
|
||||
#define VMIME_NET_SMTP_DSNATTRIBUTES_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/config.hpp"
|
||||
@ -38,39 +38,40 @@
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
namespace smtp {
|
||||
|
||||
|
||||
/** Holds a set of attributes for Delivery Status Notifications (DSN).
|
||||
*/
|
||||
class VMIME_EXPORT dsnAttributes : public object {
|
||||
class VMIME_EXPORT DSNAttributes : public object {
|
||||
|
||||
public:
|
||||
|
||||
/** Constructs an empty dsnAttributes object.
|
||||
/** Constructs an empty DSNAttributes object.
|
||||
*/
|
||||
dsnAttributes() = default;
|
||||
DSNAttributes() = default;
|
||||
|
||||
/** Constructs a new dsnAttributes object by copying an existing object.
|
||||
/** Constructs a new DSNAttributes object by copying an existing object.
|
||||
*
|
||||
* @param dsn object to copy
|
||||
*/
|
||||
dsnAttributes(const dsnAttributes& dsn) = default;
|
||||
DSNAttributes(const DSNAttributes& dsn) = default;
|
||||
|
||||
/** Constructs a new dsnAttributes object by moving an existing object.
|
||||
/** Constructs a new DSNAttributes object by moving an existing object.
|
||||
*
|
||||
* @param dsn object (Rvalue reference) to move from.
|
||||
*/
|
||||
dsnAttributes(dsnAttributes&& dsn) = default;
|
||||
DSNAttributes(DSNAttributes&& dsn) = default;
|
||||
|
||||
~dsnAttributes() = default;
|
||||
~DSNAttributes() = default;
|
||||
|
||||
/** Constructs a new dsnAttributes object by specifying the attributes.
|
||||
/** Constructs a new DSNAttributes object by specifying the attributes.
|
||||
*
|
||||
* @param dsnNotify comma separated list of notification conditions as specified in RFC 1891
|
||||
* @param dsnRet content of DSN - full message or headers only ("FULL" or "HDRS")
|
||||
* @param dsnEnvelopId envelop ID to be able to pair the DSN with original message (plain text not in "<" ">")
|
||||
*/
|
||||
dsnAttributes(const string& dsnNotify, const string& dsnRet, const string& dsnEnvelopId);
|
||||
DSNAttributes(const string& dsnNotify, const string& dsnRet, const string& dsnEnvelopId);
|
||||
|
||||
/** Returns comma separated list of notification conditions as specified in RFC 1891
|
||||
*
|
||||
@ -104,6 +105,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} // smtp
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
@ -111,4 +113,4 @@ private:
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#endif // VMIME_NET_DSNATTRIBUTES_HPP_INCLUDED
|
||||
#endif // VMIME_NET_SMTP_DSNATTRIBUTES_HPP_INCLUDED
|
@ -100,16 +100,20 @@ shared_ptr <SMTPCommand> SMTPCommand::STARTTLS() {
|
||||
|
||||
|
||||
// static
|
||||
shared_ptr <SMTPCommand> SMTPCommand::MAIL(const mailbox& mbox, const bool utf8,
|
||||
const std::string& dsnRet, const std::string& dsnEnvelopId) {
|
||||
shared_ptr <SMTPCommand> SMTPCommand::MAIL(
|
||||
const mailbox& mbox, const bool utf8,
|
||||
const shared_ptr <const DSNAttributes>& dsnAttrs
|
||||
) {
|
||||
|
||||
return MAIL(mbox, utf8, 0, dsnRet, dsnEnvelopId);
|
||||
return MAIL(mbox, utf8, 0, dsnAttrs);
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
shared_ptr <SMTPCommand> SMTPCommand::MAIL(const mailbox& mbox, const bool utf8, const size_t size,
|
||||
const std::string& dsnRet, const std::string& dsnEnvelopId) {
|
||||
shared_ptr <SMTPCommand> SMTPCommand::MAIL(
|
||||
const mailbox& mbox, const bool utf8, const size_t size,
|
||||
const shared_ptr <const DSNAttributes>& dsnAttrs
|
||||
) {
|
||||
|
||||
std::ostringstream cmd;
|
||||
cmd.imbue(std::locale::classic());
|
||||
@ -127,11 +131,11 @@ shared_ptr <SMTPCommand> SMTPCommand::MAIL(const mailbox& mbox, const bool utf8,
|
||||
|
||||
cmd << ">";
|
||||
|
||||
if (!dsnRet.empty()) {
|
||||
cmd << " " << dsn::RET << "=" << dsnRet;
|
||||
if (dsnAttrs && !dsnAttrs->getReturnFormat().empty()) {
|
||||
cmd << " " << dsn::RET << "=" << dsnAttrs->getReturnFormat();
|
||||
}
|
||||
if (!dsnEnvelopId.empty()) {
|
||||
cmd << " " << dsn::ENVID << "=<" << dsnEnvelopId << ">";
|
||||
if (dsnAttrs && !dsnAttrs->getEnvelopId().empty()) {
|
||||
cmd << " " << dsn::ENVID << "=<" << dsnAttrs->getEnvelopId() << ">";
|
||||
}
|
||||
|
||||
if (utf8) {
|
||||
@ -147,8 +151,10 @@ shared_ptr <SMTPCommand> SMTPCommand::MAIL(const mailbox& mbox, const bool utf8,
|
||||
|
||||
|
||||
// static
|
||||
shared_ptr <SMTPCommand> SMTPCommand::RCPT(const mailbox& mbox, const bool utf8,
|
||||
const string& dsnNotify) {
|
||||
shared_ptr <SMTPCommand> SMTPCommand::RCPT(
|
||||
const mailbox& mbox, const bool utf8,
|
||||
const shared_ptr <const DSNAttributes>& dsnAttrs
|
||||
) {
|
||||
|
||||
std::ostringstream cmd;
|
||||
cmd.imbue(std::locale::classic());
|
||||
@ -166,8 +172,8 @@ shared_ptr <SMTPCommand> SMTPCommand::RCPT(const mailbox& mbox, const bool utf8,
|
||||
|
||||
cmd << ">";
|
||||
|
||||
if (!dsnNotify.empty()) {
|
||||
cmd << " " << dsn::NOTIFY << "=" << dsnNotify;
|
||||
if (dsnAttrs && !dsnAttrs->getNotificationConditions().empty()) {
|
||||
cmd << " " << dsn::NOTIFY << "=" << dsnAttrs->getNotificationConditions();
|
||||
}
|
||||
|
||||
return createCommand(cmd.str());
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include "vmime/object.hpp"
|
||||
#include "vmime/base.hpp"
|
||||
|
||||
#include "DSNAttributes.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
|
||||
@ -64,11 +66,11 @@ public:
|
||||
static shared_ptr <SMTPCommand> AUTH(const string& mechName, const std::string& initialResponse);
|
||||
static shared_ptr <SMTPCommand> STARTTLS();
|
||||
static shared_ptr <SMTPCommand> MAIL(const mailbox& mbox, const bool utf8,
|
||||
const std::string& dsnRet, const std::string& dsnEnvelopId);
|
||||
const shared_ptr <const DSNAttributes>& dsnAttrs);
|
||||
static shared_ptr <SMTPCommand> MAIL(const mailbox& mbox, const bool utf8, const size_t size,
|
||||
const std::string& dsnRet, const std::string& dsnEnvelopId);
|
||||
const shared_ptr <const DSNAttributes>& dsnAttrs);
|
||||
static shared_ptr <SMTPCommand> RCPT(const mailbox& mbox, const bool utf8,
|
||||
const std::string& dsnNotify);
|
||||
const shared_ptr <const DSNAttributes>& dsnAttrs);
|
||||
static shared_ptr <SMTPCommand> RSET();
|
||||
static shared_ptr <SMTPCommand> DATA();
|
||||
static shared_ptr <SMTPCommand> BDAT(const size_t chunkSize, const bool last);
|
||||
|
61
src/vmime/net/smtp/SMTPSendOptions.cpp
Normal file
61
src/vmime/net/smtp/SMTPSendOptions.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2020 Vincent Richard <vincent@vmime.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#include "vmime/config.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include "vmime/net/smtp/SMTPSendOptions.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
namespace smtp {
|
||||
|
||||
|
||||
void SMTPSendOptions::setDSNAttributes(const shared_ptr <DSNAttributes>& dsnAttribs) {
|
||||
|
||||
m_dsnAttribs = dsnAttribs;
|
||||
}
|
||||
|
||||
|
||||
const shared_ptr <DSNAttributes> SMTPSendOptions::getDSNAttributes() {
|
||||
|
||||
return m_dsnAttribs;
|
||||
}
|
||||
|
||||
|
||||
const shared_ptr <const DSNAttributes> SMTPSendOptions::getDSNAttributes() const {
|
||||
|
||||
return m_dsnAttribs;
|
||||
}
|
||||
|
||||
|
||||
} // smtp
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
100
src/vmime/net/smtp/SMTPSendOptions.hpp
Normal file
100
src/vmime/net/smtp/SMTPSendOptions.hpp
Normal file
@ -0,0 +1,100 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2020 Vincent Richard <vincent@vmime.org>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 3 of
|
||||
// the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// Linking this library statically or dynamically with other modules is making
|
||||
// a combined work based on this library. Thus, the terms and conditions of
|
||||
// the GNU General Public License cover the whole combination.
|
||||
//
|
||||
|
||||
#ifndef VMIME_NET_SMTP_SMTPSENDOPTIONS_HPP_INCLUDED
|
||||
#define VMIME_NET_SMTP_SMTPSENDOPTIONS_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/config.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include "vmime/net/transport.hpp"
|
||||
|
||||
#include "vmime/net/smtp/DSNAttributes.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
namespace smtp {
|
||||
|
||||
|
||||
/** Holds options for sending messages over SMTP.
|
||||
*/
|
||||
class VMIME_EXPORT SMTPSendOptions : public transport::sendOptions {
|
||||
|
||||
public:
|
||||
|
||||
/** Constructs an empty SMTPSendOptions object.
|
||||
*/
|
||||
SMTPSendOptions() = default;
|
||||
|
||||
/** Constructs a new SMTPSendOptions object by copying an existing object.
|
||||
*
|
||||
* @param dsn object to copy
|
||||
*/
|
||||
SMTPSendOptions(const SMTPSendOptions& dsn) = default;
|
||||
|
||||
/** Constructs a new SMTPSendOptions object by moving an existing object.
|
||||
*
|
||||
* @param dsn object (Rvalue reference) to move from.
|
||||
*/
|
||||
SMTPSendOptions(SMTPSendOptions&& dsn) = default;
|
||||
|
||||
~SMTPSendOptions() = default;
|
||||
|
||||
/** Set DSN attributes to use when sending a message.
|
||||
*
|
||||
* @param dsnAttribs DSN attributes
|
||||
*/
|
||||
void setDSNAttributes(const shared_ptr <DSNAttributes>& dsnAttribs);
|
||||
|
||||
/** Return DSN attributes used when sending a message (const version).
|
||||
*
|
||||
* @return DSN attributes, if set
|
||||
*/
|
||||
const shared_ptr <const DSNAttributes> getDSNAttributes() const;
|
||||
|
||||
/** Return DSN attributes used when sending a message.
|
||||
*
|
||||
* @return DSN attributes, if set
|
||||
*/
|
||||
const shared_ptr <DSNAttributes> getDSNAttributes();
|
||||
|
||||
private:
|
||||
|
||||
shared_ptr <DSNAttributes> m_dsnAttribs;
|
||||
};
|
||||
|
||||
|
||||
} // smtp
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#endif // VMIME_NET_SMTP_SMTPSENDOPTIONS_HPP_INCLUDED
|
@ -33,6 +33,7 @@
|
||||
#include "vmime/net/smtp/SMTPCommandSet.hpp"
|
||||
#include "vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp"
|
||||
#include "vmime/net/smtp/SMTPExceptions.hpp"
|
||||
#include "vmime/net/smtp/SMTPSendOptions.hpp"
|
||||
|
||||
#include "vmime/exception.hpp"
|
||||
#include "vmime/mailboxList.hpp"
|
||||
@ -184,9 +185,11 @@ void SMTPTransport::sendEnvelope(
|
||||
const mailbox& sender,
|
||||
bool sendDATACommand,
|
||||
const size_t size,
|
||||
const dsnAttributes& dsnAttrs
|
||||
const sendOptions& options
|
||||
) {
|
||||
|
||||
auto opts = dynamic_cast <const SMTPSendOptions*>(&options);
|
||||
|
||||
// If no recipient/expeditor was found, throw an exception
|
||||
if (recipients.isEmpty()) {
|
||||
throw exceptions::no_recipient();
|
||||
@ -195,7 +198,7 @@ void SMTPTransport::sendEnvelope(
|
||||
}
|
||||
|
||||
// If DSN extension is used, ensure it is supported by the server
|
||||
if (!dsnAttrs.isEmpty() && !m_connection->hasExtension("DSN")) {
|
||||
if (opts && opts->getDSNAttributes() && !m_connection->hasExtension("DSN")) {
|
||||
throw SMTPDSNExtensionNotSupportedException();
|
||||
}
|
||||
|
||||
@ -237,8 +240,7 @@ void SMTPTransport::sendEnvelope(
|
||||
commands->addCommand(
|
||||
SMTPCommand::MAIL(
|
||||
sender, hasSMTPUTF8 && needSMTPUTF8, hasSize ? size : 0,
|
||||
dsnAttrs.getNotificationConditions(),
|
||||
dsnAttrs.getEnvelopId()
|
||||
opts ? opts->getDSNAttributes() : nullptr
|
||||
)
|
||||
);
|
||||
|
||||
@ -247,8 +249,7 @@ void SMTPTransport::sendEnvelope(
|
||||
commands->addCommand(
|
||||
SMTPCommand::MAIL(
|
||||
expeditor, hasSMTPUTF8 && needSMTPUTF8, hasSize ? size : 0,
|
||||
dsnAttrs.getNotificationConditions(),
|
||||
dsnAttrs.getEnvelopId()
|
||||
opts ? opts->getDSNAttributes() : nullptr
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -260,8 +261,12 @@ void SMTPTransport::sendEnvelope(
|
||||
for (size_t i = 0 ; i < recipients.getMailboxCount() ; ++i) {
|
||||
|
||||
const mailbox& mbox = *recipients.getMailboxAt(i);
|
||||
commands->addCommand(SMTPCommand::RCPT(mbox, hasSMTPUTF8 && needSMTPUTF8,
|
||||
dsnAttrs.getNotificationConditions()));
|
||||
commands->addCommand(
|
||||
SMTPCommand::RCPT(
|
||||
mbox, hasSMTPUTF8 && needSMTPUTF8,
|
||||
opts ? opts->getDSNAttributes() : nullptr
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Prepare sending of message data
|
||||
@ -388,7 +393,7 @@ void SMTPTransport::send(
|
||||
const size_t size,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const dsnAttributes& dsnAttrs
|
||||
const sendOptions& options
|
||||
) {
|
||||
|
||||
if (!isConnected()) {
|
||||
@ -396,8 +401,7 @@ void SMTPTransport::send(
|
||||
}
|
||||
|
||||
// Send message envelope
|
||||
sendEnvelope(expeditor, recipients, sender, /* sendDATACommand */ true, size,
|
||||
dsnAttrs);
|
||||
sendEnvelope(expeditor, recipients, sender, /* sendDATACommand */ true, size, options);
|
||||
|
||||
// Send the message data
|
||||
// Stream copy with "\n." to "\n.." transformation
|
||||
@ -430,7 +434,7 @@ void SMTPTransport::send(
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const dsnAttributes& dsnAttrs
|
||||
const sendOptions& options
|
||||
) {
|
||||
|
||||
if (!isConnected()) {
|
||||
@ -457,14 +461,14 @@ void SMTPTransport::send(
|
||||
|
||||
utility::inputStreamStringAdapter isAdapter(str);
|
||||
|
||||
send(expeditor, recipients, isAdapter, str.length(), progress, sender, dsnAttrs);
|
||||
send(expeditor, recipients, isAdapter, str.length(), progress, sender, options);
|
||||
return;
|
||||
}
|
||||
|
||||
// Send message envelope
|
||||
const size_t msgSize = msg->getGeneratedSize(ctx);
|
||||
|
||||
sendEnvelope(expeditor, recipients, sender, /* sendDATACommand */ false, msgSize, dsnAttrs);
|
||||
sendEnvelope(expeditor, recipients, sender, /* sendDATACommand */ false, msgSize, options);
|
||||
|
||||
// Send the message by chunks
|
||||
SMTPChunkingOutputStreamAdapter chunkStream(m_connection, msgSize, progress);
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
const size_t size,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
const sendOptions& options = sendOptions()
|
||||
);
|
||||
|
||||
void send(
|
||||
@ -88,7 +88,7 @@ public:
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
const sendOptions& options = sendOptions()
|
||||
);
|
||||
|
||||
bool isSecuredConnection() const;
|
||||
@ -118,7 +118,7 @@ private:
|
||||
const mailbox& sender,
|
||||
bool sendDATACommand,
|
||||
const size_t size,
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
const sendOptions& options = sendOptions()
|
||||
);
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "vmime/net/smtp/SMTPTransport.hpp"
|
||||
#include "vmime/net/smtp/SMTPSTransport.hpp"
|
||||
#include "vmime/net/smtp/SMTPExceptions.hpp"
|
||||
#include "vmime/net/smtp/SMTPSendOptions.hpp"
|
||||
|
||||
|
||||
#endif // VMIME_NET_SMTP_SMTP_HPP_INCLUDED
|
||||
|
@ -137,7 +137,7 @@ static void extractMailboxes(
|
||||
void transport::send(
|
||||
const shared_ptr <vmime::message>& msg,
|
||||
utility::progressListener* progress,
|
||||
const dsnAttributes& dsnAttrs
|
||||
const sendOptions& options
|
||||
) {
|
||||
|
||||
// Extract expeditor
|
||||
@ -222,7 +222,7 @@ void transport::send(
|
||||
|
||||
} headerExchanger(msg, hdr);
|
||||
|
||||
send(msg, expeditor, recipients, progress, sender, dsnAttrs);
|
||||
send(msg, expeditor, recipients, progress, sender, options);
|
||||
}
|
||||
|
||||
|
||||
@ -232,7 +232,7 @@ void transport::send(
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const dsnAttributes& dsnAttrs
|
||||
const sendOptions& options
|
||||
) {
|
||||
|
||||
// Generate the message, "stream" it and delegate the sending
|
||||
@ -246,8 +246,7 @@ void transport::send(
|
||||
|
||||
utility::inputStreamStringAdapter isAdapter(str);
|
||||
|
||||
send(expeditor, recipients, isAdapter, str.length(), progress, sender,
|
||||
dsnAttrs);
|
||||
send(expeditor, recipients, isAdapter, str.length(), progress, sender, options);
|
||||
}
|
||||
|
||||
|
||||
@ -257,6 +256,19 @@ transport::Type transport::getType() const {
|
||||
}
|
||||
|
||||
|
||||
// sendOptions
|
||||
|
||||
|
||||
transport::sendOptions::sendOptions() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
transport::sendOptions::~sendOptions() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include "vmime/net/dsnAttributes.hpp"
|
||||
#include "vmime/net/service.hpp"
|
||||
#include "vmime/utility/stream.hpp"
|
||||
|
||||
@ -64,18 +63,28 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
/** Holds a set of options that can be passed to send() methods.
|
||||
*/
|
||||
class VMIME_EXPORT sendOptions {
|
||||
|
||||
public:
|
||||
|
||||
sendOptions();
|
||||
virtual ~sendOptions();
|
||||
};
|
||||
|
||||
/** Send a message over this transport service.
|
||||
* The default implementation simply generates the whole message into
|
||||
* a string buffer and "streams" it via a inputStreamStringAdapter.
|
||||
*
|
||||
* @param msg message to send
|
||||
* @param progress progress listener, or NULL if not used
|
||||
* @param dsnAttributes attributes for Delivery Status Notification (if needed)
|
||||
* @param options sending options
|
||||
*/
|
||||
virtual void send(
|
||||
const shared_ptr <vmime::message>& msg,
|
||||
utility::progressListener* progress = NULL,
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
const sendOptions& options = sendOptions()
|
||||
);
|
||||
|
||||
/** Send a message over this transport service.
|
||||
@ -86,7 +95,7 @@ public:
|
||||
* @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)
|
||||
* @param dsnAttributes attributes for Delivery Status Notification (if needed)
|
||||
* @param options sending options
|
||||
*/
|
||||
virtual void send(
|
||||
const mailbox& expeditor,
|
||||
@ -95,7 +104,7 @@ public:
|
||||
const size_t size,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
const sendOptions& options = sendOptions()
|
||||
) = 0;
|
||||
|
||||
/** Send a message over this transport service.
|
||||
@ -107,7 +116,7 @@ public:
|
||||
* @param recipients list of recipient mailboxes
|
||||
* @param progress progress listener, or NULL if not used
|
||||
* @param sender envelope sender (if empty, expeditor will be used)
|
||||
* @param dsnAttributes attributes for Delivery Status Notification (if needed)
|
||||
* @param options sending options
|
||||
*/
|
||||
virtual void send(
|
||||
const shared_ptr <vmime::message>& msg,
|
||||
@ -115,7 +124,7 @@ public:
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
const sendOptions& options = sendOptions()
|
||||
);
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "tests/testUtils.hpp"
|
||||
|
||||
#include "vmime/net/smtp/SMTPCommand.hpp"
|
||||
#include "vmime/net/smtp/DSNAttributes.hpp"
|
||||
|
||||
|
||||
using namespace vmime::net::smtp;
|
||||
@ -114,7 +115,9 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testMAIL() {
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL(vmime::mailbox("me@vmime.org"), false, "FULL", "dsn-unique-id");
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("", "FULL", "dsn-unique-id");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL(vmime::mailbox("me@vmime.org"), false, dsnAttrs);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
VASSERT_EQ("Text", "MAIL FROM:<me@vmime.org> RET=FULL ENVID=<dsn-unique-id>", cmd->getText());
|
||||
@ -122,8 +125,10 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testMAIL_Encoded() {
|
||||
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("", "FULL", "dsn-unique-id");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL(
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), false, "FULL", "dsn-unique-id"
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), false, dsnAttrs
|
||||
);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
@ -132,8 +137,10 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testMAIL_UTF8() {
|
||||
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("", "FULL", "dsn-unique-id");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL(
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true, "FULL", "dsn-unique-id"
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true, dsnAttrs
|
||||
);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
@ -142,8 +149,10 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testMAIL_SIZE() {
|
||||
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("", "FULL", "dsn-unique-id");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL(
|
||||
vmime::mailbox("me@vmime.org"), false, 123456789, "FULL", "dsn-unique-id"
|
||||
vmime::mailbox("me@vmime.org"), false, 123456789, dsnAttrs
|
||||
);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
@ -152,8 +161,10 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testMAIL_SIZE_UTF8() {
|
||||
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("", "FULL", "dsn-unique-id");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::MAIL(
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true, 123456789, "FULL", "dsn-unique-id"
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true, 123456789, dsnAttrs
|
||||
);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
@ -162,8 +173,10 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testRCPT() {
|
||||
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("NEVER", "", "");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd =
|
||||
SMTPCommand::RCPT(vmime::mailbox("someone@vmime.org"), false, "NEVER");
|
||||
SMTPCommand::RCPT(vmime::mailbox("someone@vmime.org"), false, dsnAttrs);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
VASSERT_EQ("Text", "RCPT TO:<someone@vmime.org> NOTIFY=NEVER", cmd->getText());
|
||||
@ -171,8 +184,10 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testRCPT_Encoded() {
|
||||
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("NEVER", "", "");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::RCPT(
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), false, "NEVER"
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), false, dsnAttrs
|
||||
);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
@ -181,8 +196,10 @@ VMIME_TEST_SUITE_BEGIN(SMTPCommandTest)
|
||||
|
||||
void testRCPT_UTF8() {
|
||||
|
||||
auto dsnAttrs = vmime::make_shared <DSNAttributes>("NEVER", "", "");
|
||||
|
||||
vmime::shared_ptr <SMTPCommand> cmd = SMTPCommand::RCPT(
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true, "NEVER"
|
||||
vmime::mailbox(vmime::emailAddress("mailtest", "例え.テスト")), true, dsnAttrs
|
||||
);
|
||||
|
||||
VASSERT_NOT_NULL("Not null", cmd);
|
||||
|
Loading…
Reference in New Issue
Block a user