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/mimemultipart.cpp \
src/mimecontentformatter.cpp \
demos/demo1.cpp
HEADERS += \
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
// 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()) {

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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;
}

View File

@ -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] --- */