From c12f70b721a80dfbbfd4feb5c0f17ddef93d5a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20T=C5=91k=C3=A9s?= Date: Wed, 3 Jun 2015 23:27:54 +0300 Subject: [PATCH 1/4] Fix memory leak --- src/smtpclient.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/smtpclient.cpp b/src/smtpclient.cpp index aaa5909..e7876c8 100644 --- a/src/smtpclient.cpp +++ b/src/smtpclient.cpp @@ -29,7 +29,8 @@ SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connection authMethod(AuthPlain), connectionTimeout(5000), responseTimeout(5000), - sendMessageTimeout(60000) + sendMessageTimeout(60000), + socket(NULL) { setConnectionType(connectionType); @@ -44,7 +45,10 @@ SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connection this, SLOT(socketReadyRead())); } -SmtpClient::~SmtpClient() {} +SmtpClient::~SmtpClient() { + if (socket) + delete socket; +} /* [1] --- */ @@ -80,6 +84,9 @@ void SmtpClient::setConnectionType(ConnectionType ct) { this->connectionType = ct; + if (socket) + delete socket; + switch (connectionType) { case TcpConnection: From 9afc3499429b4754ce20cb7a47d9fac6bf37a8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20T=C5=91k=C3=A9s?= Date: Sat, 5 Sep 2015 18:22:58 +0300 Subject: [PATCH 2/4] Fix typo in default host. --- src/smtpclient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/smtpclient.h b/src/smtpclient.h index ee83884..f734aad 100644 --- a/src/smtpclient.h +++ b/src/smtpclient.h @@ -60,7 +60,7 @@ public: /* [1] Constructors and Destructors */ - SmtpClient(const QString & host = "locahost", int port = 25, ConnectionType ct = TcpConnection); + SmtpClient(const QString & host = "localhost", int port = 25, ConnectionType ct = TcpConnection); ~SmtpClient(); From 6de3493c92cdf8a90943c4e5e32c60d17c5b6192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Urs=20F=C3=A4ssler?= Date: Mon, 26 Oct 2015 16:31:51 +0100 Subject: [PATCH 3/4] cleanup compiler errors/warnings --- SMTPEmail.pro | 2 -- src/smtpclient.cpp | 14 +++++++------- src/smtpclient.h | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/SMTPEmail.pro b/SMTPEmail.pro index 4fc4400..02a7d8e 100644 --- a/SMTPEmail.pro +++ b/SMTPEmail.pro @@ -16,8 +16,6 @@ TEMPLATE = lib DEFINES += SMTP_BUILD win32:CONFIG += dll -QMAKE_CXXFLAGS += -fPIC - SOURCES += \ src/emailaddress.cpp \ src/mimeattachment.cpp \ diff --git a/src/smtpclient.cpp b/src/smtpclient.cpp index e7876c8..7370a78 100644 --- a/src/smtpclient.cpp +++ b/src/smtpclient.cpp @@ -25,12 +25,12 @@ /* [1] Constructors and destructors */ SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connectionType) : + socket(NULL), name("localhost"), authMethod(AuthPlain), connectionTimeout(5000), responseTimeout(5000), - sendMessageTimeout(60000), - socket(NULL) + sendMessageTimeout(60000) { setConnectionType(connectionType); @@ -332,7 +332,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod } } } - catch (ResponseTimeoutException e) + catch (ResponseTimeoutException) { // Responce Timeout exceeded emit smtpError(AuthenticationFailedError); @@ -428,7 +428,7 @@ void SmtpClient::quit() /* [4] Protected methods */ -void SmtpClient::waitForResponse() throw (ResponseTimeoutException) +void SmtpClient::waitForResponse() { do { if (!socket->waitForReadyRead(responseTimeout)) @@ -455,7 +455,7 @@ void SmtpClient::waitForResponse() throw (ResponseTimeoutException) } while (true); } -void SmtpClient::sendMessage(const QString &text) throw (SendMessageTimeoutException) +void SmtpClient::sendMessage(const QString &text) { socket->write(text.toUtf8() + "\r\n"); if (! socket->waitForBytesWritten(sendMessageTimeout)) @@ -470,11 +470,11 @@ void SmtpClient::sendMessage(const QString &text) throw (SendMessageTimeoutExcep /* [5] Slots for the socket's signals */ -void SmtpClient::socketStateChanged(QAbstractSocket::SocketState state) +void SmtpClient::socketStateChanged(QAbstractSocket::SocketState /*state*/) { } -void SmtpClient::socketError(QAbstractSocket::SocketError socketError) +void SmtpClient::socketError(QAbstractSocket::SocketError /*socketError*/) { } diff --git a/src/smtpclient.h b/src/smtpclient.h index f734aad..26afe81 100644 --- a/src/smtpclient.h +++ b/src/smtpclient.h @@ -154,9 +154,9 @@ protected: /* [5] Protected methods */ - void waitForResponse() throw (ResponseTimeoutException); + void waitForResponse(); - void sendMessage(const QString &text) throw (SendMessageTimeoutException); + void sendMessage(const QString &text); /* [5] --- */ From c2a734791a07c78ee4d2583989141f11c5a8b83c Mon Sep 17 00:00:00 2001 From: Cedric HT Date: Wed, 13 Jan 2016 15:31:25 +0100 Subject: [PATCH 4/4] Added Reply-To support --- src/mimemessage.cpp | 37 ++++++++++++++++++++++++++++++++++--- src/mimemessage.h | 5 ++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/mimemessage.cpp b/src/mimemessage.cpp index 0c4ebc2..cb2050e 100644 --- a/src/mimemessage.cpp +++ b/src/mimemessage.cpp @@ -24,11 +24,12 @@ /* [1] Constructors and Destructors */ MimeMessage::MimeMessage(bool createAutoMimeContent) : + replyTo(Q_NULLPTR), hEncoding(MimePart::_8Bit) { if (createAutoMimeContent) this->content = new MimeMultiPart(); - + autoMimeContentCreated = createAutoMimeContent; } @@ -58,6 +59,10 @@ void MimeMessage::setContent(MimePart *content) { this->content = content; } +void MimeMessage::setReplyTo(EmailAddress* rto) { + replyTo = rto; +} + void MimeMessage::setSender(EmailAddress* e) { this->sender = e; @@ -127,6 +132,10 @@ const QList & MimeMessage::getRecipients(RecipientType type) cons } } +const EmailAddress* MimeMessage::getReplyTo() const { + return replyTo; +} + const QString & MimeMessage::getSubject() const { return subject; @@ -175,7 +184,7 @@ QString MimeMessage::toString() /* ---------------------------------- */ - /* ------- Recipients / To ---------- */ + /* ------- Recipients / To ---------- */ mime += "To:"; QList::iterator it; int i; for (i = 0, it = recipientsTo.begin(); it != recipientsTo.end(); ++it, ++i) @@ -245,9 +254,31 @@ QString MimeMessage::toString() default: mime += subject; } + mime += "\r\n"; + /* ---------------------------------- */ + + /* ---------- Reply-To -------------- */ + if (replyTo) { + mime += "Reply-To: "; + if (replyTo->getName() != "") + { + switch (hEncoding) + { + case MimePart::Base64: + mime += " =?utf-8?B?" + QByteArray().append(replyTo->getName()).toBase64() + "?="; + break; + case MimePart::QuotedPrintable: + mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(replyTo->getName())).replace(' ', "_").replace(':',"=3A") + "?="; + break; + default: + mime += " " + replyTo->getName(); + } + } + mime += " <" + replyTo->getAddress() + ">\r\n"; + } + /* ---------------------------------- */ - mime += "\r\n"; mime += "MIME-Version: 1.0\r\n"; mime += content->toString(); diff --git a/src/mimemessage.h b/src/mimemessage.h index 18b4ec3..1a12cd3 100644 --- a/src/mimemessage.h +++ b/src/mimemessage.h @@ -53,6 +53,7 @@ public: void addBcc(EmailAddress* rcpt); void setSubject(const QString & subject); void addPart(MimePart* part); + void setReplyTo(EmailAddress* rto); void setHeaderEncoding(MimePart::Encoding); @@ -60,6 +61,7 @@ public: const QList & getRecipients(RecipientType type = To) const; const QString & getSubject() const; const QList & getParts() const; + const EmailAddress* getReplyTo() const; MimePart& getContent(); void setContent(MimePart *content); @@ -77,11 +79,12 @@ protected: /* [4] Protected members */ EmailAddress* sender; + EmailAddress* replyTo; QList recipientsTo, recipientsCc, recipientsBcc; QString subject; MimePart *content; bool autoMimeContentCreated; - + MimePart::Encoding hEncoding; /* [4] --- */