summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mailit/emailclient.cpp
authorgroucho <groucho>2003-04-24 11:19:11 (UTC)
committer groucho <groucho>2003-04-24 11:19:11 (UTC)
commit9671975e21266e3bfa6f3c793a3278b67cea34b7 (patch) (unidiff)
tree876c77939cfd0e00fc844b1b5af09b2978564a6d /noncore/unsupported/mailit/emailclient.cpp
parent51e782b9658de61dc02579e115a9c62f396609a3 (diff)
downloadopie-9671975e21266e3bfa6f3c793a3278b67cea34b7.zip
opie-9671975e21266e3bfa6f3c793a3278b67cea34b7.tar.gz
opie-9671975e21266e3bfa6f3c793a3278b67cea34b7.tar.bz2
- reworked size filtering
- started reworking offline download - better tab focus switching - Hello "Whats this" capability - Fixed parsing of To: header files (no more Delivered-To: and Reply-To: matches) - Good bye Settings.txt, hello Config Objects and encrypted passwords - Translation improvements (added trs) - Parser optimizations
Diffstat (limited to 'noncore/unsupported/mailit/emailclient.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/mailit/emailclient.cpp219
1 files changed, 98 insertions, 121 deletions
diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp
index ad1e0b4..23059cf 100644
--- a/noncore/unsupported/mailit/emailclient.cpp
+++ b/noncore/unsupported/mailit/emailclient.cpp
@@ -14,24 +14,25 @@
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 <qapplication.h> 20#include <qapplication.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include <qfile.h> 22#include <qfile.h>
23#include <qcheckbox.h> 23#include <qcheckbox.h>
24#include <qmenubar.h> 24#include <qmenubar.h>
25#include <qaction.h> 25#include <qaction.h>
26#include <qwhatsthis.h>
26#include <qpe/resource.h> 27#include <qpe/resource.h>
27#include "emailclient.h" 28#include "emailclient.h"
28 29
29QCollection::Item AccountList::newItem(QCollection::Item d) 30QCollection::Item AccountList::newItem(QCollection::Item d)
30{ 31{
31 return dupl( (MailAccount *) d); 32 return dupl( (MailAccount *) d);
32} 33}
33 34
34MailAccount* AccountList::dupl(MailAccount *in) 35MailAccount* AccountList::dupl(MailAccount *in)
35{ 36{
36 ac = new MailAccount(*in); 37 ac = new MailAccount(*in);
37 return ac; 38 return ac;
@@ -73,24 +74,25 @@ EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
73 74
74 mailconf = new Config("mailit"); 75 mailconf = new Config("mailit");
75 //In case Synchronize is not defined in settings.txt 76 //In case Synchronize is not defined in settings.txt
76 77
77 readSettings(); 78 readSettings();
78 79
79 updateAccounts(); 80 updateAccounts();
80 81
81 lineShift = "\n"; 82 lineShift = "\n";
82 readMail(); 83 readMail();
83 lineShift = "\r\n"; 84 lineShift = "\r\n";
84 85
86 mailboxView->setCurrentTab(0); //ensure that inbox has focus
85} 87}
86 88
87 89
88EmailClient::~EmailClient() 90EmailClient::~EmailClient()
89{ 91{
90 //needs to be moved from destructor to closewindow event 92 //needs to be moved from destructor to closewindow event
91 saveMail(getPath(FALSE) + "inbox.txt", inboxView); 93 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
92 //does not currently work. Defining outbox in the same 94 //does not currently work. Defining outbox in the same
93 //format as inbox is not a good solution as they have 95 //format as inbox is not a good solution as they have
94 //different properties 96 //different properties
95 saveMail(getPath(FALSE) + "outbox.txt", outboxView); 97 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
96 saveSettings(); 98 saveSettings();
@@ -104,132 +106,125 @@ void EmailClient::init()
104{ 106{
105 statusBar = new QStatusBar(this); 107 statusBar = new QStatusBar(this);
106 statusBar->setSizeGripEnabled(FALSE); 108 statusBar->setSizeGripEnabled(FALSE);
107 109
108 status1Label = new QLabel( tr("Idle"), statusBar); 110 status1Label = new QLabel( tr("Idle"), statusBar);
109 status2Label = new QLabel("", statusBar); 111 status2Label = new QLabel("", statusBar);
110 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)), 112 connect(emailHandler, SIGNAL(updatePopStatus(const QString &)),
111 status2Label, SLOT(setText(const QString &)) ); 113 status2Label, SLOT(setText(const QString &)) );
112 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)), 114 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString &)),
113 status2Label, SLOT(setText(const QString &)) ); 115 status2Label, SLOT(setText(const QString &)) );
114 116
115 progressBar = new QProgressBar(statusBar); 117 progressBar = new QProgressBar(statusBar);
118
116 connect(emailHandler, SIGNAL(mailboxSize(int)), 119 connect(emailHandler, SIGNAL(mailboxSize(int)),
117 this, SLOT(setTotalSize(int)) ); 120 this, SLOT(setTotalSize(int)) );
118 connect(emailHandler, SIGNAL(currentMailSize(int)), 121 connect(emailHandler, SIGNAL(currentMailSize(int)),
119 this, SLOT(setMailSize(int)) ); 122 this, SLOT(setMailSize(int)) );
120 connect(emailHandler, SIGNAL(downloadedSize(int)), 123 connect(emailHandler, SIGNAL(downloadedSize(int)),
121 this, SLOT(setDownloadedSize(int)) ); 124 this, SLOT(setDownloadedSize(int)) );
122 125
123 statusBar->addWidget(status1Label); 126 statusBar->addWidget(status1Label);
124 statusBar->addWidget(progressBar); 127 statusBar->addWidget(progressBar);
125 statusBar->addWidget(status2Label); 128 statusBar->addWidget(status2Label);
126 129
127 setToolBarsMovable(FALSE); 130 setToolBarsMovable(FALSE);
128 131
129 bar = new QToolBar(this); 132 bar = new QToolBar(this);
133 QWhatsThis::add(bar,tr("Main operation toolbar"));
130 bar->setHorizontalStretchable( TRUE ); 134 bar->setHorizontalStretchable( TRUE );
131 135
132 mb = new QMenuBar( bar ); 136 mb = new QMenuBar( bar );
133 137
134 QPopupMenu *mail = new QPopupMenu(mb); 138 QPopupMenu *mail = new QPopupMenu(mb);
135 mb->insertItem( tr( "&Mail" ), mail); 139 mb->insertItem( tr( "&Mail" ), mail);
136 140
137 QPopupMenu *configure = new QPopupMenu(mb); 141 QPopupMenu *configure = new QPopupMenu(mb);
138 mb->insertItem( tr( "Accounts" ), configure); 142 mb->insertItem( tr( "Accounts" ), configure);
139 143
140 selectAccountMenu = new QPopupMenu(mb); 144 selectAccountMenu = new QPopupMenu(mb);
141 editAccountMenu = new QPopupMenu(mb); 145 editAccountMenu = new QPopupMenu(mb);
142 deleteAccountMenu = new QPopupMenu(mb); 146 deleteAccountMenu = new QPopupMenu(mb);
143 147
144 mail->insertItem(tr("Get Mail in"), selectAccountMenu); 148 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
145 configure->insertItem(tr("Edit account"), editAccountMenu); 149 configure->insertItem(tr("Edit account"), editAccountMenu);
146 configure->insertItem(tr("Delete account"), deleteAccountMenu); 150 configure->insertItem(tr("Delete account"), deleteAccountMenu);
147 151
148 bar = new QToolBar(this); 152 bar = new QToolBar(this);
149 153
150 getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar); 154 getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar);
151 //connect(setAccountlButton, SIGNAL(activated()), this, SLOT(setCurrentAccount()) ); 155 QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account."));
152 // setAccountButton->addTo(bar);
153 //setAccountButton->addTo(mail);
154
155 /*idCount = 0;
156
157 for (MailAccount* accountPtr = accountList.first(); accountPtr != 0;
158 accountPtr = accountList.next()) {
159 156
160 selectAccountMenu->insertItem(accountPtr->accountName,this, SLOT(selectAccount(int)), 0, idCount);
161 idCount++;
162 }*/
163 getMailButton->setPopup(selectAccountMenu); 157 getMailButton->setPopup(selectAccountMenu);
164 158
165
166 /*getMailButton = new QAction(tr("Get all mail"), Resource::loadPixmap("mailit/getmail"), QString::null, 0, this, 0);
167 connect(getMailButton, SIGNAL(activated()), this, SLOT(getAllNewMail()) );
168 getMailButton->addTo(bar);*/
169 //getMailButton->addTo(mail);
170
171 sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0); 159 sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0);
172 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) ); 160 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
173 sendMailButton->addTo(bar); 161 sendMailButton->addTo(bar);
174 sendMailButton->addTo(mail); 162 sendMailButton->addTo(mail);
163 sendMailButton->setWhatsThis("Send mail queued in the outbox");
175 164
176 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0); 165 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
177 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) ); 166 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
178 composeButton->addTo(bar); 167 composeButton->addTo(bar);
179 composeButton->addTo(mail); 168 composeButton->addTo(mail);
169 composeButton->setWhatsThis("Compose a new mail");
180 170
181 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0); 171 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0);
182 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) ); 172 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
183 cancelButton->addTo(mail); 173 cancelButton->addTo(mail);
184 cancelButton->addTo(bar); 174 cancelButton->addTo(bar);
185 cancelButton->setEnabled(FALSE); 175 cancelButton->setEnabled(FALSE);
176 cancelButton->setWhatsThis("Stop the currently active mail transfer");
177
186 178
187 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); 179 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
188 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) ); 180 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
189 deleteButton->addTo(bar); 181 deleteButton->addTo(bar);
182 deleteButton->setWhatsThis("Remove the currently selected eMail(s)");
190 183
191 mailboxView = new OTabWidget( this, "mailboxView" ); 184 mailboxView = new OTabWidget( this, "mailboxView" );
192 185
193 QWidget* widget = new QWidget( mailboxView, "widget" ); 186 QWidget* widget = new QWidget( mailboxView, "widget" );
194 grid_2 = new QGridLayout( widget ); 187 grid_2 = new QGridLayout( widget );
195// grid_2->setSpacing(6); 188// grid_2->setSpacing(6);
196// grid_2->setMargin( 11 ); 189// grid_2->setMargin( 11 );
197 190
198 inboxView = new QListView( widget, "inboxView" ); 191 inboxView = new QListView( widget, "inboxView" );
199 inboxView->addColumn( tr( "From" ) ); 192 inboxView->addColumn( tr( "From" ) );
200 inboxView->addColumn( tr( "Subject" ) ); 193 inboxView->addColumn( tr( "Subject" ) );
201 inboxView->addColumn( tr( "Date" ) ); 194 inboxView->addColumn( tr( "Date" ) );
202 inboxView->setMinimumSize( QSize( 0, 0 ) ); 195 inboxView->setMinimumSize( QSize( 0, 0 ) );
203 inboxView->setAllColumnsShowFocus(TRUE); 196 inboxView->setAllColumnsShowFocus(TRUE);
197 QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n It keeps the fetched mail which can be viewed by double clicking the entry.\n"
198 " A blue attachment icon shows whether this mail has attachments."));
204 199
205 grid_2->addWidget( inboxView, 2, 0 ); 200 grid_2->addWidget( inboxView, 2, 0 );
206 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) ); 201 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) );
207 202
208 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" ); 203 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
209 grid_3 = new QGridLayout( widget_2 ); 204 grid_3 = new QGridLayout( widget_2 );
210// grid_3->setSpacing(6); 205// grid_3->setSpacing(6);
211// grid_3->setMargin( 11 ); 206// grid_3->setMargin( 11 );
212 207
213 outboxView = new QListView( widget_2, "outboxView" ); 208 outboxView = new QListView( widget_2, "outboxView" );
214 outboxView->addColumn( tr( "To" ) ); 209 outboxView->addColumn( tr( "To" ) );
215 outboxView->addColumn( tr( "Subject" ) ); 210 outboxView->addColumn( tr( "Subject" ) );
216 outboxView->setAllColumnsShowFocus(TRUE); 211 outboxView->setAllColumnsShowFocus(TRUE);
217 212
213 QWhatsThis::add(outboxView,QWidget::tr("This is the oubox view.\n It keeps the queued mails to send which can be reviewed by double clicking the entry."));
218 grid_3->addWidget( outboxView, 0, 0 ); 214 grid_3->addWidget( outboxView, 0, 0 );
219 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) ); 215 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) );
220 216
221 setCentralWidget(mailboxView); 217 setCentralWidget(mailboxView);
222 218
223 mailboxView->setCurrentTab(0);
224} 219}
225 220
226void EmailClient::compose() 221void EmailClient::compose()
227{ 222{
228 emit composeRequested(); 223 emit composeRequested();
229} 224}
230 225
231void EmailClient::cancel() 226void EmailClient::cancel()
232{ 227{
233 emailHandler->cancel(); 228 emailHandler->cancel();
234} 229}
235 230
@@ -315,93 +310,98 @@ void EmailClient::getNewMail() {
315 setMailAccount(); 310 setMailAccount();
316 311
317 receiving = TRUE; 312 receiving = TRUE;
318 previewingMail = TRUE; 313 previewingMail = TRUE;
319 getMailButton->setEnabled(FALSE); 314 getMailButton->setEnabled(FALSE);
320 cancelButton->setEnabled(TRUE); 315 cancelButton->setEnabled(TRUE);
321 selectAccountMenu->setEnabled(FALSE); 316 selectAccountMenu->setEnabled(FALSE);
322 317
323 status1Label->setText(currentAccount->accountName + " headers"); 318 status1Label->setText(currentAccount->accountName + " headers");
324 progressBar->reset(); 319 progressBar->reset();
325 320
326 //get any previous mails not downloaded and add to queue 321 //get any previous mails not downloaded and add to queue
327/* mailDownloadList.clear(); 322 mailDownloadList.clear();
328 Email *mailPtr; 323 Email *mailPtr;
329 item = (EmailListItem *) inboxView->firstChild(); 324 item = (EmailListItem *) inboxView->firstChild();
330 while (item != NULL) { 325 while (item != NULL) {
331 mailPtr = item->getMail(); 326 mailPtr = item->getMail();
332 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) { 327 if ( (!mailPtr->downloaded) && (mailPtr->fromAccountId == currentAccount->id) ) {
333 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size); 328 mailDownloadList.sizeInsert(mailPtr->serverId, mailPtr->size);
334 } 329 }
335 item = (EmailListItem *) item->nextSibling(); 330 item = (EmailListItem *) item->nextSibling();
336 }*/ 331 }
337 332
338 emailHandler->getMailHeaders(); 333 emailHandler->getMailHeaders();
334
339} 335}
340 336
341void EmailClient::getAllNewMail() 337void EmailClient::getAllNewMail()
342{ 338{
343 allAccounts = TRUE; 339 allAccounts = TRUE;
344 currentAccount = accountList.first(); 340 currentAccount = accountList.first();
345 getNewMail(); 341 getNewMail();
346} 342}
347 343
348void EmailClient::mailArrived(const Email &mail, bool fromDisk) 344void EmailClient::mailArrived(const Email &mail, bool fromDisk)
349{ 345{
350 Enclosure *ePtr; 346 Enclosure *ePtr;
351 Email newMail; 347 Email newMail;
352 int thisMailId; 348 int thisMailId;
353 emailHandler->parse(mail.rawMail, lineShift, &newMail); 349 emailHandler->parse(mail.rawMail, lineShift, &newMail);
354
355 mailconf->setGroup(newMail.id); 350 mailconf->setGroup(newMail.id);
356 351
357 if (fromDisk) { 352 if (fromDisk)
353 {
358 newMail.downloaded = mailconf->readBoolEntry("downloaded"); 354 newMail.downloaded = mailconf->readBoolEntry("downloaded");
359 newMail.size = mailconf->readNumEntry("size"); 355 newMail.size = mailconf->readNumEntry("size");
360 newMail.serverId = mailconf->readNumEntry("serverid"); 356 newMail.serverId = mailconf->readNumEntry("serverid");
361 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); 357 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
362 } else { //mail arrived from server 358 }
359 else
360 { //mail arrived from server
363 newMail.serverId = mail.serverId; 361 newMail.serverId = mail.serverId;
364 newMail.size = mail.size; 362 newMail.size = mail.size;
365 newMail.downloaded = mail.downloaded; 363 newMail.downloaded = mail.downloaded;
366 364
367 newMail.fromAccountId = currentAccount->id; 365 newMail.fromAccountId = currentAccount->id;
368 mailconf->writeEntry("fromaccountid", newMail.fromAccountId); 366 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
369 } 367 }
370 368
371 //add if read or not 369 //add if read or not
372 newMail.read = mailconf->readBoolEntry("mailread"); 370 newMail.read = mailconf->readBoolEntry("mailread");
373 371
374 //check if new mail 372 //check if new mail
375 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { 373 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
376 thisMailId = mailIdCount; 374 thisMailId = mailIdCount;
377 mailIdCount++; 375 mailIdCount++;
378 376
379 //set server count, so that if the user aborts, the new 377 //set server count, so that if the user aborts, the new
380 //header is not reloaded 378 //header is not reloaded
381 if (currentAccount->synchronize) 379 if ((currentAccount)&&(currentAccount->synchronize))
382 currentAccount->lastServerMailCount++; 380 currentAccount->lastServerMailCount++;
383 381
384 mailconf->writeEntry("internalmailid", thisMailId); 382 mailconf->writeEntry("internalmailid", thisMailId);
385 mailconf->writeEntry("downloaded", newMail.downloaded); 383 mailconf->writeEntry("downloaded", newMail.downloaded);
386 mailconf->writeEntry("size", (int) newMail.size); 384 mailconf->writeEntry("size", (int) newMail.size);
387 mailconf->writeEntry("serverid", newMail.serverId); 385 mailconf->writeEntry("serverid", newMail.serverId);
388 386
389 addressList->addContact(newMail.fromMail, newMail.from); 387 //addressList->addContact(newMail.fromMail, newMail.from);
390 } else if (!fromDisk) { //body to header arrived
391 mailconf->writeEntry("downloaded", TRUE);
392 } 388 }
389
390 mailconf->writeEntry("downloaded", newMail.downloaded);
391
393 QString stringMailId; 392 QString stringMailId;
394 stringMailId.setNum(thisMailId); 393 stringMailId.setNum(thisMailId);
395 //se if any attatchments needs to be stored 394 //see if any attatchments needs to be stored
395
396 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { 396 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
397 QString stringId; 397 QString stringId;
398 stringId.setNum(ePtr->id); 398 stringId.setNum(ePtr->id);
399 399
400 int id = mailconf->readNumEntry("enclosureid_" + stringId); 400 int id = mailconf->readNumEntry("enclosureid_" + stringId);
401 if (id != ePtr->id) { //new entry 401 if (id != ePtr->id) { //new entry
402 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id); 402 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
403 mailconf->writeEntry("name_" + stringId, ePtr->originalName); 403 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
404 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType); 404 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
405 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute); 405 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
406 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 406 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
407 mailconf->writeEntry("installed_" + stringId, FALSE); 407 mailconf->writeEntry("installed_" + stringId, FALSE);
@@ -417,72 +417,79 @@ void EmailClient::mailArrived(const Email &mail, bool fromDisk)
417 ePtr->saved = FALSE; 417 ePtr->saved = FALSE;
418 mailconf->writeEntry("saved_" + stringId, ePtr->saved); 418 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
419 } 419 }
420 } else { 420 } else {
421 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId); 421 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
422 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId); 422 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
423 if (ePtr->saved) { 423 if (ePtr->saved) {
424 ePtr->name = mailconf->readEntry("filename_" + stringId); 424 ePtr->name = mailconf->readEntry("filename_" + stringId);
425 ePtr->path = mailconf->readEntry("path_" + stringId); 425 ePtr->path = mailconf->readEntry("path_" + stringId);
426 } 426 }
427 } 427 }
428 } 428 }
429 if (!previewingMail && !fromDisk) { 429
430 bool found=false;
431
432 if (!fromDisk)
433 {
434
430 Email *mailPtr; 435 Email *mailPtr;
431 item = (EmailListItem *) inboxView->firstChild(); 436 item = (EmailListItem *) inboxView->firstChild();
432 while (item != NULL) { 437 while ((item != NULL)&&(!found))
438 {
433 mailPtr = item->getMail(); 439 mailPtr = item->getMail();
434 if (mailPtr->id == newMail.id) { 440 if (mailPtr->id == newMail.id) {
435 item->setMail(newMail); 441 item->setMail(newMail);
436 emit mailUpdated(item->getMail()); 442 emit mailUpdated(item->getMail());
443 found = true;
437 } 444 }
438 item = (EmailListItem *) item->nextSibling(); 445 item = (EmailListItem *) item->nextSibling();
439 } 446 }
440 } else {
441 item = new EmailListItem(inboxView, newMail, TRUE);
442 if (!newMail.downloaded)
443 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);
444 } 447 }
448 if ((!found)||(fromDisk)) item = new EmailListItem(inboxView, newMail, TRUE);
449
450 /*if (!newMail.downloaded)
451 mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/
445 452
446 mailboxView->setCurrentTab(0); 453 mailboxView->setCurrentTab(0);
447 454
448} 455}
449 456
450void EmailClient::allMailArrived(int count) 457void EmailClient::allMailArrived(int count)
451{ 458{
452 // not previewing means all mailtransfer has been done 459 // not previewing means all mailtransfer has been done
453 if (!previewingMail) { 460 /*if (!previewingMail) {*/
454 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { 461 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
455 emit newCaption("Mailit - " + currentAccount->accountName); 462 emit newCaption("Mailit - " + currentAccount->accountName);
456 getNewMail(); 463 getNewMail();
457 return; 464 return;
458 } else { 465 } else {
459 allAccounts = FALSE; 466 allAccounts = FALSE;
460 receiving = FALSE; 467 receiving = FALSE;
461 getMailButton->setEnabled(TRUE); 468 getMailButton->setEnabled(TRUE);
462 cancelButton->setEnabled(FALSE); 469 cancelButton->setEnabled(FALSE);
463 selectAccountMenu->setEnabled(TRUE); 470 selectAccountMenu->setEnabled(TRUE);
464 status1Label->setText("Idle"); 471 status1Label->setText("Idle");
465 472
466 progressBar->reset(); 473 progressBar->reset();
467 return; 474 return;
468 } 475 }
469 } 476 //}
470 477
471 // all headers downloaded from server, start downloading remaining mails 478 // all headers downloaded from server, start downloading remaining mails
472 previewingMail = FALSE; 479 previewingMail = FALSE;
473 status1Label->setText(currentAccount->accountName); 480 status1Label->setText(currentAccount->accountName);
474 progressBar->reset(); 481 progressBar->reset();
475 482
476 emailHandler->getMailByList(&mailDownloadList); 483 //emailHandler->getMailByList(&mailDownloadList);
477 484
478 mailboxView->setCurrentTab(0); 485 mailboxView->setCurrentTab(0);
479} 486}
480 487
481void EmailClient::moveMailFront(Email *mailPtr) 488void EmailClient::moveMailFront(Email *mailPtr)
482{ 489{
483 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { 490 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
484 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); 491 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
485 } 492 }
486} 493}
487 494
488void EmailClient::smtpError(int code) 495void EmailClient::smtpError(int code)
@@ -532,52 +539,50 @@ void EmailClient::popError(int code)
532 } else { 539 } else {
533 status2Label->setText("Aborted by user"); 540 status2Label->setText("Aborted by user");
534 } 541 }
535 542
536 receiving = FALSE; 543 receiving = FALSE;
537 getMailButton->setEnabled(TRUE); 544 getMailButton->setEnabled(TRUE);
538 cancelButton->setEnabled(FALSE); 545 cancelButton->setEnabled(FALSE);
539 selectAccountMenu->setEnabled(TRUE); 546 selectAccountMenu->setEnabled(TRUE);
540} 547}
541 548
542void EmailClient::inboxItemSelected() 549void EmailClient::inboxItemSelected()
543{ 550{
544 killTimer(timerID); 551 //killTimer(timerID);
545 552
546 item = (EmailListItem*) inboxView->selectedItem(); 553 item = (EmailListItem*) inboxView->selectedItem();
547 if (item != NULL) { 554 if (item != NULL) {
548 emit viewEmail(inboxView, item->getMail()); 555 emit viewEmail(inboxView, item->getMail());
549 } 556 }
550} 557}
551 558
552void EmailClient::outboxItemSelected() 559void EmailClient::outboxItemSelected()
553{ 560{
554 killTimer(timerID); 561 //killTimer(timerID);
555 562
556 item = (EmailListItem*) outboxView->selectedItem(); 563 item = (EmailListItem*) outboxView->selectedItem();
557 if (item != NULL) { 564 if (item != NULL) {
558 emit viewEmail(outboxView, item->getMail()); 565 emit viewEmail(outboxView, item->getMail());
559 } 566 }
560 567
561} 568}
562 569
563void EmailClient::readMail() 570void EmailClient::readMail()
564{ 571{
565 Email mail; 572 Email mail;
566 int start, stop; 573 int start, stop;
567 QString s, del; 574 QString s, del;
568 575
569 QFile f(getPath(FALSE) + "inbox.txt"); 576 QFile f(getPath(FALSE) + "inbox.txt");
570// QFileInfo fi(f);
571 //qDebug( f.name());
572 577
573 if ( f.open(IO_ReadOnly) ) { // file opened successfully 578 if ( f.open(IO_ReadOnly) ) { // file opened successfully
574 QTextStream t( &f ); // use a text stream 579 QTextStream t( &f ); // use a text stream
575 s = t.read(); 580 s = t.read();
576 f.close(); 581 f.close();
577 582
578 start = 0; 583 start = 0;
579 del = "\n.\n"; 584 del = "\n.\n";
580 while ((uint) start < s.length()) { 585 while ((uint) start < s.length()) {
581 stop = s.find(del, start); 586 stop = s.find(del, start);
582 if (stop == -1) 587 if (stop == -1)
583 stop = s.length() - del.length(); 588 stop = s.length() - del.length();
@@ -613,30 +618,27 @@ void EmailClient::readMail()
613} 618}
614 619
615void EmailClient::saveMail(QString fileName, QListView *view) 620void EmailClient::saveMail(QString fileName, QListView *view)
616{ 621{
617 QFile f(fileName); 622 QFile f(fileName);
618 Email *mail; 623 Email *mail;
619 624
620 if (! f.open(IO_WriteOnly) ) { 625 if (! f.open(IO_WriteOnly) ) {
621 qWarning("could not open file"); 626 qWarning("could not open file");
622 return; 627 return;
623 } 628 }
624 item = (EmailListItem *) view->firstChild(); 629 item = (EmailListItem *) view->firstChild();
625 //qDebug (QString("Write : ") );
626 QTextStream t(&f); 630 QTextStream t(&f);
627 while (item != NULL) { 631 while (item != NULL) {
628 mail = item->getMail(); 632 mail = item->getMail();
629 //qDebug(mail->rawMail);
630 //qDebug(mail->recipients.first());
631 t << mail->rawMail; 633 t << mail->rawMail;
632 634
633 mailconf->setGroup(mail->id); 635 mailconf->setGroup(mail->id);
634 mailconf->writeEntry("mailread", mail->read); 636 mailconf->writeEntry("mailread", mail->read);
635 637
636 item = (EmailListItem *) item->nextSibling(); 638 item = (EmailListItem *) item->nextSibling();
637 } 639 }
638 f.close(); 640 f.close();
639} 641}
640 642
641//paths for mailit, is settings, inbox, enclosures 643//paths for mailit, is settings, inbox, enclosures
642QString EmailClient::getPath(bool enclosurePath) 644QString EmailClient::getPath(bool enclosurePath)
@@ -653,128 +655,103 @@ QString EmailClient::getPath(bool enclosurePath)
653 655
654 if ( !dir.exists() ) 656 if ( !dir.exists() )
655 dir.mkdir( dir.path() ); 657 dir.mkdir( dir.path() );
656 658
657 return (dir.path() + "/"); 659 return (dir.path() + "/");
658 660
659 } 661 }
660 return (dir.path() + "/"); 662 return (dir.path() + "/");
661} 663}
662 664
663void EmailClient::readSettings() 665void EmailClient::readSettings()
664{ 666{
665 TextParser *p; 667 int y,acc_count, accountPos=0;
666 QString s;
667 int pos, accountPos, y;
668 QFile f( getPath(FALSE) + "settings.txt");
669
670 if ( f.open(IO_ReadOnly) ) { // file opened successfully
671 QTextStream t( &f ); // use a text stream
672 s = t.read();
673 f.close();
674
675 p = new TextParser(s, "\n");
676
677 accountPos = 0;
678 while ( (accountPos = p->find("ACCOUNTSTART",';', accountPos, TRUE)) != -1 ) {
679 accountPos++;
680 if ( (pos = p->find("ACCOUNTNAME",':', accountPos, TRUE)) != -1 )
681 account.accountName = p->getString(& ++pos, 'z', TRUE);
682 if ( (pos = p->find("NAME",':', accountPos, TRUE)) != -1)
683 account.name = p->getString(& ++pos, 'z', TRUE);
684 if ( (pos = p->find("EMAIL",':', accountPos, TRUE)) != -1)
685 account.emailAddress = p->getString(& ++pos, 'z', TRUE);
686 if ( (pos = p->find("POPUSER",':', accountPos, TRUE)) != -1)
687 account.popUserName = p->getString(& ++pos, 'z', TRUE);
688 if ( (pos = p->find("POPPASSWORD",':', accountPos, TRUE)) != -1)
689 account.popPasswd = p->getString(& ++pos, 'z', TRUE);
690 if ( (pos = p->find("POPSERVER",':', accountPos, TRUE)) != -1)
691 account.popServer = p->getString(& ++pos, 'z', TRUE);
692 if ( (pos = p->find("SMTPSERVER",':', accountPos, TRUE)) != -1)
693 account.smtpServer = p->getString(& ++pos, 'z', TRUE);
694 if ( (pos = p->find("ACCOUNTID",':', accountPos, TRUE)) != -1) {
695 s = p->getString(& ++pos, 'z', TRUE);
696 account.id = s.toInt();
697 }
698 668
669 mailconf->setGroup("mailitglobal");
670 acc_count=mailconf->readNumEntry("Accounts",0);
671
672 for (int accountPos = 0;accountPos<acc_count ; accountPos++)
673 {
674 mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ...
675 account.accountName = mailconf->readEntry("AccName","");
676 account.name = mailconf->readEntry("UserName","");
677 account.emailAddress = mailconf->readEntry("Email","");
678 account.popUserName = mailconf->readEntry("POPUser","");
679 account.popPasswd = mailconf->readEntryCrypt("POPPassword","");
680 account.popServer = mailconf->readEntry("POPServer","");
681 account.smtpServer = mailconf->readEntry("SMTPServer","");
682 account.id = mailconf->readNumEntry("AccountId",0);
683 account.syncLimit = mailconf->readNumEntry("HeaderLimit",0);
699 account.lastServerMailCount = 0; 684 account.lastServerMailCount = 0;
700 account.synchronize = FALSE; 685 account.synchronize = FALSE;
701 if ( (pos = p->find("SYNCHRONIZE",':', accountPos, TRUE)) != -1) {
702 if (p->getString(& ++pos, 'z', TRUE).upper() == "YES") {
703 account.synchronize = TRUE;
704 if ( (pos = p->find("LASTSERVERMAILCOUNT",':', accountPos, TRUE)) != -1) {
705 s = p->getString(& ++pos, 'z', TRUE);
706 account.lastServerMailCount = s.toInt();
707 }
708 }
709 }
710 686
711 if ( (pos = p->find("SYNCLIMIT",':', accountPos, TRUE)) != -1) { 687 account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes");
712 account.syncLimit = p->getString(& ++pos, 'z', TRUE).toInt(); 688 if (account.synchronize)
689 {
690 mailconf->readNumEntry("LASTSERVERMAILCOUNT",0);
713 } 691 }
714 692
715
716 accountList.append(&account); 693 accountList.append(&account);
717 } 694 }
718 delete p; 695
719 }
720 mailconf->setGroup("mailitglobal"); 696 mailconf->setGroup("mailitglobal");
721 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { 697
698 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1)
699 {
722 mailIdCount = y; 700 mailIdCount = y;
723 } 701 }
724 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1) { 702 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1)
703 {
725 accountIdCount = y; 704 accountIdCount = y;
726 } 705 }
727} 706}
728 707
729void EmailClient::saveSettings() 708void EmailClient::saveSettings()
730{ 709{
731 710 int acc_count=0;
732 QString temp;
733 QFile f( getPath(FALSE) + "settings.txt");
734 MailAccount *accountPtr; 711 MailAccount *accountPtr;
735 712
736 if (! f.open(IO_WriteOnly) ) { 713
737 qWarning("could not save settings file"); 714 if (!mailconf)
715 {
716 qWarning("could not save settings");
738 return; 717 return;
739 } 718 }
740 QTextStream t(&f);
741 t << "#Settings for OPIE Mailit program\n";
742 719
743 for (accountPtr = accountList.first(); accountPtr != 0; 720 for (accountPtr = accountList.first(); accountPtr != 0;
744 accountPtr = accountList.next()) { 721 accountPtr = accountList.next())
745 722 {
746 t << "accountStart;\n"; 723 mailconf->setGroup("Account_"+QString::number(++acc_count));
747 t << "AccountName: " + accountPtr->accountName + "\n"; 724 mailconf->writeEntry("AccName",accountPtr->accountName );
748 t << "Name: " + accountPtr->name + "\n"; 725 mailconf->writeEntry("UserName",accountPtr->name);
749 t << "Email: " + accountPtr->emailAddress + "\n"; 726 mailconf->writeEntry("Email",accountPtr->emailAddress);
750 t << "POPUser: " + accountPtr->popUserName + "\n"; 727 mailconf->writeEntry("POPUser",accountPtr->popUserName);
751 t << "POPPAssword: " + accountPtr->popPasswd + "\n"; 728 mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd);
752 t << "POPServer: " + accountPtr->popServer + "\n"; 729 mailconf->writeEntry("POPServer",accountPtr->popServer);
753 t << "SMTPServer: " + accountPtr->smtpServer + "\n"; 730 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer);
754 t << "AccountId: " << accountPtr->id << "\n"; 731 mailconf->writeEntry("AccountId",accountPtr->id);
755 if (accountPtr->synchronize) { 732 if (accountPtr->synchronize)
756 t << "Synchronize: Yes\n"; 733 {
757 t << "LastServerMailCount: "; 734 mailconf->writeEntry("Synchronize","Yes");
758 t << accountPtr->lastServerMailCount << "\n"; 735 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit);
759 } else { 736 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount);
760 t << "Synchronize: No\n"; 737 }
738 else
739 {
740 mailconf->writeEntry("Synchronize", "No");
761 } 741 }
762 t << "SyncLimit: ";
763 t << accountPtr->syncLimit << "\n";
764 t << "accountEnd;\n";
765 } 742 }
766 f.close();
767 743
768 mailconf->setGroup("mailitglobal"); 744 mailconf->setGroup("mailitglobal");
745 mailconf->writeEntry("Accounts",acc_count);
769 mailconf->writeEntry("mailidcount", mailIdCount); 746 mailconf->writeEntry("mailidcount", mailIdCount);
770 mailconf->writeEntry("accountidcount", accountIdCount); 747 mailconf->writeEntry("accountidcount", accountIdCount);
771} 748}
772 749
773void EmailClient::selectAccount(int id) 750void EmailClient::selectAccount(int id)
774{ 751{
775 if (accountList.count() > 0) { 752 if (accountList.count() > 0) {
776 currentAccount = accountList.at(id); 753 currentAccount = accountList.at(id);
777 emit newCaption("Mailit - " + currentAccount->accountName); 754 emit newCaption("Mailit - " + currentAccount->accountName);
778 getNewMail(); 755 getNewMail();
779 } else { 756 } else {
780 emit newCaption("Mailit ! No account defined"); 757 emit newCaption("Mailit ! No account defined");