Check for DSN extension support before using it.

This commit is contained in:
vincent-richard 2020-09-04 19:14:33 +02:00
parent 9205c9d0ab
commit 6c4bd0dda9
5 changed files with 99 additions and 0 deletions

View File

@ -58,6 +58,12 @@ string dsnAttributes::getEnvelopId() const {
}
bool dsnAttributes::isEmpty() const {
return m_notifications.empty() && m_returnFormat.empty() && m_envelopId.empty();
}
} // net
} // vmime

View File

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

View File

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

View File

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

View File

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