00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qapplication.h>
00021 #include <qmessagebox.h>
00022 #include <qvbox.h>
00023 #include <qfile.h>
00024 #include <qcheckbox.h>
00025 #include <qmenubar.h>
00026 #include <qaction.h>
00027 #include <qwhatsthis.h>
00028 #include <qpe/resource.h>
00029 #include "emailclient.h"
00030 #include "writemail.h"
00031
00032 QCollection::Item AccountList::newItem(QCollection::Item d)
00033 {
00034 return dupl( (MailAccount *) d);
00035 }
00036
00037 MailAccount* AccountList::dupl(MailAccount *in)
00038 {
00039 ac = new MailAccount(*in);
00040 return ac;
00041 }
00042
00043 EmailClient::EmailClient( QWidget* parent, const char* name, WFlags fl )
00044 : QMainWindow( parent, name, fl )
00045 {
00046 emailHandler = new EmailHandler();
00047 addressList = new AddressList();
00048
00049 sending = FALSE;
00050 receiving = FALSE;
00051 previewingMail = FALSE;
00052 mailIdCount = 1;
00053 accountIdCount = 1;
00054 allAccounts = FALSE;
00055
00056 init();
00057
00058
00059
00060 connect(emailHandler, SIGNAL(mailSent()), this, SLOT(mailSent()) );
00061
00062 connect(emailHandler, SIGNAL(smtpError(int,const QString&)), this,
00063 SLOT(smtpError(int,const QString&)) );
00064 connect(emailHandler, SIGNAL(popError(int,const QString&)), this,
00065 SLOT(popError(int,const QString&)) );
00066
00067 connect(inboxView, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(inboxItemSelected()) );
00068 connect(outboxView, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(outboxItemSelected()) );
00069
00070 connect(inboxView, SIGNAL(pressed(QListViewItem*)), this, SLOT(inboxItemPressed()) );
00071 connect(inboxView, SIGNAL(clicked(QListViewItem*)), this, SLOT(inboxItemReleased()) );
00072
00073 connect(emailHandler, SIGNAL(mailArrived(const Email&,bool)), this,
00074 SLOT(mailArrived(const Email&,bool)) );
00075 connect(emailHandler, SIGNAL(mailTransfered(int)), this,
00076 SLOT(allMailArrived(int)) );
00077
00078 mailconf = new Config("mailit");
00079
00080
00081 readSettings();
00082
00083 updateAccounts();
00084
00085 lineShift = "\n";
00086 readMail();
00087 lineShift = "\r\n";
00088
00089 mailboxView->setCurrentTab(0);
00090
00091
00092
00093
00094
00095 }
00096
00097
00098 EmailClient::~EmailClient()
00099 {
00100
00101 saveMail(getPath(FALSE) + "inbox.txt", inboxView);
00102
00103
00104
00105 saveMail(getPath(FALSE) + "outbox.txt", outboxView);
00106 saveSettings();
00107
00108 mailconf->write();
00109 delete mailconf;
00110
00111 }
00112
00113 void EmailClient::init()
00114 {
00115 initStatusBar(this);
00116
00117 setToolBarsMovable(FALSE);
00118
00119 bar = new QToolBar(this);
00120 QWhatsThis::add(bar,tr("Main operation toolbar"));
00121 bar->setHorizontalStretchable( TRUE );
00122
00123 mb = new QMenuBar( bar );
00124
00125 QPopupMenu *mail = new QPopupMenu(mb);
00126 mb->insertItem( tr( "&Mail" ), mail);
00127
00128 QPopupMenu *configure = new QPopupMenu(mb);
00129 mb->insertItem( tr( "Accounts" ), configure);
00130
00131 selectAccountMenu = new QPopupMenu(mb);
00132 editAccountMenu = new QPopupMenu(mb);
00133 deleteAccountMenu = new QPopupMenu(mb);
00134
00135 mail->insertItem(tr("Get Mail in"), selectAccountMenu);
00136 configure->insertItem(tr("Edit account"), editAccountMenu);
00137 configure->insertItem(tr("Delete account"), deleteAccountMenu);
00138
00139 bar = new QToolBar(this);
00140
00141 getMailButton = new QToolButton(Resource::loadPixmap("mailit/getmail"),tr("getMail"),tr("select account"), this,SLOT(getAllNewMail()),bar);
00142 QWhatsThis::add(getMailButton,tr("Click to download mail via all available accounts.\n Press and hold to select the desired account."));
00143
00144 getMailButton->setPopup(selectAccountMenu);
00145
00146 sendMailButton = new QAction(tr("Send mail"), Resource::loadPixmap("mailit/sendqueue"), QString::null, 0, this, 0);
00147 connect(sendMailButton, SIGNAL(activated()), this, SLOT(sendQuedMail()) );
00148 sendMailButton->addTo(bar);
00149 sendMailButton->addTo(mail);
00150 sendMailButton->setWhatsThis("Send mail queued in the outbox");
00151
00152 composeButton = new QAction(tr("Compose"), Resource::loadPixmap("new"), QString::null, 0, this, 0);
00153 connect(composeButton, SIGNAL(activated()), this, SLOT(compose()) );
00154 composeButton->addTo(bar);
00155 composeButton->addTo(mail);
00156 composeButton->setWhatsThis("Compose a new mail");
00157
00158 cancelButton = new QAction(tr("Cancel transfer"), Resource::loadPixmap("close"), QString::null, 0, this, 0);
00159 connect(cancelButton, SIGNAL(activated()), this, SLOT(cancel()) );
00160 cancelButton->addTo(mail);
00161 cancelButton->addTo(bar);
00162 cancelButton->setEnabled(FALSE);
00163 cancelButton->setWhatsThis("Stop the currently active mail transfer");
00164
00165
00166 deleteButton = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 );
00167 connect( deleteButton, SIGNAL( activated() ), this, SLOT( deleteItem() ) );
00168 deleteButton->addTo(bar);
00169 deleteButton->setWhatsThis("Remove the currently selected eMail(s)");
00170
00171 mailboxView = new OTabWidget( this, "mailboxView" );
00172
00173 QWidget* widget = new QWidget( mailboxView, "widget" );
00174 grid_2 = new QGridLayout( widget );
00175
00176
00177
00178 inboxView = new QListView( widget, "inboxView" );
00179 inboxView->addColumn( tr( "From" ) );
00180 inboxView->addColumn( tr( "Subject" ) );
00181 inboxView->addColumn( tr( "Date" ) );
00182 inboxView->setMinimumSize( QSize( 0, 0 ) );
00183 inboxView->setAllColumnsShowFocus(TRUE);
00184 QWhatsThis::add(inboxView,QWidget::tr("This is the inbox view.\n"
00185 "It keeps the fetched mail which can be \n"
00186 "viewed by double clicking the entry.\n"
00187 "blue attachment icon shows whether this \n"
00188 "mailhas attachments.\n"));
00189
00190 grid_2->addWidget( inboxView, 2, 0 );
00191 mailboxView->addTab( widget, "mailit/inbox", tr( "Inbox" ) );
00192
00193 QWidget* widget_2 = new QWidget( mailboxView, "widget_2" );
00194 grid_3 = new QGridLayout( widget_2 );
00195
00196
00197
00198 outboxView = new QListView( widget_2, "outboxView" );
00199 outboxView->addColumn( tr( "To" ) );
00200 outboxView->addColumn( tr( "Subject" ) );
00201 outboxView->setAllColumnsShowFocus(TRUE);
00202
00203 QWhatsThis::add(outboxView,QWidget::tr("This is the outbox view.\n"
00204 "It keeps the queued mails to send which can be \n"
00205 "reviewed by double clicking the entry."));
00206 grid_3->addWidget( outboxView, 0, 0 );
00207 mailboxView->addTab( widget_2,"mailit/outbox", tr( "Outbox" ) );
00208
00209 setCentralWidget(mailboxView);
00210
00211 }
00212
00213 void EmailClient::initStatusBar(QWidget* parent)
00214 {
00215 statusBar = new QStatusBar(parent);
00216 statusBar->setSizeGripEnabled(FALSE);
00217
00218 status1Label = new QLabel( tr("Idle"), statusBar);
00219 status2Label = new QLabel("", statusBar);
00220 connect(emailHandler, SIGNAL(updatePopStatus(const QString&)),
00221 status2Label, SLOT(setText(const QString&)) );
00222 connect(emailHandler, SIGNAL(updateSmtpStatus(const QString&)),
00223 status2Label, SLOT(setText(const QString&)) );
00224
00225 progressBar = new QProgressBar(statusBar);
00226
00227 connect(emailHandler, SIGNAL(mailboxSize(int)),
00228 this, SLOT(setTotalSize(int)) );
00229 connect(emailHandler, SIGNAL(currentMailSize(int)),
00230 this, SLOT(setMailSize(int)) );
00231 connect(emailHandler, SIGNAL(downloadedSize(int)),
00232 this, SLOT(setDownloadedSize(int)) );
00233
00234 statusBar->addWidget(status1Label);
00235 statusBar->addWidget(progressBar);
00236 statusBar->addWidget(status2Label);
00237
00238 }
00239
00240 void EmailClient::compose()
00241 {
00242 emit composeRequested();
00243 }
00244
00245 void EmailClient::cancel()
00246 {
00247 emailHandler->cancel();
00248 }
00249
00250 AddressList* EmailClient::getAdrListRef()
00251 {
00252 return addressList;
00253 }
00254
00255
00256 void EmailClient::enqueMail(const Email &mail)
00257 {
00258 if (accountList.count() == 0) {
00259 QMessageBox::warning(qApp->activeWindow(),
00260 tr("No account selected"), tr("You must create an account"), "OK\n");
00261 return;
00262 }
00263
00264 if (accountList.count() > 0) {
00265 currentAccount = accountList.first();
00266 qWarning("using account " + currentAccount->name);
00267 }
00268
00269 Email addMail = mail;
00270 addMail.from = currentAccount->name;
00271 addMail.fromMail = currentAccount->emailAddress;
00272 addMail.rawMail.prepend("From: \"" + addMail.from + "\" <" + addMail.fromMail + ">\n");
00273 item = new EmailListItem(outboxView, addMail, false);
00274
00275 mailboxView->setCurrentTab(1);
00276
00277 }
00278
00279 void EmailClient::sendQuedMail()
00280 {
00281 int count = 0;
00282
00283 if (accountList.count() == 0) {
00284 QMessageBox::warning(qApp->activeWindow(), tr("No account selected"), tr("You must create an account"), "OK\n");
00285 return;
00286 }
00287
00288 if (! sending) {
00289 item = (EmailListItem *) outboxView->firstChild();
00290 if (item != NULL) {
00291 while (item != NULL) {
00292 quedMessages.append(item->getMail());
00293 item = (EmailListItem *) item->nextSibling();
00294 count++;
00295 }
00296 setMailAccount();
00297 emailHandler->sendMail(&quedMessages);
00298 sending = TRUE;
00299 sendMailButton->setEnabled(FALSE);
00300 cancelButton->setEnabled(TRUE);
00301 } else {
00302 qWarning("sendQuedMail(): no messages to send");
00303 }
00304 }
00305 }
00306
00307 void EmailClient::setMailAccount()
00308 {
00309 emailHandler->setAccount(*currentAccount);
00310 }
00311
00312 void EmailClient::mailSent()
00313 {
00314 sending = FALSE;
00315 sendMailButton->setEnabled(TRUE);
00316
00317 quedMessages.clear();
00318 outboxView->clear();
00319 }
00320
00321 void EmailClient::getNewMail() {
00322
00323 if (accountList.count() == 0) {
00324 QMessageBox::warning(qApp->activeWindow(),tr("No account selected"),
00325 tr("You must create an account"), "OK\n");
00326 return;
00327 }
00328
00329 setMailAccount();
00330
00331 receiving = TRUE;
00332 previewingMail = TRUE;
00333 getMailButton->setEnabled(FALSE);
00334 cancelButton->setEnabled(TRUE);
00335 selectAccountMenu->setEnabled(FALSE);
00336
00337 status1Label->setText(currentAccount->accountName + " headers");
00338 progressBar->reset();
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 emailHandler->getMailHeaders();
00353
00354 }
00355
00356 void EmailClient::getAllNewMail()
00357 {
00358 allAccounts = TRUE;
00359 currentAccount = accountList.first();
00360 getNewMail();
00361 }
00362
00363 void EmailClient::mailArrived(const Email &mail, bool fromDisk)
00364 {
00365 Enclosure *ePtr;
00366 Email newMail;
00367 int thisMailId;
00368 emailHandler->parse( mail.rawMail, lineShift, &newMail);
00369 mailconf->setGroup(newMail.id);
00370
00371 if (fromDisk)
00372 {
00373
00374 newMail.downloaded = mailconf->readBoolEntry("downloaded");
00375 newMail.size = mailconf->readNumEntry("size");
00376 newMail.serverId = mailconf->readNumEntry("serverid");
00377 newMail.fromAccountId = mailconf->readNumEntry("fromaccountid");
00378 }
00379 else
00380 {
00381
00382 newMail.serverId = mail.serverId;
00383 newMail.size = mail.size;
00384 newMail.downloaded = mail.downloaded;
00385
00386 newMail.fromAccountId = emailHandler->getAccount()->id;
00387 mailconf->writeEntry("fromaccountid", newMail.fromAccountId);
00388 }
00389
00390
00391 newMail.read = mailconf->readBoolEntry("mailread");
00392
00393
00394 if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) {
00395 thisMailId = mailIdCount;
00396 mailIdCount++;
00397
00398
00399
00400 if ((currentAccount)&&(currentAccount->synchronize))
00401 currentAccount->lastServerMailCount++;
00402
00403 mailconf->writeEntry("internalmailid", thisMailId);
00404 mailconf->writeEntry("downloaded", newMail.downloaded);
00405 mailconf->writeEntry("size", (int) newMail.size);
00406 mailconf->writeEntry("serverid", newMail.serverId);
00407
00408
00409 }
00410
00411 mailconf->writeEntry("downloaded", newMail.downloaded);
00412
00413 QString stringMailId;
00414 stringMailId.setNum(thisMailId);
00415
00416
00417 for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) {
00418 QString stringId;
00419 stringId.setNum(ePtr->id);
00420
00421 int id = mailconf->readNumEntry("enclosureid_" + stringId);
00422 if (id != ePtr->id) {
00423 mailconf->writeEntry("enclosureid_" + stringId, ePtr->id);
00424 mailconf->writeEntry("name_" + stringId, ePtr->originalName);
00425 mailconf->writeEntry("contenttype_" + stringId, ePtr->contentType);
00426 mailconf->writeEntry("contentattribute_" + stringId, ePtr->contentAttribute);
00427 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
00428 mailconf->writeEntry("installed_" + stringId, FALSE);
00429
00430 ePtr->name = stringMailId + "_" + stringId;
00431 ePtr->path = getPath(TRUE);
00432 if (emailHandler->getEnclosure(ePtr)) {
00433 ePtr->saved = TRUE;
00434 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
00435 mailconf->writeEntry("filename_" + stringId, ePtr->name);
00436 mailconf->writeEntry("path_" + stringId, ePtr->path);
00437 } else {
00438 ePtr->saved = FALSE;
00439 mailconf->writeEntry("saved_" + stringId, ePtr->saved);
00440 }
00441 } else {
00442 ePtr->saved = mailconf->readBoolEntry("saved_" + stringId);
00443 ePtr->installed = mailconf->readBoolEntry("installed_" + stringId);
00444 if (ePtr->saved) {
00445 ePtr->name = mailconf->readEntry("filename_" + stringId);
00446 ePtr->path = mailconf->readEntry("path_" + stringId);
00447 }
00448 }
00449 }
00450
00451 bool found=false;
00452
00453 if (!fromDisk)
00454 {
00455
00456 Email *mailPtr;
00457 item = (EmailListItem *) inboxView->firstChild();
00458 while ((item != NULL)&&(!found))
00459 {
00460 mailPtr = item->getMail();
00461 if (mailPtr->id == newMail.id) {
00462 item->setMail(newMail);
00463 emit mailUpdated(item->getMail());
00464 found = true;
00465 }
00466 item = (EmailListItem *) item->nextSibling();
00467 }
00468 }
00469 if ((!found)||(fromDisk)) {
00470 item = new EmailListItem(inboxView, newMail, TRUE);
00471 }
00472
00473
00474
00475
00476
00477
00478
00479 mailboxView->setCurrentTab(0);
00480
00481 }
00482
00483 void EmailClient::allMailArrived(int )
00484 {
00485
00486
00487 if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) {
00488 emit newCaption("Mailit - " + currentAccount->accountName);
00489 getNewMail();
00490 return;
00491 } else {
00492 allAccounts = FALSE;
00493 receiving = FALSE;
00494 getMailButton->setEnabled(TRUE);
00495 cancelButton->setEnabled(FALSE);
00496 selectAccountMenu->setEnabled(TRUE);
00497 status1Label->setText("Idle");
00498
00499 progressBar->reset();
00500 return;
00501 }
00502
00503
00504
00505 previewingMail = FALSE;
00506 status1Label->setText(currentAccount->accountName);
00507 progressBar->reset();
00508
00509
00510 mailboxView->setCurrentTab(0);
00511 }
00512
00513
00514 void EmailClient::moveMailFront(Email *mailPtr)
00515 {
00516 if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) {
00517 mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size);
00518 }
00519 }
00520
00521 void EmailClient::smtpError(int code, const QString & Msg)
00522 {
00523 QString temp;
00524
00525 if (code == ErrUnknownResponse) {
00526 temp = tr("<qt>Unknown response from server</qt>");
00527 if( ! Msg.isEmpty() )
00528 temp += Msg;
00529 } else if (code == QSocket::ErrHostNotFound) {
00530 temp = tr("<qt>host not found</qt>");
00531 } else if (code == QSocket::ErrConnectionRefused) {
00532 temp = tr("<qt>connection refused</qt>");
00533 } else if (code == QSocket::ErrSocketRead) {
00534 temp = tr("<qt>socket packet error</qt>");
00535 }
00536
00537 if (code != ErrCancel) {
00538 QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n");
00539 } else {
00540 status2Label->setText("Aborted by user");
00541 }
00542
00543 sending = FALSE;
00544 sendMailButton->setEnabled(TRUE);
00545 cancelButton->setEnabled(FALSE);
00546 quedMessages.clear();
00547 }
00548
00549 void EmailClient::popError(int code, const QString & Msg)
00550 {
00551 QString temp;
00552
00553 if (code == ErrUnknownResponse) {
00554 temp = tr("<qt>Unknown response from server</qt>");
00555 if( ! Msg.isEmpty() )
00556 temp += Msg;
00557 } else if (code == ErrLoginFailed) {
00558 temp = tr("<qt>Login failed\nCheck user name and password</qt>");
00559 } else if (code == QSocket::ErrHostNotFound) {
00560 temp = tr("<qt>host not found</qt>");
00561 } else if (code == QSocket::ErrConnectionRefused) {
00562 temp = tr("<qt>connection refused</qt>");
00563 } else if (code == QSocket::ErrSocketRead) {
00564 temp = tr("<qt>socket packet error</qt>");
00565 }
00566
00567 if (code != ErrCancel) {
00568 QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp, tr("OK\n"));
00569
00570 } else {
00571 status2Label->setText("Aborted by user");
00572 }
00573
00574 receiving = FALSE;
00575 getMailButton->setEnabled(TRUE);
00576 cancelButton->setEnabled(FALSE);
00577 selectAccountMenu->setEnabled(TRUE);
00578 }
00579
00580 void EmailClient::inboxItemSelected()
00581 {
00582
00583
00584 item = (EmailListItem*) inboxView->selectedItem();
00585 if (item != NULL) {
00586 emit viewEmail(inboxView, item->getMail());
00587 }
00588 }
00589
00590 void EmailClient::outboxItemSelected()
00591 {
00592
00593
00594 item = (EmailListItem*) outboxView->selectedItem();
00595 if (item != NULL) {
00596 emit viewEmail(outboxView, item->getMail());
00597 }
00598
00599 }
00600
00601 void EmailClient::readMail()
00602 {
00603 Email mail;
00604 int start, stop;
00605 QString s, del;
00606
00607 QFile f(getPath(FALSE) + "inbox.txt");
00608
00609 if ( f.open(IO_ReadOnly) ) {
00610 QTextStream t( &f );
00611 s = t.read();
00612 f.close();
00613
00614 start = 0;
00615 del = "\n.\n";
00616 while ((uint) start < s.length()) {
00617 stop = s.find(del, start);
00618 if (stop == -1)
00619 stop = s.length() - del.length();
00620
00621 mail.rawMail = s.mid(start, stop + del.length() - start );
00622 start = stop + del.length();
00623 mailArrived(mail, TRUE);
00624 }
00625 }
00626
00627 QFile fo(getPath(FALSE) + "outbox.txt");
00628 if ( fo.open(IO_ReadOnly) ) {
00629 QTextStream t( &fo );
00630 s = t.read();
00631 fo.close();
00632
00633 start = 0;
00634 del = "\n.\n";
00635 while ((uint) start < s.length()) {
00636 stop = s.find(del, start);
00637 if (stop == -1)
00638 stop = s.length() - del.length();
00639
00640 mail.rawMail = s.mid(start, stop + del.length() - start );
00641 start = stop + del.length();
00642 emailHandler->parse(mail.rawMail, lineShift, &mail);
00643 mail.sent = false;
00644 mail.received = false;
00645 enqueMail(mail);
00646
00647 }
00648 }
00649 }
00650
00651 void EmailClient::saveMail(const QString &fileName, QListView *view)
00652 {
00653 QFile f(fileName);
00654 Email *mail;
00655
00656 if (! f.open(IO_WriteOnly) ) {
00657 qWarning("could not open file");
00658 return;
00659 }
00660 item = (EmailListItem *) view->firstChild();
00661 QTextStream t(&f);
00662 while (item != NULL) {
00663 mail = item->getMail();
00664 t << mail->rawMail;
00665
00666 mailconf->setGroup(mail->id);
00667 mailconf->writeEntry("mailread", mail->read);
00668
00669 item = (EmailListItem *) item->nextSibling();
00670 }
00671 f.close();
00672 }
00673
00674
00675 QString EmailClient::getPath(bool enclosurePath)
00676 {
00677 QString basePath = "qtmail";
00678 QString enclosures = "enclosures";
00679
00680 QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath);
00681 if ( !dir.exists() )
00682 dir.mkdir( dir.path() );
00683
00684 if (enclosurePath) {
00685 dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures);
00686
00687 if ( !dir.exists() )
00688 dir.mkdir( dir.path() );
00689
00690 return (dir.path() + "/");
00691
00692 }
00693 return (dir.path() + "/");
00694 }
00695
00696 void EmailClient::readSettings()
00697 {
00698 int y,acc_count;
00699
00700 mailconf->setGroup("mailitglobal");
00701 acc_count=mailconf->readNumEntry("Accounts",0);
00702
00703 for (int accountPos = 0;accountPos<acc_count ; accountPos++)
00704 {
00705 mailconf->setGroup("Account_"+QString::number(accountPos+1));
00706 account.accountName = mailconf->readEntry("AccName","");
00707 account.name = mailconf->readEntry("UserName","");
00708 account.emailAddress = mailconf->readEntry("Email","");
00709 account.popUserName = mailconf->readEntry("POPUser","");
00710 account.popPasswd = mailconf->readEntryCrypt("POPPassword","");
00711 account.popServer = mailconf->readEntry("POPServer","");
00712 account.smtpServer = mailconf->readEntry("SMTPServer","");
00713 account.id = mailconf->readNumEntry("AccountId",0);
00714 account.syncLimit = mailconf->readNumEntry("HeaderLimit",0);
00715 account.lastServerMailCount = 0;
00716 account.synchronize = FALSE;
00717
00718 account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes");
00719 if (account.synchronize)
00720 {
00721 mailconf->readNumEntry("LASTSERVERMAILCOUNT",0);
00722 }
00723
00724 accountList.append(&account);
00725 }
00726
00727 mailconf->setGroup("mailitglobal");
00728
00729 if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1)
00730 {
00731 mailIdCount = y;
00732 }
00733 if ( (y = mailconf->readNumEntry("accountidcount", -1)) != -1)
00734 {
00735 accountIdCount = y;
00736 }
00737 }
00738
00739 void EmailClient::saveSettings()
00740 {
00741 int acc_count=0;
00742 MailAccount *accountPtr;
00743
00744
00745 if (!mailconf)
00746 {
00747 qWarning("could not save settings");
00748 return;
00749 }
00750
00751 for (accountPtr = accountList.first(); accountPtr != 0;
00752 accountPtr = accountList.next())
00753 {
00754 mailconf->setGroup("Account_"+QString::number(++acc_count));
00755 mailconf->writeEntry("AccName",accountPtr->accountName );
00756 mailconf->writeEntry("UserName",accountPtr->name);
00757 mailconf->writeEntry("Email",accountPtr->emailAddress);
00758 mailconf->writeEntry("POPUser",accountPtr->popUserName);
00759 mailconf->writeEntryCrypt("POPPassword",accountPtr->popPasswd);
00760 mailconf->writeEntry("POPServer",accountPtr->popServer);
00761 mailconf->writeEntry("SMTPServer",accountPtr->smtpServer);
00762 mailconf->writeEntry("AccountId",accountPtr->id);
00763 if (accountPtr->synchronize)
00764 {
00765 mailconf->writeEntry("Synchronize","Yes");
00766 mailconf->writeEntry("HeaderLimit",accountPtr->syncLimit);
00767 mailconf->writeEntry("LastServerMailCount",accountPtr->lastServerMailCount);
00768 }
00769 else
00770 {
00771 mailconf->writeEntry("Synchronize", "No");
00772 }
00773 }
00774
00775 mailconf->setGroup("mailitglobal");
00776 mailconf->writeEntry("Accounts",acc_count);
00777 mailconf->writeEntry("mailidcount", mailIdCount);
00778 mailconf->writeEntry("accountidcount", accountIdCount);
00779 }
00780
00781 void EmailClient::selectAccount(int id)
00782 {
00783 if (accountList.count() > 0) {
00784 currentAccount = accountList.at(id);
00785 emit newCaption("Mailit - " + currentAccount->accountName);
00786 getNewMail();
00787 } else {
00788 emit newCaption( tr("Mailit ! No account defined") );
00789 }
00790 }
00791
00792 void EmailClient::editAccount(int id)
00793 {
00794 MailAccount *newAccount;
00795
00796 editAccountView = new EditAccount(this, "account", TRUE);
00797 if (id == newAccountId) {
00798 newAccount = new MailAccount;
00799 editAccountView->setAccount(newAccount);
00800 } else {
00801 newAccount = accountList.at(id);
00802 editAccountView->setAccount(newAccount, FALSE);
00803 }
00804
00805 editAccountView->showMaximized();
00806 editAccountView->exec();
00807
00808 if (editAccountView->result() == QDialog::Accepted) {
00809 if (id == newAccountId) {
00810 newAccount->id = accountIdCount;
00811 accountIdCount++;
00812 accountList.append(newAccount);
00813 updateAccounts();
00814 } else {
00815 updateAccounts();
00816 }
00817 }
00818
00819 delete editAccountView;
00820 }
00821
00822 void EmailClient::deleteAccount(int id)
00823 {
00824 MailAccount *newAccount;
00825 QString message;
00826
00827 newAccount = accountList.at(id);
00828 message = tr("Delete account:\n") + newAccount->accountName;
00829 switch( QMessageBox::warning( this, "Mailit", message,
00830 "Yes", "No", 0, 0, 1 ) ) {
00831
00832 case 0: accountList.remove(id);
00833 updateAccounts();
00834 break;
00835 case 1:
00836 break;
00837 }
00838 }
00839
00840 void EmailClient::updateAccounts()
00841 {
00842 MailAccount *accountPtr;
00843
00844
00845 editAccountMenu->clear();
00846 selectAccountMenu->clear();
00847 deleteAccountMenu->clear();
00848
00849 newAccountId = editAccountMenu->insertItem( tr("New"), this,
00850 SLOT(editAccount(int)) );
00851 editAccountMenu->insertSeparator();
00852
00853 idCount = 0;
00854 for (accountPtr = accountList.first(); accountPtr != 0;
00855 accountPtr = accountList.next()) {
00856
00857 editAccountMenu->insertItem(accountPtr->accountName,
00858 this, SLOT(editAccount(int)), 0, idCount);
00859 selectAccountMenu->insertItem(accountPtr->accountName,
00860 this, SLOT(selectAccount(int)), 0, idCount);
00861 deleteAccountMenu->insertItem(accountPtr->accountName,
00862 this, SLOT(deleteAccount(int)), 0, idCount);
00863 idCount++;
00864 }
00865 }
00866
00867 void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox)
00868 {
00869 Email *mPtr;
00870 Enclosure *ePtr;
00871
00872 if (inbox)
00873 {
00874 mPtr = mailItem->getMail();
00875
00876
00877
00878 if ( (receiving) && (mPtr->fromAccountId == currentAccount->id) ) {
00879 if ( !mPtr->downloaded )
00880 mailDownloadList.remove(mPtr->serverId, mPtr->size);
00881 }
00882
00883 mailconf->setGroup(mPtr->id);
00884 mailconf->clearGroup();
00885
00886
00887 for ( ePtr=mPtr->files.first(); ePtr != 0; ePtr=mPtr->files.next() ) {
00888 if (ePtr->saved) {
00889 QFile::remove( (ePtr->path + ePtr->name) );
00890 }
00891 }
00892 inboxView->takeItem(mailItem);
00893 }
00894 else
00895 {
00896 outboxView->takeItem(mailItem);
00897 }
00898 }
00899
00900 void EmailClient::setMailSize(int size)
00901 {
00902 progressBar->reset();
00903 progressBar->setTotalSteps(size);
00904 }
00905
00906 void EmailClient::setTotalSize(int )
00907 {
00908
00909 }
00910
00911 void EmailClient::setDownloadedSize(int size)
00912 {
00913 int total = progressBar->totalSteps();
00914
00915 if (size < total) {
00916 progressBar->setProgress(size);
00917 } else {
00918 progressBar->setProgress(total);
00919 }
00920 }
00921
00922 void EmailClient::deleteItem()
00923 {
00924 bool inbox=mailboxView->currentTab()==0;
00925 QListView* box;
00926
00927 EmailListItem* eli;
00928
00929
00930 inbox ? box=inboxView : box=outboxView;
00931
00932 eli=(EmailListItem*)box->selectedItem();
00933
00934 if (eli)
00935 {
00936 box->setSelected(eli->itemBelow(),true);
00937
00938 deleteMail(eli,(bool&)inbox);
00939 }
00940 }
00941
00942 void EmailClient::inboxItemPressed()
00943 {
00944
00945 }
00946
00947 void EmailClient::inboxItemReleased()
00948 {
00949
00950 }
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972 Email* EmailClient::getCurrentMail()
00973 {
00974 EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem());
00975 if (eli!=NULL)
00976 return eli->getMail();
00977 else
00978 return NULL;
00979 }
00980
00981 void EmailClient::download(Email* mail)
00982 {
00983 MailAccount* acc=0;
00984
00985 tempMailDownloadList.clear();
00986 tempMailDownloadList.sizeInsert(mail->serverId, mail->size);
00987
00988 acc=accountList.at(mail->fromAccountId-1);
00989 if (acc)
00990 {
00991 emailHandler->setAccount(*acc);
00992 emailHandler->getMailByList(&tempMailDownloadList);
00993 }
00994 else
00995 QMessageBox::warning(qApp->activeWindow(),
00996 tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n");
00997 }
00998
00999 void EmailClient::receive(const QCString& , const QByteArray& )
01000 {
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042 }