Skip to content

Commit

Permalink
Check for DSN extension support before using it.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-richard committed Sep 4, 2020
1 parent 9205c9d commit 6c4bd0d
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/vmime/net/dsnAttributes.cpp
Expand Up @@ -58,6 +58,12 @@ string dsnAttributes::getEnvelopId() const {
}


bool dsnAttributes::isEmpty() const {

return m_notifications.empty() && m_returnFormat.empty() && m_envelopId.empty();
}


} // net
} // vmime

Expand Down
6 changes: 6 additions & 0 deletions src/vmime/net/dsnAttributes.hpp
Expand Up @@ -90,6 +90,12 @@ class VMIME_EXPORT dsnAttributes : public object {
*/
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;
Expand Down
53 changes: 53 additions & 0 deletions src/vmime/net/smtp/SMTPExceptions.cpp
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/vmime/net/smtp/SMTPExceptions.hpp
Expand Up @@ -120,6 +120,34 @@ class VMIME_EXPORT SMTPMessageSizeExceedsCurLimitsException : public exceptions:
};


/** 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
Expand Down
6 changes: 6 additions & 0 deletions src/vmime/net/smtp/SMTPTransport.cpp
Expand Up @@ -186,13 +186,19 @@ 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();
} else if (expeditor.isEmpty()) {
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") &&
Expand Down

0 comments on commit 6c4bd0d

Please sign in to comment.