aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorvincent-richard <[email protected]>2020-09-04 17:14:33 +0000
committervincent-richard <[email protected]>2020-09-04 17:14:33 +0000
commit6c4bd0dda9eb1278b05fbf9a5b8abbc69250e78f (patch)
tree990633cba81b40d12e556719f8495f14d480d1e1 /src
parentFixed unit test for DSN support. (diff)
downloadvmime-6c4bd0dda9eb1278b05fbf9a5b8abbc69250e78f.tar.gz
vmime-6c4bd0dda9eb1278b05fbf9a5b8abbc69250e78f.zip
Check for DSN extension support before using it.
Diffstat (limited to 'src')
-rw-r--r--src/vmime/net/dsnAttributes.cpp6
-rw-r--r--src/vmime/net/dsnAttributes.hpp6
-rw-r--r--src/vmime/net/smtp/SMTPExceptions.cpp53
-rw-r--r--src/vmime/net/smtp/SMTPExceptions.hpp28
-rw-r--r--src/vmime/net/smtp/SMTPTransport.cpp6
5 files changed, 99 insertions, 0 deletions
diff --git a/src/vmime/net/dsnAttributes.cpp b/src/vmime/net/dsnAttributes.cpp
index 122e0c81..dc949b99 100644
--- a/src/vmime/net/dsnAttributes.cpp
+++ b/src/vmime/net/dsnAttributes.cpp
@@ -58,6 +58,12 @@ string dsnAttributes::getEnvelopId() const {
}
+bool dsnAttributes::isEmpty() const {
+
+ return m_notifications.empty() && m_returnFormat.empty() && m_envelopId.empty();
+}
+
+
} // net
} // vmime
diff --git a/src/vmime/net/dsnAttributes.hpp b/src/vmime/net/dsnAttributes.hpp
index 6749c721..945da287 100644
--- a/src/vmime/net/dsnAttributes.hpp
+++ b/src/vmime/net/dsnAttributes.hpp
@@ -90,6 +90,12 @@ public:
*/
string getEnvelopId() const;
+ /** Returns whether the object is empty, and no attribute has been set.
+ *
+ * @return true if object is empty, or false otherwise
+ */
+ bool isEmpty() const;
+
private:
string m_notifications;
diff --git a/src/vmime/net/smtp/SMTPExceptions.cpp b/src/vmime/net/smtp/SMTPExceptions.cpp
index 641632c5..e3b46524 100644
--- a/src/vmime/net/smtp/SMTPExceptions.cpp
+++ b/src/vmime/net/smtp/SMTPExceptions.cpp
@@ -151,6 +151,59 @@ const char* SMTPMessageSizeExceedsCurLimitsException::name() const throw() {
}
+//
+// SMTPExtensionNotSupportedException
+//
+
+SMTPExtensionNotSupportedException::SMTPExtensionNotSupportedException(const string &what, const exception& other)
+ : net_exception(what.empty() ? "A required extension is not supported by the SMTP server." : what, other) {
+
+}
+
+
+SMTPExtensionNotSupportedException::~SMTPExtensionNotSupportedException() throw() {
+
+}
+
+
+exception* SMTPExtensionNotSupportedException::clone() const {
+
+ return new SMTPExtensionNotSupportedException(*this);
+}
+
+
+const char* SMTPExtensionNotSupportedException::name() const throw() {
+
+ return "SMTPExtensionNotSupportedException";
+}
+
+
+//
+// SMTPDSNExtensionNotSupportedException
+//
+
+SMTPDSNExtensionNotSupportedException::SMTPDSNExtensionNotSupportedException(const exception& other)
+ : SMTPExtensionNotSupportedException("RFC-1891 DSN extension is not supported by the SMTP server.", other) {
+
+}
+
+
+SMTPDSNExtensionNotSupportedException::~SMTPDSNExtensionNotSupportedException() throw() {
+
+}
+
+
+exception* SMTPDSNExtensionNotSupportedException::clone() const {
+ return new SMTPDSNExtensionNotSupportedException(*this);
+}
+
+
+const char* SMTPDSNExtensionNotSupportedException::name() const throw() {
+
+ return "SMTPDSNExtensionNotSupportedException";
+}
+
+
} // smtp
} // net
} // vmime
diff --git a/src/vmime/net/smtp/SMTPExceptions.hpp b/src/vmime/net/smtp/SMTPExceptions.hpp
index 70f1e113..488ee2ec 100644
--- a/src/vmime/net/smtp/SMTPExceptions.hpp
+++ b/src/vmime/net/smtp/SMTPExceptions.hpp
@@ -120,6 +120,34 @@ public:
};
+/** SMTP error: a required extension is not supported by the server.
+ */
+class VMIME_EXPORT SMTPExtensionNotSupportedException : public exceptions::net_exception {
+
+public:
+
+ SMTPExtensionNotSupportedException(const string& what, const exception& other = NO_EXCEPTION);
+ ~SMTPExtensionNotSupportedException() throw();
+
+ exception* clone() const;
+ const char* name() const throw();
+};
+
+
+/** SMTP error: RFC-1891 DSN extension is not supported by the server.
+ */
+class VMIME_EXPORT SMTPDSNExtensionNotSupportedException : public SMTPExtensionNotSupportedException {
+
+public:
+
+ SMTPDSNExtensionNotSupportedException(const exception& other = NO_EXCEPTION);
+ ~SMTPDSNExtensionNotSupportedException() throw();
+
+ exception* clone() const;
+ const char* name() const throw();
+};
+
+
} // smtp
} // net
} // vmime
diff --git a/src/vmime/net/smtp/SMTPTransport.cpp b/src/vmime/net/smtp/SMTPTransport.cpp
index f5dd3858..561bd592 100644
--- a/src/vmime/net/smtp/SMTPTransport.cpp
+++ b/src/vmime/net/smtp/SMTPTransport.cpp
@@ -186,6 +186,7 @@ void SMTPTransport::sendEnvelope(
const size_t size,
const dsnAttributes& dsnAttrs
) {
+
// If no recipient/expeditor was found, throw an exception
if (recipients.isEmpty()) {
throw exceptions::no_recipient();
@@ -193,6 +194,11 @@ void SMTPTransport::sendEnvelope(
throw exceptions::no_expeditor();
}
+ // If DSN extension is used, ensure it is supported by the server
+ if (!dsnAttrs.isEmpty() && !m_connection->hasExtension("DSN")) {
+ throw SMTPDSNExtensionNotSupportedException();
+ }
+
const bool needReset = m_needReset;
const bool hasPipelining = m_connection->hasExtension("PIPELINING") &&