Merge pull request #10 from sjinks/dev

Fixed some bugs and memory leaks
This commit is contained in:
Tőkés Attila 2013-02-11 12:29:50 -08:00
commit 208b072ad3
14 changed files with 62 additions and 52 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.o
*.so
*.so.*
Makefile
moc_*.cpp

View File

@ -48,7 +48,6 @@ HEADERS += \
mimebase64encoder.h \ mimebase64encoder.h \
mimeqpencoder.h \ mimeqpencoder.h \
mimeqpformatter.h \ mimeqpformatter.h \
mimepart.cpp.autosave \
mimebase64formatter.h \ mimebase64formatter.h \
mimecontentformatter.h mimecontentformatter.h

View File

@ -20,11 +20,10 @@
#define EMAILADDRESS_H #define EMAILADDRESS_H
#include "smtpmime_global.h" #include "smtpmime_global.h"
#include <QObject> #include <QString>
class SMTP_MIME_EXPORT EmailAddress : public QObject class SMTP_MIME_EXPORT EmailAddress
{ {
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */

View File

@ -20,14 +20,12 @@
#define MIMEATTACHMENT_H #define MIMEATTACHMENT_H
#include <QFile>
#include "smtpmime_global.h" #include "smtpmime_global.h"
#include "mimepart.h" #include "mimepart.h"
#include "mimefile.h" #include "mimefile.h"
class SMTP_MIME_EXPORT MimeAttachment : public MimeFile class SMTP_MIME_EXPORT MimeAttachment : public MimeFile
{ {
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */

View File

@ -19,13 +19,13 @@
#ifndef MIMEFILE_H #ifndef MIMEFILE_H
#define MIMEFILE_H #define MIMEFILE_H
#include <QFile>
#include "mimepart.h" #include "mimepart.h"
#include "smtpmime_global.h" #include "smtpmime_global.h"
class QFile;
class SMTP_MIME_EXPORT MimeFile : public MimePart class SMTP_MIME_EXPORT MimeFile : public MimePart
{ {
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */

View File

@ -24,7 +24,6 @@
class SMTP_MIME_EXPORT MimeHtml : public MimeText class SMTP_MIME_EXPORT MimeHtml : public MimeText
{ {
Q_OBJECT
public: public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */

View File

@ -17,6 +17,7 @@
*/ */
#include "mimemultipart.h" #include "mimemultipart.h"
#include <QIODevice>
#include <QTime> #include <QTime>
#include <QCryptographicHash> #include <QCryptographicHash>

View File

@ -20,13 +20,11 @@
#define MIMEMULTIPART_H #define MIMEMULTIPART_H
#include <QList> #include <QList>
#include <QTextStream>
#include "smtpmime_global.h" #include "smtpmime_global.h"
#include "mimepart.h" #include "mimepart.h"
class SMTP_MIME_EXPORT MimeMultiPart : public MimePart class SMTP_MIME_EXPORT MimeMultiPart : public MimePart
{ {
Q_OBJECT
public: public:
/* [0] Enums */ /* [0] Enums */

View File

@ -19,13 +19,14 @@
#ifndef MIMEPART_H #ifndef MIMEPART_H
#define MIMEPART_H #define MIMEPART_H
#include <QObject>
#include <QTextStream>
#include "smtpmime_global.h" #include "smtpmime_global.h"
#include <QByteArray>
#include <QString>
class SMTP_MIME_EXPORT MimePart : public QObject class QIODevice;
class SMTP_MIME_EXPORT MimePart
{ {
Q_OBJECT
public: public:
/* [0] Enumerations */ /* [0] Enumerations */
@ -43,7 +44,7 @@ public:
/* [1] Constructors and Destructors */ /* [1] Constructors and Destructors */
MimePart(); MimePart();
~MimePart(); virtual ~MimePart();
/* [1] --- */ /* [1] --- */

View File

@ -18,49 +18,63 @@
#include "quotedprintable.h" #include "quotedprintable.h"
QString& QuotedPrintable::encode(const QByteArray &input) QString QuotedPrintable::encode(const QByteArray &input)
{ {
QString *output = new QString(); QString output;
char byte; 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) for (int i = 0; i < input.length() ; ++i)
{ {
byte = input[i]; byte = input[i];
if ((byte == 0x20) || (byte >= 33) && (byte <= 126) && (byte != 61)) { if ((byte == 0x20) || ((byte >= 33) && (byte <= 126) && (byte != 61))) {
output->append(byte); output.append(byte);
} }
else { else {
output->append('='); output.append('=').append(hex[((byte >> 4) & 0x0F)]).append(hex[(byte & 0x0F)]);
output->append(hex[((byte >> 4) & 0x0F)]);
output->append(hex[(byte & 0x0F)]);
} }
} }
return *output; return output;
} }
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 // 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}; 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 = new QByteArray(); 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).toAscii() == '=') if (input.at(i).toLatin1() == '=')
{ {
output->append((hexVal[input.at(++i).toAscii() - '0'] << 4) + hexVal[input.at(++i).toAscii() - '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 else
{ {
output->append(input.at(i).toAscii()); output.append(input.at(i).toLatin1());
} }
} }
return *output; while (i<len) {
output.append(input.at(i).toLatin1());
++i;
}
return output;
} }

View File

@ -19,20 +19,13 @@
#ifndef QUOTEDPRINTABLE_H #ifndef QUOTEDPRINTABLE_H
#define QUOTEDPRINTABLE_H #define QUOTEDPRINTABLE_H
#include <QObject>
#include <QByteArray> #include <QByteArray>
#include <QString>
#include "smtpmime_global.h" #include "smtpmime_global.h"
class SMTP_MIME_EXPORT QuotedPrintable : public QObject namespace QuotedPrintable {
{ SMTP_MIME_EXPORT QString encode(const QByteArray &input);
Q_OBJECT SMTP_MIME_EXPORT QByteArray decode(const QString &input);
public: }
static QString& encode(const QByteArray &input);
static QByteArray& decode(const QString &input);
private:
QuotedPrintable();
};
#endif // QUOTEDPRINTABLE_H #endif // QUOTEDPRINTABLE_H

View File

@ -617,6 +617,8 @@ void SmtpClient::socketStateChanged(QAbstractSocket::SocketState state) {
void SmtpClient::socketError(QAbstractSocket::SocketError socketError) { void SmtpClient::socketError(QAbstractSocket::SocketError socketError) {
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
qDebug() << "SocketError:" << socketError << socket->error(); qDebug() << "SocketError:" << socketError << socket->error();
#else
Q_UNUSED(socketError);
#endif #endif
emit error(SocketError); emit error(SocketError);
} }

View File

@ -1,4 +1,3 @@
#include <QtGui/QApplication>
#include <QCoreApplication> #include <QCoreApplication>
#include <QtTest/QTest> #include <QtTest/QTest>
#include <QDebug> #include <QDebug>
@ -6,16 +5,17 @@
bool success = true; bool success = true;
void runTest(QObject *test) { static void runTest(QObject *test, int argc, char** argv) {
int retVal = QTest::qExec(test); int retVal = QTest::qExec(test, argc, argv);
delete test;
success &= retVal == 0; success &= retVal == 0;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QCoreApplication a(argc, argv);
runTest(new ConnectionTest()); runTest(new ConnectionTest(), argc, argv);
if (success) if (success)
qDebug() << "SUCCESS"; qDebug() << "SUCCESS";

View File

@ -4,7 +4,8 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += testlib gui QT += testlib
QT -= gui
TARGET = test TARGET = test
CONFIG += console CONFIG += console