Create class for DSN attributes
The three attributes needed to request a Delivery Status Notification are now passed as an "dsnAttributes" object to the send methods. Fixed code style at some related palces.
This commit is contained in:
parent
e30766cf2a
commit
64ef65e03c
@ -234,8 +234,8 @@ namespace dispositionModifiers {
|
||||
}
|
||||
|
||||
// Constants for DSN (delivery status notification)
|
||||
namespace dsn
|
||||
{
|
||||
namespace dsn {
|
||||
|
||||
const char* const NOTIFY = "NOTIFY";
|
||||
const char* const NEVER = "NEVER";
|
||||
const char* const SUCCESS = "SUCCESS";
|
||||
|
@ -253,8 +253,8 @@ namespace vmime {
|
||||
}
|
||||
|
||||
/** Constants for DSN (delivery status notification) */
|
||||
namespace dsn
|
||||
{
|
||||
namespace dsn {
|
||||
|
||||
extern VMIME_EXPORT const char* const NOTIFY;
|
||||
extern VMIME_EXPORT const char* const NEVER;
|
||||
extern VMIME_EXPORT const char* const SUCCESS;
|
||||
|
65
src/vmime/net/dsnAttributes.cpp
Normal file
65
src/vmime/net/dsnAttributes.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2020 Jan Osusky <jan@osusky.name>
|
||||
//
|
||||
// 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/dsnAttributes.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
|
||||
|
||||
dsnAttributes::dsnAttributes(string dsnNotify, string dsnRet, string dsnEnvelopId)
|
||||
: m_notifications(dsnNotify), m_returnFormat(dsnRet), m_envelopId(dsnEnvelopId) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
string dsnAttributes::notificationConditions() const {
|
||||
|
||||
return m_notifications;
|
||||
}
|
||||
|
||||
|
||||
string dsnAttributes::returnFormat() const {
|
||||
|
||||
return m_returnFormat;
|
||||
}
|
||||
|
||||
|
||||
string dsnAttributes::envelopId() const {
|
||||
|
||||
return m_envelopId;
|
||||
}
|
||||
|
||||
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
108
src/vmime/net/dsnAttributes.hpp
Normal file
108
src/vmime/net/dsnAttributes.hpp
Normal file
@ -0,0 +1,108 @@
|
||||
//
|
||||
// VMime library (http://www.vmime.org)
|
||||
// Copyright (C) 2020 Jan Osusky <jan@osusky.name>
|
||||
//
|
||||
// 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_DSNATTRIBUTES_HPP_INCLUDED
|
||||
#define VMIME_NET_DSNATTRIBUTES_HPP_INCLUDED
|
||||
|
||||
|
||||
#include "vmime/config.hpp"
|
||||
|
||||
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "vmime/types.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
|
||||
|
||||
/** Holds a set of attributes for Delivery Status Notifications (DSN).
|
||||
*/
|
||||
class VMIME_EXPORT dsnAttributes : public object {
|
||||
|
||||
public:
|
||||
|
||||
/** Constructs an empty dsnAttributes object.
|
||||
*/
|
||||
dsnAttributes() = default;
|
||||
|
||||
/** Constructs a new dsnAttributes object by copying an existing object.
|
||||
*
|
||||
* @param dsn object to copy
|
||||
*/
|
||||
dsnAttributes(const dsnAttributes& dsn) = default;
|
||||
|
||||
/** Constructs a new dsnAttributes object by moving an existing object.
|
||||
*
|
||||
* @param dsn object (Rvalue reference) to move from.
|
||||
*/
|
||||
dsnAttributes(dsnAttributes&& dsn) = default;
|
||||
|
||||
~dsnAttributes() = default;
|
||||
|
||||
/** 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(string dsnNotify, string dsnRet, string dsnEnvelopId);
|
||||
|
||||
/** Returns comma separated list of notification conditions as specified in RFC 1891
|
||||
*
|
||||
* @return comma separated list of notification conditions as specified in RFC 1891
|
||||
*/
|
||||
string notificationConditions() const;
|
||||
|
||||
/** Returns requested format of the notification (RET parameter of the ESMTP MAIL command).
|
||||
*
|
||||
* @return requested format of the notification.
|
||||
*/
|
||||
string returnFormat() const;
|
||||
|
||||
/** Returns envelop ID used pair the DSN with the original message.
|
||||
*
|
||||
* @return envelop ID used pair the DSN with the original message.
|
||||
*/
|
||||
string envelopId() const;
|
||||
|
||||
private:
|
||||
|
||||
string m_notifications;
|
||||
string m_returnFormat;
|
||||
string m_envelopId;
|
||||
};
|
||||
|
||||
|
||||
} // net
|
||||
} // vmime
|
||||
|
||||
|
||||
#endif // VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#endif // VMIME_NET_DSNATTRIBUTES_HPP_INCLUDED
|
@ -149,8 +149,7 @@ void sendmailTransport::send(
|
||||
const size_t size,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const std::string& /*dsnNotify*/, const std::string& /*dsnRet*/,
|
||||
const std::string& /*dsnEnvelopId*/
|
||||
const dsnAttributes& /*dsnAttrs*/
|
||||
) {
|
||||
|
||||
// If no recipient/expeditor was found, throw an exception
|
||||
|
@ -74,9 +74,7 @@ public:
|
||||
const size_t size,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const std::string& dsnNotify = std::string(),
|
||||
const std::string& dsnRet = std::string(),
|
||||
const std::string& dsnEnvelopId = std::string()
|
||||
const dsnAttributes& dsnAttrs
|
||||
);
|
||||
|
||||
bool isSecuredConnection() const;
|
||||
|
@ -184,7 +184,7 @@ void SMTPTransport::sendEnvelope(
|
||||
const mailbox& sender,
|
||||
bool sendDATACommand,
|
||||
const size_t size,
|
||||
const std::string& dsnNotify, const std::string& dsnRet, const std::string& dsnEnvelopId
|
||||
const dsnAttributes& dsnAttrs
|
||||
) {
|
||||
// If no recipient/expeditor was found, throw an exception
|
||||
if (recipients.isEmpty()) {
|
||||
@ -230,7 +230,9 @@ void SMTPTransport::sendEnvelope(
|
||||
|
||||
commands->addCommand(
|
||||
SMTPCommand::MAIL(
|
||||
sender, hasSMTPUTF8 && needSMTPUTF8, hasSize ? size : 0, dsnRet, dsnEnvelopId
|
||||
sender, hasSMTPUTF8 && needSMTPUTF8, hasSize ? size : 0,
|
||||
dsnAttrs.notificationConditions(),
|
||||
dsnAttrs.envelopId()
|
||||
)
|
||||
);
|
||||
|
||||
@ -238,7 +240,9 @@ void SMTPTransport::sendEnvelope(
|
||||
|
||||
commands->addCommand(
|
||||
SMTPCommand::MAIL(
|
||||
expeditor, hasSMTPUTF8 && needSMTPUTF8, hasSize ? size : 0, dsnRet, dsnEnvelopId
|
||||
expeditor, hasSMTPUTF8 && needSMTPUTF8, hasSize ? size : 0,
|
||||
dsnAttrs.notificationConditions(),
|
||||
dsnAttrs.envelopId()
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -250,7 +254,8 @@ 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, dsnNotify));
|
||||
commands->addCommand(SMTPCommand::RCPT(mbox, hasSMTPUTF8 && needSMTPUTF8,
|
||||
dsnAttrs.notificationConditions()));
|
||||
}
|
||||
|
||||
// Prepare sending of message data
|
||||
@ -377,7 +382,7 @@ void SMTPTransport::send(
|
||||
const size_t size,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const std::string& dsnNotify, const std::string& dsnRet, const std::string& dsnEnvelopId
|
||||
const dsnAttributes& dsnAttrs
|
||||
) {
|
||||
|
||||
if (!isConnected()) {
|
||||
@ -386,7 +391,7 @@ void SMTPTransport::send(
|
||||
|
||||
// Send message envelope
|
||||
sendEnvelope(expeditor, recipients, sender, /* sendDATACommand */ true, size,
|
||||
dsnNotify, dsnRet, dsnEnvelopId);
|
||||
dsnAttrs);
|
||||
|
||||
// Send the message data
|
||||
// Stream copy with "\n." to "\n.." transformation
|
||||
@ -419,7 +424,7 @@ void SMTPTransport::send(
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const std::string& dsnNotify, const std::string& dsnRet, const std::string& dsnEnvelopId
|
||||
const dsnAttributes& dsnAttrs
|
||||
) {
|
||||
|
||||
if (!isConnected()) {
|
||||
@ -446,14 +451,14 @@ void SMTPTransport::send(
|
||||
|
||||
utility::inputStreamStringAdapter isAdapter(str);
|
||||
|
||||
send(expeditor, recipients, isAdapter, str.length(), progress, sender, dsnNotify, dsnRet, dsnEnvelopId);
|
||||
send(expeditor, recipients, isAdapter, str.length(), progress, sender, dsnAttrs);
|
||||
return;
|
||||
}
|
||||
|
||||
// Send message envelope
|
||||
const size_t msgSize = msg->getGeneratedSize(ctx);
|
||||
|
||||
sendEnvelope(expeditor, recipients, sender, /* sendDATACommand */ false, msgSize, dsnNotify, dsnRet, dsnEnvelopId);
|
||||
sendEnvelope(expeditor, recipients, sender, /* sendDATACommand */ false, msgSize, dsnAttrs);
|
||||
|
||||
// Send the message by chunks
|
||||
SMTPChunkingOutputStreamAdapter chunkStream(m_connection, msgSize, progress);
|
||||
|
@ -79,9 +79,7 @@ public:
|
||||
const size_t size,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const std::string& dsnNotify = std::string(),
|
||||
const std::string& dsnRet = std::string(),
|
||||
const std::string& dsnEnvelopId = std::string()
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
);
|
||||
|
||||
void send(
|
||||
@ -90,9 +88,7 @@ public:
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const std::string& dsnNotify = std::string(),
|
||||
const std::string& dsnRet = std::string(),
|
||||
const std::string& dsnEnvelopId = std::string()
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
);
|
||||
|
||||
bool isSecuredConnection() const;
|
||||
@ -114,9 +110,7 @@ private:
|
||||
* @param sender envelope sender (if empty, expeditor will be used)
|
||||
* @param sendDATACommand if true, the DATA command will be sent
|
||||
* @param size message size, in bytes (or 0, if not known)
|
||||
* @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 the original message
|
||||
* @param dsnAttributes attributes for Delivery Status Notification (if needed)
|
||||
*/
|
||||
void sendEnvelope(
|
||||
const mailbox& expeditor,
|
||||
@ -124,9 +118,7 @@ private:
|
||||
const mailbox& sender,
|
||||
bool sendDATACommand,
|
||||
const size_t size,
|
||||
const std::string& dsnNotify,
|
||||
const std::string& dsnRet,
|
||||
const std::string& dsnEnvelopId
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
);
|
||||
|
||||
|
||||
|
@ -137,8 +137,7 @@ static void extractMailboxes(
|
||||
void transport::send(
|
||||
const shared_ptr <vmime::message>& msg,
|
||||
utility::progressListener* progress,
|
||||
const std::string& dsnNotify, const std::string& dsnRet,
|
||||
const std::string& dsnEnvelopId
|
||||
const dsnAttributes& dsnAttrs
|
||||
) {
|
||||
|
||||
// Extract expeditor
|
||||
@ -223,8 +222,7 @@ void transport::send(
|
||||
|
||||
} headerExchanger(msg, hdr);
|
||||
|
||||
send(msg, expeditor, recipients, progress, sender,
|
||||
dsnNotify, dsnRet, dsnEnvelopId);
|
||||
send(msg, expeditor, recipients, progress, sender, dsnAttrs);
|
||||
}
|
||||
|
||||
|
||||
@ -234,7 +232,7 @@ void transport::send(
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress,
|
||||
const mailbox& sender,
|
||||
const std::string& dsnNotify, const std::string& dsnRet, const std::string& dsnEnvelopId
|
||||
const dsnAttributes& dsnAttrs
|
||||
) {
|
||||
|
||||
// Generate the message, "stream" it and delegate the sending
|
||||
@ -249,7 +247,7 @@ void transport::send(
|
||||
utility::inputStreamStringAdapter isAdapter(str);
|
||||
|
||||
send(expeditor, recipients, isAdapter, str.length(), progress, sender,
|
||||
dsnNotify, dsnRet, dsnEnvelopId);
|
||||
dsnAttrs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#if VMIME_HAVE_MESSAGING_FEATURES
|
||||
|
||||
|
||||
#include "vmime/net/dsnAttributes.hpp"
|
||||
#include "vmime/net/service.hpp"
|
||||
#include "vmime/utility/stream.hpp"
|
||||
|
||||
@ -69,16 +70,12 @@ public:
|
||||
*
|
||||
* @param msg message to send
|
||||
* @param progress progress listener, or NULL if not used
|
||||
* @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
|
||||
* @param dsnAttributes attributes for Delivery Status Notification (if needed)
|
||||
*/
|
||||
virtual void send(
|
||||
const shared_ptr <vmime::message>& msg,
|
||||
utility::progressListener* progress = NULL,
|
||||
const std::string& dsnNotify = std::string(),
|
||||
const std::string& dsnRet = std::string(),
|
||||
const std::string& dsnEnvelopId = std::string()
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
);
|
||||
|
||||
/** Send a message over this transport service.
|
||||
@ -89,10 +86,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 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 envelope identifier to be transmitted along with the message
|
||||
* to be able to pair the DSN with original message (plain text not in "<" ">")
|
||||
* @param dsnAttributes attributes for Delivery Status Notification (if needed)
|
||||
*/
|
||||
virtual void send(
|
||||
const mailbox& expeditor,
|
||||
@ -101,9 +95,7 @@ public:
|
||||
const size_t size,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const std::string& dsnNotify = std::string(),
|
||||
const std::string& dsnRet = std::string(),
|
||||
const std::string& dsnEnvelopId = std::string()
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
) = 0;
|
||||
|
||||
/** Send a message over this transport service.
|
||||
@ -115,6 +107,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)
|
||||
*/
|
||||
virtual void send(
|
||||
const shared_ptr <vmime::message>& msg,
|
||||
@ -122,9 +115,7 @@ public:
|
||||
const mailboxList& recipients,
|
||||
utility::progressListener* progress = NULL,
|
||||
const mailbox& sender = mailbox(),
|
||||
const std::string& dsnNotify = std::string(),
|
||||
const std::string& dsnRet = std::string(),
|
||||
const std::string& dsnEnvelopId = std::string()
|
||||
const dsnAttributes& dsnAttrs = dsnAttributes()
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user