summaryrefslogtreecommitdiff
path: root/noncore/net/mailit/emailhandler.cpp
Unidiff
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 @@
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/filemanager.h> 27#include <qpe/filemanager.h>
28 28
29QCollection::Item EnclosureList::newItem(QCollection::Item d) 29QCollection::Item EnclosureList::newItem(QCollection::Item d)
30{ 30{
31 return dupl( (Enclosure *) d); 31 return dupl( (Enclosure *) d);
32} 32}
33 33
34Enclosure* EnclosureList::dupl(Enclosure *in) 34Enclosure* EnclosureList::dupl(Enclosure *in)
35{ 35{
36 ac = new Enclosure(*in); 36 ac = new Enclosure(*in);
37 return ac; 37 return ac;
38} 38}
39 39
40EmailHandler::EmailHandler() 40EmailHandler::EmailHandler()
41{ 41{
42 qDebug("EMailHandler::EmailHandler"); 42 qDebug("EMailHandler::EmailHandler");
43 43
44 smtpClient = new SmtpClient(); 44 smtpClient = new SmtpClient();
45 popClient = new PopClient(); 45 popClient = new PopClient();
46 46
47 connect(smtpClient, SIGNAL(errorOccurred(int, const QString &)), this, 47 connect(smtpClient, SIGNAL(errorOccurred(int, const QString &)), this,
48 SIGNAL(smtpError(int, const QString &)) ); 48 SIGNAL(smtpError(int, const QString &)) );
49 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); 49 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
50 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, 50 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
51 SIGNAL(updateSmtpStatus(const QString &)) ); 51 SIGNAL(updateSmtpStatus(const QString &)) );
52 52
53 connect(popClient, SIGNAL(errorOccurred(int, const QString &)), this, 53 connect(popClient, SIGNAL(errorOccurred(int, const QString &)), this,
54 SIGNAL(popError(int, const QString &)) ); 54 SIGNAL(popError(int, const QString &)) );
55 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), 55 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
56 this, SLOT(messageArrived(const QString &, int, uint, bool)) ); 56 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
57 connect(popClient, SIGNAL(updateStatus(const QString &)), this, 57 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
58 SIGNAL(updatePopStatus(const QString &)) ); 58 SIGNAL(updatePopStatus(const QString &)) );
59 connect(popClient, SIGNAL(mailTransfered(int)), this, 59 connect(popClient, SIGNAL(mailTransfered(int)), this,
60 SIGNAL(mailTransfered(int)) ); 60 SIGNAL(mailTransfered(int)) );
61 61
62 62
63 //relaying size information 63 //relaying size information
64 connect(popClient, SIGNAL(currentMailSize(int)), 64 connect(popClient, SIGNAL(currentMailSize(int)),
65 this, SIGNAL(currentMailSize(int)) ); 65 this, SIGNAL(currentMailSize(int)) );
66 connect(popClient, SIGNAL(downloadedSize(int)), 66 connect(popClient, SIGNAL(downloadedSize(int)),
67 this, SIGNAL(downloadedSize(int)) ); 67 this, SIGNAL(downloadedSize(int)) );
68} 68}
69 69
70void EmailHandler::sendMail(QList<Email> *mailList) 70void EmailHandler::sendMail(QList<Email> *mailList)
71{ 71{
72 Email *currentMail; 72 Email *currentMail;
73 QString temp; 73 QString temp;
74 QString userName = mailAccount.name; 74 QString userName = QString::null;
75 userName += " <" + mailAccount.emailAddress + ">"; 75 // not supported by ALL SMTP servers in the MAIL From field
76 // userName = "\""+mailAccount.name+"\"";
77 userName += "<" + mailAccount.emailAddress + ">";
76 78
77 for (currentMail = mailList->first(); currentMail != 0; 79 for (currentMail = mailList->first(); currentMail != 0;
78 currentMail = mailList->next()) { 80 currentMail = mailList->next()) {
79 81
80 if (encodeMime(currentMail) == 0) { 82 if (encodeMime(currentMail) == 0) {
81 smtpClient->addMail(userName, currentMail->subject, 83 smtpClient->addMail(userName, currentMail->subject,
82 currentMail->recipients, currentMail->rawMail); 84 currentMail->recipients, currentMail->rawMail);
83 } else { //error 85 } else { //error
84 temp = tr("Could not locate all files in \nmail with subject: ") + 86 temp = tr("Could not locate all files in \nmail with subject: ") +
85 currentMail->subject; 87 currentMail->subject;
86 temp += tr("\nMail has NOT been sent"); 88 temp += tr("\nMail has NOT been sent");
87 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 89 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
88 90
89 } 91 }
90 } 92 }
91 smtpClient->newConnection(mailAccount.smtpServer, 25); 93 smtpClient->newConnection(mailAccount.smtpServer, 25);
92} 94}
93 95
94void EmailHandler::setAccount(MailAccount account) 96void EmailHandler::setAccount(MailAccount account)
95{ 97{
96 mailAccount = account; 98 mailAccount = account;
97} 99}
98 100
99void EmailHandler::getMail() 101void EmailHandler::getMail()
100{ 102{
101 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 103 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
102 if (mailAccount.synchronize) { 104 if (mailAccount.synchronize) {
103 popClient->setSynchronize(mailAccount.lastServerMailCount); 105 popClient->setSynchronize(mailAccount.lastServerMailCount);
104 } else { 106 } else {
105 popClient->removeSynchronize(); 107 popClient->removeSynchronize();
106 } 108 }
107 109
108 headers = FALSE; 110 headers = FALSE;
109 //popClient->headersOnly(headers, 0); 111 //popClient->headersOnly(headers, 0);
110 popClient->newConnection(mailAccount.popServer, 110); 112 popClient->newConnection(mailAccount.popServer, 110);
111} 113}
112 114
113void EmailHandler::getMailHeaders() 115void EmailHandler::getMailHeaders()
114{ 116{
115 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 117 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
116 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); 118 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize();
117 119
118 headers = TRUE; 120 headers = TRUE;
119 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all 121 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
120 qDebug("Initiating connection"); 122 qDebug("Initiating connection");
121 popClient->newConnection(mailAccount.popServer, 110); 123 popClient->newConnection(mailAccount.popServer, 110);
122} 124}
123 125
@@ -397,100 +399,103 @@ int EmailHandler::parse64base(char *src, char *bufOut) {
397 char li[4]; 399 char li[4];
398 int processed; 400 int processed;
399 401
400 //conversion table withouth table... 402 //conversion table withouth table...
401 for (int x = 0; x < 4; x++) { 403 for (int x = 0; x < 4; x++) {
402 c = src[x]; 404 c = src[x];
403 405
404 if ( (int) c >= 'A' && (int) c <= 'Z') 406 if ( (int) c >= 'A' && (int) c <= 'Z')
405 li[x] = (int) c - (int) 'A'; 407 li[x] = (int) c - (int) 'A';
406 if ( (int) c >= 'a' && (int) c <= 'z') 408 if ( (int) c >= 'a' && (int) c <= 'z')
407 li[x] = (int) c - (int) 'a' + 26; 409 li[x] = (int) c - (int) 'a' + 26;
408 if ( (int) c >= '0' && (int) c <= '9') 410 if ( (int) c >= '0' && (int) c <= '9')
409 li[x] = (int) c - (int) '0' + 52; 411 li[x] = (int) c - (int) '0' + 52;
410 if (c == '+') 412 if (c == '+')
411 li[x] = 62; 413 li[x] = 62;
412 if (c == '/') 414 if (c == '/')
413 li[x] = 63; 415 li[x] = 63;
414 } 416 }
415 417
416 processed = 1; 418 processed = 1;
417 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits 419 bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits
418 bufOut[0] <<= 2; 420 bufOut[0] <<= 2;
419 z = li[1] >> 4; 421 z = li[1] >> 4;
420 bufOut[0] = bufOut[0] | z; //first byte retrived 422 bufOut[0] = bufOut[0] | z; //first byte retrived
421 423
422 if (src[2] != '=') { 424 if (src[2] != '=') {
423 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits 425 bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits
424 bufOut[1] <<= 4; 426 bufOut[1] <<= 4;
425 z = li[2] >> 2; 427 z = li[2] >> 2;
426 bufOut[1] = bufOut[1] | z; //second byte retrived 428 bufOut[1] = bufOut[1] | z; //second byte retrived
427 processed++; 429 processed++;
428 430
429 if (src[3] != '=') { 431 if (src[3] != '=') {
430 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits 432 bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits
431 bufOut[2] <<= 6; 433 bufOut[2] <<= 6;
432 z = li[3]; 434 z = li[3];
433 bufOut[2] = bufOut[2] | z; //third byte retrieved 435 bufOut[2] = bufOut[2] | z; //third byte retrieved
434 processed++; 436 processed++;
435 } 437 }
436 } 438 }
437 return processed; 439 return processed;
438} 440}
439 441
440int EmailHandler::encodeMime(Email *mail) 442int EmailHandler::encodeMime(Email *mail)
441{ 443{
442 444
443 QString fileName, fileType, contentType, newBody, boundary; 445 QString fileName, fileType, contentType, newBody, boundary;
444 Enclosure *ePtr; 446 Enclosure *ePtr;
447 QString userName;
445 448
446 QString userName = mailAccount.name; 449 if ( ! mailAccount.name.isEmpty() ) {
447 if (userName.length()>0) //only embrace it if there is a user name 450 userName = "\"" + mailAccount.name + "\" <" + mailAccount.emailAddress + ">";
448 userName += " <" + mailAccount.emailAddress + ">"; 451 } else {
452 userName = "<" + mailAccount.emailAddress + ">";
453 }
449 454
450 //add standard headers 455 //add standard headers
451 newBody = "From: " + userName + "\r\nTo: "; 456 newBody = "From: " + userName + "\r\nTo: ";
452 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { 457 for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) {
453 newBody += *it + " "; 458 newBody += *it + " ";
454 } 459 }
455 460
456 newBody += "\r\nCC: "; 461 newBody += "\r\nCC: ";
457 462
458 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { 463 for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) {
459 newBody += *it + " "; 464 newBody += *it + " ";
460 } 465 }
461 466
462 newBody += "\r\nSubject: " + mail->subject + "\r\n"; 467 newBody += "\r\nSubject: " + mail->subject + "\r\n";
463 468
464 if (mail->files.count() == 0) { //just a simple mail 469 if (mail->files.count() == 0) { //just a simple mail
465 newBody += "\r\n" + mail->body; 470 newBody += "\r\n" + mail->body;
466 mail->rawMail = newBody; 471 mail->rawMail = newBody;
467 return 0; 472 return 0;
468 } 473 }
469 474
470 //Build mime encoded mail 475 //Build mime encoded mail
471 boundary = "-----4345=next_bound=0495----"; 476 boundary = "-----4345=next_bound=0495----";
472 477
473 newBody += "Mime-Version: 1.0\r\n"; 478 newBody += "Mime-Version: 1.0\r\n";
474 newBody += "Content-Type: multipart/mixed; boundary=\"" + 479 newBody += "Content-Type: multipart/mixed; boundary=\"" +
475 boundary + "\"\r\n\r\n"; 480 boundary + "\"\r\n\r\n";
476 481
477 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; 482 newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n";
478 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; 483 newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n";
479 newBody += mail->body; 484 newBody += mail->body;
480 485
481 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { 486 for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) {
482 fileName = ePtr->originalName; 487 fileName = ePtr->originalName;
483 fileType = ePtr->contentType; 488 fileType = ePtr->contentType;
484 QFileInfo fi(fileName); 489 QFileInfo fi(fileName);
485 490
486 // This specification of contentType is temporary 491 // This specification of contentType is temporary
487 contentType = ""; 492 contentType = "";
488 if (fileType == "Picture") { 493 if (fileType == "Picture") {
489 contentType = "image/x-image"; 494 contentType = "image/x-image";
490 } else if (fileType == "Document") { 495 } else if (fileType == "Document") {
491 contentType = "text/plain"; 496 contentType = "text/plain";
492 } else if (fileType == "Sound") { 497 } else if (fileType == "Sound") {
493 contentType = "audio/x-wav"; 498 contentType = "audio/x-wav";
494 } else if (fileType == "Movie") { 499 } else if (fileType == "Movie") {
495 contentType = "video/mpeg"; 500 contentType = "video/mpeg";
496 } else { 501 } else {