author | groucho <groucho> | 2003-04-15 08:07:53 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-04-15 08:07:53 (UTC) |
commit | d0de397e46581f6ed5fcfad320b2b61be3858c5d (patch) (unidiff) | |
tree | 1110503d72aa11947642a640ab50656f82c33a71 | |
parent | e263613e83b64fa93b5f3c1b904715daf076cc78 (diff) | |
download | opie-d0de397e46581f6ed5fcfad320b2b61be3858c5d.zip opie-d0de397e46581f6ed5fcfad320b2b61be3858c5d.tar.gz opie-d0de397e46581f6ed5fcfad320b2b61be3858c5d.tar.bz2 |
- SMTP fix preventing authorization with SMTP after POP
- removed debug output
- smaller bug fixes
-rw-r--r-- | noncore/net/mailit/addresslist.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mailit/emailclient.cpp | 8 | ||||
-rw-r--r-- | noncore/net/mailit/emailhandler.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mailit/mailitwindow.cpp | 3 | ||||
-rw-r--r-- | noncore/net/mailit/popclient.cpp | 10 | ||||
-rw-r--r-- | noncore/net/mailit/readmail.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mailit/smtpclient.cpp | 20 | ||||
-rw-r--r-- | noncore/unsupported/mailit/addresslist.cpp | 2 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailclient.cpp | 8 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailhandler.cpp | 2 | ||||
-rw-r--r-- | noncore/unsupported/mailit/mailitwindow.cpp | 3 | ||||
-rw-r--r-- | noncore/unsupported/mailit/popclient.cpp | 10 | ||||
-rw-r--r-- | noncore/unsupported/mailit/readmail.cpp | 1 | ||||
-rw-r--r-- | noncore/unsupported/mailit/smtpclient.cpp | 20 |
14 files changed, 42 insertions, 50 deletions
diff --git a/noncore/net/mailit/addresslist.cpp b/noncore/net/mailit/addresslist.cpp index 9fe558a..8d9ab91 100644 --- a/noncore/net/mailit/addresslist.cpp +++ b/noncore/net/mailit/addresslist.cpp | |||
@@ -1,161 +1,161 @@ | |||
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 <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qtextstream.h> | 21 | #include <qtextstream.h> |
22 | #include <opie/ocontactaccess.h> | 22 | #include <opie/ocontactaccess.h> |
23 | #include <opie/ocontact.h> | 23 | #include <opie/ocontact.h> |
24 | 24 | ||
25 | #include "addresslist.h" | 25 | #include "addresslist.h" |
26 | 26 | ||
27 | AddressList::AddressList() | 27 | AddressList::AddressList() |
28 | { | 28 | { |
29 | addresses.setAutoDelete(TRUE); | 29 | addresses.setAutoDelete(TRUE); |
30 | read(); | 30 | read(); |
31 | dirty = FALSE; | 31 | dirty = FALSE; |
32 | } | 32 | } |
33 | 33 | ||
34 | AddressList::~AddressList() | 34 | AddressList::~AddressList() |
35 | { | 35 | { |
36 | addresses.clear(); | 36 | addresses.clear(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void AddressList::addContact(QString email, QString name) | 39 | void AddressList::addContact(QString email, QString name) |
40 | { | 40 | { |
41 | //skip if not a valid email address, | 41 | //skip if not a valid email address, |
42 | if (email.find( '@') == -1) | 42 | if (email.find( '@') == -1) |
43 | return; | 43 | return; |
44 | 44 | ||
45 | if ( ! containsEmail(email) ) { | 45 | if ( ! containsEmail(email) ) { |
46 | Contact *in = new Contact; | 46 | Contact *in = new Contact; |
47 | in->email = email; | 47 | in->email = email; |
48 | in->name = name; | 48 | in->name = name; |
49 | addresses.append(in); | 49 | addresses.append(in); |
50 | dirty = TRUE; | 50 | dirty = TRUE; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | bool AddressList::containsEmail(QString email) | 54 | bool AddressList::containsEmail(QString email) |
55 | { | 55 | { |
56 | return ( getEmailRef(email) != -1 ); | 56 | return ( getEmailRef(email) != -1 ); |
57 | } | 57 | } |
58 | 58 | ||
59 | bool AddressList::containsName(QString name) | 59 | bool AddressList::containsName(QString name) |
60 | { | 60 | { |
61 | return ( getNameRef(name) != -1 ); | 61 | return ( getNameRef(name) != -1 ); |
62 | } | 62 | } |
63 | 63 | ||
64 | QString AddressList::getNameByEmail(QString email) | 64 | QString AddressList::getNameByEmail(QString email) |
65 | { | 65 | { |
66 | int pos = getEmailRef(email); | 66 | int pos = getEmailRef(email); |
67 | if (pos != -1) { | 67 | if (pos != -1) { |
68 | Contact *ptr = addresses.at(pos); | 68 | Contact *ptr = addresses.at(pos); |
69 | return ptr->name; | 69 | return ptr->name; |
70 | } | 70 | } |
71 | 71 | ||
72 | return NULL; | 72 | return NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | QString AddressList::getEmailByName(QString name) | 75 | QString AddressList::getEmailByName(QString name) |
76 | { | 76 | { |
77 | int pos = getNameRef(name); | 77 | int pos = getNameRef(name); |
78 | if (pos != -1) { | 78 | if (pos != -1) { |
79 | Contact *ptr = addresses.at(pos); | 79 | Contact *ptr = addresses.at(pos); |
80 | return ptr->email; | 80 | return ptr->email; |
81 | } | 81 | } |
82 | 82 | ||
83 | return NULL; | 83 | return NULL; |
84 | } | 84 | } |
85 | 85 | ||
86 | int AddressList::getEmailRef(QString email) | 86 | int AddressList::getEmailRef(QString email) |
87 | { | 87 | { |
88 | int pos = 0; | 88 | int pos = 0; |
89 | Contact *ptr; | 89 | Contact *ptr; |
90 | 90 | ||
91 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { | 91 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { |
92 | if (ptr->email == email) | 92 | if (ptr->email == email) |
93 | return pos; | 93 | return pos; |
94 | pos++; | 94 | pos++; |
95 | } | 95 | } |
96 | return -1; | 96 | return -1; |
97 | } | 97 | } |
98 | 98 | ||
99 | int AddressList::getNameRef(QString name) | 99 | int AddressList::getNameRef(QString name) |
100 | { | 100 | { |
101 | int pos = 0; | 101 | int pos = 0; |
102 | Contact *ptr; | 102 | Contact *ptr; |
103 | 103 | ||
104 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { | 104 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { |
105 | if (ptr->name == name) | 105 | if (ptr->name == name) |
106 | return pos; | 106 | return pos; |
107 | pos++; | 107 | pos++; |
108 | } | 108 | } |
109 | return -1; | 109 | return -1; |
110 | } | 110 | } |
111 | 111 | ||
112 | QList<Contact>* AddressList::getContactList() | 112 | QList<Contact>* AddressList::getContactList() |
113 | { | 113 | { |
114 | return &addresses; | 114 | return &addresses; |
115 | } | 115 | } |
116 | 116 | ||
117 | void AddressList::read() | 117 | void AddressList::read() |
118 | { | 118 | { |
119 | OContactAccess::List::Iterator it; | 119 | OContactAccess::List::Iterator it; |
120 | 120 | ||
121 | QString lineEmail, lineName, email, name; | 121 | QString lineEmail, lineName, email, name; |
122 | OContactAccess m_contactdb("mailit"); | 122 | OContactAccess m_contactdb("mailit"); |
123 | OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); | 123 | OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); |
124 | //OContact* oc; | 124 | //OContact* oc; |
125 | 125 | ||
126 | for ( it = m_list.begin(); it != m_list.end(); ++it ) | 126 | for ( it = m_list.begin(); it != m_list.end(); ++it ) |
127 | { | 127 | { |
128 | //oc=(OContact*) it; | 128 | //oc=(OContact*) it; |
129 | if ((*it).defaultEmail().length()!=0) | 129 | if ((*it).defaultEmail().length()!=0) |
130 | addContact((*it).defaultEmail(),(*it).fullName()); | 130 | addContact((*it).defaultEmail(),(*it).fileAs()); |
131 | } | 131 | } |
132 | 132 | ||
133 | /*if (! f.open(IO_ReadOnly) ) | 133 | /*if (! f.open(IO_ReadOnly) ) |
134 | return; | 134 | return; |
135 | 135 | ||
136 | QTextStream stream(&f); | 136 | QTextStream stream(&f); |
137 | 137 | ||
138 | while (! stream.atEnd() ) { | 138 | while (! stream.atEnd() ) { |
139 | lineEmail = stream.readLine(); | 139 | lineEmail = stream.readLine(); |
140 | if (! stream.atEnd() ) | 140 | if (! stream.atEnd() ) |
141 | lineName = stream.readLine(); | 141 | lineName = stream.readLine(); |
142 | else return; | 142 | else return; |
143 | 143 | ||
144 | email = getRightString(lineEmail); | 144 | email = getRightString(lineEmail); |
145 | name = getRightString(lineName); | 145 | name = getRightString(lineName); |
146 | addContact(email, name); | 146 | addContact(email, name); |
147 | } | 147 | } |
148 | f.close();*/ | 148 | f.close();*/ |
149 | } | 149 | } |
150 | 150 | ||
151 | QString AddressList::getRightString(QString in) | 151 | QString AddressList::getRightString(QString in) |
152 | { | 152 | { |
153 | QString out = ""; | 153 | QString out = ""; |
154 | 154 | ||
155 | int pos = in.find('='); | 155 | int pos = in.find('='); |
156 | if (pos != -1) { | 156 | if (pos != -1) { |
157 | out = in.mid(pos+1).stripWhiteSpace(); | 157 | out = in.mid(pos+1).stripWhiteSpace(); |
158 | } | 158 | } |
159 | return out; | 159 | return out; |
160 | } | 160 | } |
161 | 161 | ||
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp index 6612541..0d82a9a 100644 --- a/noncore/net/mailit/emailclient.cpp +++ b/noncore/net/mailit/emailclient.cpp | |||
@@ -279,572 +279,572 @@ void EmailClient::mailSent() | |||
279 | void EmailClient::getNewMail() { | 279 | void EmailClient::getNewMail() { |
280 | 280 | ||
281 | if (accountList.count() == 0) { | 281 | if (accountList.count() == 0) { |
282 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 282 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
283 | "You must create an account", "OK\n"); | 283 | "You must create an account", "OK\n"); |
284 | return; | 284 | return; |
285 | } | 285 | } |
286 | 286 | ||
287 | setMailAccount(); | 287 | setMailAccount(); |
288 | 288 | ||
289 | receiving = TRUE; | 289 | receiving = TRUE; |
290 | previewingMail = TRUE; | 290 | previewingMail = TRUE; |
291 | getMailButton->setEnabled(FALSE); | 291 | getMailButton->setEnabled(FALSE); |
292 | cancelButton->setEnabled(TRUE); | 292 | cancelButton->setEnabled(TRUE); |
293 | selectAccountMenu->setEnabled(FALSE); | 293 | selectAccountMenu->setEnabled(FALSE); |
294 | 294 | ||
295 | status1Label->setText(currentAccount->accountName + " headers"); | 295 | status1Label->setText(currentAccount->accountName + " headers"); |
296 | progressBar->reset(); | 296 | progressBar->reset(); |
297 | 297 | ||
298 | //get any previous mails not downloaded and add to queue | 298 | //get any previous mails not downloaded and add to queue |
299 | mailDownloadList.clear(); | 299 | mailDownloadList.clear(); |
300 | Email *mailPtr; | 300 | Email *mailPtr; |
301 | item = (EmailListItem *) inboxView->firstChild(); | 301 | item = (EmailListItem *) inboxView->firstChild(); |
302 | while (item != NULL) { | 302 | while (item != NULL) { |
303 | mailPtr = item->getMail(); | 303 | mailPtr = item->getMail(); |
304 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 304 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
305 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 305 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
306 | } | 306 | } |
307 | item = (EmailListItem *) item->nextSibling(); | 307 | item = (EmailListItem *) item->nextSibling(); |
308 | } | 308 | } |
309 | 309 | ||
310 | emailHandler->getMailHeaders(); | 310 | emailHandler->getMailHeaders(); |
311 | } | 311 | } |
312 | 312 | ||
313 | void EmailClient::getAllNewMail() | 313 | void EmailClient::getAllNewMail() |
314 | { | 314 | { |
315 | allAccounts = TRUE; | 315 | allAccounts = TRUE; |
316 | currentAccount = accountList.first(); | 316 | currentAccount = accountList.first(); |
317 | getNewMail(); | 317 | getNewMail(); |
318 | } | 318 | } |
319 | 319 | ||
320 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 320 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
321 | { | 321 | { |
322 | Enclosure *ePtr; | 322 | Enclosure *ePtr; |
323 | Email newMail; | 323 | Email newMail; |
324 | int thisMailId; | 324 | int thisMailId; |
325 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 325 | emailHandler->parse(mail.rawMail, lineShift, &newMail); |
326 | 326 | ||
327 | mailconf->setGroup(newMail.id); | 327 | mailconf->setGroup(newMail.id); |
328 | 328 | ||
329 | if (fromDisk) { | 329 | if (fromDisk) { |
330 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 330 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
331 | newMail.size = mailconf->readNumEntry("size"); | 331 | newMail.size = mailconf->readNumEntry("size"); |
332 | newMail.serverId = mailconf->readNumEntry("serverid"); | 332 | newMail.serverId = mailconf->readNumEntry("serverid"); |
333 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 333 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
334 | } else { //mail arrived from server | 334 | } else { //mail arrived from server |
335 | newMail.serverId = mail.serverId; | 335 | newMail.serverId = mail.serverId; |
336 | newMail.size = mail.size; | 336 | newMail.size = mail.size; |
337 | newMail.downloaded = mail.downloaded; | 337 | newMail.downloaded = mail.downloaded; |
338 | 338 | ||
339 | newMail.fromAccountId = currentAccount->id; | 339 | newMail.fromAccountId = currentAccount->id; |
340 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 340 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
341 | } | 341 | } |
342 | 342 | ||
343 | //add if read or not | 343 | //add if read or not |
344 | newMail.read = mailconf->readBoolEntry("mailread"); | 344 | newMail.read = mailconf->readBoolEntry("mailread"); |
345 | 345 | ||
346 | //check if new mail | 346 | //check if new mail |
347 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 347 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
348 | thisMailId = mailIdCount; | 348 | thisMailId = mailIdCount; |
349 | mailIdCount++; | 349 | mailIdCount++; |
350 | 350 | ||
351 | //set server count, so that if the user aborts, the new | 351 | //set server count, so that if the user aborts, the new |
352 | //header is not reloaded | 352 | //header is not reloaded |
353 | if (currentAccount->synchronize) | 353 | if (currentAccount->synchronize) |
354 | currentAccount->lastServerMailCount++; | 354 | currentAccount->lastServerMailCount++; |
355 | 355 | ||
356 | mailconf->writeEntry("internalmailid", thisMailId); | 356 | mailconf->writeEntry("internalmailid", thisMailId); |
357 | mailconf->writeEntry("downloaded", newMail.downloaded); | 357 | mailconf->writeEntry("downloaded", newMail.downloaded); |
358 | mailconf->writeEntry("size", (int) newMail.size); | 358 | mailconf->writeEntry("size", (int) newMail.size); |
359 | mailconf->writeEntry("serverid", newMail.serverId); | 359 | mailconf->writeEntry("serverid", newMail.serverId); |
360 | 360 | ||
361 | addressList->addContact(newMail.fromMail, newMail.from); | 361 | addressList->addContact(newMail.fromMail, newMail.from); |
362 | } else if (!fromDisk) { //body to header arrived | 362 | } else if (!fromDisk) { //body to header arrived |
363 | mailconf->writeEntry("downloaded", TRUE); | 363 | mailconf->writeEntry("downloaded", TRUE); |
364 | } | 364 | } |
365 | QString stringMailId; | 365 | QString stringMailId; |
366 | stringMailId.setNum(thisMailId); | 366 | stringMailId.setNum(thisMailId); |
367 | //se if any attatchments needs to be stored | 367 | //se if any attatchments needs to be stored |
368 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { | 368 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { |
369 | QString stringId; | 369 | QString stringId; |
370 | stringId.setNum(ePtr->id); | 370 | stringId.setNum(ePtr->id); |
371 | 371 | ||
372 | int id = mailconf->readNumEntry("enclosureid_" + stringId); | 372 | int id = mailconf->readNumEntry("enclosureid_" + stringId); |
373 | if (id != ePtr->id) { //new entry | 373 | if (id != ePtr->id) { //new entry |
374 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); | 374 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); |
375 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); | 375 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); |
376 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); | 376 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); |
377 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); | 377 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); |
378 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 378 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
379 | mailconf->writeEntry("installed_" + stringId, FALSE); | 379 | mailconf->writeEntry("installed_" + stringId, FALSE); |
380 | 380 | ||
381 | ePtr->name = stringMailId + "_" + stringId; | 381 | ePtr->name = stringMailId + "_" + stringId; |
382 | ePtr->path = getPath(TRUE); | 382 | ePtr->path = getPath(TRUE); |
383 | if (emailHandler->getEnclosure(ePtr)) { //file saved | 383 | if (emailHandler->getEnclosure(ePtr)) { //file saved |
384 | ePtr->saved = TRUE; | 384 | ePtr->saved = TRUE; |
385 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 385 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
386 | mailconf->writeEntry("filename_" + stringId, ePtr->name); | 386 | mailconf->writeEntry("filename_" + stringId, ePtr->name); |
387 | mailconf->writeEntry("path_" + stringId, ePtr->path); | 387 | mailconf->writeEntry("path_" + stringId, ePtr->path); |
388 | } else { | 388 | } else { |
389 | ePtr->saved = FALSE; | 389 | ePtr->saved = FALSE; |
390 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 390 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
391 | } | 391 | } |
392 | } else { | 392 | } else { |
393 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); | 393 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); |
394 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); | 394 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); |
395 | if (ePtr->saved) { | 395 | if (ePtr->saved) { |
396 | ePtr->name = mailconf->readEntry("filename_" + stringId); | 396 | ePtr->name = mailconf->readEntry("filename_" + stringId); |
397 | ePtr->path = mailconf->readEntry("path_" + stringId); | 397 | ePtr->path = mailconf->readEntry("path_" + stringId); |
398 | } | 398 | } |
399 | } | 399 | } |
400 | } | 400 | } |
401 | if (!previewingMail && !fromDisk) { | 401 | if (!previewingMail && !fromDisk) { |
402 | Email *mailPtr; | 402 | Email *mailPtr; |
403 | item = (EmailListItem *) inboxView->firstChild(); | 403 | item = (EmailListItem *) inboxView->firstChild(); |
404 | while (item != NULL) { | 404 | while (item != NULL) { |
405 | mailPtr = item->getMail(); | 405 | mailPtr = item->getMail(); |
406 | if (mailPtr->id == newMail.id) { | 406 | if (mailPtr->id == newMail.id) { |
407 | item->setMail(newMail); | 407 | item->setMail(newMail); |
408 | emit mailUpdated(item->getMail()); | 408 | emit mailUpdated(item->getMail()); |
409 | } | 409 | } |
410 | item = (EmailListItem *) item->nextSibling(); | 410 | item = (EmailListItem *) item->nextSibling(); |
411 | } | 411 | } |
412 | } else { | 412 | } else { |
413 | item = new EmailListItem(inboxView, newMail, TRUE); | 413 | item = new EmailListItem(inboxView, newMail, TRUE); |
414 | if (!newMail.downloaded) | 414 | if (!newMail.downloaded) |
415 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size); | 415 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size); |
416 | } | 416 | } |
417 | 417 | ||
418 | } | 418 | } |
419 | 419 | ||
420 | void EmailClient::allMailArrived(int count) | 420 | void EmailClient::allMailArrived(int count) |
421 | { | 421 | { |
422 | // not previewing means all mailtransfer has been done | 422 | // not previewing means all mailtransfer has been done |
423 | if (!previewingMail) { | 423 | if (!previewingMail) { |
424 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 424 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
425 | emit newCaption("Mailit - " + currentAccount->accountName); | 425 | emit newCaption("Mailit - " + currentAccount->accountName); |
426 | getNewMail(); | 426 | getNewMail(); |
427 | return; | 427 | return; |
428 | } else { | 428 | } else { |
429 | allAccounts = FALSE; | 429 | allAccounts = FALSE; |
430 | receiving = FALSE; | 430 | receiving = FALSE; |
431 | getMailButton->setEnabled(TRUE); | 431 | getMailButton->setEnabled(TRUE); |
432 | cancelButton->setEnabled(FALSE); | 432 | cancelButton->setEnabled(FALSE); |
433 | selectAccountMenu->setEnabled(TRUE); | 433 | selectAccountMenu->setEnabled(TRUE); |
434 | status1Label->setText("Idle"); | 434 | status1Label->setText("Idle"); |
435 | 435 | ||
436 | progressBar->reset(); | 436 | progressBar->reset(); |
437 | return; | 437 | return; |
438 | } | 438 | } |
439 | } | 439 | } |
440 | 440 | ||
441 | // all headers downloaded from server, start downloading remaining mails | 441 | // all headers downloaded from server, start downloading remaining mails |
442 | previewingMail = FALSE; | 442 | previewingMail = FALSE; |
443 | status1Label->setText(currentAccount->accountName); | 443 | status1Label->setText(currentAccount->accountName); |
444 | progressBar->reset(); | 444 | progressBar->reset(); |
445 | 445 | ||
446 | emailHandler->getMailByList(&mailDownloadList); | 446 | emailHandler->getMailByList(&mailDownloadList); |
447 | } | 447 | } |
448 | 448 | ||
449 | void EmailClient::moveMailFront(Email *mailPtr) | 449 | void EmailClient::moveMailFront(Email *mailPtr) |
450 | { | 450 | { |
451 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 451 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
452 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 452 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
453 | } | 453 | } |
454 | } | 454 | } |
455 | 455 | ||
456 | void EmailClient::smtpError(int code) | 456 | void EmailClient::smtpError(int code) |
457 | { | 457 | { |
458 | QString temp; | 458 | QString temp; |
459 | 459 | ||
460 | if (code == ErrUnknownResponse) | 460 | if (code == ErrUnknownResponse) |
461 | temp = "Unknown response from server"; | 461 | temp = "Unknown response from server"; |
462 | 462 | ||
463 | if (code == QSocket::ErrHostNotFound) | 463 | if (code == QSocket::ErrHostNotFound) |
464 | temp = "host not found"; | 464 | temp = "host not found"; |
465 | if (code == QSocket::ErrConnectionRefused) | 465 | if (code == QSocket::ErrConnectionRefused) |
466 | temp = "connection refused"; | 466 | temp = "connection refused"; |
467 | if (code == QSocket::ErrSocketRead) | 467 | if (code == QSocket::ErrSocketRead) |
468 | temp = "socket packet error"; | 468 | temp = "socket packet error"; |
469 | 469 | ||
470 | if (code != ErrCancel) { | 470 | if (code != ErrCancel) { |
471 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); | 471 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); |
472 | } else { | 472 | } else { |
473 | status2Label->setText("Aborted by user"); | 473 | status2Label->setText("Aborted by user"); |
474 | } | 474 | } |
475 | 475 | ||
476 | sending = FALSE; | 476 | sending = FALSE; |
477 | sendMailButton->setEnabled(TRUE); | 477 | sendMailButton->setEnabled(TRUE); |
478 | cancelButton->setEnabled(FALSE); | 478 | cancelButton->setEnabled(FALSE); |
479 | quedMessages.clear(); | 479 | quedMessages.clear(); |
480 | } | 480 | } |
481 | 481 | ||
482 | void EmailClient::popError(int code) | 482 | void EmailClient::popError(int code) |
483 | { | 483 | { |
484 | QString temp; | 484 | QString temp; |
485 | 485 | ||
486 | if (code == ErrUnknownResponse) | 486 | if (code == ErrUnknownResponse) |
487 | temp = "Unknown response from server"; | 487 | temp = "Unknown response from server"; |
488 | if (code == ErrLoginFailed) | 488 | if (code == ErrLoginFailed) |
489 | temp = "Login failed\nCheck user name and password"; | 489 | temp = "Login failed\nCheck user name and password"; |
490 | 490 | ||
491 | if (code == QSocket::ErrHostNotFound) | 491 | if (code == QSocket::ErrHostNotFound) |
492 | temp = "host not found"; | 492 | temp = "host not found"; |
493 | if (code == QSocket::ErrConnectionRefused) | 493 | if (code == QSocket::ErrConnectionRefused) |
494 | temp = "connection refused"; | 494 | temp = "connection refused"; |
495 | if (code == QSocket::ErrSocketRead) | 495 | if (code == QSocket::ErrSocketRead) |
496 | temp = "socket packet error"; | 496 | temp = "socket packet error"; |
497 | 497 | ||
498 | if (code != ErrCancel) { | 498 | if (code != ErrCancel) { |
499 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); | 499 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); |
500 | } else { | 500 | } else { |
501 | status2Label->setText("Aborted by user"); | 501 | status2Label->setText("Aborted by user"); |
502 | } | 502 | } |
503 | 503 | ||
504 | receiving = FALSE; | 504 | receiving = FALSE; |
505 | getMailButton->setEnabled(TRUE); | 505 | getMailButton->setEnabled(TRUE); |
506 | cancelButton->setEnabled(FALSE); | 506 | cancelButton->setEnabled(FALSE); |
507 | selectAccountMenu->setEnabled(TRUE); | 507 | selectAccountMenu->setEnabled(TRUE); |
508 | } | 508 | } |
509 | 509 | ||
510 | void EmailClient::inboxItemSelected() | 510 | void EmailClient::inboxItemSelected() |
511 | { | 511 | { |
512 | item = (EmailListItem*) inboxView->selectedItem(); | 512 | item = (EmailListItem*) inboxView->selectedItem(); |
513 | if (item != NULL) { | 513 | if (item != NULL) { |
514 | emit viewEmail(inboxView, item->getMail()); | 514 | emit viewEmail(inboxView, item->getMail()); |
515 | } | 515 | } |
516 | } | 516 | } |
517 | 517 | ||
518 | void EmailClient::outboxItemSelected() | 518 | void EmailClient::outboxItemSelected() |
519 | { | 519 | { |
520 | item = (EmailListItem*) outboxView->selectedItem(); | 520 | item = (EmailListItem*) outboxView->selectedItem(); |
521 | if (item != NULL) { | 521 | if (item != NULL) { |
522 | emit viewEmail(outboxView, item->getMail()); | 522 | emit viewEmail(outboxView, item->getMail()); |
523 | } | 523 | } |
524 | 524 | ||
525 | } | 525 | } |
526 | 526 | ||
527 | void EmailClient::readMail() | 527 | void EmailClient::readMail() |
528 | { | 528 | { |
529 | Email mail; | 529 | Email mail; |
530 | int start, stop; | 530 | int start, stop; |
531 | QString s, del; | 531 | QString s, del; |
532 | 532 | ||
533 | QFile f(getPath(FALSE) + "inbox.txt"); | 533 | QFile f(getPath(FALSE) + "inbox.txt"); |
534 | // QFileInfo fi(f); | 534 | // QFileInfo fi(f); |
535 | qDebug( f.name()); | 535 | //qDebug( f.name()); |
536 | 536 | ||
537 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 537 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
538 | QTextStream t( &f ); // use a text stream | 538 | QTextStream t( &f ); // use a text stream |
539 | s = t.read(); | 539 | s = t.read(); |
540 | f.close(); | 540 | f.close(); |
541 | 541 | ||
542 | start = 0; | 542 | start = 0; |
543 | del = "\n.\n"; | 543 | del = "\n.\n"; |
544 | while ((uint) start < s.length()) { | 544 | while ((uint) start < s.length()) { |
545 | stop = s.find(del, start); | 545 | stop = s.find(del, start); |
546 | if (stop == -1) | 546 | if (stop == -1) |
547 | stop = s.length() - del.length(); | 547 | stop = s.length() - del.length(); |
548 | 548 | ||
549 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 549 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
550 | start = stop + del.length(); | 550 | start = stop + del.length(); |
551 | mailArrived(mail, TRUE); | 551 | mailArrived(mail, TRUE); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
555 | QFile fo(getPath(FALSE) + "outbox.txt"); | 555 | QFile fo(getPath(FALSE) + "outbox.txt"); |
556 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | 556 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully |
557 | QTextStream t( &fo ); // use a text stream | 557 | QTextStream t( &fo ); // use a text stream |
558 | s = t.read(); | 558 | s = t.read(); |
559 | fo.close(); | 559 | fo.close(); |
560 | 560 | ||
561 | start = 0; | 561 | start = 0; |
562 | del = "\n.\n"; | 562 | del = "\n.\n"; |
563 | while ((uint) start < s.length()) { | 563 | while ((uint) start < s.length()) { |
564 | stop = s.find(del, start); | 564 | stop = s.find(del, start); |
565 | if (stop == -1) | 565 | if (stop == -1) |
566 | stop = s.length() - del.length(); | 566 | stop = s.length() - del.length(); |
567 | 567 | ||
568 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 568 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
569 | start = stop + del.length(); | 569 | start = stop + del.length(); |
570 | emailHandler->parse(mail.rawMail, lineShift, &mail); | 570 | emailHandler->parse(mail.rawMail, lineShift, &mail); |
571 | mail.sent = false; | 571 | mail.sent = false; |
572 | mail.received = false; | 572 | mail.received = false; |
573 | enqueMail(mail); | 573 | enqueMail(mail); |
574 | 574 | ||
575 | } | 575 | } |
576 | } | 576 | } |
577 | } | 577 | } |
578 | 578 | ||
579 | void EmailClient::saveMail(QString fileName, QListView *view) | 579 | void EmailClient::saveMail(QString fileName, QListView *view) |
580 | { | 580 | { |
581 | QFile f(fileName); | 581 | QFile f(fileName); |
582 | Email *mail; | 582 | Email *mail; |
583 | 583 | ||
584 | if (! f.open(IO_WriteOnly) ) { | 584 | if (! f.open(IO_WriteOnly) ) { |
585 | qWarning("could not open file"); | 585 | qWarning("could not open file"); |
586 | return; | 586 | return; |
587 | } | 587 | } |
588 | item = (EmailListItem *) view->firstChild(); | 588 | item = (EmailListItem *) view->firstChild(); |
589 | qDebug (QString("Write : ") ); | 589 | //qDebug (QString("Write : ") ); |
590 | QTextStream t(&f); | 590 | QTextStream t(&f); |
591 | while (item != NULL) { | 591 | while (item != NULL) { |
592 | mail = item->getMail(); | 592 | mail = item->getMail(); |
593 | qDebug(mail->rawMail); | 593 | //qDebug(mail->rawMail); |
594 | qDebug(mail->recipients.first()); | 594 | //qDebug(mail->recipients.first()); |
595 | t << mail->rawMail; | 595 | t << mail->rawMail; |
596 | 596 | ||
597 | mailconf->setGroup(mail->id); | 597 | mailconf->setGroup(mail->id); |
598 | mailconf->writeEntry("mailread", mail->read); | 598 | mailconf->writeEntry("mailread", mail->read); |
599 | 599 | ||
600 | item = (EmailListItem *) item->nextSibling(); | 600 | item = (EmailListItem *) item->nextSibling(); |
601 | } | 601 | } |
602 | f.close(); | 602 | f.close(); |
603 | } | 603 | } |
604 | 604 | ||
605 | //paths for mailit, is settings, inbox, enclosures | 605 | //paths for mailit, is settings, inbox, enclosures |
606 | QString EmailClient::getPath(bool enclosurePath) | 606 | QString EmailClient::getPath(bool enclosurePath) |
607 | { | 607 | { |
608 | QString basePath = "qtmail"; | 608 | QString basePath = "qtmail"; |
609 | QString enclosures = "enclosures"; | 609 | QString enclosures = "enclosures"; |
610 | 610 | ||
611 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | 611 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); |
612 | if ( !dir.exists() ) | 612 | if ( !dir.exists() ) |
613 | dir.mkdir( dir.path() ); | 613 | dir.mkdir( dir.path() ); |
614 | 614 | ||
615 | if (enclosurePath) { | 615 | if (enclosurePath) { |
616 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | 616 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); |
617 | 617 | ||
618 | if ( !dir.exists() ) | 618 | if ( !dir.exists() ) |
619 | dir.mkdir( dir.path() ); | 619 | dir.mkdir( dir.path() ); |
620 | 620 | ||
621 | return (dir.path() + "/"); | 621 | return (dir.path() + "/"); |
622 | 622 | ||
623 | } | 623 | } |
624 | return (dir.path() + "/"); | 624 | return (dir.path() + "/"); |
625 | } | 625 | } |
626 | 626 | ||
627 | void EmailClient::readSettings() | 627 | void EmailClient::readSettings() |
628 | { | 628 | { |
629 | TextParser *p; | 629 | TextParser *p; |
630 | QString s; | 630 | QString s; |
631 | int pos, accountPos, y; | 631 | int pos, accountPos, y; |
632 | QFile f( getPath(FALSE) + "settings.txt"); | 632 | QFile f( getPath(FALSE) + "settings.txt"); |
633 | 633 | ||
634 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 634 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
635 | QTextStream t( &f ); // use a text stream | 635 | QTextStream t( &f ); // use a text stream |
636 | s = t.read(); | 636 | s = t.read(); |
637 | f.close(); | 637 | f.close(); |
638 | 638 | ||
639 | p = new TextParser(s, "\n"); | 639 | p = new TextParser(s, "\n"); |
640 | 640 | ||
641 | accountPos = 0; | 641 | accountPos = 0; |
642 | while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) { | 642 | while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) { |
643 | accountPos++; | 643 | accountPos++; |
644 | if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 ) | 644 | if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 ) |
645 | account.accountName = p->getString(& ++pos, 'z', TRUE); | 645 | account.accountName = p->getString(& ++pos, 'z', TRUE); |
646 | if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1) | 646 | if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1) |
647 | account.name = p->getString(& ++pos, 'z', TRUE); | 647 | account.name = p->getString(& ++pos, 'z', TRUE); |
648 | if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1) | 648 | if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1) |
649 | account.emailAddress = p->getString(& ++pos, 'z', TRUE); | 649 | account.emailAddress = p->getString(& ++pos, 'z', TRUE); |
650 | if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1) | 650 | if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1) |
651 | account.popUserName = p->getString(& ++pos, 'z', TRUE); | 651 | account.popUserName = p->getString(& ++pos, 'z', TRUE); |
652 | if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1) | 652 | if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1) |
653 | account.popPasswd = p->getString(& ++pos, 'z', TRUE); | 653 | account.popPasswd = p->getString(& ++pos, 'z', TRUE); |
654 | if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1) | 654 | if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1) |
655 | account.popServer = p->getString(& ++pos, 'z', TRUE); | 655 | account.popServer = p->getString(& ++pos, 'z', TRUE); |
656 | if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1) | 656 | if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1) |
657 | account.smtpServer = p->getString(& ++pos, 'z', TRUE); | 657 | account.smtpServer = p->getString(& ++pos, 'z', TRUE); |
658 | if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) { | 658 | if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) { |
659 | s = p->getString(& ++pos, 'z', TRUE); | 659 | s = p->getString(& ++pos, 'z', TRUE); |
660 | account.id = s.toInt(); | 660 | account.id = s.toInt(); |
661 | } | 661 | } |
662 | 662 | ||
663 | account.lastServerMailCount = 0; | 663 | account.lastServerMailCount = 0; |
664 | account.synchronize = FALSE; | 664 | account.synchronize = FALSE; |
665 | if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) { | 665 | if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) { |
666 | if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") { | 666 | if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") { |
667 | account.synchronize = TRUE; | 667 | account.synchronize = TRUE; |
668 | if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) { | 668 | if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) { |
669 | s = p->getString(& ++pos, 'z', TRUE); | 669 | s = p->getString(& ++pos, 'z', TRUE); |
670 | account.lastServerMailCount = s.toInt(); | 670 | account.lastServerMailCount = s.toInt(); |
671 | } | 671 | } |
672 | } | 672 | } |
673 | } | 673 | } |
674 | 674 | ||
675 | if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) { | 675 | if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) { |
676 | account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt(); | 676 | account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt(); |
677 | } | 677 | } |
678 | 678 | ||
679 | 679 | ||
680 | accountList.append(&account); | 680 | accountList.append(&account); |
681 | } | 681 | } |
682 | delete p; | 682 | delete p; |
683 | } | 683 | } |
684 | mailconf->setGroup("mailitglobal"); | 684 | mailconf->setGroup("mailitglobal"); |
685 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { | 685 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { |
686 | mailIdCount = y; | 686 | mailIdCount = y; |
687 | } | 687 | } |
688 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { | 688 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { |
689 | accountIdCount = y; | 689 | accountIdCount = y; |
690 | } | 690 | } |
691 | } | 691 | } |
692 | 692 | ||
693 | void EmailClient::saveSettings() | 693 | void EmailClient::saveSettings() |
694 | { | 694 | { |
695 | QString temp; | 695 | QString temp; |
696 | QFile f( getPath(FALSE) + "settings.txt"); | 696 | QFile f( getPath(FALSE) + "settings.txt"); |
697 | MailAccount *accountPtr; | 697 | MailAccount *accountPtr; |
698 | 698 | ||
699 | if (! f.open(IO_WriteOnly) ) { | 699 | if (! f.open(IO_WriteOnly) ) { |
700 | qWarning("could not save settings file"); | 700 | qWarning("could not save settings file"); |
701 | return; | 701 | return; |
702 | } | 702 | } |
703 | QTextStream t(&f); | 703 | QTextStream t(&f); |
704 | t << "#Settings for QPE Mailit program\n"; | 704 | t << "#Settings for QPE Mailit program\n"; |
705 | 705 | ||
706 | for (accountPtr = accountList.first(); accountPtr != 0; | 706 | for (accountPtr = accountList.first(); accountPtr != 0; |
707 | accountPtr = accountList.next()) { | 707 | accountPtr = accountList.next()) { |
708 | 708 | ||
709 | t << "accountStart;\n"; | 709 | t << "accountStart;\n"; |
710 | t << "AccountName: " + accountPtr->accountName + "\n"; | 710 | t << "AccountName: " + accountPtr->accountName + "\n"; |
711 | t << "Name: " + accountPtr->name + "\n"; | 711 | t << "Name: " + accountPtr->name + "\n"; |
712 | t << "Email: " + accountPtr->emailAddress + "\n"; | 712 | t << "Email: " + accountPtr->emailAddress + "\n"; |
713 | t << "POPUser: " + accountPtr->popUserName + "\n"; | 713 | t << "POPUser: " + accountPtr->popUserName + "\n"; |
714 | t << "POPPAssword: " + accountPtr->popPasswd + "\n"; | 714 | t << "POPPAssword: " + accountPtr->popPasswd + "\n"; |
715 | t << "POPServer: " + accountPtr->popServer + "\n"; | 715 | t << "POPServer: " + accountPtr->popServer + "\n"; |
716 | t << "SMTPServer: " + accountPtr->smtpServer + "\n"; | 716 | t << "SMTPServer: " + accountPtr->smtpServer + "\n"; |
717 | t << "AccountId: " << accountPtr->id << "\n"; | 717 | t << "AccountId: " << accountPtr->id << "\n"; |
718 | if (accountPtr->synchronize) { | 718 | if (accountPtr->synchronize) { |
719 | t << "Synchronize: Yes\n"; | 719 | t << "Synchronize: Yes\n"; |
720 | t << "LastServerMailCount: "; | 720 | t << "LastServerMailCount: "; |
721 | t << accountPtr->lastServerMailCount << "\n"; | 721 | t << accountPtr->lastServerMailCount << "\n"; |
722 | } else { | 722 | } else { |
723 | t << "Synchronize: No\n"; | 723 | t << "Synchronize: No\n"; |
724 | } | 724 | } |
725 | t << "SyncLimit: "; | 725 | t << "SyncLimit: "; |
726 | t << accountPtr->syncLimit << "\n"; | 726 | t << accountPtr->syncLimit << "\n"; |
727 | t << "accountEnd;\n"; | 727 | t << "accountEnd;\n"; |
728 | } | 728 | } |
729 | f.close(); | 729 | f.close(); |
730 | 730 | ||
731 | mailconf->setGroup("mailitglobal"); | 731 | mailconf->setGroup("mailitglobal"); |
732 | mailconf->writeEntry("mailidcount", mailIdCount); | 732 | mailconf->writeEntry("mailidcount", mailIdCount); |
733 | mailconf->writeEntry("accountidcount", accountIdCount); | 733 | mailconf->writeEntry("accountidcount", accountIdCount); |
734 | } | 734 | } |
735 | 735 | ||
736 | void EmailClient::selectAccount(int id) | 736 | void EmailClient::selectAccount(int id) |
737 | { | 737 | { |
738 | if (accountList.count() > 0) { | 738 | if (accountList.count() > 0) { |
739 | currentAccount = accountList.at(id); | 739 | currentAccount = accountList.at(id); |
740 | emit newCaption("Mailit - " + currentAccount->accountName); | 740 | emit newCaption("Mailit - " + currentAccount->accountName); |
741 | getNewMail(); | 741 | getNewMail(); |
742 | } else { | 742 | } else { |
743 | emit newCaption("Mailit ! No account defined"); | 743 | emit newCaption("Mailit ! No account defined"); |
744 | } | 744 | } |
745 | } | 745 | } |
746 | 746 | ||
747 | void EmailClient::editAccount(int id) | 747 | void EmailClient::editAccount(int id) |
748 | { | 748 | { |
749 | MailAccount *newAccount; | 749 | MailAccount *newAccount; |
750 | 750 | ||
751 | editAccountView = new EditAccount(this, "account", TRUE); | 751 | editAccountView = new EditAccount(this, "account", TRUE); |
752 | if (id == newAccountId) { //new account | 752 | if (id == newAccountId) { //new account |
753 | newAccount = new MailAccount; | 753 | newAccount = new MailAccount; |
754 | editAccountView->setAccount(newAccount); | 754 | editAccountView->setAccount(newAccount); |
755 | } else { | 755 | } else { |
756 | newAccount = accountList.at(id); | 756 | newAccount = accountList.at(id); |
757 | editAccountView->setAccount(newAccount, FALSE); | 757 | editAccountView->setAccount(newAccount, FALSE); |
758 | } | 758 | } |
759 | 759 | ||
760 | editAccountView->showMaximized(); | 760 | editAccountView->showMaximized(); |
761 | editAccountView->exec(); | 761 | editAccountView->exec(); |
762 | 762 | ||
763 | if (editAccountView->result() == QDialog::Accepted) { | 763 | if (editAccountView->result() == QDialog::Accepted) { |
764 | if (id == newAccountId) { | 764 | if (id == newAccountId) { |
765 | newAccount->id = accountIdCount; | 765 | newAccount->id = accountIdCount; |
766 | accountIdCount++; | 766 | accountIdCount++; |
767 | accountList.append(newAccount); | 767 | accountList.append(newAccount); |
768 | updateAccounts(); | 768 | updateAccounts(); |
769 | } else { | 769 | } else { |
770 | updateAccounts(); | 770 | updateAccounts(); |
771 | } | 771 | } |
772 | } | 772 | } |
773 | 773 | ||
774 | delete editAccountView; | 774 | delete editAccountView; |
775 | } | 775 | } |
776 | 776 | ||
777 | void EmailClient::deleteAccount(int id) | 777 | void EmailClient::deleteAccount(int id) |
778 | { | 778 | { |
779 | MailAccount *newAccount; | 779 | MailAccount *newAccount; |
780 | QString message; | 780 | QString message; |
781 | 781 | ||
782 | newAccount = accountList.at(id); | 782 | newAccount = accountList.at(id); |
783 | message = "Delete account:\n" + newAccount->accountName; | 783 | message = "Delete account:\n" + newAccount->accountName; |
784 | switch( QMessageBox::warning( this, "Mailit", message, | 784 | switch( QMessageBox::warning( this, "Mailit", message, |
785 | "Yes", "No", 0, 0, 1 ) ) { | 785 | "Yes", "No", 0, 0, 1 ) ) { |
786 | 786 | ||
787 | case 0: accountList.remove(id); | 787 | case 0: accountList.remove(id); |
788 | updateAccounts(); | 788 | updateAccounts(); |
789 | break; | 789 | break; |
790 | case 1: | 790 | case 1: |
791 | break; | 791 | break; |
792 | } | 792 | } |
793 | } | 793 | } |
794 | 794 | ||
795 | void EmailClient::updateAccounts() | 795 | void EmailClient::updateAccounts() |
796 | { | 796 | { |
797 | MailAccount *accountPtr; | 797 | MailAccount *accountPtr; |
798 | 798 | ||
799 | //rebuild menus, clear all first | 799 | //rebuild menus, clear all first |
800 | editAccountMenu->clear(); | 800 | editAccountMenu->clear(); |
801 | selectAccountMenu->clear(); | 801 | selectAccountMenu->clear(); |
802 | deleteAccountMenu->clear(); | 802 | deleteAccountMenu->clear(); |
803 | 803 | ||
804 | newAccountId = editAccountMenu->insertItem("New", this, | 804 | newAccountId = editAccountMenu->insertItem("New", this, |
805 | SLOT(editAccount(int)) ); | 805 | SLOT(editAccount(int)) ); |
806 | editAccountMenu->insertSeparator(); | 806 | editAccountMenu->insertSeparator(); |
807 | 807 | ||
808 | idCount = 0; | 808 | idCount = 0; |
809 | for (accountPtr = accountList.first(); accountPtr != 0; | 809 | for (accountPtr = accountList.first(); accountPtr != 0; |
810 | accountPtr = accountList.next()) { | 810 | accountPtr = accountList.next()) { |
811 | 811 | ||
812 | editAccountMenu->insertItem(accountPtr->accountName, | 812 | editAccountMenu->insertItem(accountPtr->accountName, |
813 | this, SLOT(editAccount(int)), 0, idCount); | 813 | this, SLOT(editAccount(int)), 0, idCount); |
814 | selectAccountMenu->insertItem(accountPtr->accountName, | 814 | selectAccountMenu->insertItem(accountPtr->accountName, |
815 | this, SLOT(selectAccount(int)), 0, idCount); | 815 | this, SLOT(selectAccount(int)), 0, idCount); |
816 | deleteAccountMenu->insertItem(accountPtr->accountName, | 816 | deleteAccountMenu->insertItem(accountPtr->accountName, |
817 | this, SLOT(deleteAccount(int)), 0, idCount); | 817 | this, SLOT(deleteAccount(int)), 0, idCount); |
818 | idCount++; | 818 | idCount++; |
819 | } | 819 | } |
820 | } | 820 | } |
821 | 821 | ||
822 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | 822 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) |
823 | { | 823 | { |
824 | Email *mPtr; | 824 | Email *mPtr; |
825 | Enclosure *ePtr; | 825 | Enclosure *ePtr; |
826 | 826 | ||
827 | if (inbox) { | 827 | if (inbox) { |
828 | mPtr = mailItem->getMail(); | 828 | mPtr = mailItem->getMail(); |
829 | 829 | ||
830 | //if mail is in queue for download, remove it from | 830 | //if mail is in queue for download, remove it from |
831 | //queue if possible | 831 | //queue if possible |
832 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | 832 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { |
833 | if ( !mPtr->downloaded ) | 833 | if ( !mPtr->downloaded ) |
834 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | 834 | mailDownloadList.remove(mPtr->serverId, mPtr->size); |
835 | } | 835 | } |
836 | 836 | ||
837 | mailconf->setGroup(mPtr->id); | 837 | mailconf->setGroup(mPtr->id); |
838 | mailconf->clearGroup(); | 838 | mailconf->clearGroup(); |
839 | 839 | ||
840 | //delete any temporary attatchemnts storing | 840 | //delete any temporary attatchemnts storing |
841 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | 841 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { |
842 | if (ePtr->saved) { | 842 | if (ePtr->saved) { |
843 | QFile::remove( (ePtr->path + ePtr->name) ); | 843 | QFile::remove( (ePtr->path + ePtr->name) ); |
844 | } | 844 | } |
845 | } | 845 | } |
846 | inboxView->takeItem(mailItem); | 846 | inboxView->takeItem(mailItem); |
847 | } else { | 847 | } else { |
848 | outboxView->takeItem(mailItem); | 848 | outboxView->takeItem(mailItem); |
849 | } | 849 | } |
850 | } | 850 | } |
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp index 9c1c814..03f8a28 100644 --- a/noncore/net/mailit/emailhandler.cpp +++ b/noncore/net/mailit/emailhandler.cpp | |||
@@ -1,423 +1,421 @@ | |||
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 | ||
29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) | 29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) |
30 | { | 30 | { |
31 | return dupl( (Enclosure *) d); | 31 | return dupl( (Enclosure *) d); |
32 | } | 32 | } |
33 | 33 | ||
34 | Enclosure* EnclosureList::dupl(Enclosure *in) | 34 | Enclosure* 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 | ||
40 | EmailHandler::EmailHandler() | 40 | EmailHandler::EmailHandler() |
41 | { | 41 | { |
42 | smtpClient = new SmtpClient(); | 42 | smtpClient = new SmtpClient(); |
43 | popClient = new PopClient(); | 43 | popClient = new PopClient(); |
44 | 44 | ||
45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, | 45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, |
46 | SIGNAL(smtpError(int)) ); | 46 | SIGNAL(smtpError(int)) ); |
47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); | 47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); |
48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, | 48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, |
49 | SIGNAL(updateSmtpStatus(const QString &)) ); | 49 | SIGNAL(updateSmtpStatus(const QString &)) ); |
50 | 50 | ||
51 | connect(popClient, SIGNAL(errorOccurred(int)), this, | 51 | connect(popClient, SIGNAL(errorOccurred(int)), this, |
52 | SIGNAL(popError(int)) ); | 52 | SIGNAL(popError(int)) ); |
53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), | 53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), |
54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); | 54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); |
55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, | 55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, |
56 | SIGNAL(updatePopStatus(const QString &)) ); | 56 | SIGNAL(updatePopStatus(const QString &)) ); |
57 | connect(popClient, SIGNAL(mailTransfered(int)), this, | 57 | connect(popClient, SIGNAL(mailTransfered(int)), this, |
58 | SIGNAL(mailTransfered(int)) ); | 58 | SIGNAL(mailTransfered(int)) ); |
59 | 59 | ||
60 | 60 | ||
61 | //relaying size information | 61 | //relaying size information |
62 | connect(popClient, SIGNAL(currentMailSize(int)), | 62 | connect(popClient, SIGNAL(currentMailSize(int)), |
63 | this, SIGNAL(currentMailSize(int)) ); | 63 | this, SIGNAL(currentMailSize(int)) ); |
64 | connect(popClient, SIGNAL(downloadedSize(int)), | 64 | connect(popClient, SIGNAL(downloadedSize(int)), |
65 | this, SIGNAL(downloadedSize(int)) ); | 65 | this, SIGNAL(downloadedSize(int)) ); |
66 | } | 66 | } |
67 | 67 | ||
68 | void EmailHandler::sendMail(QList<Email> *mailList) | 68 | void EmailHandler::sendMail(QList<Email> *mailList) |
69 | { | 69 | { |
70 | Email *currentMail; | 70 | Email *currentMail; |
71 | QString temp; | 71 | QString temp; |
72 | QString userName = mailAccount.name; | 72 | QString userName = mailAccount.name; |
73 | userName += " <" + mailAccount.emailAddress + ">"; | 73 | userName += " <" + mailAccount.emailAddress + ">"; |
74 | 74 | ||
75 | for (currentMail = mailList->first(); currentMail != 0; | 75 | for (currentMail = mailList->first(); currentMail != 0; |
76 | currentMail = mailList->next()) { | 76 | currentMail = mailList->next()) { |
77 | 77 | ||
78 | if (encodeMime(currentMail) == 0) { | 78 | if (encodeMime(currentMail) == 0) { |
79 | smtpClient->addMail(userName, currentMail->subject, | 79 | smtpClient->addMail(userName, currentMail->subject, |
80 | currentMail->recipients, currentMail->rawMail); | 80 | currentMail->recipients, currentMail->rawMail); |
81 | } else { //error | 81 | } else { //error |
82 | temp = tr("Could not locate all files in \nmail with subject: ") + | 82 | temp = tr("Could not locate all files in \nmail with subject: ") + |
83 | currentMail->subject; | 83 | currentMail->subject; |
84 | temp += tr("\nMail has NOT been sent"); | 84 | temp += tr("\nMail has NOT been sent"); |
85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); | 85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); |
86 | 86 | ||
87 | } | 87 | } |
88 | } | 88 | } |
89 | smtpClient->newConnection(mailAccount.smtpServer, 25); | 89 | smtpClient->newConnection(mailAccount.smtpServer, 25); |
90 | } | 90 | } |
91 | 91 | ||
92 | void EmailHandler::setAccount(MailAccount account) | 92 | void EmailHandler::setAccount(MailAccount account) |
93 | { | 93 | { |
94 | mailAccount = account; | 94 | mailAccount = account; |
95 | } | 95 | } |
96 | 96 | ||
97 | void EmailHandler::getMail() | 97 | void EmailHandler::getMail() |
98 | { | 98 | { |
99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
100 | if (mailAccount.synchronize) { | 100 | if (mailAccount.synchronize) { |
101 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 101 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
102 | } else { | 102 | } else { |
103 | popClient->removeSynchronize(); | 103 | popClient->removeSynchronize(); |
104 | } | 104 | } |
105 | 105 | ||
106 | headers = FALSE; | 106 | headers = FALSE; |
107 | popClient->headersOnly(headers, 0); | 107 | popClient->headersOnly(headers, 0); |
108 | popClient->newConnection(mailAccount.popServer, 110); | 108 | popClient->newConnection(mailAccount.popServer, 110); |
109 | } | 109 | } |
110 | 110 | ||
111 | void EmailHandler::getMailHeaders() | 111 | void EmailHandler::getMailHeaders() |
112 | { | 112 | { |
113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
114 | if (mailAccount.synchronize) { | 114 | if (mailAccount.synchronize) { |
115 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 115 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
116 | } else { | 116 | } else { |
117 | popClient->removeSynchronize(); | 117 | popClient->removeSynchronize(); |
118 | } | 118 | } |
119 | 119 | ||
120 | headers = TRUE; | 120 | headers = TRUE; |
121 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 121 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
122 | popClient->newConnection(mailAccount.popServer, 110); | 122 | popClient->newConnection(mailAccount.popServer, 110); |
123 | } | 123 | } |
124 | 124 | ||
125 | void EmailHandler::getMailByList(MailList *mailList) | 125 | void EmailHandler::getMailByList(MailList *mailList) |
126 | { | 126 | { |
127 | if (mailList->count() == 0) { //should not occur though | 127 | if (mailList->count() == 0) { //should not occur though |
128 | emit mailTransfered(0); | 128 | emit mailTransfered(0); |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | 131 | ||
132 | headers = FALSE; | 132 | headers = FALSE; |
133 | popClient->headersOnly(FALSE, 0); | 133 | popClient->headersOnly(FALSE, 0); |
134 | popClient->newConnection(mailAccount.popServer, 110); | 134 | popClient->newConnection(mailAccount.popServer, 110); |
135 | popClient->setSelectedMails(mailList); | 135 | popClient->setSelectedMails(mailList); |
136 | } | 136 | } |
137 | 137 | ||
138 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) | 138 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) |
139 | { | 139 | { |
140 | Email mail; | 140 | Email mail; |
141 | 141 | ||
142 | mail.rawMail = message; | 142 | mail.rawMail = message; |
143 | mail.serverId = id; | 143 | mail.serverId = id; |
144 | mail.size = size; | 144 | mail.size = size; |
145 | mail.downloaded = complete; | 145 | mail.downloaded = complete; |
146 | 146 | ||
147 | emit mailArrived(mail, FALSE); | 147 | emit mailArrived(mail, FALSE); |
148 | } | 148 | } |
149 | 149 | ||
150 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 150 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) |
151 | { | 151 | { |
152 | QString temp, boundary; | 152 | QString temp, boundary; |
153 | int pos; | 153 | int pos; |
154 | QString delimiter, header, body, mimeHeader, mimeBody; | 154 | QString delimiter, header, body, mimeHeader, mimeBody; |
155 | QString content, contentType, contentAttribute, id, encoding; | 155 | QString content, contentType, contentAttribute, id, encoding; |
156 | QString fileName, storedName; | 156 | QString fileName, storedName; |
157 | int enclosureId = 0; | 157 | int enclosureId = 0; |
158 | 158 | ||
159 | mail->rawMail = in; | 159 | mail->rawMail = in; |
160 | mail->received = TRUE; | 160 | mail->received = TRUE; |
161 | mail->files.setAutoDelete(TRUE); | 161 | mail->files.setAutoDelete(TRUE); |
162 | 162 | ||
163 | temp = lineShift + "." + lineShift; | 163 | temp = lineShift + "." + lineShift; |
164 | 164 | ||
165 | if (in.right(temp.length()) != temp) { | 165 | if (in.right(temp.length()) != temp) { |
166 | qWarning(in.right(temp.length())); | ||
167 | qWarning(" . added at end of email as separator"); | ||
168 | mail->rawMail += temp; | 166 | mail->rawMail += temp; |
169 | } | 167 | } |
170 | 168 | ||
171 | 169 | ||
172 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 170 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
173 | pos = in.find(delimiter, 0, FALSE); | 171 | pos = in.find(delimiter, 0, FALSE); |
174 | header = in.left(pos); | 172 | header = in.left(pos); |
175 | body = in.right(in.length() - pos - delimiter.length()); | 173 | body = in.right(in.length() - pos - delimiter.length()); |
176 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 174 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
177 | body.truncate(body.length()-2); | 175 | body.truncate(body.length()-2); |
178 | 176 | ||
179 | TextParser p(header, lineShift); | 177 | TextParser p(header, lineShift); |
180 | 178 | ||
181 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 179 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
182 | pos++; | 180 | pos++; |
183 | if (p.separatorAt(pos) == ' ') { | 181 | if (p.separatorAt(pos) == ' ') { |
184 | mail->from = p.getString(&pos, '<', false); | 182 | mail->from = p.getString(&pos, '<', false); |
185 | mail->from = mail->from.stripWhiteSpace(); | 183 | mail->from = mail->from.stripWhiteSpace(); |
186 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 184 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
187 | mail->from = mail->from.left(mail->from.length() - 1); | 185 | mail->from = mail->from.left(mail->from.length() - 1); |
188 | mail->from = mail->from.right(mail->from.length() - 1); | 186 | mail->from = mail->from.right(mail->from.length() - 1); |
189 | } | 187 | } |
190 | pos++; | 188 | pos++; |
191 | mail->fromMail = p.getString(&pos, '>', false); | 189 | mail->fromMail = p.getString(&pos, '>', false); |
192 | } else { | 190 | } else { |
193 | if ((p.separatorAt(pos) == '<') | 191 | if ((p.separatorAt(pos) == '<') |
194 | || (p.separatorAt(pos) == ' ')) //No name.. nasty | 192 | || (p.separatorAt(pos) == ' ')) //No name.. nasty |
195 | pos++; | 193 | pos++; |
196 | pos++; | 194 | pos++; |
197 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 195 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
198 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
199 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 197 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
200 | mail->from=mail->fromMail; | 198 | mail->from=mail->fromMail; |
201 | } | 199 | } |
202 | } | 200 | } |
203 | 201 | ||
204 | //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To: | 202 | //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To: |
205 | if (pos = p.find("TO",':', pos, TRUE) != -1) | 203 | if (pos = p.find("TO",':', pos, TRUE) != -1) |
206 | { | 204 | { |
207 | pos++; | 205 | pos++; |
208 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); | 206 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); |
209 | } | 207 | } |
210 | 208 | ||
211 | 209 | ||
212 | 210 | ||
213 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 211 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
214 | pos++; | 212 | pos++; |
215 | mail->subject = p.getString(&pos, 'z', TRUE); | 213 | mail->subject = p.getString(&pos, 'z', TRUE); |
216 | } | 214 | } |
217 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 215 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
218 | pos++; | 216 | pos++; |
219 | mail->date = p.getString(&pos, 'z', true); | 217 | mail->date = p.getString(&pos, 'z', true); |
220 | } | 218 | } |
221 | 219 | ||
222 | 220 | ||
223 | 221 | ||
224 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 222 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
225 | pos++; | 223 | pos++; |
226 | if ( (p.wordAt(pos).upper() == "ID") && | 224 | if ( (p.wordAt(pos).upper() == "ID") && |
227 | (p.separatorAt(pos) == ':') ) { | 225 | (p.separatorAt(pos) == ':') ) { |
228 | 226 | ||
229 | id = p.getString(&pos, 'z', TRUE); | 227 | id = p.getString(&pos, 'z', TRUE); |
230 | mail->id = id; | 228 | mail->id = id; |
231 | } | 229 | } |
232 | } | 230 | } |
233 | 231 | ||
234 | pos = 0; | 232 | pos = 0; |
235 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 233 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
236 | pos++; | 234 | pos++; |
237 | if ( (p.wordAt(pos).upper() == "VERSION") && | 235 | if ( (p.wordAt(pos).upper() == "VERSION") && |
238 | (p.separatorAt(pos) == ':') ) { | 236 | (p.separatorAt(pos) == ':') ) { |
239 | pos++; | 237 | pos++; |
240 | if (p.getString(&pos, 'z', true) == "1.0") { | 238 | if (p.getString(&pos, 'z', true) == "1.0") { |
241 | mail->mimeType = 1; | 239 | mail->mimeType = 1; |
242 | } | 240 | } |
243 | } | 241 | } |
244 | } | 242 | } |
245 | 243 | ||
246 | if (mail->mimeType == 1) { | 244 | if (mail->mimeType == 1) { |
247 | boundary = ""; | 245 | boundary = ""; |
248 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 246 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
249 | pos++; | 247 | pos++; |
250 | boundary = p.getString(&pos, 'z', true); | 248 | boundary = p.getString(&pos, 'z', true); |
251 | if (boundary[0] == '"') { | 249 | if (boundary[0] == '"') { |
252 | boundary = boundary.left(boundary.length() - 1); //strip " | 250 | boundary = boundary.left(boundary.length() - 1); //strip " |
253 | boundary = boundary.right(boundary.length() - 1); //strip " | 251 | boundary = boundary.right(boundary.length() - 1); //strip " |
254 | } | 252 | } |
255 | boundary = "--" + boundary; //create boundary field | 253 | boundary = "--" + boundary; //create boundary field |
256 | } | 254 | } |
257 | 255 | ||
258 | if (boundary == "") { //fooled by Mime-Version | 256 | if (boundary == "") { //fooled by Mime-Version |
259 | mail->body = body; | 257 | mail->body = body; |
260 | mail->bodyPlain = body; | 258 | mail->bodyPlain = body; |
261 | return mail; | 259 | return mail; |
262 | } | 260 | } |
263 | 261 | ||
264 | while (body.length() > 0) { | 262 | while (body.length() > 0) { |
265 | pos = body.find(boundary, 0, FALSE); | 263 | pos = body.find(boundary, 0, FALSE); |
266 | pos = body.find(delimiter, pos, FALSE); | 264 | pos = body.find(delimiter, pos, FALSE); |
267 | mimeHeader = body.left(pos); | 265 | mimeHeader = body.left(pos); |
268 | mimeBody = body.right(body.length() - pos - delimiter.length()); | 266 | mimeBody = body.right(body.length() - pos - delimiter.length()); |
269 | TextParser bp(mimeHeader, lineShift); | 267 | TextParser bp(mimeHeader, lineShift); |
270 | 268 | ||
271 | contentType = ""; | 269 | contentType = ""; |
272 | contentAttribute = ""; | 270 | contentAttribute = ""; |
273 | fileName = ""; | 271 | fileName = ""; |
274 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { | 272 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { |
275 | pos++; | 273 | pos++; |
276 | if ( (bp.wordAt(pos).upper() == "TYPE") && | 274 | if ( (bp.wordAt(pos).upper() == "TYPE") && |
277 | (bp.separatorAt(pos) == ':') ) { | 275 | (bp.separatorAt(pos) == ':') ) { |
278 | contentType = bp.nextWord().upper(); | 276 | contentType = bp.nextWord().upper(); |
279 | if (bp.nextSeparator() == '/') | 277 | if (bp.nextSeparator() == '/') |
280 | contentAttribute = bp.nextWord().upper(); | 278 | contentAttribute = bp.nextWord().upper(); |
281 | content = contentType + "/" + contentAttribute; | 279 | content = contentType + "/" + contentAttribute; |
282 | } | 280 | } |
283 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { | 281 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { |
284 | pos++; | 282 | pos++; |
285 | encoding = bp.getString(&pos, 'z', TRUE); | 283 | encoding = bp.getString(&pos, 'z', TRUE); |
286 | } | 284 | } |
287 | 285 | ||
288 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { | 286 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { |
289 | pos++; | 287 | pos++; |
290 | fileName = bp.getString(&pos, 'z', TRUE); | 288 | fileName = bp.getString(&pos, 'z', TRUE); |
291 | fileName = fileName.right(fileName.length() - 1); | 289 | fileName = fileName.right(fileName.length() - 1); |
292 | fileName = fileName.left(fileName.length() - 1); | 290 | fileName = fileName.left(fileName.length() - 1); |
293 | } | 291 | } |
294 | 292 | ||
295 | } | 293 | } |
296 | pos = mimeBody.find(boundary, 0, FALSE); | 294 | pos = mimeBody.find(boundary, 0, FALSE); |
297 | if (pos == -1) //should not occur, malformed mail | 295 | if (pos == -1) //should not occur, malformed mail |
298 | pos = mimeBody.length(); | 296 | pos = mimeBody.length(); |
299 | body = mimeBody.right(mimeBody.length() - pos); | 297 | body = mimeBody.right(mimeBody.length() - pos); |
300 | mimeBody = mimeBody.left(pos); | 298 | mimeBody = mimeBody.left(pos); |
301 | 299 | ||
302 | if (fileName != "") { //attatchments of some type, audio, image etc. | 300 | if (fileName != "") { //attatchments of some type, audio, image etc. |
303 | 301 | ||
304 | Enclosure e; | 302 | Enclosure e; |
305 | e.id = enclosureId; | 303 | e.id = enclosureId; |
306 | e.originalName = fileName; | 304 | e.originalName = fileName; |
307 | e.contentType = contentType; | 305 | e.contentType = contentType; |
308 | e.contentAttribute = contentAttribute; | 306 | e.contentAttribute = contentAttribute; |
309 | e.encoding = encoding; | 307 | e.encoding = encoding; |
310 | e.body = mimeBody; | 308 | e.body = mimeBody; |
311 | e.saved = FALSE; | 309 | e.saved = FALSE; |
312 | mail->addEnclosure(&e); | 310 | mail->addEnclosure(&e); |
313 | enclosureId++; | 311 | enclosureId++; |
314 | 312 | ||
315 | } else if (contentType == "TEXT") { | 313 | } else if (contentType == "TEXT") { |
316 | if (contentAttribute == "PLAIN") { | 314 | if (contentAttribute == "PLAIN") { |
317 | mail->body = mimeBody; | 315 | mail->body = mimeBody; |
318 | mail->bodyPlain = mimeBody; | 316 | mail->bodyPlain = mimeBody; |
319 | } | 317 | } |
320 | if (contentAttribute == "HTML") { | 318 | if (contentAttribute == "HTML") { |
321 | mail->body = mimeBody; | 319 | mail->body = mimeBody; |
322 | } | 320 | } |
323 | } | 321 | } |
324 | } | 322 | } |
325 | } else { | 323 | } else { |
326 | mail->bodyPlain = body; | 324 | mail->bodyPlain = body; |
327 | mail->body = body; | 325 | mail->body = body; |
328 | } | 326 | } |
329 | return TRUE; | 327 | return TRUE; |
330 | } | 328 | } |
331 | 329 | ||
332 | bool EmailHandler::getEnclosure(Enclosure *ePtr) | 330 | bool EmailHandler::getEnclosure(Enclosure *ePtr) |
333 | { | 331 | { |
334 | QFile f(ePtr->path + ePtr->name); | 332 | QFile f(ePtr->path + ePtr->name); |
335 | char src[4]; | 333 | char src[4]; |
336 | char *destPtr; | 334 | char *destPtr; |
337 | QByteArray buffer; | 335 | QByteArray buffer; |
338 | uint bufCount, pos, decodedCount, size, x; | 336 | uint bufCount, pos, decodedCount, size, x; |
339 | 337 | ||
340 | if (! f.open(IO_WriteOnly) ) { | 338 | if (! f.open(IO_WriteOnly) ) { |
341 | qWarning("could not save: " + ePtr->path + ePtr->name); | 339 | qWarning("could not save: " + ePtr->path + ePtr->name); |
342 | return FALSE; | 340 | return FALSE; |
343 | } | 341 | } |
344 | 342 | ||
345 | if (ePtr->encoding.upper() == "BASE64") { | 343 | if (ePtr->encoding.upper() == "BASE64") { |
346 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) | 344 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) |
347 | buffer.resize(size); | 345 | buffer.resize(size); |
348 | bufCount = 0; | 346 | bufCount = 0; |
349 | pos = 0; | 347 | pos = 0; |
350 | destPtr = buffer.data(); | 348 | destPtr = buffer.data(); |
351 | 349 | ||
352 | while (pos < ePtr->body.length()) { | 350 | while (pos < ePtr->body.length()) { |
353 | decodedCount = 4; | 351 | decodedCount = 4; |
354 | x = 0; | 352 | x = 0; |
355 | while ( (x < 4) && (pos < ePtr->body.length()) ) { | 353 | while ( (x < 4) && (pos < ePtr->body.length()) ) { |
356 | src[x] = ePtr->body[pos].latin1(); | 354 | src[x] = ePtr->body[pos].latin1(); |
357 | pos++; | 355 | pos++; |
358 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') | 356 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') |
359 | x--; | 357 | x--; |
360 | x++; | 358 | x++; |
361 | } | 359 | } |
362 | if (x > 1) { | 360 | if (x > 1) { |
363 | decodedCount = parse64base(src, destPtr); | 361 | decodedCount = parse64base(src, destPtr); |
364 | destPtr += decodedCount; | 362 | destPtr += decodedCount; |
365 | bufCount += decodedCount; | 363 | bufCount += decodedCount; |
366 | } | 364 | } |
367 | } | 365 | } |
368 | 366 | ||
369 | buffer.resize(bufCount); //set correct length of file | 367 | buffer.resize(bufCount); //set correct length of file |
370 | f.writeBlock(buffer); | 368 | f.writeBlock(buffer); |
371 | } else { | 369 | } else { |
372 | QTextStream t(&f); | 370 | QTextStream t(&f); |
373 | t << ePtr->body; | 371 | t << ePtr->body; |
374 | } | 372 | } |
375 | return TRUE; | 373 | return TRUE; |
376 | } | 374 | } |
377 | 375 | ||
378 | int EmailHandler::parse64base(char *src, char *bufOut) { | 376 | int EmailHandler::parse64base(char *src, char *bufOut) { |
379 | 377 | ||
380 | char c, z; | 378 | char c, z; |
381 | char li[4]; | 379 | char li[4]; |
382 | int processed; | 380 | int processed; |
383 | 381 | ||
384 | //conversion table withouth table... | 382 | //conversion table withouth table... |
385 | for (int x = 0; x < 4; x++) { | 383 | for (int x = 0; x < 4; x++) { |
386 | c = src[x]; | 384 | c = src[x]; |
387 | 385 | ||
388 | if ( (int) c >= 'A' && (int) c <= 'Z') | 386 | if ( (int) c >= 'A' && (int) c <= 'Z') |
389 | li[x] = (int) c - (int) 'A'; | 387 | li[x] = (int) c - (int) 'A'; |
390 | if ( (int) c >= 'a' && (int) c <= 'z') | 388 | if ( (int) c >= 'a' && (int) c <= 'z') |
391 | li[x] = (int) c - (int) 'a' + 26; | 389 | li[x] = (int) c - (int) 'a' + 26; |
392 | if ( (int) c >= '0' && (int) c <= '9') | 390 | if ( (int) c >= '0' && (int) c <= '9') |
393 | li[x] = (int) c - (int) '0' + 52; | 391 | li[x] = (int) c - (int) '0' + 52; |
394 | if (c == '+') | 392 | if (c == '+') |
395 | li[x] = 62; | 393 | li[x] = 62; |
396 | if (c == '/') | 394 | if (c == '/') |
397 | li[x] = 63; | 395 | li[x] = 63; |
398 | } | 396 | } |
399 | 397 | ||
400 | processed = 1; | 398 | processed = 1; |
401 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits | 399 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits |
402 | bufOut[0] <<= 2; | 400 | bufOut[0] <<= 2; |
403 | z = li[1] >> 4; | 401 | z = li[1] >> 4; |
404 | bufOut[0] = bufOut[0] | z; //first byte retrived | 402 | bufOut[0] = bufOut[0] | z; //first byte retrived |
405 | 403 | ||
406 | if (src[2] != '=') { | 404 | if (src[2] != '=') { |
407 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits | 405 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits |
408 | bufOut[1] <<= 4; | 406 | bufOut[1] <<= 4; |
409 | z = li[2] >> 2; | 407 | z = li[2] >> 2; |
410 | bufOut[1] = bufOut[1] | z; //second byte retrived | 408 | bufOut[1] = bufOut[1] | z; //second byte retrived |
411 | processed++; | 409 | processed++; |
412 | 410 | ||
413 | if (src[3] != '=') { | 411 | if (src[3] != '=') { |
414 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits | 412 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits |
415 | bufOut[2] <<= 6; | 413 | bufOut[2] <<= 6; |
416 | z = li[3]; | 414 | z = li[3]; |
417 | bufOut[2] = bufOut[2] | z; //third byte retrieved | 415 | bufOut[2] = bufOut[2] | z; //third byte retrieved |
418 | processed++; | 416 | processed++; |
419 | } | 417 | } |
420 | } | 418 | } |
421 | return processed; | 419 | return processed; |
422 | } | 420 | } |
423 | 421 | ||
diff --git a/noncore/net/mailit/mailitwindow.cpp b/noncore/net/mailit/mailitwindow.cpp index fd49c1f..2bf1dcb 100644 --- a/noncore/net/mailit/mailitwindow.cpp +++ b/noncore/net/mailit/mailitwindow.cpp | |||
@@ -1,136 +1,133 @@ | |||
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 "mailitwindow.h" | 20 | #include "mailitwindow.h" |
21 | 21 | ||
22 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) | 22 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) |
23 | : QMainWindow(parent, name, fl) | 23 | : QMainWindow(parent, name, fl) |
24 | { | 24 | { |
25 | currentCaption = "Mailit"; | 25 | currentCaption = "Mailit"; |
26 | setCaption(tr(currentCaption)); | 26 | setCaption(tr(currentCaption)); |
27 | views = new QWidgetStack(this); | 27 | views = new QWidgetStack(this); |
28 | setCentralWidget(views); | 28 | setCentralWidget(views); |
29 | 29 | ||
30 | qWarning("***Starting writeMail"); | ||
31 | emailClient = new EmailClient(views, "client"); | 30 | emailClient = new EmailClient(views, "client"); |
32 | writeMail = new WriteMail(views, "writing"); | 31 | writeMail = new WriteMail(views, "writing"); |
33 | readMail = new ReadMail(views, "reading"); | 32 | readMail = new ReadMail(views, "reading"); |
34 | qWarning("***Finished readMail"); | ||
35 | 33 | ||
36 | views->raiseWidget(emailClient); | 34 | views->raiseWidget(emailClient); |
37 | 35 | ||
38 | connect(emailClient, SIGNAL(composeRequested()), | 36 | connect(emailClient, SIGNAL(composeRequested()), |
39 | this, SLOT(compose()) ); | 37 | this, SLOT(compose()) ); |
40 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, | 38 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, |
41 | SLOT(viewMail(QListView *, Email *)) ); | 39 | SLOT(viewMail(QListView *, Email *)) ); |
42 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, | 40 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, |
43 | SLOT(updateMailView(Email *)) ); | 41 | SLOT(updateMailView(Email *)) ); |
44 | 42 | ||
45 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); | 43 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); |
46 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, | 44 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, |
47 | SLOT(showEmailClient()) ); | 45 | SLOT(showEmailClient()) ); |
48 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, | 46 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, |
49 | SLOT(enqueMail(const Email &)) ); | 47 | SLOT(enqueMail(const Email &)) ); |
50 | 48 | ||
51 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); | 49 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); |
52 | connect(readMail, SIGNAL(replyRequested(Email &)), this, | 50 | connect(readMail, SIGNAL(replyRequested(Email &)), this, |
53 | SLOT(composeReply(Email &)) ); | 51 | SLOT(composeReply(Email &)) ); |
54 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, | 52 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, |
55 | SLOT(deleteMail(EmailListItem *, bool &)) ); | 53 | SLOT(deleteMail(EmailListItem *, bool &)) ); |
56 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, | 54 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, |
57 | SLOT(moveMailFront(Email *)) ); | 55 | SLOT(moveMailFront(Email *)) ); |
58 | 56 | ||
59 | connect(emailClient, SIGNAL(newCaption(const QString &)), | 57 | connect(emailClient, SIGNAL(newCaption(const QString &)), |
60 | this, SLOT(updateCaption(const QString &)) ); | 58 | this, SLOT(updateCaption(const QString &)) ); |
61 | viewingMail = FALSE; | 59 | viewingMail = FALSE; |
62 | 60 | ||
63 | qWarning("***Finished MailitWindow"); | ||
64 | } | 61 | } |
65 | 62 | ||
66 | MailItWindow::~MailItWindow() | 63 | MailItWindow::~MailItWindow() |
67 | { | 64 | { |
68 | } | 65 | } |
69 | 66 | ||
70 | void MailItWindow::closeEvent(QCloseEvent *e) | 67 | void MailItWindow::closeEvent(QCloseEvent *e) |
71 | { | 68 | { |
72 | if (views->visibleWidget() == emailClient) { | 69 | if (views->visibleWidget() == emailClient) { |
73 | e->accept(); | 70 | e->accept(); |
74 | } else { | 71 | } else { |
75 | showEmailClient(); | 72 | showEmailClient(); |
76 | } | 73 | } |
77 | } | 74 | } |
78 | 75 | ||
79 | void MailItWindow::compose() | 76 | void MailItWindow::compose() |
80 | { | 77 | { |
81 | viewingMail = FALSE; | 78 | viewingMail = FALSE; |
82 | emailClient->hide(); | 79 | emailClient->hide(); |
83 | readMail->hide(); | 80 | readMail->hide(); |
84 | views->raiseWidget(writeMail); | 81 | views->raiseWidget(writeMail); |
85 | writeMail->setAddressList(emailClient->getAdrListRef()); | 82 | writeMail->setAddressList(emailClient->getAdrListRef()); |
86 | setCaption( tr( "Write mail" ) ); | 83 | setCaption( tr( "Write mail" ) ); |
87 | } | 84 | } |
88 | 85 | ||
89 | void MailItWindow::composeReply(Email &mail) | 86 | void MailItWindow::composeReply(Email &mail) |
90 | { | 87 | { |
91 | compose(); | 88 | compose(); |
92 | writeMail->reply(mail); | 89 | writeMail->reply(mail); |
93 | } | 90 | } |
94 | 91 | ||
95 | void MailItWindow::showEmailClient() | 92 | void MailItWindow::showEmailClient() |
96 | { | 93 | { |
97 | viewingMail = FALSE; | 94 | viewingMail = FALSE; |
98 | writeMail->hide(); | 95 | writeMail->hide(); |
99 | readMail->hide(); | 96 | readMail->hide(); |
100 | views->raiseWidget(emailClient); | 97 | views->raiseWidget(emailClient); |
101 | setCaption( tr(currentCaption) ); | 98 | setCaption( tr(currentCaption) ); |
102 | } | 99 | } |
103 | 100 | ||
104 | void MailItWindow::viewMail(QListView *view, Email *mail) | 101 | void MailItWindow::viewMail(QListView *view, Email *mail) |
105 | { | 102 | { |
106 | viewingMail = TRUE; | 103 | viewingMail = TRUE; |
107 | emailClient->hide(); | 104 | emailClient->hide(); |
108 | readMail->update(view, mail); | 105 | readMail->update(view, mail); |
109 | views->raiseWidget(readMail); | 106 | views->raiseWidget(readMail); |
110 | setCaption( tr( "Examine mail" ) ); | 107 | setCaption( tr( "Examine mail" ) ); |
111 | } | 108 | } |
112 | 109 | ||
113 | void MailItWindow::updateMailView(Email *mail) | 110 | void MailItWindow::updateMailView(Email *mail) |
114 | { | 111 | { |
115 | if (viewingMail) { | 112 | if (viewingMail) { |
116 | readMail->mailUpdated(mail); | 113 | readMail->mailUpdated(mail); |
117 | } | 114 | } |
118 | } | 115 | } |
119 | 116 | ||
120 | void MailItWindow::updateCaption(const QString &newCaption) | 117 | void MailItWindow::updateCaption(const QString &newCaption) |
121 | { | 118 | { |
122 | currentCaption = newCaption; | 119 | currentCaption = newCaption; |
123 | setCaption(tr(currentCaption)); | 120 | setCaption(tr(currentCaption)); |
124 | } | 121 | } |
125 | 122 | ||
126 | void MailItWindow::setDocument(const QString &_address) | 123 | void MailItWindow::setDocument(const QString &_address) |
127 | { | 124 | { |
128 | // strip leading 'mailto:' | 125 | // strip leading 'mailto:' |
129 | QString address = _address; | 126 | QString address = _address; |
130 | if (address.startsWith("mailto:")) | 127 | if (address.startsWith("mailto:")) |
131 | address = address.mid(6); | 128 | address = address.mid(6); |
132 | 129 | ||
133 | compose(); | 130 | compose(); |
134 | writeMail->setRecipient(address); | 131 | writeMail->setRecipient(address); |
135 | } | 132 | } |
136 | 133 | ||
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp index 2f14ed2..f9cc337 100644 --- a/noncore/net/mailit/popclient.cpp +++ b/noncore/net/mailit/popclient.cpp | |||
@@ -1,375 +1,375 @@ | |||
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 "popclient.h" | 20 | #include "popclient.h" |
21 | #include "emailhandler.h" | 21 | #include "emailhandler.h" |
22 | //#define APOP_TEST | 22 | //#define APOP_TEST |
23 | 23 | ||
24 | extern "C" { | 24 | extern "C" { |
25 | #include "md5.h" | 25 | #include "md5.h" |
26 | } | 26 | } |
27 | 27 | ||
28 | #include <qcstring.h> | 28 | #include <qcstring.h> |
29 | 29 | ||
30 | PopClient::PopClient() | 30 | PopClient::PopClient() |
31 | { | 31 | { |
32 | socket = new QSocket(this, "popClient"); | 32 | socket = new QSocket(this, "popClient"); |
33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
36 | 36 | ||
37 | stream = new QTextStream(socket); | 37 | stream = new QTextStream(socket); |
38 | 38 | ||
39 | receiving = FALSE; | 39 | receiving = FALSE; |
40 | synchronize = FALSE; | 40 | synchronize = FALSE; |
41 | lastSync = 0; | 41 | lastSync = 0; |
42 | headerLimit = 0; | 42 | headerLimit = 0; |
43 | preview = FALSE; | 43 | preview = FALSE; |
44 | } | 44 | } |
45 | 45 | ||
46 | PopClient::~PopClient() | 46 | PopClient::~PopClient() |
47 | { | 47 | { |
48 | delete socket; | 48 | delete socket; |
49 | delete stream; | 49 | delete stream; |
50 | } | 50 | } |
51 | 51 | ||
52 | void PopClient::newConnection(QString target, int port) | 52 | void PopClient::newConnection(QString target, int port) |
53 | { | 53 | { |
54 | if (receiving) { | 54 | if (receiving) { |
55 | qWarning("socket in use, connection refused"); | 55 | qWarning("socket in use, connection refused"); |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | status = Init; | 59 | status = Init; |
60 | 60 | ||
61 | socket->connectToHost(target, port); | 61 | socket->connectToHost(target, port); |
62 | receiving = TRUE; | 62 | receiving = TRUE; |
63 | selected = FALSE; | 63 | selected = FALSE; |
64 | 64 | ||
65 | emit updateStatus("DNS lookup"); | 65 | emit updateStatus("DNS lookup"); |
66 | } | 66 | } |
67 | 67 | ||
68 | void PopClient::setAccount(QString popUser, QString popPasswd) | 68 | void PopClient::setAccount(QString popUser, QString popPasswd) |
69 | { | 69 | { |
70 | popUserName = popUser; | 70 | popUserName = popUser; |
71 | popPassword = popPasswd; | 71 | popPassword = popPasswd; |
72 | } | 72 | } |
73 | 73 | ||
74 | void PopClient::setSynchronize(int lastCount) | 74 | void PopClient::setSynchronize(int lastCount) |
75 | { | 75 | { |
76 | synchronize = TRUE; | 76 | synchronize = TRUE; |
77 | lastSync = lastCount; | 77 | lastSync = lastCount; |
78 | } | 78 | } |
79 | 79 | ||
80 | void PopClient::removeSynchronize() | 80 | void PopClient::removeSynchronize() |
81 | { | 81 | { |
82 | synchronize = FALSE; | 82 | synchronize = FALSE; |
83 | lastSync = 0; | 83 | lastSync = 0; |
84 | } | 84 | } |
85 | 85 | ||
86 | void PopClient::headersOnly(bool headers, int limit) | 86 | void PopClient::headersOnly(bool headers, int limit) |
87 | { | 87 | { |
88 | preview = headers; | 88 | preview = headers; |
89 | headerLimit = limit; | 89 | headerLimit = limit; |
90 | } | 90 | } |
91 | 91 | ||
92 | void PopClient::setSelectedMails(MailList *list) | 92 | void PopClient::setSelectedMails(MailList *list) |
93 | { | 93 | { |
94 | selected = TRUE; | 94 | selected = TRUE; |
95 | mailList = list; | 95 | mailList = list; |
96 | } | 96 | } |
97 | 97 | ||
98 | void PopClient::connectionEstablished() | 98 | void PopClient::connectionEstablished() |
99 | { | 99 | { |
100 | emit updateStatus(tr("Connection established")); | 100 | emit updateStatus(tr("Connection established")); |
101 | } | 101 | } |
102 | 102 | ||
103 | void PopClient::errorHandling(int status) | 103 | void PopClient::errorHandling(int status) |
104 | { | 104 | { |
105 | emit updateStatus(tr("Error Occured")); | 105 | emit updateStatus(tr("Error Occured")); |
106 | emit errorOccurred(status); | 106 | emit errorOccurred(status); |
107 | socket->close(); | 107 | socket->close(); |
108 | receiving = FALSE; | 108 | receiving = FALSE; |
109 | } | 109 | } |
110 | 110 | ||
111 | void PopClient::incomingData() | 111 | void PopClient::incomingData() |
112 | { | 112 | { |
113 | QString response, temp, temp2, timeStamp; | 113 | QString response, temp, temp2, timeStamp; |
114 | QString md5Source; | 114 | QString md5Source; |
115 | int start, end; | 115 | int start, end; |
116 | // char *md5Digest; | 116 | // char *md5Digest; |
117 | char md5Digest[16]; | 117 | char md5Digest[16]; |
118 | // if ( !socket->canReadLine() ) | 118 | // if ( !socket->canReadLine() ) |
119 | // return; | 119 | // return; |
120 | 120 | ||
121 | response = socket->readLine(); | 121 | response = socket->readLine(); |
122 | qDebug(response +" %d", status); | 122 | //qDebug(response +" %d", status); |
123 | 123 | ||
124 | switch(status) { | 124 | switch(status) { |
125 | //logging in | 125 | //logging in |
126 | case Init: { | 126 | case Init: { |
127 | #ifdef APOP_TEST | 127 | #ifdef APOP_TEST |
128 | start = response.find('<',0); | 128 | start = response.find('<',0); |
129 | end = response.find('>', start); | 129 | end = response.find('>', start); |
130 | if( start >= 0 && end > start ) | 130 | if( start >= 0 && end > start ) |
131 | { | 131 | { |
132 | timeStamp = response.mid( start , end - start + 1); | 132 | timeStamp = response.mid( start , end - start + 1); |
133 | md5Source = timeStamp + popPassword; | 133 | md5Source = timeStamp + popPassword; |
134 | qDebug( md5Source); | 134 | //qDebug( md5Source); |
135 | // for( int i = 0; i < md5Source.length(); i++) { | 135 | // for( int i = 0; i < md5Source.length(); i++) { |
136 | // buff[i] = (QChar)md5Source[i]; | 136 | // buff[i] = (QChar)md5Source[i]; |
137 | // } | 137 | // } |
138 | 138 | ||
139 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); | 139 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); |
140 | // md5_buffer(char const *buffer, unsigned int len, char *digest); | 140 | // md5_buffer(char const *buffer, unsigned int len, char *digest); |
141 | 141 | ||
142 | // MD5_Init( &ctx); | 142 | // MD5_Init( &ctx); |
143 | // MD5_Update( &ctx, buff, sizeof( buff) ); | 143 | // MD5_Update( &ctx, buff, sizeof( buff) ); |
144 | // MD5_Final( md5Digest, &ctx); | 144 | // MD5_Final( md5Digest, &ctx); |
145 | // MD5( buff, md5Source.length(), md5Digest); | 145 | // MD5( buff, md5Source.length(), md5Digest); |
146 | 146 | ||
147 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) | 147 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) |
148 | { | 148 | { |
149 | printf("%x", md5Digest[j]); | 149 | printf("%x", md5Digest[j]); |
150 | } | 150 | } |
151 | printf("\n"); | 151 | printf("\n"); |
152 | // qDebug(md5Digest); | 152 | // qDebug(md5Digest); |
153 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; | 153 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; |
154 | // qDebug("%s", stream); | 154 | // qDebug("%s", stream); |
155 | status = Stat; | 155 | status = Stat; |
156 | } | 156 | } |
157 | else | 157 | else |
158 | #endif | 158 | #endif |
159 | { | 159 | { |
160 | timeStamp = ""; | 160 | timeStamp = ""; |
161 | *stream << "USER " << popUserName << "\r\n"; | 161 | *stream << "USER " << popUserName << "\r\n"; |
162 | status = Pass; | 162 | status = Pass; |
163 | } | 163 | } |
164 | 164 | ||
165 | break; | 165 | break; |
166 | } | 166 | } |
167 | //password shhh. don't tell anyone (implement APOP...) | 167 | //password shhh. don't tell anyone (implement APOP...) |
168 | case Pass: { | 168 | case Pass: { |
169 | *stream << "PASS " << popPassword << "\r\n"; | 169 | *stream << "PASS " << popPassword << "\r\n"; |
170 | status = Stat; | 170 | status = Stat; |
171 | break; | 171 | break; |
172 | } | 172 | } |
173 | //ask for number of messages | 173 | //ask for number of messages |
174 | case Stat: { | 174 | case Stat: { |
175 | if (response[0] == '+') { | 175 | if (response[0] == '+') { |
176 | *stream << "STAT" << "\r\n"; | 176 | *stream << "STAT" << "\r\n"; |
177 | status = Mcnt; | 177 | status = Mcnt; |
178 | } else errorHandling(ErrLoginFailed); | 178 | } else errorHandling(ErrLoginFailed); |
179 | break; | 179 | break; |
180 | } | 180 | } |
181 | //get count of messages, eg "+OK 4 900.." -> int 4 | 181 | //get count of messages, eg "+OK 4 900.." -> int 4 |
182 | case Mcnt: { | 182 | case Mcnt: { |
183 | if (response[0] == '+') { | 183 | if (response[0] == '+') { |
184 | temp = response.replace(0, 4, ""); | 184 | temp = response.replace(0, 4, ""); |
185 | int x = temp.find(" ", 0); | 185 | int x = temp.find(" ", 0); |
186 | temp.truncate((uint) x); | 186 | temp.truncate((uint) x); |
187 | newMessages = temp.toInt(); | 187 | newMessages = temp.toInt(); |
188 | messageCount = 1; | 188 | messageCount = 1; |
189 | status = List; | 189 | status = List; |
190 | 190 | ||
191 | if (synchronize) { | 191 | if (synchronize) { |
192 | //messages deleted from server, reload all | 192 | //messages deleted from server, reload all |
193 | if (newMessages < lastSync) | 193 | if (newMessages < lastSync) |
194 | lastSync = 0; | 194 | lastSync = 0; |
195 | messageCount = lastSync + 1; | 195 | messageCount = 1; |
196 | } | 196 | } |
197 | 197 | ||
198 | if (selected) { | 198 | if (selected) { |
199 | int *ptr = mailList->first(); | 199 | int *ptr = mailList->first(); |
200 | if (ptr != 0) { | 200 | if (ptr != 0) { |
201 | newMessages++; //to ensure no early jumpout | 201 | newMessages++; //to ensure no early jumpout |
202 | messageCount = *(mailList->first()); | 202 | messageCount = *(mailList->first()); |
203 | } else newMessages = 0; | 203 | } else newMessages = 0; |
204 | } | 204 | } |
205 | } else errorHandling(ErrUnknownResponse); | 205 | } else errorHandling(ErrUnknownResponse); |
206 | } | 206 | } |
207 | //Read message number x, count upwards to messageCount | 207 | //Read message number x, count upwards to messageCount |
208 | case List: { | 208 | case List: { |
209 | if (messageCount <= newMessages) { | 209 | if (messageCount <= newMessages) { |
210 | *stream << "LIST " << messageCount << "\r\n"; | 210 | *stream << "LIST " << messageCount << "\r\n"; |
211 | status = Size; | 211 | status = Size; |
212 | temp2.setNum(newMessages - lastSync); | 212 | temp2.setNum(newMessages - lastSync); |
213 | temp.setNum(messageCount - lastSync); | 213 | temp.setNum(messageCount - lastSync); |
214 | if (!selected) { | 214 | if (!selected) { |
215 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 215 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
216 | } else { | 216 | } else { |
217 | //completing a previously closed transfer | 217 | //completing a previously closed transfer |
218 | if ( (messageCount - lastSync) <= 0) { | 218 | if ( (messageCount - lastSync) <= 0) { |
219 | temp.setNum(messageCount); | 219 | temp.setNum(messageCount); |
220 | emit updateStatus(tr("Previous message ") + temp); | 220 | emit updateStatus(tr("Previous message ") + temp); |
221 | } else { | 221 | } else { |
222 | emit updateStatus(tr("Completing message ") + temp); | 222 | emit updateStatus(tr("Completing message ") + temp); |
223 | } | 223 | } |
224 | } | 224 | } |
225 | break; | 225 | break; |
226 | } else { | 226 | } else { |
227 | emit updateStatus(tr("No new Messages")); | 227 | emit updateStatus(tr("No new Messages")); |
228 | status = Quit; | 228 | status = Quit; |
229 | } | 229 | } |
230 | } | 230 | } |
231 | //get size of message, eg "500 characters in message.." -> int 500 | 231 | //get size of message, eg "500 characters in message.." -> int 500 |
232 | case Size: { | 232 | case Size: { |
233 | if (status != Quit) { //because of idiotic switch | 233 | if (status != Quit) { //because of idiotic switch |
234 | if (response[0] == '+') { | 234 | if (response[0] == '+') { |
235 | temp = response.replace(0, 4, ""); | 235 | temp = response.replace(0, 4, ""); |
236 | int x = temp.find(" ", 0); | 236 | int x = temp.find(" ", 0); |
237 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 237 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
238 | mailSize = temp.toInt(); | 238 | mailSize = temp.toInt(); |
239 | emit currentMailSize(mailSize); | 239 | emit currentMailSize(mailSize); |
240 | 240 | ||
241 | status = Retr; | 241 | status = Retr; |
242 | } else { | 242 | } else { |
243 | qWarning(response); | 243 | //qWarning(response); |
244 | errorHandling(ErrUnknownResponse); | 244 | errorHandling(ErrUnknownResponse); |
245 | } | 245 | } |
246 | } | 246 | } |
247 | } | 247 | } |
248 | //Read message number x, count upwards to messageCount | 248 | //Read message number x, count upwards to messageCount |
249 | case Retr: { | 249 | case Retr: { |
250 | if (status != Quit) { | 250 | if (status != Quit) { |
251 | if (!preview || mailSize <= headerLimit) { | 251 | if (!preview || mailSize <= headerLimit) { |
252 | *stream << "RETR " << messageCount << "\r\n"; | 252 | *stream << "RETR " << messageCount << "\r\n"; |
253 | } else { //only header | 253 | } else { //only header |
254 | *stream << "TOP " << messageCount << " 0\r\n"; | 254 | *stream << "TOP " << messageCount << " 0\r\n"; |
255 | } | 255 | } |
256 | messageCount++; | 256 | messageCount++; |
257 | status = Ignore; | 257 | status = Ignore; |
258 | break; | 258 | break; |
259 | } } | 259 | } } |
260 | case Ignore: { | 260 | case Ignore: { |
261 | if (status != Quit) { //because of idiotic switch | 261 | if (status != Quit) { //because of idiotic switch |
262 | if (response[0] == '+') { | 262 | if (response[0] == '+') { |
263 | message = ""; | 263 | message = ""; |
264 | status = Read; | 264 | status = Read; |
265 | if (!socket->canReadLine()) //sync. problems | 265 | if (!socket->canReadLine()) //sync. problems |
266 | break; | 266 | break; |
267 | response = socket->readLine(); | 267 | response = socket->readLine(); |
268 | } else errorHandling(ErrUnknownResponse); | 268 | } else errorHandling(ErrUnknownResponse); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | //add all incoming lines to body. When size is reached, send | 271 | //add all incoming lines to body. When size is reached, send |
272 | //message, and go back to read new message | 272 | //message, and go back to read new message |
273 | case Read: { | 273 | case Read: { |
274 | if (status != Quit) { //because of idiotic switch | 274 | if (status != Quit) { //because of idiotic switch |
275 | message += response; | 275 | message += response; |
276 | while ( socket->canReadLine() ) { | 276 | while ( socket->canReadLine() ) { |
277 | response = socket->readLine(); | 277 | response = socket->readLine(); |
278 | message += response; | 278 | message += response; |
279 | } | 279 | } |
280 | emit downloadedSize(message.length()); | 280 | emit downloadedSize(message.length()); |
281 | int x = message.find("\r\n.\r\n",-5); | 281 | int x = message.find("\r\n.\r\n",-5); |
282 | if (x == -1) { | 282 | if (x == -1) { |
283 | break; | 283 | break; |
284 | } else { //message reach entire size | 284 | } else { //message reach entire size |
285 | //complete mail downloaded | 285 | //complete mail downloaded |
286 | if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ | 286 | if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ |
287 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 287 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
288 | } else { //incomplete mail downloaded | 288 | } else { //incomplete mail downloaded |
289 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 289 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
290 | } | 290 | } |
291 | if (messageCount > newMessages) //that was the last message | 291 | if (messageCount > newMessages) //that was the last message |
292 | status = Quit; | 292 | status = Quit; |
293 | else { //ask for new message | 293 | else { //ask for new message |
294 | if (selected) { //grab next from queue | 294 | if (selected) { //grab next from queue |
295 | int *ptr = mailList->next(); | 295 | int *ptr = mailList->next(); |
296 | if (ptr != 0) { | 296 | if (ptr != 0) { |
297 | messageCount = *ptr; | 297 | messageCount = *ptr; |
298 | *stream << "LIST " << messageCount << "\r\n"; | 298 | *stream << "LIST " << messageCount << "\r\n"; |
299 | status = Size; | 299 | status = Size; |
300 | //completing a previously closed transfer | 300 | //completing a previously closed transfer |
301 | if ( (messageCount - lastSync) <= 0) { | 301 | if ( (messageCount - lastSync) <= 0) { |
302 | temp.setNum(messageCount); | 302 | temp.setNum(messageCount); |
303 | emit updateStatus(tr("Previous message ") + temp); | 303 | emit updateStatus(tr("Previous message ") + temp); |
304 | } else { | 304 | } else { |
305 | temp.setNum(messageCount - lastSync); | 305 | temp.setNum(messageCount - lastSync); |
306 | emit updateStatus(tr("Completing message ") + temp); | 306 | emit updateStatus(tr("Completing message ") + temp); |
307 | } | 307 | } |
308 | break; | 308 | break; |
309 | } else { | 309 | } else { |
310 | newMessages--; | 310 | newMessages--; |
311 | status = Quit; | 311 | status = Quit; |
312 | } | 312 | } |
313 | } else { | 313 | } else { |
314 | *stream << "LIST " << messageCount << "\r\n"; | 314 | *stream << "LIST " << messageCount << "\r\n"; |
315 | status = Size; | 315 | status = Size; |
316 | temp2.setNum(newMessages - lastSync); | 316 | temp2.setNum(newMessages - lastSync); |
317 | temp.setNum(messageCount - lastSync); | 317 | temp.setNum(messageCount - lastSync); |
318 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 318 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
319 | 319 | ||
320 | break; | 320 | break; |
321 | } | 321 | } |
322 | } | 322 | } |
323 | } | 323 | } |
324 | if (status != Quit) | 324 | if (status != Quit) |
325 | break; | 325 | break; |
326 | } | 326 | } |
327 | } | 327 | } |
328 | case Quit: { | 328 | case Quit: { |
329 | *stream << "Quit\r\n"; | 329 | *stream << "Quit\r\n"; |
330 | status = Done; | 330 | status = Done; |
331 | int newM = newMessages - lastSync; | 331 | int newM = newMessages - lastSync; |
332 | if (newM > 0) { | 332 | if (newM > 0) { |
333 | temp.setNum(newM); | 333 | temp.setNum(newM); |
334 | emit updateStatus(temp + tr(" new messages")); | 334 | emit updateStatus(temp + tr(" new messages")); |
335 | } else { | 335 | } else { |
336 | emit updateStatus(tr("No new messages")); | 336 | emit updateStatus(tr("No new messages")); |
337 | } | 337 | } |
338 | 338 | ||
339 | socket->close(); | 339 | socket->close(); |
340 | receiving = FALSE; | 340 | receiving = FALSE; |
341 | emit mailTransfered(newM); | 341 | emit mailTransfered(newM); |
342 | break; | 342 | break; |
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
346 | } | 346 | } |
347 | 347 | ||
348 | // if( bAPOPAuthentication ) | 348 | // if( bAPOPAuthentication ) |
349 | // { | 349 | // { |
350 | // if( m_strTimeStamp.IsEmpty() ) | 350 | // if( m_strTimeStamp.IsEmpty() ) |
351 | // { | 351 | // { |
352 | // SetLastError("Apop error!"); | 352 | // SetLastError("Apop error!"); |
353 | // return false; | 353 | // return false; |
354 | // } | 354 | // } |
355 | // strMD5Source = m_strTimeStamp+pszPassword; | 355 | // strMD5Source = m_strTimeStamp+pszPassword; |
356 | // strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); | 356 | // strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); |
357 | // sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); | 357 | // sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); |
358 | // ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); | 358 | // ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); |
359 | // if(ret == SOCKET_ERROR) | 359 | // if(ret == SOCKET_ERROR) |
360 | // { | 360 | // { |
361 | // SetLastError("Socket error!"); | 361 | // SetLastError("Socket error!"); |
362 | // m_bSocketOK = false; | 362 | // m_bSocketOK = false; |
363 | // m_bConnected = false; | 363 | // m_bConnected = false; |
364 | // return false; | 364 | // return false; |
365 | // } | 365 | // } |
366 | // if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) | 366 | // if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) |
367 | // return false; | 367 | // return false; |
368 | // if( 0 == strResult.Find('-' , 0) ) | 368 | // if( 0 == strResult.Find('-' , 0) ) |
369 | // { | 369 | // { |
370 | // SetLastError("Username or Password error!"); | 370 | // SetLastError("Username or Password error!"); |
371 | // return false; | 371 | // return false; |
372 | // } | 372 | // } |
373 | // m_bConnected = true; | 373 | // m_bConnected = true; |
374 | 374 | ||
375 | // } | 375 | // } |
diff --git a/noncore/net/mailit/readmail.cpp b/noncore/net/mailit/readmail.cpp index a5e7147..7cd3e09 100644 --- a/noncore/net/mailit/readmail.cpp +++ b/noncore/net/mailit/readmail.cpp | |||
@@ -1,326 +1,327 @@ | |||
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 "readmail.h" | 20 | #include "readmail.h" |
21 | #include <qimage.h> | 21 | #include <qimage.h> |
22 | #include <qmime.h> | 22 | #include <qmime.h> |
23 | #include <qaction.h> | 23 | #include <qaction.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) | 26 | ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) |
27 | : QMainWindow(parent, name, fl) | 27 | : QMainWindow(parent, name, fl) |
28 | { | 28 | { |
29 | plainTxt = FALSE; | 29 | plainTxt = FALSE; |
30 | 30 | ||
31 | init(); | 31 | init(); |
32 | viewAtt = new ViewAtt(0, "View Attatchments"); | 32 | viewAtt = new ViewAtt(0, "View Attatchments"); |
33 | } | 33 | } |
34 | 34 | ||
35 | ReadMail::~ReadMail() | 35 | ReadMail::~ReadMail() |
36 | { | 36 | { |
37 | delete emailView->mimeSourceFactory(); | 37 | delete emailView->mimeSourceFactory(); |
38 | delete viewAtt; | 38 | delete viewAtt; |
39 | } | 39 | } |
40 | 40 | ||
41 | void ReadMail::init() | 41 | void ReadMail::init() |
42 | { | 42 | { |
43 | setToolBarsMovable(FALSE); | 43 | setToolBarsMovable(FALSE); |
44 | 44 | ||
45 | bar = new QToolBar(this); | 45 | bar = new QToolBar(this); |
46 | bar->setHorizontalStretchable( TRUE ); | 46 | bar->setHorizontalStretchable( TRUE ); |
47 | 47 | ||
48 | menu = new QMenuBar( bar ); | 48 | menu = new QMenuBar( bar ); |
49 | 49 | ||
50 | viewMenu = new QPopupMenu(menu); | 50 | viewMenu = new QPopupMenu(menu); |
51 | menu->insertItem( tr( "&View" ), viewMenu); | 51 | menu->insertItem( tr( "&View" ), viewMenu); |
52 | 52 | ||
53 | mailMenu = new QPopupMenu(menu); | 53 | mailMenu = new QPopupMenu(menu); |
54 | menu->insertItem( tr( "&Mail" ), mailMenu); | 54 | menu->insertItem( tr( "&Mail" ), mailMenu); |
55 | 55 | ||
56 | bar = new QToolBar(this); | 56 | bar = new QToolBar(this); |
57 | 57 | ||
58 | //reply dependant on viewing inbox | 58 | //reply dependant on viewing inbox |
59 | replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), | 59 | replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), |
60 | QString::null, 0, this, 0 ); | 60 | QString::null, 0, this, 0 ); |
61 | connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) ); | 61 | connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) ); |
62 | 62 | ||
63 | previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | 63 | previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); |
64 | connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); | 64 | connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); |
65 | previousButton->addTo(bar); | 65 | previousButton->addTo(bar); |
66 | previousButton->addTo(viewMenu); | 66 | previousButton->addTo(viewMenu); |
67 | 67 | ||
68 | nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); | 68 | nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); |
69 | connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); | 69 | connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); |
70 | nextButton->addTo(bar); | 70 | nextButton->addTo(bar); |
71 | nextButton->addTo(viewMenu); | 71 | nextButton->addTo(viewMenu); |
72 | 72 | ||
73 | attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); | 73 | attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); |
74 | connect( attatchmentsButton, SIGNAL( activated() ), this, | 74 | connect( attatchmentsButton, SIGNAL( activated() ), this, |
75 | SLOT( viewAttatchments() ) ); | 75 | SLOT( viewAttatchments() ) ); |
76 | attatchmentsButton->addTo(bar); | 76 | attatchmentsButton->addTo(bar); |
77 | attatchmentsButton->addTo(viewMenu); | 77 | attatchmentsButton->addTo(viewMenu); |
78 | 78 | ||
79 | plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); | 79 | plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); |
80 | connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); | 80 | connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); |
81 | plainTextButton->addTo(bar); | 81 | plainTextButton->addTo(bar); |
82 | plainTextButton->addTo(viewMenu); | 82 | plainTextButton->addTo(viewMenu); |
83 | 83 | ||
84 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); | 84 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); |
85 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | 85 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); |
86 | deleteButton->addTo(bar); | 86 | deleteButton->addTo(bar); |
87 | deleteButton->addTo(mailMenu); | 87 | deleteButton->addTo(mailMenu); |
88 | 88 | ||
89 | viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); | 89 | viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); |
90 | 90 | ||
91 | emailView = new QTextView( this, "emailView" ); | 91 | emailView = new QTextView( this, "emailView" ); |
92 | |||
92 | setCentralWidget(emailView); | 93 | setCentralWidget(emailView); |
93 | 94 | ||
94 | mime = new QMimeSourceFactory(); | 95 | mime = new QMimeSourceFactory(); |
95 | emailView->setMimeSourceFactory(mime); | 96 | emailView->setMimeSourceFactory(mime); |
96 | } | 97 | } |
97 | 98 | ||
98 | void ReadMail::updateView() | 99 | void ReadMail::updateView() |
99 | { | 100 | { |
100 | Enclosure *ePtr; | 101 | Enclosure *ePtr; |
101 | QString mailStringSize; | 102 | QString mailStringSize; |
102 | QString text, temp; | 103 | QString text, temp; |
103 | 104 | ||
104 | mail->read = TRUE; //mark as read | 105 | mail->read = TRUE; //mark as read |
105 | inbox = mail->received; | 106 | inbox = mail->received; |
106 | 107 | ||
107 | replyButton->removeFrom(mailMenu); | 108 | replyButton->removeFrom(mailMenu); |
108 | replyButton->removeFrom(bar); | 109 | replyButton->removeFrom(bar); |
109 | 110 | ||
110 | if (inbox == TRUE) { | 111 | if (inbox == TRUE) { |
111 | replyButton->addTo(bar); | 112 | replyButton->addTo(bar); |
112 | replyButton->addTo(mailMenu); | 113 | replyButton->addTo(mailMenu); |
113 | 114 | ||
114 | if (!mail->downloaded) { | 115 | if (!mail->downloaded) { |
115 | //report currently viewed mail so that it will be | 116 | //report currently viewed mail so that it will be |
116 | //placed first in the queue of new mails to download | 117 | //placed first in the queue of new mails to download |
117 | emit viewingMail(mail); | 118 | emit viewingMail(mail); |
118 | 119 | ||
119 | double mailSize = (double) mail->size; | 120 | double mailSize = (double) mail->size; |
120 | if (mailSize < 1024) { | 121 | if (mailSize < 1024) { |
121 | mailStringSize.setNum(mailSize); | 122 | mailStringSize.setNum(mailSize); |
122 | mailStringSize += " Bytes"; | 123 | mailStringSize += " Bytes"; |
123 | } else if (mailSize < 1024*1024) { | 124 | } else if (mailSize < 1024*1024) { |
124 | mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); | 125 | mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); |
125 | mailStringSize += " Kb"; | 126 | mailStringSize += " Kb"; |
126 | } else { | 127 | } else { |
127 | mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); | 128 | mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); |
128 | mailStringSize += " Mb"; | 129 | mailStringSize += " Mb"; |
129 | } | 130 | } |
130 | } | 131 | } |
131 | } | 132 | } |
132 | 133 | ||
133 | QMimeSourceFactory *mime = emailView->mimeSourceFactory(); | 134 | QMimeSourceFactory *mime = emailView->mimeSourceFactory(); |
134 | 135 | ||
135 | if (! plainTxt) { //use RichText, inline pics etc. | 136 | if (! plainTxt) { //use RichText, inline pics etc. |
136 | emailView->setTextFormat(QTextView::RichText); | 137 | emailView->setTextFormat(QTextView::RichText); |
137 | text = "<b><big><center><font color=\"blue\">" + mail->subject | 138 | text = "<b><big><center><font color=\"blue\">" + mail->subject |
138 | +"</font></center></big></b><br>"; | 139 | +"</font></center></big></b><br>"; |
139 | text += "<b>From: </b>" + mail->from + " <i>" + | 140 | text += "<b>From: </b>" + mail->from + " <i>" + |
140 | mail->fromMail + "</i><br>"; | 141 | mail->fromMail + "</i><br>"; |
141 | 142 | ||
142 | text +="<b>To: </b>"; | 143 | text +="<b>To: </b>"; |
143 | for (QStringList::Iterator it = mail->recipients.begin(); | 144 | for (QStringList::Iterator it = mail->recipients.begin(); |
144 | it != mail->recipients.end(); ++it ) { | 145 | it != mail->recipients.end(); ++it ) { |
145 | text += *it + " "; | 146 | text += *it + " "; |
146 | } | 147 | } |
147 | text += "<br>" + mail->date; | 148 | text += "<br>" + mail->date; |
148 | 149 | ||
149 | if (mail->files.count() > 0) { | 150 | if (mail->files.count() > 0) { |
150 | text += "<br><b>Attatchments: </b>"; | 151 | text += "<br><b>Attatchments: </b>"; |
151 | 152 | ||
152 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 153 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
153 | text += ePtr->originalName + " "; | 154 | text += ePtr->originalName + " "; |
154 | } | 155 | } |
155 | text += "<hr><br>" + mail->body; | 156 | text += "<hr><br>" + mail->body; |
156 | 157 | ||
157 | if (inbox) { | 158 | if (inbox) { |
158 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 159 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
159 | 160 | ||
160 | text += "<br><hr><b>Attatchment: </b>" + | 161 | text += "<br><hr><b>Attatchment: </b>" + |
161 | ePtr->originalName + "<hr>"; | 162 | ePtr->originalName + "<hr>"; |
162 | 163 | ||
163 | if (ePtr->contentType == "TEXT") { | 164 | if (ePtr->contentType == "TEXT") { |
164 | QFile f(ePtr->path + ePtr->name); | 165 | QFile f(ePtr->path + ePtr->name); |
165 | 166 | ||
166 | if (f.open(IO_ReadOnly) ) { | 167 | if (f.open(IO_ReadOnly) ) { |
167 | QTextStream t(&f); | 168 | QTextStream t(&f); |
168 | temp = t.read(); | 169 | temp = t.read(); |
169 | text += temp + "<br>"; | 170 | text += temp + "<br>"; |
170 | f.close(); | 171 | f.close(); |
171 | } else { | 172 | } else { |
172 | text += "<b>Could not locate file</b><br>"; | 173 | text += "<b>Could not locate file</b><br>"; |
173 | } | 174 | } |
174 | 175 | ||
175 | } | 176 | } |
176 | if (ePtr->contentType == "IMAGE") { | 177 | if (ePtr->contentType == "IMAGE") { |
177 | // temp.setNum(emailView->width());//get display width | 178 | // temp.setNum(emailView->width());//get display width |
178 | // text += "<img width=" + temp +" src =""" + | 179 | // text += "<img width=" + temp +" src =""" + |
179 | // ePtr->originalName + """> </img>"; | 180 | // ePtr->originalName + """> </img>"; |
180 | text += "<img src =""" + | 181 | text += "<img src =""" + |
181 | ePtr->originalName + """> </img>"; | 182 | ePtr->originalName + """> </img>"; |
182 | mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); | 183 | mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); |
183 | } | 184 | } |
184 | } | 185 | } |
185 | } | 186 | } |
186 | } else { | 187 | } else { |
187 | if (mail->downloaded || !inbox) { | 188 | if (mail->downloaded || !inbox) { |
188 | text += "<hr><br>" + mail->body; | 189 | text += "<hr><br>" + mail->body; |
189 | } else { | 190 | } else { |
190 | text += "<hr><br><b> Awaiting download </b><br>"; | 191 | text += "<hr><br><b> Awaiting download </b><br>"; |
191 | text += "Size of mail: " + mailStringSize; | 192 | text += "Size of mail: " + mailStringSize; |
192 | } | 193 | } |
193 | } | 194 | } |
194 | emailView->setText(text); | 195 | emailView->setText(text); |
195 | } else { // show plain txt mail | 196 | } else { // show plain txt mail |
196 | emailView->setTextFormat(QTextView::PlainText); | 197 | emailView->setTextFormat(QTextView::PlainText); |
197 | text = "Subject: " + mail->subject + "\n"; | 198 | text = "Subject: " + mail->subject + "\n"; |
198 | text += "From: " + mail->from + " " + mail->fromMail + "\n"; | 199 | text += "From: " + mail->from + " " + mail->fromMail + "\n"; |
199 | text += "To: "; | 200 | text += "To: "; |
200 | for (QStringList::Iterator it = mail->recipients.begin(); | 201 | for (QStringList::Iterator it = mail->recipients.begin(); |
201 | it != mail->recipients.end(); ++it ) { | 202 | it != mail->recipients.end(); ++it ) { |
202 | text += *it + " "; | 203 | text += *it + " "; |
203 | } | 204 | } |
204 | text += "\nDate: " + mail->date + "\n"; | 205 | text += "\nDate: " + mail->date + "\n"; |
205 | if (mail->files.count() > 0) { | 206 | if (mail->files.count() > 0) { |
206 | text += "Attatchments: "; | 207 | text += "Attatchments: "; |
207 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 208 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
208 | text += ePtr->originalName + " "; | 209 | text += ePtr->originalName + " "; |
209 | } | 210 | } |
210 | text += "\n\n"; | 211 | text += "\n\n"; |
211 | } else text += "\n"; | 212 | } else text += "\n"; |
212 | 213 | ||
213 | if (!inbox) { | 214 | if (!inbox) { |
214 | text += mail->body; | 215 | text += mail->body; |
215 | } else if (mail->downloaded) { | 216 | } else if (mail->downloaded) { |
216 | text += mail->bodyPlain; | 217 | text += mail->bodyPlain; |
217 | } else { | 218 | } else { |
218 | text += "\nAwaiting download\n"; | 219 | text += "\nAwaiting download\n"; |
219 | text += "Size of mail: " + mailStringSize; | 220 | text += "Size of mail: " + mailStringSize; |
220 | } | 221 | } |
221 | 222 | ||
222 | emailView->setText(text); | 223 | emailView->setText(text); |
223 | } | 224 | } |
224 | 225 | ||
225 | if (mail->files.count() == 0) | 226 | if (mail->files.count() == 0) |
226 | attatchmentsButton->setEnabled(FALSE); | 227 | attatchmentsButton->setEnabled(FALSE); |
227 | else attatchmentsButton->setEnabled(TRUE); | 228 | else attatchmentsButton->setEnabled(TRUE); |
228 | 229 | ||
229 | setCaption("Examining mail: " + mail->subject); | 230 | setCaption("Examining mail: " + mail->subject); |
230 | } | 231 | } |
231 | 232 | ||
232 | //update view with current EmailListItem (item) | 233 | //update view with current EmailListItem (item) |
233 | void ReadMail::update(QListView *thisView, Email *mailIn) | 234 | void ReadMail::update(QListView *thisView, Email *mailIn) |
234 | { | 235 | { |
235 | view = thisView; | 236 | view = thisView; |
236 | item = (EmailListItem *) view->selectedItem(); | 237 | item = (EmailListItem *) view->selectedItem(); |
237 | mail = mailIn; | 238 | mail = mailIn; |
238 | updateView(); | 239 | updateView(); |
239 | updateButtons(); | 240 | updateButtons(); |
240 | } | 241 | } |
241 | 242 | ||
242 | void ReadMail::mailUpdated(Email *mailIn) | 243 | void ReadMail::mailUpdated(Email *mailIn) |
243 | { | 244 | { |
244 | if (mailIn == mail) { | 245 | if (mailIn == mail) { |
245 | updateView(); | 246 | updateView(); |
246 | } else { | 247 | } else { |
247 | updateButtons(); | 248 | updateButtons(); |
248 | } | 249 | } |
249 | } | 250 | } |
250 | 251 | ||
251 | void ReadMail::close() | 252 | void ReadMail::close() |
252 | { | 253 | { |
253 | emit cancelView(); | 254 | emit cancelView(); |
254 | } | 255 | } |
255 | 256 | ||
256 | //gets next item in listview, exits if there is no next | 257 | //gets next item in listview, exits if there is no next |
257 | void ReadMail::next() | 258 | void ReadMail::next() |
258 | { | 259 | { |
259 | item = (EmailListItem *) item->nextSibling(); | 260 | item = (EmailListItem *) item->nextSibling(); |
260 | if (item != NULL) { | 261 | if (item != NULL) { |
261 | mail = item->getMail(); | 262 | mail = item->getMail(); |
262 | updateView(); | 263 | updateView(); |
263 | } | 264 | } |
264 | updateButtons(); | 265 | updateButtons(); |
265 | } | 266 | } |
266 | 267 | ||
267 | //gets previous item in listview, exits if there is no previous | 268 | //gets previous item in listview, exits if there is no previous |
268 | void ReadMail::previous() | 269 | void ReadMail::previous() |
269 | { | 270 | { |
270 | item = (EmailListItem *) item->itemAbove(); | 271 | item = (EmailListItem *) item->itemAbove(); |
271 | if (item != NULL) { | 272 | if (item != NULL) { |
272 | mail = item->getMail(); | 273 | mail = item->getMail(); |
273 | updateView(); | 274 | updateView(); |
274 | } | 275 | } |
275 | updateButtons(); | 276 | updateButtons(); |
276 | } | 277 | } |
277 | 278 | ||
278 | //deletes item, tries bringing up next or previous, exits if unsucessful | 279 | //deletes item, tries bringing up next or previous, exits if unsucessful |
279 | void ReadMail::deleteItem() | 280 | void ReadMail::deleteItem() |
280 | { | 281 | { |
281 | EmailListItem *temp = item; | 282 | EmailListItem *temp = item; |
282 | temp = (EmailListItem *) item->nextSibling();//trybelow | 283 | temp = (EmailListItem *) item->nextSibling();//trybelow |
283 | if (temp == NULL) | 284 | if (temp == NULL) |
284 | temp = (EmailListItem *) item->itemAbove(); //try above | 285 | temp = (EmailListItem *) item->itemAbove(); //try above |
285 | 286 | ||
286 | emit removeItem(item, inbox); | 287 | emit removeItem(item, inbox); |
287 | 288 | ||
288 | item = temp; | 289 | item = temp; |
289 | if (item != NULL) { //more items in list | 290 | if (item != NULL) { //more items in list |
290 | mail = item->getMail(); | 291 | mail = item->getMail(); |
291 | updateView(); | 292 | updateView(); |
292 | updateButtons(); | 293 | updateButtons(); |
293 | } else close(); //no more items to see | 294 | } else close(); //no more items to see |
294 | } | 295 | } |
295 | 296 | ||
296 | void ReadMail::updateButtons() | 297 | void ReadMail::updateButtons() |
297 | { | 298 | { |
298 | EmailListItem *temp; | 299 | EmailListItem *temp; |
299 | 300 | ||
300 | temp = item; | 301 | temp = item; |
301 | if ((EmailListItem *) temp->nextSibling() == NULL) | 302 | if ((EmailListItem *) temp->nextSibling() == NULL) |
302 | nextButton->setEnabled(FALSE); | 303 | nextButton->setEnabled(FALSE); |
303 | else nextButton->setEnabled(TRUE); | 304 | else nextButton->setEnabled(TRUE); |
304 | 305 | ||
305 | temp = item; | 306 | temp = item; |
306 | if ((EmailListItem *) temp->itemAbove() == NULL) | 307 | if ((EmailListItem *) temp->itemAbove() == NULL) |
307 | previousButton->setEnabled(FALSE); | 308 | previousButton->setEnabled(FALSE); |
308 | else previousButton->setEnabled(TRUE); | 309 | else previousButton->setEnabled(TRUE); |
309 | } | 310 | } |
310 | 311 | ||
311 | void ReadMail::shiftText() | 312 | void ReadMail::shiftText() |
312 | { | 313 | { |
313 | plainTxt = ! plainTxt; | 314 | plainTxt = ! plainTxt; |
314 | updateView(); | 315 | updateView(); |
315 | } | 316 | } |
316 | 317 | ||
317 | void ReadMail::viewAttatchments() | 318 | void ReadMail::viewAttatchments() |
318 | { | 319 | { |
319 | viewAtt->update(mail, inbox); | 320 | viewAtt->update(mail, inbox); |
320 | viewAtt->showMaximized(); | 321 | viewAtt->showMaximized(); |
321 | } | 322 | } |
322 | 323 | ||
323 | void ReadMail::reply() | 324 | void ReadMail::reply() |
324 | { | 325 | { |
325 | emit replyRequested(*mail); | 326 | emit replyRequested(*mail); |
326 | } | 327 | } |
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp index 6699a90..b2e38e5 100644 --- a/noncore/net/mailit/smtpclient.cpp +++ b/noncore/net/mailit/smtpclient.cpp | |||
@@ -1,171 +1,171 @@ | |||
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 "smtpclient.h" | 20 | #include "smtpclient.h" |
21 | #include "emailhandler.h" | 21 | #include "emailhandler.h" |
22 | 22 | ||
23 | SmtpClient::SmtpClient() | 23 | SmtpClient::SmtpClient() |
24 | { | 24 | { |
25 | socket = new QSocket(this, "smtpClient"); | 25 | socket = new QSocket(this, "smtpClient"); |
26 | stream = new QTextStream(socket); | 26 | stream = new QTextStream(socket); |
27 | mailList.setAutoDelete(TRUE); | 27 | mailList.setAutoDelete(TRUE); |
28 | 28 | ||
29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
32 | 32 | ||
33 | sending = FALSE; | 33 | sending = FALSE; |
34 | } | 34 | } |
35 | 35 | ||
36 | SmtpClient::~SmtpClient() | 36 | SmtpClient::~SmtpClient() |
37 | { | 37 | { |
38 | delete socket; | 38 | delete socket; |
39 | delete stream; | 39 | delete stream; |
40 | } | 40 | } |
41 | 41 | ||
42 | void SmtpClient::newConnection(QString target, int port) | 42 | void SmtpClient::newConnection(QString target, int port) |
43 | { | 43 | { |
44 | if (sending) { | 44 | if (sending) { |
45 | qWarning("socket in use, connection refused"); | 45 | qWarning("socket in use, connection refused"); |
46 | return; | 46 | return; |
47 | } | 47 | } |
48 | 48 | ||
49 | status = Init; | 49 | status = Init; |
50 | sending = TRUE; | 50 | sending = TRUE; |
51 | socket->connectToHost(target, port); | 51 | socket->connectToHost(target, port); |
52 | 52 | ||
53 | emit updateStatus(tr("DNS lookup")); | 53 | emit updateStatus(tr("DNS lookup")); |
54 | } | 54 | } |
55 | 55 | ||
56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) | 56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) |
57 | { | 57 | { |
58 | RawEmail *mail = new RawEmail; | 58 | RawEmail *mail = new RawEmail; |
59 | 59 | ||
60 | mail->from = from; | 60 | mail->from = from; |
61 | mail->subject = subject; | 61 | mail->subject = subject; |
62 | mail->to = to; | 62 | mail->to = to; |
63 | mail->body = body; | 63 | mail->body = body; |
64 | 64 | ||
65 | mailList.append(mail); | 65 | mailList.append(mail); |
66 | } | 66 | } |
67 | 67 | ||
68 | void SmtpClient::connectionEstablished() | 68 | void SmtpClient::connectionEstablished() |
69 | { | 69 | { |
70 | emit updateStatus(tr("Connection established")); | 70 | emit updateStatus(tr("Connection established")); |
71 | 71 | ||
72 | } | 72 | } |
73 | 73 | ||
74 | void SmtpClient::errorHandling(int status) | 74 | void SmtpClient::errorHandling(int status) |
75 | { | 75 | { |
76 | emit errorOccurred(status); | 76 | emit errorOccurred(status); |
77 | socket->close(); | 77 | socket->close(); |
78 | mailList.clear(); | 78 | mailList.clear(); |
79 | sending = FALSE; | 79 | sending = FALSE; |
80 | } | 80 | } |
81 | 81 | ||
82 | void SmtpClient::incomingData() | 82 | void SmtpClient::incomingData() |
83 | { | 83 | { |
84 | QString response; | 84 | QString response; |
85 | 85 | ||
86 | if (!socket->canReadLine()) | 86 | if (!socket->canReadLine()) |
87 | return; | 87 | return; |
88 | 88 | ||
89 | response = socket->readLine(); | 89 | response = socket->readLine(); |
90 | qDebug(response); | 90 | //qDebug(response); |
91 | 91 | ||
92 | switch(status) { | 92 | switch(status) { |
93 | case Init: { | 93 | case Init: { |
94 | if (response[0] == '2') { | 94 | if (response[0] == '2') { |
95 | status = From; | 95 | status = From; |
96 | mailPtr = mailList.first(); | 96 | mailPtr = mailList.first(); |
97 | *stream << "HELO there\r\n"; | 97 | *stream << "HELO there\r\n"; |
98 | qDebug("HELO"); | 98 | //qDebug("HELO"); |
99 | } else errorHandling(ErrUnknownResponse); | 99 | } else errorHandling(ErrUnknownResponse); |
100 | break; | 100 | break; |
101 | } | 101 | } |
102 | case From: { | 102 | case From: { |
103 | if (response[0] == '2') { | 103 | if (response[0] == '2') { |
104 | *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; | 104 | *stream << "MAIL FROM: " << mailPtr->from << "\r\n"; |
105 | status = Recv; | 105 | status = Recv; |
106 | qDebug("MAIL FROM: "+mailPtr->from); | 106 | //qDebug("MAIL FROM: "+mailPtr->from); |
107 | } else errorHandling(ErrUnknownResponse); | 107 | } else errorHandling(ErrUnknownResponse); |
108 | break; | 108 | break; |
109 | } | 109 | } |
110 | case Recv: { | 110 | case Recv: { |
111 | if (response[0] == '2') { | 111 | if (response[0] == '2') { |
112 | it = mailPtr->to.begin(); | 112 | it = mailPtr->to.begin(); |
113 | if (it == NULL) | 113 | if (it == NULL) |
114 | errorHandling(ErrUnknownResponse); | 114 | errorHandling(ErrUnknownResponse); |
115 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 115 | *stream << "RCPT TO: " << *it << ">\r\n"; |
116 | qDebug("RCPT TO: "+ *it); | 116 | //qDebug("RCPT TO: "+ *it); |
117 | status = MRcv; | 117 | status = MRcv; |
118 | } else errorHandling(ErrUnknownResponse); | 118 | } else errorHandling(ErrUnknownResponse); |
119 | break; | 119 | break; |
120 | } | 120 | } |
121 | case MRcv: { | 121 | case MRcv: { |
122 | if (response[0] == '2') { | 122 | if (response[0] == '2') { |
123 | it++; | 123 | it++; |
124 | if ( it != mailPtr->to.end() ) { | 124 | if ( it != mailPtr->to.end() ) { |
125 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 125 | *stream << "RCPT TO: <" << *it << ">\r\n"; |
126 | qDebug("RCPT TO: "+ *it); | 126 | //qDebug("RCPT TO: "+ *it); |
127 | break; | 127 | break; |
128 | } else { | 128 | } else { |
129 | status = Data; | 129 | status = Data; |
130 | } | 130 | } |
131 | } else errorHandling(ErrUnknownResponse); | 131 | } else errorHandling(ErrUnknownResponse); |
132 | } | 132 | } |
133 | case Data: { | 133 | case Data: { |
134 | if (response[0] == '2') { | 134 | if (response[0] == '2') { |
135 | *stream << "DATA\r\n"; | 135 | *stream << "DATA\r\n"; |
136 | status = Body; | 136 | status = Body; |
137 | qDebug("DATA"); | 137 | //qDebug("DATA"); |
138 | emit updateStatus(tr("Sending: ") + mailPtr->subject); | 138 | emit updateStatus(tr("Sending: ") + mailPtr->subject); |
139 | } else errorHandling(ErrUnknownResponse); | 139 | } else errorHandling(ErrUnknownResponse); |
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | case Body: { | 142 | case Body: { |
143 | if (response[0] == '3') { | 143 | if (response[0] == '3') { |
144 | *stream << mailPtr->body << "\r\n.\r\n"; | 144 | *stream << mailPtr->body << "\r\n.\r\n"; |
145 | mailPtr = mailList.next(); | 145 | mailPtr = mailList.next(); |
146 | if (mailPtr != NULL) { | 146 | if (mailPtr != NULL) { |
147 | status = From; | 147 | status = From; |
148 | } else { | 148 | } else { |
149 | status = Quit; | 149 | status = Quit; |
150 | } | 150 | } |
151 | qDebug("BODY"); | 151 | //qDebug("BODY"); |
152 | } else errorHandling(ErrUnknownResponse); | 152 | } else errorHandling(ErrUnknownResponse); |
153 | break; | 153 | break; |
154 | } | 154 | } |
155 | case Quit: { | 155 | case Quit: { |
156 | if (response[0] == '2') { | 156 | if (response[0] == '2') { |
157 | *stream << "QUIT\r\n"; | 157 | *stream << "QUIT\r\n"; |
158 | status = Done; | 158 | status = Done; |
159 | QString temp; | 159 | QString temp; |
160 | temp.setNum(mailList.count()); | 160 | temp.setNum(mailList.count()); |
161 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); | 161 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); |
162 | emit mailSent(); | 162 | emit mailSent(); |
163 | mailList.clear(); | 163 | mailList.clear(); |
164 | sending = FALSE; | 164 | sending = FALSE; |
165 | socket->close(); | 165 | socket->close(); |
166 | qDebug("QUIT"); | 166 | //qDebug("QUIT"); |
167 | } else errorHandling(ErrUnknownResponse); | 167 | } else errorHandling(ErrUnknownResponse); |
168 | break; | 168 | break; |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
diff --git a/noncore/unsupported/mailit/addresslist.cpp b/noncore/unsupported/mailit/addresslist.cpp index 9fe558a..8d9ab91 100644 --- a/noncore/unsupported/mailit/addresslist.cpp +++ b/noncore/unsupported/mailit/addresslist.cpp | |||
@@ -1,161 +1,161 @@ | |||
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 <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qtextstream.h> | 21 | #include <qtextstream.h> |
22 | #include <opie/ocontactaccess.h> | 22 | #include <opie/ocontactaccess.h> |
23 | #include <opie/ocontact.h> | 23 | #include <opie/ocontact.h> |
24 | 24 | ||
25 | #include "addresslist.h" | 25 | #include "addresslist.h" |
26 | 26 | ||
27 | AddressList::AddressList() | 27 | AddressList::AddressList() |
28 | { | 28 | { |
29 | addresses.setAutoDelete(TRUE); | 29 | addresses.setAutoDelete(TRUE); |
30 | read(); | 30 | read(); |
31 | dirty = FALSE; | 31 | dirty = FALSE; |
32 | } | 32 | } |
33 | 33 | ||
34 | AddressList::~AddressList() | 34 | AddressList::~AddressList() |
35 | { | 35 | { |
36 | addresses.clear(); | 36 | addresses.clear(); |
37 | } | 37 | } |
38 | 38 | ||
39 | void AddressList::addContact(QString email, QString name) | 39 | void AddressList::addContact(QString email, QString name) |
40 | { | 40 | { |
41 | //skip if not a valid email address, | 41 | //skip if not a valid email address, |
42 | if (email.find( '@') == -1) | 42 | if (email.find( '@') == -1) |
43 | return; | 43 | return; |
44 | 44 | ||
45 | if ( ! containsEmail(email) ) { | 45 | if ( ! containsEmail(email) ) { |
46 | Contact *in = new Contact; | 46 | Contact *in = new Contact; |
47 | in->email = email; | 47 | in->email = email; |
48 | in->name = name; | 48 | in->name = name; |
49 | addresses.append(in); | 49 | addresses.append(in); |
50 | dirty = TRUE; | 50 | dirty = TRUE; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | bool AddressList::containsEmail(QString email) | 54 | bool AddressList::containsEmail(QString email) |
55 | { | 55 | { |
56 | return ( getEmailRef(email) != -1 ); | 56 | return ( getEmailRef(email) != -1 ); |
57 | } | 57 | } |
58 | 58 | ||
59 | bool AddressList::containsName(QString name) | 59 | bool AddressList::containsName(QString name) |
60 | { | 60 | { |
61 | return ( getNameRef(name) != -1 ); | 61 | return ( getNameRef(name) != -1 ); |
62 | } | 62 | } |
63 | 63 | ||
64 | QString AddressList::getNameByEmail(QString email) | 64 | QString AddressList::getNameByEmail(QString email) |
65 | { | 65 | { |
66 | int pos = getEmailRef(email); | 66 | int pos = getEmailRef(email); |
67 | if (pos != -1) { | 67 | if (pos != -1) { |
68 | Contact *ptr = addresses.at(pos); | 68 | Contact *ptr = addresses.at(pos); |
69 | return ptr->name; | 69 | return ptr->name; |
70 | } | 70 | } |
71 | 71 | ||
72 | return NULL; | 72 | return NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | QString AddressList::getEmailByName(QString name) | 75 | QString AddressList::getEmailByName(QString name) |
76 | { | 76 | { |
77 | int pos = getNameRef(name); | 77 | int pos = getNameRef(name); |
78 | if (pos != -1) { | 78 | if (pos != -1) { |
79 | Contact *ptr = addresses.at(pos); | 79 | Contact *ptr = addresses.at(pos); |
80 | return ptr->email; | 80 | return ptr->email; |
81 | } | 81 | } |
82 | 82 | ||
83 | return NULL; | 83 | return NULL; |
84 | } | 84 | } |
85 | 85 | ||
86 | int AddressList::getEmailRef(QString email) | 86 | int AddressList::getEmailRef(QString email) |
87 | { | 87 | { |
88 | int pos = 0; | 88 | int pos = 0; |
89 | Contact *ptr; | 89 | Contact *ptr; |
90 | 90 | ||
91 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { | 91 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { |
92 | if (ptr->email == email) | 92 | if (ptr->email == email) |
93 | return pos; | 93 | return pos; |
94 | pos++; | 94 | pos++; |
95 | } | 95 | } |
96 | return -1; | 96 | return -1; |
97 | } | 97 | } |
98 | 98 | ||
99 | int AddressList::getNameRef(QString name) | 99 | int AddressList::getNameRef(QString name) |
100 | { | 100 | { |
101 | int pos = 0; | 101 | int pos = 0; |
102 | Contact *ptr; | 102 | Contact *ptr; |
103 | 103 | ||
104 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { | 104 | for (ptr = addresses.first(); ptr != 0; ptr = addresses.next() ) { |
105 | if (ptr->name == name) | 105 | if (ptr->name == name) |
106 | return pos; | 106 | return pos; |
107 | pos++; | 107 | pos++; |
108 | } | 108 | } |
109 | return -1; | 109 | return -1; |
110 | } | 110 | } |
111 | 111 | ||
112 | QList<Contact>* AddressList::getContactList() | 112 | QList<Contact>* AddressList::getContactList() |
113 | { | 113 | { |
114 | return &addresses; | 114 | return &addresses; |
115 | } | 115 | } |
116 | 116 | ||
117 | void AddressList::read() | 117 | void AddressList::read() |
118 | { | 118 | { |
119 | OContactAccess::List::Iterator it; | 119 | OContactAccess::List::Iterator it; |
120 | 120 | ||
121 | QString lineEmail, lineName, email, name; | 121 | QString lineEmail, lineName, email, name; |
122 | OContactAccess m_contactdb("mailit"); | 122 | OContactAccess m_contactdb("mailit"); |
123 | OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); | 123 | OContactAccess::List m_list = m_contactdb.sorted( true, 0, 0, 0 ); |
124 | //OContact* oc; | 124 | //OContact* oc; |
125 | 125 | ||
126 | for ( it = m_list.begin(); it != m_list.end(); ++it ) | 126 | for ( it = m_list.begin(); it != m_list.end(); ++it ) |
127 | { | 127 | { |
128 | //oc=(OContact*) it; | 128 | //oc=(OContact*) it; |
129 | if ((*it).defaultEmail().length()!=0) | 129 | if ((*it).defaultEmail().length()!=0) |
130 | addContact((*it).defaultEmail(),(*it).fullName()); | 130 | addContact((*it).defaultEmail(),(*it).fileAs()); |
131 | } | 131 | } |
132 | 132 | ||
133 | /*if (! f.open(IO_ReadOnly) ) | 133 | /*if (! f.open(IO_ReadOnly) ) |
134 | return; | 134 | return; |
135 | 135 | ||
136 | QTextStream stream(&f); | 136 | QTextStream stream(&f); |
137 | 137 | ||
138 | while (! stream.atEnd() ) { | 138 | while (! stream.atEnd() ) { |
139 | lineEmail = stream.readLine(); | 139 | lineEmail = stream.readLine(); |
140 | if (! stream.atEnd() ) | 140 | if (! stream.atEnd() ) |
141 | lineName = stream.readLine(); | 141 | lineName = stream.readLine(); |
142 | else return; | 142 | else return; |
143 | 143 | ||
144 | email = getRightString(lineEmail); | 144 | email = getRightString(lineEmail); |
145 | name = getRightString(lineName); | 145 | name = getRightString(lineName); |
146 | addContact(email, name); | 146 | addContact(email, name); |
147 | } | 147 | } |
148 | f.close();*/ | 148 | f.close();*/ |
149 | } | 149 | } |
150 | 150 | ||
151 | QString AddressList::getRightString(QString in) | 151 | QString AddressList::getRightString(QString in) |
152 | { | 152 | { |
153 | QString out = ""; | 153 | QString out = ""; |
154 | 154 | ||
155 | int pos = in.find('='); | 155 | int pos = in.find('='); |
156 | if (pos != -1) { | 156 | if (pos != -1) { |
157 | out = in.mid(pos+1).stripWhiteSpace(); | 157 | out = in.mid(pos+1).stripWhiteSpace(); |
158 | } | 158 | } |
159 | return out; | 159 | return out; |
160 | } | 160 | } |
161 | 161 | ||
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp index 6612541..0d82a9a 100644 --- a/noncore/unsupported/mailit/emailclient.cpp +++ b/noncore/unsupported/mailit/emailclient.cpp | |||
@@ -279,572 +279,572 @@ void EmailClient::mailSent() | |||
279 | void EmailClient::getNewMail() { | 279 | void EmailClient::getNewMail() { |
280 | 280 | ||
281 | if (accountList.count() == 0) { | 281 | if (accountList.count() == 0) { |
282 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 282 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
283 | "You must create an account", "OK\n"); | 283 | "You must create an account", "OK\n"); |
284 | return; | 284 | return; |
285 | } | 285 | } |
286 | 286 | ||
287 | setMailAccount(); | 287 | setMailAccount(); |
288 | 288 | ||
289 | receiving = TRUE; | 289 | receiving = TRUE; |
290 | previewingMail = TRUE; | 290 | previewingMail = TRUE; |
291 | getMailButton->setEnabled(FALSE); | 291 | getMailButton->setEnabled(FALSE); |
292 | cancelButton->setEnabled(TRUE); | 292 | cancelButton->setEnabled(TRUE); |
293 | selectAccountMenu->setEnabled(FALSE); | 293 | selectAccountMenu->setEnabled(FALSE); |
294 | 294 | ||
295 | status1Label->setText(currentAccount->accountName + " headers"); | 295 | status1Label->setText(currentAccount->accountName + " headers"); |
296 | progressBar->reset(); | 296 | progressBar->reset(); |
297 | 297 | ||
298 | //get any previous mails not downloaded and add to queue | 298 | //get any previous mails not downloaded and add to queue |
299 | mailDownloadList.clear(); | 299 | mailDownloadList.clear(); |
300 | Email *mailPtr; | 300 | Email *mailPtr; |
301 | item = (EmailListItem *) inboxView->firstChild(); | 301 | item = (EmailListItem *) inboxView->firstChild(); |
302 | while (item != NULL) { | 302 | while (item != NULL) { |
303 | mailPtr = item->getMail(); | 303 | mailPtr = item->getMail(); |
304 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 304 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
305 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 305 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
306 | } | 306 | } |
307 | item = (EmailListItem *) item->nextSibling(); | 307 | item = (EmailListItem *) item->nextSibling(); |
308 | } | 308 | } |
309 | 309 | ||
310 | emailHandler->getMailHeaders(); | 310 | emailHandler->getMailHeaders(); |
311 | } | 311 | } |
312 | 312 | ||
313 | void EmailClient::getAllNewMail() | 313 | void EmailClient::getAllNewMail() |
314 | { | 314 | { |
315 | allAccounts = TRUE; | 315 | allAccounts = TRUE; |
316 | currentAccount = accountList.first(); | 316 | currentAccount = accountList.first(); |
317 | getNewMail(); | 317 | getNewMail(); |
318 | } | 318 | } |
319 | 319 | ||
320 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 320 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
321 | { | 321 | { |
322 | Enclosure *ePtr; | 322 | Enclosure *ePtr; |
323 | Email newMail; | 323 | Email newMail; |
324 | int thisMailId; | 324 | int thisMailId; |
325 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 325 | emailHandler->parse(mail.rawMail, lineShift, &newMail); |
326 | 326 | ||
327 | mailconf->setGroup(newMail.id); | 327 | mailconf->setGroup(newMail.id); |
328 | 328 | ||
329 | if (fromDisk) { | 329 | if (fromDisk) { |
330 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 330 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
331 | newMail.size = mailconf->readNumEntry("size"); | 331 | newMail.size = mailconf->readNumEntry("size"); |
332 | newMail.serverId = mailconf->readNumEntry("serverid"); | 332 | newMail.serverId = mailconf->readNumEntry("serverid"); |
333 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 333 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
334 | } else { //mail arrived from server | 334 | } else { //mail arrived from server |
335 | newMail.serverId = mail.serverId; | 335 | newMail.serverId = mail.serverId; |
336 | newMail.size = mail.size; | 336 | newMail.size = mail.size; |
337 | newMail.downloaded = mail.downloaded; | 337 | newMail.downloaded = mail.downloaded; |
338 | 338 | ||
339 | newMail.fromAccountId = currentAccount->id; | 339 | newMail.fromAccountId = currentAccount->id; |
340 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 340 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
341 | } | 341 | } |
342 | 342 | ||
343 | //add if read or not | 343 | //add if read or not |
344 | newMail.read = mailconf->readBoolEntry("mailread"); | 344 | newMail.read = mailconf->readBoolEntry("mailread"); |
345 | 345 | ||
346 | //check if new mail | 346 | //check if new mail |
347 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 347 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
348 | thisMailId = mailIdCount; | 348 | thisMailId = mailIdCount; |
349 | mailIdCount++; | 349 | mailIdCount++; |
350 | 350 | ||
351 | //set server count, so that if the user aborts, the new | 351 | //set server count, so that if the user aborts, the new |
352 | //header is not reloaded | 352 | //header is not reloaded |
353 | if (currentAccount->synchronize) | 353 | if (currentAccount->synchronize) |
354 | currentAccount->lastServerMailCount++; | 354 | currentAccount->lastServerMailCount++; |
355 | 355 | ||
356 | mailconf->writeEntry("internalmailid", thisMailId); | 356 | mailconf->writeEntry("internalmailid", thisMailId); |
357 | mailconf->writeEntry("downloaded", newMail.downloaded); | 357 | mailconf->writeEntry("downloaded", newMail.downloaded); |
358 | mailconf->writeEntry("size", (int) newMail.size); | 358 | mailconf->writeEntry("size", (int) newMail.size); |
359 | mailconf->writeEntry("serverid", newMail.serverId); | 359 | mailconf->writeEntry("serverid", newMail.serverId); |
360 | 360 | ||
361 | addressList->addContact(newMail.fromMail, newMail.from); | 361 | addressList->addContact(newMail.fromMail, newMail.from); |
362 | } else if (!fromDisk) { //body to header arrived | 362 | } else if (!fromDisk) { //body to header arrived |
363 | mailconf->writeEntry("downloaded", TRUE); | 363 | mailconf->writeEntry("downloaded", TRUE); |
364 | } | 364 | } |
365 | QString stringMailId; | 365 | QString stringMailId; |
366 | stringMailId.setNum(thisMailId); | 366 | stringMailId.setNum(thisMailId); |
367 | //se if any attatchments needs to be stored | 367 | //se if any attatchments needs to be stored |
368 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { | 368 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { |
369 | QString stringId; | 369 | QString stringId; |
370 | stringId.setNum(ePtr->id); | 370 | stringId.setNum(ePtr->id); |
371 | 371 | ||
372 | int id = mailconf->readNumEntry("enclosureid_" + stringId); | 372 | int id = mailconf->readNumEntry("enclosureid_" + stringId); |
373 | if (id != ePtr->id) { //new entry | 373 | if (id != ePtr->id) { //new entry |
374 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); | 374 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); |
375 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); | 375 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); |
376 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); | 376 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); |
377 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); | 377 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); |
378 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 378 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
379 | mailconf->writeEntry("installed_" + stringId, FALSE); | 379 | mailconf->writeEntry("installed_" + stringId, FALSE); |
380 | 380 | ||
381 | ePtr->name = stringMailId + "_" + stringId; | 381 | ePtr->name = stringMailId + "_" + stringId; |
382 | ePtr->path = getPath(TRUE); | 382 | ePtr->path = getPath(TRUE); |
383 | if (emailHandler->getEnclosure(ePtr)) { //file saved | 383 | if (emailHandler->getEnclosure(ePtr)) { //file saved |
384 | ePtr->saved = TRUE; | 384 | ePtr->saved = TRUE; |
385 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 385 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
386 | mailconf->writeEntry("filename_" + stringId, ePtr->name); | 386 | mailconf->writeEntry("filename_" + stringId, ePtr->name); |
387 | mailconf->writeEntry("path_" + stringId, ePtr->path); | 387 | mailconf->writeEntry("path_" + stringId, ePtr->path); |
388 | } else { | 388 | } else { |
389 | ePtr->saved = FALSE; | 389 | ePtr->saved = FALSE; |
390 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 390 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
391 | } | 391 | } |
392 | } else { | 392 | } else { |
393 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); | 393 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); |
394 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); | 394 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); |
395 | if (ePtr->saved) { | 395 | if (ePtr->saved) { |
396 | ePtr->name = mailconf->readEntry("filename_" + stringId); | 396 | ePtr->name = mailconf->readEntry("filename_" + stringId); |
397 | ePtr->path = mailconf->readEntry("path_" + stringId); | 397 | ePtr->path = mailconf->readEntry("path_" + stringId); |
398 | } | 398 | } |
399 | } | 399 | } |
400 | } | 400 | } |
401 | if (!previewingMail && !fromDisk) { | 401 | if (!previewingMail && !fromDisk) { |
402 | Email *mailPtr; | 402 | Email *mailPtr; |
403 | item = (EmailListItem *) inboxView->firstChild(); | 403 | item = (EmailListItem *) inboxView->firstChild(); |
404 | while (item != NULL) { | 404 | while (item != NULL) { |
405 | mailPtr = item->getMail(); | 405 | mailPtr = item->getMail(); |
406 | if (mailPtr->id == newMail.id) { | 406 | if (mailPtr->id == newMail.id) { |
407 | item->setMail(newMail); | 407 | item->setMail(newMail); |
408 | emit mailUpdated(item->getMail()); | 408 | emit mailUpdated(item->getMail()); |
409 | } | 409 | } |
410 | item = (EmailListItem *) item->nextSibling(); | 410 | item = (EmailListItem *) item->nextSibling(); |
411 | } | 411 | } |
412 | } else { | 412 | } else { |
413 | item = new EmailListItem(inboxView, newMail, TRUE); | 413 | item = new EmailListItem(inboxView, newMail, TRUE); |
414 | if (!newMail.downloaded) | 414 | if (!newMail.downloaded) |
415 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size); | 415 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size); |
416 | } | 416 | } |
417 | 417 | ||
418 | } | 418 | } |
419 | 419 | ||
420 | void EmailClient::allMailArrived(int count) | 420 | void EmailClient::allMailArrived(int count) |
421 | { | 421 | { |
422 | // not previewing means all mailtransfer has been done | 422 | // not previewing means all mailtransfer has been done |
423 | if (!previewingMail) { | 423 | if (!previewingMail) { |
424 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 424 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
425 | emit newCaption("Mailit - " + currentAccount->accountName); | 425 | emit newCaption("Mailit - " + currentAccount->accountName); |
426 | getNewMail(); | 426 | getNewMail(); |
427 | return; | 427 | return; |
428 | } else { | 428 | } else { |
429 | allAccounts = FALSE; | 429 | allAccounts = FALSE; |
430 | receiving = FALSE; | 430 | receiving = FALSE; |
431 | getMailButton->setEnabled(TRUE); | 431 | getMailButton->setEnabled(TRUE); |
432 | cancelButton->setEnabled(FALSE); | 432 | cancelButton->setEnabled(FALSE); |
433 | selectAccountMenu->setEnabled(TRUE); | 433 | selectAccountMenu->setEnabled(TRUE); |
434 | status1Label->setText("Idle"); | 434 | status1Label->setText("Idle"); |
435 | 435 | ||
436 | progressBar->reset(); | 436 | progressBar->reset(); |
437 | return; | 437 | return; |
438 | } | 438 | } |
439 | } | 439 | } |
440 | 440 | ||
441 | // all headers downloaded from server, start downloading remaining mails | 441 | // all headers downloaded from server, start downloading remaining mails |
442 | previewingMail = FALSE; | 442 | previewingMail = FALSE; |
443 | status1Label->setText(currentAccount->accountName); | 443 | status1Label->setText(currentAccount->accountName); |
444 | progressBar->reset(); | 444 | progressBar->reset(); |
445 | 445 | ||
446 | emailHandler->getMailByList(&mailDownloadList); | 446 | emailHandler->getMailByList(&mailDownloadList); |
447 | } | 447 | } |
448 | 448 | ||
449 | void EmailClient::moveMailFront(Email *mailPtr) | 449 | void EmailClient::moveMailFront(Email *mailPtr) |
450 | { | 450 | { |
451 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 451 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
452 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 452 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
453 | } | 453 | } |
454 | } | 454 | } |
455 | 455 | ||
456 | void EmailClient::smtpError(int code) | 456 | void EmailClient::smtpError(int code) |
457 | { | 457 | { |
458 | QString temp; | 458 | QString temp; |
459 | 459 | ||
460 | if (code == ErrUnknownResponse) | 460 | if (code == ErrUnknownResponse) |
461 | temp = "Unknown response from server"; | 461 | temp = "Unknown response from server"; |
462 | 462 | ||
463 | if (code == QSocket::ErrHostNotFound) | 463 | if (code == QSocket::ErrHostNotFound) |
464 | temp = "host not found"; | 464 | temp = "host not found"; |
465 | if (code == QSocket::ErrConnectionRefused) | 465 | if (code == QSocket::ErrConnectionRefused) |
466 | temp = "connection refused"; | 466 | temp = "connection refused"; |
467 | if (code == QSocket::ErrSocketRead) | 467 | if (code == QSocket::ErrSocketRead) |
468 | temp = "socket packet error"; | 468 | temp = "socket packet error"; |
469 | 469 | ||
470 | if (code != ErrCancel) { | 470 | if (code != ErrCancel) { |
471 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); | 471 | QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); |
472 | } else { | 472 | } else { |
473 | status2Label->setText("Aborted by user"); | 473 | status2Label->setText("Aborted by user"); |
474 | } | 474 | } |
475 | 475 | ||
476 | sending = FALSE; | 476 | sending = FALSE; |
477 | sendMailButton->setEnabled(TRUE); | 477 | sendMailButton->setEnabled(TRUE); |
478 | cancelButton->setEnabled(FALSE); | 478 | cancelButton->setEnabled(FALSE); |
479 | quedMessages.clear(); | 479 | quedMessages.clear(); |
480 | } | 480 | } |
481 | 481 | ||
482 | void EmailClient::popError(int code) | 482 | void EmailClient::popError(int code) |
483 | { | 483 | { |
484 | QString temp; | 484 | QString temp; |
485 | 485 | ||
486 | if (code == ErrUnknownResponse) | 486 | if (code == ErrUnknownResponse) |
487 | temp = "Unknown response from server"; | 487 | temp = "Unknown response from server"; |
488 | if (code == ErrLoginFailed) | 488 | if (code == ErrLoginFailed) |
489 | temp = "Login failed\nCheck user name and password"; | 489 | temp = "Login failed\nCheck user name and password"; |
490 | 490 | ||
491 | if (code == QSocket::ErrHostNotFound) | 491 | if (code == QSocket::ErrHostNotFound) |
492 | temp = "host not found"; | 492 | temp = "host not found"; |
493 | if (code == QSocket::ErrConnectionRefused) | 493 | if (code == QSocket::ErrConnectionRefused) |
494 | temp = "connection refused"; | 494 | temp = "connection refused"; |
495 | if (code == QSocket::ErrSocketRead) | 495 | if (code == QSocket::ErrSocketRead) |
496 | temp = "socket packet error"; | 496 | temp = "socket packet error"; |
497 | 497 | ||
498 | if (code != ErrCancel) { | 498 | if (code != ErrCancel) { |
499 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); | 499 | QMessageBox::warning(qApp->activeWindow(), "Receiving error", temp, "OK\n"); |
500 | } else { | 500 | } else { |
501 | status2Label->setText("Aborted by user"); | 501 | status2Label->setText("Aborted by user"); |
502 | } | 502 | } |
503 | 503 | ||
504 | receiving = FALSE; | 504 | receiving = FALSE; |
505 | getMailButton->setEnabled(TRUE); | 505 | getMailButton->setEnabled(TRUE); |
506 | cancelButton->setEnabled(FALSE); | 506 | cancelButton->setEnabled(FALSE); |
507 | selectAccountMenu->setEnabled(TRUE); | 507 | selectAccountMenu->setEnabled(TRUE); |
508 | } | 508 | } |
509 | 509 | ||
510 | void EmailClient::inboxItemSelected() | 510 | void EmailClient::inboxItemSelected() |
511 | { | 511 | { |
512 | item = (EmailListItem*) inboxView->selectedItem(); | 512 | item = (EmailListItem*) inboxView->selectedItem(); |
513 | if (item != NULL) { | 513 | if (item != NULL) { |
514 | emit viewEmail(inboxView, item->getMail()); | 514 | emit viewEmail(inboxView, item->getMail()); |
515 | } | 515 | } |
516 | } | 516 | } |
517 | 517 | ||
518 | void EmailClient::outboxItemSelected() | 518 | void EmailClient::outboxItemSelected() |
519 | { | 519 | { |
520 | item = (EmailListItem*) outboxView->selectedItem(); | 520 | item = (EmailListItem*) outboxView->selectedItem(); |
521 | if (item != NULL) { | 521 | if (item != NULL) { |
522 | emit viewEmail(outboxView, item->getMail()); | 522 | emit viewEmail(outboxView, item->getMail()); |
523 | } | 523 | } |
524 | 524 | ||
525 | } | 525 | } |
526 | 526 | ||
527 | void EmailClient::readMail() | 527 | void EmailClient::readMail() |
528 | { | 528 | { |
529 | Email mail; | 529 | Email mail; |
530 | int start, stop; | 530 | int start, stop; |
531 | QString s, del; | 531 | QString s, del; |
532 | 532 | ||
533 | QFile f(getPath(FALSE) + "inbox.txt"); | 533 | QFile f(getPath(FALSE) + "inbox.txt"); |
534 | // QFileInfo fi(f); | 534 | // QFileInfo fi(f); |
535 | qDebug( f.name()); | 535 | //qDebug( f.name()); |
536 | 536 | ||
537 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 537 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
538 | QTextStream t( &f ); // use a text stream | 538 | QTextStream t( &f ); // use a text stream |
539 | s = t.read(); | 539 | s = t.read(); |
540 | f.close(); | 540 | f.close(); |
541 | 541 | ||
542 | start = 0; | 542 | start = 0; |
543 | del = "\n.\n"; | 543 | del = "\n.\n"; |
544 | while ((uint) start < s.length()) { | 544 | while ((uint) start < s.length()) { |
545 | stop = s.find(del, start); | 545 | stop = s.find(del, start); |
546 | if (stop == -1) | 546 | if (stop == -1) |
547 | stop = s.length() - del.length(); | 547 | stop = s.length() - del.length(); |
548 | 548 | ||
549 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 549 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
550 | start = stop + del.length(); | 550 | start = stop + del.length(); |
551 | mailArrived(mail, TRUE); | 551 | mailArrived(mail, TRUE); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
555 | QFile fo(getPath(FALSE) + "outbox.txt"); | 555 | QFile fo(getPath(FALSE) + "outbox.txt"); |
556 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | 556 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully |
557 | QTextStream t( &fo ); // use a text stream | 557 | QTextStream t( &fo ); // use a text stream |
558 | s = t.read(); | 558 | s = t.read(); |
559 | fo.close(); | 559 | fo.close(); |
560 | 560 | ||
561 | start = 0; | 561 | start = 0; |
562 | del = "\n.\n"; | 562 | del = "\n.\n"; |
563 | while ((uint) start < s.length()) { | 563 | while ((uint) start < s.length()) { |
564 | stop = s.find(del, start); | 564 | stop = s.find(del, start); |
565 | if (stop == -1) | 565 | if (stop == -1) |
566 | stop = s.length() - del.length(); | 566 | stop = s.length() - del.length(); |
567 | 567 | ||
568 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 568 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
569 | start = stop + del.length(); | 569 | start = stop + del.length(); |
570 | emailHandler->parse(mail.rawMail, lineShift, &mail); | 570 | emailHandler->parse(mail.rawMail, lineShift, &mail); |
571 | mail.sent = false; | 571 | mail.sent = false; |
572 | mail.received = false; | 572 | mail.received = false; |
573 | enqueMail(mail); | 573 | enqueMail(mail); |
574 | 574 | ||
575 | } | 575 | } |
576 | } | 576 | } |
577 | } | 577 | } |
578 | 578 | ||
579 | void EmailClient::saveMail(QString fileName, QListView *view) | 579 | void EmailClient::saveMail(QString fileName, QListView *view) |
580 | { | 580 | { |
581 | QFile f(fileName); | 581 | QFile f(fileName); |
582 | Email *mail; | 582 | Email *mail; |
583 | 583 | ||
584 | if (! f.open(IO_WriteOnly) ) { | 584 | if (! f.open(IO_WriteOnly) ) { |
585 | qWarning("could not open file"); | 585 | qWarning("could not open file"); |
586 | return; | 586 | return; |
587 | } | 587 | } |
588 | item = (EmailListItem *) view->firstChild(); | 588 | item = (EmailListItem *) view->firstChild(); |
589 | qDebug (QString("Write : ") ); | 589 | //qDebug (QString("Write : ") ); |
590 | QTextStream t(&f); | 590 | QTextStream t(&f); |
591 | while (item != NULL) { | 591 | while (item != NULL) { |
592 | mail = item->getMail(); | 592 | mail = item->getMail(); |
593 | qDebug(mail->rawMail); | 593 | //qDebug(mail->rawMail); |
594 | qDebug(mail->recipients.first()); | 594 | //qDebug(mail->recipients.first()); |
595 | t << mail->rawMail; | 595 | t << mail->rawMail; |
596 | 596 | ||
597 | mailconf->setGroup(mail->id); | 597 | mailconf->setGroup(mail->id); |
598 | mailconf->writeEntry("mailread", mail->read); | 598 | mailconf->writeEntry("mailread", mail->read); |
599 | 599 | ||
600 | item = (EmailListItem *) item->nextSibling(); | 600 | item = (EmailListItem *) item->nextSibling(); |
601 | } | 601 | } |
602 | f.close(); | 602 | f.close(); |
603 | } | 603 | } |
604 | 604 | ||
605 | //paths for mailit, is settings, inbox, enclosures | 605 | //paths for mailit, is settings, inbox, enclosures |
606 | QString EmailClient::getPath(bool enclosurePath) | 606 | QString EmailClient::getPath(bool enclosurePath) |
607 | { | 607 | { |
608 | QString basePath = "qtmail"; | 608 | QString basePath = "qtmail"; |
609 | QString enclosures = "enclosures"; | 609 | QString enclosures = "enclosures"; |
610 | 610 | ||
611 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | 611 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); |
612 | if ( !dir.exists() ) | 612 | if ( !dir.exists() ) |
613 | dir.mkdir( dir.path() ); | 613 | dir.mkdir( dir.path() ); |
614 | 614 | ||
615 | if (enclosurePath) { | 615 | if (enclosurePath) { |
616 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | 616 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); |
617 | 617 | ||
618 | if ( !dir.exists() ) | 618 | if ( !dir.exists() ) |
619 | dir.mkdir( dir.path() ); | 619 | dir.mkdir( dir.path() ); |
620 | 620 | ||
621 | return (dir.path() + "/"); | 621 | return (dir.path() + "/"); |
622 | 622 | ||
623 | } | 623 | } |
624 | return (dir.path() + "/"); | 624 | return (dir.path() + "/"); |
625 | } | 625 | } |
626 | 626 | ||
627 | void EmailClient::readSettings() | 627 | void EmailClient::readSettings() |
628 | { | 628 | { |
629 | TextParser *p; | 629 | TextParser *p; |
630 | QString s; | 630 | QString s; |
631 | int pos, accountPos, y; | 631 | int pos, accountPos, y; |
632 | QFile f( getPath(FALSE) + "settings.txt"); | 632 | QFile f( getPath(FALSE) + "settings.txt"); |
633 | 633 | ||
634 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 634 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
635 | QTextStream t( &f ); // use a text stream | 635 | QTextStream t( &f ); // use a text stream |
636 | s = t.read(); | 636 | s = t.read(); |
637 | f.close(); | 637 | f.close(); |
638 | 638 | ||
639 | p = new TextParser(s, "\n"); | 639 | p = new TextParser(s, "\n"); |
640 | 640 | ||
641 | accountPos = 0; | 641 | accountPos = 0; |
642 | while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) { | 642 | while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) { |
643 | accountPos++; | 643 | accountPos++; |
644 | if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 ) | 644 | if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 ) |
645 | account.accountName = p->getString(& ++pos, 'z', TRUE); | 645 | account.accountName = p->getString(& ++pos, 'z', TRUE); |
646 | if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1) | 646 | if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1) |
647 | account.name = p->getString(& ++pos, 'z', TRUE); | 647 | account.name = p->getString(& ++pos, 'z', TRUE); |
648 | if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1) | 648 | if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1) |
649 | account.emailAddress = p->getString(& ++pos, 'z', TRUE); | 649 | account.emailAddress = p->getString(& ++pos, 'z', TRUE); |
650 | if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1) | 650 | if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1) |
651 | account.popUserName = p->getString(& ++pos, 'z', TRUE); | 651 | account.popUserName = p->getString(& ++pos, 'z', TRUE); |
652 | if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1) | 652 | if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1) |
653 | account.popPasswd = p->getString(& ++pos, 'z', TRUE); | 653 | account.popPasswd = p->getString(& ++pos, 'z', TRUE); |
654 | if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1) | 654 | if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1) |
655 | account.popServer = p->getString(& ++pos, 'z', TRUE); | 655 | account.popServer = p->getString(& ++pos, 'z', TRUE); |
656 | if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1) | 656 | if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1) |
657 | account.smtpServer = p->getString(& ++pos, 'z', TRUE); | 657 | account.smtpServer = p->getString(& ++pos, 'z', TRUE); |
658 | if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) { | 658 | if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) { |
659 | s = p->getString(& ++pos, 'z', TRUE); | 659 | s = p->getString(& ++pos, 'z', TRUE); |
660 | account.id = s.toInt(); | 660 | account.id = s.toInt(); |
661 | } | 661 | } |
662 | 662 | ||
663 | account.lastServerMailCount = 0; | 663 | account.lastServerMailCount = 0; |
664 | account.synchronize = FALSE; | 664 | account.synchronize = FALSE; |
665 | if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) { | 665 | if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) { |
666 | if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") { | 666 | if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") { |
667 | account.synchronize = TRUE; | 667 | account.synchronize = TRUE; |
668 | if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) { | 668 | if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) { |
669 | s = p->getString(& ++pos, 'z', TRUE); | 669 | s = p->getString(& ++pos, 'z', TRUE); |
670 | account.lastServerMailCount = s.toInt(); | 670 | account.lastServerMailCount = s.toInt(); |
671 | } | 671 | } |
672 | } | 672 | } |
673 | } | 673 | } |
674 | 674 | ||
675 | if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) { | 675 | if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) { |
676 | account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt(); | 676 | account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt(); |
677 | } | 677 | } |
678 | 678 | ||
679 | 679 | ||
680 | accountList.append(&account); | 680 | accountList.append(&account); |
681 | } | 681 | } |
682 | delete p; | 682 | delete p; |
683 | } | 683 | } |
684 | mailconf->setGroup("mailitglobal"); | 684 | mailconf->setGroup("mailitglobal"); |
685 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { | 685 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { |
686 | mailIdCount = y; | 686 | mailIdCount = y; |
687 | } | 687 | } |
688 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { | 688 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { |
689 | accountIdCount = y; | 689 | accountIdCount = y; |
690 | } | 690 | } |
691 | } | 691 | } |
692 | 692 | ||
693 | void EmailClient::saveSettings() | 693 | void EmailClient::saveSettings() |
694 | { | 694 | { |
695 | QString temp; | 695 | QString temp; |
696 | QFile f( getPath(FALSE) + "settings.txt"); | 696 | QFile f( getPath(FALSE) + "settings.txt"); |
697 | MailAccount *accountPtr; | 697 | MailAccount *accountPtr; |
698 | 698 | ||
699 | if (! f.open(IO_WriteOnly) ) { | 699 | if (! f.open(IO_WriteOnly) ) { |
700 | qWarning("could not save settings file"); | 700 | qWarning("could not save settings file"); |
701 | return; | 701 | return; |
702 | } | 702 | } |
703 | QTextStream t(&f); | 703 | QTextStream t(&f); |
704 | t << "#Settings for QPE Mailit program\n"; | 704 | t << "#Settings for QPE Mailit program\n"; |
705 | 705 | ||
706 | for (accountPtr = accountList.first(); accountPtr != 0; | 706 | for (accountPtr = accountList.first(); accountPtr != 0; |
707 | accountPtr = accountList.next()) { | 707 | accountPtr = accountList.next()) { |
708 | 708 | ||
709 | t << "accountStart;\n"; | 709 | t << "accountStart;\n"; |
710 | t << "AccountName: " + accountPtr->accountName + "\n"; | 710 | t << "AccountName: " + accountPtr->accountName + "\n"; |
711 | t << "Name: " + accountPtr->name + "\n"; | 711 | t << "Name: " + accountPtr->name + "\n"; |
712 | t << "Email: " + accountPtr->emailAddress + "\n"; | 712 | t << "Email: " + accountPtr->emailAddress + "\n"; |
713 | t << "POPUser: " + accountPtr->popUserName + "\n"; | 713 | t << "POPUser: " + accountPtr->popUserName + "\n"; |
714 | t << "POPPAssword: " + accountPtr->popPasswd + "\n"; | 714 | t << "POPPAssword: " + accountPtr->popPasswd + "\n"; |
715 | t << "POPServer: " + accountPtr->popServer + "\n"; | 715 | t << "POPServer: " + accountPtr->popServer + "\n"; |
716 | t << "SMTPServer: " + accountPtr->smtpServer + "\n"; | 716 | t << "SMTPServer: " + accountPtr->smtpServer + "\n"; |
717 | t << "AccountId: " << accountPtr->id << "\n"; | 717 | t << "AccountId: " << accountPtr->id << "\n"; |
718 | if (accountPtr->synchronize) { | 718 | if (accountPtr->synchronize) { |
719 | t << "Synchronize: Yes\n"; | 719 | t << "Synchronize: Yes\n"; |
720 | t << "LastServerMailCount: "; | 720 | t << "LastServerMailCount: "; |
721 | t << accountPtr->lastServerMailCount << "\n"; | 721 | t << accountPtr->lastServerMailCount << "\n"; |
722 | } else { | 722 | } else { |
723 | t << "Synchronize: No\n"; | 723 | t << "Synchronize: No\n"; |
724 | } | 724 | } |
725 | t << "SyncLimit: "; | 725 | t << "SyncLimit: "; |
726 | t << accountPtr->syncLimit << "\n"; | 726 | t << accountPtr->syncLimit << "\n"; |
727 | t << "accountEnd;\n"; | 727 | t << "accountEnd;\n"; |
728 | } | 728 | } |
729 | f.close(); | 729 | f.close(); |
730 | 730 | ||
731 | mailconf->setGroup("mailitglobal"); | 731 | mailconf->setGroup("mailitglobal"); |
732 | mailconf->writeEntry("mailidcount", mailIdCount); | 732 | mailconf->writeEntry("mailidcount", mailIdCount); |
733 | mailconf->writeEntry("accountidcount", accountIdCount); | 733 | mailconf->writeEntry("accountidcount", accountIdCount); |
734 | } | 734 | } |
735 | 735 | ||
736 | void EmailClient::selectAccount(int id) | 736 | void EmailClient::selectAccount(int id) |
737 | { | 737 | { |
738 | if (accountList.count() > 0) { | 738 | if (accountList.count() > 0) { |
739 | currentAccount = accountList.at(id); | 739 | currentAccount = accountList.at(id); |
740 | emit newCaption("Mailit - " + currentAccount->accountName); | 740 | emit newCaption("Mailit - " + currentAccount->accountName); |
741 | getNewMail(); | 741 | getNewMail(); |
742 | } else { | 742 | } else { |
743 | emit newCaption("Mailit ! No account defined"); | 743 | emit newCaption("Mailit ! No account defined"); |
744 | } | 744 | } |
745 | } | 745 | } |
746 | 746 | ||
747 | void EmailClient::editAccount(int id) | 747 | void EmailClient::editAccount(int id) |
748 | { | 748 | { |
749 | MailAccount *newAccount; | 749 | MailAccount *newAccount; |
750 | 750 | ||
751 | editAccountView = new EditAccount(this, "account", TRUE); | 751 | editAccountView = new EditAccount(this, "account", TRUE); |
752 | if (id == newAccountId) { //new account | 752 | if (id == newAccountId) { //new account |
753 | newAccount = new MailAccount; | 753 | newAccount = new MailAccount; |
754 | editAccountView->setAccount(newAccount); | 754 | editAccountView->setAccount(newAccount); |
755 | } else { | 755 | } else { |
756 | newAccount = accountList.at(id); | 756 | newAccount = accountList.at(id); |
757 | editAccountView->setAccount(newAccount, FALSE); | 757 | editAccountView->setAccount(newAccount, FALSE); |
758 | } | 758 | } |
759 | 759 | ||
760 | editAccountView->showMaximized(); | 760 | editAccountView->showMaximized(); |
761 | editAccountView->exec(); | 761 | editAccountView->exec(); |
762 | 762 | ||
763 | if (editAccountView->result() == QDialog::Accepted) { | 763 | if (editAccountView->result() == QDialog::Accepted) { |
764 | if (id == newAccountId) { | 764 | if (id == newAccountId) { |
765 | newAccount->id = accountIdCount; | 765 | newAccount->id = accountIdCount; |
766 | accountIdCount++; | 766 | accountIdCount++; |
767 | accountList.append(newAccount); | 767 | accountList.append(newAccount); |
768 | updateAccounts(); | 768 | updateAccounts(); |
769 | } else { | 769 | } else { |
770 | updateAccounts(); | 770 | updateAccounts(); |
771 | } | 771 | } |
772 | } | 772 | } |
773 | 773 | ||
774 | delete editAccountView; | 774 | delete editAccountView; |
775 | } | 775 | } |
776 | 776 | ||
777 | void EmailClient::deleteAccount(int id) | 777 | void EmailClient::deleteAccount(int id) |
778 | { | 778 | { |
779 | MailAccount *newAccount; | 779 | MailAccount *newAccount; |
780 | QString message; | 780 | QString message; |
781 | 781 | ||
782 | newAccount = accountList.at(id); | 782 | newAccount = accountList.at(id); |
783 | message = "Delete account:\n" + newAccount->accountName; | 783 | message = "Delete account:\n" + newAccount->accountName; |
784 | switch( QMessageBox::warning( this, "Mailit", message, | 784 | switch( QMessageBox::warning( this, "Mailit", message, |
785 | "Yes", "No", 0, 0, 1 ) ) { | 785 | "Yes", "No", 0, 0, 1 ) ) { |
786 | 786 | ||
787 | case 0: accountList.remove(id); | 787 | case 0: accountList.remove(id); |
788 | updateAccounts(); | 788 | updateAccounts(); |
789 | break; | 789 | break; |
790 | case 1: | 790 | case 1: |
791 | break; | 791 | break; |
792 | } | 792 | } |
793 | } | 793 | } |
794 | 794 | ||
795 | void EmailClient::updateAccounts() | 795 | void EmailClient::updateAccounts() |
796 | { | 796 | { |
797 | MailAccount *accountPtr; | 797 | MailAccount *accountPtr; |
798 | 798 | ||
799 | //rebuild menus, clear all first | 799 | //rebuild menus, clear all first |
800 | editAccountMenu->clear(); | 800 | editAccountMenu->clear(); |
801 | selectAccountMenu->clear(); | 801 | selectAccountMenu->clear(); |
802 | deleteAccountMenu->clear(); | 802 | deleteAccountMenu->clear(); |
803 | 803 | ||
804 | newAccountId = editAccountMenu->insertItem("New", this, | 804 | newAccountId = editAccountMenu->insertItem("New", this, |
805 | SLOT(editAccount(int)) ); | 805 | SLOT(editAccount(int)) ); |
806 | editAccountMenu->insertSeparator(); | 806 | editAccountMenu->insertSeparator(); |
807 | 807 | ||
808 | idCount = 0; | 808 | idCount = 0; |
809 | for (accountPtr = accountList.first(); accountPtr != 0; | 809 | for (accountPtr = accountList.first(); accountPtr != 0; |
810 | accountPtr = accountList.next()) { | 810 | accountPtr = accountList.next()) { |
811 | 811 | ||
812 | editAccountMenu->insertItem(accountPtr->accountName, | 812 | editAccountMenu->insertItem(accountPtr->accountName, |
813 | this, SLOT(editAccount(int)), 0, idCount); | 813 | this, SLOT(editAccount(int)), 0, idCount); |
814 | selectAccountMenu->insertItem(accountPtr->accountName, | 814 | selectAccountMenu->insertItem(accountPtr->accountName, |
815 | this, SLOT(selectAccount(int)), 0, idCount); | 815 | this, SLOT(selectAccount(int)), 0, idCount); |
816 | deleteAccountMenu->insertItem(accountPtr->accountName, | 816 | deleteAccountMenu->insertItem(accountPtr->accountName, |
817 | this, SLOT(deleteAccount(int)), 0, idCount); | 817 | this, SLOT(deleteAccount(int)), 0, idCount); |
818 | idCount++; | 818 | idCount++; |
819 | } | 819 | } |
820 | } | 820 | } |
821 | 821 | ||
822 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | 822 | void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) |
823 | { | 823 | { |
824 | Email *mPtr; | 824 | Email *mPtr; |
825 | Enclosure *ePtr; | 825 | Enclosure *ePtr; |
826 | 826 | ||
827 | if (inbox) { | 827 | if (inbox) { |
828 | mPtr = mailItem->getMail(); | 828 | mPtr = mailItem->getMail(); |
829 | 829 | ||
830 | //if mail is in queue for download, remove it from | 830 | //if mail is in queue for download, remove it from |
831 | //queue if possible | 831 | //queue if possible |
832 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | 832 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { |
833 | if ( !mPtr->downloaded ) | 833 | if ( !mPtr->downloaded ) |
834 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | 834 | mailDownloadList.remove(mPtr->serverId, mPtr->size); |
835 | } | 835 | } |
836 | 836 | ||
837 | mailconf->setGroup(mPtr->id); | 837 | mailconf->setGroup(mPtr->id); |
838 | mailconf->clearGroup(); | 838 | mailconf->clearGroup(); |
839 | 839 | ||
840 | //delete any temporary attatchemnts storing | 840 | //delete any temporary attatchemnts storing |
841 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | 841 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { |
842 | if (ePtr->saved) { | 842 | if (ePtr->saved) { |
843 | QFile::remove( (ePtr->path + ePtr->name) ); | 843 | QFile::remove( (ePtr->path + ePtr->name) ); |
844 | } | 844 | } |
845 | } | 845 | } |
846 | inboxView->takeItem(mailItem); | 846 | inboxView->takeItem(mailItem); |
847 | } else { | 847 | } else { |
848 | outboxView->takeItem(mailItem); | 848 | outboxView->takeItem(mailItem); |
849 | } | 849 | } |
850 | } | 850 | } |
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp index 9c1c814..03f8a28 100644 --- a/noncore/unsupported/mailit/emailhandler.cpp +++ b/noncore/unsupported/mailit/emailhandler.cpp | |||
@@ -1,423 +1,421 @@ | |||
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 | ||
29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) | 29 | QCollection::Item EnclosureList::newItem(QCollection::Item d) |
30 | { | 30 | { |
31 | return dupl( (Enclosure *) d); | 31 | return dupl( (Enclosure *) d); |
32 | } | 32 | } |
33 | 33 | ||
34 | Enclosure* EnclosureList::dupl(Enclosure *in) | 34 | Enclosure* 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 | ||
40 | EmailHandler::EmailHandler() | 40 | EmailHandler::EmailHandler() |
41 | { | 41 | { |
42 | smtpClient = new SmtpClient(); | 42 | smtpClient = new SmtpClient(); |
43 | popClient = new PopClient(); | 43 | popClient = new PopClient(); |
44 | 44 | ||
45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, | 45 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, |
46 | SIGNAL(smtpError(int)) ); | 46 | SIGNAL(smtpError(int)) ); |
47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); | 47 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); |
48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, | 48 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, |
49 | SIGNAL(updateSmtpStatus(const QString &)) ); | 49 | SIGNAL(updateSmtpStatus(const QString &)) ); |
50 | 50 | ||
51 | connect(popClient, SIGNAL(errorOccurred(int)), this, | 51 | connect(popClient, SIGNAL(errorOccurred(int)), this, |
52 | SIGNAL(popError(int)) ); | 52 | SIGNAL(popError(int)) ); |
53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), | 53 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), |
54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); | 54 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); |
55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, | 55 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, |
56 | SIGNAL(updatePopStatus(const QString &)) ); | 56 | SIGNAL(updatePopStatus(const QString &)) ); |
57 | connect(popClient, SIGNAL(mailTransfered(int)), this, | 57 | connect(popClient, SIGNAL(mailTransfered(int)), this, |
58 | SIGNAL(mailTransfered(int)) ); | 58 | SIGNAL(mailTransfered(int)) ); |
59 | 59 | ||
60 | 60 | ||
61 | //relaying size information | 61 | //relaying size information |
62 | connect(popClient, SIGNAL(currentMailSize(int)), | 62 | connect(popClient, SIGNAL(currentMailSize(int)), |
63 | this, SIGNAL(currentMailSize(int)) ); | 63 | this, SIGNAL(currentMailSize(int)) ); |
64 | connect(popClient, SIGNAL(downloadedSize(int)), | 64 | connect(popClient, SIGNAL(downloadedSize(int)), |
65 | this, SIGNAL(downloadedSize(int)) ); | 65 | this, SIGNAL(downloadedSize(int)) ); |
66 | } | 66 | } |
67 | 67 | ||
68 | void EmailHandler::sendMail(QList<Email> *mailList) | 68 | void EmailHandler::sendMail(QList<Email> *mailList) |
69 | { | 69 | { |
70 | Email *currentMail; | 70 | Email *currentMail; |
71 | QString temp; | 71 | QString temp; |
72 | QString userName = mailAccount.name; | 72 | QString userName = mailAccount.name; |
73 | userName += " <" + mailAccount.emailAddress + ">"; | 73 | userName += " <" + mailAccount.emailAddress + ">"; |
74 | 74 | ||
75 | for (currentMail = mailList->first(); currentMail != 0; | 75 | for (currentMail = mailList->first(); currentMail != 0; |
76 | currentMail = mailList->next()) { | 76 | currentMail = mailList->next()) { |
77 | 77 | ||
78 | if (encodeMime(currentMail) == 0) { | 78 | if (encodeMime(currentMail) == 0) { |
79 | smtpClient->addMail(userName, currentMail->subject, | 79 | smtpClient->addMail(userName, currentMail->subject, |
80 | currentMail->recipients, currentMail->rawMail); | 80 | currentMail->recipients, currentMail->rawMail); |
81 | } else { //error | 81 | } else { //error |
82 | temp = tr("Could not locate all files in \nmail with subject: ") + | 82 | temp = tr("Could not locate all files in \nmail with subject: ") + |
83 | currentMail->subject; | 83 | currentMail->subject; |
84 | temp += tr("\nMail has NOT been sent"); | 84 | temp += tr("\nMail has NOT been sent"); |
85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); | 85 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); |
86 | 86 | ||
87 | } | 87 | } |
88 | } | 88 | } |
89 | smtpClient->newConnection(mailAccount.smtpServer, 25); | 89 | smtpClient->newConnection(mailAccount.smtpServer, 25); |
90 | } | 90 | } |
91 | 91 | ||
92 | void EmailHandler::setAccount(MailAccount account) | 92 | void EmailHandler::setAccount(MailAccount account) |
93 | { | 93 | { |
94 | mailAccount = account; | 94 | mailAccount = account; |
95 | } | 95 | } |
96 | 96 | ||
97 | void EmailHandler::getMail() | 97 | void EmailHandler::getMail() |
98 | { | 98 | { |
99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 99 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
100 | if (mailAccount.synchronize) { | 100 | if (mailAccount.synchronize) { |
101 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 101 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
102 | } else { | 102 | } else { |
103 | popClient->removeSynchronize(); | 103 | popClient->removeSynchronize(); |
104 | } | 104 | } |
105 | 105 | ||
106 | headers = FALSE; | 106 | headers = FALSE; |
107 | popClient->headersOnly(headers, 0); | 107 | popClient->headersOnly(headers, 0); |
108 | popClient->newConnection(mailAccount.popServer, 110); | 108 | popClient->newConnection(mailAccount.popServer, 110); |
109 | } | 109 | } |
110 | 110 | ||
111 | void EmailHandler::getMailHeaders() | 111 | void EmailHandler::getMailHeaders() |
112 | { | 112 | { |
113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 113 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
114 | if (mailAccount.synchronize) { | 114 | if (mailAccount.synchronize) { |
115 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 115 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
116 | } else { | 116 | } else { |
117 | popClient->removeSynchronize(); | 117 | popClient->removeSynchronize(); |
118 | } | 118 | } |
119 | 119 | ||
120 | headers = TRUE; | 120 | headers = TRUE; |
121 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 121 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
122 | popClient->newConnection(mailAccount.popServer, 110); | 122 | popClient->newConnection(mailAccount.popServer, 110); |
123 | } | 123 | } |
124 | 124 | ||
125 | void EmailHandler::getMailByList(MailList *mailList) | 125 | void EmailHandler::getMailByList(MailList *mailList) |
126 | { | 126 | { |
127 | if (mailList->count() == 0) { //should not occur though | 127 | if (mailList->count() == 0) { //should not occur though |
128 | emit mailTransfered(0); | 128 | emit mailTransfered(0); |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | 131 | ||
132 | headers = FALSE; | 132 | headers = FALSE; |
133 | popClient->headersOnly(FALSE, 0); | 133 | popClient->headersOnly(FALSE, 0); |
134 | popClient->newConnection(mailAccount.popServer, 110); | 134 | popClient->newConnection(mailAccount.popServer, 110); |
135 | popClient->setSelectedMails(mailList); | 135 | popClient->setSelectedMails(mailList); |
136 | } | 136 | } |
137 | 137 | ||
138 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) | 138 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) |
139 | { | 139 | { |
140 | Email mail; | 140 | Email mail; |
141 | 141 | ||
142 | mail.rawMail = message; | 142 | mail.rawMail = message; |
143 | mail.serverId = id; | 143 | mail.serverId = id; |
144 | mail.size = size; | 144 | mail.size = size; |
145 | mail.downloaded = complete; | 145 | mail.downloaded = complete; |
146 | 146 | ||
147 | emit mailArrived(mail, FALSE); | 147 | emit mailArrived(mail, FALSE); |
148 | } | 148 | } |
149 | 149 | ||
150 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 150 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) |
151 | { | 151 | { |
152 | QString temp, boundary; | 152 | QString temp, boundary; |
153 | int pos; | 153 | int pos; |
154 | QString delimiter, header, body, mimeHeader, mimeBody; | 154 | QString delimiter, header, body, mimeHeader, mimeBody; |
155 | QString content, contentType, contentAttribute, id, encoding; | 155 | QString content, contentType, contentAttribute, id, encoding; |
156 | QString fileName, storedName; | 156 | QString fileName, storedName; |
157 | int enclosureId = 0; | 157 | int enclosureId = 0; |
158 | 158 | ||
159 | mail->rawMail = in; | 159 | mail->rawMail = in; |
160 | mail->received = TRUE; | 160 | mail->received = TRUE; |
161 | mail->files.setAutoDelete(TRUE); | 161 | mail->files.setAutoDelete(TRUE); |
162 | 162 | ||
163 | temp = lineShift + "." + lineShift; | 163 | temp = lineShift + "." + lineShift; |
164 | 164 | ||
165 | if (in.right(temp.length()) != temp) { | 165 | if (in.right(temp.length()) != temp) { |
166 | qWarning(in.right(temp.length())); | ||
167 | qWarning(" . added at end of email as separator"); | ||
168 | mail->rawMail += temp; | 166 | mail->rawMail += temp; |
169 | } | 167 | } |
170 | 168 | ||
171 | 169 | ||
172 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 170 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
173 | pos = in.find(delimiter, 0, FALSE); | 171 | pos = in.find(delimiter, 0, FALSE); |
174 | header = in.left(pos); | 172 | header = in.left(pos); |
175 | body = in.right(in.length() - pos - delimiter.length()); | 173 | body = in.right(in.length() - pos - delimiter.length()); |
176 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 174 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
177 | body.truncate(body.length()-2); | 175 | body.truncate(body.length()-2); |
178 | 176 | ||
179 | TextParser p(header, lineShift); | 177 | TextParser p(header, lineShift); |
180 | 178 | ||
181 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 179 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
182 | pos++; | 180 | pos++; |
183 | if (p.separatorAt(pos) == ' ') { | 181 | if (p.separatorAt(pos) == ' ') { |
184 | mail->from = p.getString(&pos, '<', false); | 182 | mail->from = p.getString(&pos, '<', false); |
185 | mail->from = mail->from.stripWhiteSpace(); | 183 | mail->from = mail->from.stripWhiteSpace(); |
186 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 184 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
187 | mail->from = mail->from.left(mail->from.length() - 1); | 185 | mail->from = mail->from.left(mail->from.length() - 1); |
188 | mail->from = mail->from.right(mail->from.length() - 1); | 186 | mail->from = mail->from.right(mail->from.length() - 1); |
189 | } | 187 | } |
190 | pos++; | 188 | pos++; |
191 | mail->fromMail = p.getString(&pos, '>', false); | 189 | mail->fromMail = p.getString(&pos, '>', false); |
192 | } else { | 190 | } else { |
193 | if ((p.separatorAt(pos) == '<') | 191 | if ((p.separatorAt(pos) == '<') |
194 | || (p.separatorAt(pos) == ' ')) //No name.. nasty | 192 | || (p.separatorAt(pos) == ' ')) //No name.. nasty |
195 | pos++; | 193 | pos++; |
196 | pos++; | 194 | pos++; |
197 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 195 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
198 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
199 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 197 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
200 | mail->from=mail->fromMail; | 198 | mail->from=mail->fromMail; |
201 | } | 199 | } |
202 | } | 200 | } |
203 | 201 | ||
204 | //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To: | 202 | //@@@ToDo: Rewrite the parser as To: stops at the first occurence- which is Delivered-To: |
205 | if (pos = p.find("TO",':', pos, TRUE) != -1) | 203 | if (pos = p.find("TO",':', pos, TRUE) != -1) |
206 | { | 204 | { |
207 | pos++; | 205 | pos++; |
208 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); | 206 | mail->recipients.append (p.getString(&pos, 'z', TRUE) ); |
209 | } | 207 | } |
210 | 208 | ||
211 | 209 | ||
212 | 210 | ||
213 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 211 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
214 | pos++; | 212 | pos++; |
215 | mail->subject = p.getString(&pos, 'z', TRUE); | 213 | mail->subject = p.getString(&pos, 'z', TRUE); |
216 | } | 214 | } |
217 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 215 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
218 | pos++; | 216 | pos++; |
219 | mail->date = p.getString(&pos, 'z', true); | 217 | mail->date = p.getString(&pos, 'z', true); |
220 | } | 218 | } |
221 | 219 | ||
222 | 220 | ||
223 | 221 | ||
224 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 222 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
225 | pos++; | 223 | pos++; |
226 | if ( (p.wordAt(pos).upper() == "ID") && | 224 | if ( (p.wordAt(pos).upper() == "ID") && |
227 | (p.separatorAt(pos) == ':') ) { | 225 | (p.separatorAt(pos) == ':') ) { |
228 | 226 | ||
229 | id = p.getString(&pos, 'z', TRUE); | 227 | id = p.getString(&pos, 'z', TRUE); |
230 | mail->id = id; | 228 | mail->id = id; |
231 | } | 229 | } |
232 | } | 230 | } |
233 | 231 | ||
234 | pos = 0; | 232 | pos = 0; |
235 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 233 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
236 | pos++; | 234 | pos++; |
237 | if ( (p.wordAt(pos).upper() == "VERSION") && | 235 | if ( (p.wordAt(pos).upper() == "VERSION") && |
238 | (p.separatorAt(pos) == ':') ) { | 236 | (p.separatorAt(pos) == ':') ) { |
239 | pos++; | 237 | pos++; |
240 | if (p.getString(&pos, 'z', true) == "1.0") { | 238 | if (p.getString(&pos, 'z', true) == "1.0") { |
241 | mail->mimeType = 1; | 239 | mail->mimeType = 1; |
242 | } | 240 | } |
243 | } | 241 | } |
244 | } | 242 | } |
245 | 243 | ||
246 | if (mail->mimeType == 1) { | 244 | if (mail->mimeType == 1) { |
247 | boundary = ""; | 245 | boundary = ""; |
248 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 246 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
249 | pos++; | 247 | pos++; |
250 | boundary = p.getString(&pos, 'z', true); | 248 | boundary = p.getString(&pos, 'z', true); |
251 | if (boundary[0] == '"') { | 249 | if (boundary[0] == '"') { |
252 | boundary = boundary.left(boundary.length() - 1); //strip " | 250 | boundary = boundary.left(boundary.length() - 1); //strip " |
253 | boundary = boundary.right(boundary.length() - 1); //strip " | 251 | boundary = boundary.right(boundary.length() - 1); //strip " |
254 | } | 252 | } |
255 | boundary = "--" + boundary; //create boundary field | 253 | boundary = "--" + boundary; //create boundary field |
256 | } | 254 | } |
257 | 255 | ||
258 | if (boundary == "") { //fooled by Mime-Version | 256 | if (boundary == "") { //fooled by Mime-Version |
259 | mail->body = body; | 257 | mail->body = body; |
260 | mail->bodyPlain = body; | 258 | mail->bodyPlain = body; |
261 | return mail; | 259 | return mail; |
262 | } | 260 | } |
263 | 261 | ||
264 | while (body.length() > 0) { | 262 | while (body.length() > 0) { |
265 | pos = body.find(boundary, 0, FALSE); | 263 | pos = body.find(boundary, 0, FALSE); |
266 | pos = body.find(delimiter, pos, FALSE); | 264 | pos = body.find(delimiter, pos, FALSE); |
267 | mimeHeader = body.left(pos); | 265 | mimeHeader = body.left(pos); |
268 | mimeBody = body.right(body.length() - pos - delimiter.length()); | 266 | mimeBody = body.right(body.length() - pos - delimiter.length()); |
269 | TextParser bp(mimeHeader, lineShift); | 267 | TextParser bp(mimeHeader, lineShift); |
270 | 268 | ||
271 | contentType = ""; | 269 | contentType = ""; |
272 | contentAttribute = ""; | 270 | contentAttribute = ""; |
273 | fileName = ""; | 271 | fileName = ""; |
274 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { | 272 | if ((pos = bp.find("CONTENT",'-', 0, TRUE)) != -1) { |
275 | pos++; | 273 | pos++; |
276 | if ( (bp.wordAt(pos).upper() == "TYPE") && | 274 | if ( (bp.wordAt(pos).upper() == "TYPE") && |
277 | (bp.separatorAt(pos) == ':') ) { | 275 | (bp.separatorAt(pos) == ':') ) { |
278 | contentType = bp.nextWord().upper(); | 276 | contentType = bp.nextWord().upper(); |
279 | if (bp.nextSeparator() == '/') | 277 | if (bp.nextSeparator() == '/') |
280 | contentAttribute = bp.nextWord().upper(); | 278 | contentAttribute = bp.nextWord().upper(); |
281 | content = contentType + "/" + contentAttribute; | 279 | content = contentType + "/" + contentAttribute; |
282 | } | 280 | } |
283 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { | 281 | if ((pos = bp.find("ENCODING",':', 0, TRUE)) != -1) { |
284 | pos++; | 282 | pos++; |
285 | encoding = bp.getString(&pos, 'z', TRUE); | 283 | encoding = bp.getString(&pos, 'z', TRUE); |
286 | } | 284 | } |
287 | 285 | ||
288 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { | 286 | if ( (pos = bp.find("FILENAME",'=', 0, TRUE)) != -1) { |
289 | pos++; | 287 | pos++; |
290 | fileName = bp.getString(&pos, 'z', TRUE); | 288 | fileName = bp.getString(&pos, 'z', TRUE); |
291 | fileName = fileName.right(fileName.length() - 1); | 289 | fileName = fileName.right(fileName.length() - 1); |
292 | fileName = fileName.left(fileName.length() - 1); | 290 | fileName = fileName.left(fileName.length() - 1); |
293 | } | 291 | } |
294 | 292 | ||
295 | } | 293 | } |
296 | pos = mimeBody.find(boundary, 0, FALSE); | 294 | pos = mimeBody.find(boundary, 0, FALSE); |
297 | if (pos == -1) //should not occur, malformed mail | 295 | if (pos == -1) //should not occur, malformed mail |
298 | pos = mimeBody.length(); | 296 | pos = mimeBody.length(); |
299 | body = mimeBody.right(mimeBody.length() - pos); | 297 | body = mimeBody.right(mimeBody.length() - pos); |
300 | mimeBody = mimeBody.left(pos); | 298 | mimeBody = mimeBody.left(pos); |
301 | 299 | ||
302 | if (fileName != "") { //attatchments of some type, audio, image etc. | 300 | if (fileName != "") { //attatchments of some type, audio, image etc. |
303 | 301 | ||
304 | Enclosure e; | 302 | Enclosure e; |
305 | e.id = enclosureId; | 303 | e.id = enclosureId; |
306 | e.originalName = fileName; | 304 | e.originalName = fileName; |
307 | e.contentType = contentType; | 305 | e.contentType = contentType; |
308 | e.contentAttribute = contentAttribute; | 306 | e.contentAttribute = contentAttribute; |
309 | e.encoding = encoding; | 307 | e.encoding = encoding; |
310 | e.body = mimeBody; | 308 | e.body = mimeBody; |
311 | e.saved = FALSE; | 309 | e.saved = FALSE; |
312 | mail->addEnclosure(&e); | 310 | mail->addEnclosure(&e); |
313 | enclosureId++; | 311 | enclosureId++; |
314 | 312 | ||
315 | } else if (contentType == "TEXT") { | 313 | } else if (contentType == "TEXT") { |
316 | if (contentAttribute == "PLAIN") { | 314 | if (contentAttribute == "PLAIN") { |
317 | mail->body = mimeBody; | 315 | mail->body = mimeBody; |
318 | mail->bodyPlain = mimeBody; | 316 | mail->bodyPlain = mimeBody; |
319 | } | 317 | } |
320 | if (contentAttribute == "HTML") { | 318 | if (contentAttribute == "HTML") { |
321 | mail->body = mimeBody; | 319 | mail->body = mimeBody; |
322 | } | 320 | } |
323 | } | 321 | } |
324 | } | 322 | } |
325 | } else { | 323 | } else { |
326 | mail->bodyPlain = body; | 324 | mail->bodyPlain = body; |
327 | mail->body = body; | 325 | mail->body = body; |
328 | } | 326 | } |
329 | return TRUE; | 327 | return TRUE; |
330 | } | 328 | } |
331 | 329 | ||
332 | bool EmailHandler::getEnclosure(Enclosure *ePtr) | 330 | bool EmailHandler::getEnclosure(Enclosure *ePtr) |
333 | { | 331 | { |
334 | QFile f(ePtr->path + ePtr->name); | 332 | QFile f(ePtr->path + ePtr->name); |
335 | char src[4]; | 333 | char src[4]; |
336 | char *destPtr; | 334 | char *destPtr; |
337 | QByteArray buffer; | 335 | QByteArray buffer; |
338 | uint bufCount, pos, decodedCount, size, x; | 336 | uint bufCount, pos, decodedCount, size, x; |
339 | 337 | ||
340 | if (! f.open(IO_WriteOnly) ) { | 338 | if (! f.open(IO_WriteOnly) ) { |
341 | qWarning("could not save: " + ePtr->path + ePtr->name); | 339 | qWarning("could not save: " + ePtr->path + ePtr->name); |
342 | return FALSE; | 340 | return FALSE; |
343 | } | 341 | } |
344 | 342 | ||
345 | if (ePtr->encoding.upper() == "BASE64") { | 343 | if (ePtr->encoding.upper() == "BASE64") { |
346 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) | 344 | size = (ePtr->body.length() * 3 / 4); //approximate size (always above) |
347 | buffer.resize(size); | 345 | buffer.resize(size); |
348 | bufCount = 0; | 346 | bufCount = 0; |
349 | pos = 0; | 347 | pos = 0; |
350 | destPtr = buffer.data(); | 348 | destPtr = buffer.data(); |
351 | 349 | ||
352 | while (pos < ePtr->body.length()) { | 350 | while (pos < ePtr->body.length()) { |
353 | decodedCount = 4; | 351 | decodedCount = 4; |
354 | x = 0; | 352 | x = 0; |
355 | while ( (x < 4) && (pos < ePtr->body.length()) ) { | 353 | while ( (x < 4) && (pos < ePtr->body.length()) ) { |
356 | src[x] = ePtr->body[pos].latin1(); | 354 | src[x] = ePtr->body[pos].latin1(); |
357 | pos++; | 355 | pos++; |
358 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') | 356 | if (src[x] == '\r' || src[x] == '\n' || src[x] == ' ') |
359 | x--; | 357 | x--; |
360 | x++; | 358 | x++; |
361 | } | 359 | } |
362 | if (x > 1) { | 360 | if (x > 1) { |
363 | decodedCount = parse64base(src, destPtr); | 361 | decodedCount = parse64base(src, destPtr); |
364 | destPtr += decodedCount; | 362 | destPtr += decodedCount; |
365 | bufCount += decodedCount; | 363 | bufCount += decodedCount; |
366 | } | 364 | } |
367 | } | 365 | } |
368 | 366 | ||
369 | buffer.resize(bufCount); //set correct length of file | 367 | buffer.resize(bufCount); //set correct length of file |
370 | f.writeBlock(buffer); | 368 | f.writeBlock(buffer); |
371 | } else { | 369 | } else { |
372 | QTextStream t(&f); | 370 | QTextStream t(&f); |
373 | t << ePtr->body; | 371 | t << ePtr->body; |
374 | } | 372 | } |
375 | return TRUE; | 373 | return TRUE; |
376 | } | 374 | } |
377 | 375 | ||
378 | int EmailHandler::parse64base(char *src, char *bufOut) { | 376 | int EmailHandler::parse64base(char *src, char *bufOut) { |
379 | 377 | ||
380 | char c, z; | 378 | char c, z; |
381 | char li[4]; | 379 | char li[4]; |
382 | int processed; | 380 | int processed; |
383 | 381 | ||
384 | //conversion table withouth table... | 382 | //conversion table withouth table... |
385 | for (int x = 0; x < 4; x++) { | 383 | for (int x = 0; x < 4; x++) { |
386 | c = src[x]; | 384 | c = src[x]; |
387 | 385 | ||
388 | if ( (int) c >= 'A' && (int) c <= 'Z') | 386 | if ( (int) c >= 'A' && (int) c <= 'Z') |
389 | li[x] = (int) c - (int) 'A'; | 387 | li[x] = (int) c - (int) 'A'; |
390 | if ( (int) c >= 'a' && (int) c <= 'z') | 388 | if ( (int) c >= 'a' && (int) c <= 'z') |
391 | li[x] = (int) c - (int) 'a' + 26; | 389 | li[x] = (int) c - (int) 'a' + 26; |
392 | if ( (int) c >= '0' && (int) c <= '9') | 390 | if ( (int) c >= '0' && (int) c <= '9') |
393 | li[x] = (int) c - (int) '0' + 52; | 391 | li[x] = (int) c - (int) '0' + 52; |
394 | if (c == '+') | 392 | if (c == '+') |
395 | li[x] = 62; | 393 | li[x] = 62; |
396 | if (c == '/') | 394 | if (c == '/') |
397 | li[x] = 63; | 395 | li[x] = 63; |
398 | } | 396 | } |
399 | 397 | ||
400 | processed = 1; | 398 | processed = 1; |
401 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits | 399 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits |
402 | bufOut[0] <<= 2; | 400 | bufOut[0] <<= 2; |
403 | z = li[1] >> 4; | 401 | z = li[1] >> 4; |
404 | bufOut[0] = bufOut[0] | z; //first byte retrived | 402 | bufOut[0] = bufOut[0] | z; //first byte retrived |
405 | 403 | ||
406 | if (src[2] != '=') { | 404 | if (src[2] != '=') { |
407 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits | 405 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits |
408 | bufOut[1] <<= 4; | 406 | bufOut[1] <<= 4; |
409 | z = li[2] >> 2; | 407 | z = li[2] >> 2; |
410 | bufOut[1] = bufOut[1] | z; //second byte retrived | 408 | bufOut[1] = bufOut[1] | z; //second byte retrived |
411 | processed++; | 409 | processed++; |
412 | 410 | ||
413 | if (src[3] != '=') { | 411 | if (src[3] != '=') { |
414 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits | 412 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits |
415 | bufOut[2] <<= 6; | 413 | bufOut[2] <<= 6; |
416 | z = li[3]; | 414 | z = li[3]; |
417 | bufOut[2] = bufOut[2] | z; //third byte retrieved | 415 | bufOut[2] = bufOut[2] | z; //third byte retrieved |
418 | processed++; | 416 | processed++; |
419 | } | 417 | } |
420 | } | 418 | } |
421 | return processed; | 419 | return processed; |
422 | } | 420 | } |
423 | 421 | ||
diff --git a/noncore/unsupported/mailit/mailitwindow.cpp b/noncore/unsupported/mailit/mailitwindow.cpp index fd49c1f..2bf1dcb 100644 --- a/noncore/unsupported/mailit/mailitwindow.cpp +++ b/noncore/unsupported/mailit/mailitwindow.cpp | |||
@@ -1,136 +1,133 @@ | |||
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 "mailitwindow.h" | 20 | #include "mailitwindow.h" |
21 | 21 | ||
22 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) | 22 | MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) |
23 | : QMainWindow(parent, name, fl) | 23 | : QMainWindow(parent, name, fl) |
24 | { | 24 | { |
25 | currentCaption = "Mailit"; | 25 | currentCaption = "Mailit"; |
26 | setCaption(tr(currentCaption)); | 26 | setCaption(tr(currentCaption)); |
27 | views = new QWidgetStack(this); | 27 | views = new QWidgetStack(this); |
28 | setCentralWidget(views); | 28 | setCentralWidget(views); |
29 | 29 | ||
30 | qWarning("***Starting writeMail"); | ||
31 | emailClient = new EmailClient(views, "client"); | 30 | emailClient = new EmailClient(views, "client"); |
32 | writeMail = new WriteMail(views, "writing"); | 31 | writeMail = new WriteMail(views, "writing"); |
33 | readMail = new ReadMail(views, "reading"); | 32 | readMail = new ReadMail(views, "reading"); |
34 | qWarning("***Finished readMail"); | ||
35 | 33 | ||
36 | views->raiseWidget(emailClient); | 34 | views->raiseWidget(emailClient); |
37 | 35 | ||
38 | connect(emailClient, SIGNAL(composeRequested()), | 36 | connect(emailClient, SIGNAL(composeRequested()), |
39 | this, SLOT(compose()) ); | 37 | this, SLOT(compose()) ); |
40 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, | 38 | connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, |
41 | SLOT(viewMail(QListView *, Email *)) ); | 39 | SLOT(viewMail(QListView *, Email *)) ); |
42 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, | 40 | connect(emailClient, SIGNAL(mailUpdated(Email *)), this, |
43 | SLOT(updateMailView(Email *)) ); | 41 | SLOT(updateMailView(Email *)) ); |
44 | 42 | ||
45 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); | 43 | connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); |
46 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, | 44 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, |
47 | SLOT(showEmailClient()) ); | 45 | SLOT(showEmailClient()) ); |
48 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, | 46 | connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, |
49 | SLOT(enqueMail(const Email &)) ); | 47 | SLOT(enqueMail(const Email &)) ); |
50 | 48 | ||
51 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); | 49 | connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); |
52 | connect(readMail, SIGNAL(replyRequested(Email &)), this, | 50 | connect(readMail, SIGNAL(replyRequested(Email &)), this, |
53 | SLOT(composeReply(Email &)) ); | 51 | SLOT(composeReply(Email &)) ); |
54 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, | 52 | connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, |
55 | SLOT(deleteMail(EmailListItem *, bool &)) ); | 53 | SLOT(deleteMail(EmailListItem *, bool &)) ); |
56 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, | 54 | connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, |
57 | SLOT(moveMailFront(Email *)) ); | 55 | SLOT(moveMailFront(Email *)) ); |
58 | 56 | ||
59 | connect(emailClient, SIGNAL(newCaption(const QString &)), | 57 | connect(emailClient, SIGNAL(newCaption(const QString &)), |
60 | this, SLOT(updateCaption(const QString &)) ); | 58 | this, SLOT(updateCaption(const QString &)) ); |
61 | viewingMail = FALSE; | 59 | viewingMail = FALSE; |
62 | 60 | ||
63 | qWarning("***Finished MailitWindow"); | ||
64 | } | 61 | } |
65 | 62 | ||
66 | MailItWindow::~MailItWindow() | 63 | MailItWindow::~MailItWindow() |
67 | { | 64 | { |
68 | } | 65 | } |
69 | 66 | ||
70 | void MailItWindow::closeEvent(QCloseEvent *e) | 67 | void MailItWindow::closeEvent(QCloseEvent *e) |
71 | { | 68 | { |
72 | if (views->visibleWidget() == emailClient) { | 69 | if (views->visibleWidget() == emailClient) { |
73 | e->accept(); | 70 | e->accept(); |
74 | } else { | 71 | } else { |
75 | showEmailClient(); | 72 | showEmailClient(); |
76 | } | 73 | } |
77 | } | 74 | } |
78 | 75 | ||
79 | void MailItWindow::compose() | 76 | void MailItWindow::compose() |
80 | { | 77 | { |
81 | viewingMail = FALSE; | 78 | viewingMail = FALSE; |
82 | emailClient->hide(); | 79 | emailClient->hide(); |
83 | readMail->hide(); | 80 | readMail->hide(); |
84 | views->raiseWidget(writeMail); | 81 | views->raiseWidget(writeMail); |
85 | writeMail->setAddressList(emailClient->getAdrListRef()); | 82 | writeMail->setAddressList(emailClient->getAdrListRef()); |
86 | setCaption( tr( "Write mail" ) ); | 83 | setCaption( tr( "Write mail" ) ); |
87 | } | 84 | } |
88 | 85 | ||
89 | void MailItWindow::composeReply(Email &mail) | 86 | void MailItWindow::composeReply(Email &mail) |
90 | { | 87 | { |
91 | compose(); | 88 | compose(); |
92 | writeMail->reply(mail); | 89 | writeMail->reply(mail); |
93 | } | 90 | } |
94 | 91 | ||
95 | void MailItWindow::showEmailClient() | 92 | void MailItWindow::showEmailClient() |
96 | { | 93 | { |
97 | viewingMail = FALSE; | 94 | viewingMail = FALSE; |
98 | writeMail->hide(); | 95 | writeMail->hide(); |
99 | readMail->hide(); | 96 | readMail->hide(); |
100 | views->raiseWidget(emailClient); | 97 | views->raiseWidget(emailClient); |
101 | setCaption( tr(currentCaption) ); | 98 | setCaption( tr(currentCaption) ); |
102 | } | 99 | } |
103 | 100 | ||
104 | void MailItWindow::viewMail(QListView *view, Email *mail) | 101 | void MailItWindow::viewMail(QListView *view, Email *mail) |
105 | { | 102 | { |
106 | viewingMail = TRUE; | 103 | viewingMail = TRUE; |
107 | emailClient->hide(); | 104 | emailClient->hide(); |
108 | readMail->update(view, mail); | 105 | readMail->update(view, mail); |
109 | views->raiseWidget(readMail); | 106 | views->raiseWidget(readMail); |
110 | setCaption( tr( "Examine mail" ) ); | 107 | setCaption( tr( "Examine mail" ) ); |
111 | } | 108 | } |
112 | 109 | ||
113 | void MailItWindow::updateMailView(Email *mail) | 110 | void MailItWindow::updateMailView(Email *mail) |
114 | { | 111 | { |
115 | if (viewingMail) { | 112 | if (viewingMail) { |
116 | readMail->mailUpdated(mail); | 113 | readMail->mailUpdated(mail); |
117 | } | 114 | } |
118 | } | 115 | } |
119 | 116 | ||
120 | void MailItWindow::updateCaption(const QString &newCaption) | 117 | void MailItWindow::updateCaption(const QString &newCaption) |
121 | { | 118 | { |
122 | currentCaption = newCaption; | 119 | currentCaption = newCaption; |
123 | setCaption(tr(currentCaption)); | 120 | setCaption(tr(currentCaption)); |
124 | } | 121 | } |
125 | 122 | ||
126 | void MailItWindow::setDocument(const QString &_address) | 123 | void MailItWindow::setDocument(const QString &_address) |
127 | { | 124 | { |
128 | // strip leading 'mailto:' | 125 | // strip leading 'mailto:' |
129 | QString address = _address; | 126 | QString address = _address; |
130 | if (address.startsWith("mailto:")) | 127 | if (address.startsWith("mailto:")) |
131 | address = address.mid(6); | 128 | address = address.mid(6); |
132 | 129 | ||
133 | compose(); | 130 | compose(); |
134 | writeMail->setRecipient(address); | 131 | writeMail->setRecipient(address); |
135 | } | 132 | } |
136 | 133 | ||
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp index 2f14ed2..f9cc337 100644 --- a/noncore/unsupported/mailit/popclient.cpp +++ b/noncore/unsupported/mailit/popclient.cpp | |||
@@ -1,375 +1,375 @@ | |||
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 "popclient.h" | 20 | #include "popclient.h" |
21 | #include "emailhandler.h" | 21 | #include "emailhandler.h" |
22 | //#define APOP_TEST | 22 | //#define APOP_TEST |
23 | 23 | ||
24 | extern "C" { | 24 | extern "C" { |
25 | #include "md5.h" | 25 | #include "md5.h" |
26 | } | 26 | } |
27 | 27 | ||
28 | #include <qcstring.h> | 28 | #include <qcstring.h> |
29 | 29 | ||
30 | PopClient::PopClient() | 30 | PopClient::PopClient() |
31 | { | 31 | { |
32 | socket = new QSocket(this, "popClient"); | 32 | socket = new QSocket(this, "popClient"); |
33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 33 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 34 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 35 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
36 | 36 | ||
37 | stream = new QTextStream(socket); | 37 | stream = new QTextStream(socket); |
38 | 38 | ||
39 | receiving = FALSE; | 39 | receiving = FALSE; |
40 | synchronize = FALSE; | 40 | synchronize = FALSE; |
41 | lastSync = 0; | 41 | lastSync = 0; |
42 | headerLimit = 0; | 42 | headerLimit = 0; |
43 | preview = FALSE; | 43 | preview = FALSE; |
44 | } | 44 | } |
45 | 45 | ||
46 | PopClient::~PopClient() | 46 | PopClient::~PopClient() |
47 | { | 47 | { |
48 | delete socket; | 48 | delete socket; |
49 | delete stream; | 49 | delete stream; |
50 | } | 50 | } |
51 | 51 | ||
52 | void PopClient::newConnection(QString target, int port) | 52 | void PopClient::newConnection(QString target, int port) |
53 | { | 53 | { |
54 | if (receiving) { | 54 | if (receiving) { |
55 | qWarning("socket in use, connection refused"); | 55 | qWarning("socket in use, connection refused"); |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | 58 | ||
59 | status = Init; | 59 | status = Init; |
60 | 60 | ||
61 | socket->connectToHost(target, port); | 61 | socket->connectToHost(target, port); |
62 | receiving = TRUE; | 62 | receiving = TRUE; |
63 | selected = FALSE; | 63 | selected = FALSE; |
64 | 64 | ||
65 | emit updateStatus("DNS lookup"); | 65 | emit updateStatus("DNS lookup"); |
66 | } | 66 | } |
67 | 67 | ||
68 | void PopClient::setAccount(QString popUser, QString popPasswd) | 68 | void PopClient::setAccount(QString popUser, QString popPasswd) |
69 | { | 69 | { |
70 | popUserName = popUser; | 70 | popUserName = popUser; |
71 | popPassword = popPasswd; | 71 | popPassword = popPasswd; |
72 | } | 72 | } |
73 | 73 | ||
74 | void PopClient::setSynchronize(int lastCount) | 74 | void PopClient::setSynchronize(int lastCount) |
75 | { | 75 | { |
76 | synchronize = TRUE; | 76 | synchronize = TRUE; |
77 | lastSync = lastCount; | 77 | lastSync = lastCount; |
78 | } | 78 | } |
79 | 79 | ||
80 | void PopClient::removeSynchronize() | 80 | void PopClient::removeSynchronize() |
81 | { | 81 | { |
82 | synchronize = FALSE; | 82 | synchronize = FALSE; |
83 | lastSync = 0; | 83 | lastSync = 0; |
84 | } | 84 | } |
85 | 85 | ||
86 | void PopClient::headersOnly(bool headers, int limit) | 86 | void PopClient::headersOnly(bool headers, int limit) |
87 | { | 87 | { |
88 | preview = headers; | 88 | preview = headers; |
89 | headerLimit = limit; | 89 | headerLimit = limit; |
90 | } | 90 | } |
91 | 91 | ||
92 | void PopClient::setSelectedMails(MailList *list) | 92 | void PopClient::setSelectedMails(MailList *list) |
93 | { | 93 | { |
94 | selected = TRUE; | 94 | selected = TRUE; |
95 | mailList = list; | 95 | mailList = list; |
96 | } | 96 | } |
97 | 97 | ||
98 | void PopClient::connectionEstablished() | 98 | void PopClient::connectionEstablished() |
99 | { | 99 | { |
100 | emit updateStatus(tr("Connection established")); | 100 | emit updateStatus(tr("Connection established")); |
101 | } | 101 | } |
102 | 102 | ||
103 | void PopClient::errorHandling(int status) | 103 | void PopClient::errorHandling(int status) |
104 | { | 104 | { |
105 | emit updateStatus(tr("Error Occured")); | 105 | emit updateStatus(tr("Error Occured")); |
106 | emit errorOccurred(status); | 106 | emit errorOccurred(status); |
107 | socket->close(); | 107 | socket->close(); |
108 | receiving = FALSE; | 108 | receiving = FALSE; |
109 | } | 109 | } |
110 | 110 | ||
111 | void PopClient::incomingData() | 111 | void PopClient::incomingData() |
112 | { | 112 | { |
113 | QString response, temp, temp2, timeStamp; | 113 | QString response, temp, temp2, timeStamp; |
114 | QString md5Source; | 114 | QString md5Source; |
115 | int start, end; | 115 | int start, end; |
116 | // char *md5Digest; | 116 | // char *md5Digest; |
117 | char md5Digest[16]; | 117 | char md5Digest[16]; |
118 | // if ( !socket->canReadLine() ) | 118 | // if ( !socket->canReadLine() ) |
119 | // return; | 119 | // return; |
120 | 120 | ||
121 | response = socket->readLine(); | 121 | response = socket->readLine(); |
122 | qDebug(response +" %d", status); | 122 | //qDebug(response +" %d", status); |
123 | 123 | ||
124 | switch(status) { | 124 | switch(status) { |
125 | //logging in | 125 | //logging in |
126 | case Init: { | 126 | case Init: { |
127 | #ifdef APOP_TEST | 127 | #ifdef APOP_TEST |
128 | start = response.find('<',0); | 128 | start = response.find('<',0); |
129 | end = response.find('>', start); | 129 | end = response.find('>', start); |
130 | if( start >= 0 && end > start ) | 130 | if( start >= 0 && end > start ) |
131 | { | 131 | { |
132 | timeStamp = response.mid( start , end - start + 1); | 132 | timeStamp = response.mid( start , end - start + 1); |
133 | md5Source = timeStamp + popPassword; | 133 | md5Source = timeStamp + popPassword; |
134 | qDebug( md5Source); | 134 | //qDebug( md5Source); |
135 | // for( int i = 0; i < md5Source.length(); i++) { | 135 | // for( int i = 0; i < md5Source.length(); i++) { |
136 | // buff[i] = (QChar)md5Source[i]; | 136 | // buff[i] = (QChar)md5Source[i]; |
137 | // } | 137 | // } |
138 | 138 | ||
139 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); | 139 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); |
140 | // md5_buffer(char const *buffer, unsigned int len, char *digest); | 140 | // md5_buffer(char const *buffer, unsigned int len, char *digest); |
141 | 141 | ||
142 | // MD5_Init( &ctx); | 142 | // MD5_Init( &ctx); |
143 | // MD5_Update( &ctx, buff, sizeof( buff) ); | 143 | // MD5_Update( &ctx, buff, sizeof( buff) ); |
144 | // MD5_Final( md5Digest, &ctx); | 144 | // MD5_Final( md5Digest, &ctx); |
145 | // MD5( buff, md5Source.length(), md5Digest); | 145 | // MD5( buff, md5Source.length(), md5Digest); |
146 | 146 | ||
147 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) | 147 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) |
148 | { | 148 | { |
149 | printf("%x", md5Digest[j]); | 149 | printf("%x", md5Digest[j]); |
150 | } | 150 | } |
151 | printf("\n"); | 151 | printf("\n"); |
152 | // qDebug(md5Digest); | 152 | // qDebug(md5Digest); |
153 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; | 153 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; |
154 | // qDebug("%s", stream); | 154 | // qDebug("%s", stream); |
155 | status = Stat; | 155 | status = Stat; |
156 | } | 156 | } |
157 | else | 157 | else |
158 | #endif | 158 | #endif |
159 | { | 159 | { |
160 | timeStamp = ""; | 160 | timeStamp = ""; |
161 | *stream << "USER " << popUserName << "\r\n"; | 161 | *stream << "USER " << popUserName << "\r\n"; |
162 | status = Pass; | 162 | status = Pass; |
163 | } | 163 | } |
164 | 164 | ||
165 | break; | 165 | break; |
166 | } | 166 | } |
167 | //password shhh. don't tell anyone (implement APOP...) | 167 | //password shhh. don't tell anyone (implement APOP...) |
168 | case Pass: { | 168 | case Pass: { |
169 | *stream << "PASS " << popPassword << "\r\n"; | 169 | *stream << "PASS " << popPassword << "\r\n"; |
170 | status = Stat; | 170 | status = Stat; |
171 | break; | 171 | break; |
172 | } | 172 | } |
173 | //ask for number of messages | 173 | //ask for number of messages |
174 | case Stat: { | 174 | case Stat: { |
175 | if (response[0] == '+') { | 175 | if (response[0] == '+') { |
176 | *stream << "STAT" << "\r\n"; | 176 | *stream << "STAT" << "\r\n"; |
177 | status = Mcnt; | 177 | status = Mcnt; |
178 | } else errorHandling(ErrLoginFailed); | 178 | } else errorHandling(ErrLoginFailed); |
179 | break; | 179 | break; |
180 | } | 180 | } |
181 | //get count of messages, eg "+OK 4 900.." -> int 4 | 181 | //get count of messages, eg "+OK 4 900.." -> int 4 |
182 | case Mcnt: { | 182 | case Mcnt: { |
183 | if (response[0] == '+') { | 183 | if (response[0] == '+') { |
184 | temp = response.replace(0, 4, ""); | 184 | temp = response.replace(0, 4, ""); |
185 | int x = temp.find(" ", 0); | 185 | int x = temp.find(" ", 0); |
186 | temp.truncate((uint) x); | 186 | temp.truncate((uint) x); |
187 | newMessages = temp.toInt(); | 187 | newMessages = temp.toInt(); |
188 | messageCount = 1; | 188 | messageCount = 1; |
189 | status = List; | 189 | status = List; |
190 | 190 | ||
191 | if (synchronize) { | 191 | if (synchronize) { |
192 | //messages deleted from server, reload all | 192 | //messages deleted from server, reload all |
193 | if (newMessages < lastSync) | 193 | if (newMessages < lastSync) |
194 | lastSync = 0; | 194 | lastSync = 0; |
195 | messageCount = lastSync + 1; | 195 | messageCount = 1; |
196 | } | 196 | } |
197 | 197 | ||
198 | if (selected) { | 198 | if (selected) { |
199 | int *ptr = mailList->first(); | 199 | int *ptr = mailList->first(); |
200 | if (ptr != 0) { | 200 | if (ptr != 0) { |
201 | newMessages++; //to ensure no early jumpout | 201 | newMessages++; //to ensure no early jumpout |
202 | messageCount = *(mailList->first()); | 202 | messageCount = *(mailList->first()); |
203 | } else newMessages = 0; | 203 | } else newMessages = 0; |
204 | } | 204 | } |
205 | } else errorHandling(ErrUnknownResponse); | 205 | } else errorHandling(ErrUnknownResponse); |
206 | } | 206 | } |
207 | //Read message number x, count upwards to messageCount | 207 | //Read message number x, count upwards to messageCount |
208 | case List: { | 208 | case List: { |
209 | if (messageCount <= newMessages) { | 209 | if (messageCount <= newMessages) { |
210 | *stream << "LIST " << messageCount << "\r\n"; | 210 | *stream << "LIST " << messageCount << "\r\n"; |
211 | status = Size; | 211 | status = Size; |
212 | temp2.setNum(newMessages - lastSync); | 212 | temp2.setNum(newMessages - lastSync); |
213 | temp.setNum(messageCount - lastSync); | 213 | temp.setNum(messageCount - lastSync); |
214 | if (!selected) { | 214 | if (!selected) { |
215 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 215 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
216 | } else { | 216 | } else { |
217 | //completing a previously closed transfer | 217 | //completing a previously closed transfer |
218 | if ( (messageCount - lastSync) <= 0) { | 218 | if ( (messageCount - lastSync) <= 0) { |
219 | temp.setNum(messageCount); | 219 | temp.setNum(messageCount); |
220 | emit updateStatus(tr("Previous message ") + temp); | 220 | emit updateStatus(tr("Previous message ") + temp); |
221 | } else { | 221 | } else { |
222 | emit updateStatus(tr("Completing message ") + temp); | 222 | emit updateStatus(tr("Completing message ") + temp); |
223 | } | 223 | } |
224 | } | 224 | } |
225 | break; | 225 | break; |
226 | } else { | 226 | } else { |
227 | emit updateStatus(tr("No new Messages")); | 227 | emit updateStatus(tr("No new Messages")); |
228 | status = Quit; | 228 | status = Quit; |
229 | } | 229 | } |
230 | } | 230 | } |
231 | //get size of message, eg "500 characters in message.." -> int 500 | 231 | //get size of message, eg "500 characters in message.." -> int 500 |
232 | case Size: { | 232 | case Size: { |
233 | if (status != Quit) { //because of idiotic switch | 233 | if (status != Quit) { //because of idiotic switch |
234 | if (response[0] == '+') { | 234 | if (response[0] == '+') { |
235 | temp = response.replace(0, 4, ""); | 235 | temp = response.replace(0, 4, ""); |
236 | int x = temp.find(" ", 0); | 236 | int x = temp.find(" ", 0); |
237 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 237 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
238 | mailSize = temp.toInt(); | 238 | mailSize = temp.toInt(); |
239 | emit currentMailSize(mailSize); | 239 | emit currentMailSize(mailSize); |
240 | 240 | ||
241 | status = Retr; | 241 | status = Retr; |
242 | } else { | 242 | } else { |
243 | qWarning(response); | 243 | //qWarning(response); |
244 | errorHandling(ErrUnknownResponse); | 244 | errorHandling(ErrUnknownResponse); |
245 | } | 245 | } |
246 | } | 246 | } |
247 | } | 247 | } |
248 | //Read message number x, count upwards to messageCount | 248 | //Read message number x, count upwards to messageCount |
249 | case Retr: { | 249 | case Retr: { |
250 | if (status != Quit) { | 250 | if (status != Quit) { |
251 | if (!preview || mailSize <= headerLimit) { | 251 | if (!preview || mailSize <= headerLimit) { |
252 | *stream << "RETR " << messageCount << "\r\n"; | 252 | *stream << "RETR " << messageCount << "\r\n"; |
253 | } else { //only header | 253 | } else { //only header |
254 | *stream << "TOP " << messageCount << " 0\r\n"; | 254 | *stream << "TOP " << messageCount << " 0\r\n"; |
255 | } | 255 | } |
256 | messageCount++; | 256 | messageCount++; |
257 | status = Ignore; | 257 | status = Ignore; |
258 | break; | 258 | break; |
259 | } } | 259 | } } |
260 | case Ignore: { | 260 | case Ignore: { |
261 | if (status != Quit) { //because of idiotic switch | 261 | if (status != Quit) { //because of idiotic switch |
262 | if (response[0] == '+') { | 262 | if (response[0] == '+') { |
263 | message = ""; | 263 | message = ""; |
264 | status = Read; | 264 | status = Read; |
265 | if (!socket->canReadLine()) //sync. problems | 265 | if (!socket->canReadLine()) //sync. problems |
266 | break; | 266 | break; |
267 | response = socket->readLine(); | 267 | response = socket->readLine(); |
268 | } else errorHandling(ErrUnknownResponse); | 268 | } else errorHandling(ErrUnknownResponse); |
269 | } | 269 | } |
270 | } | 270 | } |
271 | //add all incoming lines to body. When size is reached, send | 271 | //add all incoming lines to body. When size is reached, send |
272 | //message, and go back to read new message | 272 | //message, and go back to read new message |
273 | case Read: { | 273 | case Read: { |
274 | if (status != Quit) { //because of idiotic switch | 274 | if (status != Quit) { //because of idiotic switch |
275 | message += response; | 275 | message += response; |
276 | while ( socket->canReadLine() ) { | 276 | while ( socket->canReadLine() ) { |
277 | response = socket->readLine(); | 277 | response = socket->readLine(); |
278 | message += response; | 278 | message += response; |
279 | } | 279 | } |
280 | emit downloadedSize(message.length()); | 280 | emit downloadedSize(message.length()); |
281 | int x = message.find("\r\n.\r\n",-5); | 281 | int x = message.find("\r\n.\r\n",-5); |
282 | if (x == -1) { | 282 | if (x == -1) { |
283 | break; | 283 | break; |
284 | } else { //message reach entire size | 284 | } else { //message reach entire size |
285 | //complete mail downloaded | 285 | //complete mail downloaded |
286 | if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ | 286 | if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ |
287 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 287 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
288 | } else { //incomplete mail downloaded | 288 | } else { //incomplete mail downloaded |
289 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 289 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
290 | } | 290 | } |
291 | if (messageCount > newMessages) //that was the last message | 291 | if (messageCount > newMessages) //that was the last message |
292 | status = Quit; | 292 | status = Quit; |
293 | else { //ask for new message | 293 | else { //ask for new message |
294 | if (selected) { //grab next from queue | 294 | if (selected) { //grab next from queue |
295 | int *ptr = mailList->next(); | 295 | int *ptr = mailList->next(); |
296 | if (ptr != 0) { | 296 | if (ptr != 0) { |
297 | messageCount = *ptr; | 297 | messageCount = *ptr; |
298 | *stream << "LIST " << messageCount << "\r\n"; | 298 | *stream << "LIST " << messageCount << "\r\n"; |
299 | status = Size; | 299 | status = Size; |
300 | //completing a previously closed transfer | 300 | //completing a previously closed transfer |
301 | if ( (messageCount - lastSync) <= 0) { | 301 | if ( (messageCount - lastSync) <= 0) { |
302 | temp.setNum(messageCount); | 302 | temp.setNum(messageCount); |
303 | emit updateStatus(tr("Previous message ") + temp); | 303 | emit updateStatus(tr("Previous message ") + temp); |
304 | } else { | 304 | } else { |
305 | temp.setNum(messageCount - lastSync); | 305 | temp.setNum(messageCount - lastSync); |
306 | emit updateStatus(tr("Completing message ") + temp); | 306 | emit updateStatus(tr("Completing message ") + temp); |
307 | } | 307 | } |
308 | break; | 308 | break; |
309 | } else { | 309 | } else { |
310 | newMessages--; | 310 | newMessages--; |
311 | status = Quit; | 311 | status = Quit; |
312 | } | 312 | } |
313 | } else { | 313 | } else { |
314 | *stream << "LIST " << messageCount << "\r\n"; | 314 | *stream << "LIST " << messageCount << "\r\n"; |
315 | status = Size; | 315 | status = Size; |
316 | temp2.setNum(newMessages - lastSync); | 316 | temp2.setNum(newMessages - lastSync); |
317 | temp.setNum(messageCount - lastSync); | 317 | temp.setNum(messageCount - lastSync); |
318 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 318 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
319 | 319 | ||
320 | break; | 320 | break; |
321 | } | 321 | } |
322 | } | 322 | } |
323 | } | 323 | } |
324 | if (status != Quit) | 324 | if (status != Quit) |
325 | break; | 325 | break; |
326 | } | 326 | } |
327 | } | 327 | } |
328 | case Quit: { | 328 | case Quit: { |
329 | *stream << "Quit\r\n"; | 329 | *stream << "Quit\r\n"; |
330 | status = Done; | 330 | status = Done; |
331 | int newM = newMessages - lastSync; | 331 | int newM = newMessages - lastSync; |
332 | if (newM > 0) { | 332 | if (newM > 0) { |
333 | temp.setNum(newM); | 333 | temp.setNum(newM); |
334 | emit updateStatus(temp + tr(" new messages")); | 334 | emit updateStatus(temp + tr(" new messages")); |
335 | } else { | 335 | } else { |
336 | emit updateStatus(tr("No new messages")); | 336 | emit updateStatus(tr("No new messages")); |
337 | } | 337 | } |
338 | 338 | ||
339 | socket->close(); | 339 | socket->close(); |
340 | receiving = FALSE; | 340 | receiving = FALSE; |
341 | emit mailTransfered(newM); | 341 | emit mailTransfered(newM); |
342 | break; | 342 | break; |
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
346 | } | 346 | } |
347 | 347 | ||
348 | // if( bAPOPAuthentication ) | 348 | // if( bAPOPAuthentication ) |
349 | // { | 349 | // { |
350 | // if( m_strTimeStamp.IsEmpty() ) | 350 | // if( m_strTimeStamp.IsEmpty() ) |
351 | // { | 351 | // { |
352 | // SetLastError("Apop error!"); | 352 | // SetLastError("Apop error!"); |
353 | // return false; | 353 | // return false; |
354 | // } | 354 | // } |
355 | // strMD5Source = m_strTimeStamp+pszPassword; | 355 | // strMD5Source = m_strTimeStamp+pszPassword; |
356 | // strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); | 356 | // strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); |
357 | // sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); | 357 | // sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); |
358 | // ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); | 358 | // ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); |
359 | // if(ret == SOCKET_ERROR) | 359 | // if(ret == SOCKET_ERROR) |
360 | // { | 360 | // { |
361 | // SetLastError("Socket error!"); | 361 | // SetLastError("Socket error!"); |
362 | // m_bSocketOK = false; | 362 | // m_bSocketOK = false; |
363 | // m_bConnected = false; | 363 | // m_bConnected = false; |
364 | // return false; | 364 | // return false; |
365 | // } | 365 | // } |
366 | // if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) | 366 | // if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) |
367 | // return false; | 367 | // return false; |
368 | // if( 0 == strResult.Find('-' , 0) ) | 368 | // if( 0 == strResult.Find('-' , 0) ) |
369 | // { | 369 | // { |
370 | // SetLastError("Username or Password error!"); | 370 | // SetLastError("Username or Password error!"); |
371 | // return false; | 371 | // return false; |
372 | // } | 372 | // } |
373 | // m_bConnected = true; | 373 | // m_bConnected = true; |
374 | 374 | ||
375 | // } | 375 | // } |
diff --git a/noncore/unsupported/mailit/readmail.cpp b/noncore/unsupported/mailit/readmail.cpp index a5e7147..7cd3e09 100644 --- a/noncore/unsupported/mailit/readmail.cpp +++ b/noncore/unsupported/mailit/readmail.cpp | |||
@@ -1,326 +1,327 @@ | |||
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 "readmail.h" | 20 | #include "readmail.h" |
21 | #include <qimage.h> | 21 | #include <qimage.h> |
22 | #include <qmime.h> | 22 | #include <qmime.h> |
23 | #include <qaction.h> | 23 | #include <qaction.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) | 26 | ReadMail::ReadMail( QWidget* parent, const char* name, WFlags fl ) |
27 | : QMainWindow(parent, name, fl) | 27 | : QMainWindow(parent, name, fl) |
28 | { | 28 | { |
29 | plainTxt = FALSE; | 29 | plainTxt = FALSE; |
30 | 30 | ||
31 | init(); | 31 | init(); |
32 | viewAtt = new ViewAtt(0, "View Attatchments"); | 32 | viewAtt = new ViewAtt(0, "View Attatchments"); |
33 | } | 33 | } |
34 | 34 | ||
35 | ReadMail::~ReadMail() | 35 | ReadMail::~ReadMail() |
36 | { | 36 | { |
37 | delete emailView->mimeSourceFactory(); | 37 | delete emailView->mimeSourceFactory(); |
38 | delete viewAtt; | 38 | delete viewAtt; |
39 | } | 39 | } |
40 | 40 | ||
41 | void ReadMail::init() | 41 | void ReadMail::init() |
42 | { | 42 | { |
43 | setToolBarsMovable(FALSE); | 43 | setToolBarsMovable(FALSE); |
44 | 44 | ||
45 | bar = new QToolBar(this); | 45 | bar = new QToolBar(this); |
46 | bar->setHorizontalStretchable( TRUE ); | 46 | bar->setHorizontalStretchable( TRUE ); |
47 | 47 | ||
48 | menu = new QMenuBar( bar ); | 48 | menu = new QMenuBar( bar ); |
49 | 49 | ||
50 | viewMenu = new QPopupMenu(menu); | 50 | viewMenu = new QPopupMenu(menu); |
51 | menu->insertItem( tr( "&View" ), viewMenu); | 51 | menu->insertItem( tr( "&View" ), viewMenu); |
52 | 52 | ||
53 | mailMenu = new QPopupMenu(menu); | 53 | mailMenu = new QPopupMenu(menu); |
54 | menu->insertItem( tr( "&Mail" ), mailMenu); | 54 | menu->insertItem( tr( "&Mail" ), mailMenu); |
55 | 55 | ||
56 | bar = new QToolBar(this); | 56 | bar = new QToolBar(this); |
57 | 57 | ||
58 | //reply dependant on viewing inbox | 58 | //reply dependant on viewing inbox |
59 | replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), | 59 | replyButton = new QAction( tr( "Reply" ), Resource::loadPixmap( "mailit/reply" ), |
60 | QString::null, 0, this, 0 ); | 60 | QString::null, 0, this, 0 ); |
61 | connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) ); | 61 | connect(replyButton, SIGNAL(activated()), this, SLOT(reply()) ); |
62 | 62 | ||
63 | previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | 63 | previousButton = new QAction( tr( "Previous" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); |
64 | connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); | 64 | connect( previousButton, SIGNAL( activated() ), this, SLOT( previous() ) ); |
65 | previousButton->addTo(bar); | 65 | previousButton->addTo(bar); |
66 | previousButton->addTo(viewMenu); | 66 | previousButton->addTo(viewMenu); |
67 | 67 | ||
68 | nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); | 68 | nextButton = new QAction( tr( "Next" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); |
69 | connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); | 69 | connect( nextButton, SIGNAL( activated() ), this, SLOT( next() ) ); |
70 | nextButton->addTo(bar); | 70 | nextButton->addTo(bar); |
71 | nextButton->addTo(viewMenu); | 71 | nextButton->addTo(viewMenu); |
72 | 72 | ||
73 | attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); | 73 | attatchmentsButton = new QAction( tr( "Attatchments" ), Resource::loadPixmap( "mailit/attach" ), QString::null, 0, this, 0 ); |
74 | connect( attatchmentsButton, SIGNAL( activated() ), this, | 74 | connect( attatchmentsButton, SIGNAL( activated() ), this, |
75 | SLOT( viewAttatchments() ) ); | 75 | SLOT( viewAttatchments() ) ); |
76 | attatchmentsButton->addTo(bar); | 76 | attatchmentsButton->addTo(bar); |
77 | attatchmentsButton->addTo(viewMenu); | 77 | attatchmentsButton->addTo(viewMenu); |
78 | 78 | ||
79 | plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); | 79 | plainTextButton = new QAction( tr( "Text Format" ), Resource::loadPixmap( "DocsIcon" ), QString::null, 0, this, 0, TRUE); |
80 | connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); | 80 | connect( plainTextButton, SIGNAL( activated() ), this, SLOT( shiftText() ) ); |
81 | plainTextButton->addTo(bar); | 81 | plainTextButton->addTo(bar); |
82 | plainTextButton->addTo(viewMenu); | 82 | plainTextButton->addTo(viewMenu); |
83 | 83 | ||
84 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); | 84 | deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); |
85 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); | 85 | connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); |
86 | deleteButton->addTo(bar); | 86 | deleteButton->addTo(bar); |
87 | deleteButton->addTo(mailMenu); | 87 | deleteButton->addTo(mailMenu); |
88 | 88 | ||
89 | viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); | 89 | viewMenu->insertItem(Resource::loadPixmap("close"), "Close", this, SLOT(close())); |
90 | 90 | ||
91 | emailView = new QTextView( this, "emailView" ); | 91 | emailView = new QTextView( this, "emailView" ); |
92 | |||
92 | setCentralWidget(emailView); | 93 | setCentralWidget(emailView); |
93 | 94 | ||
94 | mime = new QMimeSourceFactory(); | 95 | mime = new QMimeSourceFactory(); |
95 | emailView->setMimeSourceFactory(mime); | 96 | emailView->setMimeSourceFactory(mime); |
96 | } | 97 | } |
97 | 98 | ||
98 | void ReadMail::updateView() | 99 | void ReadMail::updateView() |
99 | { | 100 | { |
100 | Enclosure *ePtr; | 101 | Enclosure *ePtr; |
101 | QString mailStringSize; | 102 | QString mailStringSize; |
102 | QString text, temp; | 103 | QString text, temp; |
103 | 104 | ||
104 | mail->read = TRUE; //mark as read | 105 | mail->read = TRUE; //mark as read |
105 | inbox = mail->received; | 106 | inbox = mail->received; |
106 | 107 | ||
107 | replyButton->removeFrom(mailMenu); | 108 | replyButton->removeFrom(mailMenu); |
108 | replyButton->removeFrom(bar); | 109 | replyButton->removeFrom(bar); |
109 | 110 | ||
110 | if (inbox == TRUE) { | 111 | if (inbox == TRUE) { |
111 | replyButton->addTo(bar); | 112 | replyButton->addTo(bar); |
112 | replyButton->addTo(mailMenu); | 113 | replyButton->addTo(mailMenu); |
113 | 114 | ||
114 | if (!mail->downloaded) { | 115 | if (!mail->downloaded) { |
115 | //report currently viewed mail so that it will be | 116 | //report currently viewed mail so that it will be |
116 | //placed first in the queue of new mails to download | 117 | //placed first in the queue of new mails to download |
117 | emit viewingMail(mail); | 118 | emit viewingMail(mail); |
118 | 119 | ||
119 | double mailSize = (double) mail->size; | 120 | double mailSize = (double) mail->size; |
120 | if (mailSize < 1024) { | 121 | if (mailSize < 1024) { |
121 | mailStringSize.setNum(mailSize); | 122 | mailStringSize.setNum(mailSize); |
122 | mailStringSize += " Bytes"; | 123 | mailStringSize += " Bytes"; |
123 | } else if (mailSize < 1024*1024) { | 124 | } else if (mailSize < 1024*1024) { |
124 | mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); | 125 | mailStringSize.setNum( (mailSize / 1024), 'g', 2 ); |
125 | mailStringSize += " Kb"; | 126 | mailStringSize += " Kb"; |
126 | } else { | 127 | } else { |
127 | mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); | 128 | mailStringSize.setNum( (mailSize / (1024*1024)), 'g', 3); |
128 | mailStringSize += " Mb"; | 129 | mailStringSize += " Mb"; |
129 | } | 130 | } |
130 | } | 131 | } |
131 | } | 132 | } |
132 | 133 | ||
133 | QMimeSourceFactory *mime = emailView->mimeSourceFactory(); | 134 | QMimeSourceFactory *mime = emailView->mimeSourceFactory(); |
134 | 135 | ||
135 | if (! plainTxt) { //use RichText, inline pics etc. | 136 | if (! plainTxt) { //use RichText, inline pics etc. |
136 | emailView->setTextFormat(QTextView::RichText); | 137 | emailView->setTextFormat(QTextView::RichText); |
137 | text = "<b><big><center><font color=\"blue\">" + mail->subject | 138 | text = "<b><big><center><font color=\"blue\">" + mail->subject |
138 | +"</font></center></big></b><br>"; | 139 | +"</font></center></big></b><br>"; |
139 | text += "<b>From: </b>" + mail->from + " <i>" + | 140 | text += "<b>From: </b>" + mail->from + " <i>" + |
140 | mail->fromMail + "</i><br>"; | 141 | mail->fromMail + "</i><br>"; |
141 | 142 | ||
142 | text +="<b>To: </b>"; | 143 | text +="<b>To: </b>"; |
143 | for (QStringList::Iterator it = mail->recipients.begin(); | 144 | for (QStringList::Iterator it = mail->recipients.begin(); |
144 | it != mail->recipients.end(); ++it ) { | 145 | it != mail->recipients.end(); ++it ) { |
145 | text += *it + " "; | 146 | text += *it + " "; |
146 | } | 147 | } |
147 | text += "<br>" + mail->date; | 148 | text += "<br>" + mail->date; |
148 | 149 | ||
149 | if (mail->files.count() > 0) { | 150 | if (mail->files.count() > 0) { |
150 | text += "<br><b>Attatchments: </b>"; | 151 | text += "<br><b>Attatchments: </b>"; |
151 | 152 | ||
152 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 153 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
153 | text += ePtr->originalName + " "; | 154 | text += ePtr->originalName + " "; |
154 | } | 155 | } |
155 | text += "<hr><br>" + mail->body; | 156 | text += "<hr><br>" + mail->body; |
156 | 157 | ||
157 | if (inbox) { | 158 | if (inbox) { |
158 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 159 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
159 | 160 | ||
160 | text += "<br><hr><b>Attatchment: </b>" + | 161 | text += "<br><hr><b>Attatchment: </b>" + |
161 | ePtr->originalName + "<hr>"; | 162 | ePtr->originalName + "<hr>"; |
162 | 163 | ||
163 | if (ePtr->contentType == "TEXT") { | 164 | if (ePtr->contentType == "TEXT") { |
164 | QFile f(ePtr->path + ePtr->name); | 165 | QFile f(ePtr->path + ePtr->name); |
165 | 166 | ||
166 | if (f.open(IO_ReadOnly) ) { | 167 | if (f.open(IO_ReadOnly) ) { |
167 | QTextStream t(&f); | 168 | QTextStream t(&f); |
168 | temp = t.read(); | 169 | temp = t.read(); |
169 | text += temp + "<br>"; | 170 | text += temp + "<br>"; |
170 | f.close(); | 171 | f.close(); |
171 | } else { | 172 | } else { |
172 | text += "<b>Could not locate file</b><br>"; | 173 | text += "<b>Could not locate file</b><br>"; |
173 | } | 174 | } |
174 | 175 | ||
175 | } | 176 | } |
176 | if (ePtr->contentType == "IMAGE") { | 177 | if (ePtr->contentType == "IMAGE") { |
177 | // temp.setNum(emailView->width());//get display width | 178 | // temp.setNum(emailView->width());//get display width |
178 | // text += "<img width=" + temp +" src =""" + | 179 | // text += "<img width=" + temp +" src =""" + |
179 | // ePtr->originalName + """> </img>"; | 180 | // ePtr->originalName + """> </img>"; |
180 | text += "<img src =""" + | 181 | text += "<img src =""" + |
181 | ePtr->originalName + """> </img>"; | 182 | ePtr->originalName + """> </img>"; |
182 | mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); | 183 | mime->setPixmap(ePtr->originalName, QPixmap( (ePtr->path + ePtr->name) )); |
183 | } | 184 | } |
184 | } | 185 | } |
185 | } | 186 | } |
186 | } else { | 187 | } else { |
187 | if (mail->downloaded || !inbox) { | 188 | if (mail->downloaded || !inbox) { |
188 | text += "<hr><br>" + mail->body; | 189 | text += "<hr><br>" + mail->body; |
189 | } else { | 190 | } else { |
190 | text += "<hr><br><b> Awaiting download </b><br>"; | 191 | text += "<hr><br><b> Awaiting download </b><br>"; |
191 | text += "Size of mail: " + mailStringSize; | 192 | text += "Size of mail: " + mailStringSize; |
192 | } | 193 | } |
193 | } | 194 | } |
194 | emailView->setText(text); | 195 | emailView->setText(text); |
195 | } else { // show plain txt mail | 196 | } else { // show plain txt mail |
196 | emailView->setTextFormat(QTextView::PlainText); | 197 | emailView->setTextFormat(QTextView::PlainText); |
197 | text = "Subject: " + mail->subject + "\n"; | 198 | text = "Subject: " + mail->subject + "\n"; |
198 | text += "From: " + mail->from + " " + mail->fromMail + "\n"; | 199 | text += "From: " + mail->from + " " + mail->fromMail + "\n"; |
199 | text += "To: "; | 200 | text += "To: "; |
200 | for (QStringList::Iterator it = mail->recipients.begin(); | 201 | for (QStringList::Iterator it = mail->recipients.begin(); |
201 | it != mail->recipients.end(); ++it ) { | 202 | it != mail->recipients.end(); ++it ) { |
202 | text += *it + " "; | 203 | text += *it + " "; |
203 | } | 204 | } |
204 | text += "\nDate: " + mail->date + "\n"; | 205 | text += "\nDate: " + mail->date + "\n"; |
205 | if (mail->files.count() > 0) { | 206 | if (mail->files.count() > 0) { |
206 | text += "Attatchments: "; | 207 | text += "Attatchments: "; |
207 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 208 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
208 | text += ePtr->originalName + " "; | 209 | text += ePtr->originalName + " "; |
209 | } | 210 | } |
210 | text += "\n\n"; | 211 | text += "\n\n"; |
211 | } else text += "\n"; | 212 | } else text += "\n"; |
212 | 213 | ||
213 | if (!inbox) { | 214 | if (!inbox) { |
214 | text += mail->body; | 215 | text += mail->body; |
215 | } else if (mail->downloaded) { | 216 | } else if (mail->downloaded) { |
216 | text += mail->bodyPlain; | 217 | text += mail->bodyPlain; |
217 | } else { | 218 | } else { |
218 | text += "\nAwaiting download\n"; | 219 | text += "\nAwaiting download\n"; |
219 | text += "Size of mail: " + mailStringSize; | 220 | text += "Size of mail: " + mailStringSize; |
220 | } | 221 | } |
221 | 222 | ||
222 | emailView->setText(text); | 223 | emailView->setText(text); |
223 | } | 224 | } |
224 | 225 | ||
225 | if (mail->files.count() == 0) | 226 | if (mail->files.count() == 0) |
226 | attatchmentsButton->setEnabled(FALSE); | 227 | attatchmentsButton->setEnabled(FALSE); |
227 | else attatchmentsButton->setEnabled(TRUE); | 228 | else attatchmentsButton->setEnabled(TRUE); |
228 | 229 | ||
229 | setCaption("Examining mail: " + mail->subject); | 230 | setCaption("Examining mail: " + mail->subject); |
230 | } | 231 | } |
231 | 232 | ||
232 | //update view with current EmailListItem (item) | 233 | //update view with current EmailListItem (item) |
233 | void ReadMail::update(QListView *thisView, Email *mailIn) | 234 | void ReadMail::update(QListView *thisView, Email *mailIn) |
234 | { | 235 | { |
235 | view = thisView; | 236 | view = thisView; |
236 | item = (EmailListItem *) view->selectedItem(); | 237 | item = (EmailListItem *) view->selectedItem(); |
237 | mail = mailIn; | 238 | mail = mailIn; |
238 | updateView(); | 239 | updateView(); |
239 | updateButtons(); | 240 | updateButtons(); |
240 | } | 241 | } |
241 | 242 | ||
242 | void ReadMail::mailUpdated(Email *mailIn) | 243 | void ReadMail::mailUpdated(Email *mailIn) |
243 | { | 244 | { |
244 | if (mailIn == mail) { | 245 | if (mailIn == mail) { |
245 | updateView(); | 246 | updateView(); |
246 | } else { | 247 | } else { |
247 | updateButtons(); | 248 | updateButtons(); |
248 | } | 249 | } |
249 | } | 250 | } |
250 | 251 | ||
251 | void ReadMail::close() | 252 | void ReadMail::close() |
252 | { | 253 | { |
253 | emit cancelView(); | 254 | emit cancelView(); |
254 | } | 255 | } |
255 | 256 | ||
256 | //gets next item in listview, exits if there is no next | 257 | //gets next item in listview, exits if there is no next |
257 | void ReadMail::next() | 258 | void ReadMail::next() |
258 | { | 259 | { |
259 | item = (EmailListItem *) item->nextSibling(); | 260 | item = (EmailListItem *) item->nextSibling(); |
260 | if (item != NULL) { | 261 | if (item != NULL) { |
261 | mail = item->getMail(); | 262 | mail = item->getMail(); |
262 | updateView(); | 263 | updateView(); |
263 | } | 264 | } |
264 | updateButtons(); | 265 | updateButtons(); |
265 | } | 266 | } |
266 | 267 | ||
267 | //gets previous item in listview, exits if there is no previous | 268 | //gets previous item in listview, exits if there is no previous |
268 | void ReadMail::previous() | 269 | void ReadMail::previous() |
269 | { | 270 | { |
270 | item = (EmailListItem *) item->itemAbove(); | 271 | item = (EmailListItem *) item->itemAbove(); |
271 | if (item != NULL) { | 272 | if (item != NULL) { |
272 | mail = item->getMail(); | 273 | mail = item->getMail(); |
273 | updateView(); | 274 | updateView(); |
274 | } | 275 | } |
275 | updateButtons(); | 276 | updateButtons(); |
276 | } | 277 | } |
277 | 278 | ||
278 | //deletes item, tries bringing up next or previous, exits if unsucessful | 279 | //deletes item, tries bringing up next or previous, exits if unsucessful |
279 | void ReadMail::deleteItem() | 280 | void ReadMail::deleteItem() |
280 | { | 281 | { |
281 | EmailListItem *temp = item; | 282 | EmailListItem *temp = item; |
282 | temp = (EmailListItem *) item->nextSibling();//trybelow | 283 | temp = (EmailListItem *) item->nextSibling();//trybelow |
283 | if (temp == NULL) | 284 | if (temp == NULL) |
284 | temp = (EmailListItem *) item->itemAbove(); //try above | 285 | temp = (EmailListItem *) item->itemAbove(); //try above |
285 | 286 | ||
286 | emit removeItem(item, inbox); | 287 | emit removeItem(item, inbox); |
287 | 288 | ||
288 | item = temp; | 289 | item = temp; |
289 | if (item != NULL) { //more items in list | 290 | if (item != NULL) { //more items in list |
290 | mail = item->getMail(); | 291 | mail = item->getMail(); |
291 | updateView(); | 292 | updateView(); |
292 | updateButtons(); | 293 | updateButtons(); |
293 | } else close(); //no more items to see | 294 | } else close(); //no more items to see |
294 | } | 295 | } |
295 | 296 | ||
296 | void ReadMail::updateButtons() | 297 | void ReadMail::updateButtons() |
297 | { | 298 | { |
298 | EmailListItem *temp; | 299 | EmailListItem *temp; |
299 | 300 | ||
300 | temp = item; | 301 | temp = item; |
301 | if ((EmailListItem *) temp->nextSibling() == NULL) | 302 | if ((EmailListItem *) temp->nextSibling() == NULL) |
302 | nextButton->setEnabled(FALSE); | 303 | nextButton->setEnabled(FALSE); |
303 | else nextButton->setEnabled(TRUE); | 304 | else nextButton->setEnabled(TRUE); |
304 | 305 | ||
305 | temp = item; | 306 | temp = item; |
306 | if ((EmailListItem *) temp->itemAbove() == NULL) | 307 | if ((EmailListItem *) temp->itemAbove() == NULL) |
307 | previousButton->setEnabled(FALSE); | 308 | previousButton->setEnabled(FALSE); |
308 | else previousButton->setEnabled(TRUE); | 309 | else previousButton->setEnabled(TRUE); |
309 | } | 310 | } |
310 | 311 | ||
311 | void ReadMail::shiftText() | 312 | void ReadMail::shiftText() |
312 | { | 313 | { |
313 | plainTxt = ! plainTxt; | 314 | plainTxt = ! plainTxt; |
314 | updateView(); | 315 | updateView(); |
315 | } | 316 | } |
316 | 317 | ||
317 | void ReadMail::viewAttatchments() | 318 | void ReadMail::viewAttatchments() |
318 | { | 319 | { |
319 | viewAtt->update(mail, inbox); | 320 | viewAtt->update(mail, inbox); |
320 | viewAtt->showMaximized(); | 321 | viewAtt->showMaximized(); |
321 | } | 322 | } |
322 | 323 | ||
323 | void ReadMail::reply() | 324 | void ReadMail::reply() |
324 | { | 325 | { |
325 | emit replyRequested(*mail); | 326 | emit replyRequested(*mail); |
326 | } | 327 | } |
diff --git a/noncore/unsupported/mailit/smtpclient.cpp b/noncore/unsupported/mailit/smtpclient.cpp index 6699a90..b2e38e5 100644 --- a/noncore/unsupported/mailit/smtpclient.cpp +++ b/noncore/unsupported/mailit/smtpclient.cpp | |||
@@ -1,171 +1,171 @@ | |||
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 "smtpclient.h" | 20 | #include "smtpclient.h" |
21 | #include "emailhandler.h" | 21 | #include "emailhandler.h" |
22 | 22 | ||
23 | SmtpClient::SmtpClient() | 23 | SmtpClient::SmtpClient() |
24 | { | 24 | { |
25 | socket = new QSocket(this, "smtpClient"); | 25 | socket = new QSocket(this, "smtpClient"); |
26 | stream = new QTextStream(socket); | 26 | stream = new QTextStream(socket); |
27 | mailList.setAutoDelete(TRUE); | 27 | mailList.setAutoDelete(TRUE); |
28 | 28 | ||
29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 29 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 30 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 31 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
32 | 32 | ||
33 | sending = FALSE; | 33 | sending = FALSE; |
34 | } | 34 | } |
35 | 35 | ||
36 | SmtpClient::~SmtpClient() | 36 | SmtpClient::~SmtpClient() |
37 | { | 37 | { |
38 | delete socket; | 38 | delete socket; |
39 | delete stream; | 39 | delete stream; |
40 | } | 40 | } |
41 | 41 | ||
42 | void SmtpClient::newConnection(QString target, int port) | 42 | void SmtpClient::newConnection(QString target, int port) |
43 | { | 43 | { |
44 | if (sending) { | 44 | if (sending) { |
45 | qWarning("socket in use, connection refused"); | 45 | qWarning("socket in use, connection refused"); |
46 | return; | 46 | return; |
47 | } | 47 | } |
48 | 48 | ||
49 | status = Init; | 49 | status = Init; |
50 | sending = TRUE; | 50 | sending = TRUE; |
51 | socket->connectToHost(target, port); | 51 | socket->connectToHost(target, port); |
52 | 52 | ||
53 | emit updateStatus(tr("DNS lookup")); | 53 | emit updateStatus(tr("DNS lookup")); |
54 | } | 54 | } |
55 | 55 | ||
56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) | 56 | void SmtpClient::addMail(QString from, QString subject, QStringList to, QString body) |
57 | { | 57 | { |
58 | RawEmail *mail = new RawEmail; | 58 | RawEmail *mail = new RawEmail; |
59 | 59 | ||
60 | mail->from = from; | 60 | mail->from = from; |
61 | mail->subject = subject; | 61 | mail->subject = subject; |
62 | mail->to = to; | 62 | mail->to = to; |
63 | mail->body = body; | 63 | mail->body = body; |
64 | 64 | ||
65 | mailList.append(mail); | 65 | mailList.append(mail); |
66 | } | 66 | } |
67 | 67 | ||
68 | void SmtpClient::connectionEstablished() | 68 | void SmtpClient::connectionEstablished() |
69 | { | 69 | { |
70 | emit updateStatus(tr("Connection established")); | 70 | emit updateStatus(tr("Connection established")); |
71 | 71 | ||
72 | } | 72 | } |
73 | 73 | ||
74 | void SmtpClient::errorHandling(int status) | 74 | void SmtpClient::errorHandling(int status) |
75 | { | 75 | { |
76 | emit errorOccurred(status); | 76 | emit errorOccurred(status); |
77 | socket->close(); | 77 | socket->close(); |
78 | mailList.clear(); | 78 | mailList.clear(); |
79 | sending = FALSE; | 79 | sending = FALSE; |
80 | } | 80 | } |
81 | 81 | ||
82 | void SmtpClient::incomingData() | 82 | void SmtpClient::incomingData() |
83 | { | 83 | { |
84 | QString response; | 84 | QString response; |
85 | 85 | ||
86 | if (!socket->canReadLine()) | 86 | if (!socket->canReadLine()) |
87 | return; | 87 | return; |
88 | 88 | ||
89 | response = socket->readLine(); | 89 | response = socket->readLine(); |
90 | qDebug(response); | 90 | //qDebug(response); |
91 | 91 | ||
92 | switch(status) { | 92 | switch(status) { |
93 | case Init: { | 93 | case Init: { |
94 | if (response[0] == '2') { | 94 | if (response[0] == '2') { |
95 | status = From; | 95 | status = From; |
96 | mailPtr = mailList.first(); | 96 | mailPtr = mailList.first(); |
97 | *stream << "HELO there\r\n"; | 97 | *stream << "HELO there\r\n"; |
98 | qDebug("HELO"); | 98 | //qDebug("HELO"); |
99 | } else errorHandling(ErrUnknownResponse); | 99 | } else errorHandling(ErrUnknownResponse); |
100 | break; | 100 | break; |
101 | } | 101 | } |
102 | case From: { | 102 | case From: { |
103 | if (response[0] == '2') { | 103 | if (response[0] == '2') { |
104 | *stream << "MAIL FROM: <" << mailPtr->from << ">\r\n"; | 104 | *stream << "MAIL FROM: " << mailPtr->from << "\r\n"; |
105 | status = Recv; | 105 | status = Recv; |
106 | qDebug("MAIL FROM: "+mailPtr->from); | 106 | //qDebug("MAIL FROM: "+mailPtr->from); |
107 | } else errorHandling(ErrUnknownResponse); | 107 | } else errorHandling(ErrUnknownResponse); |
108 | break; | 108 | break; |
109 | } | 109 | } |
110 | case Recv: { | 110 | case Recv: { |
111 | if (response[0] == '2') { | 111 | if (response[0] == '2') { |
112 | it = mailPtr->to.begin(); | 112 | it = mailPtr->to.begin(); |
113 | if (it == NULL) | 113 | if (it == NULL) |
114 | errorHandling(ErrUnknownResponse); | 114 | errorHandling(ErrUnknownResponse); |
115 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 115 | *stream << "RCPT TO: " << *it << ">\r\n"; |
116 | qDebug("RCPT TO: "+ *it); | 116 | //qDebug("RCPT TO: "+ *it); |
117 | status = MRcv; | 117 | status = MRcv; |
118 | } else errorHandling(ErrUnknownResponse); | 118 | } else errorHandling(ErrUnknownResponse); |
119 | break; | 119 | break; |
120 | } | 120 | } |
121 | case MRcv: { | 121 | case MRcv: { |
122 | if (response[0] == '2') { | 122 | if (response[0] == '2') { |
123 | it++; | 123 | it++; |
124 | if ( it != mailPtr->to.end() ) { | 124 | if ( it != mailPtr->to.end() ) { |
125 | *stream << "RCPT TO: <" << *it << ">\r\n"; | 125 | *stream << "RCPT TO: <" << *it << ">\r\n"; |
126 | qDebug("RCPT TO: "+ *it); | 126 | //qDebug("RCPT TO: "+ *it); |
127 | break; | 127 | break; |
128 | } else { | 128 | } else { |
129 | status = Data; | 129 | status = Data; |
130 | } | 130 | } |
131 | } else errorHandling(ErrUnknownResponse); | 131 | } else errorHandling(ErrUnknownResponse); |
132 | } | 132 | } |
133 | case Data: { | 133 | case Data: { |
134 | if (response[0] == '2') { | 134 | if (response[0] == '2') { |
135 | *stream << "DATA\r\n"; | 135 | *stream << "DATA\r\n"; |
136 | status = Body; | 136 | status = Body; |
137 | qDebug("DATA"); | 137 | //qDebug("DATA"); |
138 | emit updateStatus(tr("Sending: ") + mailPtr->subject); | 138 | emit updateStatus(tr("Sending: ") + mailPtr->subject); |
139 | } else errorHandling(ErrUnknownResponse); | 139 | } else errorHandling(ErrUnknownResponse); |
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | case Body: { | 142 | case Body: { |
143 | if (response[0] == '3') { | 143 | if (response[0] == '3') { |
144 | *stream << mailPtr->body << "\r\n.\r\n"; | 144 | *stream << mailPtr->body << "\r\n.\r\n"; |
145 | mailPtr = mailList.next(); | 145 | mailPtr = mailList.next(); |
146 | if (mailPtr != NULL) { | 146 | if (mailPtr != NULL) { |
147 | status = From; | 147 | status = From; |
148 | } else { | 148 | } else { |
149 | status = Quit; | 149 | status = Quit; |
150 | } | 150 | } |
151 | qDebug("BODY"); | 151 | //qDebug("BODY"); |
152 | } else errorHandling(ErrUnknownResponse); | 152 | } else errorHandling(ErrUnknownResponse); |
153 | break; | 153 | break; |
154 | } | 154 | } |
155 | case Quit: { | 155 | case Quit: { |
156 | if (response[0] == '2') { | 156 | if (response[0] == '2') { |
157 | *stream << "QUIT\r\n"; | 157 | *stream << "QUIT\r\n"; |
158 | status = Done; | 158 | status = Done; |
159 | QString temp; | 159 | QString temp; |
160 | temp.setNum(mailList.count()); | 160 | temp.setNum(mailList.count()); |
161 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); | 161 | emit updateStatus(tr("Sent ") + temp + tr(" messages")); |
162 | emit mailSent(); | 162 | emit mailSent(); |
163 | mailList.clear(); | 163 | mailList.clear(); |
164 | sending = FALSE; | 164 | sending = FALSE; |
165 | socket->close(); | 165 | socket->close(); |
166 | qDebug("QUIT"); | 166 | //qDebug("QUIT"); |
167 | } else errorHandling(ErrUnknownResponse); | 167 | } else errorHandling(ErrUnknownResponse); |
168 | break; | 168 | break; |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |