Small fixes.

This commit is contained in:
Attila Tőkés 2014-11-01 22:50:37 +02:00
parent f8db82bae5
commit 6877ac8148
9 changed files with 42 additions and 31 deletions

View File

@ -31,7 +31,6 @@ SOURCES += \
src/quotedprintable.cpp \ src/quotedprintable.cpp \
src/mimemultipart.cpp \ src/mimemultipart.cpp \
src/mimecontentformatter.cpp \ src/mimecontentformatter.cpp \
demos/demo1.cpp
HEADERS += \ HEADERS += \
src/emailaddress.h \ src/emailaddress.h \

View File

@ -17,17 +17,20 @@ int main(int argc, char *argv[])
// We need to set the username (your email address) and password // We need to set the username (your email address) and password
// for smtp authentification. // for smtp authentification.
smtp.setUser("your_email_address@gmail.com"); smtp.setUser("your_email_address@host.com");
smtp.setPassword("your_password"); smtp.setPassword("your_password");
// Now we create a MimeMessage object. This is the email. // Now we create a MimeMessage object. This is the email.
MimeMessage message; MimeMessage message;
message.setSender(new EmailAddress("your_email_address@gmail.com", "Your Name")); EmailAddress sender("your_email_address@host.com", "Your Name");
message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); message.setSender(&sender);
message.setSubject("SmtpClient for Qt - Demo");
EmailAddress to("recipient@host.com", "Recipient's Name");
message.addRecipient(&to);
message.setSubject("SmtpClient for Qt - Demo");
// Now add some text to the email. // Now add some text to the email.
// First we create a MimeText object. // First we create a MimeText object.
@ -40,7 +43,6 @@ int main(int argc, char *argv[])
message.addPart(&text); message.addPart(&text);
// Now we can send the mail // Now we can send the mail
if (!smtp.connectToHost()) { if (!smtp.connectToHost()) {

View File

@ -26,15 +26,19 @@ int main(int argc, char *argv[])
SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
smtp.setUser("your_email@gmail.com"); smtp.setUser("your_email@host.com");
smtp.setPassword("your_password"); smtp.setPassword("your_password");
// Create a MimeMessage // Create a MimeMessage
MimeMessage message; MimeMessage message;
message.setSender(new EmailAddress("your_email_address@gmail.com", "Your Name")); EmailAddress sender("your_email_address@host.com", "Your Name");
message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); message.setSender(&sender);
EmailAddress to("recipient@host.com", "Recipient's Name");
message.addRecipient(&to);
message.setSubject("SmtpClient for Qt - Demo"); message.setSubject("SmtpClient for Qt - Demo");
// Add some text // Add some text
@ -52,7 +56,8 @@ int main(int argc, char *argv[])
message.addPart(&attachment); message.addPart(&attachment);
// Add an another attachment // Add an another attachment
message.addPart(new MimeAttachment(new QFile("document.pdf"))); MimeAttachment document(new QFile("document.pdf"));
message.addPart(&document);
// Now we can send the mail // Now we can send the mail

View File

@ -26,15 +26,19 @@ int main(int argc, char *argv[])
SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
smtp.setUser("your_email@gmail.com"); smtp.setUser("your_email@host.com");
smtp.setPassword("your_password"); smtp.setPassword("your_password");
// Create a MimeMessage // Create a MimeMessage
MimeMessage message; MimeMessage message;
message.setSender(new EmailAddress("your_email@gmail.com", "Your Name")); EmailAddress sender("your_email_address@host.com", "Your Name");
message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); message.setSender(&sender);
EmailAddress to("recipient@host.com", "Recipient's Name");
message.addRecipient(&to);
message.setSubject("SmtpClient for Qt - Example 3 - Html email with images"); message.setSubject("SmtpClient for Qt - Example 3 - Html email with images");
// Now we need to create a MimeHtml object for HTML content // Now we need to create a MimeHtml object for HTML content

View File

@ -28,6 +28,7 @@ MimeFile::MimeFile(QFile *file)
this->cName = QFileInfo(*file).fileName(); this->cName = QFileInfo(*file).fileName();
this->cEncoding = Base64; this->cEncoding = Base64;
} }
MimeFile::MimeFile(const QByteArray& stream, const QString& fileName) MimeFile::MimeFile(const QByteArray& stream, const QString& fileName)
{ {
this->cEncoding = Base64; this->cEncoding = Base64;

View File

@ -18,9 +18,9 @@
#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'}; const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
@ -31,39 +31,39 @@ QString& QuotedPrintable::encode(const QByteArray &input)
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('=');
output->append(hex[((byte >> 4) & 0x0F)]); output.append(hex[((byte >> 4) & 0x0F)]);
output->append(hex[(byte & 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}; 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) for (int i = 0; i < input.length(); ++i)
{ {
if (input.at(i).toLatin1() == '=') if (input.at(i).toLatin1() == '=')
{ {
output->append((hexVal[input.at(i + 1).toLatin1() - '0'] << 4) + hexVal[input.at(i + 2).toLatin1() - '0']); output.append((hexVal[input.at(i + 1).toLatin1() - '0'] << 4) + hexVal[input.at(i + 2).toLatin1() - '0']);
i += 2; i += 2;
} }
else else
{ {
output->append(input.at(i).toLatin1()); output.append(input.at(i).toLatin1());
} }
} }
return *output; return output;
} }

View File

@ -29,8 +29,8 @@ class SMTP_EXPORT QuotedPrintable : public QObject
Q_OBJECT Q_OBJECT
public: public:
static QString& encode(const QByteArray &input); static QString encode(const QByteArray &input);
static QByteArray& decode(const QString &input); static QByteArray decode(const QString &input);
private: private:
QuotedPrintable(); QuotedPrintable();

View File

@ -66,7 +66,7 @@ void SmtpClient::setAuthMethod(AuthMethod method)
this->authMethod = method; this->authMethod = method;
} }
void SmtpClient::setHost(QString &host) void SmtpClient::setHost(const QString &host)
{ {
this->host = host; this->host = host;
} }

View File

@ -70,7 +70,7 @@ public:
/* [2] Getters and Setters */ /* [2] Getters and Setters */
const QString& getHost() const; const QString& getHost() const;
void setHost(QString &host); void setHost(const QString &host);
int getPort() const; int getPort() const;
void setPort(int port); void setPort(int port);
@ -82,7 +82,7 @@ public:
void setConnectionType(ConnectionType ct); void setConnectionType(ConnectionType ct);
const QString & getUser() const; const QString & getUser() const;
void setUser(const QString &host); void setUser(const QString &user);
const QString & getPassword() const; const QString & getPassword() const;
void setPassword(const QString &password); void setPassword(const QString &password);
@ -175,7 +175,7 @@ signals:
/* [7] Signals */ /* [7] Signals */
void smtpError(SmtpError e); void smtpError(SmtpClient::SmtpError e);
/* [7] --- */ /* [7] --- */