aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Osusky <[email protected]>2020-07-23 08:42:15 +0000
committerJan Osusky <[email protected]>2020-07-23 08:42:15 +0000
commit64ef65e03c21927ecf52c983f0902c4189be5d42 (patch)
tree3eb4581820dd0d6d793d75c5e0a6355a359df0a7
parentAdd basic support for delivery status notifications (DSN) (diff)
downloadvmime-64ef65e03c21927ecf52c983f0902c4189be5d42.tar.gz
vmime-64ef65e03c21927ecf52c983f0902c4189be5d42.zip
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.
-rw-r--r--src/vmime/constants.cpp4
-rw-r--r--src/vmime/constants.hpp4
-rw-r--r--src/vmime/net/dsnAttributes.cpp65
-rw-r--r--src/vmime/net/dsnAttributes.hpp108
-rw-r--r--src/vmime/net/sendmail/sendmailTransport.cpp3
-rw-r--r--src/vmime/net/sendmail/sendmailTransport.hpp4
-rw-r--r--src/vmime/net/smtp/SMTPTransport.cpp23
-rw-r--r--src/vmime/net/smtp/SMTPTransport.hpp16
-rw-r--r--src/vmime/net/transport.cpp10
-rw-r--r--src/vmime/net/transport.hpp23
10 files changed, 208 insertions, 52 deletions
diff --git a/src/vmime/constants.cpp b/src/vmime/constants.cpp
index 6a7ddcb2..445c0121 100644
--- a/src/vmime/constants.cpp
+++ b/src/vmime/constants.cpp
@@ -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";
diff --git a/src/vmime/constants.hpp b/src/vmime/constants.hpp
index d15aea1d..9d253832 100644
--- a/src/vmime/constants.hpp
+++ b/src/vmime/constants.hpp
@@ -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;
diff --git a/src/vmime/net/dsnAttributes.cpp b/src/vmime/net/dsnAttributes.cpp
new file mode 100644
index 00000000..e76faa00
--- /dev/null
+++ b/src/vmime/net/dsnAttributes.cpp
@@ -0,0 +1,65 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2020 Jan Osusky <[email protected]>
+//
+// 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
diff --git a/src/vmime/net/dsnAttributes.hpp b/src/vmime/net/dsnAttributes.hpp
new file mode 100644
index 00000000..debb9940
--- /dev/null
+++ b/src/vmime/net/dsnAttributes.hpp
@@ -0,0 +1,108 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2020 Jan Osusky <[email protected]>
+//
+// 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
diff --git a/src/vmime/net/sendmail/sendmailTransport.cpp b/src/vmime/net/sendmail/sendmailTransport.cpp
index f7817bd7..7010fd85 100644
--- a/src/vmime/net/sendmail/sendmailTransport.cpp
+++ b/src/vmime/net/sendmail/sendmailTransport.cpp
@@ -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
diff --git a/src/vmime/net/sendmail/sendmailTransport.hpp b/src/vmime/net/sendmail/sendmailTransport.hpp
index 467f9c0d..56e11d7c 100644
--- a/src/vmime/net/sendmail/sendmailTransport.hpp
+++ b/src/vmime/net/sendmail/sendmailTransport.hpp
@@ -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;
diff --git a/src/vmime/net/smtp/SMTPTransport.cpp b/src/vmime/net/smtp/SMTPTransport.cpp
index 0af3046a..7ccedd88 100644
--- a/src/vmime/net/smtp/SMTPTransport.cpp
+++ b/src/vmime/net/smtp/SMTPTransport.cpp
@@ -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);
diff --git a/src/vmime/net/smtp/SMTPTransport.hpp b/src/vmime/net/smtp/SMTPTransport.hpp
index 26d86ea1..cd7c712d 100644
--- a/src/vmime/net/smtp/SMTPTransport.hpp
+++ b/src/vmime/net/smtp/SMTPTransport.hpp
@@ -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()
);
diff --git a/src/vmime/net/transport.cpp b/src/vmime/net/transport.cpp
index 218ab7f6..0991302b 100644
--- a/src/vmime/net/transport.cpp
+++ b/src/vmime/net/transport.cpp
@@ -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);
}
diff --git a/src/vmime/net/transport.hpp b/src/vmime/net/transport.hpp
index 089399c8..daa4717f 100644
--- a/src/vmime/net/transport.hpp
+++ b/src/vmime/net/transport.hpp
@@ -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()
);