summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-05-24 02:07:21 (UTC)
committer llornkcor <llornkcor>2003-05-24 02:07:21 (UTC)
commit694ff39fe4f0f4164edd7a2a80abe6be3a4fa2f9 (patch) (unidiff)
tree6c3f2a5837e32adf2755de4f90d3590d585f1a96
parent62d2ddfb5cd77e2637cdf7fe16d76aac04975984 (diff)
downloadopie-694ff39fe4f0f4164edd7a2a80abe6be3a4fa2f9.zip
opie-694ff39fe4f0f4164edd7a2a80abe6be3a4fa2f9.tar.gz
opie-694ff39fe4f0f4164edd7a2a80abe6be3a4fa2f9.tar.bz2
fix for a few crashes. one being stack overwrite. please test before I commit to 0_99
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/emailclient.cpp8
-rw-r--r--noncore/net/mailit/emailhandler.cpp8
-rw-r--r--noncore/net/mailit/mailitwindow.cpp22
-rw-r--r--noncore/unsupported/mailit/emailclient.cpp8
-rw-r--r--noncore/unsupported/mailit/emailhandler.cpp8
-rw-r--r--noncore/unsupported/mailit/mailitwindow.cpp22
6 files changed, 42 insertions, 34 deletions
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp
index 2102ba7..da1226c 100644
--- a/noncore/net/mailit/emailclient.cpp
+++ b/noncore/net/mailit/emailclient.cpp
@@ -440,68 +440,68 @@ void EmailClient::mailArrived(const Email &mail, bool fromDisk)
440 } 440 }
441 } else { 441 } else {
442 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); 442 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
443 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); 443 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
444 if (ePtr->saved) { 444 if (ePtr->saved) {
445 ePtr->name = mailconf->readEntry("filename_" + stringId); 445 ePtr->name = mailconf->readEntry("filename_" + stringId);
446 ePtr->path = mailconf->readEntry("path_" + stringId); 446 ePtr->path = mailconf->readEntry("path_" + stringId);
447 } 447 }
448 } 448 }
449 } 449 }
450 450
451 bool found=false; 451 bool found=false;
452 452
453 if (!fromDisk) 453 if (!fromDisk)
454 { 454 {
455 455
456 Email *mailPtr; 456 Email *mailPtr;
457 item = (EmailListItem *) inboxView->firstChild(); 457 item = (EmailListItem *) inboxView->firstChild();
458 while ((item != NULL)&&(!found)) 458 while ((item != NULL)&&(!found))
459 { 459 {
460 mailPtr = item->getMail(); 460 mailPtr = item->getMail();
461 if (mailPtr->id == newMail.id) { 461 if (mailPtr->id == newMail.id) {
462 item->setMail(newMail); 462 item->setMail(newMail);
463 emit mailUpdated(item->getMail()); 463 emit mailUpdated(item->getMail());
464 found = true; 464 found = true;
465 } 465 }
466 item = (EmailListItem *) item->nextSibling(); 466 item = (EmailListItem *) item->nextSibling();
467 } 467 }
468 } 468 }
469 if ((!found)||(fromDisk)) { 469 if ((!found)||(fromDisk)) {
470 item = new EmailListItem(inboxView, newMail, TRUE); 470 item = new EmailListItem(inboxView, newMail, TRUE);
471 } 471 }
472 if (item->getMail()->files.count()>0) 472// if (item->getMail()->files.count()>0)
473 { 473// {
474 item->setPixmap(0, Resource::loadPixmap("mailit/attach")); 474// item->setPixmap(0, Resource::loadPixmap("mailit/attach"));
475 } 475// }
476 /*if (!newMail.downloaded) 476 /*if (!newMail.downloaded)
477 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ 477 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/
478 478
479 mailboxView->setCurrentTab(0); 479 mailboxView->setCurrentTab(0);
480 480
481} 481}
482 482
483void EmailClient::allMailArrived(int count) 483void EmailClient::allMailArrived(int count)
484{ 484{
485 // not previewing means all mailtransfer has been done 485 // not previewing means all mailtransfer has been done
486 /*if (!previewingMail) {*/ 486 /*if (!previewingMail) {*/
487 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { 487 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
488 emit newCaption("Mailit - " + currentAccount->accountName); 488 emit newCaption("Mailit - " + currentAccount->accountName);
489 getNewMail(); 489 getNewMail();
490 return; 490 return;
491 } else { 491 } else {
492 allAccounts = FALSE; 492 allAccounts = FALSE;
493 receiving = FALSE; 493 receiving = FALSE;
494 getMailButton->setEnabled(TRUE); 494 getMailButton->setEnabled(TRUE);
495 cancelButton->setEnabled(FALSE); 495 cancelButton->setEnabled(FALSE);
496 selectAccountMenu->setEnabled(TRUE); 496 selectAccountMenu->setEnabled(TRUE);
497 status1Label->setText("Idle"); 497 status1Label->setText("Idle");
498 498
499 progressBar->reset(); 499 progressBar->reset();
500 return; 500 return;
501 } 501 }
502 //} 502 //}
503 503
504 // all headers downloaded from server, start downloading remaining mails 504 // all headers downloaded from server, start downloading remaining mails
505 previewingMail = FALSE; 505 previewingMail = FALSE;
506 status1Label->setText(currentAccount->accountName); 506 status1Label->setText(currentAccount->accountName);
507 progressBar->reset(); 507 progressBar->reset();
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp
index 59ccd90..39f693d 100644
--- a/noncore/net/mailit/emailhandler.cpp
+++ b/noncore/net/mailit/emailhandler.cpp
@@ -146,66 +146,68 @@ void EmailHandler::messageArrived(const QString &message, int id, uint size, boo
146 mail.downloaded = complete; 146 mail.downloaded = complete;
147 147
148 emit mailArrived(mail, FALSE); 148 emit mailArrived(mail, FALSE);
149} 149}
150 150
151bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) 151bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail)
152{ 152{
153 QString temp, boundary; 153 QString temp, boundary;
154 int pos; 154 int pos;
155 QString delimiter, header, body, mimeHeader, mimeBody; 155 QString delimiter, header, body, mimeHeader, mimeBody;
156 QString content, contentType, contentAttribute, id, encoding; 156 QString content, contentType, contentAttribute, id, encoding;
157 QString fileName, storedName; 157 QString fileName, storedName;
158 int enclosureId = 0; 158 int enclosureId = 0;
159 159
160 mail->rawMail = in; 160 mail->rawMail = in;
161 mail->received = TRUE; 161 mail->received = TRUE;
162 mail->files.setAutoDelete(TRUE); 162 mail->files.setAutoDelete(TRUE);
163 163
164 temp = lineShift + "." + lineShift; 164 temp = lineShift + "." + lineShift;
165 165
166 if (in.right(temp.length()) != temp) { 166 if (in.right(temp.length()) != temp) {
167 mail->rawMail += temp; 167 mail->rawMail += temp;
168 } 168 }
169 169
170 170
171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
172 pos = in.find(delimiter, 0, FALSE); 172 pos = in.find(delimiter, 0, FALSE);
173 header = in.left(pos); 173 header = in.left(pos);
174 body = in.right(in.length() - pos - delimiter.length()); 174 body = in.right(in.length() - pos - delimiter.length());
175 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'))
176 body.truncate(body.length()-2); 176 body.truncate(body.length()-2);
177 177
178 TextParser p(header, lineShift); 178 // TextParser p(header, lineShift);
179 179 TextParser * lp = new TextParser(header, lineShift);
180#define p (*lp)
181
180 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 182 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
181 pos++; 183 pos++;
182 if (p.separatorAt(pos) == ' ') { 184 if (p.separatorAt(pos) == ' ') {
183 mail->from = p.getString(&pos, '<', false); 185 mail->from = p.getString(&pos, '<', false);
184 mail->from = mail->from.stripWhiteSpace(); 186 mail->from = mail->from.stripWhiteSpace();
185 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 187 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
186 mail->from = mail->from.left(mail->from.length() - 1); 188 mail->from = mail->from.left(mail->from.length() - 1);
187 mail->from = mail->from.right(mail->from.length() - 1); 189 mail->from = mail->from.right(mail->from.length() - 1);
188 } 190 }
189 pos++; 191 pos++;
190 mail->fromMail = p.getString(&pos, '>', false); 192 mail->fromMail = p.getString(&pos, '>', false);
191 } else { 193 } else {
192 if (p.separatorAt(pos) == '<') //No name.. nasty 194 if (p.separatorAt(pos) == '<') //No name.. nasty
193 pos++; 195 pos++;
194 //pos++; 196 //pos++;
195 mail->fromMail = p.getString(&pos, 'z', TRUE); 197 mail->fromMail = p.getString(&pos, 'z', TRUE);
196 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
197 mail->fromMail.truncate(mail->fromMail.length() - 1); 199 mail->fromMail.truncate(mail->fromMail.length() - 1);
198 mail->from=mail->fromMail; 200 mail->from=mail->fromMail;
199 } 201 }
200 } 202 }
201 203
202 pos=0; 204 pos=0;
203 205
204 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: 206 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
205 while((pos = p.find("TO",':', pos+1, TRUE))!=-1) 207 while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
206 { 208 {
207 QString rec; 209 QString rec;
208 210
209 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: 211 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To:
210 { 212 {
211 pos++; 213 pos++;
@@ -241,64 +243,65 @@ bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mai
241 id = p.getString(&pos, 'z', TRUE); 243 id = p.getString(&pos, 'z', TRUE);
242 mail->id = id; 244 mail->id = id;
243 } 245 }
244 } 246 }
245 247
246 pos = 0; 248 pos = 0;
247 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 249 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
248 pos++; 250 pos++;
249 if ( (p.wordAt(pos).upper() == "VERSION") && 251 if ( (p.wordAt(pos).upper() == "VERSION") &&
250 (p.separatorAt(pos) == ':') ) { 252 (p.separatorAt(pos) == ':') ) {
251 pos++; 253 pos++;
252 if (p.getString(&pos, 'z', true) == "1.0") { 254 if (p.getString(&pos, 'z', true) == "1.0") {
253 mail->mimeType = 1; 255 mail->mimeType = 1;
254 } 256 }
255 } 257 }
256 } 258 }
257 259
258 if (mail->mimeType == 1) { 260 if (mail->mimeType == 1) {
259 boundary = ""; 261 boundary = "";
260 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 262 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
261 pos++; 263 pos++;
262 boundary = p.getString(&pos, 'z', true); 264 boundary = p.getString(&pos, 'z', true);
263 if (boundary[0] == '"') { 265 if (boundary[0] == '"') {
264 boundary = boundary.left(boundary.length() - 1); //strip " 266 boundary = boundary.left(boundary.length() - 1); //strip "
265 boundary = boundary.right(boundary.length() - 1); //strip " 267 boundary = boundary.right(boundary.length() - 1); //strip "
266 } 268 }
267 boundary = "--" + boundary; //create boundary field 269 boundary = "--" + boundary; //create boundary field
268 } 270 }
269 271
270 if (boundary == "") { //fooled by Mime-Version 272 if (boundary == "") { //fooled by Mime-Version
271 mail->body = body; 273 mail->body = body;
272 mail->bodyPlain = body; 274 mail->bodyPlain = body;
275 delete lp;
273 return mail; 276 return mail;
274 } 277 }
275 278
276 while (body.length() > 0) { 279 while (body.length() > 0) {
277 pos = body.find(boundary, 0, FALSE); 280 pos = body.find(boundary, 0, FALSE);
278 pos = body.find(delimiter, pos, FALSE); 281 pos = body.find(delimiter, pos, FALSE);
279 mimeHeader = body.left(pos); 282 mimeHeader = body.left(pos);
280 mimeBody = body.right(body.length() - pos - delimiter.length()); 283 mimeBody = body.right(body.length() - pos - delimiter.length());
281 TextParser bp(mimeHeader, lineShift); 284 TextParser bp(mimeHeader, lineShift);
282 285
283 contentType = ""; 286 contentType = "";
284 contentAttribute = ""; 287 contentAttribute = "";
285 fileName = ""; 288 fileName = "";
286 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 289 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
287 pos++; 290 pos++;
288 if ( (bp.wordAt(pos).upper() == "TYPE") && 291 if ( (bp.wordAt(pos).upper() == "TYPE") &&
289 (bp.separatorAt(pos) == ':') ) { 292 (bp.separatorAt(pos) == ':') ) {
290 contentType = bp.nextWord().upper(); 293 contentType = bp.nextWord().upper();
291 if (bp.nextSeparator() == '/') 294 if (bp.nextSeparator() == '/')
292 contentAttribute = bp.nextWord().upper(); 295 contentAttribute = bp.nextWord().upper();
293 content = contentType + "/" + contentAttribute; 296 content = contentType + "/" + contentAttribute;
294 } 297 }
295 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 298 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
296 pos++; 299 pos++;
297 encoding = bp.getString(&pos, 'z', TRUE); 300 encoding = bp.getString(&pos, 'z', TRUE);
298 } 301 }
299 302
300 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 303 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
301 pos++; 304 pos++;
302 fileName = bp.getString(&pos, 'z', TRUE); 305 fileName = bp.getString(&pos, 'z', TRUE);
303 fileName = fileName.right(fileName.length() - 1); 306 fileName = fileName.right(fileName.length() - 1);
304 fileName = fileName.left(fileName.length() - 1); 307 fileName = fileName.left(fileName.length() - 1);
@@ -309,64 +312,65 @@ bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mai
309 if (pos == -1) //should not occur, malformed mail 312 if (pos == -1) //should not occur, malformed mail
310 pos = mimeBody.length(); 313 pos = mimeBody.length();
311 body = mimeBody.right(mimeBody.length() - pos); 314 body = mimeBody.right(mimeBody.length() - pos);
312 mimeBody = mimeBody.left(pos); 315 mimeBody = mimeBody.left(pos);
313 316
314 if (fileName != "") { //attatchments of some type, audio, image etc. 317 if (fileName != "") { //attatchments of some type, audio, image etc.
315 318
316 Enclosure e; 319 Enclosure e;
317 e.id = enclosureId; 320 e.id = enclosureId;
318 e.originalName = fileName; 321 e.originalName = fileName;
319 e.contentType = contentType; 322 e.contentType = contentType;
320 e.contentAttribute = contentAttribute; 323 e.contentAttribute = contentAttribute;
321 e.encoding = encoding; 324 e.encoding = encoding;
322 e.body = mimeBody; 325 e.body = mimeBody;
323 e.saved = FALSE; 326 e.saved = FALSE;
324 mail->addEnclosure(&e); 327 mail->addEnclosure(&e);
325 enclosureId++; 328 enclosureId++;
326 329
327 } else if (contentType == "TEXT") { 330 } else if (contentType == "TEXT") {
328 if (contentAttribute == "PLAIN") { 331 if (contentAttribute == "PLAIN") {
329 mail->body = mimeBody; 332 mail->body = mimeBody;
330 mail->bodyPlain = mimeBody; 333 mail->bodyPlain = mimeBody;
331 } 334 }
332 if (contentAttribute == "HTML") { 335 if (contentAttribute == "HTML") {
333 mail->body = mimeBody; 336 mail->body = mimeBody;
334 } 337 }
335 } 338 }
336 } 339 }
337 } else { 340 } else {
338 mail->bodyPlain = body; 341 mail->bodyPlain = body;
339 mail->body = body; 342 mail->body = body;
340 } 343 }
344 delete lp;
341 return TRUE; 345 return TRUE;
342} 346}
343 347
344bool EmailHandler::getEnclosure(Enclosure *ePtr) 348bool EmailHandler::getEnclosure(Enclosure *ePtr)
345{ 349{
346 QFile f(ePtr->path + ePtr->name); 350 QFile f(ePtr->path + ePtr->name);
347 char src[4]; 351 char src[4];
348 char *destPtr; 352 char *destPtr;
349 QByteArray buffer; 353 QByteArray buffer;
350 uint bufCount, pos, decodedCount, size, x; 354 uint bufCount, pos, decodedCount, size, x;
351 355
352 if (! f.open(IO_WriteOnly) ) { 356 if (! f.open(IO_WriteOnly) ) {
353 qWarning("could not save: " + ePtr->path + ePtr->name); 357 qWarning("could not save: " + ePtr->path + ePtr->name);
354 return FALSE; 358 return FALSE;
355 } 359 }
356 360
357 if (ePtr->encoding.upper() == "BASE64") { 361 if (ePtr->encoding.upper() == "BASE64") {
358 size = (ePtr->body.length() * 3 / 4); //approximate size (always above) 362 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
359 buffer.resize(size); 363 buffer.resize(size);
360 bufCount = 0; 364 bufCount = 0;
361 pos = 0; 365 pos = 0;
362 destPtr = buffer.data(); 366 destPtr = buffer.data();
363 367
364 while (pos < ePtr->body.length()) { 368 while (pos < ePtr->body.length()) {
365 decodedCount = 4; 369 decodedCount = 4;
366 x = 0; 370 x = 0;
367 while ( (x < 4) && (pos < ePtr->body.length()) ) { 371 while ( (x < 4) && (pos < ePtr->body.length()) ) {
368 src[x] = ePtr->body[pos].latin1(); 372 src[x] = ePtr->body[pos].latin1();
369 pos++; 373 pos++;
370 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') 374 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
371 x--; 375 x--;
372 x++; 376 x++;
diff --git a/noncore/net/mailit/mailitwindow.cpp b/noncore/net/mailit/mailitwindow.cpp
index a111241..f945a0f 100644
--- a/noncore/net/mailit/mailitwindow.cpp
+++ b/noncore/net/mailit/mailitwindow.cpp
@@ -93,76 +93,76 @@ void MailItWindow::compose()
93 93
94void MailItWindow::composeReply(Email &mail, bool& replyAll) 94void MailItWindow::composeReply(Email &mail, bool& replyAll)
95{ 95{
96 compose(); 96 compose();
97 writeMail->reply(mail,replyAll) ; 97 writeMail->reply(mail,replyAll) ;
98} 98}
99 99
100void MailItWindow::composeForward(Email &mail) 100void MailItWindow::composeForward(Email &mail)
101{ 101{
102 compose(); 102 compose();
103 writeMail->forward(mail) ; 103 writeMail->forward(mail) ;
104} 104}
105 105
106 106
107void MailItWindow::showEmailClient() 107void MailItWindow::showEmailClient()
108{ 108{
109 viewingMail = FALSE; 109 viewingMail = FALSE;
110 writeMail->hide(); 110 writeMail->hide();
111 readMail->hide(); 111 readMail->hide();
112 views->raiseWidget(emailClient); 112 views->raiseWidget(emailClient);
113 setCaption( tr(currentCaption) ); 113 setCaption( tr(currentCaption) );
114} 114}
115 115
116void MailItWindow::viewMail(QListView *view, Email *mail) 116void MailItWindow::viewMail(QListView *view, Email *mail)
117{ 117{
118 viewingMail = TRUE; 118 viewingMail = TRUE;
119 emailClient->hide(); 119 emailClient->hide();
120 120
121 int result=0; 121 int result=0;
122 122
123 if ((mail->received)&&(!mail->downloaded)) 123 if ((mail->received)&&(!mail->downloaded))
124 { 124 {
125 QMessageBox mb( tr("Mail not downloaded"), 125 QMessageBox mb( tr("Mail not downloaded"),
126 tr("The mail you have clicked \n" 126 tr("The mail you have clicked \n"
127 "has not been downloaded yet.\n " 127 "has not been downloaded yet.\n "
128 "Would you like to do it now ?"), 128 "Would you like to do it now ?"),
129 QMessageBox::Information, 129 QMessageBox::Information,
130 QMessageBox::Yes | QMessageBox::Default, 130 QMessageBox::Yes | QMessageBox::Default,
131 QMessageBox::No | QMessageBox::Escape,0 ); 131 QMessageBox::No | QMessageBox::Escape,0 );
132 132
133 result=mb.exec(); 133 result=mb.exec();
134 134
135 if (result==QMessageBox::Yes) 135 if (result==QMessageBox::Yes)
136 { 136 {
137 emailClient->download(mail); 137 emailClient->download(mail);
138 } 138 }
139 } 139 }
140 140
141 readMail->update(view, mail); 141 readMail->update(view, mail);
142 views->raiseWidget(readMail); 142 views->raiseWidget(readMail);
143 setCaption( tr( "Examine mail" ) ); 143 setCaption( tr( "Read Mail" ) );
144} 144}
145 145
146void MailItWindow::updateMailView(Email *mail) 146void MailItWindow::updateMailView(Email *mail)
147{ 147{
148 if (viewingMail) { 148 if (viewingMail) {
149 readMail->mailUpdated(mail); 149 readMail->mailUpdated(mail);
150 } 150 }
151} 151}
152 152
153void MailItWindow::updateCaption(const QString &newCaption) 153void MailItWindow::updateCaption(const QString &newCaption)
154{ 154{
155 currentCaption = newCaption; 155 currentCaption = newCaption;
156 setCaption(tr(currentCaption)); 156 setCaption(tr(currentCaption));
157} 157}
158 158
159void MailItWindow::setDocument(const QString &_address) 159void MailItWindow::setDocument(const QString &_address)
160{ 160{
161 // strip leading 'mailto:' 161 // strip leading 'mailto:'
162 QString address = _address; 162 QString address = _address;
163 if (address.startsWith("mailto:")) 163 if (address.startsWith("mailto:"))
164 address = address.mid(6); 164 address = address.mid(6);
165 165
166 compose(); 166 compose();
167 writeMail->setRecipient(address); 167 writeMail->setRecipient(address);
168} 168}
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp
index 2102ba7..da1226c 100644
--- a/noncore/unsupported/mailit/emailclient.cpp
+++ b/noncore/unsupported/mailit/emailclient.cpp
@@ -440,68 +440,68 @@ void EmailClient::mailArrived(const Email &mail, bool fromDisk)
440 } 440 }
441 } else { 441 } else {
442 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); 442 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
443 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); 443 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
444 if (ePtr->saved) { 444 if (ePtr->saved) {
445 ePtr->name = mailconf->readEntry("filename_" + stringId); 445 ePtr->name = mailconf->readEntry("filename_" + stringId);
446 ePtr->path = mailconf->readEntry("path_" + stringId); 446 ePtr->path = mailconf->readEntry("path_" + stringId);
447 } 447 }
448 } 448 }
449 } 449 }
450 450
451 bool found=false; 451 bool found=false;
452 452
453 if (!fromDisk) 453 if (!fromDisk)
454 { 454 {
455 455
456 Email *mailPtr; 456 Email *mailPtr;
457 item = (EmailListItem *) inboxView->firstChild(); 457 item = (EmailListItem *) inboxView->firstChild();
458 while ((item != NULL)&&(!found)) 458 while ((item != NULL)&&(!found))
459 { 459 {
460 mailPtr = item->getMail(); 460 mailPtr = item->getMail();
461 if (mailPtr->id == newMail.id) { 461 if (mailPtr->id == newMail.id) {
462 item->setMail(newMail); 462 item->setMail(newMail);
463 emit mailUpdated(item->getMail()); 463 emit mailUpdated(item->getMail());
464 found = true; 464 found = true;
465 } 465 }
466 item = (EmailListItem *) item->nextSibling(); 466 item = (EmailListItem *) item->nextSibling();
467 } 467 }
468 } 468 }
469 if ((!found)||(fromDisk)) { 469 if ((!found)||(fromDisk)) {
470 item = new EmailListItem(inboxView, newMail, TRUE); 470 item = new EmailListItem(inboxView, newMail, TRUE);
471 } 471 }
472 if (item->getMail()->files.count()>0) 472// if (item->getMail()->files.count()>0)
473 { 473// {
474 item->setPixmap(0, Resource::loadPixmap("mailit/attach")); 474// item->setPixmap(0, Resource::loadPixmap("mailit/attach"));
475 } 475// }
476 /*if (!newMail.downloaded) 476 /*if (!newMail.downloaded)
477 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ 477 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/
478 478
479 mailboxView->setCurrentTab(0); 479 mailboxView->setCurrentTab(0);
480 480
481} 481}
482 482
483void EmailClient::allMailArrived(int count) 483void EmailClient::allMailArrived(int count)
484{ 484{
485 // not previewing means all mailtransfer has been done 485 // not previewing means all mailtransfer has been done
486 /*if (!previewingMail) {*/ 486 /*if (!previewingMail) {*/
487 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { 487 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
488 emit newCaption("Mailit - " + currentAccount->accountName); 488 emit newCaption("Mailit - " + currentAccount->accountName);
489 getNewMail(); 489 getNewMail();
490 return; 490 return;
491 } else { 491 } else {
492 allAccounts = FALSE; 492 allAccounts = FALSE;
493 receiving = FALSE; 493 receiving = FALSE;
494 getMailButton->setEnabled(TRUE); 494 getMailButton->setEnabled(TRUE);
495 cancelButton->setEnabled(FALSE); 495 cancelButton->setEnabled(FALSE);
496 selectAccountMenu->setEnabled(TRUE); 496 selectAccountMenu->setEnabled(TRUE);
497 status1Label->setText("Idle"); 497 status1Label->setText("Idle");
498 498
499 progressBar->reset(); 499 progressBar->reset();
500 return; 500 return;
501 } 501 }
502 //} 502 //}
503 503
504 // all headers downloaded from server, start downloading remaining mails 504 // all headers downloaded from server, start downloading remaining mails
505 previewingMail = FALSE; 505 previewingMail = FALSE;
506 status1Label->setText(currentAccount->accountName); 506 status1Label->setText(currentAccount->accountName);
507 progressBar->reset(); 507 progressBar->reset();
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp
index 59ccd90..39f693d 100644
--- a/noncore/unsupported/mailit/emailhandler.cpp
+++ b/noncore/unsupported/mailit/emailhandler.cpp
@@ -146,66 +146,68 @@ void EmailHandler::messageArrived(const QString &message, int id, uint size, boo
146 mail.downloaded = complete; 146 mail.downloaded = complete;
147 147
148 emit mailArrived(mail, FALSE); 148 emit mailArrived(mail, FALSE);
149} 149}
150 150
151bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) 151bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail)
152{ 152{
153 QString temp, boundary; 153 QString temp, boundary;
154 int pos; 154 int pos;
155 QString delimiter, header, body, mimeHeader, mimeBody; 155 QString delimiter, header, body, mimeHeader, mimeBody;
156 QString content, contentType, contentAttribute, id, encoding; 156 QString content, contentType, contentAttribute, id, encoding;
157 QString fileName, storedName; 157 QString fileName, storedName;
158 int enclosureId = 0; 158 int enclosureId = 0;
159 159
160 mail->rawMail = in; 160 mail->rawMail = in;
161 mail->received = TRUE; 161 mail->received = TRUE;
162 mail->files.setAutoDelete(TRUE); 162 mail->files.setAutoDelete(TRUE);
163 163
164 temp = lineShift + "." + lineShift; 164 temp = lineShift + "." + lineShift;
165 165
166 if (in.right(temp.length()) != temp) { 166 if (in.right(temp.length()) != temp) {
167 mail->rawMail += temp; 167 mail->rawMail += temp;
168 } 168 }
169 169
170 170
171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" 171 delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n"
172 pos = in.find(delimiter, 0, FALSE); 172 pos = in.find(delimiter, 0, FALSE);
173 header = in.left(pos); 173 header = in.left(pos);
174 body = in.right(in.length() - pos - delimiter.length()); 174 body = in.right(in.length() - pos - delimiter.length());
175 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'))
176 body.truncate(body.length()-2); 176 body.truncate(body.length()-2);
177 177
178 TextParser p(header, lineShift); 178 // TextParser p(header, lineShift);
179 179 TextParser * lp = new TextParser(header, lineShift);
180#define p (*lp)
181
180 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { 182 if ((pos = p.find("FROM",':', 0, TRUE)) != -1) {
181 pos++; 183 pos++;
182 if (p.separatorAt(pos) == ' ') { 184 if (p.separatorAt(pos) == ' ') {
183 mail->from = p.getString(&pos, '<', false); 185 mail->from = p.getString(&pos, '<', false);
184 mail->from = mail->from.stripWhiteSpace(); 186 mail->from = mail->from.stripWhiteSpace();
185 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { 187 if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) {
186 mail->from = mail->from.left(mail->from.length() - 1); 188 mail->from = mail->from.left(mail->from.length() - 1);
187 mail->from = mail->from.right(mail->from.length() - 1); 189 mail->from = mail->from.right(mail->from.length() - 1);
188 } 190 }
189 pos++; 191 pos++;
190 mail->fromMail = p.getString(&pos, '>', false); 192 mail->fromMail = p.getString(&pos, '>', false);
191 } else { 193 } else {
192 if (p.separatorAt(pos) == '<') //No name.. nasty 194 if (p.separatorAt(pos) == '<') //No name.. nasty
193 pos++; 195 pos++;
194 //pos++; 196 //pos++;
195 mail->fromMail = p.getString(&pos, 'z', TRUE); 197 mail->fromMail = p.getString(&pos, 'z', TRUE);
196 if (mail->fromMail.at(mail->fromMail.length()-1) == '>') 198 if (mail->fromMail.at(mail->fromMail.length()-1) == '>')
197 mail->fromMail.truncate(mail->fromMail.length() - 1); 199 mail->fromMail.truncate(mail->fromMail.length() - 1);
198 mail->from=mail->fromMail; 200 mail->from=mail->fromMail;
199 } 201 }
200 } 202 }
201 203
202 pos=0; 204 pos=0;
203 205
204 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: 206 //Search for To: after the FROM: attribute to prevent hitting the Delivered-To:
205 while((pos = p.find("TO",':', pos+1, TRUE))!=-1) 207 while((pos = p.find("TO",':', pos+1, TRUE))!=-1)
206 { 208 {
207 QString rec; 209 QString rec;
208 210
209 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: 211 if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To:
210 { 212 {
211 pos++; 213 pos++;
@@ -241,64 +243,65 @@ bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mai
241 id = p.getString(&pos, 'z', TRUE); 243 id = p.getString(&pos, 'z', TRUE);
242 mail->id = id; 244 mail->id = id;
243 } 245 }
244 } 246 }
245 247
246 pos = 0; 248 pos = 0;
247 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { 249 while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) {
248 pos++; 250 pos++;
249 if ( (p.wordAt(pos).upper() == "VERSION") && 251 if ( (p.wordAt(pos).upper() == "VERSION") &&
250 (p.separatorAt(pos) == ':') ) { 252 (p.separatorAt(pos) == ':') ) {
251 pos++; 253 pos++;
252 if (p.getString(&pos, 'z', true) == "1.0") { 254 if (p.getString(&pos, 'z', true) == "1.0") {
253 mail->mimeType = 1; 255 mail->mimeType = 1;
254 } 256 }
255 } 257 }
256 } 258 }
257 259
258 if (mail->mimeType == 1) { 260 if (mail->mimeType == 1) {
259 boundary = ""; 261 boundary = "";
260 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { 262 if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) {
261 pos++; 263 pos++;
262 boundary = p.getString(&pos, 'z', true); 264 boundary = p.getString(&pos, 'z', true);
263 if (boundary[0] == '"') { 265 if (boundary[0] == '"') {
264 boundary = boundary.left(boundary.length() - 1); //strip " 266 boundary = boundary.left(boundary.length() - 1); //strip "
265 boundary = boundary.right(boundary.length() - 1); //strip " 267 boundary = boundary.right(boundary.length() - 1); //strip "
266 } 268 }
267 boundary = "--" + boundary; //create boundary field 269 boundary = "--" + boundary; //create boundary field
268 } 270 }
269 271
270 if (boundary == "") { //fooled by Mime-Version 272 if (boundary == "") { //fooled by Mime-Version
271 mail->body = body; 273 mail->body = body;
272 mail->bodyPlain = body; 274 mail->bodyPlain = body;
275 delete lp;
273 return mail; 276 return mail;
274 } 277 }
275 278
276 while (body.length() > 0) { 279 while (body.length() > 0) {
277 pos = body.find(boundary, 0, FALSE); 280 pos = body.find(boundary, 0, FALSE);
278 pos = body.find(delimiter, pos, FALSE); 281 pos = body.find(delimiter, pos, FALSE);
279 mimeHeader = body.left(pos); 282 mimeHeader = body.left(pos);
280 mimeBody = body.right(body.length() - pos - delimiter.length()); 283 mimeBody = body.right(body.length() - pos - delimiter.length());
281 TextParser bp(mimeHeader, lineShift); 284 TextParser bp(mimeHeader, lineShift);
282 285
283 contentType = ""; 286 contentType = "";
284 contentAttribute = ""; 287 contentAttribute = "";
285 fileName = ""; 288 fileName = "";
286 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { 289 if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) {
287 pos++; 290 pos++;
288 if ( (bp.wordAt(pos).upper() == "TYPE") && 291 if ( (bp.wordAt(pos).upper() == "TYPE") &&
289 (bp.separatorAt(pos) == ':') ) { 292 (bp.separatorAt(pos) == ':') ) {
290 contentType = bp.nextWord().upper(); 293 contentType = bp.nextWord().upper();
291 if (bp.nextSeparator() == '/') 294 if (bp.nextSeparator() == '/')
292 contentAttribute = bp.nextWord().upper(); 295 contentAttribute = bp.nextWord().upper();
293 content = contentType + "/" + contentAttribute; 296 content = contentType + "/" + contentAttribute;
294 } 297 }
295 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { 298 if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) {
296 pos++; 299 pos++;
297 encoding = bp.getString(&pos, 'z', TRUE); 300 encoding = bp.getString(&pos, 'z', TRUE);
298 } 301 }
299 302
300 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { 303 if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) {
301 pos++; 304 pos++;
302 fileName = bp.getString(&pos, 'z', TRUE); 305 fileName = bp.getString(&pos, 'z', TRUE);
303 fileName = fileName.right(fileName.length() - 1); 306 fileName = fileName.right(fileName.length() - 1);
304 fileName = fileName.left(fileName.length() - 1); 307 fileName = fileName.left(fileName.length() - 1);
@@ -309,64 +312,65 @@ bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mai
309 if (pos == -1) //should not occur, malformed mail 312 if (pos == -1) //should not occur, malformed mail
310 pos = mimeBody.length(); 313 pos = mimeBody.length();
311 body = mimeBody.right(mimeBody.length() - pos); 314 body = mimeBody.right(mimeBody.length() - pos);
312 mimeBody = mimeBody.left(pos); 315 mimeBody = mimeBody.left(pos);
313 316
314 if (fileName != "") { //attatchments of some type, audio, image etc. 317 if (fileName != "") { //attatchments of some type, audio, image etc.
315 318
316 Enclosure e; 319 Enclosure e;
317 e.id = enclosureId; 320 e.id = enclosureId;
318 e.originalName = fileName; 321 e.originalName = fileName;
319 e.contentType = contentType; 322 e.contentType = contentType;
320 e.contentAttribute = contentAttribute; 323 e.contentAttribute = contentAttribute;
321 e.encoding = encoding; 324 e.encoding = encoding;
322 e.body = mimeBody; 325 e.body = mimeBody;
323 e.saved = FALSE; 326 e.saved = FALSE;
324 mail->addEnclosure(&e); 327 mail->addEnclosure(&e);
325 enclosureId++; 328 enclosureId++;
326 329
327 } else if (contentType == "TEXT") { 330 } else if (contentType == "TEXT") {
328 if (contentAttribute == "PLAIN") { 331 if (contentAttribute == "PLAIN") {
329 mail->body = mimeBody; 332 mail->body = mimeBody;
330 mail->bodyPlain = mimeBody; 333 mail->bodyPlain = mimeBody;
331 } 334 }
332 if (contentAttribute == "HTML") { 335 if (contentAttribute == "HTML") {
333 mail->body = mimeBody; 336 mail->body = mimeBody;
334 } 337 }
335 } 338 }
336 } 339 }
337 } else { 340 } else {
338 mail->bodyPlain = body; 341 mail->bodyPlain = body;
339 mail->body = body; 342 mail->body = body;
340 } 343 }
344 delete lp;
341 return TRUE; 345 return TRUE;
342} 346}
343 347
344bool EmailHandler::getEnclosure(Enclosure *ePtr) 348bool EmailHandler::getEnclosure(Enclosure *ePtr)
345{ 349{
346 QFile f(ePtr->path + ePtr->name); 350 QFile f(ePtr->path + ePtr->name);
347 char src[4]; 351 char src[4];
348 char *destPtr; 352 char *destPtr;
349 QByteArray buffer; 353 QByteArray buffer;
350 uint bufCount, pos, decodedCount, size, x; 354 uint bufCount, pos, decodedCount, size, x;
351 355
352 if (! f.open(IO_WriteOnly) ) { 356 if (! f.open(IO_WriteOnly) ) {
353 qWarning("could not save: " + ePtr->path + ePtr->name); 357 qWarning("could not save: " + ePtr->path + ePtr->name);
354 return FALSE; 358 return FALSE;
355 } 359 }
356 360
357 if (ePtr->encoding.upper() == "BASE64") { 361 if (ePtr->encoding.upper() == "BASE64") {
358 size = (ePtr->body.length() * 3 / 4); //approximate size (always above) 362 size = (ePtr->body.length() * 3 / 4); //approximate size (always above)
359 buffer.resize(size); 363 buffer.resize(size);
360 bufCount = 0; 364 bufCount = 0;
361 pos = 0; 365 pos = 0;
362 destPtr = buffer.data(); 366 destPtr = buffer.data();
363 367
364 while (pos < ePtr->body.length()) { 368 while (pos < ePtr->body.length()) {
365 decodedCount = 4; 369 decodedCount = 4;
366 x = 0; 370 x = 0;
367 while ( (x < 4) && (pos < ePtr->body.length()) ) { 371 while ( (x < 4) && (pos < ePtr->body.length()) ) {
368 src[x] = ePtr->body[pos].latin1(); 372 src[x] = ePtr->body[pos].latin1();
369 pos++; 373 pos++;
370 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') 374 if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ')
371 x--; 375 x--;
372 x++; 376 x++;
diff --git a/noncore/unsupported/mailit/mailitwindow.cpp b/noncore/unsupported/mailit/mailitwindow.cpp
index a111241..f945a0f 100644
--- a/noncore/unsupported/mailit/mailitwindow.cpp
+++ b/noncore/unsupported/mailit/mailitwindow.cpp
@@ -93,76 +93,76 @@ void MailItWindow::compose()
93 93
94void MailItWindow::composeReply(Email &mail, bool& replyAll) 94void MailItWindow::composeReply(Email &mail, bool& replyAll)
95{ 95{
96 compose(); 96 compose();
97 writeMail->reply(mail,replyAll) ; 97 writeMail->reply(mail,replyAll) ;
98} 98}
99 99
100void MailItWindow::composeForward(Email &mail) 100void MailItWindow::composeForward(Email &mail)
101{ 101{
102 compose(); 102 compose();
103 writeMail->forward(mail) ; 103 writeMail->forward(mail) ;
104} 104}
105 105
106 106
107void MailItWindow::showEmailClient() 107void MailItWindow::showEmailClient()
108{ 108{
109 viewingMail = FALSE; 109 viewingMail = FALSE;
110 writeMail->hide(); 110 writeMail->hide();
111 readMail->hide(); 111 readMail->hide();
112 views->raiseWidget(emailClient); 112 views->raiseWidget(emailClient);
113 setCaption( tr(currentCaption) ); 113 setCaption( tr(currentCaption) );
114} 114}
115 115
116void MailItWindow::viewMail(QListView *view, Email *mail) 116void MailItWindow::viewMail(QListView *view, Email *mail)
117{ 117{
118 viewingMail = TRUE; 118 viewingMail = TRUE;
119 emailClient->hide(); 119 emailClient->hide();
120 120
121 int result=0; 121 int result=0;
122 122
123 if ((mail->received)&&(!mail->downloaded)) 123 if ((mail->received)&&(!mail->downloaded))
124 { 124 {
125 QMessageBox mb( tr("Mail not downloaded"), 125 QMessageBox mb( tr("Mail not downloaded"),
126 tr("The mail you have clicked \n" 126 tr("The mail you have clicked \n"
127 "has not been downloaded yet.\n " 127 "has not been downloaded yet.\n "
128 "Would you like to do it now ?"), 128 "Would you like to do it now ?"),
129 QMessageBox::Information, 129 QMessageBox::Information,
130 QMessageBox::Yes | QMessageBox::Default, 130 QMessageBox::Yes | QMessageBox::Default,
131 QMessageBox::No | QMessageBox::Escape,0 ); 131 QMessageBox::No | QMessageBox::Escape,0 );
132 132
133 result=mb.exec(); 133 result=mb.exec();
134 134
135 if (result==QMessageBox::Yes) 135 if (result==QMessageBox::Yes)
136 { 136 {
137 emailClient->download(mail); 137 emailClient->download(mail);
138 } 138 }
139 } 139 }
140 140
141 readMail->update(view, mail); 141 readMail->update(view, mail);
142 views->raiseWidget(readMail); 142 views->raiseWidget(readMail);
143 setCaption( tr( "Examine mail" ) ); 143 setCaption( tr( "Read Mail" ) );
144} 144}
145 145
146void MailItWindow::updateMailView(Email *mail) 146void MailItWindow::updateMailView(Email *mail)
147{ 147{
148 if (viewingMail) { 148 if (viewingMail) {
149 readMail->mailUpdated(mail); 149 readMail->mailUpdated(mail);
150 } 150 }
151} 151}
152 152
153void MailItWindow::updateCaption(const QString &newCaption) 153void MailItWindow::updateCaption(const QString &newCaption)
154{ 154{
155 currentCaption = newCaption; 155 currentCaption = newCaption;
156 setCaption(tr(currentCaption)); 156 setCaption(tr(currentCaption));
157} 157}
158 158
159void MailItWindow::setDocument(const QString &_address) 159void MailItWindow::setDocument(const QString &_address)
160{ 160{
161 // strip leading 'mailto:' 161 // strip leading 'mailto:'
162 QString address = _address; 162 QString address = _address;
163 if (address.startsWith("mailto:")) 163 if (address.startsWith("mailto:"))
164 address = address.mid(6); 164 address = address.mid(6);
165 165
166 compose(); 166 compose();
167 writeMail->setRecipient(address); 167 writeMail->setRecipient(address);
168} 168}