diff --git a/SMTPEmail.pro b/SMTPEmail.pro index 9c3453a..4fc4400 100644 --- a/SMTPEmail.pro +++ b/SMTPEmail.pro @@ -31,7 +31,6 @@ SOURCES += \ src/quotedprintable.cpp \ src/mimemultipart.cpp \ src/mimecontentformatter.cpp \ - demos/demo1.cpp HEADERS += \ src/emailaddress.h \ diff --git a/demos/demo1/demo1.cpp b/demos/demo1/demo1.cpp index 5531337..752c722 100644 --- a/demos/demo1/demo1.cpp +++ b/demos/demo1/demo1.cpp @@ -17,17 +17,20 @@ int main(int argc, char *argv[]) // We need to set the username (your email address) and password // for smtp authentification. - smtp.setUser("your_email_address@gmail.com"); + smtp.setUser("your_email_address@host.com"); smtp.setPassword("your_password"); // Now we create a MimeMessage object. This is the email. MimeMessage message; - message.setSender(new EmailAddress("your_email_address@gmail.com", "Your Name")); - message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); - message.setSubject("SmtpClient for Qt - Demo"); + EmailAddress sender("your_email_address@host.com", "Your Name"); + message.setSender(&sender); + EmailAddress to("recipient@host.com", "Recipient's Name"); + message.addRecipient(&to); + + message.setSubject("SmtpClient for Qt - Demo"); // Now add some text to the email. // First we create a MimeText object. @@ -40,7 +43,6 @@ int main(int argc, char *argv[]) message.addPart(&text); - // Now we can send the mail if (!smtp.connectToHost()) { diff --git a/demos/demo3/demo3.cpp b/demos/demo3/demo3.cpp index 0d3247a..ec93ad0 100644 --- a/demos/demo3/demo3.cpp +++ b/demos/demo3/demo3.cpp @@ -26,15 +26,19 @@ int main(int argc, char *argv[]) SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); - smtp.setUser("your_email@gmail.com"); + smtp.setUser("your_email@host.com"); smtp.setPassword("your_password"); // Create a MimeMessage MimeMessage message; - message.setSender(new EmailAddress("your_email_address@gmail.com", "Your Name")); - message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); + EmailAddress sender("your_email_address@host.com", "Your Name"); + message.setSender(&sender); + + EmailAddress to("recipient@host.com", "Recipient's Name"); + message.addRecipient(&to); + message.setSubject("SmtpClient for Qt - Demo"); // Add some text @@ -52,7 +56,8 @@ int main(int argc, char *argv[]) message.addPart(&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 diff --git a/demos/demo4/demo4.cpp b/demos/demo4/demo4.cpp index 92b1545..463d91a 100644 --- a/demos/demo4/demo4.cpp +++ b/demos/demo4/demo4.cpp @@ -26,15 +26,19 @@ int main(int argc, char *argv[]) SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection); - smtp.setUser("your_email@gmail.com"); + smtp.setUser("your_email@host.com"); smtp.setPassword("your_password"); // Create a MimeMessage MimeMessage message; - message.setSender(new EmailAddress("your_email@gmail.com", "Your Name")); - message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name")); + EmailAddress sender("your_email_address@host.com", "Your 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"); // Now we need to create a MimeHtml object for HTML content diff --git a/src/mimefile.cpp b/src/mimefile.cpp index 4991697..c6f313a 100644 --- a/src/mimefile.cpp +++ b/src/mimefile.cpp @@ -28,6 +28,7 @@ MimeFile::MimeFile(QFile *file) this->cName = QFileInfo(*file).fileName(); this->cEncoding = Base64; } + MimeFile::MimeFile(const QByteArray& stream, const QString& fileName) { this->cEncoding = Base64; diff --git a/src/quotedprintable.cpp b/src/quotedprintable.cpp index dddd180..aa3eda6 100644 --- a/src/quotedprintable.cpp +++ b/src/quotedprintable.cpp @@ -18,9 +18,9 @@ #include "quotedprintable.h" -QString& QuotedPrintable::encode(const QByteArray &input) +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'}; @@ -31,39 +31,39 @@ QString& QuotedPrintable::encode(const QByteArray &input) 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('='); + 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 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).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; } else { - output->append(input.at(i).toLatin1()); + output.append(input.at(i).toLatin1()); } } - return *output; + return output; } diff --git a/src/quotedprintable.h b/src/quotedprintable.h index 020b7d2..03d3acf 100644 --- a/src/quotedprintable.h +++ b/src/quotedprintable.h @@ -29,8 +29,8 @@ class SMTP_EXPORT QuotedPrintable : public QObject Q_OBJECT public: - static QString& encode(const QByteArray &input); - static QByteArray& decode(const QString &input); + static QString encode(const QByteArray &input); + static QByteArray decode(const QString &input); private: QuotedPrintable(); diff --git a/src/smtpclient.cpp b/src/smtpclient.cpp index 8035324..aaa5909 100644 --- a/src/smtpclient.cpp +++ b/src/smtpclient.cpp @@ -66,7 +66,7 @@ void SmtpClient::setAuthMethod(AuthMethod method) this->authMethod = method; } -void SmtpClient::setHost(QString &host) +void SmtpClient::setHost(const QString &host) { this->host = host; } diff --git a/src/smtpclient.h b/src/smtpclient.h index 2234d9a..ee83884 100644 --- a/src/smtpclient.h +++ b/src/smtpclient.h @@ -70,7 +70,7 @@ public: /* [2] Getters and Setters */ const QString& getHost() const; - void setHost(QString &host); + void setHost(const QString &host); int getPort() const; void setPort(int port); @@ -82,7 +82,7 @@ public: void setConnectionType(ConnectionType ct); const QString & getUser() const; - void setUser(const QString &host); + void setUser(const QString &user); const QString & getPassword() const; void setPassword(const QString &password); @@ -175,7 +175,7 @@ signals: /* [7] Signals */ - void smtpError(SmtpError e); + void smtpError(SmtpClient::SmtpError e); /* [7] --- */