summaryrefslogtreecommitdiff
path: root/noncore/net/mailit/emailhandler.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/mailit/emailhandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/emailhandler.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp
index 5b8bda1..06e978d 100644
--- a/noncore/net/mailit/emailhandler.cpp
+++ b/noncore/net/mailit/emailhandler.cpp
@@ -26,98 +26,100 @@
#include <qpe/applnk.h>
#include <qpe/filemanager.h>
QCollection::Item EnclosureList::newItem(QCollection::Item d)
{
return dupl( (Enclosure *) d);
}
Enclosure* EnclosureList::dupl(Enclosure *in)
{
ac = new Enclosure(*in);
return ac;
}
EmailHandler::EmailHandler()
{
qDebug("EMailHandler::EmailHandler");
smtpClient = new SmtpClient();
popClient = new PopClient();
connect(smtpClient, SIGNAL(errorOccurred(int, const QString &)), this,
SIGNAL(smtpError(int, const QString &)) );
connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
SIGNAL(updateSmtpStatus(const QString &)) );
connect(popClient, SIGNAL(errorOccurred(int, const QString &)), this,
SIGNAL(popError(int, const QString &)) );
connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
this, SLOT(messageArrived(const QString &, int, uint, bool)) );
connect(popClient, SIGNAL(updateStatus(const QString &)), this,
SIGNAL(updatePopStatus(const QString &)) );
connect(popClient, SIGNAL(mailTransfered(int)), this,
SIGNAL(mailTransfered(int)) );
//relaying size information
connect(popClient, SIGNAL(currentMailSize(int)),
this, SIGNAL(currentMailSize(int)) );
connect(popClient, SIGNAL(downloadedSize(int)),
this, SIGNAL(downloadedSize(int)) );
}
void EmailHandler::sendMail(QList<Email> *mailList)
{
Email *currentMail;
QString temp;
- QString userName = mailAccount.name;
- userName += " <" + mailAccount.emailAddress + ">";
+ QString userName = QString::null;
+ // not supported by ALL SMTP servers in the MAIL From field
+ // userName = "\""+mailAccount.name+"\"";
+ userName += "<" + mailAccount.emailAddress + ">";
for (currentMail = mailList->first(); currentMail != 0;
currentMail = mailList->next()) {
if (encodeMime(currentMail) == 0) {
smtpClient->addMail(userName, currentMail->subject,
currentMail->recipients, currentMail->rawMail);
} else { //error
temp = tr("Could not locate all files in \nmail with subject: ") +
currentMail->subject;
temp += tr("\nMail has NOT been sent");
QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
}
}
smtpClient->newConnection(mailAccount.smtpServer, 25);
}
void EmailHandler::setAccount(MailAccount account)
{
mailAccount = account;
}
void EmailHandler::getMail()
{
popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
if (mailAccount.synchronize) {
popClient->setSynchronize(mailAccount.lastServerMailCount);
} else {
popClient->removeSynchronize();
}
headers = FALSE;
//popClient->headersOnly(headers, 0);
popClient->newConnection(mailAccount.popServer, 110);
}
void EmailHandler::getMailHeaders()
{
popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize();
headers = TRUE;
popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
qDebug("Initiating connection");
popClient->newConnection(mailAccount.popServer, 110);
}
@@ -397,100 +399,103 @@ int EmailHandler::parse64base(char *src, char *bufOut) {
char li[4];
int processed;
//conversion table withouth table...
for (int x = 0; x < 4; x++) {
c = src[x];
if ( (int) c >= 'A' && (int) c <= 'Z')
li[x] = (int) c - (int) 'A';
if ( (int) c >= 'a' && (int) c <= 'z')
li[x] = (int) c - (int) 'a' + 26;
if ( (int) c >= '0' && (int) c <= '9')
li[x] = (int) c - (int) '0' + 52;
if (c == '+')
li[x] = 62;
if (c == '/')
li[x] = 63;
}
processed = 1;
bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
bufOut[0] <<= 2;
z = li[1] >> 4;
bufOut[0] = bufOut[0] | z; //first byte retrived
if (src[2] != '=') {
bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
bufOut[1] <<= 4;
z = li[2] >> 2;
bufOut[1] = bufOut[1] | z; //second byte retrived
processed++;
if (src[3] != '=') {
bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
bufOut[2] <<= 6;
z = li[3];
bufOut[2] = bufOut[2] | z; //third byte retrieved
processed++;
}
}
return processed;
}
int EmailHandler::encodeMime(Email *mail)
{
QString fileName, fileType, contentType, newBody, boundary;
Enclosure *ePtr;
+ QString userName;
- QString userName = mailAccount.name;
- if (userName.length()>0) //only embrace it if there is a user name
- userName += " <" + mailAccount.emailAddress + ">";
+ if ( ! mailAccount.name.isEmpty() ) {
+ userName = "\"" + mailAccount.name + "\" <" + mailAccount.emailAddress + ">";
+ } else {
+ userName = "<" + mailAccount.emailAddress + ">";
+ }
//add standard headers
newBody = "From: " + userName + "\r\nTo: ";
for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
newBody += *it + " ";
}
newBody += "\r\nCC: ";
for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) {
newBody += *it + " ";
}
newBody += "\r\nSubject: " + mail->subject + "\r\n";
if (mail->files.count() == 0) { //just a simple mail
newBody += "\r\n" + mail->body;
mail->rawMail = newBody;
return 0;
}
//Build mime encoded mail
boundary = "-----4345=next_bound=0495----";
newBody += "Mime-Version: 1.0\r\n";
newBody += "Content-Type: multipart/mixed; boundary=\"" +
boundary + "\"\r\n\r\n";
newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
newBody += mail->body;
for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
fileName = ePtr->originalName;
fileType = ePtr->contentType;
QFileInfo fi(fileName);
// This specification of contentType is temporary
contentType = "";
if (fileType == "Picture") {
contentType = "image/x-image";
} else if (fileType == "Document") {
contentType = "text/plain";
} else if (fileType == "Sound") {
contentType = "audio/x-wav";
} else if (fileType == "Movie") {
contentType = "video/mpeg";
} else {