From 38f06fcb48ddfc1026747751635aaece73bfe272 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 15:29:19 +0200 Subject: [PATCH 01/14] Added .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4bac168 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +*.so +*.so.* +Makefile +moc_*.cpp From 3b4ec583fa31c79412a9ea5dbc8050a00ddc29f8 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 15:30:08 +0200 Subject: [PATCH 02/14] Removed mimepart.cpp.autosave from the project --- src/SMTPEmail.pro | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SMTPEmail.pro b/src/SMTPEmail.pro index 4abab5f..df601fd 100644 --- a/src/SMTPEmail.pro +++ b/src/SMTPEmail.pro @@ -48,7 +48,6 @@ HEADERS += \ mimebase64encoder.h \ mimeqpencoder.h \ mimeqpformatter.h \ - mimepart.cpp.autosave \ mimebase64formatter.h \ mimecontentformatter.h From 49a43f2370a237d617149248606d6d7924e49069 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 15:40:10 +0200 Subject: [PATCH 03/14] Make test app console --- test/main.cpp | 3 +-- test/test.pro | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 3d3900b..430c185 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -13,7 +12,7 @@ void runTest(QObject *test) { int main(int argc, char *argv[]) { - QApplication a(argc, argv); + QCoreApplication a(argc, argv); runTest(new ConnectionTest()); diff --git a/test/test.pro b/test/test.pro index 499b18e..0641456 100644 --- a/test/test.pro +++ b/test/test.pro @@ -4,7 +4,8 @@ # #------------------------------------------------- -QT += testlib gui +QT += testlib +QT -= gui TARGET = test CONFIG += console From 4e2d1446dda4bee6842d232dc9aab559152f7002 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 15:41:39 +0200 Subject: [PATCH 04/14] Fix memory leak --- test/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/main.cpp b/test/main.cpp index 430c185..7ee90a2 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -7,6 +7,7 @@ bool success = true; void runTest(QObject *test) { int retVal = QTest::qExec(test); + delete test; success &= retVal == 0; } From 8967ae4aad7e0e3624831585d8e35425246f65ad Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 15:47:48 +0200 Subject: [PATCH 05/14] Convert QuotedPrintable class to namespace --- src/quotedprintable.cpp | 4 ++-- src/quotedprintable.h | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/quotedprintable.cpp b/src/quotedprintable.cpp index e7e130c..ab56a36 100644 --- a/src/quotedprintable.cpp +++ b/src/quotedprintable.cpp @@ -18,7 +18,7 @@ #include "quotedprintable.h" -QString& QuotedPrintable::encode(const QByteArray &input) +QString QuotedPrintable::encode(const QByteArray &input) { QString *output = new QString(); @@ -43,7 +43,7 @@ QString& QuotedPrintable::encode(const QByteArray &input) } -QByteArray& QuotedPrintable::decode(const QString &input) +QByteArray QuotedPrintable::decode(const QString &input) { // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F const int hexVal[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}; diff --git a/src/quotedprintable.h b/src/quotedprintable.h index 5a54dc4..7eb855c 100644 --- a/src/quotedprintable.h +++ b/src/quotedprintable.h @@ -19,20 +19,13 @@ #ifndef QUOTEDPRINTABLE_H #define QUOTEDPRINTABLE_H -#include #include +#include #include "smtpmime_global.h" -class SMTP_MIME_EXPORT QuotedPrintable : public QObject -{ - Q_OBJECT -public: - - static QString& encode(const QByteArray &input); - static QByteArray& decode(const QString &input); - -private: - QuotedPrintable(); -}; +namespace QuotedPrintable { + SMTP_MIME_EXPORT QString encode(const QByteArray &input); + SMTP_MIME_EXPORT QByteArray decode(const QString &input); +} #endif // QUOTEDPRINTABLE_H From 8156bc0a9523494e204d162ab1ae830e6f2848f5 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 15:51:58 +0200 Subject: [PATCH 06/14] Fix memory leaks: do not allocate results on heap --- src/quotedprintable.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/quotedprintable.cpp b/src/quotedprintable.cpp index ab56a36..83fd9b6 100644 --- a/src/quotedprintable.cpp +++ b/src/quotedprintable.cpp @@ -20,7 +20,7 @@ QString QuotedPrintable::encode(const QByteArray &input) { - QString *output = new QString(); + QString output; char byte; const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; @@ -30,16 +30,14 @@ QString QuotedPrintable::encode(const QByteArray &input) byte = input[i]; if ((byte == 0x20) || (byte >= 33) && (byte <= 126) && (byte != 61)) { - output->append(byte); + output.append(byte); } else { - output->append('='); - output->append(hex[((byte >> 4) & 0x0F)]); - output->append(hex[(byte & 0x0F)]); + output.append('=').append(hex[((byte >> 4) & 0x0F)]).append(hex[(byte & 0x0F)]); } } - return *output; + return output; } @@ -48,19 +46,19 @@ QByteArray QuotedPrintable::decode(const QString &input) // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F const int hexVal[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}; - QByteArray *output = new QByteArray(); + QByteArray output; for (int i = 0; i < input.length(); ++i) { - if (input.at(i).toAscii() == '=') + if (input.at(i).toLatin1() == '=') { - output->append((hexVal[input.at(++i).toAscii() - '0'] << 4) + hexVal[input.at(++i).toAscii() - '0']); + output.append((hexVal[input.at(++i).toLatin1() - '0'] << 4) + hexVal[input.at(++i).toLatin1() - '0']); } else { - output->append(input.at(i).toAscii()); + output.append(input.at(i).toLatin1()); } } - return *output; + return output; } From 6339318cde6cbcc5cd157a5b503177ccbeb5e425 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 16:10:38 +0200 Subject: [PATCH 07/14] Tests to run can be specified in command line --- test/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 7ee90a2..1a51960 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -5,8 +5,8 @@ bool success = true; -void runTest(QObject *test) { - int retVal = QTest::qExec(test); +static void runTest(QObject *test, int argc, char** argv) { + int retVal = QTest::qExec(test, argc, argv); delete test; success &= retVal == 0; } @@ -15,7 +15,7 @@ int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - runTest(new ConnectionTest()); + runTest(new ConnectionTest(), argc, argv); if (success) qDebug() << "SUCCESS"; From 8a0282b6c1f1c14c81df98a38f5668f70ca6f244 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 16:24:06 +0200 Subject: [PATCH 08/14] Fix -Wlogical-op-parentheses warning --- src/quotedprintable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quotedprintable.cpp b/src/quotedprintable.cpp index 83fd9b6..3b901f4 100644 --- a/src/quotedprintable.cpp +++ b/src/quotedprintable.cpp @@ -29,7 +29,7 @@ QString QuotedPrintable::encode(const QByteArray &input) { byte = input[i]; - if ((byte == 0x20) || (byte >= 33) && (byte <= 126) && (byte != 61)) { + if ((byte == 0x20) || ((byte >= 33) && (byte <= 126) && (byte != 61))) { output.append(byte); } else { From 7b42551a20082cc8fb25bfd82daa40470d21240e Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 16:25:44 +0200 Subject: [PATCH 09/14] Fix -Wsequence-point warning --- src/quotedprintable.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/quotedprintable.cpp b/src/quotedprintable.cpp index 3b901f4..34d170c 100644 --- a/src/quotedprintable.cpp +++ b/src/quotedprintable.cpp @@ -52,7 +52,8 @@ QByteArray QuotedPrintable::decode(const QString &input) { if (input.at(i).toLatin1() == '=') { - output.append((hexVal[input.at(++i).toLatin1() - '0'] << 4) + hexVal[input.at(++i).toLatin1() - '0']); + output.append((hexVal[input.at(i+1).toLatin1() - '0'] << 4) + hexVal[input.at(i+2).toLatin1() - '0']); + i += 2; } else { From 968cad3328d394075fef28492bf94fb8d8388d13 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 16:43:24 +0200 Subject: [PATCH 10/14] Fix crash in decode() on malformed input --- src/quotedprintable.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/quotedprintable.cpp b/src/quotedprintable.cpp index 34d170c..fceaca5 100644 --- a/src/quotedprintable.cpp +++ b/src/quotedprintable.cpp @@ -48,7 +48,9 @@ QByteArray QuotedPrintable::decode(const QString &input) QByteArray output; - for (int i = 0; i < input.length(); ++i) + int len = input.length(); + int i; + for (i = 0; i < len-2; ++i) { if (input.at(i).toLatin1() == '=') { @@ -61,5 +63,10 @@ QByteArray QuotedPrintable::decode(const QString &input) } } + while (i Date: Sun, 10 Feb 2013 16:50:09 +0200 Subject: [PATCH 11/14] Do not derive EmailAddress from QObject --- src/emailaddress.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/emailaddress.h b/src/emailaddress.h index 44f1a2e..e3eb6e5 100644 --- a/src/emailaddress.h +++ b/src/emailaddress.h @@ -20,11 +20,10 @@ #define EMAILADDRESS_H #include "smtpmime_global.h" -#include +#include -class SMTP_MIME_EXPORT EmailAddress : public QObject +class SMTP_MIME_EXPORT EmailAddress { - Q_OBJECT public: /* [1] Constructors and Destructors */ From e792db9fa8fa2d43e4bdc779f8ad711533961d01 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 17:06:52 +0200 Subject: [PATCH 12/14] Do not derive MimePart from QObject --- src/mimeattachment.h | 2 -- src/mimefile.h | 4 ++-- src/mimehtml.h | 1 - src/mimemultipart.cpp | 1 + src/mimemultipart.h | 2 -- src/mimepart.h | 11 ++++++----- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/mimeattachment.h b/src/mimeattachment.h index 90a5780..8b8e4cd 100644 --- a/src/mimeattachment.h +++ b/src/mimeattachment.h @@ -20,14 +20,12 @@ #define MIMEATTACHMENT_H -#include #include "smtpmime_global.h" #include "mimepart.h" #include "mimefile.h" class SMTP_MIME_EXPORT MimeAttachment : public MimeFile { - Q_OBJECT public: /* [1] Constructors and Destructors */ diff --git a/src/mimefile.h b/src/mimefile.h index 8540c77..0ec74f2 100644 --- a/src/mimefile.h +++ b/src/mimefile.h @@ -19,13 +19,13 @@ #ifndef MIMEFILE_H #define MIMEFILE_H -#include #include "mimepart.h" #include "smtpmime_global.h" +class QFile; + class SMTP_MIME_EXPORT MimeFile : public MimePart { - Q_OBJECT public: /* [1] Constructors and Destructors */ diff --git a/src/mimehtml.h b/src/mimehtml.h index 5d59bc4..b8b7098 100644 --- a/src/mimehtml.h +++ b/src/mimehtml.h @@ -24,7 +24,6 @@ class SMTP_MIME_EXPORT MimeHtml : public MimeText { - Q_OBJECT public: /* [1] Constructors and Destructors */ diff --git a/src/mimemultipart.cpp b/src/mimemultipart.cpp index b3a70d1..8f14144 100644 --- a/src/mimemultipart.cpp +++ b/src/mimemultipart.cpp @@ -17,6 +17,7 @@ */ #include "mimemultipart.h" +#include #include #include diff --git a/src/mimemultipart.h b/src/mimemultipart.h index 6355347..f4770c4 100644 --- a/src/mimemultipart.h +++ b/src/mimemultipart.h @@ -20,13 +20,11 @@ #define MIMEMULTIPART_H #include -#include #include "smtpmime_global.h" #include "mimepart.h" class SMTP_MIME_EXPORT MimeMultiPart : public MimePart { - Q_OBJECT public: /* [0] Enums */ diff --git a/src/mimepart.h b/src/mimepart.h index 49bbb19..bb3d65a 100644 --- a/src/mimepart.h +++ b/src/mimepart.h @@ -19,13 +19,14 @@ #ifndef MIMEPART_H #define MIMEPART_H -#include -#include #include "smtpmime_global.h" +#include +#include -class SMTP_MIME_EXPORT MimePart : public QObject +class QIODevice; + +class SMTP_MIME_EXPORT MimePart { - Q_OBJECT public: /* [0] Enumerations */ @@ -43,7 +44,7 @@ public: /* [1] Constructors and Destructors */ MimePart(); - ~MimePart(); + virtual ~MimePart(); /* [1] --- */ From 22f768ca99578809a314f3f4e7978983959378f8 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 17:10:30 +0200 Subject: [PATCH 13/14] Fix -Wunused-parameter warning --- src/smtpclient.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/smtpclient.cpp b/src/smtpclient.cpp index cbbcd5f..39cd786 100644 --- a/src/smtpclient.cpp +++ b/src/smtpclient.cpp @@ -617,6 +617,8 @@ void SmtpClient::socketStateChanged(QAbstractSocket::SocketState state) { void SmtpClient::socketError(QAbstractSocket::SocketError socketError) { #ifndef QT_NO_DEBUG qDebug() << "SocketError:" << socketError << socket->error(); +#else + Q_UNUSED(socketError); #endif emit error(SocketError); } From 40d69fc5923283e09df898387f0544abb2bdbdcf Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 10 Feb 2013 22:18:41 +0200 Subject: [PATCH 14/14] Make sure to stay within hexVal bounds --- src/quotedprintable.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/quotedprintable.cpp b/src/quotedprintable.cpp index fceaca5..1d83ddb 100644 --- a/src/quotedprintable.cpp +++ b/src/quotedprintable.cpp @@ -23,7 +23,7 @@ QString QuotedPrintable::encode(const QByteArray &input) QString output; char byte; - const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; for (int i = 0; i < input.length() ; ++i) { @@ -43,8 +43,8 @@ QString QuotedPrintable::encode(const QByteArray &input) QByteArray QuotedPrintable::decode(const QString &input) { - // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F - const int hexVal[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}; + // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F + static const int hexVal[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}; QByteArray output; @@ -54,7 +54,15 @@ QByteArray QuotedPrintable::decode(const QString &input) { if (input.at(i).toLatin1() == '=') { - output.append((hexVal[input.at(i+1).toLatin1() - '0'] << 4) + hexVal[input.at(i+2).toLatin1() - '0']); + int x = input.at(i+1).toLatin1() - '0'; + int y = input.at(i+2).toLatin1() - '0'; + if (x >= 0 && y >= 0 && x < 23 && y < 23) { + output.append(char((hexVal[x] << 4) + hexVal[y])); + } + else { + output.append('=').append(char(x + '0')).append(char(y + '0')); + } + i += 2; } else