author | llornkcor <llornkcor> | 2003-05-24 01:20:33 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-05-24 01:20:33 (UTC) |
commit | 62d2ddfb5cd77e2637cdf7fe16d76aac04975984 (patch) (unidiff) | |
tree | 2157d57bab2d6e491226f5bc8468a4c2527e1456 | |
parent | 0c4b5288ccd4bcd1668816a0c4e12ce0a76b4e6e (diff) | |
download | opie-62d2ddfb5cd77e2637cdf7fe16d76aac04975984.zip opie-62d2ddfb5cd77e2637cdf7fe16d76aac04975984.tar.gz opie-62d2ddfb5cd77e2637cdf7fe16d76aac04975984.tar.bz2 |
QString to const QString
26 files changed, 1210 insertions, 1208 deletions
diff --git a/noncore/net/mailit/addresslist.cpp b/noncore/net/mailit/addresslist.cpp index 7d60ebf..18d14bc 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(const QString &email, const 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(const 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(const 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(const 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(const 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(const 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(const 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;(*it).defaultEmail() | 124 | //OContact* oc;(*it).defaultEmail() |
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).fileAs()); | 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(const 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/addresslist.h b/noncore/net/mailit/addresslist.h index 99cef9a..b46d467 100644 --- a/noncore/net/mailit/addresslist.h +++ b/noncore/net/mailit/addresslist.h | |||
@@ -1,58 +1,58 @@ | |||
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 | #ifndef ADDRESSLIST_H | 20 | #ifndef ADDRESSLIST_H |
21 | #define ADDRESSLIST_H | 21 | #define ADDRESSLIST_H |
22 | 22 | ||
23 | #include <qobject.h> | 23 | #include <qobject.h> |
24 | #include <qlist.h> | 24 | #include <qlist.h> |
25 | 25 | ||
26 | struct Contact | 26 | struct Contact |
27 | { | 27 | { |
28 | QString email; | 28 | QString email; |
29 | QString name; | 29 | QString name; |
30 | }; | 30 | }; |
31 | 31 | ||
32 | class AddressList : public QObject | 32 | class AddressList : public QObject |
33 | { | 33 | { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | 35 | ||
36 | public: | 36 | public: |
37 | AddressList(); | 37 | AddressList(); |
38 | ~AddressList(); | 38 | ~AddressList(); |
39 | void addContact(QString email, QString name); | 39 | void addContact(const QString &email, const QString &name); |
40 | bool containsEmail(QString email); | 40 | bool containsEmail(const QString &email); |
41 | bool containsName(QString name); | 41 | bool containsName(const QString &name); |
42 | QString getNameByEmail(QString email); | 42 | QString getNameByEmail(const QString &email); |
43 | QString getEmailByName(QString name); | 43 | QString getEmailByName(const QString &name); |
44 | QList<Contact>* getContactList(); | 44 | QList<Contact>* getContactList(); |
45 | 45 | ||
46 | private: | 46 | private: |
47 | int getEmailRef(QString email); | 47 | int getEmailRef(const QString &email); |
48 | int getNameRef(QString name); | 48 | int getNameRef(const QString &name); |
49 | QString getRightString(QString in); | 49 | QString getRightString(const QString &in); |
50 | void read(); | 50 | void read(); |
51 | 51 | ||
52 | private: | 52 | private: |
53 | QList<Contact> addresses; | 53 | QList<Contact> addresses; |
54 | QString filename; | 54 | QString filename; |
55 | bool dirty; | 55 | bool dirty; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | #endif | 58 | #endif |
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp index b039cc4..2102ba7 100644 --- a/noncore/net/mailit/emailclient.cpp +++ b/noncore/net/mailit/emailclient.cpp | |||
@@ -320,203 +320,204 @@ void EmailClient::mailSent() | |||
320 | 320 | ||
321 | void EmailClient::getNewMail() { | 321 | void EmailClient::getNewMail() { |
322 | 322 | ||
323 | if (accountList.count() == 0) { | 323 | if (accountList.count() == 0) { |
324 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 324 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
325 | "You must create an account", "OK\n"); | 325 | "You must create an account", "OK\n"); |
326 | return; | 326 | return; |
327 | } | 327 | } |
328 | 328 | ||
329 | setMailAccount(); | 329 | setMailAccount(); |
330 | 330 | ||
331 | receiving = TRUE; | 331 | receiving = TRUE; |
332 | previewingMail = TRUE; | 332 | previewingMail = TRUE; |
333 | getMailButton->setEnabled(FALSE); | 333 | getMailButton->setEnabled(FALSE); |
334 | cancelButton->setEnabled(TRUE); | 334 | cancelButton->setEnabled(TRUE); |
335 | selectAccountMenu->setEnabled(FALSE); | 335 | selectAccountMenu->setEnabled(FALSE); |
336 | 336 | ||
337 | status1Label->setText(currentAccount->accountName + " headers"); | 337 | status1Label->setText(currentAccount->accountName + " headers"); |
338 | progressBar->reset(); | 338 | progressBar->reset(); |
339 | 339 | ||
340 | //get any previous mails not downloaded and add to queue | 340 | //get any previous mails not downloaded and add to queue |
341 | /*mailDownloadList.clear(); | 341 | /*mailDownloadList.clear(); |
342 | Email *mailPtr; | 342 | Email *mailPtr; |
343 | item = (EmailListItem *) inboxView->firstChild(); | 343 | item = (EmailListItem *) inboxView->firstChild(); |
344 | while (item != NULL) { | 344 | while (item != NULL) { |
345 | mailPtr = item->getMail(); | 345 | mailPtr = item->getMail(); |
346 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 346 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
347 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 347 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
348 | } | 348 | } |
349 | item = (EmailListItem *) item->nextSibling(); | 349 | item = (EmailListItem *) item->nextSibling(); |
350 | }*/ | 350 | }*/ |
351 | 351 | ||
352 | emailHandler->getMailHeaders(); | 352 | emailHandler->getMailHeaders(); |
353 | 353 | ||
354 | } | 354 | } |
355 | 355 | ||
356 | void EmailClient::getAllNewMail() | 356 | void EmailClient::getAllNewMail() |
357 | { | 357 | { |
358 | allAccounts = TRUE; | 358 | allAccounts = TRUE; |
359 | currentAccount = accountList.first(); | 359 | currentAccount = accountList.first(); |
360 | getNewMail(); | 360 | getNewMail(); |
361 | } | 361 | } |
362 | 362 | ||
363 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 363 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
364 | { | 364 | { |
365 | Enclosure *ePtr; | 365 | Enclosure *ePtr; |
366 | Email newMail; | 366 | Email newMail; |
367 | int thisMailId; | 367 | int thisMailId; |
368 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 368 | emailHandler->parse( mail.rawMail, lineShift, &newMail); |
369 | mailconf->setGroup(newMail.id); | 369 | mailconf->setGroup(newMail.id); |
370 | 370 | ||
371 | if (fromDisk) | 371 | if (fromDisk) |
372 | { | 372 | { |
373 | 373 | ||
374 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 374 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
375 | newMail.size = mailconf->readNumEntry("size"); | 375 | newMail.size = mailconf->readNumEntry("size"); |
376 | newMail.serverId = mailconf->readNumEntry("serverid"); | 376 | newMail.serverId = mailconf->readNumEntry("serverid"); |
377 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 377 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
378 | } | 378 | } |
379 | else | 379 | else |
380 | { //mail arrived from server | 380 | { //mail arrived from server |
381 | 381 | ||
382 | newMail.serverId = mail.serverId; | 382 | newMail.serverId = mail.serverId; |
383 | newMail.size = mail.size; | 383 | newMail.size = mail.size; |
384 | newMail.downloaded = mail.downloaded; | 384 | newMail.downloaded = mail.downloaded; |
385 | 385 | ||
386 | newMail.fromAccountId = emailHandler->getAccount()->id; | 386 | newMail.fromAccountId = emailHandler->getAccount()->id; |
387 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 387 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
388 | } | 388 | } |
389 | 389 | ||
390 | //add if read or not | 390 | //add if read or not |
391 | newMail.read = mailconf->readBoolEntry("mailread"); | 391 | newMail.read = mailconf->readBoolEntry("mailread"); |
392 | 392 | ||
393 | //check if new mail | 393 | //check if new mail |
394 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 394 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
395 | thisMailId = mailIdCount; | 395 | thisMailId = mailIdCount; |
396 | mailIdCount++; | 396 | mailIdCount++; |
397 | 397 | ||
398 | //set server count, so that if the user aborts, the new | 398 | //set server count, so that if the user aborts, the new |
399 | //header is not reloaded | 399 | //header is not reloaded |
400 | if ((currentAccount)&&(currentAccount->synchronize)) | 400 | if ((currentAccount)&&(currentAccount->synchronize)) |
401 | currentAccount->lastServerMailCount++; | 401 | currentAccount->lastServerMailCount++; |
402 | 402 | ||
403 | mailconf->writeEntry("internalmailid", thisMailId); | 403 | mailconf->writeEntry("internalmailid", thisMailId); |
404 | mailconf->writeEntry("downloaded", newMail.downloaded); | 404 | mailconf->writeEntry("downloaded", newMail.downloaded); |
405 | mailconf->writeEntry("size", (int) newMail.size); | 405 | mailconf->writeEntry("size", (int) newMail.size); |
406 | mailconf->writeEntry("serverid", newMail.serverId); | 406 | mailconf->writeEntry("serverid", newMail.serverId); |
407 | 407 | ||
408 | //addressList->addContact(newMail.fromMail, newMail.from); | 408 | //addressList->addContact(newMail.fromMail, newMail.from); |
409 | } | 409 | } |
410 | 410 | ||
411 | mailconf->writeEntry("downloaded", newMail.downloaded); | 411 | mailconf->writeEntry("downloaded", newMail.downloaded); |
412 | 412 | ||
413 | QString stringMailId; | 413 | QString stringMailId; |
414 | stringMailId.setNum(thisMailId); | 414 | stringMailId.setNum(thisMailId); |
415 | //see if any attatchments needs to be stored | 415 | //see if any attatchments needs to be stored |
416 | 416 | ||
417 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { | 417 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { |
418 | QString stringId; | 418 | QString stringId; |
419 | stringId.setNum(ePtr->id); | 419 | stringId.setNum(ePtr->id); |
420 | 420 | ||
421 | int id = mailconf->readNumEntry("enclosureid_" + stringId); | 421 | int id = mailconf->readNumEntry("enclosureid_" + stringId); |
422 | if (id != ePtr->id) { //new entry | 422 | if (id != ePtr->id) { //new entry |
423 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); | 423 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); |
424 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); | 424 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); |
425 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); | 425 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); |
426 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); | 426 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); |
427 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 427 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
428 | mailconf->writeEntry("installed_" + stringId, FALSE); | 428 | mailconf->writeEntry("installed_" + stringId, FALSE); |
429 | 429 | ||
430 | ePtr->name = stringMailId + "_" + stringId; | 430 | ePtr->name = stringMailId + "_" + stringId; |
431 | ePtr->path = getPath(TRUE); | 431 | ePtr->path = getPath(TRUE); |
432 | if (emailHandler->getEnclosure(ePtr)) { //file saved | 432 | if (emailHandler->getEnclosure(ePtr)) { //file saved |
433 | ePtr->saved = TRUE; | 433 | ePtr->saved = TRUE; |
434 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 434 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
435 | mailconf->writeEntry("filename_" + stringId, ePtr->name); | 435 | mailconf->writeEntry("filename_" + stringId, ePtr->name); |
436 | mailconf->writeEntry("path_" + stringId, ePtr->path); | 436 | mailconf->writeEntry("path_" + stringId, ePtr->path); |
437 | } else { | 437 | } else { |
438 | ePtr->saved = FALSE; | 438 | ePtr->saved = FALSE; |
439 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 439 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
440 | } | 440 | } |
441 | } else { | 441 | } else { |
442 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); | 442 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); |
443 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); | 443 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); |
444 | if (ePtr->saved) { | 444 | if (ePtr->saved) { |
445 | ePtr->name = mailconf->readEntry("filename_" + stringId); | 445 | ePtr->name = mailconf->readEntry("filename_" + stringId); |
446 | ePtr->path = mailconf->readEntry("path_" + stringId); | 446 | ePtr->path = mailconf->readEntry("path_" + stringId); |
447 | } | 447 | } |
448 | } | 448 | } |
449 | } | 449 | } |
450 | 450 | ||
451 | bool found=false; | 451 | bool found=false; |
452 | 452 | ||
453 | if (!fromDisk) | 453 | if (!fromDisk) |
454 | { | 454 | { |
455 | 455 | ||
456 | Email *mailPtr; | 456 | Email *mailPtr; |
457 | item = (EmailListItem *) inboxView->firstChild(); | 457 | item = (EmailListItem *) inboxView->firstChild(); |
458 | while ((item != NULL)&&(!found)) | 458 | while ((item != NULL)&&(!found)) |
459 | { | 459 | { |
460 | mailPtr = item->getMail(); | 460 | mailPtr = item->getMail(); |
461 | if (mailPtr->id == newMail.id) { | 461 | if (mailPtr->id == newMail.id) { |
462 | item->setMail(newMail); | 462 | item->setMail(newMail); |
463 | emit mailUpdated(item->getMail()); | 463 | emit mailUpdated(item->getMail()); |
464 | found = true; | 464 | found = true; |
465 | } | 465 | } |
466 | item = (EmailListItem *) item->nextSibling(); | 466 | item = (EmailListItem *) item->nextSibling(); |
467 | } | 467 | } |
468 | } | 468 | } |
469 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); | 469 | if ((!found)||(fromDisk)) { |
470 | 470 | item = new EmailListItem(inboxView, newMail, TRUE); | |
471 | if (item->getMail()->files.count()>0) | 471 | } |
472 | { | 472 | if (item->getMail()->files.count()>0) |
473 | item->setPixmap(0, Resource::loadPixmap("mailit/attach")); | 473 | { |
474 | } | 474 | item->setPixmap(0, Resource::loadPixmap("mailit/attach")); |
475 | } | ||
475 | /*if (!newMail.downloaded) | 476 | /*if (!newMail.downloaded) |
476 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ | 477 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ |
477 | 478 | ||
478 | mailboxView->setCurrentTab(0); | 479 | mailboxView->setCurrentTab(0); |
479 | 480 | ||
480 | } | 481 | } |
481 | 482 | ||
482 | void EmailClient::allMailArrived(int count) | 483 | void EmailClient::allMailArrived(int count) |
483 | { | 484 | { |
484 | // not previewing means all mailtransfer has been done | 485 | // not previewing means all mailtransfer has been done |
485 | /*if (!previewingMail) {*/ | 486 | /*if (!previewingMail) {*/ |
486 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 487 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
487 | emit newCaption("Mailit - " + currentAccount->accountName); | 488 | emit newCaption("Mailit - " + currentAccount->accountName); |
488 | getNewMail(); | 489 | getNewMail(); |
489 | return; | 490 | return; |
490 | } else { | 491 | } else { |
491 | allAccounts = FALSE; | 492 | allAccounts = FALSE; |
492 | receiving = FALSE; | 493 | receiving = FALSE; |
493 | getMailButton->setEnabled(TRUE); | 494 | getMailButton->setEnabled(TRUE); |
494 | cancelButton->setEnabled(FALSE); | 495 | cancelButton->setEnabled(FALSE); |
495 | selectAccountMenu->setEnabled(TRUE); | 496 | selectAccountMenu->setEnabled(TRUE); |
496 | status1Label->setText("Idle"); | 497 | status1Label->setText("Idle"); |
497 | 498 | ||
498 | progressBar->reset(); | 499 | progressBar->reset(); |
499 | return; | 500 | return; |
500 | } | 501 | } |
501 | //} | 502 | //} |
502 | 503 | ||
503 | // all headers downloaded from server, start downloading remaining mails | 504 | // all headers downloaded from server, start downloading remaining mails |
504 | previewingMail = FALSE; | 505 | previewingMail = FALSE; |
505 | status1Label->setText(currentAccount->accountName); | 506 | status1Label->setText(currentAccount->accountName); |
506 | progressBar->reset(); | 507 | progressBar->reset(); |
507 | 508 | ||
508 | 509 | ||
509 | mailboxView->setCurrentTab(0); | 510 | mailboxView->setCurrentTab(0); |
510 | } | 511 | } |
511 | 512 | ||
512 | 513 | ||
513 | void EmailClient::moveMailFront(Email *mailPtr) | 514 | void EmailClient::moveMailFront(Email *mailPtr) |
514 | { | 515 | { |
515 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 516 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
516 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 517 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
517 | } | 518 | } |
518 | } | 519 | } |
519 | 520 | ||
520 | void EmailClient::smtpError(int code) | 521 | void EmailClient::smtpError(int code) |
521 | { | 522 | { |
522 | QString temp; | 523 | QString temp; |
@@ -597,167 +598,167 @@ void EmailClient::readMail() | |||
597 | Email mail; | 598 | Email mail; |
598 | int start, stop; | 599 | int start, stop; |
599 | QString s, del; | 600 | QString s, del; |
600 | 601 | ||
601 | QFile f(getPath(FALSE) + "inbox.txt"); | 602 | QFile f(getPath(FALSE) + "inbox.txt"); |
602 | 603 | ||
603 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 604 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
604 | QTextStream t( &f ); // use a text stream | 605 | QTextStream t( &f ); // use a text stream |
605 | s = t.read(); | 606 | s = t.read(); |
606 | f.close(); | 607 | f.close(); |
607 | 608 | ||
608 | start = 0; | 609 | start = 0; |
609 | del = "\n.\n"; | 610 | del = "\n.\n"; |
610 | while ((uint) start < s.length()) { | 611 | while ((uint) start < s.length()) { |
611 | stop = s.find(del, start); | 612 | stop = s.find(del, start); |
612 | if (stop == -1) | 613 | if (stop == -1) |
613 | stop = s.length() - del.length(); | 614 | stop = s.length() - del.length(); |
614 | 615 | ||
615 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 616 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
616 | start = stop + del.length(); | 617 | start = stop + del.length(); |
617 | mailArrived(mail, TRUE); | 618 | mailArrived(mail, TRUE); |
618 | } | 619 | } |
619 | } | 620 | } |
620 | 621 | ||
621 | QFile fo(getPath(FALSE) + "outbox.txt"); | 622 | QFile fo(getPath(FALSE) + "outbox.txt"); |
622 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | 623 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully |
623 | QTextStream t( &fo ); // use a text stream | 624 | QTextStream t( &fo ); // use a text stream |
624 | s = t.read(); | 625 | s = t.read(); |
625 | fo.close(); | 626 | fo.close(); |
626 | 627 | ||
627 | start = 0; | 628 | start = 0; |
628 | del = "\n.\n"; | 629 | del = "\n.\n"; |
629 | while ((uint) start < s.length()) { | 630 | while ((uint) start < s.length()) { |
630 | stop = s.find(del, start); | 631 | stop = s.find(del, start); |
631 | if (stop == -1) | 632 | if (stop == -1) |
632 | stop = s.length() - del.length(); | 633 | stop = s.length() - del.length(); |
633 | 634 | ||
634 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 635 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
635 | start = stop + del.length(); | 636 | start = stop + del.length(); |
636 | emailHandler->parse(mail.rawMail, lineShift, &mail); | 637 | emailHandler->parse(mail.rawMail, lineShift, &mail); |
637 | mail.sent = false; | 638 | mail.sent = false; |
638 | mail.received = false; | 639 | mail.received = false; |
639 | enqueMail(mail); | 640 | enqueMail(mail); |
640 | 641 | ||
641 | } | 642 | } |
642 | } | 643 | } |
643 | } | 644 | } |
644 | 645 | ||
645 | void EmailClient::saveMail(QString fileName, QListView *view) | 646 | void EmailClient::saveMail(const QString &fileName, QListView *view) |
646 | { | 647 | { |
647 | QFile f(fileName); | 648 | QFile f(fileName); |
648 | Email *mail; | 649 | Email *mail; |
649 | 650 | ||
650 | if (! f.open(IO_WriteOnly) ) { | 651 | if (! f.open(IO_WriteOnly) ) { |
651 | qWarning("could not open file"); | 652 | qWarning("could not open file"); |
652 | return; | 653 | return; |
653 | } | 654 | } |
654 | item = (EmailListItem *) view->firstChild(); | 655 | item = (EmailListItem *) view->firstChild(); |
655 | QTextStream t(&f); | 656 | QTextStream t(&f); |
656 | while (item != NULL) { | 657 | while (item != NULL) { |
657 | mail = item->getMail(); | 658 | mail = item->getMail(); |
658 | t << mail->rawMail; | 659 | t << mail->rawMail; |
659 | 660 | ||
660 | mailconf->setGroup(mail->id); | 661 | mailconf->setGroup(mail->id); |
661 | mailconf->writeEntry("mailread", mail->read); | 662 | mailconf->writeEntry("mailread", mail->read); |
662 | 663 | ||
663 | item = (EmailListItem *) item->nextSibling(); | 664 | item = (EmailListItem *) item->nextSibling(); |
664 | } | 665 | } |
665 | f.close(); | 666 | f.close(); |
666 | } | 667 | } |
667 | 668 | ||
668 | //paths for mailit, is settings, inbox, enclosures | 669 | //paths for mailit, is settings, inbox, enclosures |
669 | QString EmailClient::getPath(bool enclosurePath) | 670 | QString EmailClient::getPath(bool enclosurePath) |
670 | { | 671 | { |
671 | QString basePath = "qtmail"; | 672 | QString basePath = "qtmail"; |
672 | QString enclosures = "enclosures"; | 673 | QString enclosures = "enclosures"; |
673 | 674 | ||
674 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | 675 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); |
675 | if ( !dir.exists() ) | 676 | if ( !dir.exists() ) |
676 | dir.mkdir( dir.path() ); | 677 | dir.mkdir( dir.path() ); |
677 | 678 | ||
678 | if (enclosurePath) { | 679 | if (enclosurePath) { |
679 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | 680 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); |
680 | 681 | ||
681 | if ( !dir.exists() ) | 682 | if ( !dir.exists() ) |
682 | dir.mkdir( dir.path() ); | 683 | dir.mkdir( dir.path() ); |
683 | 684 | ||
684 | return (dir.path() + "/"); | 685 | return (dir.path() + "/"); |
685 | 686 | ||
686 | } | 687 | } |
687 | return (dir.path() + "/"); | 688 | return (dir.path() + "/"); |
688 | } | 689 | } |
689 | 690 | ||
690 | void EmailClient::readSettings() | 691 | void EmailClient::readSettings() |
691 | { | 692 | { |
692 | int y,acc_count; | 693 | int y,acc_count; |
693 | 694 | ||
694 | mailconf->setGroup("mailitglobal"); | 695 | mailconf->setGroup("mailitglobal"); |
695 | acc_count=mailconf->readNumEntry("Accounts",0); | 696 | acc_count=mailconf->readNumEntry("Accounts",0); |
696 | 697 | ||
697 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) | 698 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) |
698 | { | 699 | { |
699 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... | 700 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... |
700 | account.accountName = mailconf->readEntry("AccName",""); | 701 | account.accountName = mailconf->readEntry("AccName",""); |
701 | account.name = mailconf->readEntry("UserName",""); | 702 | account.name = mailconf->readEntry("UserName",""); |
702 | account.emailAddress = mailconf->readEntry("Email",""); | 703 | account.emailAddress = mailconf->readEntry("Email",""); |
703 | account.popUserName = mailconf->readEntry("POPUser",""); | 704 | account.popUserName = mailconf->readEntry("POPUser",""); |
704 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); | 705 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); |
705 | account.popServer = mailconf->readEntry("POPServer",""); | 706 | account.popServer = mailconf->readEntry("POPServer",""); |
706 | account.smtpServer = mailconf->readEntry("SMTPServer",""); | 707 | account.smtpServer = mailconf->readEntry("SMTPServer",""); |
707 | account.id = mailconf->readNumEntry("AccountId",0); | 708 | account.id = mailconf->readNumEntry("AccountId",0); |
708 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); | 709 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); |
709 | account.lastServerMailCount = 0; | 710 | account.lastServerMailCount = 0; |
710 | account.synchronize = FALSE; | 711 | account.synchronize = FALSE; |
711 | 712 | ||
712 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); | 713 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); |
713 | if (account.synchronize) | 714 | if (account.synchronize) |
714 | { | 715 | { |
715 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); | 716 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); |
716 | } | 717 | } |
717 | 718 | ||
718 | accountList.append(&account); | 719 | accountList.append(&account); |
719 | } | 720 | } |
720 | 721 | ||
721 | mailconf->setGroup("mailitglobal"); | 722 | mailconf->setGroup("mailitglobal"); |
722 | 723 | ||
723 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) | 724 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) |
724 | { | 725 | { |
725 | mailIdCount = y; | 726 | mailIdCount = y; |
726 | } | 727 | } |
727 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) | 728 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) |
728 | { | 729 | { |
729 | accountIdCount = y; | 730 | accountIdCount = y; |
730 | } | 731 | } |
731 | } | 732 | } |
732 | 733 | ||
733 | void EmailClient::saveSettings() | 734 | void EmailClient::saveSettings() |
734 | { | 735 | { |
735 | int acc_count=0; | 736 | int acc_count=0; |
736 | MailAccount *accountPtr; | 737 | MailAccount *accountPtr; |
737 | 738 | ||
738 | 739 | ||
739 | if (!mailconf) | 740 | if (!mailconf) |
740 | { | 741 | { |
741 | qWarning("could not save settings"); | 742 | qWarning("could not save settings"); |
742 | return; | 743 | return; |
743 | } | 744 | } |
744 | 745 | ||
745 | for (accountPtr = accountList.first(); accountPtr != 0; | 746 | for (accountPtr = accountList.first(); accountPtr != 0; |
746 | accountPtr = accountList.next()) | 747 | accountPtr = accountList.next()) |
747 | { | 748 | { |
748 | mailconf->setGroup("Account_"+QString::number(++acc_count)); | 749 | mailconf->setGroup("Account_"+QString::number(++acc_count)); |
749 | mailconf->writeEntry("AccName",accountPtr->accountName ); | 750 | mailconf->writeEntry("AccName",accountPtr->accountName ); |
750 | mailconf->writeEntry("UserName",accountPtr->name); | 751 | mailconf->writeEntry("UserName",accountPtr->name); |
751 | mailconf->writeEntry("Email",accountPtr->emailAddress); | 752 | mailconf->writeEntry("Email",accountPtr->emailAddress); |
752 | mailconf->writeEntry("POPUser",accountPtr->popUserName); | 753 | mailconf->writeEntry("POPUser",accountPtr->popUserName); |
753 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); | 754 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); |
754 | mailconf->writeEntry("POPServer",accountPtr->popServer); | 755 | mailconf->writeEntry("POPServer",accountPtr->popServer); |
755 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); | 756 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); |
756 | mailconf->writeEntry("AccountId",accountPtr->id); | 757 | mailconf->writeEntry("AccountId",accountPtr->id); |
757 | if (accountPtr->synchronize) | 758 | if (accountPtr->synchronize) |
758 | { | 759 | { |
759 | mailconf->writeEntry("Synchronize","Yes"); | 760 | mailconf->writeEntry("Synchronize","Yes"); |
760 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); | 761 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); |
761 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); | 762 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); |
762 | } | 763 | } |
763 | else | 764 | else |
@@ -870,167 +871,167 @@ void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | |||
870 | //if mail is in queue for download, remove it from | 871 | //if mail is in queue for download, remove it from |
871 | //queue if possible | 872 | //queue if possible |
872 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | 873 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { |
873 | if ( !mPtr->downloaded ) | 874 | if ( !mPtr->downloaded ) |
874 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | 875 | mailDownloadList.remove(mPtr->serverId, mPtr->size); |
875 | } | 876 | } |
876 | 877 | ||
877 | mailconf->setGroup(mPtr->id); | 878 | mailconf->setGroup(mPtr->id); |
878 | mailconf->clearGroup(); | 879 | mailconf->clearGroup(); |
879 | 880 | ||
880 | //delete any temporary attatchemnts storing | 881 | //delete any temporary attatchemnts storing |
881 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | 882 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { |
882 | if (ePtr->saved) { | 883 | if (ePtr->saved) { |
883 | QFile::remove( (ePtr->path + ePtr->name) ); | 884 | QFile::remove( (ePtr->path + ePtr->name) ); |
884 | } | 885 | } |
885 | } | 886 | } |
886 | inboxView->takeItem(mailItem); | 887 | inboxView->takeItem(mailItem); |
887 | } | 888 | } |
888 | else | 889 | else |
889 | { | 890 | { |
890 | outboxView->takeItem(mailItem); | 891 | outboxView->takeItem(mailItem); |
891 | } | 892 | } |
892 | } | 893 | } |
893 | 894 | ||
894 | void EmailClient::setMailSize(int size) | 895 | void EmailClient::setMailSize(int size) |
895 | { | 896 | { |
896 | progressBar->reset(); | 897 | progressBar->reset(); |
897 | progressBar->setTotalSteps(size); | 898 | progressBar->setTotalSteps(size); |
898 | } | 899 | } |
899 | 900 | ||
900 | void EmailClient::setTotalSize(int size) | 901 | void EmailClient::setTotalSize(int size) |
901 | { | 902 | { |
902 | 903 | ||
903 | } | 904 | } |
904 | 905 | ||
905 | void EmailClient::setDownloadedSize(int size) | 906 | void EmailClient::setDownloadedSize(int size) |
906 | { | 907 | { |
907 | int total = progressBar->totalSteps(); | 908 | int total = progressBar->totalSteps(); |
908 | 909 | ||
909 | if (size < total) { | 910 | if (size < total) { |
910 | progressBar->setProgress(size); | 911 | progressBar->setProgress(size); |
911 | } else { | 912 | } else { |
912 | progressBar->setProgress(total); | 913 | progressBar->setProgress(total); |
913 | } | 914 | } |
914 | } | 915 | } |
915 | 916 | ||
916 | void EmailClient::deleteItem() | 917 | void EmailClient::deleteItem() |
917 | { | 918 | { |
918 | bool inbox=mailboxView->currentTab()==0; | 919 | bool inbox=mailboxView->currentTab()==0; |
919 | QListView* box; | 920 | QListView* box; |
920 | 921 | ||
921 | EmailListItem* eli; | 922 | EmailListItem* eli; |
922 | int pos; | 923 | int pos; |
923 | 924 | ||
924 | inbox ? box=inboxView : box=outboxView; | 925 | inbox ? box=inboxView : box=outboxView; |
925 | 926 | ||
926 | eli=(EmailListItem*)box->selectedItem(); | 927 | eli=(EmailListItem*)box->selectedItem(); |
927 | 928 | ||
928 | if (eli) | 929 | if (eli) |
929 | { | 930 | { |
930 | box->setSelected(eli->itemBelow(),true);//select the previous item | 931 | box->setSelected(eli->itemBelow(),true); //select the previous item |
931 | 932 | ||
932 | deleteMail(eli,(bool&)inbox); //remove mail entry | 933 | deleteMail(eli,(bool&)inbox); //remove mail entry |
933 | } | 934 | } |
934 | } | 935 | } |
935 | 936 | ||
936 | void EmailClient::inboxItemPressed() | 937 | void EmailClient::inboxItemPressed() |
937 | { | 938 | { |
938 | //timerID=startTimer(500); | 939 | // timerID=startTimer(500); |
939 | } | 940 | } |
940 | 941 | ||
941 | void EmailClient::inboxItemReleased() | 942 | void EmailClient::inboxItemReleased() |
942 | { | 943 | { |
943 | //killTimer(timerID); | 944 | // killTimer(timerID); |
944 | } | 945 | } |
945 | 946 | ||
946 | /*void EmailClient::timerEvent(QTimerEvent *e) | 947 | /*void EmailClient::timerEvent(QTimerEvent *e) |
947 | { | 948 | { |
948 | /*killTimer(timerID); | 949 | /*killTimer(timerID); |
949 | 950 | ||
950 | 951 | ||
951 | QPopupMenu *action = new QPopupMenu(this); | 952 | QPopupMenu *action = new QPopupMenu(this); |
952 | 953 | ||
953 | int reply=0; | 954 | int reply=0; |
954 | 955 | ||
955 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); | 956 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); |
956 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); | 957 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); |
957 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); | 958 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); |
958 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); | 959 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); |
959 | 960 | ||
960 | action->exec(QCursor::pos()); | 961 | action->exec(QCursor::pos()); |
961 | 962 | ||
962 | if (action) delete action; | 963 | if (action) delete action; |
963 | 964 | ||
964 | }*/ | 965 | }*/ |
965 | 966 | ||
966 | Email* EmailClient::getCurrentMail() | 967 | Email* EmailClient::getCurrentMail() |
967 | { | 968 | { |
968 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); | 969 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); |
969 | if (eli!=NULL) | 970 | if (eli!=NULL) |
970 | return eli->getMail(); | 971 | return eli->getMail(); |
971 | else | 972 | else |
972 | return NULL; | 973 | return NULL; |
973 | } | 974 | } |
974 | 975 | ||
975 | void EmailClient::download(Email* mail) | 976 | void EmailClient::download(Email* mail) |
976 | { | 977 | { |
977 | MailAccount* acc=0; | 978 | MailAccount* acc=0; |
978 | 979 | ||
979 | tempMailDownloadList.clear(); | 980 | tempMailDownloadList.clear(); |
980 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); | 981 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); |
981 | 982 | ||
982 | acc=accountList.at(mail->fromAccountId-1); | 983 | acc=accountList.at(mail->fromAccountId-1); |
983 | if (acc) | 984 | if (acc) |
984 | { | 985 | { |
985 | emailHandler->setAccount(*acc); | 986 | emailHandler->setAccount(*acc); |
986 | emailHandler->getMailByList(&tempMailDownloadList); | 987 | emailHandler->getMailByList(&tempMailDownloadList); |
987 | } | 988 | } |
988 | else | 989 | else |
989 | QMessageBox::warning(qApp->activeWindow(), | 990 | QMessageBox::warning(qApp->activeWindow(), |
990 | tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); | 991 | tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); |
991 | } | 992 | } |
992 | 993 | ||
993 | void EmailClient::receive(const QCString& msg, const QByteArray& data) | 994 | void EmailClient::receive(const QCString& msg, const QByteArray& data) |
994 | { | 995 | { |
995 | /*if (msg=="getMail()") | 996 | /*if (msg=="getMail()") |
996 | { | 997 | { |
997 | /*QDialog qd(qApp->activeWindow(),"Getting mail",true); | 998 | /*QDialog qd(qApp->activeWindow(),"Getting mail",true); |
998 | QVBoxLayout *vbProg = new QVBoxLayout( &qd ); | 999 | QVBoxLayout *vbProg = new QVBoxLayout( &qd ); |
999 | 1000 | ||
1000 | initStatusBar(&qd); | 1001 | initStatusBar(&qd); |
1001 | 1002 | ||
1002 | if (statusBar==0) | 1003 | if (statusBar==0) |
1003 | { | 1004 | { |
1004 | qDebug("No Bar ..."); | 1005 | qDebug("No Bar ..."); |
1005 | //statusBar=new ProgressBar(&qd); | 1006 | //statusBar=new ProgressBar(&qd); |
1006 | } | 1007 | } |
1007 | statusBar->show(); | 1008 | statusBar->show(); |
1008 | vbProg->addWidget(statusBar); | 1009 | vbProg->addWidget(statusBar); |
1009 | qd.showMaximized(); | 1010 | qd.showMaximized(); |
1010 | qd.show(); | 1011 | qd.show(); |
1011 | emit getAllNewMail(); | 1012 | emit getAllNewMail(); |
1012 | //qd.exec(); | 1013 | //qd.exec(); |
1013 | } | 1014 | } |
1014 | else if (msg=="compose()") | 1015 | else if (msg=="compose()") |
1015 | { | 1016 | { |
1016 | QDialog qd(qApp->activeWindow(),"Getting mail",true); | 1017 | QDialog qd(qApp->activeWindow(),"Getting mail",true); |
1017 | 1018 | ||
1018 | WriteMail wm(&qd,"write new mail"); | 1019 | WriteMail wm(&qd,"write new mail"); |
1019 | QVBoxLayout vbProg( &qd ); | 1020 | QVBoxLayout vbProg( &qd ); |
1020 | 1021 | ||
1021 | wm.showMaximized(); | 1022 | wm.showMaximized(); |
1022 | vbProg.addWidget(&wm); | 1023 | vbProg.addWidget(&wm); |
1023 | 1024 | ||
1024 | qd.showMaximized(); | 1025 | qd.showMaximized(); |
1025 | 1026 | ||
1026 | emit composeRequested(); | 1027 | emit composeRequested(); |
1027 | qd.exec(); | 1028 | qd.exec(); |
1028 | 1029 | ||
1029 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | 1030 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); |
1030 | } | 1031 | } |
1031 | 1032 | ||
1032 | else if (msg=="dialog()") | 1033 | else if (msg=="dialog()") |
1033 | { | 1034 | { |
1034 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | 1035 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); |
1035 | }*/ | 1036 | }*/ |
1036 | } | 1037 | } |
diff --git a/noncore/net/mailit/emailclient.h b/noncore/net/mailit/emailclient.h index 994fec5..c98cfce 100644 --- a/noncore/net/mailit/emailclient.h +++ b/noncore/net/mailit/emailclient.h | |||
@@ -61,97 +61,97 @@ private: | |||
61 | MailAccount* dupl(MailAccount *in); | 61 | MailAccount* dupl(MailAccount *in); |
62 | MailAccount *ac; | 62 | MailAccount *ac; |
63 | }; | 63 | }; |
64 | 64 | ||
65 | //class EmailClient : public EmailClientBase | 65 | //class EmailClient : public EmailClientBase |
66 | class EmailClient : public QMainWindow | 66 | class EmailClient : public QMainWindow |
67 | { | 67 | { |
68 | Q_OBJECT | 68 | Q_OBJECT |
69 | 69 | ||
70 | public: | 70 | public: |
71 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); | 71 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); |
72 | ~EmailClient(); | 72 | ~EmailClient(); |
73 | AddressList* getAdrListRef(); | 73 | AddressList* getAdrListRef(); |
74 | 74 | ||
75 | protected: | 75 | protected: |
76 | //void timerEvent(QTimerEvent*); | 76 | //void timerEvent(QTimerEvent*); |
77 | 77 | ||
78 | signals: | 78 | signals: |
79 | void composeRequested(); | 79 | void composeRequested(); |
80 | void viewEmail(QListView *, Email *); | 80 | void viewEmail(QListView *, Email *); |
81 | void mailUpdated(Email *); | 81 | void mailUpdated(Email *); |
82 | void newCaption(const QString &); | 82 | void newCaption(const QString &); |
83 | void replyRequested(Email&, bool&); | 83 | void replyRequested(Email&, bool&); |
84 | void forwardRequested(Email&); | 84 | void forwardRequested(Email&); |
85 | void removeItem(EmailListItem*, bool&); | 85 | void removeItem(EmailListItem*, bool&); |
86 | /*void reply(Email&); | 86 | /*void reply(Email&); |
87 | void replyAll(Email&); | 87 | void replyAll(Email&); |
88 | void remove(Email&); | 88 | void remove(Email&); |
89 | void forward(Email&);*/ | 89 | void forward(Email&);*/ |
90 | 90 | ||
91 | public slots: | 91 | public slots: |
92 | void compose(); | 92 | void compose(); |
93 | void cancel(); | 93 | void cancel(); |
94 | void enqueMail(const Email &mail); | 94 | void enqueMail(const Email &mail); |
95 | void setMailAccount(); | 95 | void setMailAccount(); |
96 | void sendQuedMail(); | 96 | void sendQuedMail(); |
97 | void mailSent(); | 97 | void mailSent(); |
98 | void deleteItem(); | 98 | void deleteItem(); |
99 | void getNewMail(); | 99 | void getNewMail(); |
100 | void getAllNewMail(); | 100 | void getAllNewMail(); |
101 | void smtpError(int code); | 101 | void smtpError(int code); |
102 | void popError(int code); | 102 | void popError(int code); |
103 | void inboxItemSelected(); | 103 | void inboxItemSelected(); |
104 | void outboxItemSelected(); | 104 | void outboxItemSelected(); |
105 | void inboxItemPressed(); | 105 | void inboxItemPressed(); |
106 | void inboxItemReleased(); | 106 | void inboxItemReleased(); |
107 | void mailArrived(const Email &mail, bool fromDisk); | 107 | void mailArrived(const Email &mail, bool fromDisk); |
108 | void allMailArrived(int); | 108 | void allMailArrived(int); |
109 | void saveMail(QString fileName, QListView *view); | 109 | void saveMail(const QString &fileName, QListView *view); |
110 | void selectAccount(int); | 110 | void selectAccount(int); |
111 | void editAccount(int); | 111 | void editAccount(int); |
112 | void updateAccounts(); | 112 | void updateAccounts(); |
113 | void deleteAccount(int); | 113 | void deleteAccount(int); |
114 | void deleteMail(EmailListItem *mailItem, bool &inbox); | 114 | void deleteMail(EmailListItem *mailItem, bool &inbox); |
115 | void setTotalSize(int); | 115 | void setTotalSize(int); |
116 | void setMailSize(int); | 116 | void setMailSize(int); |
117 | void setDownloadedSize(int); | 117 | void setDownloadedSize(int); |
118 | void moveMailFront(Email *mailPtr); | 118 | void moveMailFront(Email *mailPtr); |
119 | void download(Email*); | 119 | void download(Email*); |
120 | /* void reply(); | 120 | /* void reply(); |
121 | void replyAll(); | 121 | void replyAll(); |
122 | void forward(); | 122 | void forward(); |
123 | void remove();*/ | 123 | void remove();*/ |
124 | 124 | ||
125 | private slots: | 125 | private slots: |
126 | void receive(const QCString&, const QByteArray&); | 126 | void receive(const QCString&, const QByteArray&); |
127 | 127 | ||
128 | private: | 128 | private: |
129 | void init(); | 129 | void init(); |
130 | void initStatusBar(QWidget*); | 130 | void initStatusBar(QWidget*); |
131 | void readMail(); | 131 | void readMail(); |
132 | QString getPath(bool enclosurePath); | 132 | QString getPath(bool enclosurePath); |
133 | void readSettings(); | 133 | void readSettings(); |
134 | void saveSettings(); | 134 | void saveSettings(); |
135 | Email* getCurrentMail(); | 135 | Email* getCurrentMail(); |
136 | int timerID; | 136 | int timerID; |
137 | Config *mailconf; | 137 | Config *mailconf; |
138 | int newAccountId, idCount, mailIdCount; | 138 | int newAccountId, idCount, mailIdCount; |
139 | int accountIdCount; | 139 | int accountIdCount; |
140 | AccountList accountList; | 140 | AccountList accountList; |
141 | AddressList *addressList; | 141 | AddressList *addressList; |
142 | 142 | ||
143 | EditAccount *editAccountView; | 143 | EditAccount *editAccountView; |
144 | EmailListItem *item; | 144 | EmailListItem *item; |
145 | EmailHandler *emailHandler; | 145 | EmailHandler *emailHandler; |
146 | QList<Email> quedMessages; | 146 | QList<Email> quedMessages; |
147 | MailList mailDownloadList; | 147 | MailList mailDownloadList; |
148 | MailList tempMailDownloadList; | 148 | MailList tempMailDownloadList; |
149 | 149 | ||
150 | bool sending, receiving, previewingMail, allAccounts; | 150 | bool sending, receiving, previewingMail, allAccounts; |
151 | QString lineShift; | 151 | QString lineShift; |
152 | MailAccount account, *currentAccount; | 152 | MailAccount account, *currentAccount; |
153 | 153 | ||
154 | QCopChannel* channel; | 154 | QCopChannel* channel; |
155 | 155 | ||
156 | QToolBar *bar; | 156 | QToolBar *bar; |
157 | QProgressBar *progressBar; | 157 | QProgressBar *progressBar; |
diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp index 62fa64f..59ccd90 100644 --- a/noncore/net/mailit/emailhandler.cpp +++ b/noncore/net/mailit/emailhandler.cpp | |||
@@ -1,90 +1,90 @@ | |||
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 | qDebug("EMailHandler::EmailHandler"); | 42 | qDebug("EMailHandler::EmailHandler"); |
43 | 43 | ||
44 | smtpClient = new SmtpClient(); | 44 | smtpClient = new SmtpClient(); |
45 | popClient = new PopClient(); | 45 | popClient = new PopClient(); |
46 | 46 | ||
47 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, | 47 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, |
48 | SIGNAL(smtpError(int)) ); | 48 | SIGNAL(smtpError(int)) ); |
49 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); | 49 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); |
50 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, | 50 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, |
51 | SIGNAL(updateSmtpStatus(const QString &)) ); | 51 | SIGNAL(updateSmtpStatus(const QString &)) ); |
52 | 52 | ||
53 | connect(popClient, SIGNAL(errorOccurred(int)), this, | 53 | connect(popClient, SIGNAL(errorOccurred(int)), this, |
54 | SIGNAL(popError(int)) ); | 54 | SIGNAL(popError(int)) ); |
55 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), | 55 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), |
56 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); | 56 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); |
57 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, | 57 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, |
58 | SIGNAL(updatePopStatus(const QString &)) ); | 58 | SIGNAL(updatePopStatus(const QString &)) ); |
59 | connect(popClient, SIGNAL(mailTransfered(int)), this, | 59 | connect(popClient, SIGNAL(mailTransfered(int)), this, |
60 | SIGNAL(mailTransfered(int)) ); | 60 | SIGNAL(mailTransfered(int)) ); |
61 | 61 | ||
62 | 62 | ||
63 | //relaying size information | 63 | //relaying size information |
64 | connect(popClient, SIGNAL(currentMailSize(int)), | 64 | connect(popClient, SIGNAL(currentMailSize(int)), |
65 | this, SIGNAL(currentMailSize(int)) ); | 65 | this, SIGNAL(currentMailSize(int)) ); |
66 | connect(popClient, SIGNAL(downloadedSize(int)), | 66 | connect(popClient, SIGNAL(downloadedSize(int)), |
67 | this, SIGNAL(downloadedSize(int)) ); | 67 | this, SIGNAL(downloadedSize(int)) ); |
68 | } | 68 | } |
69 | 69 | ||
70 | void EmailHandler::sendMail(QList<Email> *mailList) | 70 | void EmailHandler::sendMail(QList<Email> *mailList) |
71 | { | 71 | { |
72 | Email *currentMail; | 72 | Email *currentMail; |
73 | QString temp; | 73 | QString temp; |
74 | QString userName = mailAccount.name; | 74 | QString userName = mailAccount.name; |
75 | userName += " <" + mailAccount.emailAddress + ">"; | 75 | userName += " <" + mailAccount.emailAddress + ">"; |
76 | 76 | ||
77 | for (currentMail = mailList->first(); currentMail != 0; | 77 | for (currentMail = mailList->first(); currentMail != 0; |
78 | currentMail = mailList->next()) { | 78 | currentMail = mailList->next()) { |
79 | 79 | ||
80 | if (encodeMime(currentMail) == 0) { | 80 | if (encodeMime(currentMail) == 0) { |
81 | smtpClient->addMail(userName, currentMail->subject, | 81 | smtpClient->addMail(userName, currentMail->subject, |
82 | currentMail->recipients, currentMail->rawMail); | 82 | currentMail->recipients, currentMail->rawMail); |
83 | } else { //error | 83 | } else { //error |
84 | temp = tr("Could not locate all files in \nmail with subject: ") + | 84 | temp = tr("Could not locate all files in \nmail with subject: ") + |
85 | currentMail->subject; | 85 | currentMail->subject; |
86 | temp += tr("\nMail has NOT been sent"); | 86 | temp += tr("\nMail has NOT been sent"); |
87 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); | 87 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); |
88 | 88 | ||
89 | } | 89 | } |
90 | } | 90 | } |
@@ -103,167 +103,167 @@ void EmailHandler::getMail() | |||
103 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 103 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
104 | } else { | 104 | } else { |
105 | popClient->removeSynchronize(); | 105 | popClient->removeSynchronize(); |
106 | } | 106 | } |
107 | 107 | ||
108 | headers = FALSE; | 108 | headers = FALSE; |
109 | //popClient->headersOnly(headers, 0); | 109 | //popClient->headersOnly(headers, 0); |
110 | popClient->newConnection(mailAccount.popServer, 110); | 110 | popClient->newConnection(mailAccount.popServer, 110); |
111 | } | 111 | } |
112 | 112 | ||
113 | void EmailHandler::getMailHeaders() | 113 | void EmailHandler::getMailHeaders() |
114 | { | 114 | { |
115 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 115 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
116 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); | 116 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); |
117 | 117 | ||
118 | headers = TRUE; | 118 | headers = TRUE; |
119 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 119 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
120 | qDebug("Initiating connection"); | 120 | qDebug("Initiating connection"); |
121 | popClient->newConnection(mailAccount.popServer, 110); | 121 | popClient->newConnection(mailAccount.popServer, 110); |
122 | } | 122 | } |
123 | 123 | ||
124 | void EmailHandler::getMailByList(MailList *mailList) | 124 | void EmailHandler::getMailByList(MailList *mailList) |
125 | { | 125 | { |
126 | if (mailList->count() == 0) { //should not occur though | 126 | if (mailList->count() == 0) { //should not occur though |
127 | emit mailTransfered(0); | 127 | emit mailTransfered(0); |
128 | return; | 128 | return; |
129 | } | 129 | } |
130 | 130 | ||
131 | headers = FALSE; | 131 | headers = FALSE; |
132 | popClient->headersOnly(FALSE, 0); | 132 | popClient->headersOnly(FALSE, 0); |
133 | 133 | ||
134 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); | 134 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); |
135 | popClient->setSelectedMails(mailList); | 135 | popClient->setSelectedMails(mailList); |
136 | popClient->newConnection(mailAccount.popServer, 110); | 136 | popClient->newConnection(mailAccount.popServer, 110); |
137 | } | 137 | } |
138 | 138 | ||
139 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) | 139 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) |
140 | { | 140 | { |
141 | Email mail; | 141 | Email mail; |
142 | 142 | ||
143 | mail.rawMail = message; | 143 | mail.rawMail = message; |
144 | mail.serverId = id; | 144 | mail.serverId = id; |
145 | mail.size = size; | 145 | mail.size = size; |
146 | mail.downloaded = complete; | 146 | mail.downloaded = complete; |
147 | 147 | ||
148 | emit mailArrived(mail, FALSE); | 148 | emit mailArrived(mail, FALSE); |
149 | } | 149 | } |
150 | 150 | ||
151 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 151 | bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) |
152 | { | 152 | { |
153 | QString temp, boundary; | 153 | QString temp, boundary; |
154 | int pos; | 154 | int pos; |
155 | QString delimiter, header, body, mimeHeader, mimeBody; | 155 | QString delimiter, header, body, mimeHeader, mimeBody; |
156 | QString content, contentType, contentAttribute, id, encoding; | 156 | QString content, contentType, contentAttribute, id, encoding; |
157 | QString fileName, storedName; | 157 | QString fileName, storedName; |
158 | int enclosureId = 0; | 158 | int enclosureId = 0; |
159 | 159 | ||
160 | mail->rawMail = in; | 160 | mail->rawMail = in; |
161 | mail->received = TRUE; | 161 | mail->received = TRUE; |
162 | mail->files.setAutoDelete(TRUE); | 162 | mail->files.setAutoDelete(TRUE); |
163 | 163 | ||
164 | temp = lineShift + "." + lineShift; | 164 | temp = lineShift + "." + lineShift; |
165 | 165 | ||
166 | if (in.right(temp.length()) != temp) { | 166 | if (in.right(temp.length()) != temp) { |
167 | mail->rawMail += temp; | 167 | mail->rawMail += temp; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
172 | pos = in.find(delimiter, 0, FALSE); | 172 | pos = in.find(delimiter, 0, FALSE); |
173 | header = in.left(pos); | 173 | header = in.left(pos); |
174 | body = in.right(in.length() - pos - delimiter.length()); | 174 | body = in.right(in.length() - pos - delimiter.length()); |
175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
176 | body.truncate(body.length()-2); | 176 | body.truncate(body.length()-2); |
177 | 177 | ||
178 | TextParser p(header, lineShift); | 178 | TextParser p(header, lineShift); |
179 | 179 | ||
180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
181 | pos++; | 181 | pos++; |
182 | if (p.separatorAt(pos) == ' ') { | 182 | if (p.separatorAt(pos) == ' ') { |
183 | mail->from = p.getString(&pos, '<', false); | 183 | mail->from = p.getString(&pos, '<', false); |
184 | mail->from = mail->from.stripWhiteSpace(); | 184 | mail->from = mail->from.stripWhiteSpace(); |
185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
186 | mail->from = mail->from.left(mail->from.length() - 1); | 186 | mail->from = mail->from.left(mail->from.length() - 1); |
187 | mail->from = mail->from.right(mail->from.length() - 1); | 187 | mail->from = mail->from.right(mail->from.length() - 1); |
188 | } | 188 | } |
189 | pos++; | 189 | pos++; |
190 | mail->fromMail = p.getString(&pos, '>', false); | 190 | mail->fromMail = p.getString(&pos, '>', false); |
191 | } else { | 191 | } else { |
192 | if (p.separatorAt(pos) == '<') //No name.. nasty | 192 | if (p.separatorAt(pos) == '<') //No name.. nasty |
193 | pos++; | 193 | pos++; |
194 | //pos++; | 194 | //pos++; |
195 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 195 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
197 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 197 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
198 | mail->from=mail->fromMail; | 198 | mail->from=mail->fromMail; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | pos=0; | 202 | pos=0; |
203 | 203 | ||
204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | 204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: |
205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | 205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) |
206 | { | 206 | { |
207 | QString rec; | 207 | QString rec; |
208 | 208 | ||
209 | if (p.separatorAt(pos-1)!='-')//The - separator means that this is a Delivered-To: or Reply-To: | 209 | if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: |
210 | { | 210 | { |
211 | pos++; | 211 | pos++; |
212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); | 212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | // | 215 | // |
216 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); | 216 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); |
217 | 217 | ||
218 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) | 218 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) |
219 | { | 219 | { |
220 | pos++; | 220 | pos++; |
221 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); | 221 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); |
222 | } | 222 | } |
223 | 223 | ||
224 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 224 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
225 | pos++; | 225 | pos++; |
226 | mail->subject = p.getString(&pos, 'z', TRUE); | 226 | mail->subject = p.getString(&pos, 'z', TRUE); |
227 | } | 227 | } |
228 | 228 | ||
229 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 229 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
230 | pos++; | 230 | pos++; |
231 | mail->date = p.getString(&pos, 'z', TRUE); | 231 | mail->date = p.getString(&pos, 'z', TRUE); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | 235 | ||
236 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 236 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
237 | pos++; | 237 | pos++; |
238 | if ( (p.wordAt(pos).upper() == "ID") && | 238 | if ( (p.wordAt(pos).upper() == "ID") && |
239 | (p.separatorAt(pos) == ':') ) { | 239 | (p.separatorAt(pos) == ':') ) { |
240 | 240 | ||
241 | id = p.getString(&pos, 'z', TRUE); | 241 | id = p.getString(&pos, 'z', TRUE); |
242 | mail->id = id; | 242 | mail->id = id; |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | pos = 0; | 246 | pos = 0; |
247 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 247 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
248 | pos++; | 248 | pos++; |
249 | if ( (p.wordAt(pos).upper() == "VERSION") && | 249 | if ( (p.wordAt(pos).upper() == "VERSION") && |
250 | (p.separatorAt(pos) == ':') ) { | 250 | (p.separatorAt(pos) == ':') ) { |
251 | pos++; | 251 | pos++; |
252 | if (p.getString(&pos, 'z', true) == "1.0") { | 252 | if (p.getString(&pos, 'z', true) == "1.0") { |
253 | mail->mimeType = 1; | 253 | mail->mimeType = 1; |
254 | } | 254 | } |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | if (mail->mimeType == 1) { | 258 | if (mail->mimeType == 1) { |
259 | boundary = ""; | 259 | boundary = ""; |
260 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 260 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
261 | pos++; | 261 | pos++; |
262 | boundary = p.getString(&pos, 'z', true); | 262 | boundary = p.getString(&pos, 'z', true); |
263 | if (boundary[0] == '"') { | 263 | if (boundary[0] == '"') { |
264 | boundary = boundary.left(boundary.length() - 1); //strip " | 264 | boundary = boundary.left(boundary.length() - 1); //strip " |
265 | boundary = boundary.right(boundary.length() - 1); //strip " | 265 | boundary = boundary.right(boundary.length() - 1); //strip " |
266 | } | 266 | } |
267 | boundary = "--" + boundary; //create boundary field | 267 | boundary = "--" + boundary; //create boundary field |
268 | } | 268 | } |
269 | 269 | ||
@@ -395,167 +395,167 @@ int EmailHandler::parse64base(char *src, char *bufOut) { | |||
395 | 395 | ||
396 | //conversion table withouth table... | 396 | //conversion table withouth table... |
397 | for (int x = 0; x < 4; x++) { | 397 | for (int x = 0; x < 4; x++) { |
398 | c = src[x]; | 398 | c = src[x]; |
399 | 399 | ||
400 | if ( (int) c >= 'A' && (int) c <= 'Z') | 400 | if ( (int) c >= 'A' && (int) c <= 'Z') |
401 | li[x] = (int) c - (int) 'A'; | 401 | li[x] = (int) c - (int) 'A'; |
402 | if ( (int) c >= 'a' && (int) c <= 'z') | 402 | if ( (int) c >= 'a' && (int) c <= 'z') |
403 | li[x] = (int) c - (int) 'a' + 26; | 403 | li[x] = (int) c - (int) 'a' + 26; |
404 | if ( (int) c >= '0' && (int) c <= '9') | 404 | if ( (int) c >= '0' && (int) c <= '9') |
405 | li[x] = (int) c - (int) '0' + 52; | 405 | li[x] = (int) c - (int) '0' + 52; |
406 | if (c == '+') | 406 | if (c == '+') |
407 | li[x] = 62; | 407 | li[x] = 62; |
408 | if (c == '/') | 408 | if (c == '/') |
409 | li[x] = 63; | 409 | li[x] = 63; |
410 | } | 410 | } |
411 | 411 | ||
412 | processed = 1; | 412 | processed = 1; |
413 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits | 413 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits |
414 | bufOut[0] <<= 2; | 414 | bufOut[0] <<= 2; |
415 | z = li[1] >> 4; | 415 | z = li[1] >> 4; |
416 | bufOut[0] = bufOut[0] | z; //first byte retrived | 416 | bufOut[0] = bufOut[0] | z; //first byte retrived |
417 | 417 | ||
418 | if (src[2] != '=') { | 418 | if (src[2] != '=') { |
419 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits | 419 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits |
420 | bufOut[1] <<= 4; | 420 | bufOut[1] <<= 4; |
421 | z = li[2] >> 2; | 421 | z = li[2] >> 2; |
422 | bufOut[1] = bufOut[1] | z; //second byte retrived | 422 | bufOut[1] = bufOut[1] | z; //second byte retrived |
423 | processed++; | 423 | processed++; |
424 | 424 | ||
425 | if (src[3] != '=') { | 425 | if (src[3] != '=') { |
426 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits | 426 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits |
427 | bufOut[2] <<= 6; | 427 | bufOut[2] <<= 6; |
428 | z = li[3]; | 428 | z = li[3]; |
429 | bufOut[2] = bufOut[2] | z; //third byte retrieved | 429 | bufOut[2] = bufOut[2] | z; //third byte retrieved |
430 | processed++; | 430 | processed++; |
431 | } | 431 | } |
432 | } | 432 | } |
433 | return processed; | 433 | return processed; |
434 | } | 434 | } |
435 | 435 | ||
436 | int EmailHandler::encodeMime(Email *mail) | 436 | int EmailHandler::encodeMime(Email *mail) |
437 | { | 437 | { |
438 | 438 | ||
439 | QString fileName, fileType, contentType, newBody, boundary; | 439 | QString fileName, fileType, contentType, newBody, boundary; |
440 | Enclosure *ePtr; | 440 | Enclosure *ePtr; |
441 | 441 | ||
442 | QString userName = mailAccount.name; | 442 | QString userName = mailAccount.name; |
443 | if (userName.length()>0)//only embrace it if there is a user name | 443 | if (userName.length()>0) //only embrace it if there is a user name |
444 | userName += " <" + mailAccount.emailAddress + ">"; | 444 | userName += " <" + mailAccount.emailAddress + ">"; |
445 | 445 | ||
446 | //add standard headers | 446 | //add standard headers |
447 | newBody = "From: " + userName + "\r\nTo: "; | 447 | newBody = "From: " + userName + "\r\nTo: "; |
448 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { | 448 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { |
449 | newBody += *it + " "; | 449 | newBody += *it + " "; |
450 | } | 450 | } |
451 | 451 | ||
452 | newBody += "\r\nCC: "; | 452 | newBody += "\r\nCC: "; |
453 | 453 | ||
454 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { | 454 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { |
455 | newBody += *it + " "; | 455 | newBody += *it + " "; |
456 | } | 456 | } |
457 | 457 | ||
458 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; | 458 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; |
459 | 459 | ||
460 | if (mail->files.count() == 0) { //just a simple mail | 460 | if (mail->files.count() == 0) { //just a simple mail |
461 | newBody += "\r\n" + mail->body; | 461 | newBody += "\r\n" + mail->body; |
462 | mail->rawMail = newBody; | 462 | mail->rawMail = newBody; |
463 | return 0; | 463 | return 0; |
464 | } | 464 | } |
465 | 465 | ||
466 | //Build mime encoded mail | 466 | //Build mime encoded mail |
467 | boundary = "-----4345=next_bound=0495----"; | 467 | boundary = "-----4345=next_bound=0495----"; |
468 | 468 | ||
469 | newBody += "Mime-Version: 1.0\r\n"; | 469 | newBody += "Mime-Version: 1.0\r\n"; |
470 | newBody += "Content-Type: multipart/mixed; boundary=\"" + | 470 | newBody += "Content-Type: multipart/mixed; boundary=\"" + |
471 | boundary + "\"\r\n\r\n"; | 471 | boundary + "\"\r\n\r\n"; |
472 | 472 | ||
473 | newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; | 473 | newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; |
474 | newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; | 474 | newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; |
475 | newBody += mail->body; | 475 | newBody += mail->body; |
476 | 476 | ||
477 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 477 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
478 | fileName = ePtr->originalName; | 478 | fileName = ePtr->originalName; |
479 | fileType = ePtr->contentType; | 479 | fileType = ePtr->contentType; |
480 | QFileInfo fi(fileName); | 480 | QFileInfo fi(fileName); |
481 | 481 | ||
482 | // This specification of contentType is temporary | 482 | // This specification of contentType is temporary |
483 | contentType = ""; | 483 | contentType = ""; |
484 | if (fileType == "Picture") { | 484 | if (fileType == "Picture") { |
485 | contentType = "image/x-image"; | 485 | contentType = "image/x-image"; |
486 | } else if (fileType == "Document") { | 486 | } else if (fileType == "Document") { |
487 | contentType = "text/plain"; | 487 | contentType = "text/plain"; |
488 | } else if (fileType == "Sound") { | 488 | } else if (fileType == "Sound") { |
489 | contentType = "audio/x-wav"; | 489 | contentType = "audio/x-wav"; |
490 | } else if (fileType == "Movie") { | 490 | } else if (fileType == "Movie") { |
491 | contentType = "video/mpeg"; | 491 | contentType = "video/mpeg"; |
492 | } else { | 492 | } else { |
493 | contentType = "application/octet-stream"; | 493 | contentType = "application/octet-stream"; |
494 | } | 494 | } |
495 | 495 | ||
496 | newBody += "\r\n\r\n--" + boundary + "\r\n"; | 496 | newBody += "\r\n\r\n--" + boundary + "\r\n"; |
497 | newBody += "Content-Type: " + contentType + "; name=\"" + | 497 | newBody += "Content-Type: " + contentType + "; name=\"" + |
498 | fi.fileName() + "\"\r\n"; | 498 | fi.fileName() + "\"\r\n"; |
499 | newBody += "Content-Transfer-Encoding: base64\r\n"; | 499 | newBody += "Content-Transfer-Encoding: base64\r\n"; |
500 | newBody += "Content-Disposition: inline; filename=\"" + | 500 | newBody += "Content-Disposition: inline; filename=\"" + |
501 | fi.fileName() + "\"\r\n\r\n"; | 501 | fi.fileName() + "\"\r\n\r\n"; |
502 | 502 | ||
503 | if (encodeFile(fileName, &newBody) == -1) //file not found? | 503 | if (encodeFile(fileName, &newBody) == -1) //file not found? |
504 | return -1; | 504 | return -1; |
505 | } | 505 | } |
506 | 506 | ||
507 | newBody += "\r\n\r\n--" + boundary + "--"; | 507 | newBody += "\r\n\r\n--" + boundary + "--"; |
508 | mail->rawMail = newBody; | 508 | mail->rawMail = newBody; |
509 | 509 | ||
510 | return 0; | 510 | return 0; |
511 | } | 511 | } |
512 | 512 | ||
513 | int EmailHandler::encodeFile(QString fileName, QString *toBody) | 513 | int EmailHandler::encodeFile(const QString &fileName, QString *toBody) |
514 | { | 514 | { |
515 | char *fileData; | 515 | char *fileData; |
516 | char *dataPtr; | 516 | char *dataPtr; |
517 | QString temp; | 517 | QString temp; |
518 | uint dataSize, count; | 518 | uint dataSize, count; |
519 | QFile f(fileName); | 519 | QFile f(fileName); |
520 | 520 | ||
521 | if (! f.open(IO_ReadOnly) ) { | 521 | if (! f.open(IO_ReadOnly) ) { |
522 | qWarning("could not open file: " + fileName); | 522 | qWarning("could not open file: " + fileName); |
523 | return -1; | 523 | return -1; |
524 | } | 524 | } |
525 | QTextStream s(&f); | 525 | QTextStream s(&f); |
526 | dataSize = f.size(); | 526 | dataSize = f.size(); |
527 | fileData = (char *) malloc(dataSize + 3); | 527 | fileData = (char *) malloc(dataSize + 3); |
528 | s.readRawBytes(fileData, dataSize); | 528 | s.readRawBytes(fileData, dataSize); |
529 | 529 | ||
530 | temp = ""; | 530 | temp = ""; |
531 | dataPtr = fileData; | 531 | dataPtr = fileData; |
532 | count = 0; | 532 | count = 0; |
533 | while (dataSize > 0) { | 533 | while (dataSize > 0) { |
534 | if (dataSize < 3) { | 534 | if (dataSize < 3) { |
535 | encode64base(dataPtr, &temp, dataSize); | 535 | encode64base(dataPtr, &temp, dataSize); |
536 | dataSize = 0; | 536 | dataSize = 0; |
537 | } else { | 537 | } else { |
538 | encode64base(dataPtr, &temp, 3); | 538 | encode64base(dataPtr, &temp, 3); |
539 | dataSize -= 3; | 539 | dataSize -= 3; |
540 | dataPtr += 3; | 540 | dataPtr += 3; |
541 | count += 4; | 541 | count += 4; |
542 | } | 542 | } |
543 | if (count > 72) { | 543 | if (count > 72) { |
544 | count = 0; | 544 | count = 0; |
545 | temp += "\r\n"; | 545 | temp += "\r\n"; |
546 | } | 546 | } |
547 | } | 547 | } |
548 | toBody->append(temp); | 548 | toBody->append(temp); |
549 | 549 | ||
550 | delete(fileData); | 550 | delete(fileData); |
551 | f.close(); | 551 | f.close(); |
552 | return 0; | 552 | return 0; |
553 | } | 553 | } |
554 | 554 | ||
555 | void EmailHandler::encode64base(char *src, QString *dest, int len) | 555 | void EmailHandler::encode64base(char *src, QString *dest, int len) |
556 | { | 556 | { |
557 | QString temp; | 557 | QString temp; |
558 | uchar c; | 558 | uchar c; |
559 | uchar bufOut[4]; | 559 | uchar bufOut[4]; |
560 | 560 | ||
561 | bufOut[0] = src[0]; | 561 | bufOut[0] = src[0]; |
diff --git a/noncore/net/mailit/emailhandler.h b/noncore/net/mailit/emailhandler.h index 5b59f65..e4e7f46 100644 --- a/noncore/net/mailit/emailhandler.h +++ b/noncore/net/mailit/emailhandler.h | |||
@@ -1,150 +1,150 @@ | |||
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 | #ifndef EmailHandler_H | 20 | #ifndef EmailHandler_H |
21 | #define EmailHandler_H | 21 | #define EmailHandler_H |
22 | 22 | ||
23 | #include <qobject.h> | 23 | #include <qobject.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qdatetime.h> | 25 | #include <qdatetime.h> |
26 | #include <qlist.h> | 26 | #include <qlist.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qfile.h> | 28 | #include <qfile.h> |
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | #include <qcollection.h> | 30 | #include <qcollection.h> |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | 32 | ||
33 | #include "smtpclient.h" | 33 | #include "smtpclient.h" |
34 | #include "popclient.h" | 34 | #include "popclient.h" |
35 | #include "textparser.h" | 35 | #include "textparser.h" |
36 | #include "maillist.h" | 36 | #include "maillist.h" |
37 | 37 | ||
38 | struct Enclosure | 38 | struct Enclosure |
39 | { | 39 | { |
40 | int id; | 40 | int id; |
41 | QString originalName; | 41 | QString originalName; |
42 | QString name; | 42 | QString name; |
43 | QString path; | 43 | QString path; |
44 | QString contentType; | 44 | QString contentType; |
45 | QString contentAttribute; | 45 | QString contentAttribute; |
46 | QString encoding; | 46 | QString encoding; |
47 | QString body; //might use to much mem. check!! | 47 | QString body; //might use to much mem. check!! |
48 | bool saved, installed; | 48 | bool saved, installed; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | class EnclosureList : public QList<Enclosure> | 51 | class EnclosureList : public QList<Enclosure> |
52 | { | 52 | { |
53 | public: | 53 | public: |
54 | Item newItem(Item d); | 54 | Item newItem(Item d); |
55 | private: | 55 | private: |
56 | Enclosure* dupl(Enclosure *in); | 56 | Enclosure* dupl(Enclosure *in); |
57 | Enclosure *ac; | 57 | Enclosure *ac; |
58 | }; | 58 | }; |
59 | 59 | ||
60 | struct Email | 60 | struct Email |
61 | { | 61 | { |
62 | QString id; | 62 | QString id; |
63 | QString from; | 63 | QString from; |
64 | QString fromMail; | 64 | QString fromMail; |
65 | QStringList recipients; | 65 | QStringList recipients; |
66 | QStringList carbonCopies; | 66 | QStringList carbonCopies; |
67 | QString date; | 67 | QString date; |
68 | QString subject; | 68 | QString subject; |
69 | QString body; | 69 | QString body; |
70 | QString bodyPlain; | 70 | QString bodyPlain; |
71 | bool sent, received, read, downloaded; | 71 | bool sent, received, read, downloaded; |
72 | QString rawMail; | 72 | QString rawMail; |
73 | int mimeType; //1 = Mime 1.0 | 73 | int mimeType; //1 = Mime 1.0 |
74 | int serverId; | 74 | int serverId; |
75 | int internalId; | 75 | int internalId; |
76 | int fromAccountId; | 76 | int fromAccountId; |
77 | QString contentType; //0 = text | 77 | QString contentType; //0 = text |
78 | QString contentAttribute; //0 = plain, 1 = html | 78 | QString contentAttribute; //0 = plain, 1 = html |
79 | EnclosureList files; | 79 | EnclosureList files; |
80 | uint size; | 80 | uint size; |
81 | 81 | ||
82 | void addEnclosure(Enclosure *e) | 82 | void addEnclosure(Enclosure *e) |
83 | { | 83 | { |
84 | files.append(e); | 84 | files.append(e); |
85 | } | 85 | } |
86 | }; | 86 | }; |
87 | 87 | ||
88 | struct MailAccount | 88 | struct MailAccount |
89 | { | 89 | { |
90 | QString accountName; | 90 | QString accountName; |
91 | QString name; | 91 | QString name; |
92 | QString emailAddress; | 92 | QString emailAddress; |
93 | QString popUserName; | 93 | QString popUserName; |
94 | QString popPasswd; | 94 | QString popPasswd; |
95 | QString popServer; | 95 | QString popServer; |
96 | QString smtpServer; | 96 | QString smtpServer; |
97 | bool synchronize; | 97 | bool synchronize; |
98 | int syncLimit; | 98 | int syncLimit; |
99 | int lastServerMailCount; | 99 | int lastServerMailCount; |
100 | int id; | 100 | int id; |
101 | }; | 101 | }; |
102 | 102 | ||
103 | const int ErrUnknownResponse = 1001; | 103 | const int ErrUnknownResponse = 1001; |
104 | const int ErrLoginFailed = 1002; | 104 | const int ErrLoginFailed = 1002; |
105 | const int ErrCancel = 1003; | 105 | const int ErrCancel = 1003; |
106 | 106 | ||
107 | 107 | ||
108 | class EmailHandler : public QObject | 108 | class EmailHandler : public QObject |
109 | { | 109 | { |
110 | Q_OBJECT | 110 | Q_OBJECT |
111 | 111 | ||
112 | public: | 112 | public: |
113 | EmailHandler(); | 113 | EmailHandler(); |
114 | void setAccount(MailAccount account); | 114 | void setAccount(MailAccount account); |
115 | MailAccount* getAccount(){return &mailAccount;} | 115 | MailAccount* getAccount(){return &mailAccount;} |
116 | void sendMail(QList<Email> *mailList); | 116 | void sendMail(QList<Email> *mailList); |
117 | void getMail(); | 117 | void getMail(); |
118 | void getMailHeaders(); | 118 | void getMailHeaders(); |
119 | void getMailByList(MailList *mailList); | 119 | void getMailByList(MailList *mailList); |
120 | bool parse(QString in, QString lineShift, Email *mail); | 120 | bool parse(const QString &in, const QString &lineShift, Email *mail); |
121 | bool getEnclosure(Enclosure *ePtr); | 121 | bool getEnclosure(Enclosure *ePtr); |
122 | int parse64base(char *src, char *dest); | 122 | int parse64base(char *src, char *dest); |
123 | int encodeMime(Email *mail); | 123 | int encodeMime(Email *mail); |
124 | int encodeFile(QString fileName, QString *toBody); | 124 | int encodeFile(const QString &fileName, QString *toBody); |
125 | void encode64base(char *src, QString *dest, int len); | 125 | void encode64base(char *src, QString *dest, int len); |
126 | void cancel(); | 126 | void cancel(); |
127 | 127 | ||
128 | signals: | 128 | signals: |
129 | void mailSent(); | 129 | void mailSent(); |
130 | void smtpError(int); | 130 | void smtpError(int); |
131 | void popError(int); | 131 | void popError(int); |
132 | void mailArrived(const Email &, bool); | 132 | void mailArrived(const Email &, bool); |
133 | void updatePopStatus(const QString &); | 133 | void updatePopStatus(const QString &); |
134 | void updateSmtpStatus(const QString &); | 134 | void updateSmtpStatus(const QString &); |
135 | void mailTransfered(int); | 135 | void mailTransfered(int); |
136 | void mailboxSize(int); | 136 | void mailboxSize(int); |
137 | void currentMailSize(int); | 137 | void currentMailSize(int); |
138 | void downloadedSize(int); | 138 | void downloadedSize(int); |
139 | 139 | ||
140 | public slots: | 140 | public slots: |
141 | void messageArrived(const QString &, int id, uint size, bool complete); | 141 | void messageArrived(const QString &, int id, uint size, bool complete); |
142 | 142 | ||
143 | private: | 143 | private: |
144 | MailAccount mailAccount; | 144 | MailAccount mailAccount; |
145 | SmtpClient *smtpClient; | 145 | SmtpClient *smtpClient; |
146 | PopClient *popClient; | 146 | PopClient *popClient; |
147 | bool headers; | 147 | bool headers; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | #endif | 150 | #endif |
diff --git a/noncore/net/mailit/emaillistitem.cpp b/noncore/net/mailit/emaillistitem.cpp index b925a1c..fc9f766 100644 --- a/noncore/net/mailit/emaillistitem.cpp +++ b/noncore/net/mailit/emaillistitem.cpp | |||
@@ -1,99 +1,99 @@ | |||
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 <qstring.h> | 20 | #include <qstring.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include "emaillistitem.h" | 22 | #include "emaillistitem.h" |
23 | 23 | ||
24 | EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox) | 24 | EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox) |
25 | : QListViewItem(parent) | 25 | : QListViewItem(parent) |
26 | { | 26 | { |
27 | QString temp; | 27 | QString temp; |
28 | 28 | ||
29 | mail = mailIn; | 29 | mail = mailIn; |
30 | 30 | ||
31 | if (inbox) { | 31 | if (inbox) { |
32 | setText(0, mail.from); | 32 | setText(0, mail.from); |
33 | } else { | 33 | } else { |
34 | QStringList::Iterator it = mail.recipients.begin(); | 34 | QStringList::Iterator it = mail.recipients.begin(); |
35 | temp = *it; | 35 | temp = *it; |
36 | if (mail.recipients.count() > 1) | 36 | if (mail.recipients.count() > 1) |
37 | temp += "..."; | 37 | temp += "..."; |
38 | setText(0, temp); | 38 | setText(0, temp); |
39 | } | 39 | } |
40 | setText(1, mail.subject); | 40 | setText(1, mail.subject); |
41 | setText(2,mail.date); | 41 | setText(2,mail.date); |
42 | 42 | ||
43 | if (mailIn.files.count()>0) | 43 | if (mailIn.files.count()>0) |
44 | { | 44 | { |
45 | setPixmap(0, Resource::loadPixmap("mailit/attach")); | 45 | setPixmap(0, Resource::loadPixmap("mailit/attach")); |
46 | } | 46 | } |
47 | 47 | ||
48 | selected = FALSE; | 48 | selected = FALSE; |
49 | } | 49 | } |
50 | 50 | ||
51 | Email* EmailListItem::getMail() | 51 | Email* EmailListItem::getMail() |
52 | { | 52 | { |
53 | return &mail; | 53 | return &mail; |
54 | } | 54 | } |
55 | 55 | ||
56 | void EmailListItem::setMail(Email newMail) | 56 | void EmailListItem::setMail(Email newMail) |
57 | { | 57 | { |
58 | mail = newMail; | 58 | mail = newMail; |
59 | repaint(); | 59 | repaint(); |
60 | } | 60 | } |
61 | 61 | ||
62 | void EmailListItem::setItemSelected(bool enable) | 62 | void EmailListItem::setItemSelected(bool enable) |
63 | { | 63 | { |
64 | selected = enable; | 64 | selected = enable; |
65 | setSelected(enable); | 65 | setSelected(enable); |
66 | repaint(); | 66 | repaint(); |
67 | } | 67 | } |
68 | 68 | ||
69 | bool EmailListItem::isItemSelected() | 69 | bool EmailListItem::isItemSelected() |
70 | { | 70 | { |
71 | return selected; | 71 | return selected; |
72 | } | 72 | } |
73 | 73 | ||
74 | void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg, | 74 | void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg, |
75 | int column, int width, int alignment ) | 75 | int column, int width, int alignment ) |
76 | { | 76 | { |
77 | 77 | ||
78 | QColorGroup _cg( cg ); | 78 | QColorGroup _cg( cg ); |
79 | QColor c = _cg.text(); | 79 | QColor c = _cg.text(); |
80 | 80 | ||
81 | if ( (! mail.read) && (mail.received) ) | 81 | if ( (! mail.read) && (mail.received) ) |
82 | _cg.setColor( QColorGroup::Text, Qt::blue); | 82 | _cg.setColor( QColorGroup::Text, Qt::blue); |
83 | if (!mail.downloaded) | 83 | if (!mail.downloaded) |
84 | _cg.setColor( QColorGroup::Text, Qt::red); | 84 | _cg.setColor( QColorGroup::Text, Qt::red); |
85 | 85 | ||
86 | /*if (selected) { | 86 | /* if (selected) { |
87 | _cg.setColor(QColorGroup::Base, Qt::blue); | 87 | _cg.setColor(QColorGroup::Base, Qt::blue); |
88 | _cg.setColor(QColorGroup::Text, Qt::yellow); | 88 | _cg.setColor(QColorGroup::Text, Qt::yellow); |
89 | if (isSelected()) { | 89 | if (isSelected()) { |
90 | _cg.setColor(QColorGroup::HighlightedText, Qt::yellow); | 90 | _cg.setColor(QColorGroup::HighlightedText, Qt::yellow); |
91 | } else { | 91 | } else { |
92 | _cg.setColor(QColorGroup::Highlight, Qt::blue); | 92 | _cg.setColor(QColorGroup::Highlight, Qt::blue); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | */ | 95 | */ |
96 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 96 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
97 | 97 | ||
98 | _cg.setColor( QColorGroup::Text, c ); | 98 | _cg.setColor( QColorGroup::Text, c ); |
99 | } | 99 | } |
diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp index fedc4e2..dc0116d 100644 --- a/noncore/net/mailit/popclient.cpp +++ b/noncore/net/mailit/popclient.cpp | |||
@@ -5,323 +5,323 @@ | |||
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 | 32 | ||
33 | socket = new QSocket(this, "popClient"); | 33 | socket = new QSocket(this, "popClient"); |
34 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 34 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
35 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 35 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
36 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 36 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
37 | 37 | ||
38 | stream = new QTextStream(socket); | 38 | stream = new QTextStream(socket); |
39 | 39 | ||
40 | receiving = FALSE; | 40 | receiving = FALSE; |
41 | synchronize = FALSE; | 41 | synchronize = FALSE; |
42 | lastSync = 0; | 42 | lastSync = 0; |
43 | headerLimit = 0; | 43 | headerLimit = 0; |
44 | preview = FALSE; | 44 | preview = FALSE; |
45 | } | 45 | } |
46 | 46 | ||
47 | PopClient::~PopClient() | 47 | PopClient::~PopClient() |
48 | { | 48 | { |
49 | delete socket; | 49 | delete socket; |
50 | delete stream; | 50 | delete stream; |
51 | } | 51 | } |
52 | 52 | ||
53 | void PopClient::newConnection(QString target, int port) | 53 | void PopClient::newConnection(const QString &target, int port) |
54 | { | 54 | { |
55 | if (receiving) { | 55 | if (receiving) { |
56 | qWarning("socket in use, connection refused"); | 56 | qWarning("socket in use, connection refused"); |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | 59 | ||
60 | status = Init; | 60 | status = Init; |
61 | 61 | ||
62 | socket->connectToHost(target, port); | 62 | socket->connectToHost(target, port); |
63 | receiving = TRUE; | 63 | receiving = TRUE; |
64 | //selected = FALSE; | 64 | //selected = FALSE; |
65 | 65 | ||
66 | emit updateStatus("DNS lookup"); | 66 | emit updateStatus("DNS lookup"); |
67 | } | 67 | } |
68 | 68 | ||
69 | void PopClient::setAccount(QString popUser, QString popPasswd) | 69 | void PopClient::setAccount(const QString &popUser, const QString &popPasswd) |
70 | { | 70 | { |
71 | popUserName = popUser; | 71 | popUserName = popUser; |
72 | popPassword = popPasswd; | 72 | popPassword = popPasswd; |
73 | } | 73 | } |
74 | 74 | ||
75 | void PopClient::setSynchronize(int lastCount) | 75 | void PopClient::setSynchronize(int lastCount) |
76 | { | 76 | { |
77 | synchronize = TRUE; | 77 | synchronize = TRUE; |
78 | lastSync = lastCount; | 78 | lastSync = lastCount; |
79 | } | 79 | } |
80 | 80 | ||
81 | void PopClient::removeSynchronize() | 81 | void PopClient::removeSynchronize() |
82 | { | 82 | { |
83 | synchronize = FALSE; | 83 | synchronize = FALSE; |
84 | lastSync = 0; | 84 | lastSync = 0; |
85 | } | 85 | } |
86 | 86 | ||
87 | void PopClient::headersOnly(bool headers, int limit) | 87 | void PopClient::headersOnly(bool headers, int limit) |
88 | { | 88 | { |
89 | preview = headers; | 89 | preview = headers; |
90 | headerLimit = limit; | 90 | headerLimit = limit; |
91 | } | 91 | } |
92 | 92 | ||
93 | void PopClient::setSelectedMails(MailList *list) | 93 | void PopClient::setSelectedMails(MailList *list) |
94 | { | 94 | { |
95 | selected = TRUE; | 95 | selected = TRUE; |
96 | mailList = list; | 96 | mailList = list; |
97 | } | 97 | } |
98 | 98 | ||
99 | void PopClient::connectionEstablished() | 99 | void PopClient::connectionEstablished() |
100 | { | 100 | { |
101 | emit updateStatus(tr("Connection established")); | 101 | emit updateStatus(tr("Connection established")); |
102 | } | 102 | } |
103 | 103 | ||
104 | void PopClient::errorHandling(int status) | 104 | void PopClient::errorHandling(int status) |
105 | { | 105 | { |
106 | emit updateStatus(tr("Error Occured")); | 106 | emit updateStatus(tr("Error Occured")); |
107 | emit errorOccurred(status); | 107 | emit errorOccurred(status); |
108 | socket->close(); | 108 | socket->close(); |
109 | receiving = FALSE; | 109 | receiving = FALSE; |
110 | } | 110 | } |
111 | 111 | ||
112 | void PopClient::incomingData() | 112 | void PopClient::incomingData() |
113 | { | 113 | { |
114 | QString response, temp, temp2, timeStamp; | 114 | QString response, temp, temp2, timeStamp; |
115 | QString md5Source; | 115 | QString md5Source; |
116 | int start, end; | 116 | int start, end; |
117 | // char *md5Digest; | 117 | // char *md5Digest; |
118 | char md5Digest[16]; | 118 | char md5Digest[16]; |
119 | // if ( !socket->canReadLine() ) | 119 | // if ( !socket->canReadLine() ) |
120 | // return; | 120 | // return; |
121 | 121 | ||
122 | 122 | ||
123 | response = socket->readLine(); | 123 | response = socket->readLine(); |
124 | 124 | ||
125 | switch(status) { | 125 | switch(status) { |
126 | //logging in | 126 | //logging in |
127 | case Init: { | 127 | case Init: { |
128 | #ifdef APOP_TEST | 128 | #ifdef APOP_TEST |
129 | start = response.find('<',0); | 129 | start = response.find('<',0); |
130 | end = response.find('>', start); | 130 | end = response.find('>', start); |
131 | if( start >= 0 && end > start ) | 131 | if( start >= 0 && end > start ) |
132 | { | 132 | { |
133 | timeStamp = response.mid( start , end - start + 1); | 133 | timeStamp = response.mid( start , end - start + 1); |
134 | md5Source = timeStamp + popPassword; | 134 | md5Source = timeStamp + popPassword; |
135 | 135 | ||
136 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); | 136 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); |
137 | 137 | ||
138 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) | 138 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) |
139 | { | 139 | { |
140 | printf("%x", md5Digest[j]); | 140 | printf("%x", md5Digest[j]); |
141 | } | 141 | } |
142 | printf("\n"); | 142 | printf("\n"); |
143 | // qDebug(md5Digest); | 143 | // qDebug(md5Digest); |
144 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; | 144 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; |
145 | // qDebug("%s", stream); | 145 | // qDebug("%s", stream); |
146 | status = Stat; | 146 | status = Stat; |
147 | } | 147 | } |
148 | else | 148 | else |
149 | #endif | 149 | #endif |
150 | { | 150 | { |
151 | timeStamp = ""; | 151 | timeStamp = ""; |
152 | *stream << "USER " << popUserName << "\r\n"; | 152 | *stream << "USER " << popUserName << "\r\n"; |
153 | status = Pass; | 153 | status = Pass; |
154 | } | 154 | } |
155 | 155 | ||
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | 158 | ||
159 | case Pass: { | 159 | case Pass: { |
160 | *stream << "PASS " << popPassword << "\r\n"; | 160 | *stream << "PASS " << popPassword << "\r\n"; |
161 | status = Stat; | 161 | status = Stat; |
162 | 162 | ||
163 | break; | 163 | break; |
164 | } | 164 | } |
165 | //ask for number of messages | 165 | //ask for number of messages |
166 | case Stat: { | 166 | case Stat: { |
167 | if (response[0] == '+') { | 167 | if (response[0] == '+') { |
168 | *stream << "STAT" << "\r\n"; | 168 | *stream << "STAT" << "\r\n"; |
169 | status = Mcnt; | 169 | status = Mcnt; |
170 | } else errorHandling(ErrLoginFailed); | 170 | } else errorHandling(ErrLoginFailed); |
171 | break; | 171 | break; |
172 | } | 172 | } |
173 | //get count of messages, eg "+OK 4 900.." -> int 4 | 173 | //get count of messages, eg "+OK 4 900.." -> int 4 |
174 | case Mcnt: { | 174 | case Mcnt: { |
175 | if (response[0] == '+') { | 175 | if (response[0] == '+') { |
176 | temp = response.replace(0, 4, ""); | 176 | temp = response.replace(0, 4, ""); |
177 | int x = temp.find(" ", 0); | 177 | int x = temp.find(" ", 0); |
178 | temp.truncate((uint) x); | 178 | temp.truncate((uint) x); |
179 | newMessages = temp.toInt(); | 179 | newMessages = temp.toInt(); |
180 | messageCount = 1; | 180 | messageCount = 1; |
181 | status = List; | 181 | status = List; |
182 | 182 | ||
183 | if (synchronize) { | 183 | if (synchronize) { |
184 | //messages deleted from server, reload all | 184 | //messages deleted from server, reload all |
185 | if (newMessages < lastSync) | 185 | if (newMessages < lastSync) |
186 | lastSync = 0; | 186 | lastSync = 0; |
187 | messageCount = 1; | 187 | messageCount = 1; |
188 | } | 188 | } |
189 | 189 | ||
190 | if (selected) { | 190 | if (selected) { |
191 | int *ptr = mailList->first(); | 191 | int *ptr = mailList->first(); |
192 | if (ptr != 0) { | 192 | if (ptr != 0) { |
193 | newMessages++; //to ensure no early jumpout | 193 | newMessages++; //to ensure no early jumpout |
194 | messageCount = *ptr; | 194 | messageCount = *ptr; |
195 | } else newMessages = 0; | 195 | } else newMessages = 0; |
196 | } | 196 | } |
197 | 197 | ||
198 | } else errorHandling(ErrUnknownResponse); | 198 | } else errorHandling(ErrUnknownResponse); |
199 | } | 199 | } |
200 | //Read message number x, count upwards to messageCount | 200 | //Read message number x, count upwards to messageCount |
201 | case List: { | 201 | case List: { |
202 | if (messageCount <= newMessages) { | 202 | if (messageCount <= newMessages) { |
203 | *stream << "LIST " << messageCount << "\r\n"; | 203 | *stream << "LIST " << messageCount << "\r\n"; |
204 | status = Size; | 204 | status = Size; |
205 | temp2.setNum(newMessages - lastSync); | 205 | temp2.setNum(newMessages - lastSync); |
206 | temp.setNum(messageCount - lastSync); | 206 | temp.setNum(messageCount - lastSync); |
207 | if (!selected) { | 207 | if (!selected) { |
208 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 208 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
209 | } else { | 209 | } else { |
210 | //completing a previously closed transfer | 210 | //completing a previously closed transfer |
211 | /* if ( (messageCount - lastSync) <= 0) { | 211 | /* if ( (messageCount - lastSync) <= 0) { |
212 | temp.setNum(messageCount); | 212 | temp.setNum(messageCount); |
213 | emit updateStatus(tr("Previous message ") + temp); | 213 | emit updateStatus(tr("Previous message ") + temp); |
214 | } else {*/ | 214 | } else {*/ |
215 | emit updateStatus(tr("Completing message ") + temp); | 215 | emit updateStatus(tr("Completing message ") + temp); |
216 | //} | 216 | //} |
217 | } | 217 | } |
218 | break; | 218 | break; |
219 | } else { | 219 | } else { |
220 | emit updateStatus(tr("No new Messages")); | 220 | emit updateStatus(tr("No new Messages")); |
221 | status = Quit; | 221 | status = Quit; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | //get size of message, eg "500 characters in message.." -> int 500 | 224 | //get size of message, eg "500 characters in message.." -> int 500 |
225 | case Size: { | 225 | case Size: { |
226 | if (status != Quit) { //because of idiotic switch | 226 | if (status != Quit) { //because of idiotic switch |
227 | if (response[0] == '+') { | 227 | if (response[0] == '+') { |
228 | temp = response.replace(0, 4, ""); | 228 | temp = response.replace(0, 4, ""); |
229 | int x = temp.find(" ", 0); | 229 | int x = temp.find(" ", 0); |
230 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 230 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
231 | mailSize = temp.toInt(); | 231 | mailSize = temp.toInt(); |
232 | emit currentMailSize(mailSize); | 232 | emit currentMailSize(mailSize); |
233 | 233 | ||
234 | status = Retr; | 234 | status = Retr; |
235 | } else { | 235 | } else { |
236 | //qWarning(response); | 236 | //qWarning(response); |
237 | errorHandling(ErrUnknownResponse); | 237 | errorHandling(ErrUnknownResponse); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | } | 240 | } |
241 | //Read message number x, count upwards to messageCount | 241 | //Read message number x, count upwards to messageCount |
242 | case Retr: { | 242 | case Retr: { |
243 | if (status != Quit) { | 243 | if (status != Quit) { |
244 | if ((selected)||(mailSize <= headerLimit)) | 244 | if ((selected)||(mailSize <= headerLimit)) |
245 | { | 245 | { |
246 | *stream << "RETR " << messageCount << "\r\n"; | 246 | *stream << "RETR " << messageCount << "\r\n"; |
247 | } else { //only header | 247 | } else { //only header |
248 | *stream << "TOP " << messageCount << " 0\r\n"; | 248 | *stream << "TOP " << messageCount << " 0\r\n"; |
249 | } | 249 | } |
250 | messageCount++; | 250 | messageCount++; |
251 | status = Ignore; | 251 | status = Ignore; |
252 | break; | 252 | break; |
253 | } } | 253 | } } |
254 | case Ignore: { | 254 | case Ignore: { |
255 | if (status != Quit) { //because of idiotic switch | 255 | if (status != Quit) { //because of idiotic switch |
256 | if (response[0] == '+') { | 256 | if (response[0] == '+') { |
257 | message = ""; | 257 | message = ""; |
258 | status = Read; | 258 | status = Read; |
259 | if (!socket->canReadLine()) //sync. problems | 259 | if (!socket->canReadLine()) //sync. problems |
260 | break; | 260 | break; |
261 | response = socket->readLine(); | 261 | response = socket->readLine(); |
262 | } else errorHandling(ErrUnknownResponse); | 262 | } else errorHandling(ErrUnknownResponse); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | //add all incoming lines to body. When size is reached, send | 265 | //add all incoming lines to body. When size is reached, send |
266 | //message, and go back to read new message | 266 | //message, and go back to read new message |
267 | case Read: { | 267 | case Read: { |
268 | if (status != Quit) { //because of idiotic switch | 268 | if (status != Quit) { //because of idiotic switch |
269 | message += response; | 269 | message += response; |
270 | while ( socket->canReadLine() ) { | 270 | while ( socket->canReadLine() ) { |
271 | response = socket->readLine(); | 271 | response = socket->readLine(); |
272 | message += response; | 272 | message += response; |
273 | } | 273 | } |
274 | emit downloadedSize(message.length()); | 274 | emit downloadedSize(message.length()); |
275 | int x = message.find("\r\n.\r\n",-5); | 275 | int x = message.find("\r\n.\r\n",-5); |
276 | if (x == -1) { | 276 | if (x == -1) { |
277 | break; | 277 | break; |
278 | } else { //message reach entire size | 278 | } else { //message reach entire size |
279 | if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active | 279 | if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active |
280 | { | 280 | { |
281 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 281 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
282 | } else { //incomplete mail downloaded | 282 | } else { //incomplete mail downloaded |
283 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 283 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
284 | } | 284 | } |
285 | 285 | ||
286 | if ((messageCount > newMessages)||(selected)) //last message ? | 286 | if ((messageCount > newMessages)||(selected)) //last message ? |
287 | { | 287 | { |
288 | status = Quit; | 288 | status = Quit; |
289 | if (selected) { //grab next from queue | 289 | if (selected) { //grab next from queue |
290 | newMessages--; | 290 | newMessages--; |
291 | status = Quit; | 291 | status = Quit; |
292 | } | 292 | } |
293 | } | 293 | } |
294 | else | 294 | else |
295 | { | 295 | { |
296 | *stream << "LIST " << messageCount << "\r\n"; | 296 | *stream << "LIST " << messageCount << "\r\n"; |
297 | status = Size; | 297 | status = Size; |
298 | temp2.setNum(newMessages - lastSync); | 298 | temp2.setNum(newMessages - lastSync); |
299 | temp.setNum(messageCount - lastSync); | 299 | temp.setNum(messageCount - lastSync); |
300 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 300 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
301 | 301 | ||
302 | break; | 302 | break; |
303 | } | 303 | } |
304 | } | 304 | } |
305 | } | 305 | } |
306 | if (status != Quit) | 306 | if (status != Quit) |
307 | break; | 307 | break; |
308 | } | 308 | } |
309 | case Quit: { | 309 | case Quit: { |
310 | *stream << "Quit\r\n"; | 310 | *stream << "Quit\r\n"; |
311 | status = Done; | 311 | status = Done; |
312 | int newM = newMessages - lastSync; | 312 | int newM = newMessages - lastSync; |
313 | if (newM > 0) { | 313 | if (newM > 0) { |
314 | temp.setNum(newM); | 314 | temp.setNum(newM); |
315 | emit updateStatus(temp + tr(" new messages")); | 315 | emit updateStatus(temp + tr(" new messages")); |
316 | } else { | 316 | } else { |
317 | emit updateStatus(tr("No new messages")); | 317 | emit updateStatus(tr("No new messages")); |
318 | } | 318 | } |
319 | 319 | ||
320 | socket->close(); | 320 | socket->close(); |
321 | receiving = FALSE; | 321 | receiving = FALSE; |
322 | emit mailTransfered(newM); | 322 | emit mailTransfered(newM); |
323 | break; | 323 | break; |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | } | 327 | } |
diff --git a/noncore/net/mailit/popclient.h b/noncore/net/mailit/popclient.h index 10b71ab..c58bc48 100644 --- a/noncore/net/mailit/popclient.h +++ b/noncore/net/mailit/popclient.h | |||
@@ -1,76 +1,76 @@ | |||
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 | #ifndef PopClient_H | 20 | #ifndef PopClient_H |
21 | #define PopClient_H | 21 | #define PopClient_H |
22 | 22 | ||
23 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <qsocket.h> | 24 | #include <qsocket.h> |
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | #include <qlist.h> | 28 | #include <qlist.h> |
29 | #include "maillist.h" | 29 | #include "maillist.h" |
30 | 30 | ||
31 | class PopClient: public QObject | 31 | class PopClient: public QObject |
32 | { | 32 | { |
33 | Q_OBJECT | 33 | Q_OBJECT |
34 | 34 | ||
35 | public: | 35 | public: |
36 | PopClient(); | 36 | PopClient(); |
37 | ~PopClient(); | 37 | ~PopClient(); |
38 | void newConnection(QString target, int port); | 38 | void newConnection(const QString &target, int port); |
39 | void setAccount(QString popUser, QString popPasswd); | 39 | void setAccount(const QString &popUser, const QString &popPasswd); |
40 | void setSynchronize(int lastCount); | 40 | void setSynchronize(int lastCount); |
41 | void removeSynchronize(); | 41 | void removeSynchronize(); |
42 | void headersOnly(bool headers, int limit); | 42 | void headersOnly(bool headers, int limit); |
43 | void setSelectedMails(MailList *list); | 43 | void setSelectedMails(MailList *list); |
44 | 44 | ||
45 | signals: | 45 | signals: |
46 | void newMessage(const QString &, int, uint, bool); | 46 | void newMessage(const QString &, int, uint, bool); |
47 | void errorOccurred(int status); | 47 | void errorOccurred(int status); |
48 | void updateStatus(const QString &); | 48 | void updateStatus(const QString &); |
49 | void mailTransfered(int); | 49 | void mailTransfered(int); |
50 | void mailboxSize(int); | 50 | void mailboxSize(int); |
51 | void currentMailSize(int); | 51 | void currentMailSize(int); |
52 | void downloadedSize(int); | 52 | void downloadedSize(int); |
53 | 53 | ||
54 | public slots: | 54 | public slots: |
55 | void errorHandling(int); | 55 | void errorHandling(int); |
56 | 56 | ||
57 | protected slots: | 57 | protected slots: |
58 | void connectionEstablished(); | 58 | void connectionEstablished(); |
59 | void incomingData(); | 59 | void incomingData(); |
60 | 60 | ||
61 | private: | 61 | private: |
62 | QSocket *socket; | 62 | QSocket *socket; |
63 | QTextStream *stream; | 63 | QTextStream *stream; |
64 | enum transferStatus | 64 | enum transferStatus |
65 | { | 65 | { |
66 | Init, Pass, Stat, Mcnt, Read, List, Size, Retr, Acks, | 66 | Init, Pass, Stat, Mcnt, Read, List, Size, Retr, Acks, |
67 | Quit, Done, Ignore | 67 | Quit, Done, Ignore |
68 | }; | 68 | }; |
69 | int status, lastSync; | 69 | int status, lastSync; |
70 | int messageCount, newMessages, mailSize, headerLimit; | 70 | int messageCount, newMessages, mailSize, headerLimit; |
71 | bool receiving, synchronize, preview, selected; | 71 | bool receiving, synchronize, preview, selected; |
72 | QString popUserName, popPassword, message; | 72 | QString popUserName, popPassword, message; |
73 | MailList *mailList; | 73 | MailList *mailList; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | #endif | 76 | #endif |
diff --git a/noncore/net/mailit/smtpclient.cpp b/noncore/net/mailit/smtpclient.cpp index 8a51a5b..2916f45 100644 --- a/noncore/net/mailit/smtpclient.cpp +++ b/noncore/net/mailit/smtpclient.cpp | |||
@@ -1,104 +1,104 @@ | |||
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(const 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(const QString &from, const QString &subject, const QStringList &to, const 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 | 90 | ||
91 | switch(status) { | 91 | switch(status) { |
92 | case Init: { | 92 | case Init: { |
93 | if (response[0] == '2') { | 93 | if (response[0] == '2') { |
94 | status = From; | 94 | status = From; |
95 | mailPtr = mailList.first(); | 95 | mailPtr = mailList.first(); |
96 | *stream << "HELO there\r\n"; | 96 | *stream << "HELO there\r\n"; |
97 | } else errorHandling(ErrUnknownResponse); | 97 | } else errorHandling(ErrUnknownResponse); |
98 | break; | 98 | break; |
99 | } | 99 | } |
100 | case From: { | 100 | case From: { |
101 | if (response[0] == '2') { | 101 | if (response[0] == '2') { |
102 | *stream << "MAIL FROM: " << mailPtr->from << "\r\n"; | 102 | *stream << "MAIL FROM: " << mailPtr->from << "\r\n"; |
103 | status = Recv; | 103 | status = Recv; |
104 | } else errorHandling(ErrUnknownResponse); | 104 | } else errorHandling(ErrUnknownResponse); |
diff --git a/noncore/net/mailit/smtpclient.h b/noncore/net/mailit/smtpclient.h index ca65af4..45c0703 100644 --- a/noncore/net/mailit/smtpclient.h +++ b/noncore/net/mailit/smtpclient.h | |||
@@ -1,75 +1,75 @@ | |||
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 | #ifndef SmtpClient_H | 20 | #ifndef SmtpClient_H |
21 | #define SmtpClient_H | 21 | #define SmtpClient_H |
22 | 22 | ||
23 | //#include <stdio.h> | 23 | //#include <stdio.h> |
24 | #include <qsocket.h> | 24 | #include <qsocket.h> |
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <qlist.h> | 29 | #include <qlist.h> |
30 | 30 | ||
31 | struct RawEmail | 31 | struct RawEmail |
32 | { | 32 | { |
33 | QString from; | 33 | QString from; |
34 | QString subject; | 34 | QString subject; |
35 | QStringList to; | 35 | QStringList to; |
36 | QString body; | 36 | QString body; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | class SmtpClient: public QObject | 39 | class SmtpClient: public QObject |
40 | { | 40 | { |
41 | Q_OBJECT | 41 | Q_OBJECT |
42 | 42 | ||
43 | public: | 43 | public: |
44 | SmtpClient(); | 44 | SmtpClient(); |
45 | ~SmtpClient(); | 45 | ~SmtpClient(); |
46 | void newConnection(QString target, int port); | 46 | void newConnection(const QString &target, int port); |
47 | void addMail(QString from, QString subject, QStringList to, QString body); | 47 | void addMail(const QString &from, const QString &subject, const QStringList &to, const QString &body); |
48 | 48 | ||
49 | signals: | 49 | signals: |
50 | void errorOccurred(int); | 50 | void errorOccurred(int); |
51 | void updateStatus(const QString &); | 51 | void updateStatus(const QString &); |
52 | void mailSent(); | 52 | void mailSent(); |
53 | 53 | ||
54 | public slots: | 54 | public slots: |
55 | void errorHandling(int); | 55 | void errorHandling(int); |
56 | 56 | ||
57 | protected slots: | 57 | protected slots: |
58 | void connectionEstablished(); | 58 | void connectionEstablished(); |
59 | void incomingData(); | 59 | void incomingData(); |
60 | 60 | ||
61 | private: | 61 | private: |
62 | QSocket *socket; | 62 | QSocket *socket; |
63 | QTextStream *stream; | 63 | QTextStream *stream; |
64 | enum transferStatus | 64 | enum transferStatus |
65 | { | 65 | { |
66 | Init, From, Recv, MRcv, Data, Body, Quit, Done | 66 | Init, From, Recv, MRcv, Data, Body, Quit, Done |
67 | }; | 67 | }; |
68 | int status; | 68 | int status; |
69 | QList<RawEmail> mailList; | 69 | QList<RawEmail> mailList; |
70 | RawEmail *mailPtr; | 70 | RawEmail *mailPtr; |
71 | bool sending; | 71 | bool sending; |
72 | QStringList::Iterator it; | 72 | QStringList::Iterator it; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | #endif | 75 | #endif |
diff --git a/noncore/net/mailit/textparser.cpp b/noncore/net/mailit/textparser.cpp index 3fa5f6e..e5c9f7c 100644 --- a/noncore/net/mailit/textparser.cpp +++ b/noncore/net/mailit/textparser.cpp | |||
@@ -1,304 +1,304 @@ | |||
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 "textparser.h" | 20 | #include "textparser.h" |
21 | 21 | ||
22 | TextParser::TextParser(QString in, QString lineBreak) | 22 | TextParser::TextParser(const QString &in, const QString &lineBreak) |
23 | { | 23 | { |
24 | data = in; | 24 | data = in; |
25 | lineSep = lineBreak; | 25 | lineSep = lineBreak; |
26 | 26 | ||
27 | init(); | 27 | init(); |
28 | createSeparators(); | 28 | createSeparators(); |
29 | split(); | 29 | split(); |
30 | } | 30 | } |
31 | 31 | ||
32 | TextParser::TextParser(QString in, QString lineBreak, QString sep) | 32 | TextParser::TextParser(const QString &in, const QString &lineBreak, const QString &sep) |
33 | { | 33 | { |
34 | data = in; | 34 | data = in; |
35 | lineSep = lineBreak; | 35 | lineSep = lineBreak; |
36 | 36 | ||
37 | init(); | 37 | init(); |
38 | separators = sep; | 38 | separators = sep; |
39 | split(); | 39 | split(); |
40 | } | 40 | } |
41 | 41 | ||
42 | void TextParser::init() | 42 | void TextParser::init() |
43 | { | 43 | { |
44 | lineCount = 0; | 44 | lineCount = 0; |
45 | linePos = 0; | 45 | linePos = 0; |
46 | totalElmCount = 0; | 46 | totalElmCount = 0; |
47 | separatorPos = -1; //not initialized | 47 | separatorPos = -1; //not initialized |
48 | wordPos = -1; //not initialized | 48 | wordPos = -1; //not initialized |
49 | sepAtLine = 0; | 49 | sepAtLine = 0; |
50 | sepAtPosElm = -1; //such that nextSep equals 0 | 50 | sepAtPosElm = -1; //such that nextSep equals 0 |
51 | wordAtLine = 0; | 51 | wordAtLine = 0; |
52 | wordAtPosElm = -1; //such that nextWord equals 0 | 52 | wordAtPosElm = -1; //such that nextWord equals 0 |
53 | atLine = 0; | 53 | atLine = 0; |
54 | atPosElm = 0; | 54 | atPosElm = 0; |
55 | } | 55 | } |
56 | 56 | ||
57 | void TextParser::createSeparators() | 57 | void TextParser::createSeparators() |
58 | { | 58 | { |
59 | separators = " @#,.:;<>*/(){}|'?-+=_"; | 59 | separators = " @#,.:;<>*/(){}|'?-+=_"; |
60 | } | 60 | } |
61 | 61 | ||
62 | /*Returns pos of given search criteria, -1 if not found */ | 62 | /* Returns pos of given search criteria, -1 if not found */ |
63 | int TextParser::find(QString target, QChar sep, int pos, bool upperCase) | 63 | int TextParser::find(const QString &target, QChar sep, int pos, bool upperCase) |
64 | { | 64 | { |
65 | 65 | ||
66 | t_splitElm parsstr; | 66 | t_splitElm parsstr; |
67 | QString pString; | 67 | QString pString, pTarget; |
68 | 68 | pTarget = target; | |
69 | int atLine = 0, atPosElm = 0; | 69 | int atLine = 0, atPosElm = 0; |
70 | 70 | ||
71 | getLineReference(pos,&atLine,&atPosElm); | 71 | getLineReference(pos,&atLine,&atPosElm); |
72 | 72 | ||
73 | for (int x = pos; x < totalElmCount; x++) | 73 | for (int x = pos; x < totalElmCount; x++) |
74 | { | 74 | { |
75 | parsstr=splitDone[atLine].elm[atPosElm++]; | 75 | parsstr=splitDone[atLine].elm[atPosElm++]; |
76 | 76 | ||
77 | if (upperCase) | 77 | if (upperCase) |
78 | { | 78 | { |
79 | pString=parsstr.str.upper(); | 79 | pString=parsstr.str.upper(); |
80 | target=target.upper(); | 80 | pTarget=pTarget.upper(); |
81 | } | 81 | } |
82 | else | 82 | else |
83 | { | 83 | { |
84 | pString=parsstr.str; | 84 | pString=parsstr.str; |
85 | } | 85 | } |
86 | if ((pString == target) && (parsstr.separator == sep)) | 86 | if ((pString == pTarget) && (parsstr.separator == sep)) |
87 | { | 87 | { |
88 | return x; | 88 | return x; |
89 | } | 89 | } |
90 | if (atPosElm >= splitDone[atLine].elmCount) | 90 | if (atPosElm >= splitDone[atLine].elmCount) |
91 | { //new Line | 91 | { //new Line |
92 | atLine++; | 92 | atLine++; |
93 | atPosElm = 0; | 93 | atPosElm = 0; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | return -1; | 96 | return -1; |
97 | } | 97 | } |
98 | 98 | ||
99 | int TextParser::elmCount() | 99 | int TextParser::elmCount() |
100 | { | 100 | { |
101 | return totalElmCount; | 101 | return totalElmCount; |
102 | } | 102 | } |
103 | 103 | ||
104 | QChar TextParser::separatorAt(int pos) | 104 | QChar TextParser::separatorAt(int pos) |
105 | { | 105 | { |
106 | if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1) | 106 | if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1) |
107 | return QChar::null; | 107 | return QChar::null; |
108 | 108 | ||
109 | separatorPos = pos; | 109 | separatorPos = pos; |
110 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; | 110 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; |
111 | } | 111 | } |
112 | 112 | ||
113 | QChar TextParser::nextSeparator() | 113 | QChar TextParser::nextSeparator() |
114 | { | 114 | { |
115 | sepAtPosElm++; | 115 | sepAtPosElm++; |
116 | if (splitDone[sepAtLine].elmCount <= sepAtPosElm) { | 116 | if (splitDone[sepAtLine].elmCount <= sepAtPosElm) { |
117 | sepAtLine++; | 117 | sepAtLine++; |
118 | sepAtPosElm = 0; | 118 | sepAtPosElm = 0; |
119 | } | 119 | } |
120 | 120 | ||
121 | separatorPos++; | 121 | separatorPos++; |
122 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; | 122 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; |
123 | } | 123 | } |
124 | 124 | ||
125 | bool TextParser::hasNextSeparator() | 125 | bool TextParser::hasNextSeparator() |
126 | { | 126 | { |
127 | return ((separatorPos+1) < totalElmCount); | 127 | return ((separatorPos+1) < totalElmCount); |
128 | } | 128 | } |
129 | 129 | ||
130 | QString TextParser::wordAt(int pos) | 130 | QString TextParser::wordAt(int pos) |
131 | { | 131 | { |
132 | if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1) | 132 | if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1) |
133 | return NULL; | 133 | return NULL; |
134 | 134 | ||
135 | wordPos = pos; | 135 | wordPos = pos; |
136 | return splitDone[wordAtLine].elm[wordAtPosElm].str; | 136 | return splitDone[wordAtLine].elm[wordAtPosElm].str; |
137 | } | 137 | } |
138 | 138 | ||
139 | QString TextParser::nextWord() | 139 | QString TextParser::nextWord() |
140 | { | 140 | { |
141 | wordAtPosElm++; | 141 | wordAtPosElm++; |
142 | if (splitDone[wordAtLine].elmCount <= wordAtPosElm) { | 142 | if (splitDone[wordAtLine].elmCount <= wordAtPosElm) { |
143 | wordAtLine++; | 143 | wordAtLine++; |
144 | wordAtPosElm = 0; | 144 | wordAtPosElm = 0; |
145 | } | 145 | } |
146 | 146 | ||
147 | wordPos++; | 147 | wordPos++; |
148 | return splitDone[wordAtLine].elm[wordAtPosElm].str; | 148 | return splitDone[wordAtLine].elm[wordAtPosElm].str; |
149 | } | 149 | } |
150 | 150 | ||
151 | bool TextParser::hasNextWord() | 151 | bool TextParser::hasNextWord() |
152 | { | 152 | { |
153 | return ((wordPos + 1) < totalElmCount); | 153 | return ((wordPos + 1) < totalElmCount); |
154 | } | 154 | } |
155 | 155 | ||
156 | QString TextParser::getString(int *pos, QChar stop, bool lineEnd = false) | 156 | QString TextParser::getString(int *pos, QChar stop, bool lineEnd = false) |
157 | { | 157 | { |
158 | QString returnStr = wordAt(*pos); | 158 | QString returnStr = wordAt(*pos); |
159 | QChar chr = separatorAt(*pos); | 159 | QChar chr = separatorAt(*pos); |
160 | QString s; | 160 | QString s; |
161 | 161 | ||
162 | if (returnStr == "") | 162 | if (returnStr == "") |
163 | return ""; | 163 | return ""; |
164 | if (chr == stop) | 164 | if (chr == stop) |
165 | return returnStr; | 165 | return returnStr; |
166 | 166 | ||
167 | if (!lineEnd) { | 167 | if (!lineEnd) { |
168 | while ((chr != stop) && hasNextWord()) { | 168 | while ((chr != stop) && hasNextWord()) { |
169 | returnStr.append(chr); | 169 | returnStr.append(chr); |
170 | returnStr += nextWord(); | 170 | returnStr += nextWord(); |
171 | chr = nextSeparator(); | 171 | chr = nextSeparator(); |
172 | } | 172 | } |
173 | } else { //copy from pos to end of line | 173 | } else { //copy from pos to end of line |
174 | getLineReference(*pos, &atLine, &atPosElm); | 174 | getLineReference(*pos, &atLine, &atPosElm); |
175 | returnStr = ""; | 175 | returnStr = ""; |
176 | while (atPosElm < splitDone[atLine].elmCount) { | 176 | while (atPosElm < splitDone[atLine].elmCount) { |
177 | if (splitDone[atLine].elm[atPosElm].str != "") { | 177 | if (splitDone[atLine].elm[atPosElm].str != "") { |
178 | returnStr += splitDone[atLine].elm[atPosElm].str; | 178 | returnStr += splitDone[atLine].elm[atPosElm].str; |
179 | } | 179 | } |
180 | chr = splitDone[atLine].elm[atPosElm].separator; | 180 | chr = splitDone[atLine].elm[atPosElm].separator; |
181 | if (!chr.isNull() && (int) chr != 0) { | 181 | if (!chr.isNull() && (int) chr != 0) { |
182 | returnStr.append(splitDone[atLine].elm[atPosElm].separator); | 182 | returnStr.append(splitDone[atLine].elm[atPosElm].separator); |
183 | } | 183 | } |
184 | atPosElm++; | 184 | atPosElm++; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | *pos = wordPos; | 188 | *pos = wordPos; |
189 | return returnStr; | 189 | return returnStr; |
190 | } | 190 | } |
191 | 191 | ||
192 | QString TextParser::getNextLine() | 192 | QString TextParser::getNextLine() |
193 | { | 193 | { |
194 | atLine++; | 194 | atLine++; |
195 | atPosElm = 0; | 195 | atPosElm = 0; |
196 | if (atLine < lineCount) | 196 | if (atLine < lineCount) |
197 | return splitDone[atLine].str; | 197 | return splitDone[atLine].str; |
198 | return ""; | 198 | return ""; |
199 | } | 199 | } |
200 | 200 | ||
201 | bool TextParser::hasNextLine() | 201 | bool TextParser::hasNextLine() |
202 | { | 202 | { |
203 | if (atLine+1 < lineCount) | 203 | if (atLine+1 < lineCount) |
204 | return TRUE;; | 204 | return TRUE;; |
205 | return FALSE; | 205 | return FALSE; |
206 | } | 206 | } |
207 | 207 | ||
208 | int TextParser::endLinePos(int pos) | 208 | int TextParser::endLinePos(int pos) |
209 | { | 209 | { |
210 | if ( (getLineReference(pos, &atLine, &atPosElm)) == -1) | 210 | if ( (getLineReference(pos, &atLine, &atPosElm)) == -1) |
211 | return -1; | 211 | return -1; |
212 | 212 | ||
213 | return (pos + (splitDone[atLine].elmCount - atPosElm) + 1); | 213 | return (pos + (splitDone[atLine].elmCount - atPosElm) + 1); |
214 | } | 214 | } |
215 | 215 | ||
216 | int TextParser::getLineReference(int pos, int *line, int *inLinePos) | 216 | int TextParser::getLineReference(int pos, int *line, int *inLinePos) |
217 | { | 217 | { |
218 | int currentPos = 0; | 218 | int currentPos = 0; |
219 | 219 | ||
220 | for (int x = 0; x < lineCount; x++) { | 220 | for (int x = 0; x < lineCount; x++) { |
221 | if ( currentPos + splitDone[x].elmCount > pos) { | 221 | if ( currentPos + splitDone[x].elmCount > pos) { |
222 | *line = x; | 222 | *line = x; |
223 | *inLinePos = pos - currentPos; | 223 | *inLinePos = pos - currentPos; |
224 | return 0; //pos found okay | 224 | return 0; //pos found okay |
225 | } | 225 | } |
226 | currentPos += splitDone[x].elmCount; | 226 | currentPos += splitDone[x].elmCount; |
227 | } | 227 | } |
228 | return -1; //no reference found | 228 | return -1; //no reference found |
229 | } | 229 | } |
230 | 230 | ||
231 | void TextParser::split() | 231 | void TextParser::split() |
232 | { | 232 | { |
233 | t_splitLine newLine; | 233 | t_splitLine newLine; |
234 | 234 | ||
235 | while ((uint) linePos < data.length()) { | 235 | while ((uint) linePos < data.length()) { |
236 | newLine = nextLine(); | 236 | newLine = nextLine(); |
237 | splitDone[lineCount] = splitLine(newLine); | 237 | splitDone[lineCount] = splitLine(newLine); |
238 | totalElmCount += splitDone[lineCount].elmCount; | 238 | totalElmCount += splitDone[lineCount].elmCount; |
239 | lineCount++; | 239 | lineCount++; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | t_splitLine TextParser::splitLine(t_splitLine line) | 243 | t_splitLine TextParser::splitLine(t_splitLine line) |
244 | { | 244 | { |
245 | uint pos = 0; | 245 | uint pos = 0; |
246 | uint elmCount = 0; | 246 | uint elmCount = 0; |
247 | t_splitLine tempLine = line; | 247 | t_splitLine tempLine = line; |
248 | 248 | ||
249 | tempLine.str = line.str.simplifyWhiteSpace(); | 249 | tempLine.str = line.str.simplifyWhiteSpace(); |
250 | tempLine.elm[0].str = ""; | 250 | tempLine.elm[0].str = ""; |
251 | while ( pos < line.str.length() ) { | 251 | while ( pos < line.str.length() ) { |
252 | if ( isSeparator(tempLine.str[pos]) ) { | 252 | if ( isSeparator(tempLine.str[pos]) ) { |
253 | tempLine.elm[elmCount].separator = tempLine.str[pos]; | 253 | tempLine.elm[elmCount].separator = tempLine.str[pos]; |
254 | elmCount++; | 254 | elmCount++; |
255 | pos++; | 255 | pos++; |
256 | while (tempLine.str[pos] == ' ') | 256 | while (tempLine.str[pos] == ' ') |
257 | pos++; | 257 | pos++; |
258 | if (pos > line.str.length()) | 258 | if (pos > line.str.length()) |
259 | elmCount--; | 259 | elmCount--; |
260 | tempLine.elm[elmCount].str = ""; | 260 | tempLine.elm[elmCount].str = ""; |
261 | } else { | 261 | } else { |
262 | if (!tempLine.str[pos].isNull()) | 262 | if (!tempLine.str[pos].isNull()) |
263 | tempLine.elm[elmCount].str += tempLine.str[pos]; | 263 | tempLine.elm[elmCount].str += tempLine.str[pos]; |
264 | pos++; | 264 | pos++; |
265 | } | 265 | } |
266 | } | 266 | } |
267 | 267 | ||
268 | tempLine.elmCount = elmCount + 1; | 268 | tempLine.elmCount = elmCount + 1; |
269 | return tempLine; | 269 | return tempLine; |
270 | } | 270 | } |
271 | 271 | ||
272 | bool TextParser::isSeparator(QChar chr) | 272 | bool TextParser::isSeparator(QChar chr) |
273 | { | 273 | { |
274 | for (uint x = 0; x < separators.length(); x++) { | 274 | for (uint x = 0; x < separators.length(); x++) { |
275 | if (chr == separators[x]) | 275 | if (chr == separators[x]) |
276 | return true; | 276 | return true; |
277 | } | 277 | } |
278 | return false; | 278 | return false; |
279 | } | 279 | } |
280 | 280 | ||
281 | t_splitLine TextParser::nextLine() | 281 | t_splitLine TextParser::nextLine() |
282 | { | 282 | { |
283 | int newLinePos; | 283 | int newLinePos; |
284 | t_splitLine lineType; | 284 | t_splitLine lineType; |
285 | 285 | ||
286 | newLinePos = data.find(lineSep, linePos); | 286 | newLinePos = data.find(lineSep, linePos); |
287 | 287 | ||
288 | lineType.lineType = NewLine; | 288 | lineType.lineType = NewLine; |
289 | lineType.str = ""; | 289 | lineType.str = ""; |
290 | 290 | ||
291 | if (newLinePos == -1) { | 291 | if (newLinePos == -1) { |
292 | newLinePos = data.length(); | 292 | newLinePos = data.length(); |
293 | lineType.lineType = LastLine; | 293 | lineType.lineType = LastLine; |
294 | } | 294 | } |
295 | 295 | ||
296 | for (int x = linePos; x < newLinePos; x++) | 296 | for (int x = linePos; x < newLinePos; x++) |
297 | lineType.str += data[x]; | 297 | lineType.str += data[x]; |
298 | 298 | ||
299 | linePos = newLinePos; | 299 | linePos = newLinePos; |
300 | if ((uint) linePos < data.length()) //if not EOF, add length of lineSep | 300 | if ((uint) linePos < data.length()) //if not EOF, add length of lineSep |
301 | linePos += lineSep.length(); | 301 | linePos += lineSep.length(); |
302 | 302 | ||
303 | return lineType; | 303 | return lineType; |
304 | } | 304 | } |
diff --git a/noncore/net/mailit/textparser.h b/noncore/net/mailit/textparser.h index c5e88a0..03bb6d5 100644 --- a/noncore/net/mailit/textparser.h +++ b/noncore/net/mailit/textparser.h | |||
@@ -4,82 +4,82 @@ | |||
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 <qobject.h> | 20 | #include <qobject.h> |
21 | #include <qstring.h> | 21 | #include <qstring.h> |
22 | 22 | ||
23 | #ifndef TEXTPARSER_H | 23 | #ifndef TEXTPARSER_H |
24 | #define TEXTPARSER_H | 24 | #define TEXTPARSER_H |
25 | 25 | ||
26 | enum t_strType { Word, Number}; | 26 | enum t_strType { Word, Number}; |
27 | enum t_lineType {NewLine, LastLine}; | 27 | enum t_lineType {NewLine, LastLine}; |
28 | 28 | ||
29 | const uint MAX_ELEMENTS = 200; //Should be dynamic | 29 | const uint MAX_ELEMENTS = 200; //Should be dynamic |
30 | const uint MAX_LINES = 500; //Should be dynamic | 30 | const uint MAX_LINES = 500; //Should be dynamic |
31 | 31 | ||
32 | struct t_splitElm | 32 | struct t_splitElm |
33 | { | 33 | { |
34 | QChar separator; | 34 | QChar separator; |
35 | int strType; | 35 | int strType; |
36 | QString str; | 36 | QString str; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | struct t_splitLine | 39 | struct t_splitLine |
40 | { | 40 | { |
41 | t_lineType lineType; | 41 | t_lineType lineType; |
42 | QString str; //a bit redundant... | 42 | QString str; //a bit redundant... |
43 | t_splitElm elm[MAX_ELEMENTS]; | 43 | t_splitElm elm[MAX_ELEMENTS]; |
44 | int elmCount; | 44 | int elmCount; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | class TextParser: public QObject | 47 | class TextParser: public QObject |
48 | { | 48 | { |
49 | Q_OBJECT | 49 | Q_OBJECT |
50 | 50 | ||
51 | public: | 51 | public: |
52 | TextParser(QString in, QString lineBreak); | 52 | TextParser(const QString &in, const QString &lineBreak); |
53 | TextParser(QString in, QString lineBreak, QString sep); | 53 | TextParser(const QString &in, const QString &lineBreak, const QString &sep); |
54 | int find(QString target, QChar sep, int pos, bool upperCase); | 54 | int find(const QString &target, QChar sep, int pos, bool upperCase); |
55 | int elmCount(); | 55 | int elmCount(); |
56 | QChar separatorAt(int pos); | 56 | QChar separatorAt(int pos); |
57 | QChar nextSeparator(); | 57 | QChar nextSeparator(); |
58 | bool hasNextSeparator(); | 58 | bool hasNextSeparator(); |
59 | QString wordAt(int pos); | 59 | QString wordAt(int pos); |
60 | QString nextWord(); | 60 | QString nextWord(); |
61 | bool hasNextWord(); | 61 | bool hasNextWord(); |
62 | QString getString(int *pos, QChar stop, bool lineEnd); | 62 | QString getString(int *pos, QChar stop, bool lineEnd); |
63 | QString getNextLine(); | 63 | QString getNextLine(); |
64 | bool hasNextLine(); | 64 | bool hasNextLine(); |
65 | int endLinePos(int pos); | 65 | int endLinePos(int pos); |
66 | 66 | ||
67 | private: | 67 | private: |
68 | void init(); | 68 | void init(); |
69 | void createSeparators(); | 69 | void createSeparators(); |
70 | t_splitLine nextLine(); | 70 | t_splitLine nextLine(); |
71 | void split(); | 71 | void split(); |
72 | t_splitLine splitLine(t_splitLine line); | 72 | t_splitLine splitLine(t_splitLine line); |
73 | bool isSeparator(QChar chr); | 73 | bool isSeparator(QChar chr); |
74 | t_splitLine splitDone[MAX_LINES]; | 74 | t_splitLine splitDone[MAX_LINES]; |
75 | int getLineReference(int pos, int *line, int *inLinePos); | 75 | int getLineReference(int pos, int *line, int *inLinePos); |
76 | 76 | ||
77 | int lineCount, linePos, totalElmCount; | 77 | int lineCount, linePos, totalElmCount; |
78 | int separatorPos, wordPos; | 78 | int separatorPos, wordPos; |
79 | QString data, separators, lineSep; | 79 | QString data, separators, lineSep; |
80 | int sepAtLine, sepAtPosElm; | 80 | int sepAtLine, sepAtPosElm; |
81 | int wordAtLine, wordAtPosElm; | 81 | int wordAtLine, wordAtPosElm; |
82 | int atLine, atPosElm; | 82 | int atLine, atPosElm; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | #endif | 85 | #endif |
diff --git a/noncore/unsupported/mailit/addresslist.cpp b/noncore/unsupported/mailit/addresslist.cpp index 7d60ebf..18d14bc 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(const QString &email, const 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(const 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(const 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(const 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(const 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(const 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(const 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;(*it).defaultEmail() | 124 | //OContact* oc;(*it).defaultEmail() |
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).fileAs()); | 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(const 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/addresslist.h b/noncore/unsupported/mailit/addresslist.h index 99cef9a..b46d467 100644 --- a/noncore/unsupported/mailit/addresslist.h +++ b/noncore/unsupported/mailit/addresslist.h | |||
@@ -1,58 +1,58 @@ | |||
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 | #ifndef ADDRESSLIST_H | 20 | #ifndef ADDRESSLIST_H |
21 | #define ADDRESSLIST_H | 21 | #define ADDRESSLIST_H |
22 | 22 | ||
23 | #include <qobject.h> | 23 | #include <qobject.h> |
24 | #include <qlist.h> | 24 | #include <qlist.h> |
25 | 25 | ||
26 | struct Contact | 26 | struct Contact |
27 | { | 27 | { |
28 | QString email; | 28 | QString email; |
29 | QString name; | 29 | QString name; |
30 | }; | 30 | }; |
31 | 31 | ||
32 | class AddressList : public QObject | 32 | class AddressList : public QObject |
33 | { | 33 | { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | 35 | ||
36 | public: | 36 | public: |
37 | AddressList(); | 37 | AddressList(); |
38 | ~AddressList(); | 38 | ~AddressList(); |
39 | void addContact(QString email, QString name); | 39 | void addContact(const QString &email, const QString &name); |
40 | bool containsEmail(QString email); | 40 | bool containsEmail(const QString &email); |
41 | bool containsName(QString name); | 41 | bool containsName(const QString &name); |
42 | QString getNameByEmail(QString email); | 42 | QString getNameByEmail(const QString &email); |
43 | QString getEmailByName(QString name); | 43 | QString getEmailByName(const QString &name); |
44 | QList<Contact>* getContactList(); | 44 | QList<Contact>* getContactList(); |
45 | 45 | ||
46 | private: | 46 | private: |
47 | int getEmailRef(QString email); | 47 | int getEmailRef(const QString &email); |
48 | int getNameRef(QString name); | 48 | int getNameRef(const QString &name); |
49 | QString getRightString(QString in); | 49 | QString getRightString(const QString &in); |
50 | void read(); | 50 | void read(); |
51 | 51 | ||
52 | private: | 52 | private: |
53 | QList<Contact> addresses; | 53 | QList<Contact> addresses; |
54 | QString filename; | 54 | QString filename; |
55 | bool dirty; | 55 | bool dirty; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | #endif | 58 | #endif |
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp index b039cc4..2102ba7 100644 --- a/noncore/unsupported/mailit/emailclient.cpp +++ b/noncore/unsupported/mailit/emailclient.cpp | |||
@@ -320,203 +320,204 @@ void EmailClient::mailSent() | |||
320 | 320 | ||
321 | void EmailClient::getNewMail() { | 321 | void EmailClient::getNewMail() { |
322 | 322 | ||
323 | if (accountList.count() == 0) { | 323 | if (accountList.count() == 0) { |
324 | QMessageBox::warning(qApp->activeWindow(),"No account selected", | 324 | QMessageBox::warning(qApp->activeWindow(),"No account selected", |
325 | "You must create an account", "OK\n"); | 325 | "You must create an account", "OK\n"); |
326 | return; | 326 | return; |
327 | } | 327 | } |
328 | 328 | ||
329 | setMailAccount(); | 329 | setMailAccount(); |
330 | 330 | ||
331 | receiving = TRUE; | 331 | receiving = TRUE; |
332 | previewingMail = TRUE; | 332 | previewingMail = TRUE; |
333 | getMailButton->setEnabled(FALSE); | 333 | getMailButton->setEnabled(FALSE); |
334 | cancelButton->setEnabled(TRUE); | 334 | cancelButton->setEnabled(TRUE); |
335 | selectAccountMenu->setEnabled(FALSE); | 335 | selectAccountMenu->setEnabled(FALSE); |
336 | 336 | ||
337 | status1Label->setText(currentAccount->accountName + " headers"); | 337 | status1Label->setText(currentAccount->accountName + " headers"); |
338 | progressBar->reset(); | 338 | progressBar->reset(); |
339 | 339 | ||
340 | //get any previous mails not downloaded and add to queue | 340 | //get any previous mails not downloaded and add to queue |
341 | /*mailDownloadList.clear(); | 341 | /*mailDownloadList.clear(); |
342 | Email *mailPtr; | 342 | Email *mailPtr; |
343 | item = (EmailListItem *) inboxView->firstChild(); | 343 | item = (EmailListItem *) inboxView->firstChild(); |
344 | while (item != NULL) { | 344 | while (item != NULL) { |
345 | mailPtr = item->getMail(); | 345 | mailPtr = item->getMail(); |
346 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { | 346 | if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { |
347 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); | 347 | mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); |
348 | } | 348 | } |
349 | item = (EmailListItem *) item->nextSibling(); | 349 | item = (EmailListItem *) item->nextSibling(); |
350 | }*/ | 350 | }*/ |
351 | 351 | ||
352 | emailHandler->getMailHeaders(); | 352 | emailHandler->getMailHeaders(); |
353 | 353 | ||
354 | } | 354 | } |
355 | 355 | ||
356 | void EmailClient::getAllNewMail() | 356 | void EmailClient::getAllNewMail() |
357 | { | 357 | { |
358 | allAccounts = TRUE; | 358 | allAccounts = TRUE; |
359 | currentAccount = accountList.first(); | 359 | currentAccount = accountList.first(); |
360 | getNewMail(); | 360 | getNewMail(); |
361 | } | 361 | } |
362 | 362 | ||
363 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) | 363 | void EmailClient::mailArrived(const Email &mail, bool fromDisk) |
364 | { | 364 | { |
365 | Enclosure *ePtr; | 365 | Enclosure *ePtr; |
366 | Email newMail; | 366 | Email newMail; |
367 | int thisMailId; | 367 | int thisMailId; |
368 | emailHandler->parse(mail.rawMail, lineShift, &newMail); | 368 | emailHandler->parse( mail.rawMail, lineShift, &newMail); |
369 | mailconf->setGroup(newMail.id); | 369 | mailconf->setGroup(newMail.id); |
370 | 370 | ||
371 | if (fromDisk) | 371 | if (fromDisk) |
372 | { | 372 | { |
373 | 373 | ||
374 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); | 374 | newMail.downloaded = mailconf->readBoolEntry("downloaded"); |
375 | newMail.size = mailconf->readNumEntry("size"); | 375 | newMail.size = mailconf->readNumEntry("size"); |
376 | newMail.serverId = mailconf->readNumEntry("serverid"); | 376 | newMail.serverId = mailconf->readNumEntry("serverid"); |
377 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); | 377 | newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); |
378 | } | 378 | } |
379 | else | 379 | else |
380 | { //mail arrived from server | 380 | { //mail arrived from server |
381 | 381 | ||
382 | newMail.serverId = mail.serverId; | 382 | newMail.serverId = mail.serverId; |
383 | newMail.size = mail.size; | 383 | newMail.size = mail.size; |
384 | newMail.downloaded = mail.downloaded; | 384 | newMail.downloaded = mail.downloaded; |
385 | 385 | ||
386 | newMail.fromAccountId = emailHandler->getAccount()->id; | 386 | newMail.fromAccountId = emailHandler->getAccount()->id; |
387 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); | 387 | mailconf->writeEntry("fromaccountid", newMail.fromAccountId); |
388 | } | 388 | } |
389 | 389 | ||
390 | //add if read or not | 390 | //add if read or not |
391 | newMail.read = mailconf->readBoolEntry("mailread"); | 391 | newMail.read = mailconf->readBoolEntry("mailread"); |
392 | 392 | ||
393 | //check if new mail | 393 | //check if new mail |
394 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { | 394 | if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { |
395 | thisMailId = mailIdCount; | 395 | thisMailId = mailIdCount; |
396 | mailIdCount++; | 396 | mailIdCount++; |
397 | 397 | ||
398 | //set server count, so that if the user aborts, the new | 398 | //set server count, so that if the user aborts, the new |
399 | //header is not reloaded | 399 | //header is not reloaded |
400 | if ((currentAccount)&&(currentAccount->synchronize)) | 400 | if ((currentAccount)&&(currentAccount->synchronize)) |
401 | currentAccount->lastServerMailCount++; | 401 | currentAccount->lastServerMailCount++; |
402 | 402 | ||
403 | mailconf->writeEntry("internalmailid", thisMailId); | 403 | mailconf->writeEntry("internalmailid", thisMailId); |
404 | mailconf->writeEntry("downloaded", newMail.downloaded); | 404 | mailconf->writeEntry("downloaded", newMail.downloaded); |
405 | mailconf->writeEntry("size", (int) newMail.size); | 405 | mailconf->writeEntry("size", (int) newMail.size); |
406 | mailconf->writeEntry("serverid", newMail.serverId); | 406 | mailconf->writeEntry("serverid", newMail.serverId); |
407 | 407 | ||
408 | //addressList->addContact(newMail.fromMail, newMail.from); | 408 | //addressList->addContact(newMail.fromMail, newMail.from); |
409 | } | 409 | } |
410 | 410 | ||
411 | mailconf->writeEntry("downloaded", newMail.downloaded); | 411 | mailconf->writeEntry("downloaded", newMail.downloaded); |
412 | 412 | ||
413 | QString stringMailId; | 413 | QString stringMailId; |
414 | stringMailId.setNum(thisMailId); | 414 | stringMailId.setNum(thisMailId); |
415 | //see if any attatchments needs to be stored | 415 | //see if any attatchments needs to be stored |
416 | 416 | ||
417 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { | 417 | for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { |
418 | QString stringId; | 418 | QString stringId; |
419 | stringId.setNum(ePtr->id); | 419 | stringId.setNum(ePtr->id); |
420 | 420 | ||
421 | int id = mailconf->readNumEntry("enclosureid_" + stringId); | 421 | int id = mailconf->readNumEntry("enclosureid_" + stringId); |
422 | if (id != ePtr->id) { //new entry | 422 | if (id != ePtr->id) { //new entry |
423 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); | 423 | mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); |
424 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); | 424 | mailconf->writeEntry("name_" + stringId, ePtr->originalName); |
425 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); | 425 | mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); |
426 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); | 426 | mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); |
427 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 427 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
428 | mailconf->writeEntry("installed_" + stringId, FALSE); | 428 | mailconf->writeEntry("installed_" + stringId, FALSE); |
429 | 429 | ||
430 | ePtr->name = stringMailId + "_" + stringId; | 430 | ePtr->name = stringMailId + "_" + stringId; |
431 | ePtr->path = getPath(TRUE); | 431 | ePtr->path = getPath(TRUE); |
432 | if (emailHandler->getEnclosure(ePtr)) { //file saved | 432 | if (emailHandler->getEnclosure(ePtr)) { //file saved |
433 | ePtr->saved = TRUE; | 433 | ePtr->saved = TRUE; |
434 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 434 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
435 | mailconf->writeEntry("filename_" + stringId, ePtr->name); | 435 | mailconf->writeEntry("filename_" + stringId, ePtr->name); |
436 | mailconf->writeEntry("path_" + stringId, ePtr->path); | 436 | mailconf->writeEntry("path_" + stringId, ePtr->path); |
437 | } else { | 437 | } else { |
438 | ePtr->saved = FALSE; | 438 | ePtr->saved = FALSE; |
439 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); | 439 | mailconf->writeEntry("saved_" + stringId, ePtr->saved); |
440 | } | 440 | } |
441 | } else { | 441 | } else { |
442 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); | 442 | ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); |
443 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); | 443 | ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); |
444 | if (ePtr->saved) { | 444 | if (ePtr->saved) { |
445 | ePtr->name = mailconf->readEntry("filename_" + stringId); | 445 | ePtr->name = mailconf->readEntry("filename_" + stringId); |
446 | ePtr->path = mailconf->readEntry("path_" + stringId); | 446 | ePtr->path = mailconf->readEntry("path_" + stringId); |
447 | } | 447 | } |
448 | } | 448 | } |
449 | } | 449 | } |
450 | 450 | ||
451 | bool found=false; | 451 | bool found=false; |
452 | 452 | ||
453 | if (!fromDisk) | 453 | if (!fromDisk) |
454 | { | 454 | { |
455 | 455 | ||
456 | Email *mailPtr; | 456 | Email *mailPtr; |
457 | item = (EmailListItem *) inboxView->firstChild(); | 457 | item = (EmailListItem *) inboxView->firstChild(); |
458 | while ((item != NULL)&&(!found)) | 458 | while ((item != NULL)&&(!found)) |
459 | { | 459 | { |
460 | mailPtr = item->getMail(); | 460 | mailPtr = item->getMail(); |
461 | if (mailPtr->id == newMail.id) { | 461 | if (mailPtr->id == newMail.id) { |
462 | item->setMail(newMail); | 462 | item->setMail(newMail); |
463 | emit mailUpdated(item->getMail()); | 463 | emit mailUpdated(item->getMail()); |
464 | found = true; | 464 | found = true; |
465 | } | 465 | } |
466 | item = (EmailListItem *) item->nextSibling(); | 466 | item = (EmailListItem *) item->nextSibling(); |
467 | } | 467 | } |
468 | } | 468 | } |
469 | if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE); | 469 | if ((!found)||(fromDisk)) { |
470 | 470 | item = new EmailListItem(inboxView, newMail, TRUE); | |
471 | if (item->getMail()->files.count()>0) | 471 | } |
472 | { | 472 | if (item->getMail()->files.count()>0) |
473 | item->setPixmap(0, Resource::loadPixmap("mailit/attach")); | 473 | { |
474 | } | 474 | item->setPixmap(0, Resource::loadPixmap("mailit/attach")); |
475 | } | ||
475 | /*if (!newMail.downloaded) | 476 | /*if (!newMail.downloaded) |
476 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ | 477 | mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ |
477 | 478 | ||
478 | mailboxView->setCurrentTab(0); | 479 | mailboxView->setCurrentTab(0); |
479 | 480 | ||
480 | } | 481 | } |
481 | 482 | ||
482 | void EmailClient::allMailArrived(int count) | 483 | void EmailClient::allMailArrived(int count) |
483 | { | 484 | { |
484 | // not previewing means all mailtransfer has been done | 485 | // not previewing means all mailtransfer has been done |
485 | /*if (!previewingMail) {*/ | 486 | /*if (!previewingMail) {*/ |
486 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { | 487 | if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { |
487 | emit newCaption("Mailit - " + currentAccount->accountName); | 488 | emit newCaption("Mailit - " + currentAccount->accountName); |
488 | getNewMail(); | 489 | getNewMail(); |
489 | return; | 490 | return; |
490 | } else { | 491 | } else { |
491 | allAccounts = FALSE; | 492 | allAccounts = FALSE; |
492 | receiving = FALSE; | 493 | receiving = FALSE; |
493 | getMailButton->setEnabled(TRUE); | 494 | getMailButton->setEnabled(TRUE); |
494 | cancelButton->setEnabled(FALSE); | 495 | cancelButton->setEnabled(FALSE); |
495 | selectAccountMenu->setEnabled(TRUE); | 496 | selectAccountMenu->setEnabled(TRUE); |
496 | status1Label->setText("Idle"); | 497 | status1Label->setText("Idle"); |
497 | 498 | ||
498 | progressBar->reset(); | 499 | progressBar->reset(); |
499 | return; | 500 | return; |
500 | } | 501 | } |
501 | //} | 502 | //} |
502 | 503 | ||
503 | // all headers downloaded from server, start downloading remaining mails | 504 | // all headers downloaded from server, start downloading remaining mails |
504 | previewingMail = FALSE; | 505 | previewingMail = FALSE; |
505 | status1Label->setText(currentAccount->accountName); | 506 | status1Label->setText(currentAccount->accountName); |
506 | progressBar->reset(); | 507 | progressBar->reset(); |
507 | 508 | ||
508 | 509 | ||
509 | mailboxView->setCurrentTab(0); | 510 | mailboxView->setCurrentTab(0); |
510 | } | 511 | } |
511 | 512 | ||
512 | 513 | ||
513 | void EmailClient::moveMailFront(Email *mailPtr) | 514 | void EmailClient::moveMailFront(Email *mailPtr) |
514 | { | 515 | { |
515 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { | 516 | if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { |
516 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); | 517 | mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); |
517 | } | 518 | } |
518 | } | 519 | } |
519 | 520 | ||
520 | void EmailClient::smtpError(int code) | 521 | void EmailClient::smtpError(int code) |
521 | { | 522 | { |
522 | QString temp; | 523 | QString temp; |
@@ -597,167 +598,167 @@ void EmailClient::readMail() | |||
597 | Email mail; | 598 | Email mail; |
598 | int start, stop; | 599 | int start, stop; |
599 | QString s, del; | 600 | QString s, del; |
600 | 601 | ||
601 | QFile f(getPath(FALSE) + "inbox.txt"); | 602 | QFile f(getPath(FALSE) + "inbox.txt"); |
602 | 603 | ||
603 | if ( f.open(IO_ReadOnly) ) { // file opened successfully | 604 | if ( f.open(IO_ReadOnly) ) { // file opened successfully |
604 | QTextStream t( &f ); // use a text stream | 605 | QTextStream t( &f ); // use a text stream |
605 | s = t.read(); | 606 | s = t.read(); |
606 | f.close(); | 607 | f.close(); |
607 | 608 | ||
608 | start = 0; | 609 | start = 0; |
609 | del = "\n.\n"; | 610 | del = "\n.\n"; |
610 | while ((uint) start < s.length()) { | 611 | while ((uint) start < s.length()) { |
611 | stop = s.find(del, start); | 612 | stop = s.find(del, start); |
612 | if (stop == -1) | 613 | if (stop == -1) |
613 | stop = s.length() - del.length(); | 614 | stop = s.length() - del.length(); |
614 | 615 | ||
615 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 616 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
616 | start = stop + del.length(); | 617 | start = stop + del.length(); |
617 | mailArrived(mail, TRUE); | 618 | mailArrived(mail, TRUE); |
618 | } | 619 | } |
619 | } | 620 | } |
620 | 621 | ||
621 | QFile fo(getPath(FALSE) + "outbox.txt"); | 622 | QFile fo(getPath(FALSE) + "outbox.txt"); |
622 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully | 623 | if ( fo.open(IO_ReadOnly) ) { // file opened successfully |
623 | QTextStream t( &fo ); // use a text stream | 624 | QTextStream t( &fo ); // use a text stream |
624 | s = t.read(); | 625 | s = t.read(); |
625 | fo.close(); | 626 | fo.close(); |
626 | 627 | ||
627 | start = 0; | 628 | start = 0; |
628 | del = "\n.\n"; | 629 | del = "\n.\n"; |
629 | while ((uint) start < s.length()) { | 630 | while ((uint) start < s.length()) { |
630 | stop = s.find(del, start); | 631 | stop = s.find(del, start); |
631 | if (stop == -1) | 632 | if (stop == -1) |
632 | stop = s.length() - del.length(); | 633 | stop = s.length() - del.length(); |
633 | 634 | ||
634 | mail.rawMail = s.mid(start, stop + del.length() - start ); | 635 | mail.rawMail = s.mid(start, stop + del.length() - start ); |
635 | start = stop + del.length(); | 636 | start = stop + del.length(); |
636 | emailHandler->parse(mail.rawMail, lineShift, &mail); | 637 | emailHandler->parse(mail.rawMail, lineShift, &mail); |
637 | mail.sent = false; | 638 | mail.sent = false; |
638 | mail.received = false; | 639 | mail.received = false; |
639 | enqueMail(mail); | 640 | enqueMail(mail); |
640 | 641 | ||
641 | } | 642 | } |
642 | } | 643 | } |
643 | } | 644 | } |
644 | 645 | ||
645 | void EmailClient::saveMail(QString fileName, QListView *view) | 646 | void EmailClient::saveMail(const QString &fileName, QListView *view) |
646 | { | 647 | { |
647 | QFile f(fileName); | 648 | QFile f(fileName); |
648 | Email *mail; | 649 | Email *mail; |
649 | 650 | ||
650 | if (! f.open(IO_WriteOnly) ) { | 651 | if (! f.open(IO_WriteOnly) ) { |
651 | qWarning("could not open file"); | 652 | qWarning("could not open file"); |
652 | return; | 653 | return; |
653 | } | 654 | } |
654 | item = (EmailListItem *) view->firstChild(); | 655 | item = (EmailListItem *) view->firstChild(); |
655 | QTextStream t(&f); | 656 | QTextStream t(&f); |
656 | while (item != NULL) { | 657 | while (item != NULL) { |
657 | mail = item->getMail(); | 658 | mail = item->getMail(); |
658 | t << mail->rawMail; | 659 | t << mail->rawMail; |
659 | 660 | ||
660 | mailconf->setGroup(mail->id); | 661 | mailconf->setGroup(mail->id); |
661 | mailconf->writeEntry("mailread", mail->read); | 662 | mailconf->writeEntry("mailread", mail->read); |
662 | 663 | ||
663 | item = (EmailListItem *) item->nextSibling(); | 664 | item = (EmailListItem *) item->nextSibling(); |
664 | } | 665 | } |
665 | f.close(); | 666 | f.close(); |
666 | } | 667 | } |
667 | 668 | ||
668 | //paths for mailit, is settings, inbox, enclosures | 669 | //paths for mailit, is settings, inbox, enclosures |
669 | QString EmailClient::getPath(bool enclosurePath) | 670 | QString EmailClient::getPath(bool enclosurePath) |
670 | { | 671 | { |
671 | QString basePath = "qtmail"; | 672 | QString basePath = "qtmail"; |
672 | QString enclosures = "enclosures"; | 673 | QString enclosures = "enclosures"; |
673 | 674 | ||
674 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); | 675 | QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); |
675 | if ( !dir.exists() ) | 676 | if ( !dir.exists() ) |
676 | dir.mkdir( dir.path() ); | 677 | dir.mkdir( dir.path() ); |
677 | 678 | ||
678 | if (enclosurePath) { | 679 | if (enclosurePath) { |
679 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); | 680 | dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); |
680 | 681 | ||
681 | if ( !dir.exists() ) | 682 | if ( !dir.exists() ) |
682 | dir.mkdir( dir.path() ); | 683 | dir.mkdir( dir.path() ); |
683 | 684 | ||
684 | return (dir.path() + "/"); | 685 | return (dir.path() + "/"); |
685 | 686 | ||
686 | } | 687 | } |
687 | return (dir.path() + "/"); | 688 | return (dir.path() + "/"); |
688 | } | 689 | } |
689 | 690 | ||
690 | void EmailClient::readSettings() | 691 | void EmailClient::readSettings() |
691 | { | 692 | { |
692 | int y,acc_count; | 693 | int y,acc_count; |
693 | 694 | ||
694 | mailconf->setGroup("mailitglobal"); | 695 | mailconf->setGroup("mailitglobal"); |
695 | acc_count=mailconf->readNumEntry("Accounts",0); | 696 | acc_count=mailconf->readNumEntry("Accounts",0); |
696 | 697 | ||
697 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) | 698 | for (int accountPos = 0;accountPos<acc_count ; accountPos++) |
698 | { | 699 | { |
699 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... | 700 | mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... |
700 | account.accountName = mailconf->readEntry("AccName",""); | 701 | account.accountName = mailconf->readEntry("AccName",""); |
701 | account.name = mailconf->readEntry("UserName",""); | 702 | account.name = mailconf->readEntry("UserName",""); |
702 | account.emailAddress = mailconf->readEntry("Email",""); | 703 | account.emailAddress = mailconf->readEntry("Email",""); |
703 | account.popUserName = mailconf->readEntry("POPUser",""); | 704 | account.popUserName = mailconf->readEntry("POPUser",""); |
704 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); | 705 | account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); |
705 | account.popServer = mailconf->readEntry("POPServer",""); | 706 | account.popServer = mailconf->readEntry("POPServer",""); |
706 | account.smtpServer = mailconf->readEntry("SMTPServer",""); | 707 | account.smtpServer = mailconf->readEntry("SMTPServer",""); |
707 | account.id = mailconf->readNumEntry("AccountId",0); | 708 | account.id = mailconf->readNumEntry("AccountId",0); |
708 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); | 709 | account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); |
709 | account.lastServerMailCount = 0; | 710 | account.lastServerMailCount = 0; |
710 | account.synchronize = FALSE; | 711 | account.synchronize = FALSE; |
711 | 712 | ||
712 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); | 713 | account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); |
713 | if (account.synchronize) | 714 | if (account.synchronize) |
714 | { | 715 | { |
715 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); | 716 | mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); |
716 | } | 717 | } |
717 | 718 | ||
718 | accountList.append(&account); | 719 | accountList.append(&account); |
719 | } | 720 | } |
720 | 721 | ||
721 | mailconf->setGroup("mailitglobal"); | 722 | mailconf->setGroup("mailitglobal"); |
722 | 723 | ||
723 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) | 724 | if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) |
724 | { | 725 | { |
725 | mailIdCount = y; | 726 | mailIdCount = y; |
726 | } | 727 | } |
727 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) | 728 | if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) |
728 | { | 729 | { |
729 | accountIdCount = y; | 730 | accountIdCount = y; |
730 | } | 731 | } |
731 | } | 732 | } |
732 | 733 | ||
733 | void EmailClient::saveSettings() | 734 | void EmailClient::saveSettings() |
734 | { | 735 | { |
735 | int acc_count=0; | 736 | int acc_count=0; |
736 | MailAccount *accountPtr; | 737 | MailAccount *accountPtr; |
737 | 738 | ||
738 | 739 | ||
739 | if (!mailconf) | 740 | if (!mailconf) |
740 | { | 741 | { |
741 | qWarning("could not save settings"); | 742 | qWarning("could not save settings"); |
742 | return; | 743 | return; |
743 | } | 744 | } |
744 | 745 | ||
745 | for (accountPtr = accountList.first(); accountPtr != 0; | 746 | for (accountPtr = accountList.first(); accountPtr != 0; |
746 | accountPtr = accountList.next()) | 747 | accountPtr = accountList.next()) |
747 | { | 748 | { |
748 | mailconf->setGroup("Account_"+QString::number(++acc_count)); | 749 | mailconf->setGroup("Account_"+QString::number(++acc_count)); |
749 | mailconf->writeEntry("AccName",accountPtr->accountName ); | 750 | mailconf->writeEntry("AccName",accountPtr->accountName ); |
750 | mailconf->writeEntry("UserName",accountPtr->name); | 751 | mailconf->writeEntry("UserName",accountPtr->name); |
751 | mailconf->writeEntry("Email",accountPtr->emailAddress); | 752 | mailconf->writeEntry("Email",accountPtr->emailAddress); |
752 | mailconf->writeEntry("POPUser",accountPtr->popUserName); | 753 | mailconf->writeEntry("POPUser",accountPtr->popUserName); |
753 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); | 754 | mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd); |
754 | mailconf->writeEntry("POPServer",accountPtr->popServer); | 755 | mailconf->writeEntry("POPServer",accountPtr->popServer); |
755 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); | 756 | mailconf->writeEntry("SMTPServer",accountPtr->smtpServer); |
756 | mailconf->writeEntry("AccountId",accountPtr->id); | 757 | mailconf->writeEntry("AccountId",accountPtr->id); |
757 | if (accountPtr->synchronize) | 758 | if (accountPtr->synchronize) |
758 | { | 759 | { |
759 | mailconf->writeEntry("Synchronize","Yes"); | 760 | mailconf->writeEntry("Synchronize","Yes"); |
760 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); | 761 | mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit); |
761 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); | 762 | mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount); |
762 | } | 763 | } |
763 | else | 764 | else |
@@ -870,167 +871,167 @@ void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) | |||
870 | //if mail is in queue for download, remove it from | 871 | //if mail is in queue for download, remove it from |
871 | //queue if possible | 872 | //queue if possible |
872 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { | 873 | if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) { |
873 | if ( !mPtr->downloaded ) | 874 | if ( !mPtr->downloaded ) |
874 | mailDownloadList.remove(mPtr->serverId, mPtr->size); | 875 | mailDownloadList.remove(mPtr->serverId, mPtr->size); |
875 | } | 876 | } |
876 | 877 | ||
877 | mailconf->setGroup(mPtr->id); | 878 | mailconf->setGroup(mPtr->id); |
878 | mailconf->clearGroup(); | 879 | mailconf->clearGroup(); |
879 | 880 | ||
880 | //delete any temporary attatchemnts storing | 881 | //delete any temporary attatchemnts storing |
881 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { | 882 | for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) { |
882 | if (ePtr->saved) { | 883 | if (ePtr->saved) { |
883 | QFile::remove( (ePtr->path + ePtr->name) ); | 884 | QFile::remove( (ePtr->path + ePtr->name) ); |
884 | } | 885 | } |
885 | } | 886 | } |
886 | inboxView->takeItem(mailItem); | 887 | inboxView->takeItem(mailItem); |
887 | } | 888 | } |
888 | else | 889 | else |
889 | { | 890 | { |
890 | outboxView->takeItem(mailItem); | 891 | outboxView->takeItem(mailItem); |
891 | } | 892 | } |
892 | } | 893 | } |
893 | 894 | ||
894 | void EmailClient::setMailSize(int size) | 895 | void EmailClient::setMailSize(int size) |
895 | { | 896 | { |
896 | progressBar->reset(); | 897 | progressBar->reset(); |
897 | progressBar->setTotalSteps(size); | 898 | progressBar->setTotalSteps(size); |
898 | } | 899 | } |
899 | 900 | ||
900 | void EmailClient::setTotalSize(int size) | 901 | void EmailClient::setTotalSize(int size) |
901 | { | 902 | { |
902 | 903 | ||
903 | } | 904 | } |
904 | 905 | ||
905 | void EmailClient::setDownloadedSize(int size) | 906 | void EmailClient::setDownloadedSize(int size) |
906 | { | 907 | { |
907 | int total = progressBar->totalSteps(); | 908 | int total = progressBar->totalSteps(); |
908 | 909 | ||
909 | if (size < total) { | 910 | if (size < total) { |
910 | progressBar->setProgress(size); | 911 | progressBar->setProgress(size); |
911 | } else { | 912 | } else { |
912 | progressBar->setProgress(total); | 913 | progressBar->setProgress(total); |
913 | } | 914 | } |
914 | } | 915 | } |
915 | 916 | ||
916 | void EmailClient::deleteItem() | 917 | void EmailClient::deleteItem() |
917 | { | 918 | { |
918 | bool inbox=mailboxView->currentTab()==0; | 919 | bool inbox=mailboxView->currentTab()==0; |
919 | QListView* box; | 920 | QListView* box; |
920 | 921 | ||
921 | EmailListItem* eli; | 922 | EmailListItem* eli; |
922 | int pos; | 923 | int pos; |
923 | 924 | ||
924 | inbox ? box=inboxView : box=outboxView; | 925 | inbox ? box=inboxView : box=outboxView; |
925 | 926 | ||
926 | eli=(EmailListItem*)box->selectedItem(); | 927 | eli=(EmailListItem*)box->selectedItem(); |
927 | 928 | ||
928 | if (eli) | 929 | if (eli) |
929 | { | 930 | { |
930 | box->setSelected(eli->itemBelow(),true);//select the previous item | 931 | box->setSelected(eli->itemBelow(),true); //select the previous item |
931 | 932 | ||
932 | deleteMail(eli,(bool&)inbox); //remove mail entry | 933 | deleteMail(eli,(bool&)inbox); //remove mail entry |
933 | } | 934 | } |
934 | } | 935 | } |
935 | 936 | ||
936 | void EmailClient::inboxItemPressed() | 937 | void EmailClient::inboxItemPressed() |
937 | { | 938 | { |
938 | //timerID=startTimer(500); | 939 | // timerID=startTimer(500); |
939 | } | 940 | } |
940 | 941 | ||
941 | void EmailClient::inboxItemReleased() | 942 | void EmailClient::inboxItemReleased() |
942 | { | 943 | { |
943 | //killTimer(timerID); | 944 | // killTimer(timerID); |
944 | } | 945 | } |
945 | 946 | ||
946 | /*void EmailClient::timerEvent(QTimerEvent *e) | 947 | /*void EmailClient::timerEvent(QTimerEvent *e) |
947 | { | 948 | { |
948 | /*killTimer(timerID); | 949 | /*killTimer(timerID); |
949 | 950 | ||
950 | 951 | ||
951 | QPopupMenu *action = new QPopupMenu(this); | 952 | QPopupMenu *action = new QPopupMenu(this); |
952 | 953 | ||
953 | int reply=0; | 954 | int reply=0; |
954 | 955 | ||
955 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); | 956 | action->insertItem(tr( "Reply To" ),this,SLOT(reply())); |
956 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); | 957 | action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); |
957 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); | 958 | action->insertItem( tr( "Forward" ), this,SLOT(forward())); |
958 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); | 959 | action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); |
959 | 960 | ||
960 | action->exec(QCursor::pos()); | 961 | action->exec(QCursor::pos()); |
961 | 962 | ||
962 | if (action) delete action; | 963 | if (action) delete action; |
963 | 964 | ||
964 | }*/ | 965 | }*/ |
965 | 966 | ||
966 | Email* EmailClient::getCurrentMail() | 967 | Email* EmailClient::getCurrentMail() |
967 | { | 968 | { |
968 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); | 969 | EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); |
969 | if (eli!=NULL) | 970 | if (eli!=NULL) |
970 | return eli->getMail(); | 971 | return eli->getMail(); |
971 | else | 972 | else |
972 | return NULL; | 973 | return NULL; |
973 | } | 974 | } |
974 | 975 | ||
975 | void EmailClient::download(Email* mail) | 976 | void EmailClient::download(Email* mail) |
976 | { | 977 | { |
977 | MailAccount* acc=0; | 978 | MailAccount* acc=0; |
978 | 979 | ||
979 | tempMailDownloadList.clear(); | 980 | tempMailDownloadList.clear(); |
980 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); | 981 | tempMailDownloadList.sizeInsert(mail->serverId, mail->size); |
981 | 982 | ||
982 | acc=accountList.at(mail->fromAccountId-1); | 983 | acc=accountList.at(mail->fromAccountId-1); |
983 | if (acc) | 984 | if (acc) |
984 | { | 985 | { |
985 | emailHandler->setAccount(*acc); | 986 | emailHandler->setAccount(*acc); |
986 | emailHandler->getMailByList(&tempMailDownloadList); | 987 | emailHandler->getMailByList(&tempMailDownloadList); |
987 | } | 988 | } |
988 | else | 989 | else |
989 | QMessageBox::warning(qApp->activeWindow(), | 990 | QMessageBox::warning(qApp->activeWindow(), |
990 | tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); | 991 | tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); |
991 | } | 992 | } |
992 | 993 | ||
993 | void EmailClient::receive(const QCString& msg, const QByteArray& data) | 994 | void EmailClient::receive(const QCString& msg, const QByteArray& data) |
994 | { | 995 | { |
995 | /*if (msg=="getMail()") | 996 | /*if (msg=="getMail()") |
996 | { | 997 | { |
997 | /*QDialog qd(qApp->activeWindow(),"Getting mail",true); | 998 | /*QDialog qd(qApp->activeWindow(),"Getting mail",true); |
998 | QVBoxLayout *vbProg = new QVBoxLayout( &qd ); | 999 | QVBoxLayout *vbProg = new QVBoxLayout( &qd ); |
999 | 1000 | ||
1000 | initStatusBar(&qd); | 1001 | initStatusBar(&qd); |
1001 | 1002 | ||
1002 | if (statusBar==0) | 1003 | if (statusBar==0) |
1003 | { | 1004 | { |
1004 | qDebug("No Bar ..."); | 1005 | qDebug("No Bar ..."); |
1005 | //statusBar=new ProgressBar(&qd); | 1006 | //statusBar=new ProgressBar(&qd); |
1006 | } | 1007 | } |
1007 | statusBar->show(); | 1008 | statusBar->show(); |
1008 | vbProg->addWidget(statusBar); | 1009 | vbProg->addWidget(statusBar); |
1009 | qd.showMaximized(); | 1010 | qd.showMaximized(); |
1010 | qd.show(); | 1011 | qd.show(); |
1011 | emit getAllNewMail(); | 1012 | emit getAllNewMail(); |
1012 | //qd.exec(); | 1013 | //qd.exec(); |
1013 | } | 1014 | } |
1014 | else if (msg=="compose()") | 1015 | else if (msg=="compose()") |
1015 | { | 1016 | { |
1016 | QDialog qd(qApp->activeWindow(),"Getting mail",true); | 1017 | QDialog qd(qApp->activeWindow(),"Getting mail",true); |
1017 | 1018 | ||
1018 | WriteMail wm(&qd,"write new mail"); | 1019 | WriteMail wm(&qd,"write new mail"); |
1019 | QVBoxLayout vbProg( &qd ); | 1020 | QVBoxLayout vbProg( &qd ); |
1020 | 1021 | ||
1021 | wm.showMaximized(); | 1022 | wm.showMaximized(); |
1022 | vbProg.addWidget(&wm); | 1023 | vbProg.addWidget(&wm); |
1023 | 1024 | ||
1024 | qd.showMaximized(); | 1025 | qd.showMaximized(); |
1025 | 1026 | ||
1026 | emit composeRequested(); | 1027 | emit composeRequested(); |
1027 | qd.exec(); | 1028 | qd.exec(); |
1028 | 1029 | ||
1029 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | 1030 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); |
1030 | } | 1031 | } |
1031 | 1032 | ||
1032 | else if (msg=="dialog()") | 1033 | else if (msg=="dialog()") |
1033 | { | 1034 | { |
1034 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); | 1035 | QMessageBox::warning(qApp->activeWindow(),tr("Info"), tr("Info"), "OK\n"); |
1035 | }*/ | 1036 | }*/ |
1036 | } | 1037 | } |
diff --git a/noncore/unsupported/mailit/emailclient.h b/noncore/unsupported/mailit/emailclient.h index 994fec5..c98cfce 100644 --- a/noncore/unsupported/mailit/emailclient.h +++ b/noncore/unsupported/mailit/emailclient.h | |||
@@ -61,97 +61,97 @@ private: | |||
61 | MailAccount* dupl(MailAccount *in); | 61 | MailAccount* dupl(MailAccount *in); |
62 | MailAccount *ac; | 62 | MailAccount *ac; |
63 | }; | 63 | }; |
64 | 64 | ||
65 | //class EmailClient : public EmailClientBase | 65 | //class EmailClient : public EmailClientBase |
66 | class EmailClient : public QMainWindow | 66 | class EmailClient : public QMainWindow |
67 | { | 67 | { |
68 | Q_OBJECT | 68 | Q_OBJECT |
69 | 69 | ||
70 | public: | 70 | public: |
71 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); | 71 | EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); |
72 | ~EmailClient(); | 72 | ~EmailClient(); |
73 | AddressList* getAdrListRef(); | 73 | AddressList* getAdrListRef(); |
74 | 74 | ||
75 | protected: | 75 | protected: |
76 | //void timerEvent(QTimerEvent*); | 76 | //void timerEvent(QTimerEvent*); |
77 | 77 | ||
78 | signals: | 78 | signals: |
79 | void composeRequested(); | 79 | void composeRequested(); |
80 | void viewEmail(QListView *, Email *); | 80 | void viewEmail(QListView *, Email *); |
81 | void mailUpdated(Email *); | 81 | void mailUpdated(Email *); |
82 | void newCaption(const QString &); | 82 | void newCaption(const QString &); |
83 | void replyRequested(Email&, bool&); | 83 | void replyRequested(Email&, bool&); |
84 | void forwardRequested(Email&); | 84 | void forwardRequested(Email&); |
85 | void removeItem(EmailListItem*, bool&); | 85 | void removeItem(EmailListItem*, bool&); |
86 | /*void reply(Email&); | 86 | /*void reply(Email&); |
87 | void replyAll(Email&); | 87 | void replyAll(Email&); |
88 | void remove(Email&); | 88 | void remove(Email&); |
89 | void forward(Email&);*/ | 89 | void forward(Email&);*/ |
90 | 90 | ||
91 | public slots: | 91 | public slots: |
92 | void compose(); | 92 | void compose(); |
93 | void cancel(); | 93 | void cancel(); |
94 | void enqueMail(const Email &mail); | 94 | void enqueMail(const Email &mail); |
95 | void setMailAccount(); | 95 | void setMailAccount(); |
96 | void sendQuedMail(); | 96 | void sendQuedMail(); |
97 | void mailSent(); | 97 | void mailSent(); |
98 | void deleteItem(); | 98 | void deleteItem(); |
99 | void getNewMail(); | 99 | void getNewMail(); |
100 | void getAllNewMail(); | 100 | void getAllNewMail(); |
101 | void smtpError(int code); | 101 | void smtpError(int code); |
102 | void popError(int code); | 102 | void popError(int code); |
103 | void inboxItemSelected(); | 103 | void inboxItemSelected(); |
104 | void outboxItemSelected(); | 104 | void outboxItemSelected(); |
105 | void inboxItemPressed(); | 105 | void inboxItemPressed(); |
106 | void inboxItemReleased(); | 106 | void inboxItemReleased(); |
107 | void mailArrived(const Email &mail, bool fromDisk); | 107 | void mailArrived(const Email &mail, bool fromDisk); |
108 | void allMailArrived(int); | 108 | void allMailArrived(int); |
109 | void saveMail(QString fileName, QListView *view); | 109 | void saveMail(const QString &fileName, QListView *view); |
110 | void selectAccount(int); | 110 | void selectAccount(int); |
111 | void editAccount(int); | 111 | void editAccount(int); |
112 | void updateAccounts(); | 112 | void updateAccounts(); |
113 | void deleteAccount(int); | 113 | void deleteAccount(int); |
114 | void deleteMail(EmailListItem *mailItem, bool &inbox); | 114 | void deleteMail(EmailListItem *mailItem, bool &inbox); |
115 | void setTotalSize(int); | 115 | void setTotalSize(int); |
116 | void setMailSize(int); | 116 | void setMailSize(int); |
117 | void setDownloadedSize(int); | 117 | void setDownloadedSize(int); |
118 | void moveMailFront(Email *mailPtr); | 118 | void moveMailFront(Email *mailPtr); |
119 | void download(Email*); | 119 | void download(Email*); |
120 | /* void reply(); | 120 | /* void reply(); |
121 | void replyAll(); | 121 | void replyAll(); |
122 | void forward(); | 122 | void forward(); |
123 | void remove();*/ | 123 | void remove();*/ |
124 | 124 | ||
125 | private slots: | 125 | private slots: |
126 | void receive(const QCString&, const QByteArray&); | 126 | void receive(const QCString&, const QByteArray&); |
127 | 127 | ||
128 | private: | 128 | private: |
129 | void init(); | 129 | void init(); |
130 | void initStatusBar(QWidget*); | 130 | void initStatusBar(QWidget*); |
131 | void readMail(); | 131 | void readMail(); |
132 | QString getPath(bool enclosurePath); | 132 | QString getPath(bool enclosurePath); |
133 | void readSettings(); | 133 | void readSettings(); |
134 | void saveSettings(); | 134 | void saveSettings(); |
135 | Email* getCurrentMail(); | 135 | Email* getCurrentMail(); |
136 | int timerID; | 136 | int timerID; |
137 | Config *mailconf; | 137 | Config *mailconf; |
138 | int newAccountId, idCount, mailIdCount; | 138 | int newAccountId, idCount, mailIdCount; |
139 | int accountIdCount; | 139 | int accountIdCount; |
140 | AccountList accountList; | 140 | AccountList accountList; |
141 | AddressList *addressList; | 141 | AddressList *addressList; |
142 | 142 | ||
143 | EditAccount *editAccountView; | 143 | EditAccount *editAccountView; |
144 | EmailListItem *item; | 144 | EmailListItem *item; |
145 | EmailHandler *emailHandler; | 145 | EmailHandler *emailHandler; |
146 | QList<Email> quedMessages; | 146 | QList<Email> quedMessages; |
147 | MailList mailDownloadList; | 147 | MailList mailDownloadList; |
148 | MailList tempMailDownloadList; | 148 | MailList tempMailDownloadList; |
149 | 149 | ||
150 | bool sending, receiving, previewingMail, allAccounts; | 150 | bool sending, receiving, previewingMail, allAccounts; |
151 | QString lineShift; | 151 | QString lineShift; |
152 | MailAccount account, *currentAccount; | 152 | MailAccount account, *currentAccount; |
153 | 153 | ||
154 | QCopChannel* channel; | 154 | QCopChannel* channel; |
155 | 155 | ||
156 | QToolBar *bar; | 156 | QToolBar *bar; |
157 | QProgressBar *progressBar; | 157 | QProgressBar *progressBar; |
diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp index 62fa64f..59ccd90 100644 --- a/noncore/unsupported/mailit/emailhandler.cpp +++ b/noncore/unsupported/mailit/emailhandler.cpp | |||
@@ -1,90 +1,90 @@ | |||
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 | qDebug("EMailHandler::EmailHandler"); | 42 | qDebug("EMailHandler::EmailHandler"); |
43 | 43 | ||
44 | smtpClient = new SmtpClient(); | 44 | smtpClient = new SmtpClient(); |
45 | popClient = new PopClient(); | 45 | popClient = new PopClient(); |
46 | 46 | ||
47 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, | 47 | connect(smtpClient, SIGNAL(errorOccurred(int)), this, |
48 | SIGNAL(smtpError(int)) ); | 48 | SIGNAL(smtpError(int)) ); |
49 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); | 49 | connect(smtpClient, SIGNAL(mailSent()), this, SIGNAL(mailSent()) ); |
50 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, | 50 | connect(smtpClient, SIGNAL(updateStatus(const QString &)), this, |
51 | SIGNAL(updateSmtpStatus(const QString &)) ); | 51 | SIGNAL(updateSmtpStatus(const QString &)) ); |
52 | 52 | ||
53 | connect(popClient, SIGNAL(errorOccurred(int)), this, | 53 | connect(popClient, SIGNAL(errorOccurred(int)), this, |
54 | SIGNAL(popError(int)) ); | 54 | SIGNAL(popError(int)) ); |
55 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), | 55 | connect(popClient, SIGNAL(newMessage(const QString &, int, uint, bool)), |
56 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); | 56 | this, SLOT(messageArrived(const QString &, int, uint, bool)) ); |
57 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, | 57 | connect(popClient, SIGNAL(updateStatus(const QString &)), this, |
58 | SIGNAL(updatePopStatus(const QString &)) ); | 58 | SIGNAL(updatePopStatus(const QString &)) ); |
59 | connect(popClient, SIGNAL(mailTransfered(int)), this, | 59 | connect(popClient, SIGNAL(mailTransfered(int)), this, |
60 | SIGNAL(mailTransfered(int)) ); | 60 | SIGNAL(mailTransfered(int)) ); |
61 | 61 | ||
62 | 62 | ||
63 | //relaying size information | 63 | //relaying size information |
64 | connect(popClient, SIGNAL(currentMailSize(int)), | 64 | connect(popClient, SIGNAL(currentMailSize(int)), |
65 | this, SIGNAL(currentMailSize(int)) ); | 65 | this, SIGNAL(currentMailSize(int)) ); |
66 | connect(popClient, SIGNAL(downloadedSize(int)), | 66 | connect(popClient, SIGNAL(downloadedSize(int)), |
67 | this, SIGNAL(downloadedSize(int)) ); | 67 | this, SIGNAL(downloadedSize(int)) ); |
68 | } | 68 | } |
69 | 69 | ||
70 | void EmailHandler::sendMail(QList<Email> *mailList) | 70 | void EmailHandler::sendMail(QList<Email> *mailList) |
71 | { | 71 | { |
72 | Email *currentMail; | 72 | Email *currentMail; |
73 | QString temp; | 73 | QString temp; |
74 | QString userName = mailAccount.name; | 74 | QString userName = mailAccount.name; |
75 | userName += " <" + mailAccount.emailAddress + ">"; | 75 | userName += " <" + mailAccount.emailAddress + ">"; |
76 | 76 | ||
77 | for (currentMail = mailList->first(); currentMail != 0; | 77 | for (currentMail = mailList->first(); currentMail != 0; |
78 | currentMail = mailList->next()) { | 78 | currentMail = mailList->next()) { |
79 | 79 | ||
80 | if (encodeMime(currentMail) == 0) { | 80 | if (encodeMime(currentMail) == 0) { |
81 | smtpClient->addMail(userName, currentMail->subject, | 81 | smtpClient->addMail(userName, currentMail->subject, |
82 | currentMail->recipients, currentMail->rawMail); | 82 | currentMail->recipients, currentMail->rawMail); |
83 | } else { //error | 83 | } else { //error |
84 | temp = tr("Could not locate all files in \nmail with subject: ") + | 84 | temp = tr("Could not locate all files in \nmail with subject: ") + |
85 | currentMail->subject; | 85 | currentMail->subject; |
86 | temp += tr("\nMail has NOT been sent"); | 86 | temp += tr("\nMail has NOT been sent"); |
87 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); | 87 | QMessageBox::warning(qApp->activeWindow(), tr("Attachment error"), temp, tr("OK\n")); |
88 | 88 | ||
89 | } | 89 | } |
90 | } | 90 | } |
@@ -103,167 +103,167 @@ void EmailHandler::getMail() | |||
103 | popClient->setSynchronize(mailAccount.lastServerMailCount); | 103 | popClient->setSynchronize(mailAccount.lastServerMailCount); |
104 | } else { | 104 | } else { |
105 | popClient->removeSynchronize(); | 105 | popClient->removeSynchronize(); |
106 | } | 106 | } |
107 | 107 | ||
108 | headers = FALSE; | 108 | headers = FALSE; |
109 | //popClient->headersOnly(headers, 0); | 109 | //popClient->headersOnly(headers, 0); |
110 | popClient->newConnection(mailAccount.popServer, 110); | 110 | popClient->newConnection(mailAccount.popServer, 110); |
111 | } | 111 | } |
112 | 112 | ||
113 | void EmailHandler::getMailHeaders() | 113 | void EmailHandler::getMailHeaders() |
114 | { | 114 | { |
115 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); | 115 | popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); |
116 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); | 116 | mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); |
117 | 117 | ||
118 | headers = TRUE; | 118 | headers = TRUE; |
119 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all | 119 | popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all |
120 | qDebug("Initiating connection"); | 120 | qDebug("Initiating connection"); |
121 | popClient->newConnection(mailAccount.popServer, 110); | 121 | popClient->newConnection(mailAccount.popServer, 110); |
122 | } | 122 | } |
123 | 123 | ||
124 | void EmailHandler::getMailByList(MailList *mailList) | 124 | void EmailHandler::getMailByList(MailList *mailList) |
125 | { | 125 | { |
126 | if (mailList->count() == 0) { //should not occur though | 126 | if (mailList->count() == 0) { //should not occur though |
127 | emit mailTransfered(0); | 127 | emit mailTransfered(0); |
128 | return; | 128 | return; |
129 | } | 129 | } |
130 | 130 | ||
131 | headers = FALSE; | 131 | headers = FALSE; |
132 | popClient->headersOnly(FALSE, 0); | 132 | popClient->headersOnly(FALSE, 0); |
133 | 133 | ||
134 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); | 134 | popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); |
135 | popClient->setSelectedMails(mailList); | 135 | popClient->setSelectedMails(mailList); |
136 | popClient->newConnection(mailAccount.popServer, 110); | 136 | popClient->newConnection(mailAccount.popServer, 110); |
137 | } | 137 | } |
138 | 138 | ||
139 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) | 139 | void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) |
140 | { | 140 | { |
141 | Email mail; | 141 | Email mail; |
142 | 142 | ||
143 | mail.rawMail = message; | 143 | mail.rawMail = message; |
144 | mail.serverId = id; | 144 | mail.serverId = id; |
145 | mail.size = size; | 145 | mail.size = size; |
146 | mail.downloaded = complete; | 146 | mail.downloaded = complete; |
147 | 147 | ||
148 | emit mailArrived(mail, FALSE); | 148 | emit mailArrived(mail, FALSE); |
149 | } | 149 | } |
150 | 150 | ||
151 | bool EmailHandler::parse(QString in, QString lineShift, Email *mail) | 151 | bool EmailHandler::parse(const QString &in, const QString &lineShift, Email *mail) |
152 | { | 152 | { |
153 | QString temp, boundary; | 153 | QString temp, boundary; |
154 | int pos; | 154 | int pos; |
155 | QString delimiter, header, body, mimeHeader, mimeBody; | 155 | QString delimiter, header, body, mimeHeader, mimeBody; |
156 | QString content, contentType, contentAttribute, id, encoding; | 156 | QString content, contentType, contentAttribute, id, encoding; |
157 | QString fileName, storedName; | 157 | QString fileName, storedName; |
158 | int enclosureId = 0; | 158 | int enclosureId = 0; |
159 | 159 | ||
160 | mail->rawMail = in; | 160 | mail->rawMail = in; |
161 | mail->received = TRUE; | 161 | mail->received = TRUE; |
162 | mail->files.setAutoDelete(TRUE); | 162 | mail->files.setAutoDelete(TRUE); |
163 | 163 | ||
164 | temp = lineShift + "." + lineShift; | 164 | temp = lineShift + "." + lineShift; |
165 | 165 | ||
166 | if (in.right(temp.length()) != temp) { | 166 | if (in.right(temp.length()) != temp) { |
167 | mail->rawMail += temp; | 167 | mail->rawMail += temp; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" | 171 | delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" |
172 | pos = in.find(delimiter, 0, FALSE); | 172 | pos = in.find(delimiter, 0, FALSE); |
173 | header = in.left(pos); | 173 | header = in.left(pos); |
174 | body = in.right(in.length() - pos - delimiter.length()); | 174 | body = in.right(in.length() - pos - delimiter.length()); |
175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) | 175 | if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) |
176 | body.truncate(body.length()-2); | 176 | body.truncate(body.length()-2); |
177 | 177 | ||
178 | TextParser p(header, lineShift); | 178 | TextParser p(header, lineShift); |
179 | 179 | ||
180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { | 180 | if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { |
181 | pos++; | 181 | pos++; |
182 | if (p.separatorAt(pos) == ' ') { | 182 | if (p.separatorAt(pos) == ' ') { |
183 | mail->from = p.getString(&pos, '<', false); | 183 | mail->from = p.getString(&pos, '<', false); |
184 | mail->from = mail->from.stripWhiteSpace(); | 184 | mail->from = mail->from.stripWhiteSpace(); |
185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { | 185 | if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { |
186 | mail->from = mail->from.left(mail->from.length() - 1); | 186 | mail->from = mail->from.left(mail->from.length() - 1); |
187 | mail->from = mail->from.right(mail->from.length() - 1); | 187 | mail->from = mail->from.right(mail->from.length() - 1); |
188 | } | 188 | } |
189 | pos++; | 189 | pos++; |
190 | mail->fromMail = p.getString(&pos, '>', false); | 190 | mail->fromMail = p.getString(&pos, '>', false); |
191 | } else { | 191 | } else { |
192 | if (p.separatorAt(pos) == '<') //No name.. nasty | 192 | if (p.separatorAt(pos) == '<') //No name.. nasty |
193 | pos++; | 193 | pos++; |
194 | //pos++; | 194 | //pos++; |
195 | mail->fromMail = p.getString(&pos, 'z', TRUE); | 195 | mail->fromMail = p.getString(&pos, 'z', TRUE); |
196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') | 196 | if (mail->fromMail.at(mail->fromMail.length()-1) == '>') |
197 | mail->fromMail.truncate(mail->fromMail.length() - 1); | 197 | mail->fromMail.truncate(mail->fromMail.length() - 1); |
198 | mail->from=mail->fromMail; | 198 | mail->from=mail->fromMail; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | pos=0; | 202 | pos=0; |
203 | 203 | ||
204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: | 204 | //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: |
205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) | 205 | while((pos = p.find("TO",':', pos+1, TRUE))!=-1) |
206 | { | 206 | { |
207 | QString rec; | 207 | QString rec; |
208 | 208 | ||
209 | if (p.separatorAt(pos-1)!='-')//The - separator means that this is a Delivered-To: or Reply-To: | 209 | if (p.separatorAt(pos-1)!='-') //The - separator means that this is a Delivered-To: or Reply-To: |
210 | { | 210 | { |
211 | pos++; | 211 | pos++; |
212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); | 212 | mail->recipients.append(p.getString(&pos, '\r', TRUE)); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | // | 215 | // |
216 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); | 216 | //if (pos==-1) mail->recipients.append (tr("undisclosed recipients") ); |
217 | 217 | ||
218 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) | 218 | if ((pos = p.find("CC",':', 0, TRUE)) != -1) |
219 | { | 219 | { |
220 | pos++; | 220 | pos++; |
221 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); | 221 | mail->carbonCopies.append (p.getString(&pos, 'z', TRUE) ); |
222 | } | 222 | } |
223 | 223 | ||
224 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { | 224 | if ((pos = p.find("SUBJECT",':', 0, TRUE)) != -1) { |
225 | pos++; | 225 | pos++; |
226 | mail->subject = p.getString(&pos, 'z', TRUE); | 226 | mail->subject = p.getString(&pos, 'z', TRUE); |
227 | } | 227 | } |
228 | 228 | ||
229 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { | 229 | if ((pos = p.find("DATE",':', 0, TRUE)) != -1) { |
230 | pos++; | 230 | pos++; |
231 | mail->date = p.getString(&pos, 'z', TRUE); | 231 | mail->date = p.getString(&pos, 'z', TRUE); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | 235 | ||
236 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { | 236 | if ((pos = p.find("MESSAGE",'-', 0, TRUE)) != -1) { |
237 | pos++; | 237 | pos++; |
238 | if ( (p.wordAt(pos).upper() == "ID") && | 238 | if ( (p.wordAt(pos).upper() == "ID") && |
239 | (p.separatorAt(pos) == ':') ) { | 239 | (p.separatorAt(pos) == ':') ) { |
240 | 240 | ||
241 | id = p.getString(&pos, 'z', TRUE); | 241 | id = p.getString(&pos, 'z', TRUE); |
242 | mail->id = id; | 242 | mail->id = id; |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | pos = 0; | 246 | pos = 0; |
247 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { | 247 | while ( ((pos = p.find("MIME",'-', pos, TRUE)) != -1) ) { |
248 | pos++; | 248 | pos++; |
249 | if ( (p.wordAt(pos).upper() == "VERSION") && | 249 | if ( (p.wordAt(pos).upper() == "VERSION") && |
250 | (p.separatorAt(pos) == ':') ) { | 250 | (p.separatorAt(pos) == ':') ) { |
251 | pos++; | 251 | pos++; |
252 | if (p.getString(&pos, 'z', true) == "1.0") { | 252 | if (p.getString(&pos, 'z', true) == "1.0") { |
253 | mail->mimeType = 1; | 253 | mail->mimeType = 1; |
254 | } | 254 | } |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | if (mail->mimeType == 1) { | 258 | if (mail->mimeType == 1) { |
259 | boundary = ""; | 259 | boundary = ""; |
260 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { | 260 | if ((pos = p.find("BOUNDARY", '=', 0, TRUE)) != -1) { |
261 | pos++; | 261 | pos++; |
262 | boundary = p.getString(&pos, 'z', true); | 262 | boundary = p.getString(&pos, 'z', true); |
263 | if (boundary[0] == '"') { | 263 | if (boundary[0] == '"') { |
264 | boundary = boundary.left(boundary.length() - 1); //strip " | 264 | boundary = boundary.left(boundary.length() - 1); //strip " |
265 | boundary = boundary.right(boundary.length() - 1); //strip " | 265 | boundary = boundary.right(boundary.length() - 1); //strip " |
266 | } | 266 | } |
267 | boundary = "--" + boundary; //create boundary field | 267 | boundary = "--" + boundary; //create boundary field |
268 | } | 268 | } |
269 | 269 | ||
@@ -395,167 +395,167 @@ int EmailHandler::parse64base(char *src, char *bufOut) { | |||
395 | 395 | ||
396 | //conversion table withouth table... | 396 | //conversion table withouth table... |
397 | for (int x = 0; x < 4; x++) { | 397 | for (int x = 0; x < 4; x++) { |
398 | c = src[x]; | 398 | c = src[x]; |
399 | 399 | ||
400 | if ( (int) c >= 'A' && (int) c <= 'Z') | 400 | if ( (int) c >= 'A' && (int) c <= 'Z') |
401 | li[x] = (int) c - (int) 'A'; | 401 | li[x] = (int) c - (int) 'A'; |
402 | if ( (int) c >= 'a' && (int) c <= 'z') | 402 | if ( (int) c >= 'a' && (int) c <= 'z') |
403 | li[x] = (int) c - (int) 'a' + 26; | 403 | li[x] = (int) c - (int) 'a' + 26; |
404 | if ( (int) c >= '0' && (int) c <= '9') | 404 | if ( (int) c >= '0' && (int) c <= '9') |
405 | li[x] = (int) c - (int) '0' + 52; | 405 | li[x] = (int) c - (int) '0' + 52; |
406 | if (c == '+') | 406 | if (c == '+') |
407 | li[x] = 62; | 407 | li[x] = 62; |
408 | if (c == '/') | 408 | if (c == '/') |
409 | li[x] = 63; | 409 | li[x] = 63; |
410 | } | 410 | } |
411 | 411 | ||
412 | processed = 1; | 412 | processed = 1; |
413 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits | 413 | bufOut[0] = (char) li[0] & (32+16+8+4+2+1); //mask out top 2 bits |
414 | bufOut[0] <<= 2; | 414 | bufOut[0] <<= 2; |
415 | z = li[1] >> 4; | 415 | z = li[1] >> 4; |
416 | bufOut[0] = bufOut[0] | z; //first byte retrived | 416 | bufOut[0] = bufOut[0] | z; //first byte retrived |
417 | 417 | ||
418 | if (src[2] != '=') { | 418 | if (src[2] != '=') { |
419 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits | 419 | bufOut[1] = (char) li[1] & (8+4+2+1); //mask out top 4 bits |
420 | bufOut[1] <<= 4; | 420 | bufOut[1] <<= 4; |
421 | z = li[2] >> 2; | 421 | z = li[2] >> 2; |
422 | bufOut[1] = bufOut[1] | z; //second byte retrived | 422 | bufOut[1] = bufOut[1] | z; //second byte retrived |
423 | processed++; | 423 | processed++; |
424 | 424 | ||
425 | if (src[3] != '=') { | 425 | if (src[3] != '=') { |
426 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits | 426 | bufOut[2] = (char) li[2] & (2+1); //mask out top 6 bits |
427 | bufOut[2] <<= 6; | 427 | bufOut[2] <<= 6; |
428 | z = li[3]; | 428 | z = li[3]; |
429 | bufOut[2] = bufOut[2] | z; //third byte retrieved | 429 | bufOut[2] = bufOut[2] | z; //third byte retrieved |
430 | processed++; | 430 | processed++; |
431 | } | 431 | } |
432 | } | 432 | } |
433 | return processed; | 433 | return processed; |
434 | } | 434 | } |
435 | 435 | ||
436 | int EmailHandler::encodeMime(Email *mail) | 436 | int EmailHandler::encodeMime(Email *mail) |
437 | { | 437 | { |
438 | 438 | ||
439 | QString fileName, fileType, contentType, newBody, boundary; | 439 | QString fileName, fileType, contentType, newBody, boundary; |
440 | Enclosure *ePtr; | 440 | Enclosure *ePtr; |
441 | 441 | ||
442 | QString userName = mailAccount.name; | 442 | QString userName = mailAccount.name; |
443 | if (userName.length()>0)//only embrace it if there is a user name | 443 | if (userName.length()>0) //only embrace it if there is a user name |
444 | userName += " <" + mailAccount.emailAddress + ">"; | 444 | userName += " <" + mailAccount.emailAddress + ">"; |
445 | 445 | ||
446 | //add standard headers | 446 | //add standard headers |
447 | newBody = "From: " + userName + "\r\nTo: "; | 447 | newBody = "From: " + userName + "\r\nTo: "; |
448 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { | 448 | for (QStringList::Iterator it = mail->recipients.begin(); it != mail->recipients.end(); ++it ) { |
449 | newBody += *it + " "; | 449 | newBody += *it + " "; |
450 | } | 450 | } |
451 | 451 | ||
452 | newBody += "\r\nCC: "; | 452 | newBody += "\r\nCC: "; |
453 | 453 | ||
454 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { | 454 | for (QStringList::Iterator it = mail->carbonCopies.begin(); it != mail->carbonCopies.end(); ++it ) { |
455 | newBody += *it + " "; | 455 | newBody += *it + " "; |
456 | } | 456 | } |
457 | 457 | ||
458 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; | 458 | newBody += "\r\nSubject: " + mail->subject + "\r\n"; |
459 | 459 | ||
460 | if (mail->files.count() == 0) { //just a simple mail | 460 | if (mail->files.count() == 0) { //just a simple mail |
461 | newBody += "\r\n" + mail->body; | 461 | newBody += "\r\n" + mail->body; |
462 | mail->rawMail = newBody; | 462 | mail->rawMail = newBody; |
463 | return 0; | 463 | return 0; |
464 | } | 464 | } |
465 | 465 | ||
466 | //Build mime encoded mail | 466 | //Build mime encoded mail |
467 | boundary = "-----4345=next_bound=0495----"; | 467 | boundary = "-----4345=next_bound=0495----"; |
468 | 468 | ||
469 | newBody += "Mime-Version: 1.0\r\n"; | 469 | newBody += "Mime-Version: 1.0\r\n"; |
470 | newBody += "Content-Type: multipart/mixed; boundary=\"" + | 470 | newBody += "Content-Type: multipart/mixed; boundary=\"" + |
471 | boundary + "\"\r\n\r\n"; | 471 | boundary + "\"\r\n\r\n"; |
472 | 472 | ||
473 | newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; | 473 | newBody += "This is a multipart message in Mime 1.0 format\r\n\r\n"; |
474 | newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; | 474 | newBody += "--" + boundary + "\r\nContent-Type: text/plain\r\n\r\n"; |
475 | newBody += mail->body; | 475 | newBody += mail->body; |
476 | 476 | ||
477 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { | 477 | for ( ePtr=mail->files.first(); ePtr != 0; ePtr=mail->files.next() ) { |
478 | fileName = ePtr->originalName; | 478 | fileName = ePtr->originalName; |
479 | fileType = ePtr->contentType; | 479 | fileType = ePtr->contentType; |
480 | QFileInfo fi(fileName); | 480 | QFileInfo fi(fileName); |
481 | 481 | ||
482 | // This specification of contentType is temporary | 482 | // This specification of contentType is temporary |
483 | contentType = ""; | 483 | contentType = ""; |
484 | if (fileType == "Picture") { | 484 | if (fileType == "Picture") { |
485 | contentType = "image/x-image"; | 485 | contentType = "image/x-image"; |
486 | } else if (fileType == "Document") { | 486 | } else if (fileType == "Document") { |
487 | contentType = "text/plain"; | 487 | contentType = "text/plain"; |
488 | } else if (fileType == "Sound") { | 488 | } else if (fileType == "Sound") { |
489 | contentType = "audio/x-wav"; | 489 | contentType = "audio/x-wav"; |
490 | } else if (fileType == "Movie") { | 490 | } else if (fileType == "Movie") { |
491 | contentType = "video/mpeg"; | 491 | contentType = "video/mpeg"; |
492 | } else { | 492 | } else { |
493 | contentType = "application/octet-stream"; | 493 | contentType = "application/octet-stream"; |
494 | } | 494 | } |
495 | 495 | ||
496 | newBody += "\r\n\r\n--" + boundary + "\r\n"; | 496 | newBody += "\r\n\r\n--" + boundary + "\r\n"; |
497 | newBody += "Content-Type: " + contentType + "; name=\"" + | 497 | newBody += "Content-Type: " + contentType + "; name=\"" + |
498 | fi.fileName() + "\"\r\n"; | 498 | fi.fileName() + "\"\r\n"; |
499 | newBody += "Content-Transfer-Encoding: base64\r\n"; | 499 | newBody += "Content-Transfer-Encoding: base64\r\n"; |
500 | newBody += "Content-Disposition: inline; filename=\"" + | 500 | newBody += "Content-Disposition: inline; filename=\"" + |
501 | fi.fileName() + "\"\r\n\r\n"; | 501 | fi.fileName() + "\"\r\n\r\n"; |
502 | 502 | ||
503 | if (encodeFile(fileName, &newBody) == -1) //file not found? | 503 | if (encodeFile(fileName, &newBody) == -1) //file not found? |
504 | return -1; | 504 | return -1; |
505 | } | 505 | } |
506 | 506 | ||
507 | newBody += "\r\n\r\n--" + boundary + "--"; | 507 | newBody += "\r\n\r\n--" + boundary + "--"; |
508 | mail->rawMail = newBody; | 508 | mail->rawMail = newBody; |
509 | 509 | ||
510 | return 0; | 510 | return 0; |
511 | } | 511 | } |
512 | 512 | ||
513 | int EmailHandler::encodeFile(QString fileName, QString *toBody) | 513 | int EmailHandler::encodeFile(const QString &fileName, QString *toBody) |
514 | { | 514 | { |
515 | char *fileData; | 515 | char *fileData; |
516 | char *dataPtr; | 516 | char *dataPtr; |
517 | QString temp; | 517 | QString temp; |
518 | uint dataSize, count; | 518 | uint dataSize, count; |
519 | QFile f(fileName); | 519 | QFile f(fileName); |
520 | 520 | ||
521 | if (! f.open(IO_ReadOnly) ) { | 521 | if (! f.open(IO_ReadOnly) ) { |
522 | qWarning("could not open file: " + fileName); | 522 | qWarning("could not open file: " + fileName); |
523 | return -1; | 523 | return -1; |
524 | } | 524 | } |
525 | QTextStream s(&f); | 525 | QTextStream s(&f); |
526 | dataSize = f.size(); | 526 | dataSize = f.size(); |
527 | fileData = (char *) malloc(dataSize + 3); | 527 | fileData = (char *) malloc(dataSize + 3); |
528 | s.readRawBytes(fileData, dataSize); | 528 | s.readRawBytes(fileData, dataSize); |
529 | 529 | ||
530 | temp = ""; | 530 | temp = ""; |
531 | dataPtr = fileData; | 531 | dataPtr = fileData; |
532 | count = 0; | 532 | count = 0; |
533 | while (dataSize > 0) { | 533 | while (dataSize > 0) { |
534 | if (dataSize < 3) { | 534 | if (dataSize < 3) { |
535 | encode64base(dataPtr, &temp, dataSize); | 535 | encode64base(dataPtr, &temp, dataSize); |
536 | dataSize = 0; | 536 | dataSize = 0; |
537 | } else { | 537 | } else { |
538 | encode64base(dataPtr, &temp, 3); | 538 | encode64base(dataPtr, &temp, 3); |
539 | dataSize -= 3; | 539 | dataSize -= 3; |
540 | dataPtr += 3; | 540 | dataPtr += 3; |
541 | count += 4; | 541 | count += 4; |
542 | } | 542 | } |
543 | if (count > 72) { | 543 | if (count > 72) { |
544 | count = 0; | 544 | count = 0; |
545 | temp += "\r\n"; | 545 | temp += "\r\n"; |
546 | } | 546 | } |
547 | } | 547 | } |
548 | toBody->append(temp); | 548 | toBody->append(temp); |
549 | 549 | ||
550 | delete(fileData); | 550 | delete(fileData); |
551 | f.close(); | 551 | f.close(); |
552 | return 0; | 552 | return 0; |
553 | } | 553 | } |
554 | 554 | ||
555 | void EmailHandler::encode64base(char *src, QString *dest, int len) | 555 | void EmailHandler::encode64base(char *src, QString *dest, int len) |
556 | { | 556 | { |
557 | QString temp; | 557 | QString temp; |
558 | uchar c; | 558 | uchar c; |
559 | uchar bufOut[4]; | 559 | uchar bufOut[4]; |
560 | 560 | ||
561 | bufOut[0] = src[0]; | 561 | bufOut[0] = src[0]; |
diff --git a/noncore/unsupported/mailit/emailhandler.h b/noncore/unsupported/mailit/emailhandler.h index 5b59f65..e4e7f46 100644 --- a/noncore/unsupported/mailit/emailhandler.h +++ b/noncore/unsupported/mailit/emailhandler.h | |||
@@ -1,150 +1,150 @@ | |||
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 | #ifndef EmailHandler_H | 20 | #ifndef EmailHandler_H |
21 | #define EmailHandler_H | 21 | #define EmailHandler_H |
22 | 22 | ||
23 | #include <qobject.h> | 23 | #include <qobject.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qdatetime.h> | 25 | #include <qdatetime.h> |
26 | #include <qlist.h> | 26 | #include <qlist.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qfile.h> | 28 | #include <qfile.h> |
29 | #include <qstringlist.h> | 29 | #include <qstringlist.h> |
30 | #include <qcollection.h> | 30 | #include <qcollection.h> |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | 32 | ||
33 | #include "smtpclient.h" | 33 | #include "smtpclient.h" |
34 | #include "popclient.h" | 34 | #include "popclient.h" |
35 | #include "textparser.h" | 35 | #include "textparser.h" |
36 | #include "maillist.h" | 36 | #include "maillist.h" |
37 | 37 | ||
38 | struct Enclosure | 38 | struct Enclosure |
39 | { | 39 | { |
40 | int id; | 40 | int id; |
41 | QString originalName; | 41 | QString originalName; |
42 | QString name; | 42 | QString name; |
43 | QString path; | 43 | QString path; |
44 | QString contentType; | 44 | QString contentType; |
45 | QString contentAttribute; | 45 | QString contentAttribute; |
46 | QString encoding; | 46 | QString encoding; |
47 | QString body; //might use to much mem. check!! | 47 | QString body; //might use to much mem. check!! |
48 | bool saved, installed; | 48 | bool saved, installed; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | class EnclosureList : public QList<Enclosure> | 51 | class EnclosureList : public QList<Enclosure> |
52 | { | 52 | { |
53 | public: | 53 | public: |
54 | Item newItem(Item d); | 54 | Item newItem(Item d); |
55 | private: | 55 | private: |
56 | Enclosure* dupl(Enclosure *in); | 56 | Enclosure* dupl(Enclosure *in); |
57 | Enclosure *ac; | 57 | Enclosure *ac; |
58 | }; | 58 | }; |
59 | 59 | ||
60 | struct Email | 60 | struct Email |
61 | { | 61 | { |
62 | QString id; | 62 | QString id; |
63 | QString from; | 63 | QString from; |
64 | QString fromMail; | 64 | QString fromMail; |
65 | QStringList recipients; | 65 | QStringList recipients; |
66 | QStringList carbonCopies; | 66 | QStringList carbonCopies; |
67 | QString date; | 67 | QString date; |
68 | QString subject; | 68 | QString subject; |
69 | QString body; | 69 | QString body; |
70 | QString bodyPlain; | 70 | QString bodyPlain; |
71 | bool sent, received, read, downloaded; | 71 | bool sent, received, read, downloaded; |
72 | QString rawMail; | 72 | QString rawMail; |
73 | int mimeType; //1 = Mime 1.0 | 73 | int mimeType; //1 = Mime 1.0 |
74 | int serverId; | 74 | int serverId; |
75 | int internalId; | 75 | int internalId; |
76 | int fromAccountId; | 76 | int fromAccountId; |
77 | QString contentType; //0 = text | 77 | QString contentType; //0 = text |
78 | QString contentAttribute; //0 = plain, 1 = html | 78 | QString contentAttribute; //0 = plain, 1 = html |
79 | EnclosureList files; | 79 | EnclosureList files; |
80 | uint size; | 80 | uint size; |
81 | 81 | ||
82 | void addEnclosure(Enclosure *e) | 82 | void addEnclosure(Enclosure *e) |
83 | { | 83 | { |
84 | files.append(e); | 84 | files.append(e); |
85 | } | 85 | } |
86 | }; | 86 | }; |
87 | 87 | ||
88 | struct MailAccount | 88 | struct MailAccount |
89 | { | 89 | { |
90 | QString accountName; | 90 | QString accountName; |
91 | QString name; | 91 | QString name; |
92 | QString emailAddress; | 92 | QString emailAddress; |
93 | QString popUserName; | 93 | QString popUserName; |
94 | QString popPasswd; | 94 | QString popPasswd; |
95 | QString popServer; | 95 | QString popServer; |
96 | QString smtpServer; | 96 | QString smtpServer; |
97 | bool synchronize; | 97 | bool synchronize; |
98 | int syncLimit; | 98 | int syncLimit; |
99 | int lastServerMailCount; | 99 | int lastServerMailCount; |
100 | int id; | 100 | int id; |
101 | }; | 101 | }; |
102 | 102 | ||
103 | const int ErrUnknownResponse = 1001; | 103 | const int ErrUnknownResponse = 1001; |
104 | const int ErrLoginFailed = 1002; | 104 | const int ErrLoginFailed = 1002; |
105 | const int ErrCancel = 1003; | 105 | const int ErrCancel = 1003; |
106 | 106 | ||
107 | 107 | ||
108 | class EmailHandler : public QObject | 108 | class EmailHandler : public QObject |
109 | { | 109 | { |
110 | Q_OBJECT | 110 | Q_OBJECT |
111 | 111 | ||
112 | public: | 112 | public: |
113 | EmailHandler(); | 113 | EmailHandler(); |
114 | void setAccount(MailAccount account); | 114 | void setAccount(MailAccount account); |
115 | MailAccount* getAccount(){return &mailAccount;} | 115 | MailAccount* getAccount(){return &mailAccount;} |
116 | void sendMail(QList<Email> *mailList); | 116 | void sendMail(QList<Email> *mailList); |
117 | void getMail(); | 117 | void getMail(); |
118 | void getMailHeaders(); | 118 | void getMailHeaders(); |
119 | void getMailByList(MailList *mailList); | 119 | void getMailByList(MailList *mailList); |
120 | bool parse(QString in, QString lineShift, Email *mail); | 120 | bool parse(const QString &in, const QString &lineShift, Email *mail); |
121 | bool getEnclosure(Enclosure *ePtr); | 121 | bool getEnclosure(Enclosure *ePtr); |
122 | int parse64base(char *src, char *dest); | 122 | int parse64base(char *src, char *dest); |
123 | int encodeMime(Email *mail); | 123 | int encodeMime(Email *mail); |
124 | int encodeFile(QString fileName, QString *toBody); | 124 | int encodeFile(const QString &fileName, QString *toBody); |
125 | void encode64base(char *src, QString *dest, int len); | 125 | void encode64base(char *src, QString *dest, int len); |
126 | void cancel(); | 126 | void cancel(); |
127 | 127 | ||
128 | signals: | 128 | signals: |
129 | void mailSent(); | 129 | void mailSent(); |
130 | void smtpError(int); | 130 | void smtpError(int); |
131 | void popError(int); | 131 | void popError(int); |
132 | void mailArrived(const Email &, bool); | 132 | void mailArrived(const Email &, bool); |
133 | void updatePopStatus(const QString &); | 133 | void updatePopStatus(const QString &); |
134 | void updateSmtpStatus(const QString &); | 134 | void updateSmtpStatus(const QString &); |
135 | void mailTransfered(int); | 135 | void mailTransfered(int); |
136 | void mailboxSize(int); | 136 | void mailboxSize(int); |
137 | void currentMailSize(int); | 137 | void currentMailSize(int); |
138 | void downloadedSize(int); | 138 | void downloadedSize(int); |
139 | 139 | ||
140 | public slots: | 140 | public slots: |
141 | void messageArrived(const QString &, int id, uint size, bool complete); | 141 | void messageArrived(const QString &, int id, uint size, bool complete); |
142 | 142 | ||
143 | private: | 143 | private: |
144 | MailAccount mailAccount; | 144 | MailAccount mailAccount; |
145 | SmtpClient *smtpClient; | 145 | SmtpClient *smtpClient; |
146 | PopClient *popClient; | 146 | PopClient *popClient; |
147 | bool headers; | 147 | bool headers; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | #endif | 150 | #endif |
diff --git a/noncore/unsupported/mailit/emaillistitem.cpp b/noncore/unsupported/mailit/emaillistitem.cpp index b925a1c..fc9f766 100644 --- a/noncore/unsupported/mailit/emaillistitem.cpp +++ b/noncore/unsupported/mailit/emaillistitem.cpp | |||
@@ -1,99 +1,99 @@ | |||
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 <qstring.h> | 20 | #include <qstring.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include "emaillistitem.h" | 22 | #include "emaillistitem.h" |
23 | 23 | ||
24 | EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox) | 24 | EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox) |
25 | : QListViewItem(parent) | 25 | : QListViewItem(parent) |
26 | { | 26 | { |
27 | QString temp; | 27 | QString temp; |
28 | 28 | ||
29 | mail = mailIn; | 29 | mail = mailIn; |
30 | 30 | ||
31 | if (inbox) { | 31 | if (inbox) { |
32 | setText(0, mail.from); | 32 | setText(0, mail.from); |
33 | } else { | 33 | } else { |
34 | QStringList::Iterator it = mail.recipients.begin(); | 34 | QStringList::Iterator it = mail.recipients.begin(); |
35 | temp = *it; | 35 | temp = *it; |
36 | if (mail.recipients.count() > 1) | 36 | if (mail.recipients.count() > 1) |
37 | temp += "..."; | 37 | temp += "..."; |
38 | setText(0, temp); | 38 | setText(0, temp); |
39 | } | 39 | } |
40 | setText(1, mail.subject); | 40 | setText(1, mail.subject); |
41 | setText(2,mail.date); | 41 | setText(2,mail.date); |
42 | 42 | ||
43 | if (mailIn.files.count()>0) | 43 | if (mailIn.files.count()>0) |
44 | { | 44 | { |
45 | setPixmap(0, Resource::loadPixmap("mailit/attach")); | 45 | setPixmap(0, Resource::loadPixmap("mailit/attach")); |
46 | } | 46 | } |
47 | 47 | ||
48 | selected = FALSE; | 48 | selected = FALSE; |
49 | } | 49 | } |
50 | 50 | ||
51 | Email* EmailListItem::getMail() | 51 | Email* EmailListItem::getMail() |
52 | { | 52 | { |
53 | return &mail; | 53 | return &mail; |
54 | } | 54 | } |
55 | 55 | ||
56 | void EmailListItem::setMail(Email newMail) | 56 | void EmailListItem::setMail(Email newMail) |
57 | { | 57 | { |
58 | mail = newMail; | 58 | mail = newMail; |
59 | repaint(); | 59 | repaint(); |
60 | } | 60 | } |
61 | 61 | ||
62 | void EmailListItem::setItemSelected(bool enable) | 62 | void EmailListItem::setItemSelected(bool enable) |
63 | { | 63 | { |
64 | selected = enable; | 64 | selected = enable; |
65 | setSelected(enable); | 65 | setSelected(enable); |
66 | repaint(); | 66 | repaint(); |
67 | } | 67 | } |
68 | 68 | ||
69 | bool EmailListItem::isItemSelected() | 69 | bool EmailListItem::isItemSelected() |
70 | { | 70 | { |
71 | return selected; | 71 | return selected; |
72 | } | 72 | } |
73 | 73 | ||
74 | void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg, | 74 | void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg, |
75 | int column, int width, int alignment ) | 75 | int column, int width, int alignment ) |
76 | { | 76 | { |
77 | 77 | ||
78 | QColorGroup _cg( cg ); | 78 | QColorGroup _cg( cg ); |
79 | QColor c = _cg.text(); | 79 | QColor c = _cg.text(); |
80 | 80 | ||
81 | if ( (! mail.read) && (mail.received) ) | 81 | if ( (! mail.read) && (mail.received) ) |
82 | _cg.setColor( QColorGroup::Text, Qt::blue); | 82 | _cg.setColor( QColorGroup::Text, Qt::blue); |
83 | if (!mail.downloaded) | 83 | if (!mail.downloaded) |
84 | _cg.setColor( QColorGroup::Text, Qt::red); | 84 | _cg.setColor( QColorGroup::Text, Qt::red); |
85 | 85 | ||
86 | /*if (selected) { | 86 | /* if (selected) { |
87 | _cg.setColor(QColorGroup::Base, Qt::blue); | 87 | _cg.setColor(QColorGroup::Base, Qt::blue); |
88 | _cg.setColor(QColorGroup::Text, Qt::yellow); | 88 | _cg.setColor(QColorGroup::Text, Qt::yellow); |
89 | if (isSelected()) { | 89 | if (isSelected()) { |
90 | _cg.setColor(QColorGroup::HighlightedText, Qt::yellow); | 90 | _cg.setColor(QColorGroup::HighlightedText, Qt::yellow); |
91 | } else { | 91 | } else { |
92 | _cg.setColor(QColorGroup::Highlight, Qt::blue); | 92 | _cg.setColor(QColorGroup::Highlight, Qt::blue); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | */ | 95 | */ |
96 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 96 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
97 | 97 | ||
98 | _cg.setColor( QColorGroup::Text, c ); | 98 | _cg.setColor( QColorGroup::Text, c ); |
99 | } | 99 | } |
diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp index fedc4e2..dc0116d 100644 --- a/noncore/unsupported/mailit/popclient.cpp +++ b/noncore/unsupported/mailit/popclient.cpp | |||
@@ -5,323 +5,323 @@ | |||
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 | 32 | ||
33 | socket = new QSocket(this, "popClient"); | 33 | socket = new QSocket(this, "popClient"); |
34 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); | 34 | connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); |
35 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); | 35 | connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
36 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); | 36 | connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); |
37 | 37 | ||
38 | stream = new QTextStream(socket); | 38 | stream = new QTextStream(socket); |
39 | 39 | ||
40 | receiving = FALSE; | 40 | receiving = FALSE; |
41 | synchronize = FALSE; | 41 | synchronize = FALSE; |
42 | lastSync = 0; | 42 | lastSync = 0; |
43 | headerLimit = 0; | 43 | headerLimit = 0; |
44 | preview = FALSE; | 44 | preview = FALSE; |
45 | } | 45 | } |
46 | 46 | ||
47 | PopClient::~PopClient() | 47 | PopClient::~PopClient() |
48 | { | 48 | { |
49 | delete socket; | 49 | delete socket; |
50 | delete stream; | 50 | delete stream; |
51 | } | 51 | } |
52 | 52 | ||
53 | void PopClient::newConnection(QString target, int port) | 53 | void PopClient::newConnection(const QString &target, int port) |
54 | { | 54 | { |
55 | if (receiving) { | 55 | if (receiving) { |
56 | qWarning("socket in use, connection refused"); | 56 | qWarning("socket in use, connection refused"); |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | 59 | ||
60 | status = Init; | 60 | status = Init; |
61 | 61 | ||
62 | socket->connectToHost(target, port); | 62 | socket->connectToHost(target, port); |
63 | receiving = TRUE; | 63 | receiving = TRUE; |
64 | //selected = FALSE; | 64 | //selected = FALSE; |
65 | 65 | ||
66 | emit updateStatus("DNS lookup"); | 66 | emit updateStatus("DNS lookup"); |
67 | } | 67 | } |
68 | 68 | ||
69 | void PopClient::setAccount(QString popUser, QString popPasswd) | 69 | void PopClient::setAccount(const QString &popUser, const QString &popPasswd) |
70 | { | 70 | { |
71 | popUserName = popUser; | 71 | popUserName = popUser; |
72 | popPassword = popPasswd; | 72 | popPassword = popPasswd; |
73 | } | 73 | } |
74 | 74 | ||
75 | void PopClient::setSynchronize(int lastCount) | 75 | void PopClient::setSynchronize(int lastCount) |
76 | { | 76 | { |
77 | synchronize = TRUE; | 77 | synchronize = TRUE; |
78 | lastSync = lastCount; | 78 | lastSync = lastCount; |
79 | } | 79 | } |
80 | 80 | ||
81 | void PopClient::removeSynchronize() | 81 | void PopClient::removeSynchronize() |
82 | { | 82 | { |
83 | synchronize = FALSE; | 83 | synchronize = FALSE; |
84 | lastSync = 0; | 84 | lastSync = 0; |
85 | } | 85 | } |
86 | 86 | ||
87 | void PopClient::headersOnly(bool headers, int limit) | 87 | void PopClient::headersOnly(bool headers, int limit) |
88 | { | 88 | { |
89 | preview = headers; | 89 | preview = headers; |
90 | headerLimit = limit; | 90 | headerLimit = limit; |
91 | } | 91 | } |
92 | 92 | ||
93 | void PopClient::setSelectedMails(MailList *list) | 93 | void PopClient::setSelectedMails(MailList *list) |
94 | { | 94 | { |
95 | selected = TRUE; | 95 | selected = TRUE; |
96 | mailList = list; | 96 | mailList = list; |
97 | } | 97 | } |
98 | 98 | ||
99 | void PopClient::connectionEstablished() | 99 | void PopClient::connectionEstablished() |
100 | { | 100 | { |
101 | emit updateStatus(tr("Connection established")); | 101 | emit updateStatus(tr("Connection established")); |
102 | } | 102 | } |
103 | 103 | ||
104 | void PopClient::errorHandling(int status) | 104 | void PopClient::errorHandling(int status) |
105 | { | 105 | { |
106 | emit updateStatus(tr("Error Occured")); | 106 | emit updateStatus(tr("Error Occured")); |
107 | emit errorOccurred(status); | 107 | emit errorOccurred(status); |
108 | socket->close(); | 108 | socket->close(); |
109 | receiving = FALSE; | 109 | receiving = FALSE; |
110 | } | 110 | } |
111 | 111 | ||
112 | void PopClient::incomingData() | 112 | void PopClient::incomingData() |
113 | { | 113 | { |
114 | QString response, temp, temp2, timeStamp; | 114 | QString response, temp, temp2, timeStamp; |
115 | QString md5Source; | 115 | QString md5Source; |
116 | int start, end; | 116 | int start, end; |
117 | // char *md5Digest; | 117 | // char *md5Digest; |
118 | char md5Digest[16]; | 118 | char md5Digest[16]; |
119 | // if ( !socket->canReadLine() ) | 119 | // if ( !socket->canReadLine() ) |
120 | // return; | 120 | // return; |
121 | 121 | ||
122 | 122 | ||
123 | response = socket->readLine(); | 123 | response = socket->readLine(); |
124 | 124 | ||
125 | switch(status) { | 125 | switch(status) { |
126 | //logging in | 126 | //logging in |
127 | case Init: { | 127 | case Init: { |
128 | #ifdef APOP_TEST | 128 | #ifdef APOP_TEST |
129 | start = response.find('<',0); | 129 | start = response.find('<',0); |
130 | end = response.find('>', start); | 130 | end = response.find('>', start); |
131 | if( start >= 0 && end > start ) | 131 | if( start >= 0 && end > start ) |
132 | { | 132 | { |
133 | timeStamp = response.mid( start , end - start + 1); | 133 | timeStamp = response.mid( start , end - start + 1); |
134 | md5Source = timeStamp + popPassword; | 134 | md5Source = timeStamp + popPassword; |
135 | 135 | ||
136 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); | 136 | md5_buffer( (char const *)md5Source, md5Source.length(),&md5Digest[0]); |
137 | 137 | ||
138 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) | 138 | for(int j =0;j < MD5_DIGEST_LENGTH ;j++) |
139 | { | 139 | { |
140 | printf("%x", md5Digest[j]); | 140 | printf("%x", md5Digest[j]); |
141 | } | 141 | } |
142 | printf("\n"); | 142 | printf("\n"); |
143 | // qDebug(md5Digest); | 143 | // qDebug(md5Digest); |
144 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; | 144 | *stream << "APOP " << popUserName << " " << md5Digest << "\r\n"; |
145 | // qDebug("%s", stream); | 145 | // qDebug("%s", stream); |
146 | status = Stat; | 146 | status = Stat; |
147 | } | 147 | } |
148 | else | 148 | else |
149 | #endif | 149 | #endif |
150 | { | 150 | { |
151 | timeStamp = ""; | 151 | timeStamp = ""; |
152 | *stream << "USER " << popUserName << "\r\n"; | 152 | *stream << "USER " << popUserName << "\r\n"; |
153 | status = Pass; | 153 | status = Pass; |
154 | } | 154 | } |
155 | 155 | ||
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | 158 | ||
159 | case Pass: { | 159 | case Pass: { |
160 | *stream << "PASS " << popPassword << "\r\n"; | 160 | *stream << "PASS " << popPassword << "\r\n"; |
161 | status = Stat; | 161 | status = Stat; |
162 | 162 | ||
163 | break; | 163 | break; |
164 | } | 164 | } |
165 | //ask for number of messages | 165 | //ask for number of messages |
166 | case Stat: { | 166 | case Stat: { |
167 | if (response[0] == '+') { | 167 | if (response[0] == '+') { |
168 | *stream << "STAT" << "\r\n"; | 168 | *stream << "STAT" << "\r\n"; |
169 | status = Mcnt; | 169 | status = Mcnt; |
170 | } else errorHandling(ErrLoginFailed); | 170 | } else errorHandling(ErrLoginFailed); |
171 | break; | 171 | break; |
172 | } | 172 | } |
173 | //get count of messages, eg "+OK 4 900.." -> int 4 | 173 | //get count of messages, eg "+OK 4 900.." -> int 4 |
174 | case Mcnt: { | 174 | case Mcnt: { |
175 | if (response[0] == '+') { | 175 | if (response[0] == '+') { |
176 | temp = response.replace(0, 4, ""); | 176 | temp = response.replace(0, 4, ""); |
177 | int x = temp.find(" ", 0); | 177 | int x = temp.find(" ", 0); |
178 | temp.truncate((uint) x); | 178 | temp.truncate((uint) x); |
179 | newMessages = temp.toInt(); | 179 | newMessages = temp.toInt(); |
180 | messageCount = 1; | 180 | messageCount = 1; |
181 | status = List; | 181 | status = List; |
182 | 182 | ||
183 | if (synchronize) { | 183 | if (synchronize) { |
184 | //messages deleted from server, reload all | 184 | //messages deleted from server, reload all |
185 | if (newMessages < lastSync) | 185 | if (newMessages < lastSync) |
186 | lastSync = 0; | 186 | lastSync = 0; |
187 | messageCount = 1; | 187 | messageCount = 1; |
188 | } | 188 | } |
189 | 189 | ||
190 | if (selected) { | 190 | if (selected) { |
191 | int *ptr = mailList->first(); | 191 | int *ptr = mailList->first(); |
192 | if (ptr != 0) { | 192 | if (ptr != 0) { |
193 | newMessages++; //to ensure no early jumpout | 193 | newMessages++; //to ensure no early jumpout |
194 | messageCount = *ptr; | 194 | messageCount = *ptr; |
195 | } else newMessages = 0; | 195 | } else newMessages = 0; |
196 | } | 196 | } |
197 | 197 | ||
198 | } else errorHandling(ErrUnknownResponse); | 198 | } else errorHandling(ErrUnknownResponse); |
199 | } | 199 | } |
200 | //Read message number x, count upwards to messageCount | 200 | //Read message number x, count upwards to messageCount |
201 | case List: { | 201 | case List: { |
202 | if (messageCount <= newMessages) { | 202 | if (messageCount <= newMessages) { |
203 | *stream << "LIST " << messageCount << "\r\n"; | 203 | *stream << "LIST " << messageCount << "\r\n"; |
204 | status = Size; | 204 | status = Size; |
205 | temp2.setNum(newMessages - lastSync); | 205 | temp2.setNum(newMessages - lastSync); |
206 | temp.setNum(messageCount - lastSync); | 206 | temp.setNum(messageCount - lastSync); |
207 | if (!selected) { | 207 | if (!selected) { |
208 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 208 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
209 | } else { | 209 | } else { |
210 | //completing a previously closed transfer | 210 | //completing a previously closed transfer |
211 | /* if ( (messageCount - lastSync) <= 0) { | 211 | /* if ( (messageCount - lastSync) <= 0) { |
212 | temp.setNum(messageCount); | 212 | temp.setNum(messageCount); |
213 | emit updateStatus(tr("Previous message ") + temp); | 213 | emit updateStatus(tr("Previous message ") + temp); |
214 | } else {*/ | 214 | } else {*/ |
215 | emit updateStatus(tr("Completing message ") + temp); | 215 | emit updateStatus(tr("Completing message ") + temp); |
216 | //} | 216 | //} |
217 | } | 217 | } |
218 | break; | 218 | break; |
219 | } else { | 219 | } else { |
220 | emit updateStatus(tr("No new Messages")); | 220 | emit updateStatus(tr("No new Messages")); |
221 | status = Quit; | 221 | status = Quit; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | //get size of message, eg "500 characters in message.." -> int 500 | 224 | //get size of message, eg "500 characters in message.." -> int 500 |
225 | case Size: { | 225 | case Size: { |
226 | if (status != Quit) { //because of idiotic switch | 226 | if (status != Quit) { //because of idiotic switch |
227 | if (response[0] == '+') { | 227 | if (response[0] == '+') { |
228 | temp = response.replace(0, 4, ""); | 228 | temp = response.replace(0, 4, ""); |
229 | int x = temp.find(" ", 0); | 229 | int x = temp.find(" ", 0); |
230 | temp = temp.right(temp.length() - ((uint) x + 1) ); | 230 | temp = temp.right(temp.length() - ((uint) x + 1) ); |
231 | mailSize = temp.toInt(); | 231 | mailSize = temp.toInt(); |
232 | emit currentMailSize(mailSize); | 232 | emit currentMailSize(mailSize); |
233 | 233 | ||
234 | status = Retr; | 234 | status = Retr; |
235 | } else { | 235 | } else { |
236 | //qWarning(response); | 236 | //qWarning(response); |
237 | errorHandling(ErrUnknownResponse); | 237 | errorHandling(ErrUnknownResponse); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | } | 240 | } |
241 | //Read message number x, count upwards to messageCount | 241 | //Read message number x, count upwards to messageCount |
242 | case Retr: { | 242 | case Retr: { |
243 | if (status != Quit) { | 243 | if (status != Quit) { |
244 | if ((selected)||(mailSize <= headerLimit)) | 244 | if ((selected)||(mailSize <= headerLimit)) |
245 | { | 245 | { |
246 | *stream << "RETR " << messageCount << "\r\n"; | 246 | *stream << "RETR " << messageCount << "\r\n"; |
247 | } else { //only header | 247 | } else { //only header |
248 | *stream << "TOP " << messageCount << " 0\r\n"; | 248 | *stream << "TOP " << messageCount << " 0\r\n"; |
249 | } | 249 | } |
250 | messageCount++; | 250 | messageCount++; |
251 | status = Ignore; | 251 | status = Ignore; |
252 | break; | 252 | break; |
253 | } } | 253 | } } |
254 | case Ignore: { | 254 | case Ignore: { |
255 | if (status != Quit) { //because of idiotic switch | 255 | if (status != Quit) { //because of idiotic switch |
256 | if (response[0] == '+') { | 256 | if (response[0] == '+') { |
257 | message = ""; | 257 | message = ""; |
258 | status = Read; | 258 | status = Read; |
259 | if (!socket->canReadLine()) //sync. problems | 259 | if (!socket->canReadLine()) //sync. problems |
260 | break; | 260 | break; |
261 | response = socket->readLine(); | 261 | response = socket->readLine(); |
262 | } else errorHandling(ErrUnknownResponse); | 262 | } else errorHandling(ErrUnknownResponse); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | //add all incoming lines to body. When size is reached, send | 265 | //add all incoming lines to body. When size is reached, send |
266 | //message, and go back to read new message | 266 | //message, and go back to read new message |
267 | case Read: { | 267 | case Read: { |
268 | if (status != Quit) { //because of idiotic switch | 268 | if (status != Quit) { //because of idiotic switch |
269 | message += response; | 269 | message += response; |
270 | while ( socket->canReadLine() ) { | 270 | while ( socket->canReadLine() ) { |
271 | response = socket->readLine(); | 271 | response = socket->readLine(); |
272 | message += response; | 272 | message += response; |
273 | } | 273 | } |
274 | emit downloadedSize(message.length()); | 274 | emit downloadedSize(message.length()); |
275 | int x = message.find("\r\n.\r\n",-5); | 275 | int x = message.find("\r\n.\r\n",-5); |
276 | if (x == -1) { | 276 | if (x == -1) { |
277 | break; | 277 | break; |
278 | } else { //message reach entire size | 278 | } else { //message reach entire size |
279 | if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active | 279 | if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active |
280 | { | 280 | { |
281 | emit newMessage(message, messageCount-1, mailSize, TRUE); | 281 | emit newMessage(message, messageCount-1, mailSize, TRUE); |
282 | } else { //incomplete mail downloaded | 282 | } else { //incomplete mail downloaded |
283 | emit newMessage(message, messageCount-1, mailSize, FALSE); | 283 | emit newMessage(message, messageCount-1, mailSize, FALSE); |
284 | } | 284 | } |
285 | 285 | ||
286 | if ((messageCount > newMessages)||(selected)) //last message ? | 286 | if ((messageCount > newMessages)||(selected)) //last message ? |
287 | { | 287 | { |
288 | status = Quit; | 288 | status = Quit; |
289 | if (selected) { //grab next from queue | 289 | if (selected) { //grab next from queue |
290 | newMessages--; | 290 | newMessages--; |
291 | status = Quit; | 291 | status = Quit; |
292 | } | 292 | } |
293 | } | 293 | } |
294 | else | 294 | else |
295 | { | 295 | { |
296 | *stream << "LIST " << messageCount << "\r\n"; | 296 | *stream << "LIST " << messageCount << "\r\n"; |
297 | status = Size; | 297 | status = Size; |
298 | temp2.setNum(newMessages - lastSync); | 298 | temp2.setNum(newMessages - lastSync); |
299 | temp.setNum(messageCount - lastSync); | 299 | temp.setNum(messageCount - lastSync); |
300 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); | 300 | emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); |
301 | 301 | ||
302 | break; | 302 | break; |
303 | } | 303 | } |
304 | } | 304 | } |
305 | } | 305 | } |
306 | if (status != Quit) | 306 | if (status != Quit) |
307 | break; | 307 | break; |
308 | } | 308 | } |
309 | case Quit: { | 309 | case Quit: { |
310 | *stream << "Quit\r\n"; | 310 | *stream << "Quit\r\n"; |
311 | status = Done; | 311 | status = Done; |
312 | int newM = newMessages - lastSync; | 312 | int newM = newMessages - lastSync; |
313 | if (newM > 0) { | 313 | if (newM > 0) { |
314 | temp.setNum(newM); | 314 | temp.setNum(newM); |
315 | emit updateStatus(temp + tr(" new messages")); | 315 | emit updateStatus(temp + tr(" new messages")); |
316 | } else { | 316 | } else { |
317 | emit updateStatus(tr("No new messages")); | 317 | emit updateStatus(tr("No new messages")); |
318 | } | 318 | } |
319 | 319 | ||
320 | socket->close(); | 320 | socket->close(); |
321 | receiving = FALSE; | 321 | receiving = FALSE; |
322 | emit mailTransfered(newM); | 322 | emit mailTransfered(newM); |
323 | break; | 323 | break; |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | } | 327 | } |
diff --git a/noncore/unsupported/mailit/popclient.h b/noncore/unsupported/mailit/popclient.h index 10b71ab..c58bc48 100644 --- a/noncore/unsupported/mailit/popclient.h +++ b/noncore/unsupported/mailit/popclient.h | |||
@@ -1,76 +1,76 @@ | |||
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 | #ifndef PopClient_H | 20 | #ifndef PopClient_H |
21 | #define PopClient_H | 21 | #define PopClient_H |
22 | 22 | ||
23 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <qsocket.h> | 24 | #include <qsocket.h> |
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | #include <qlist.h> | 28 | #include <qlist.h> |
29 | #include "maillist.h" | 29 | #include "maillist.h" |
30 | 30 | ||
31 | class PopClient: public QObject | 31 | class PopClient: public QObject |
32 | { | 32 | { |
33 | Q_OBJECT | 33 | Q_OBJECT |
34 | 34 | ||
35 | public: | 35 | public: |
36 | PopClient(); | 36 | PopClient(); |
37 | ~PopClient(); | 37 | ~PopClient(); |
38 | void newConnection(QString target, int port); | 38 | void newConnection(const QString &target, int port); |
39 | void setAccount(QString popUser, QString popPasswd); | 39 | void setAccount(const QString &popUser, const QString &popPasswd); |
40 | void setSynchronize(int lastCount); | 40 | void setSynchronize(int lastCount); |
41 | void removeSynchronize(); | 41 | void removeSynchronize(); |
42 | void headersOnly(bool headers, int limit); | 42 | void headersOnly(bool headers, int limit); |
43 | void setSelectedMails(MailList *list); | 43 | void setSelectedMails(MailList *list); |
44 | 44 | ||
45 | signals: | 45 | signals: |
46 | void newMessage(const QString &, int, uint, bool); | 46 | void newMessage(const QString &, int, uint, bool); |
47 | void errorOccurred(int status); | 47 | void errorOccurred(int status); |
48 | void updateStatus(const QString &); | 48 | void updateStatus(const QString &); |
49 | void mailTransfered(int); | 49 | void mailTransfered(int); |
50 | void mailboxSize(int); | 50 | void mailboxSize(int); |
51 | void currentMailSize(int); | 51 | void currentMailSize(int); |
52 | void downloadedSize(int); | 52 | void downloadedSize(int); |
53 | 53 | ||
54 | public slots: | 54 | public slots: |
55 | void errorHandling(int); | 55 | void errorHandling(int); |
56 | 56 | ||
57 | protected slots: | 57 | protected slots: |
58 | void connectionEstablished(); | 58 | void connectionEstablished(); |
59 | void incomingData(); | 59 | void incomingData(); |
60 | 60 | ||
61 | private: | 61 | private: |
62 | QSocket *socket; | 62 | QSocket *socket; |
63 | QTextStream *stream; | 63 | QTextStream *stream; |
64 | enum transferStatus | 64 | enum transferStatus |
65 | { | 65 | { |
66 | Init, Pass, Stat, Mcnt, Read, List, Size, Retr, Acks, | 66 | Init, Pass, Stat, Mcnt, Read, List, Size, Retr, Acks, |
67 | Quit, Done, Ignore | 67 | Quit, Done, Ignore |
68 | }; | 68 | }; |
69 | int status, lastSync; | 69 | int status, lastSync; |
70 | int messageCount, newMessages, mailSize, headerLimit; | 70 | int messageCount, newMessages, mailSize, headerLimit; |
71 | bool receiving, synchronize, preview, selected; | 71 | bool receiving, synchronize, preview, selected; |
72 | QString popUserName, popPassword, message; | 72 | QString popUserName, popPassword, message; |
73 | MailList *mailList; | 73 | MailList *mailList; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | #endif | 76 | #endif |
diff --git a/noncore/unsupported/mailit/smtpclient.cpp b/noncore/unsupported/mailit/smtpclient.cpp index 8a51a5b..2916f45 100644 --- a/noncore/unsupported/mailit/smtpclient.cpp +++ b/noncore/unsupported/mailit/smtpclient.cpp | |||
@@ -1,104 +1,104 @@ | |||
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(const 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(const QString &from, const QString &subject, const QStringList &to, const 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 | 90 | ||
91 | switch(status) { | 91 | switch(status) { |
92 | case Init: { | 92 | case Init: { |
93 | if (response[0] == '2') { | 93 | if (response[0] == '2') { |
94 | status = From; | 94 | status = From; |
95 | mailPtr = mailList.first(); | 95 | mailPtr = mailList.first(); |
96 | *stream << "HELO there\r\n"; | 96 | *stream << "HELO there\r\n"; |
97 | } else errorHandling(ErrUnknownResponse); | 97 | } else errorHandling(ErrUnknownResponse); |
98 | break; | 98 | break; |
99 | } | 99 | } |
100 | case From: { | 100 | case From: { |
101 | if (response[0] == '2') { | 101 | if (response[0] == '2') { |
102 | *stream << "MAIL FROM: " << mailPtr->from << "\r\n"; | 102 | *stream << "MAIL FROM: " << mailPtr->from << "\r\n"; |
103 | status = Recv; | 103 | status = Recv; |
104 | } else errorHandling(ErrUnknownResponse); | 104 | } else errorHandling(ErrUnknownResponse); |
diff --git a/noncore/unsupported/mailit/smtpclient.h b/noncore/unsupported/mailit/smtpclient.h index ca65af4..45c0703 100644 --- a/noncore/unsupported/mailit/smtpclient.h +++ b/noncore/unsupported/mailit/smtpclient.h | |||
@@ -1,75 +1,75 @@ | |||
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 | #ifndef SmtpClient_H | 20 | #ifndef SmtpClient_H |
21 | #define SmtpClient_H | 21 | #define SmtpClient_H |
22 | 22 | ||
23 | //#include <stdio.h> | 23 | //#include <stdio.h> |
24 | #include <qsocket.h> | 24 | #include <qsocket.h> |
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <qlist.h> | 29 | #include <qlist.h> |
30 | 30 | ||
31 | struct RawEmail | 31 | struct RawEmail |
32 | { | 32 | { |
33 | QString from; | 33 | QString from; |
34 | QString subject; | 34 | QString subject; |
35 | QStringList to; | 35 | QStringList to; |
36 | QString body; | 36 | QString body; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | class SmtpClient: public QObject | 39 | class SmtpClient: public QObject |
40 | { | 40 | { |
41 | Q_OBJECT | 41 | Q_OBJECT |
42 | 42 | ||
43 | public: | 43 | public: |
44 | SmtpClient(); | 44 | SmtpClient(); |
45 | ~SmtpClient(); | 45 | ~SmtpClient(); |
46 | void newConnection(QString target, int port); | 46 | void newConnection(const QString &target, int port); |
47 | void addMail(QString from, QString subject, QStringList to, QString body); | 47 | void addMail(const QString &from, const QString &subject, const QStringList &to, const QString &body); |
48 | 48 | ||
49 | signals: | 49 | signals: |
50 | void errorOccurred(int); | 50 | void errorOccurred(int); |
51 | void updateStatus(const QString &); | 51 | void updateStatus(const QString &); |
52 | void mailSent(); | 52 | void mailSent(); |
53 | 53 | ||
54 | public slots: | 54 | public slots: |
55 | void errorHandling(int); | 55 | void errorHandling(int); |
56 | 56 | ||
57 | protected slots: | 57 | protected slots: |
58 | void connectionEstablished(); | 58 | void connectionEstablished(); |
59 | void incomingData(); | 59 | void incomingData(); |
60 | 60 | ||
61 | private: | 61 | private: |
62 | QSocket *socket; | 62 | QSocket *socket; |
63 | QTextStream *stream; | 63 | QTextStream *stream; |
64 | enum transferStatus | 64 | enum transferStatus |
65 | { | 65 | { |
66 | Init, From, Recv, MRcv, Data, Body, Quit, Done | 66 | Init, From, Recv, MRcv, Data, Body, Quit, Done |
67 | }; | 67 | }; |
68 | int status; | 68 | int status; |
69 | QList<RawEmail> mailList; | 69 | QList<RawEmail> mailList; |
70 | RawEmail *mailPtr; | 70 | RawEmail *mailPtr; |
71 | bool sending; | 71 | bool sending; |
72 | QStringList::Iterator it; | 72 | QStringList::Iterator it; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | #endif | 75 | #endif |
diff --git a/noncore/unsupported/mailit/textparser.cpp b/noncore/unsupported/mailit/textparser.cpp index 3fa5f6e..e5c9f7c 100644 --- a/noncore/unsupported/mailit/textparser.cpp +++ b/noncore/unsupported/mailit/textparser.cpp | |||
@@ -1,304 +1,304 @@ | |||
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 "textparser.h" | 20 | #include "textparser.h" |
21 | 21 | ||
22 | TextParser::TextParser(QString in, QString lineBreak) | 22 | TextParser::TextParser(const QString &in, const QString &lineBreak) |
23 | { | 23 | { |
24 | data = in; | 24 | data = in; |
25 | lineSep = lineBreak; | 25 | lineSep = lineBreak; |
26 | 26 | ||
27 | init(); | 27 | init(); |
28 | createSeparators(); | 28 | createSeparators(); |
29 | split(); | 29 | split(); |
30 | } | 30 | } |
31 | 31 | ||
32 | TextParser::TextParser(QString in, QString lineBreak, QString sep) | 32 | TextParser::TextParser(const QString &in, const QString &lineBreak, const QString &sep) |
33 | { | 33 | { |
34 | data = in; | 34 | data = in; |
35 | lineSep = lineBreak; | 35 | lineSep = lineBreak; |
36 | 36 | ||
37 | init(); | 37 | init(); |
38 | separators = sep; | 38 | separators = sep; |
39 | split(); | 39 | split(); |
40 | } | 40 | } |
41 | 41 | ||
42 | void TextParser::init() | 42 | void TextParser::init() |
43 | { | 43 | { |
44 | lineCount = 0; | 44 | lineCount = 0; |
45 | linePos = 0; | 45 | linePos = 0; |
46 | totalElmCount = 0; | 46 | totalElmCount = 0; |
47 | separatorPos = -1; //not initialized | 47 | separatorPos = -1; //not initialized |
48 | wordPos = -1; //not initialized | 48 | wordPos = -1; //not initialized |
49 | sepAtLine = 0; | 49 | sepAtLine = 0; |
50 | sepAtPosElm = -1; //such that nextSep equals 0 | 50 | sepAtPosElm = -1; //such that nextSep equals 0 |
51 | wordAtLine = 0; | 51 | wordAtLine = 0; |
52 | wordAtPosElm = -1; //such that nextWord equals 0 | 52 | wordAtPosElm = -1; //such that nextWord equals 0 |
53 | atLine = 0; | 53 | atLine = 0; |
54 | atPosElm = 0; | 54 | atPosElm = 0; |
55 | } | 55 | } |
56 | 56 | ||
57 | void TextParser::createSeparators() | 57 | void TextParser::createSeparators() |
58 | { | 58 | { |
59 | separators = " @#,.:;<>*/(){}|'?-+=_"; | 59 | separators = " @#,.:;<>*/(){}|'?-+=_"; |
60 | } | 60 | } |
61 | 61 | ||
62 | /*Returns pos of given search criteria, -1 if not found */ | 62 | /* Returns pos of given search criteria, -1 if not found */ |
63 | int TextParser::find(QString target, QChar sep, int pos, bool upperCase) | 63 | int TextParser::find(const QString &target, QChar sep, int pos, bool upperCase) |
64 | { | 64 | { |
65 | 65 | ||
66 | t_splitElm parsstr; | 66 | t_splitElm parsstr; |
67 | QString pString; | 67 | QString pString, pTarget; |
68 | 68 | pTarget = target; | |
69 | int atLine = 0, atPosElm = 0; | 69 | int atLine = 0, atPosElm = 0; |
70 | 70 | ||
71 | getLineReference(pos,&atLine,&atPosElm); | 71 | getLineReference(pos,&atLine,&atPosElm); |
72 | 72 | ||
73 | for (int x = pos; x < totalElmCount; x++) | 73 | for (int x = pos; x < totalElmCount; x++) |
74 | { | 74 | { |
75 | parsstr=splitDone[atLine].elm[atPosElm++]; | 75 | parsstr=splitDone[atLine].elm[atPosElm++]; |
76 | 76 | ||
77 | if (upperCase) | 77 | if (upperCase) |
78 | { | 78 | { |
79 | pString=parsstr.str.upper(); | 79 | pString=parsstr.str.upper(); |
80 | target=target.upper(); | 80 | pTarget=pTarget.upper(); |
81 | } | 81 | } |
82 | else | 82 | else |
83 | { | 83 | { |
84 | pString=parsstr.str; | 84 | pString=parsstr.str; |
85 | } | 85 | } |
86 | if ((pString == target) && (parsstr.separator == sep)) | 86 | if ((pString == pTarget) && (parsstr.separator == sep)) |
87 | { | 87 | { |
88 | return x; | 88 | return x; |
89 | } | 89 | } |
90 | if (atPosElm >= splitDone[atLine].elmCount) | 90 | if (atPosElm >= splitDone[atLine].elmCount) |
91 | { //new Line | 91 | { //new Line |
92 | atLine++; | 92 | atLine++; |
93 | atPosElm = 0; | 93 | atPosElm = 0; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | return -1; | 96 | return -1; |
97 | } | 97 | } |
98 | 98 | ||
99 | int TextParser::elmCount() | 99 | int TextParser::elmCount() |
100 | { | 100 | { |
101 | return totalElmCount; | 101 | return totalElmCount; |
102 | } | 102 | } |
103 | 103 | ||
104 | QChar TextParser::separatorAt(int pos) | 104 | QChar TextParser::separatorAt(int pos) |
105 | { | 105 | { |
106 | if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1) | 106 | if (getLineReference(pos, &sepAtLine, &sepAtPosElm) == -1) |
107 | return QChar::null; | 107 | return QChar::null; |
108 | 108 | ||
109 | separatorPos = pos; | 109 | separatorPos = pos; |
110 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; | 110 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; |
111 | } | 111 | } |
112 | 112 | ||
113 | QChar TextParser::nextSeparator() | 113 | QChar TextParser::nextSeparator() |
114 | { | 114 | { |
115 | sepAtPosElm++; | 115 | sepAtPosElm++; |
116 | if (splitDone[sepAtLine].elmCount <= sepAtPosElm) { | 116 | if (splitDone[sepAtLine].elmCount <= sepAtPosElm) { |
117 | sepAtLine++; | 117 | sepAtLine++; |
118 | sepAtPosElm = 0; | 118 | sepAtPosElm = 0; |
119 | } | 119 | } |
120 | 120 | ||
121 | separatorPos++; | 121 | separatorPos++; |
122 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; | 122 | return splitDone[sepAtLine].elm[sepAtPosElm].separator; |
123 | } | 123 | } |
124 | 124 | ||
125 | bool TextParser::hasNextSeparator() | 125 | bool TextParser::hasNextSeparator() |
126 | { | 126 | { |
127 | return ((separatorPos+1) < totalElmCount); | 127 | return ((separatorPos+1) < totalElmCount); |
128 | } | 128 | } |
129 | 129 | ||
130 | QString TextParser::wordAt(int pos) | 130 | QString TextParser::wordAt(int pos) |
131 | { | 131 | { |
132 | if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1) | 132 | if (getLineReference(pos, &wordAtLine, &wordAtPosElm) == -1) |
133 | return NULL; | 133 | return NULL; |
134 | 134 | ||
135 | wordPos = pos; | 135 | wordPos = pos; |
136 | return splitDone[wordAtLine].elm[wordAtPosElm].str; | 136 | return splitDone[wordAtLine].elm[wordAtPosElm].str; |
137 | } | 137 | } |
138 | 138 | ||
139 | QString TextParser::nextWord() | 139 | QString TextParser::nextWord() |
140 | { | 140 | { |
141 | wordAtPosElm++; | 141 | wordAtPosElm++; |
142 | if (splitDone[wordAtLine].elmCount <= wordAtPosElm) { | 142 | if (splitDone[wordAtLine].elmCount <= wordAtPosElm) { |
143 | wordAtLine++; | 143 | wordAtLine++; |
144 | wordAtPosElm = 0; | 144 | wordAtPosElm = 0; |
145 | } | 145 | } |
146 | 146 | ||
147 | wordPos++; | 147 | wordPos++; |
148 | return splitDone[wordAtLine].elm[wordAtPosElm].str; | 148 | return splitDone[wordAtLine].elm[wordAtPosElm].str; |
149 | } | 149 | } |
150 | 150 | ||
151 | bool TextParser::hasNextWord() | 151 | bool TextParser::hasNextWord() |
152 | { | 152 | { |
153 | return ((wordPos + 1) < totalElmCount); | 153 | return ((wordPos + 1) < totalElmCount); |
154 | } | 154 | } |
155 | 155 | ||
156 | QString TextParser::getString(int *pos, QChar stop, bool lineEnd = false) | 156 | QString TextParser::getString(int *pos, QChar stop, bool lineEnd = false) |
157 | { | 157 | { |
158 | QString returnStr = wordAt(*pos); | 158 | QString returnStr = wordAt(*pos); |
159 | QChar chr = separatorAt(*pos); | 159 | QChar chr = separatorAt(*pos); |
160 | QString s; | 160 | QString s; |
161 | 161 | ||
162 | if (returnStr == "") | 162 | if (returnStr == "") |
163 | return ""; | 163 | return ""; |
164 | if (chr == stop) | 164 | if (chr == stop) |
165 | return returnStr; | 165 | return returnStr; |
166 | 166 | ||
167 | if (!lineEnd) { | 167 | if (!lineEnd) { |
168 | while ((chr != stop) && hasNextWord()) { | 168 | while ((chr != stop) && hasNextWord()) { |
169 | returnStr.append(chr); | 169 | returnStr.append(chr); |
170 | returnStr += nextWord(); | 170 | returnStr += nextWord(); |
171 | chr = nextSeparator(); | 171 | chr = nextSeparator(); |
172 | } | 172 | } |
173 | } else { //copy from pos to end of line | 173 | } else { //copy from pos to end of line |
174 | getLineReference(*pos, &atLine, &atPosElm); | 174 | getLineReference(*pos, &atLine, &atPosElm); |
175 | returnStr = ""; | 175 | returnStr = ""; |
176 | while (atPosElm < splitDone[atLine].elmCount) { | 176 | while (atPosElm < splitDone[atLine].elmCount) { |
177 | if (splitDone[atLine].elm[atPosElm].str != "") { | 177 | if (splitDone[atLine].elm[atPosElm].str != "") { |
178 | returnStr += splitDone[atLine].elm[atPosElm].str; | 178 | returnStr += splitDone[atLine].elm[atPosElm].str; |
179 | } | 179 | } |
180 | chr = splitDone[atLine].elm[atPosElm].separator; | 180 | chr = splitDone[atLine].elm[atPosElm].separator; |
181 | if (!chr.isNull() && (int) chr != 0) { | 181 | if (!chr.isNull() && (int) chr != 0) { |
182 | returnStr.append(splitDone[atLine].elm[atPosElm].separator); | 182 | returnStr.append(splitDone[atLine].elm[atPosElm].separator); |
183 | } | 183 | } |
184 | atPosElm++; | 184 | atPosElm++; |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | *pos = wordPos; | 188 | *pos = wordPos; |
189 | return returnStr; | 189 | return returnStr; |
190 | } | 190 | } |
191 | 191 | ||
192 | QString TextParser::getNextLine() | 192 | QString TextParser::getNextLine() |
193 | { | 193 | { |
194 | atLine++; | 194 | atLine++; |
195 | atPosElm = 0; | 195 | atPosElm = 0; |
196 | if (atLine < lineCount) | 196 | if (atLine < lineCount) |
197 | return splitDone[atLine].str; | 197 | return splitDone[atLine].str; |
198 | return ""; | 198 | return ""; |
199 | } | 199 | } |
200 | 200 | ||
201 | bool TextParser::hasNextLine() | 201 | bool TextParser::hasNextLine() |
202 | { | 202 | { |
203 | if (atLine+1 < lineCount) | 203 | if (atLine+1 < lineCount) |
204 | return TRUE;; | 204 | return TRUE;; |
205 | return FALSE; | 205 | return FALSE; |
206 | } | 206 | } |
207 | 207 | ||
208 | int TextParser::endLinePos(int pos) | 208 | int TextParser::endLinePos(int pos) |
209 | { | 209 | { |
210 | if ( (getLineReference(pos, &atLine, &atPosElm)) == -1) | 210 | if ( (getLineReference(pos, &atLine, &atPosElm)) == -1) |
211 | return -1; | 211 | return -1; |
212 | 212 | ||
213 | return (pos + (splitDone[atLine].elmCount - atPosElm) + 1); | 213 | return (pos + (splitDone[atLine].elmCount - atPosElm) + 1); |
214 | } | 214 | } |
215 | 215 | ||
216 | int TextParser::getLineReference(int pos, int *line, int *inLinePos) | 216 | int TextParser::getLineReference(int pos, int *line, int *inLinePos) |
217 | { | 217 | { |
218 | int currentPos = 0; | 218 | int currentPos = 0; |
219 | 219 | ||
220 | for (int x = 0; x < lineCount; x++) { | 220 | for (int x = 0; x < lineCount; x++) { |
221 | if ( currentPos + splitDone[x].elmCount > pos) { | 221 | if ( currentPos + splitDone[x].elmCount > pos) { |
222 | *line = x; | 222 | *line = x; |
223 | *inLinePos = pos - currentPos; | 223 | *inLinePos = pos - currentPos; |
224 | return 0; //pos found okay | 224 | return 0; //pos found okay |
225 | } | 225 | } |
226 | currentPos += splitDone[x].elmCount; | 226 | currentPos += splitDone[x].elmCount; |
227 | } | 227 | } |
228 | return -1; //no reference found | 228 | return -1; //no reference found |
229 | } | 229 | } |
230 | 230 | ||
231 | void TextParser::split() | 231 | void TextParser::split() |
232 | { | 232 | { |
233 | t_splitLine newLine; | 233 | t_splitLine newLine; |
234 | 234 | ||
235 | while ((uint) linePos < data.length()) { | 235 | while ((uint) linePos < data.length()) { |
236 | newLine = nextLine(); | 236 | newLine = nextLine(); |
237 | splitDone[lineCount] = splitLine(newLine); | 237 | splitDone[lineCount] = splitLine(newLine); |
238 | totalElmCount += splitDone[lineCount].elmCount; | 238 | totalElmCount += splitDone[lineCount].elmCount; |
239 | lineCount++; | 239 | lineCount++; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | t_splitLine TextParser::splitLine(t_splitLine line) | 243 | t_splitLine TextParser::splitLine(t_splitLine line) |
244 | { | 244 | { |
245 | uint pos = 0; | 245 | uint pos = 0; |
246 | uint elmCount = 0; | 246 | uint elmCount = 0; |
247 | t_splitLine tempLine = line; | 247 | t_splitLine tempLine = line; |
248 | 248 | ||
249 | tempLine.str = line.str.simplifyWhiteSpace(); | 249 | tempLine.str = line.str.simplifyWhiteSpace(); |
250 | tempLine.elm[0].str = ""; | 250 | tempLine.elm[0].str = ""; |
251 | while ( pos < line.str.length() ) { | 251 | while ( pos < line.str.length() ) { |
252 | if ( isSeparator(tempLine.str[pos]) ) { | 252 | if ( isSeparator(tempLine.str[pos]) ) { |
253 | tempLine.elm[elmCount].separator = tempLine.str[pos]; | 253 | tempLine.elm[elmCount].separator = tempLine.str[pos]; |
254 | elmCount++; | 254 | elmCount++; |
255 | pos++; | 255 | pos++; |
256 | while (tempLine.str[pos] == ' ') | 256 | while (tempLine.str[pos] == ' ') |
257 | pos++; | 257 | pos++; |
258 | if (pos > line.str.length()) | 258 | if (pos > line.str.length()) |
259 | elmCount--; | 259 | elmCount--; |
260 | tempLine.elm[elmCount].str = ""; | 260 | tempLine.elm[elmCount].str = ""; |
261 | } else { | 261 | } else { |
262 | if (!tempLine.str[pos].isNull()) | 262 | if (!tempLine.str[pos].isNull()) |
263 | tempLine.elm[elmCount].str += tempLine.str[pos]; | 263 | tempLine.elm[elmCount].str += tempLine.str[pos]; |
264 | pos++; | 264 | pos++; |
265 | } | 265 | } |
266 | } | 266 | } |
267 | 267 | ||
268 | tempLine.elmCount = elmCount + 1; | 268 | tempLine.elmCount = elmCount + 1; |
269 | return tempLine; | 269 | return tempLine; |
270 | } | 270 | } |
271 | 271 | ||
272 | bool TextParser::isSeparator(QChar chr) | 272 | bool TextParser::isSeparator(QChar chr) |
273 | { | 273 | { |
274 | for (uint x = 0; x < separators.length(); x++) { | 274 | for (uint x = 0; x < separators.length(); x++) { |
275 | if (chr == separators[x]) | 275 | if (chr == separators[x]) |
276 | return true; | 276 | return true; |
277 | } | 277 | } |
278 | return false; | 278 | return false; |
279 | } | 279 | } |
280 | 280 | ||
281 | t_splitLine TextParser::nextLine() | 281 | t_splitLine TextParser::nextLine() |
282 | { | 282 | { |
283 | int newLinePos; | 283 | int newLinePos; |
284 | t_splitLine lineType; | 284 | t_splitLine lineType; |
285 | 285 | ||
286 | newLinePos = data.find(lineSep, linePos); | 286 | newLinePos = data.find(lineSep, linePos); |
287 | 287 | ||
288 | lineType.lineType = NewLine; | 288 | lineType.lineType = NewLine; |
289 | lineType.str = ""; | 289 | lineType.str = ""; |
290 | 290 | ||
291 | if (newLinePos == -1) { | 291 | if (newLinePos == -1) { |
292 | newLinePos = data.length(); | 292 | newLinePos = data.length(); |
293 | lineType.lineType = LastLine; | 293 | lineType.lineType = LastLine; |
294 | } | 294 | } |
295 | 295 | ||
296 | for (int x = linePos; x < newLinePos; x++) | 296 | for (int x = linePos; x < newLinePos; x++) |
297 | lineType.str += data[x]; | 297 | lineType.str += data[x]; |
298 | 298 | ||
299 | linePos = newLinePos; | 299 | linePos = newLinePos; |
300 | if ((uint) linePos < data.length()) //if not EOF, add length of lineSep | 300 | if ((uint) linePos < data.length()) //if not EOF, add length of lineSep |
301 | linePos += lineSep.length(); | 301 | linePos += lineSep.length(); |
302 | 302 | ||
303 | return lineType; | 303 | return lineType; |
304 | } | 304 | } |
diff --git a/noncore/unsupported/mailit/textparser.h b/noncore/unsupported/mailit/textparser.h index c5e88a0..03bb6d5 100644 --- a/noncore/unsupported/mailit/textparser.h +++ b/noncore/unsupported/mailit/textparser.h | |||
@@ -4,82 +4,82 @@ | |||
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 <qobject.h> | 20 | #include <qobject.h> |
21 | #include <qstring.h> | 21 | #include <qstring.h> |
22 | 22 | ||
23 | #ifndef TEXTPARSER_H | 23 | #ifndef TEXTPARSER_H |
24 | #define TEXTPARSER_H | 24 | #define TEXTPARSER_H |
25 | 25 | ||
26 | enum t_strType { Word, Number}; | 26 | enum t_strType { Word, Number}; |
27 | enum t_lineType {NewLine, LastLine}; | 27 | enum t_lineType {NewLine, LastLine}; |
28 | 28 | ||
29 | const uint MAX_ELEMENTS = 200; //Should be dynamic | 29 | const uint MAX_ELEMENTS = 200; //Should be dynamic |
30 | const uint MAX_LINES = 500; //Should be dynamic | 30 | const uint MAX_LINES = 500; //Should be dynamic |
31 | 31 | ||
32 | struct t_splitElm | 32 | struct t_splitElm |
33 | { | 33 | { |
34 | QChar separator; | 34 | QChar separator; |
35 | int strType; | 35 | int strType; |
36 | QString str; | 36 | QString str; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | struct t_splitLine | 39 | struct t_splitLine |
40 | { | 40 | { |
41 | t_lineType lineType; | 41 | t_lineType lineType; |
42 | QString str; //a bit redundant... | 42 | QString str; //a bit redundant... |
43 | t_splitElm elm[MAX_ELEMENTS]; | 43 | t_splitElm elm[MAX_ELEMENTS]; |
44 | int elmCount; | 44 | int elmCount; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | class TextParser: public QObject | 47 | class TextParser: public QObject |
48 | { | 48 | { |
49 | Q_OBJECT | 49 | Q_OBJECT |
50 | 50 | ||
51 | public: | 51 | public: |
52 | TextParser(QString in, QString lineBreak); | 52 | TextParser(const QString &in, const QString &lineBreak); |
53 | TextParser(QString in, QString lineBreak, QString sep); | 53 | TextParser(const QString &in, const QString &lineBreak, const QString &sep); |
54 | int find(QString target, QChar sep, int pos, bool upperCase); | 54 | int find(const QString &target, QChar sep, int pos, bool upperCase); |
55 | int elmCount(); | 55 | int elmCount(); |
56 | QChar separatorAt(int pos); | 56 | QChar separatorAt(int pos); |
57 | QChar nextSeparator(); | 57 | QChar nextSeparator(); |
58 | bool hasNextSeparator(); | 58 | bool hasNextSeparator(); |
59 | QString wordAt(int pos); | 59 | QString wordAt(int pos); |
60 | QString nextWord(); | 60 | QString nextWord(); |
61 | bool hasNextWord(); | 61 | bool hasNextWord(); |
62 | QString getString(int *pos, QChar stop, bool lineEnd); | 62 | QString getString(int *pos, QChar stop, bool lineEnd); |
63 | QString getNextLine(); | 63 | QString getNextLine(); |
64 | bool hasNextLine(); | 64 | bool hasNextLine(); |
65 | int endLinePos(int pos); | 65 | int endLinePos(int pos); |
66 | 66 | ||
67 | private: | 67 | private: |
68 | void init(); | 68 | void init(); |
69 | void createSeparators(); | 69 | void createSeparators(); |
70 | t_splitLine nextLine(); | 70 | t_splitLine nextLine(); |
71 | void split(); | 71 | void split(); |
72 | t_splitLine splitLine(t_splitLine line); | 72 | t_splitLine splitLine(t_splitLine line); |
73 | bool isSeparator(QChar chr); | 73 | bool isSeparator(QChar chr); |
74 | t_splitLine splitDone[MAX_LINES]; | 74 | t_splitLine splitDone[MAX_LINES]; |
75 | int getLineReference(int pos, int *line, int *inLinePos); | 75 | int getLineReference(int pos, int *line, int *inLinePos); |
76 | 76 | ||
77 | int lineCount, linePos, totalElmCount; | 77 | int lineCount, linePos, totalElmCount; |
78 | int separatorPos, wordPos; | 78 | int separatorPos, wordPos; |
79 | QString data, separators, lineSep; | 79 | QString data, separators, lineSep; |
80 | int sepAtLine, sepAtPosElm; | 80 | int sepAtLine, sepAtPosElm; |
81 | int wordAtLine, wordAtPosElm; | 81 | int wordAtLine, wordAtPosElm; |
82 | int atLine, atPosElm; | 82 | int atLine, atPosElm; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | #endif | 85 | #endif |