summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mailit/emailhandler.cpp
authorgroucho <groucho>2003-04-29 08:04:34 (UTC)
committer groucho <groucho>2003-04-29 08:04:34 (UTC)
commitf09f685be0540e98cc33bc4f664a812aed756926 (patch) (unidiff)
tree10a2193eafd1dc0ae25cd458f3bfa9f0f23522e1 /noncore/unsupported/mailit/emailhandler.cpp
parente096c9d1f2be1ec74ede583fc4221871a56ef508 (diff)
downloadopie-f09f685be0540e98cc33bc4f664a812aed756926.zip
opie-f09f685be0540e98cc33bc4f664a812aed756926.tar.gz
opie-f09f685be0540e98cc33bc4f664a812aed756926.tar.bz2
- added ReplyAll for CC: addressing
- added a download button in mail view - smaller layout fixes - now it's getting to be real useful
Diffstat (limited to 'noncore/unsupported/mailit/emailhandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mailit/emailhandler.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp
index fbbada7..c7b27a0 100644
--- a/noncore/unsupported/mailit/emailhandler.cpp
+++ b/noncore/unsupported/mailit/emailhandler.cpp
@@ -1,213 +1,216 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qfileinfo.h> 20#include <qfileinfo.h>
21#include <stdlib.h> 21#include <stdlib.h>
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qmessagebox.h> 23#include <qmessagebox.h>
24#include <qcstring.h> 24#include <qcstring.h>
25#include "emailhandler.h" 25#include "emailhandler.h"
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");
43
42 smtpClient = new SmtpClient(); 44 smtpClient = new SmtpClient();
43 popClient = new PopClient(); 45 popClient = new PopClient();
44 46
45 connect(smtpClient, SIGNAL(errorOccurred(int)), this, 47 connect(smtpClient, SIGNAL(errorOccurred(int)), this,
46 SIGNAL(smtpError(int)) ); 48 SIGNAL(smtpError(int)) );
47 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); 49 connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) );
48 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, 50 connect(smtpClient, SIGNAL(updateStatus(const QString &)), this,
49 SIGNAL(updateSmtpStatus(const QString &)) ); 51 SIGNAL(updateSmtpStatus(const QString &)) );
50 52
51 connect(popClient, SIGNAL(errorOccurred(int)), this, 53 connect(popClient, SIGNAL(errorOccurred(int)), this,
52 SIGNAL(popError(int)) ); 54 SIGNAL(popError(int)) );
53 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), 55 connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)),
54 this, SLOT(messageArrived(const QString &, int, uint, bool)) ); 56 this, SLOT(messageArrived(const QString &, int, uint, bool)) );
55 connect(popClient, SIGNAL(updateStatus(const QString &)), this, 57 connect(popClient, SIGNAL(updateStatus(const QString &)), this,
56 SIGNAL(updatePopStatus(const QString &)) ); 58 SIGNAL(updatePopStatus(const QString &)) );
57 connect(popClient, SIGNAL(mailTransfered(int)), this, 59 connect(popClient, SIGNAL(mailTransfered(int)), this,
58 SIGNAL(mailTransfered(int)) ); 60 SIGNAL(mailTransfered(int)) );
59 61
60 62
61 //relaying size information 63 //relaying size information
62 connect(popClient, SIGNAL(currentMailSize(int)), 64 connect(popClient, SIGNAL(currentMailSize(int)),
63 this, SIGNAL(currentMailSize(int)) ); 65 this, SIGNAL(currentMailSize(int)) );
64 connect(popClient, SIGNAL(downloadedSize(int)), 66 connect(popClient, SIGNAL(downloadedSize(int)),
65 this, SIGNAL(downloadedSize(int)) ); 67 this, SIGNAL(downloadedSize(int)) );
66} 68}
67 69
68void EmailHandler::sendMail(QList<Email> *mailList) 70void EmailHandler::sendMail(QList<Email> *mailList)
69{ 71{
70 Email *currentMail; 72 Email *currentMail;
71 QString temp; 73 QString temp;
72 QString userName = mailAccount.name; 74 QString userName = mailAccount.name;
73 userName += " <" + mailAccount.emailAddress + ">"; 75 userName += " <" + mailAccount.emailAddress + ">";
74 76
75 for (currentMail = mailList->first(); currentMail != 0; 77 for (currentMail = mailList->first(); currentMail != 0;
76 currentMail = mailList->next()) { 78 currentMail = mailList->next()) {
77 79
78 if (encodeMime(currentMail) == 0) { 80 if (encodeMime(currentMail) == 0) {
79 smtpClient->addMail(userName, currentMail->subject, 81 smtpClient->addMail(userName, currentMail->subject,
80 currentMail->recipients, currentMail->rawMail); 82 currentMail->recipients, currentMail->rawMail);
81 } else { //error 83 } else { //error
82 temp = tr("Could not locate all files in \nmail with subject: ") + 84 temp = tr("Could not locate all files in \nmail with subject: ") +
83 currentMail->subject; 85 currentMail->subject;
84 temp += tr("\nMail has NOT been sent"); 86 temp += tr("\nMail has NOT been sent");
85 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); 87 QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n"));
86 88
87 } 89 }
88 } 90 }
89 smtpClient->newConnection(mailAccount.smtpServer, 25); 91 smtpClient->newConnection(mailAccount.smtpServer, 25);
90} 92}
91 93
92void EmailHandler::setAccount(MailAccount account) 94void EmailHandler::setAccount(MailAccount account)
93{ 95{
94 mailAccount = account; 96 mailAccount = account;
95} 97}
96 98
97void EmailHandler::getMail() 99void EmailHandler::getMail()
98{ 100{
99 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 101 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
100 if (mailAccount.synchronize) { 102 if (mailAccount.synchronize) {
101 popClient->setSynchronize(mailAccount.lastServerMailCount); 103 popClient->setSynchronize(mailAccount.lastServerMailCount);
102 } else { 104 } else {
103 popClient->removeSynchronize(); 105 popClient->removeSynchronize();
104 } 106 }
105 107
106 headers = FALSE; 108 headers = FALSE;
107 //popClient->headersOnly(headers, 0); 109 //popClient->headersOnly(headers, 0);
108 popClient->newConnection(mailAccount.popServer, 110); 110 popClient->newConnection(mailAccount.popServer, 110);
109} 111}
110 112
111void EmailHandler::getMailHeaders() 113void EmailHandler::getMailHeaders()
112{ 114{
113 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); 115 popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd);
114 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); 116 mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize();
115 117
116 headers = TRUE; 118 headers = TRUE;
117 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all 119 popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all
120 qDebug("Initiating connection");
118 popClient->newConnection(mailAccount.popServer, 110); 121 popClient->newConnection(mailAccount.popServer, 110);
119} 122}
120 123
121void EmailHandler::getMailByList(MailList *mailList) 124void EmailHandler::getMailByList(MailList *mailList)
122{ 125{
123 if (mailList->count() == 0) { //should not occur though 126 if (mailList->count() == 0) { //should not occur though
124 emit mailTransfered(0); 127 emit mailTransfered(0);
125 return; 128 return;
126 } 129 }
127 130
128 headers = FALSE; 131 headers = FALSE;
129 popClient->headersOnly(FALSE, 0); 132 popClient->headersOnly(FALSE, 0);
130 133
131 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); 134 popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd);
132 popClient->setSelectedMails(mailList); 135 popClient->setSelectedMails(mailList);
133 popClient->newConnection(mailAccount.popServer, 110); 136 popClient->newConnection(mailAccount.popServer, 110);
134 } 137 }
135 138
136void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) 139void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete)
137{ 140{
138 Email mail; 141 Email mail;
139 142
140 mail.rawMail = message; 143 mail.rawMail = message;
141 mail.serverId = id; 144 mail.serverId = id;
142 mail.size = size; 145 mail.size = size;
143 mail.downloaded = complete; 146 mail.downloaded = complete;
144 147
145 emit mailArrived(mail, FALSE); 148 emit mailArrived(mail, FALSE);
146} 149}
147 150
148bool EmailHandler::parse(QString in, QString lineShift, Email *mail) 151bool EmailHandler::parse(QString in, QString lineShift, Email *mail)
149{ 152{
150 QString temp, boundary; 153 QString temp, boundary;
151 int pos; 154 int pos;
152 QString delimiter, header, body, mimeHeader, mimeBody; 155 QString delimiter, header, body, mimeHeader, mimeBody;
153 QString content, contentType, contentAttribute, id, encoding; 156 QString content, contentType, contentAttribute, id, encoding;
154 QString fileName, storedName; 157 QString fileName, storedName;
155 int enclosureId = 0; 158 int enclosureId = 0;
156 159
157 mail->rawMail = in; 160 mail->rawMail = in;
158 mail->received = TRUE; 161 mail->received = TRUE;
159 mail->files.setAutoDelete(TRUE); 162 mail->files.setAutoDelete(TRUE);
160 163
161 temp = lineShift + "." + lineShift; 164 temp = lineShift + "." + lineShift;
162 165
163 if (in.right(temp.length()) != temp) { 166 if (in.right(temp.length()) != temp) {
164 mail->rawMail += temp; 167 mail->rawMail += temp;
165 } 168 }
166 169
167 170
168 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
169 pos = in.find(delimiter, 0, FALSE); 172 pos = in.find(delimiter, 0, FALSE);
170 header = in.left(pos); 173 header = in.left(pos);
171 body = in.right(in.length() - pos - delimiter.length()); 174 body = in.right(in.length() - pos - delimiter.length());
172 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) 175 if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n'))
173 body.truncate(body.length()-2); 176 body.truncate(body.length()-2);
174 177
175 TextParser p(header, lineShift); 178 TextParser p(header, lineShift);
176 179
177 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 180 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
178 pos++; 181 pos++;
179 if (p.separatorAt(pos) == ' ') { 182 if (p.separatorAt(pos) == ' ') {
180 mail->from = p.getString(&pos, '<', false); 183 mail->from = p.getString(&pos, '<', false);
181 mail->from = mail->from.stripWhiteSpace(); 184 mail->from = mail->from.stripWhiteSpace();
182 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 185 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
183 mail->from = mail->from.left(mail->from.length() - 1); 186 mail->from = mail->from.left(mail->from.length() - 1);
184 mail->from = mail->from.right(mail->from.length() - 1); 187 mail->from = mail->from.right(mail->from.length() - 1);
185 } 188 }
186 pos++; 189 pos++;
187 mail->fromMail = p.getString(&pos, '>', false); 190 mail->fromMail = p.getString(&pos, '>', false);
188 } else { 191 } else {
189 if (p.separatorAt(pos) == '<') //No name.. nasty 192 if (p.separatorAt(pos) == '<') //No name.. nasty
190 pos++; 193 pos++;
191 //pos++; 194 //pos++;
192 mail->fromMail = p.getString(&pos, 'z', TRUE); 195 mail->fromMail = p.getString(&pos, 'z', TRUE);
193 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 196 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
194 mail->fromMail.truncate(mail->fromMail.length() - 1); 197 mail->fromMail.truncate(mail->fromMail.length() - 1);
195 mail->from=mail->fromMail; 198 mail->from=mail->fromMail;
196 } 199 }
197 } 200 }
198 201
199 pos=0; 202 pos=0;
200 203
201 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: 204 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
202 while((pos = p.find("TO",':', pos+1, TRUE))!=-1) 205 while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
203 { 206 {
204 QString rec; 207 QString rec;
205 208
206 if (p.separatorAt(pos-1)!='-') 209 if (p.separatorAt(pos-1)!='-')
207 { 210 {
208 pos++; 211 pos++;
209 mail->recipients.append(p.getString(&pos, '\r', TRUE)); 212 mail->recipients.append(p.getString(&pos, '\r', TRUE));
210 } 213 }
211 /*else { 214 /*else {
212 if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty 215 if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty
213 pos++; 216 pos++;
@@ -533,96 +536,97 @@ int EmailHandler::encodeFile(QString fileName, QString *toBody)
533 QTextStream s(&f); 536 QTextStream s(&f);
534 dataSize = f.size(); 537 dataSize = f.size();
535 fileData = (char *) malloc(dataSize + 3); 538 fileData = (char *) malloc(dataSize + 3);
536 s.readRawBytes(fileData, dataSize); 539 s.readRawBytes(fileData, dataSize);
537 540
538 temp = ""; 541 temp = "";
539 dataPtr = fileData; 542 dataPtr = fileData;
540 count = 0; 543 count = 0;
541 while (dataSize > 0) { 544 while (dataSize > 0) {
542 if (dataSize < 3) { 545 if (dataSize < 3) {
543 encode64base(dataPtr, &temp, dataSize); 546 encode64base(dataPtr, &temp, dataSize);
544 dataSize = 0; 547 dataSize = 0;
545 } else { 548 } else {
546 encode64base(dataPtr, &temp, 3); 549 encode64base(dataPtr, &temp, 3);
547 dataSize -= 3; 550 dataSize -= 3;
548 dataPtr += 3; 551 dataPtr += 3;
549 count += 4; 552 count += 4;
550 } 553 }
551 if (count > 72) { 554 if (count > 72) {
552 count = 0; 555 count = 0;
553 temp += "\r\n"; 556 temp += "\r\n";
554 } 557 }
555 } 558 }
556 toBody->append(temp); 559 toBody->append(temp);
557 560
558 delete(fileData); 561 delete(fileData);
559 f.close(); 562 f.close();
560 return 0; 563 return 0;
561} 564}
562 565
563void EmailHandler::encode64base(char *src, QString *dest, int len) 566void EmailHandler::encode64base(char *src, QString *dest, int len)
564{ 567{
565 QString temp; 568 QString temp;
566 uchar c; 569 uchar c;
567 uchar bufOut[4]; 570 uchar bufOut[4];
568 571
569 bufOut[0] = src[0]; 572 bufOut[0] = src[0];
570 bufOut[0] >>= 2; //Done byte 0 573 bufOut[0] >>= 2; //Done byte 0
571 574
572 bufOut[1] = src[0]; 575 bufOut[1] = src[0];
573 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits 576 bufOut[1] = bufOut[1] & (1 + 2); //mask out top 6 bits
574 bufOut[1] <<= 4; //copy up 4 places 577 bufOut[1] <<= 4; //copy up 4 places
575 if (len > 1) { 578 if (len > 1) {
576 c = src[1]; 579 c = src[1];
577 } else { 580 } else {
578 c = 0; 581 c = 0;
579 } 582 }
580 583
581 c = c & (16 + 32 + 64 + 128); 584 c = c & (16 + 32 + 64 + 128);
582 c >>= 4; 585 c >>= 4;
583 bufOut[1] = bufOut[1] | c; //Done byte 1 586 bufOut[1] = bufOut[1] | c; //Done byte 1
584 587
585 bufOut[2] = src[1]; 588 bufOut[2] = src[1];
586 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8); 589 bufOut[2] = bufOut[2] & (1 + 2 + 4 + 8);
587 bufOut[2] <<= 2; 590 bufOut[2] <<= 2;
588 if (len > 2) { 591 if (len > 2) {
589 c = src[2]; 592 c = src[2];
590 } else { 593 } else {
591 c = 0; 594 c = 0;
592 } 595 }
593 c >>= 6; 596 c >>= 6;
594 bufOut[2] = bufOut[2] | c; 597 bufOut[2] = bufOut[2] | c;
595 598
596 bufOut[3] = src[2]; 599 bufOut[3] = src[2];
597 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32); 600 bufOut[3] = bufOut[3] & (1 + 2 + 4 + 8 + 16 + 32);
598 601
599 if (len == 1) { 602 if (len == 1) {
600 bufOut[2] = 64; 603 bufOut[2] = 64;
601 bufOut[3] = 64; 604 bufOut[3] = 64;
602 } 605 }
603 if (len == 2) { 606 if (len == 2) {
604 bufOut[3] = 64; 607 bufOut[3] = 64;
605 } 608 }
606 for (int x = 0; x < 4; x++) { 609 for (int x = 0; x < 4; x++) {
607 if (bufOut[x] <= 25) 610 if (bufOut[x] <= 25)
608 bufOut[x] += (uint) 'A'; 611 bufOut[x] += (uint) 'A';
609 else if (bufOut[x] >= 26 && bufOut[x] <= 51) 612 else if (bufOut[x] >= 26 && bufOut[x] <= 51)
610 bufOut[x] += (uint) 'a' - 26; 613 bufOut[x] += (uint) 'a' - 26;
611 else if (bufOut[x] >= 52 && bufOut[x] <= 61) 614 else if (bufOut[x] >= 52 && bufOut[x] <= 61)
612 bufOut[x] += (uint) '0' - 52; 615 bufOut[x] += (uint) '0' - 52;
613 else if (bufOut[x] == 62) 616 else if (bufOut[x] == 62)
614 bufOut[x] = '+'; 617 bufOut[x] = '+';
615 else if (bufOut[x] == 63) 618 else if (bufOut[x] == 63)
616 bufOut[x] = '/'; 619 bufOut[x] = '/';
617 else if (bufOut[x] == 64) 620 else if (bufOut[x] == 64)
618 bufOut[x] = '='; 621 bufOut[x] = '=';
619 622
620 dest->append(bufOut[x]); 623 dest->append(bufOut[x]);
621 } 624 }
622} 625}
623 626
624void EmailHandler::cancel() 627void EmailHandler::cancel()
625{ 628{
626 popClient->errorHandling(ErrCancel); 629 popClient->errorHandling(ErrCancel);
627 smtpClient->errorHandling(ErrCancel); 630 smtpClient->errorHandling(ErrCancel);
628} 631}
632