author | groucho <groucho> | 2003-04-28 08:31:24 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-04-28 08:31:24 (UTC) |
commit | 63d3f7ca039d93612abaa4a65fc00b337c42ec9d (patch) (side-by-side diff) | |
tree | ea4a08e00d5a229f20c3e4150f707a2ac8f9e882 | |
parent | c3b703405fe77fbe16596ebd7d814a6e463f9243 (diff) | |
download | opie-63d3f7ca039d93612abaa4a65fc00b337c42ec9d.zip opie-63d3f7ca039d93612abaa4a65fc00b337c42ec9d.tar.gz opie-63d3f7ca039d93612abaa4a65fc00b337c42ec9d.tar.bz2 |
- bug fixes in the parser (from header)
- bug fixes in address selector (uses cc: now)
- remove now selects next item afterwards (speeds up mass deletion)
- smaller fixes
-rw-r--r-- | noncore/net/mailit/emailclient.cpp | 75 | ||||
-rw-r--r-- | noncore/net/mailit/emailclient.h | 3 | ||||
-rw-r--r-- | noncore/net/mailit/emailhandler.cpp | 16 | ||||
-rw-r--r-- | noncore/net/mailit/emailhandler.h | 1 | ||||
-rw-r--r-- | noncore/net/mailit/mailitwindow.cpp | 26 | ||||
-rw-r--r-- | noncore/net/mailit/popclient.cpp | 80 | ||||
-rw-r--r-- | noncore/net/mailit/writemail.cpp | 28 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailclient.cpp | 75 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailclient.h | 3 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailhandler.cpp | 16 | ||||
-rw-r--r-- | noncore/unsupported/mailit/emailhandler.h | 1 | ||||
-rw-r--r-- | noncore/unsupported/mailit/mailitwindow.cpp | 26 | ||||
-rw-r--r-- | noncore/unsupported/mailit/popclient.cpp | 80 | ||||
-rw-r--r-- | noncore/unsupported/mailit/writemail.cpp | 28 |
14 files changed, 208 insertions, 250 deletions
diff --git a/noncore/net/mailit/emailclient.cpp b/noncore/net/mailit/emailclient.cpp index 23059cf..dff1888 100644 --- a/noncore/net/mailit/emailclient.cpp +++ b/noncore/net/mailit/emailclient.cpp @@ -333,65 +333,65 @@ void EmailClient::getNewMail() { emailHandler->getMailHeaders(); } void EmailClient::getAllNewMail() { allAccounts = TRUE; currentAccount = accountList.first(); getNewMail(); } void EmailClient::mailArrived(const Email &mail, bool fromDisk) { Enclosure *ePtr; Email newMail; int thisMailId; emailHandler->parse(mail.rawMail, lineShift, &newMail); mailconf->setGroup(newMail.id); if (fromDisk) { newMail.downloaded = mailconf->readBoolEntry("downloaded"); newMail.size = mailconf->readNumEntry("size"); newMail.serverId = mailconf->readNumEntry("serverid"); newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); } else { //mail arrived from server newMail.serverId = mail.serverId; newMail.size = mail.size; newMail.downloaded = mail.downloaded; - newMail.fromAccountId = currentAccount->id; + newMail.fromAccountId = emailHandler->getAccount()->id; mailconf->writeEntry("fromaccountid", newMail.fromAccountId); } //add if read or not newMail.read = mailconf->readBoolEntry("mailread"); //check if new mail if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { thisMailId = mailIdCount; mailIdCount++; //set server count, so that if the user aborts, the new //header is not reloaded if ((currentAccount)&&(currentAccount->synchronize)) currentAccount->lastServerMailCount++; mailconf->writeEntry("internalmailid", thisMailId); mailconf->writeEntry("downloaded", newMail.downloaded); mailconf->writeEntry("size", (int) newMail.size); mailconf->writeEntry("serverid", newMail.serverId); //addressList->addContact(newMail.fromMail, newMail.from); } mailconf->writeEntry("downloaded", newMail.downloaded); QString stringMailId; stringMailId.setNum(thisMailId); //see if any attatchments needs to be stored for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { QString stringId; @@ -451,69 +451,69 @@ void EmailClient::mailArrived(const Email &mail, bool fromDisk) mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ mailboxView->setCurrentTab(0); } void EmailClient::allMailArrived(int count) { // not previewing means all mailtransfer has been done /*if (!previewingMail) {*/ if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { emit newCaption("Mailit - " + currentAccount->accountName); getNewMail(); return; } else { allAccounts = FALSE; receiving = FALSE; getMailButton->setEnabled(TRUE); cancelButton->setEnabled(FALSE); selectAccountMenu->setEnabled(TRUE); status1Label->setText("Idle"); progressBar->reset(); return; } //} // all headers downloaded from server, start downloading remaining mails previewingMail = FALSE; status1Label->setText(currentAccount->accountName); progressBar->reset(); - //emailHandler->getMailByList(&mailDownloadList); - + mailboxView->setCurrentTab(0); } + void EmailClient::moveMailFront(Email *mailPtr) { if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); } } void EmailClient::smtpError(int code) { QString temp; if (code == ErrUnknownResponse) temp = "Unknown response from server"; if (code == QSocket::ErrHostNotFound) temp = "host not found"; if (code == QSocket::ErrConnectionRefused) temp = "connection refused"; if (code == QSocket::ErrSocketRead) temp = "socket packet error"; if (code != ErrCancel) { QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); } else { status2Label->setText("Aborted by user"); } sending = FALSE; sendMailButton->setEnabled(TRUE); cancelButton->setEnabled(FALSE); quedMessages.clear(); } @@ -635,65 +635,65 @@ void EmailClient::saveMail(QString fileName, QListView *view) mailconf->setGroup(mail->id); mailconf->writeEntry("mailread", mail->read); item = (EmailListItem *) item->nextSibling(); } f.close(); } //paths for mailit, is settings, inbox, enclosures QString EmailClient::getPath(bool enclosurePath) { QString basePath = "qtmail"; QString enclosures = "enclosures"; QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); if ( !dir.exists() ) dir.mkdir( dir.path() ); if (enclosurePath) { dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); if ( !dir.exists() ) dir.mkdir( dir.path() ); return (dir.path() + "/"); } return (dir.path() + "/"); } void EmailClient::readSettings() { - int y,acc_count, accountPos=0; + int y,acc_count; mailconf->setGroup("mailitglobal"); acc_count=mailconf->readNumEntry("Accounts",0); for (int accountPos = 0;accountPos<acc_count ; accountPos++) { mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... account.accountName = mailconf->readEntry("AccName",""); account.name = mailconf->readEntry("UserName",""); account.emailAddress = mailconf->readEntry("Email",""); account.popUserName = mailconf->readEntry("POPUser",""); account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); account.popServer = mailconf->readEntry("POPServer",""); account.smtpServer = mailconf->readEntry("SMTPServer",""); account.id = mailconf->readNumEntry("AccountId",0); account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); account.lastServerMailCount = 0; account.synchronize = FALSE; account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); if (account.synchronize) { mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); } accountList.append(&account); } mailconf->setGroup("mailitglobal"); if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { @@ -862,120 +862,107 @@ void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) } else { outboxView->takeItem(mailItem); } } void EmailClient::setMailSize(int size) { progressBar->reset(); progressBar->setTotalSteps(size); } void EmailClient::setTotalSize(int size) { } void EmailClient::setDownloadedSize(int size) { int total = progressBar->totalSteps(); if (size < total) { progressBar->setProgress(size); } else { progressBar->setProgress(total); } } void EmailClient::deleteItem() { bool inbox=mailboxView->currentTab()==0; + QListView* box; EmailListItem* eli; + int pos; + + inbox ? box=inboxView : box=outboxView; - inbox ? eli=(EmailListItem*)inboxView->selectedItem():eli=(EmailListItem*)outboxView->selectedItem(); + eli=(EmailListItem*)box->selectedItem(); if (eli) - deleteMail(eli,(bool&)inbox); + { + box->setSelected(eli->itemBelow(),true); //select the previous item + + deleteMail(eli,(bool&)inbox); //remove mail entry + } } void EmailClient::inboxItemPressed() { // timerID=startTimer(500); } void EmailClient::inboxItemReleased() { // killTimer(timerID); } void EmailClient::timerEvent(QTimerEvent *e) { /*killTimer(timerID); QPopupMenu *action = new QPopupMenu(this); int reply=0; action->insertItem(tr( "Reply To" ),this,SLOT(reply())); action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); action->insertItem( tr( "Forward" ), this,SLOT(forward())); action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); action->exec(QCursor::pos()); if (action) delete action; */ } Email* EmailClient::getCurrentMail() { EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); if (eli!=NULL) return eli->getMail(); else return NULL; } -/* -void EmailClient::reply() -{ - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit reply(*mail); - } -} - -void EmailClient::replyAll() -{ - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit replyAll(*mail); - } -} - -void EmailClient::forward() +void EmailClient::download(Email* mail) { - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit reply(*mail); - } + MailAccount* acc=0; + + tempMailDownloadList.clear(); + tempMailDownloadList.sizeInsert(mail->serverId, mail->size); + if (accountList.count()>0) + qDebug("Accounts present"); + + acc=accountList.at(mail->fromAccountId-1); + if (acc) + { + emailHandler->setAccount(*acc); + emailHandler->getMailByList(&tempMailDownloadList); + } + else + QMessageBox::warning(qApp->activeWindow(), + tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); } - -void EmailClient::remove() -{ - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit remove(*mail); - } -}*/ diff --git a/noncore/net/mailit/emailclient.h b/noncore/net/mailit/emailclient.h index 0890dcf..549683b 100644 --- a/noncore/net/mailit/emailclient.h +++ b/noncore/net/mailit/emailclient.h @@ -41,64 +41,65 @@ #include <qdir.h> #include <stdlib.h> #include <opie/otabwidget.h> #include <qtimer.h> #include "emailhandler.h" #include "emaillistitem.h" #include "textparser.h" #include "editaccount.h" #include "maillist.h" #include "addresslist.h" #include <qpe/config.h> class AccountList : public QList<MailAccount> { public: Item newItem(Item d); private: MailAccount* dupl(MailAccount *in); MailAccount *ac; }; //class EmailClient : public EmailClientBase class EmailClient : public QMainWindow { Q_OBJECT public: EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); ~EmailClient(); AddressList* getAdrListRef(); + void download(Email*); protected: void timerEvent(QTimerEvent*); signals: void composeRequested(); void viewEmail(QListView *, Email *); void mailUpdated(Email *); void newCaption(const QString &); void replyRequested(Email&, bool&); void forwardRequested(Email&); void removeItem(EmailListItem*, bool&); /*void reply(Email&); void replyAll(Email&); void remove(Email&); void forward(Email&);*/ public slots: void compose(); void cancel(); void enqueMail(const Email &mail); void setMailAccount(); void sendQuedMail(); void mailSent(); void deleteItem(); void getNewMail(); void getAllNewMail(); void smtpError(int code); void popError(int code); void inboxItemSelected(); void outboxItemSelected(); void inboxItemPressed(); @@ -110,62 +111,64 @@ public slots: void editAccount(int); void updateAccounts(); void deleteAccount(int); void deleteMail(EmailListItem *mailItem, bool &inbox); void setTotalSize(int); void setMailSize(int); void setDownloadedSize(int); void moveMailFront(Email *mailPtr); /* void reply(); void replyAll(); void forward(); void remove();*/ private: void init(); void readMail(); QString getPath(bool enclosurePath); void readSettings(); void saveSettings(); Email* getCurrentMail(); int timerID; Config *mailconf; int newAccountId, idCount, mailIdCount; int accountIdCount; AccountList accountList; AddressList *addressList; EditAccount *editAccountView; EmailListItem *item; EmailHandler *emailHandler; QList<Email> quedMessages; MailList mailDownloadList; + MailList tempMailDownloadList; + bool sending, receiving, previewingMail, allAccounts; QString lineShift; MailAccount account, *currentAccount; QToolBar *bar; QProgressBar *progressBar; QStatusBar *statusBar; QLabel *status1Label, *status2Label; QToolButton *getMailButton; QAction *sendMailButton; QAction *composeButton; QAction *cancelButton; QAction *deleteButton; //QToolButton *setAccountButton; QMenuBar *mb; QPopupMenu *selectAccountMenu; QPopupMenu *editAccountMenu; QPopupMenu *deleteAccountMenu; QPopupMenu *setAccountMenu; OTabWidget* mailboxView; QListView* inboxView; QListView* outboxView; QGridLayout* grid_2; QGridLayout* grid_3; }; #endif // EMAILCLIENT_H diff --git a/noncore/net/mailit/emailhandler.cpp b/noncore/net/mailit/emailhandler.cpp index b180051..fbbada7 100644 --- a/noncore/net/mailit/emailhandler.cpp +++ b/noncore/net/mailit/emailhandler.cpp @@ -98,126 +98,126 @@ void EmailHandler::getMail() { popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); if (mailAccount.synchronize) { popClient->setSynchronize(mailAccount.lastServerMailCount); } else { popClient->removeSynchronize(); } headers = FALSE; //popClient->headersOnly(headers, 0); popClient->newConnection(mailAccount.popServer, 110); } void EmailHandler::getMailHeaders() { popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); headers = TRUE; popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all popClient->newConnection(mailAccount.popServer, 110); } void EmailHandler::getMailByList(MailList *mailList) { if (mailList->count() == 0) { //should not occur though emit mailTransfered(0); return; } headers = FALSE; popClient->headersOnly(FALSE, 0); - popClient->newConnection(mailAccount.popServer, 110); + + popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); popClient->setSelectedMails(mailList); -} + popClient->newConnection(mailAccount.popServer, 110); + } -void EmailHandler::messageArrived(const QString &message, int id, uint size, bool incomplete) +void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) { Email mail; mail.rawMail = message; mail.serverId = id; mail.size = size; - mail.downloaded = incomplete; + mail.downloaded = complete; emit mailArrived(mail, FALSE); } bool EmailHandler::parse(QString in, QString lineShift, Email *mail) { QString temp, boundary; int pos; QString delimiter, header, body, mimeHeader, mimeBody; QString content, contentType, contentAttribute, id, encoding; QString fileName, storedName; int enclosureId = 0; mail->rawMail = in; mail->received = TRUE; mail->files.setAutoDelete(TRUE); temp = lineShift + "." + lineShift; if (in.right(temp.length()) != temp) { mail->rawMail += temp; } delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" pos = in.find(delimiter, 0, FALSE); header = in.left(pos); body = in.right(in.length() - pos - delimiter.length()); if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) body.truncate(body.length()-2); TextParser p(header, lineShift); if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { pos++; if (p.separatorAt(pos) == ' ') { mail->from = p.getString(&pos, '<', false); mail->from = mail->from.stripWhiteSpace(); if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { mail->from = mail->from.left(mail->from.length() - 1); mail->from = mail->from.right(mail->from.length() - 1); } pos++; - mail->fromMail = p.getString(&pos, '>', false); } else { - if ((p.separatorAt(pos) == '<') - || (p.separatorAt(pos) == ' ')) //No name.. nasty - pos++; + if (p.separatorAt(pos) == '<') //No name.. nasty pos++; + //pos++; mail->fromMail = p.getString(&pos, 'z', TRUE); if (mail->fromMail.at(mail->fromMail.length()-1) == '>') mail->fromMail.truncate(mail->fromMail.length() - 1); mail->from=mail->fromMail; } } pos=0; //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: while((pos = p.find("TO",':', pos+1, TRUE))!=-1) { QString rec; if (p.separatorAt(pos-1)!='-') { pos++; mail->recipients.append(p.getString(&pos, '\r', TRUE)); } /*else { if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty pos++; pos++; mail->fromMail = p.getString(&pos, 'z', TRUE); if (mail->fromMail.at(mail->fromMail.length()-1) == '>') mail->fromMail.truncate(mail->fromMail.length() - 1); mail->from=mail->fromMail; } mail->recipients.append (p.getString(&pos, 'z', TRUE) ); }*/ } // diff --git a/noncore/net/mailit/emailhandler.h b/noncore/net/mailit/emailhandler.h index e47fd9a..b645868 100644 --- a/noncore/net/mailit/emailhandler.h +++ b/noncore/net/mailit/emailhandler.h @@ -82,64 +82,65 @@ struct Email { files.append(e); } }; struct MailAccount { QString accountName; QString name; QString emailAddress; QString popUserName; QString popPasswd; QString popServer; QString smtpServer; bool synchronize; int syncLimit; int lastServerMailCount; int id; }; const int ErrUnknownResponse = 1001; const int ErrLoginFailed = 1002; const int ErrCancel = 1003; class EmailHandler : public QObject { Q_OBJECT public: EmailHandler(); void setAccount(MailAccount account); + MailAccount* getAccount(){return &mailAccount;} void sendMail(QList<Email> *mailList); void getMail(); void getMailHeaders(); void getMailByList(MailList *mailList); bool parse(QString in, QString lineShift, Email *mail); bool getEnclosure(Enclosure *ePtr); int parse64base(char *src, char *dest); int encodeMime(Email *mail); int encodeFile(QString fileName, QString *toBody); void encode64base(char *src, QString *dest, int len); void cancel(); signals: void mailSent(); void smtpError(int); void popError(int); void mailArrived(const Email &, bool); void updatePopStatus(const QString &); void updateSmtpStatus(const QString &); void mailTransfered(int); void mailboxSize(int); void currentMailSize(int); void downloadedSize(int); public slots: void messageArrived(const QString &, int id, uint size, bool complete); private: MailAccount mailAccount; SmtpClient *smtpClient; PopClient *popClient; bool headers; diff --git a/noncore/net/mailit/mailitwindow.cpp b/noncore/net/mailit/mailitwindow.cpp index 7181adf..ffee67e 100644 --- a/noncore/net/mailit/mailitwindow.cpp +++ b/noncore/net/mailit/mailitwindow.cpp @@ -1,143 +1,165 @@ /********************************************************************** ** Copyright (C) 2001 Trolltech AS. All rights reserved. ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qwhatsthis.h> +#include <qmessagebox.h> #include "mailitwindow.h" MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) : QMainWindow(parent, name, WStyle_ContextHelp) { currentCaption = "Mailit"; setCaption(tr(currentCaption)); views = new QWidgetStack(this); setCentralWidget(views); QWhatsThis::add(views,tr("Central view area")); emailClient = new EmailClient(views, "client"); writeMail = new WriteMail(views, "writing"); readMail = new ReadMail(views, "reading"); views->raiseWidget(emailClient); connect(emailClient, SIGNAL(composeRequested()), this, SLOT(compose()) ); connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, SLOT(viewMail(QListView *, Email *)) ); connect(emailClient, SIGNAL(mailUpdated(Email *)), this, SLOT(updateMailView(Email *)) ); connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, SLOT(showEmailClient()) ); connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, SLOT(enqueMail(const Email &)) ); connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, SLOT(composeReply(Email &, bool&)) ); connect(readMail, SIGNAL(forwardRequested(Email &)), this, SLOT(composeForward(Email &)) ); connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, SLOT(deleteMail(EmailListItem *, bool &)) ); connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, SLOT(moveMailFront(Email *)) ); connect(emailClient, SIGNAL(newCaption(const QString &)), this, SLOT(updateCaption(const QString &)) ); - viewingMail = FALSE; - + viewingMail = FALSE; } MailItWindow::~MailItWindow() { } void MailItWindow::closeEvent(QCloseEvent *e) { if (views->visibleWidget() == emailClient) { e->accept(); } else { showEmailClient(); } } void MailItWindow::compose() { viewingMail = FALSE; emailClient->hide(); readMail->hide(); views->raiseWidget(writeMail); writeMail->setAddressList(emailClient->getAdrListRef()); + writeMail->newMail(); setCaption( tr( "Write mail" ) ); } void MailItWindow::composeReply(Email &mail, bool& replyAll) { compose(); writeMail->reply(mail,replyAll) ; } void MailItWindow::composeForward(Email &mail) { compose(); writeMail->forward(mail) ; } void MailItWindow::showEmailClient() { viewingMail = FALSE; writeMail->hide(); readMail->hide(); views->raiseWidget(emailClient); setCaption( tr(currentCaption) ); } void MailItWindow::viewMail(QListView *view, Email *mail) { viewingMail = TRUE; emailClient->hide(); + + int result=0; + + if ((mail->received)&&(!mail->downloaded)) + { + QMessageBox mb( tr("Mail not downloaded"), + tr("The mail you have clicked \n" + "has not been downloaded yet.\n " + "Would you like to do it now ?"), + QMessageBox::Information, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No | QMessageBox::Escape,0 ); + + result=mb.exec(); + + if (result==QMessageBox::Yes) + { + emailClient->download(mail); + } + } + readMail->update(view, mail); views->raiseWidget(readMail); setCaption( tr( "Examine mail" ) ); } void MailItWindow::updateMailView(Email *mail) { if (viewingMail) { readMail->mailUpdated(mail); } } void MailItWindow::updateCaption(const QString &newCaption) { currentCaption = newCaption; setCaption(tr(currentCaption)); } void MailItWindow::setDocument(const QString &_address) { // strip leading 'mailto:' QString address = _address; if (address.startsWith("mailto:")) address = address.mid(6); compose(); writeMail->setRecipient(address); } diff --git a/noncore/net/mailit/popclient.cpp b/noncore/net/mailit/popclient.cpp index 67306be..6105d09 100644 --- a/noncore/net/mailit/popclient.cpp +++ b/noncore/net/mailit/popclient.cpp @@ -31,65 +31,65 @@ PopClient::PopClient() { socket = new QSocket(this, "popClient"); connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); stream = new QTextStream(socket); receiving = FALSE; synchronize = FALSE; lastSync = 0; headerLimit = 0; preview = FALSE; } PopClient::~PopClient() { delete socket; delete stream; } void PopClient::newConnection(QString target, int port) { if (receiving) { qWarning("socket in use, connection refused"); return; } status = Init; socket->connectToHost(target, port); receiving = TRUE; - selected = FALSE; + //selected = FALSE; emit updateStatus("DNS lookup"); } void PopClient::setAccount(QString popUser, QString popPasswd) { popUserName = popUser; popPassword = popPasswd; } void PopClient::setSynchronize(int lastCount) { synchronize = TRUE; lastSync = lastCount; } void PopClient::removeSynchronize() { synchronize = FALSE; lastSync = 0; } void PopClient::headersOnly(bool headers, int limit) { preview = headers; headerLimit = limit; } void PopClient::setSelectedMails(MailList *list) { selected = TRUE; mailList = list; @@ -155,213 +155,171 @@ void PopClient::incomingData() } case Pass: { *stream << "PASS " << popPassword << "\r\n"; status = Stat; break; } //ask for number of messages case Stat: { if (response[0] == '+') { *stream << "STAT" << "\r\n"; status = Mcnt; } else errorHandling(ErrLoginFailed); break; } //get count of messages, eg "+OK 4 900.." -> int 4 case Mcnt: { if (response[0] == '+') { temp = response.replace(0, 4, ""); int x = temp.find(" ", 0); temp.truncate((uint) x); newMessages = temp.toInt(); messageCount = 1; status = List; if (synchronize) { //messages deleted from server, reload all if (newMessages < lastSync) lastSync = 0; messageCount = 1; } - if (selected) { + if (selected) { int *ptr = mailList->first(); if (ptr != 0) { newMessages++; //to ensure no early jumpout - messageCount = *(mailList->first()); - } else newMessages = 0; - } + messageCount = *ptr; + } else newMessages = 0; + } + } else errorHandling(ErrUnknownResponse); } //Read message number x, count upwards to messageCount case List: { if (messageCount <= newMessages) { *stream << "LIST " << messageCount << "\r\n"; status = Size; temp2.setNum(newMessages - lastSync); temp.setNum(messageCount - lastSync); if (!selected) { emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); } else { //completing a previously closed transfer - if ( (messageCount - lastSync) <= 0) { + /* if ( (messageCount - lastSync) <= 0) { temp.setNum(messageCount); emit updateStatus(tr("Previous message ") + temp); - } else { + } else {*/ emit updateStatus(tr("Completing message ") + temp); - } + //} } break; } else { emit updateStatus(tr("No new Messages")); status = Quit; } } //get size of message, eg "500 characters in message.." -> int 500 case Size: { if (status != Quit) { //because of idiotic switch if (response[0] == '+') { temp = response.replace(0, 4, ""); int x = temp.find(" ", 0); temp = temp.right(temp.length() - ((uint) x + 1) ); mailSize = temp.toInt(); emit currentMailSize(mailSize); status = Retr; } else { //qWarning(response); errorHandling(ErrUnknownResponse); } } } //Read message number x, count upwards to messageCount case Retr: { if (status != Quit) { - if (mailSize <= headerLimit) + if ((selected)||(mailSize <= headerLimit)) { *stream << "RETR " << messageCount << "\r\n"; } else { //only header *stream << "TOP " << messageCount << " 0\r\n"; } messageCount++; status = Ignore; break; } } case Ignore: { if (status != Quit) { //because of idiotic switch if (response[0] == '+') { message = ""; status = Read; if (!socket->canReadLine()) //sync. problems break; response = socket->readLine(); } else errorHandling(ErrUnknownResponse); } } //add all incoming lines to body. When size is reached, send //message, and go back to read new message case Read: { if (status != Quit) { //because of idiotic switch message += response; while ( socket->canReadLine() ) { response = socket->readLine(); message += response; } emit downloadedSize(message.length()); int x = message.find("\r\n.\r\n",-5); if (x == -1) { break; } else { //message reach entire size - //complete mail downloaded - //if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ - if ( mailSize <= headerLimit) + + if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active { emit newMessage(message, messageCount-1, mailSize, TRUE); } else { //incomplete mail downloaded emit newMessage(message, messageCount-1, mailSize, FALSE); } - if (messageCount > newMessages) //that was the last message + + if ((messageCount > newMessages)||(selected)) //last message ? + { status = Quit; - else { //ask for new message if (selected) { //grab next from queue - int *ptr = mailList->next(); - if (ptr != 0) { - messageCount = *ptr; - *stream << "LIST " << messageCount << "\r\n"; - status = Size; - //completing a previously closed transfer - if ( (messageCount - lastSync) <= 0) { - temp.setNum(messageCount); - emit updateStatus(tr("Previous message ") + temp); - } else { - temp.setNum(messageCount - lastSync); - emit updateStatus(tr("Completing message ") + temp); - } - break; - } else { newMessages--; status = Quit; } - } else { + } + else + { *stream << "LIST " << messageCount << "\r\n"; status = Size; temp2.setNum(newMessages - lastSync); temp.setNum(messageCount - lastSync); emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); break; - } + } } } if (status != Quit) break; - } } case Quit: { *stream << "Quit\r\n"; status = Done; int newM = newMessages - lastSync; if (newM > 0) { temp.setNum(newM); emit updateStatus(temp + tr(" new messages")); } else { emit updateStatus(tr("No new messages")); } socket->close(); receiving = FALSE; emit mailTransfered(newM); break; } } } - -// if( bAPOPAuthentication ) -// { -// if( m_strTimeStamp.IsEmpty() ) -// { -// SetLastError("Apop error!"); -// return false; -// } -// strMD5Source = m_strTimeStamp+pszPassword; -// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); -// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); -// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); -// if(ret == SOCKET_ERROR) -// { -// SetLastError("Socket error!"); -// m_bSocketOK = false; -// m_bConnected = false; -// return false; -// } -// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) -// return false; -// if( 0 == strResult.Find('-' , 0) ) -// { -// SetLastError("Username or Password error!"); -// return false; -// } -// m_bConnected = true; - -// } diff --git a/noncore/net/mailit/writemail.cpp b/noncore/net/mailit/writemail.cpp index 0336c83..dcf0c6e 100644 --- a/noncore/net/mailit/writemail.cpp +++ b/noncore/net/mailit/writemail.cpp @@ -94,90 +94,89 @@ void WriteMail::init() subjetLabel = new QLabel( widget, "subjetLabel" ); subjetLabel->setText( tr( "Subject:" ) ); grid->addWidget( subjetLabel, 1, 0 ); ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); ToolButton13_2->setText( tr( "..." ) ); grid->addWidget( ToolButton13_2, 1, 2 ); subjectInput = new QLineEdit( widget, "subjectInput" ); grid->addWidget( subjectInput, 1, 1 ); QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); toInput = new QLineEdit( widget, "toInput" ); grid->addWidget( toInput, 0, 1 ); QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); ccInput = new QLineEdit( widget, "ccInput" ); ccInput->hide(); grid->addWidget( ccInput, 0, 1 ); QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here")); addressButton = new QToolButton( widget, "addressButton" ); addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); addressButton->setToggleButton(TRUE); grid->addWidget( addressButton, 0, 2 ); connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook")); emailInput = new QMultiLineEdit( widget, "emailInput" ); grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); - QWhatsThis::add(recipientsBox,QWidget::tr("Enter your mail text here")); + QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here")); addressView = new QListView( widget, "addressView"); addressView->addColumn("Name"); addressView->addColumn("EMail"); addressView->setAllColumnsShowFocus(TRUE); addressView->setMultiSelection(TRUE); addressView->hide(); grid->addMultiCellWidget( addressView, 3, 3, 0, 2); - QWhatsThis::add(recipientsBox,QWidget::tr("Chose the recipients from this list")); + QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list")); okButton = new QToolButton(bar, "ok"); okButton->setPixmap( Resource::loadPixmap("enter") ); okButton->hide(); connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); setCentralWidget(widget); } void WriteMail::reject() { emit cancelMail(); } -// need to insert date void WriteMail::accept() { QStringList attachedFiles, attachmentsType; int idCount = 0; if (toInput->text() == "") { QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); return; } if (! getRecipients(false) ) { QMessageBox::warning(this,tr("Incorrect recipient separator"), tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); return; } if ((ccInput->text()!="") && (! getRecipients(true) )) { QMessageBox::warning(this,tr("Incorrect carbon copy separator"), tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); return; } mail.subject = subjectInput->text(); mail.body = emailInput->text(); mail.sent = false; mail.received = false; mail.rawMail = "To: "; @@ -223,159 +222,168 @@ void WriteMail::accept() } mail.rawMail += mail.body; mail.rawMail += "\n"; mail.rawMail += ".\n"; emit sendMailRequested(mail); addAtt->clear(); } void WriteMail::getAddress() { showingAddressList = !showingAddressList; if (showingAddressList) { emailInput->hide(); addressView->show(); okButton->show(); } else { addressView->hide(); okButton->hide(); emailInput->show(); } } void WriteMail::attachFile() { addAtt->showMaximized(); } void WriteMail::reply(Email replyMail, bool replyAll) { int pos; + QString ccRecipients; mail = replyMail; mail.files.clear(); toInput->setText(mail.fromMail); - //replyAll ? ccInput->setText(mail.c) + if (replyAll) + { + for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it) + { + ccRecipients.append(*it); + ccRecipients.append(";"); + } + ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end + ccInput->setText(ccRecipients); + } + addRecipients(replyAll); subjectInput->setText(tr("Re: ") + mail.subject); pos = 0; mail.body.insert(pos, ">"); while (pos != -1) { pos = mail.body.find('\n', pos); if (pos != -1) mail.body.insert(++pos, ">>"); } emailInput->setText(mail.body); } void WriteMail::forward(Email forwMail) { int pos=0; QString fwdBody=tr("======forwarded message from "); fwdBody.append(forwMail.fromMail); fwdBody.append(tr(" starts======\n\n")); mail=forwMail; toInput->setText(""); ccInput->setText(""); subjectInput->setText(tr("FWD: ") + mail.subject); fwdBody+=mail.body; fwdBody+=QString(tr("======end of forwarded message======\n\n")); emailInput->setText(fwdBody); } bool WriteMail::getRecipients(bool ccField) { QString str, temp; int pos = 0; mail.recipients.clear(); ccField ? temp = ccInput->text() : temp=toInput->text() ; while ( (pos = temp.find(';')) != -1) { str = temp.left(pos).stripWhiteSpace(); temp = temp.right(temp.length() - (pos + 1)); if ( str.find('@') == -1) return false; ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); addressList->addContact(str, ""); } temp = temp.stripWhiteSpace(); if ( temp.find('@') == -1) return false; ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); addressList->addContact(temp, ""); return TRUE; } void WriteMail::addRecipients() { - - addRecipients(false); + toInput->isVisible() ? addRecipients(false) : addRecipients(true); } - + void WriteMail::addRecipients(bool ccField) { QString recipients = ""; mail.recipients.clear(); QListViewItem *item = addressView->firstChild(); while (item != NULL) { if ( item->isSelected() ) { if (recipients == "") { - recipients = item->text(0); + recipients = item->text(1); } else { - recipients += "; " + item->text(0); + recipients += "; " + item->text(1); } } item = item->nextSibling(); } ccField ? ccInput->setText(recipients):toInput->setText(recipients); addressView->hide(); okButton->hide(); emailInput->show(); addressButton->setOn(FALSE); showingAddressList = !showingAddressList; } void WriteMail::changeRecipients(int selection) { if (selection==0) { toInput->show(); ccInput->hide(); } else if (selection==1) { toInput->hide(); ccInput->show(); } } void WriteMail::setRecipient(const QString &recipient) { toInput->setText(recipient); } void WriteMail::newMail() { toInput->clear(); subjectInput->clear(); emailInput->clear(); - //to clear selected setAddressList(addressList); } diff --git a/noncore/unsupported/mailit/emailclient.cpp b/noncore/unsupported/mailit/emailclient.cpp index 23059cf..dff1888 100644 --- a/noncore/unsupported/mailit/emailclient.cpp +++ b/noncore/unsupported/mailit/emailclient.cpp @@ -333,65 +333,65 @@ void EmailClient::getNewMail() { emailHandler->getMailHeaders(); } void EmailClient::getAllNewMail() { allAccounts = TRUE; currentAccount = accountList.first(); getNewMail(); } void EmailClient::mailArrived(const Email &mail, bool fromDisk) { Enclosure *ePtr; Email newMail; int thisMailId; emailHandler->parse(mail.rawMail, lineShift, &newMail); mailconf->setGroup(newMail.id); if (fromDisk) { newMail.downloaded = mailconf->readBoolEntry("downloaded"); newMail.size = mailconf->readNumEntry("size"); newMail.serverId = mailconf->readNumEntry("serverid"); newMail.fromAccountId = mailconf->readNumEntry("fromaccountid"); } else { //mail arrived from server newMail.serverId = mail.serverId; newMail.size = mail.size; newMail.downloaded = mail.downloaded; - newMail.fromAccountId = currentAccount->id; + newMail.fromAccountId = emailHandler->getAccount()->id; mailconf->writeEntry("fromaccountid", newMail.fromAccountId); } //add if read or not newMail.read = mailconf->readBoolEntry("mailread"); //check if new mail if ( (thisMailId = mailconf->readNumEntry("internalmailid", -1)) == -1) { thisMailId = mailIdCount; mailIdCount++; //set server count, so that if the user aborts, the new //header is not reloaded if ((currentAccount)&&(currentAccount->synchronize)) currentAccount->lastServerMailCount++; mailconf->writeEntry("internalmailid", thisMailId); mailconf->writeEntry("downloaded", newMail.downloaded); mailconf->writeEntry("size", (int) newMail.size); mailconf->writeEntry("serverid", newMail.serverId); //addressList->addContact(newMail.fromMail, newMail.from); } mailconf->writeEntry("downloaded", newMail.downloaded); QString stringMailId; stringMailId.setNum(thisMailId); //see if any attatchments needs to be stored for ( ePtr=newMail.files.first(); ePtr != 0; ePtr=newMail.files.next() ) { QString stringId; @@ -451,69 +451,69 @@ void EmailClient::mailArrived(const Email &mail, bool fromDisk) mailDownloadList.sizeInsert(newMail.serverId, newMail.size);*/ mailboxView->setCurrentTab(0); } void EmailClient::allMailArrived(int count) { // not previewing means all mailtransfer has been done /*if (!previewingMail) {*/ if ( (allAccounts) && ( (currentAccount = accountList.next()) !=0 ) ) { emit newCaption("Mailit - " + currentAccount->accountName); getNewMail(); return; } else { allAccounts = FALSE; receiving = FALSE; getMailButton->setEnabled(TRUE); cancelButton->setEnabled(FALSE); selectAccountMenu->setEnabled(TRUE); status1Label->setText("Idle"); progressBar->reset(); return; } //} // all headers downloaded from server, start downloading remaining mails previewingMail = FALSE; status1Label->setText(currentAccount->accountName); progressBar->reset(); - //emailHandler->getMailByList(&mailDownloadList); - + mailboxView->setCurrentTab(0); } + void EmailClient::moveMailFront(Email *mailPtr) { if ( (receiving) && (mailPtr->fromAccountId == currentAccount->id) ) { mailDownloadList.moveFront(mailPtr->serverId, mailPtr->size); } } void EmailClient::smtpError(int code) { QString temp; if (code == ErrUnknownResponse) temp = "Unknown response from server"; if (code == QSocket::ErrHostNotFound) temp = "host not found"; if (code == QSocket::ErrConnectionRefused) temp = "connection refused"; if (code == QSocket::ErrSocketRead) temp = "socket packet error"; if (code != ErrCancel) { QMessageBox::warning(qApp->activeWindow(), "Sending error", temp, "OK\n"); } else { status2Label->setText("Aborted by user"); } sending = FALSE; sendMailButton->setEnabled(TRUE); cancelButton->setEnabled(FALSE); quedMessages.clear(); } @@ -635,65 +635,65 @@ void EmailClient::saveMail(QString fileName, QListView *view) mailconf->setGroup(mail->id); mailconf->writeEntry("mailread", mail->read); item = (EmailListItem *) item->nextSibling(); } f.close(); } //paths for mailit, is settings, inbox, enclosures QString EmailClient::getPath(bool enclosurePath) { QString basePath = "qtmail"; QString enclosures = "enclosures"; QDir dir = (QString(getenv("HOME")) + "/Applications/" + basePath); if ( !dir.exists() ) dir.mkdir( dir.path() ); if (enclosurePath) { dir = (QString(getenv("HOME")) + "/Applications/" + basePath + "/" + enclosures); if ( !dir.exists() ) dir.mkdir( dir.path() ); return (dir.path() + "/"); } return (dir.path() + "/"); } void EmailClient::readSettings() { - int y,acc_count, accountPos=0; + int y,acc_count; mailconf->setGroup("mailitglobal"); acc_count=mailconf->readNumEntry("Accounts",0); for (int accountPos = 0;accountPos<acc_count ; accountPos++) { mailconf->setGroup("Account_"+QString::number(accountPos+1)); //Account numbers start at 1 ... account.accountName = mailconf->readEntry("AccName",""); account.name = mailconf->readEntry("UserName",""); account.emailAddress = mailconf->readEntry("Email",""); account.popUserName = mailconf->readEntry("POPUser",""); account.popPasswd = mailconf->readEntryCrypt("POPPassword",""); account.popServer = mailconf->readEntry("POPServer",""); account.smtpServer = mailconf->readEntry("SMTPServer",""); account.id = mailconf->readNumEntry("AccountId",0); account.syncLimit = mailconf->readNumEntry("HeaderLimit",0); account.lastServerMailCount = 0; account.synchronize = FALSE; account.synchronize = (mailconf->readEntry("Synchronize","No")=="Yes"); if (account.synchronize) { mailconf->readNumEntry("LASTSERVERMAILCOUNT",0); } accountList.append(&account); } mailconf->setGroup("mailitglobal"); if ( (y = mailconf->readNumEntry("mailidcount", -1)) != -1) { @@ -862,120 +862,107 @@ void EmailClient::deleteMail(EmailListItem *mailItem, bool &inbox) } else { outboxView->takeItem(mailItem); } } void EmailClient::setMailSize(int size) { progressBar->reset(); progressBar->setTotalSteps(size); } void EmailClient::setTotalSize(int size) { } void EmailClient::setDownloadedSize(int size) { int total = progressBar->totalSteps(); if (size < total) { progressBar->setProgress(size); } else { progressBar->setProgress(total); } } void EmailClient::deleteItem() { bool inbox=mailboxView->currentTab()==0; + QListView* box; EmailListItem* eli; + int pos; + + inbox ? box=inboxView : box=outboxView; - inbox ? eli=(EmailListItem*)inboxView->selectedItem():eli=(EmailListItem*)outboxView->selectedItem(); + eli=(EmailListItem*)box->selectedItem(); if (eli) - deleteMail(eli,(bool&)inbox); + { + box->setSelected(eli->itemBelow(),true); //select the previous item + + deleteMail(eli,(bool&)inbox); //remove mail entry + } } void EmailClient::inboxItemPressed() { // timerID=startTimer(500); } void EmailClient::inboxItemReleased() { // killTimer(timerID); } void EmailClient::timerEvent(QTimerEvent *e) { /*killTimer(timerID); QPopupMenu *action = new QPopupMenu(this); int reply=0; action->insertItem(tr( "Reply To" ),this,SLOT(reply())); action->insertItem( tr( "Reply All" ),this,SLOT(replyAll())); action->insertItem( tr( "Forward" ), this,SLOT(forward())); action->insertItem( tr( "Remove Mail" ), this,SLOT(remove())); action->exec(QCursor::pos()); if (action) delete action; */ } Email* EmailClient::getCurrentMail() { EmailListItem *eli=(EmailListItem* ) (inboxView->selectedItem()); if (eli!=NULL) return eli->getMail(); else return NULL; } -/* -void EmailClient::reply() -{ - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit reply(*mail); - } -} - -void EmailClient::replyAll() -{ - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit replyAll(*mail); - } -} - -void EmailClient::forward() +void EmailClient::download(Email* mail) { - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit reply(*mail); - } + MailAccount* acc=0; + + tempMailDownloadList.clear(); + tempMailDownloadList.sizeInsert(mail->serverId, mail->size); + if (accountList.count()>0) + qDebug("Accounts present"); + + acc=accountList.at(mail->fromAccountId-1); + if (acc) + { + emailHandler->setAccount(*acc); + emailHandler->getMailByList(&tempMailDownloadList); + } + else + QMessageBox::warning(qApp->activeWindow(), + tr("No account associated"), tr("There is no active account \nassociated to this mail\n it can not be downloaded"), "Abort\n"); } - -void EmailClient::remove() -{ - Email* mail=getCurrentMail(); - - if (mail!=NULL) - { - emit remove(*mail); - } -}*/ diff --git a/noncore/unsupported/mailit/emailclient.h b/noncore/unsupported/mailit/emailclient.h index 0890dcf..549683b 100644 --- a/noncore/unsupported/mailit/emailclient.h +++ b/noncore/unsupported/mailit/emailclient.h @@ -41,64 +41,65 @@ #include <qdir.h> #include <stdlib.h> #include <opie/otabwidget.h> #include <qtimer.h> #include "emailhandler.h" #include "emaillistitem.h" #include "textparser.h" #include "editaccount.h" #include "maillist.h" #include "addresslist.h" #include <qpe/config.h> class AccountList : public QList<MailAccount> { public: Item newItem(Item d); private: MailAccount* dupl(MailAccount *in); MailAccount *ac; }; //class EmailClient : public EmailClientBase class EmailClient : public QMainWindow { Q_OBJECT public: EmailClient( QWidget* parent, const char* name, WFlags fl = 0 ); ~EmailClient(); AddressList* getAdrListRef(); + void download(Email*); protected: void timerEvent(QTimerEvent*); signals: void composeRequested(); void viewEmail(QListView *, Email *); void mailUpdated(Email *); void newCaption(const QString &); void replyRequested(Email&, bool&); void forwardRequested(Email&); void removeItem(EmailListItem*, bool&); /*void reply(Email&); void replyAll(Email&); void remove(Email&); void forward(Email&);*/ public slots: void compose(); void cancel(); void enqueMail(const Email &mail); void setMailAccount(); void sendQuedMail(); void mailSent(); void deleteItem(); void getNewMail(); void getAllNewMail(); void smtpError(int code); void popError(int code); void inboxItemSelected(); void outboxItemSelected(); void inboxItemPressed(); @@ -110,62 +111,64 @@ public slots: void editAccount(int); void updateAccounts(); void deleteAccount(int); void deleteMail(EmailListItem *mailItem, bool &inbox); void setTotalSize(int); void setMailSize(int); void setDownloadedSize(int); void moveMailFront(Email *mailPtr); /* void reply(); void replyAll(); void forward(); void remove();*/ private: void init(); void readMail(); QString getPath(bool enclosurePath); void readSettings(); void saveSettings(); Email* getCurrentMail(); int timerID; Config *mailconf; int newAccountId, idCount, mailIdCount; int accountIdCount; AccountList accountList; AddressList *addressList; EditAccount *editAccountView; EmailListItem *item; EmailHandler *emailHandler; QList<Email> quedMessages; MailList mailDownloadList; + MailList tempMailDownloadList; + bool sending, receiving, previewingMail, allAccounts; QString lineShift; MailAccount account, *currentAccount; QToolBar *bar; QProgressBar *progressBar; QStatusBar *statusBar; QLabel *status1Label, *status2Label; QToolButton *getMailButton; QAction *sendMailButton; QAction *composeButton; QAction *cancelButton; QAction *deleteButton; //QToolButton *setAccountButton; QMenuBar *mb; QPopupMenu *selectAccountMenu; QPopupMenu *editAccountMenu; QPopupMenu *deleteAccountMenu; QPopupMenu *setAccountMenu; OTabWidget* mailboxView; QListView* inboxView; QListView* outboxView; QGridLayout* grid_2; QGridLayout* grid_3; }; #endif // EMAILCLIENT_H diff --git a/noncore/unsupported/mailit/emailhandler.cpp b/noncore/unsupported/mailit/emailhandler.cpp index b180051..fbbada7 100644 --- a/noncore/unsupported/mailit/emailhandler.cpp +++ b/noncore/unsupported/mailit/emailhandler.cpp @@ -98,126 +98,126 @@ void EmailHandler::getMail() { popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); if (mailAccount.synchronize) { popClient->setSynchronize(mailAccount.lastServerMailCount); } else { popClient->removeSynchronize(); } headers = FALSE; //popClient->headersOnly(headers, 0); popClient->newConnection(mailAccount.popServer, 110); } void EmailHandler::getMailHeaders() { popClient->setAccount(mailAccount.popUserName, mailAccount.popPasswd); mailAccount.synchronize ? popClient->setSynchronize(mailAccount.lastServerMailCount): popClient->removeSynchronize(); headers = TRUE; popClient->headersOnly(headers, mailAccount.syncLimit); //less than requested syncLimit, download all popClient->newConnection(mailAccount.popServer, 110); } void EmailHandler::getMailByList(MailList *mailList) { if (mailList->count() == 0) { //should not occur though emit mailTransfered(0); return; } headers = FALSE; popClient->headersOnly(FALSE, 0); - popClient->newConnection(mailAccount.popServer, 110); + + popClient->setAccount(mailAccount.popUserName,mailAccount.popPasswd); popClient->setSelectedMails(mailList); -} + popClient->newConnection(mailAccount.popServer, 110); + } -void EmailHandler::messageArrived(const QString &message, int id, uint size, bool incomplete) +void EmailHandler::messageArrived(const QString &message, int id, uint size, bool complete) { Email mail; mail.rawMail = message; mail.serverId = id; mail.size = size; - mail.downloaded = incomplete; + mail.downloaded = complete; emit mailArrived(mail, FALSE); } bool EmailHandler::parse(QString in, QString lineShift, Email *mail) { QString temp, boundary; int pos; QString delimiter, header, body, mimeHeader, mimeBody; QString content, contentType, contentAttribute, id, encoding; QString fileName, storedName; int enclosureId = 0; mail->rawMail = in; mail->received = TRUE; mail->files.setAutoDelete(TRUE); temp = lineShift + "." + lineShift; if (in.right(temp.length()) != temp) { mail->rawMail += temp; } delimiter = lineShift + lineShift; // "\n\n" or "\r\n\r\n" pos = in.find(delimiter, 0, FALSE); header = in.left(pos); body = in.right(in.length() - pos - delimiter.length()); if ((body.at(body.length()-2) == '.') && (body.at(body.length()-3) == '\n')) body.truncate(body.length()-2); TextParser p(header, lineShift); if ((pos = p.find("FROM",':', 0, TRUE)) != -1) { pos++; if (p.separatorAt(pos) == ' ') { mail->from = p.getString(&pos, '<', false); mail->from = mail->from.stripWhiteSpace(); if ( (mail->from.length() > 2) && (mail->from[0] == '"') ) { mail->from = mail->from.left(mail->from.length() - 1); mail->from = mail->from.right(mail->from.length() - 1); } pos++; - mail->fromMail = p.getString(&pos, '>', false); } else { - if ((p.separatorAt(pos) == '<') - || (p.separatorAt(pos) == ' ')) //No name.. nasty - pos++; + if (p.separatorAt(pos) == '<') //No name.. nasty pos++; + //pos++; mail->fromMail = p.getString(&pos, 'z', TRUE); if (mail->fromMail.at(mail->fromMail.length()-1) == '>') mail->fromMail.truncate(mail->fromMail.length() - 1); mail->from=mail->fromMail; } } pos=0; //Search for To: after the FROM: attribute to prevent hitting the Delivered-To: while((pos = p.find("TO",':', pos+1, TRUE))!=-1) { QString rec; if (p.separatorAt(pos-1)!='-') { pos++; mail->recipients.append(p.getString(&pos, '\r', TRUE)); } /*else { if ((p.separatorAt(pos) == '<')|| (p.separatorAt(pos) == ' ')) //No name.. nasty pos++; pos++; mail->fromMail = p.getString(&pos, 'z', TRUE); if (mail->fromMail.at(mail->fromMail.length()-1) == '>') mail->fromMail.truncate(mail->fromMail.length() - 1); mail->from=mail->fromMail; } mail->recipients.append (p.getString(&pos, 'z', TRUE) ); }*/ } // diff --git a/noncore/unsupported/mailit/emailhandler.h b/noncore/unsupported/mailit/emailhandler.h index e47fd9a..b645868 100644 --- a/noncore/unsupported/mailit/emailhandler.h +++ b/noncore/unsupported/mailit/emailhandler.h @@ -82,64 +82,65 @@ struct Email { files.append(e); } }; struct MailAccount { QString accountName; QString name; QString emailAddress; QString popUserName; QString popPasswd; QString popServer; QString smtpServer; bool synchronize; int syncLimit; int lastServerMailCount; int id; }; const int ErrUnknownResponse = 1001; const int ErrLoginFailed = 1002; const int ErrCancel = 1003; class EmailHandler : public QObject { Q_OBJECT public: EmailHandler(); void setAccount(MailAccount account); + MailAccount* getAccount(){return &mailAccount;} void sendMail(QList<Email> *mailList); void getMail(); void getMailHeaders(); void getMailByList(MailList *mailList); bool parse(QString in, QString lineShift, Email *mail); bool getEnclosure(Enclosure *ePtr); int parse64base(char *src, char *dest); int encodeMime(Email *mail); int encodeFile(QString fileName, QString *toBody); void encode64base(char *src, QString *dest, int len); void cancel(); signals: void mailSent(); void smtpError(int); void popError(int); void mailArrived(const Email &, bool); void updatePopStatus(const QString &); void updateSmtpStatus(const QString &); void mailTransfered(int); void mailboxSize(int); void currentMailSize(int); void downloadedSize(int); public slots: void messageArrived(const QString &, int id, uint size, bool complete); private: MailAccount mailAccount; SmtpClient *smtpClient; PopClient *popClient; bool headers; diff --git a/noncore/unsupported/mailit/mailitwindow.cpp b/noncore/unsupported/mailit/mailitwindow.cpp index 7181adf..ffee67e 100644 --- a/noncore/unsupported/mailit/mailitwindow.cpp +++ b/noncore/unsupported/mailit/mailitwindow.cpp @@ -1,143 +1,165 @@ /********************************************************************** ** Copyright (C) 2001 Trolltech AS. All rights reserved. ** ** This file is part of Qt Palmtop Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qwhatsthis.h> +#include <qmessagebox.h> #include "mailitwindow.h" MailItWindow::MailItWindow(QWidget *parent, const char *name, WFlags fl) : QMainWindow(parent, name, WStyle_ContextHelp) { currentCaption = "Mailit"; setCaption(tr(currentCaption)); views = new QWidgetStack(this); setCentralWidget(views); QWhatsThis::add(views,tr("Central view area")); emailClient = new EmailClient(views, "client"); writeMail = new WriteMail(views, "writing"); readMail = new ReadMail(views, "reading"); views->raiseWidget(emailClient); connect(emailClient, SIGNAL(composeRequested()), this, SLOT(compose()) ); connect(emailClient, SIGNAL(viewEmail(QListView *, Email *)), this, SLOT(viewMail(QListView *, Email *)) ); connect(emailClient, SIGNAL(mailUpdated(Email *)), this, SLOT(updateMailView(Email *)) ); connect(writeMail, SIGNAL(cancelMail()), this, SLOT(showEmailClient()) ); connect(writeMail, SIGNAL(sendMailRequested(const Email &)), this, SLOT(showEmailClient()) ); connect(writeMail, SIGNAL(sendMailRequested(const Email &)), emailClient, SLOT(enqueMail(const Email &)) ); connect(readMail, SIGNAL(cancelView()), this, SLOT(showEmailClient()) ); connect(readMail, SIGNAL(replyRequested(Email &, bool&)), this, SLOT(composeReply(Email &, bool&)) ); connect(readMail, SIGNAL(forwardRequested(Email &)), this, SLOT(composeForward(Email &)) ); connect(readMail, SIGNAL(removeItem(EmailListItem *, bool &)), emailClient, SLOT(deleteMail(EmailListItem *, bool &)) ); connect(readMail, SIGNAL(viewingMail(Email *)), emailClient, SLOT(moveMailFront(Email *)) ); connect(emailClient, SIGNAL(newCaption(const QString &)), this, SLOT(updateCaption(const QString &)) ); - viewingMail = FALSE; - + viewingMail = FALSE; } MailItWindow::~MailItWindow() { } void MailItWindow::closeEvent(QCloseEvent *e) { if (views->visibleWidget() == emailClient) { e->accept(); } else { showEmailClient(); } } void MailItWindow::compose() { viewingMail = FALSE; emailClient->hide(); readMail->hide(); views->raiseWidget(writeMail); writeMail->setAddressList(emailClient->getAdrListRef()); + writeMail->newMail(); setCaption( tr( "Write mail" ) ); } void MailItWindow::composeReply(Email &mail, bool& replyAll) { compose(); writeMail->reply(mail,replyAll) ; } void MailItWindow::composeForward(Email &mail) { compose(); writeMail->forward(mail) ; } void MailItWindow::showEmailClient() { viewingMail = FALSE; writeMail->hide(); readMail->hide(); views->raiseWidget(emailClient); setCaption( tr(currentCaption) ); } void MailItWindow::viewMail(QListView *view, Email *mail) { viewingMail = TRUE; emailClient->hide(); + + int result=0; + + if ((mail->received)&&(!mail->downloaded)) + { + QMessageBox mb( tr("Mail not downloaded"), + tr("The mail you have clicked \n" + "has not been downloaded yet.\n " + "Would you like to do it now ?"), + QMessageBox::Information, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No | QMessageBox::Escape,0 ); + + result=mb.exec(); + + if (result==QMessageBox::Yes) + { + emailClient->download(mail); + } + } + readMail->update(view, mail); views->raiseWidget(readMail); setCaption( tr( "Examine mail" ) ); } void MailItWindow::updateMailView(Email *mail) { if (viewingMail) { readMail->mailUpdated(mail); } } void MailItWindow::updateCaption(const QString &newCaption) { currentCaption = newCaption; setCaption(tr(currentCaption)); } void MailItWindow::setDocument(const QString &_address) { // strip leading 'mailto:' QString address = _address; if (address.startsWith("mailto:")) address = address.mid(6); compose(); writeMail->setRecipient(address); } diff --git a/noncore/unsupported/mailit/popclient.cpp b/noncore/unsupported/mailit/popclient.cpp index 67306be..6105d09 100644 --- a/noncore/unsupported/mailit/popclient.cpp +++ b/noncore/unsupported/mailit/popclient.cpp @@ -31,65 +31,65 @@ PopClient::PopClient() { socket = new QSocket(this, "popClient"); connect(socket, SIGNAL(error(int)), this, SLOT(errorHandling(int))); connect(socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); connect(socket, SIGNAL(readyRead()), this, SLOT(incomingData())); stream = new QTextStream(socket); receiving = FALSE; synchronize = FALSE; lastSync = 0; headerLimit = 0; preview = FALSE; } PopClient::~PopClient() { delete socket; delete stream; } void PopClient::newConnection(QString target, int port) { if (receiving) { qWarning("socket in use, connection refused"); return; } status = Init; socket->connectToHost(target, port); receiving = TRUE; - selected = FALSE; + //selected = FALSE; emit updateStatus("DNS lookup"); } void PopClient::setAccount(QString popUser, QString popPasswd) { popUserName = popUser; popPassword = popPasswd; } void PopClient::setSynchronize(int lastCount) { synchronize = TRUE; lastSync = lastCount; } void PopClient::removeSynchronize() { synchronize = FALSE; lastSync = 0; } void PopClient::headersOnly(bool headers, int limit) { preview = headers; headerLimit = limit; } void PopClient::setSelectedMails(MailList *list) { selected = TRUE; mailList = list; @@ -155,213 +155,171 @@ void PopClient::incomingData() } case Pass: { *stream << "PASS " << popPassword << "\r\n"; status = Stat; break; } //ask for number of messages case Stat: { if (response[0] == '+') { *stream << "STAT" << "\r\n"; status = Mcnt; } else errorHandling(ErrLoginFailed); break; } //get count of messages, eg "+OK 4 900.." -> int 4 case Mcnt: { if (response[0] == '+') { temp = response.replace(0, 4, ""); int x = temp.find(" ", 0); temp.truncate((uint) x); newMessages = temp.toInt(); messageCount = 1; status = List; if (synchronize) { //messages deleted from server, reload all if (newMessages < lastSync) lastSync = 0; messageCount = 1; } - if (selected) { + if (selected) { int *ptr = mailList->first(); if (ptr != 0) { newMessages++; //to ensure no early jumpout - messageCount = *(mailList->first()); - } else newMessages = 0; - } + messageCount = *ptr; + } else newMessages = 0; + } + } else errorHandling(ErrUnknownResponse); } //Read message number x, count upwards to messageCount case List: { if (messageCount <= newMessages) { *stream << "LIST " << messageCount << "\r\n"; status = Size; temp2.setNum(newMessages - lastSync); temp.setNum(messageCount - lastSync); if (!selected) { emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); } else { //completing a previously closed transfer - if ( (messageCount - lastSync) <= 0) { + /* if ( (messageCount - lastSync) <= 0) { temp.setNum(messageCount); emit updateStatus(tr("Previous message ") + temp); - } else { + } else {*/ emit updateStatus(tr("Completing message ") + temp); - } + //} } break; } else { emit updateStatus(tr("No new Messages")); status = Quit; } } //get size of message, eg "500 characters in message.." -> int 500 case Size: { if (status != Quit) { //because of idiotic switch if (response[0] == '+') { temp = response.replace(0, 4, ""); int x = temp.find(" ", 0); temp = temp.right(temp.length() - ((uint) x + 1) ); mailSize = temp.toInt(); emit currentMailSize(mailSize); status = Retr; } else { //qWarning(response); errorHandling(ErrUnknownResponse); } } } //Read message number x, count upwards to messageCount case Retr: { if (status != Quit) { - if (mailSize <= headerLimit) + if ((selected)||(mailSize <= headerLimit)) { *stream << "RETR " << messageCount << "\r\n"; } else { //only header *stream << "TOP " << messageCount << " 0\r\n"; } messageCount++; status = Ignore; break; } } case Ignore: { if (status != Quit) { //because of idiotic switch if (response[0] == '+') { message = ""; status = Read; if (!socket->canReadLine()) //sync. problems break; response = socket->readLine(); } else errorHandling(ErrUnknownResponse); } } //add all incoming lines to body. When size is reached, send //message, and go back to read new message case Read: { if (status != Quit) { //because of idiotic switch message += response; while ( socket->canReadLine() ) { response = socket->readLine(); message += response; } emit downloadedSize(message.length()); int x = message.find("\r\n.\r\n",-5); if (x == -1) { break; } else { //message reach entire size - //complete mail downloaded - //if ( (!preview ) || ((preview) && (mailSize <= headerLimit)) ){ - if ( mailSize <= headerLimit) + + if ( (selected)||(mailSize <= headerLimit)) //mail size limit is not used if late download is active { emit newMessage(message, messageCount-1, mailSize, TRUE); } else { //incomplete mail downloaded emit newMessage(message, messageCount-1, mailSize, FALSE); } - if (messageCount > newMessages) //that was the last message + + if ((messageCount > newMessages)||(selected)) //last message ? + { status = Quit; - else { //ask for new message if (selected) { //grab next from queue - int *ptr = mailList->next(); - if (ptr != 0) { - messageCount = *ptr; - *stream << "LIST " << messageCount << "\r\n"; - status = Size; - //completing a previously closed transfer - if ( (messageCount - lastSync) <= 0) { - temp.setNum(messageCount); - emit updateStatus(tr("Previous message ") + temp); - } else { - temp.setNum(messageCount - lastSync); - emit updateStatus(tr("Completing message ") + temp); - } - break; - } else { newMessages--; status = Quit; } - } else { + } + else + { *stream << "LIST " << messageCount << "\r\n"; status = Size; temp2.setNum(newMessages - lastSync); temp.setNum(messageCount - lastSync); emit updateStatus(tr("Retrieving ") + temp + "/" + temp2); break; - } + } } } if (status != Quit) break; - } } case Quit: { *stream << "Quit\r\n"; status = Done; int newM = newMessages - lastSync; if (newM > 0) { temp.setNum(newM); emit updateStatus(temp + tr(" new messages")); } else { emit updateStatus(tr("No new messages")); } socket->close(); receiving = FALSE; emit mailTransfered(newM); break; } } } - -// if( bAPOPAuthentication ) -// { -// if( m_strTimeStamp.IsEmpty() ) -// { -// SetLastError("Apop error!"); -// return false; -// } -// strMD5Source = m_strTimeStamp+pszPassword; -// strMD5Dst = MD5_GetMD5( (BYTE*)(const char*)strMD5Source , strMD5Source.GetLength() ); -// sprintf(msg , "apop %s %s\r\n" , pszUser , strMD5Dst); -// ret = send(m_sPop3Socket , msg , strlen(msg) , NULL); -// if(ret == SOCKET_ERROR) -// { -// SetLastError("Socket error!"); -// m_bSocketOK = false; -// m_bConnected = false; -// return false; -// } -// if( !GetSocketResult(&strResult , COMMAND_END_FLAG) ) -// return false; -// if( 0 == strResult.Find('-' , 0) ) -// { -// SetLastError("Username or Password error!"); -// return false; -// } -// m_bConnected = true; - -// } diff --git a/noncore/unsupported/mailit/writemail.cpp b/noncore/unsupported/mailit/writemail.cpp index 0336c83..dcf0c6e 100644 --- a/noncore/unsupported/mailit/writemail.cpp +++ b/noncore/unsupported/mailit/writemail.cpp @@ -94,90 +94,89 @@ void WriteMail::init() subjetLabel = new QLabel( widget, "subjetLabel" ); subjetLabel->setText( tr( "Subject:" ) ); grid->addWidget( subjetLabel, 1, 0 ); ToolButton13_2 = new QToolButton( widget, "ToolButton13_2" ); ToolButton13_2->setText( tr( "..." ) ); grid->addWidget( ToolButton13_2, 1, 2 ); subjectInput = new QLineEdit( widget, "subjectInput" ); grid->addWidget( subjectInput, 1, 1 ); QWhatsThis::add(subjectInput,QWidget::tr("The mail subject should be entered here")); toInput = new QLineEdit( widget, "toInput" ); grid->addWidget( toInput, 0, 1 ); QWhatsThis::add(recipientsBox,QWidget::tr("Recipients can be entered here")); ccInput = new QLineEdit( widget, "ccInput" ); ccInput->hide(); grid->addWidget( ccInput, 0, 1 ); QWhatsThis::add(ccInput,QWidget::tr("If you would like to send copies of your mail they can be entered here")); addressButton = new QToolButton( widget, "addressButton" ); addressButton->setPixmap( Resource::loadPixmap("AddressBook") ); addressButton->setToggleButton(TRUE); grid->addWidget( addressButton, 0, 2 ); connect(addressButton, SIGNAL(clicked()), this, SLOT(getAddress()) ); QWhatsThis::add(addressButton,QWidget::tr("This button opens the address selector with all mail adresses from your OPIE addressbook")); emailInput = new QMultiLineEdit( widget, "emailInput" ); grid->addMultiCellWidget( emailInput, 2, 2, 0, 2); - QWhatsThis::add(recipientsBox,QWidget::tr("Enter your mail text here")); + QWhatsThis::add(emailInput,QWidget::tr("Enter your mail text here")); addressView = new QListView( widget, "addressView"); addressView->addColumn("Name"); addressView->addColumn("EMail"); addressView->setAllColumnsShowFocus(TRUE); addressView->setMultiSelection(TRUE); addressView->hide(); grid->addMultiCellWidget( addressView, 3, 3, 0, 2); - QWhatsThis::add(recipientsBox,QWidget::tr("Chose the recipients from this list")); + QWhatsThis::add(recipientsBox,QWidget::tr("Choose the recipients from this list")); okButton = new QToolButton(bar, "ok"); okButton->setPixmap( Resource::loadPixmap("enter") ); okButton->hide(); connect(okButton, SIGNAL(clicked()), this, SLOT(addRecipients()) ); QWhatsThis::add(okButton,QWidget::tr("Queue your mail by clicking here")); setCentralWidget(widget); } void WriteMail::reject() { emit cancelMail(); } -// need to insert date void WriteMail::accept() { QStringList attachedFiles, attachmentsType; int idCount = 0; if (toInput->text() == "") { QMessageBox::warning(this,tr("No recipient"), tr("Send mail to whom?"), tr("OK\n")); return; } if (! getRecipients(false) ) { QMessageBox::warning(this,tr("Incorrect recipient separator"), tr("Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); return; } if ((ccInput->text()!="") && (! getRecipients(true) )) { QMessageBox::warning(this,tr("Incorrect carbon copy separator"), tr("CC Recipients must be separated by ;\nand be valid emailaddresses"), tr("OK\n")); return; } mail.subject = subjectInput->text(); mail.body = emailInput->text(); mail.sent = false; mail.received = false; mail.rawMail = "To: "; @@ -223,159 +222,168 @@ void WriteMail::accept() } mail.rawMail += mail.body; mail.rawMail += "\n"; mail.rawMail += ".\n"; emit sendMailRequested(mail); addAtt->clear(); } void WriteMail::getAddress() { showingAddressList = !showingAddressList; if (showingAddressList) { emailInput->hide(); addressView->show(); okButton->show(); } else { addressView->hide(); okButton->hide(); emailInput->show(); } } void WriteMail::attachFile() { addAtt->showMaximized(); } void WriteMail::reply(Email replyMail, bool replyAll) { int pos; + QString ccRecipients; mail = replyMail; mail.files.clear(); toInput->setText(mail.fromMail); - //replyAll ? ccInput->setText(mail.c) + if (replyAll) + { + for (QStringList::Iterator it = mail.carbonCopies.begin();it != mail.carbonCopies.end(); ++it) + { + ccRecipients.append(*it); + ccRecipients.append(";"); + } + ccRecipients.truncate(ccRecipients.length()-1); //no ; at the end + ccInput->setText(ccRecipients); + } + addRecipients(replyAll); subjectInput->setText(tr("Re: ") + mail.subject); pos = 0; mail.body.insert(pos, ">"); while (pos != -1) { pos = mail.body.find('\n', pos); if (pos != -1) mail.body.insert(++pos, ">>"); } emailInput->setText(mail.body); } void WriteMail::forward(Email forwMail) { int pos=0; QString fwdBody=tr("======forwarded message from "); fwdBody.append(forwMail.fromMail); fwdBody.append(tr(" starts======\n\n")); mail=forwMail; toInput->setText(""); ccInput->setText(""); subjectInput->setText(tr("FWD: ") + mail.subject); fwdBody+=mail.body; fwdBody+=QString(tr("======end of forwarded message======\n\n")); emailInput->setText(fwdBody); } bool WriteMail::getRecipients(bool ccField) { QString str, temp; int pos = 0; mail.recipients.clear(); ccField ? temp = ccInput->text() : temp=toInput->text() ; while ( (pos = temp.find(';')) != -1) { str = temp.left(pos).stripWhiteSpace(); temp = temp.right(temp.length() - (pos + 1)); if ( str.find('@') == -1) return false; ccField ? mail.carbonCopies.append(str) : mail.recipients.append(str); addressList->addContact(str, ""); } temp = temp.stripWhiteSpace(); if ( temp.find('@') == -1) return false; ccField ? mail.carbonCopies.append(temp) : mail.recipients.append(temp); addressList->addContact(temp, ""); return TRUE; } void WriteMail::addRecipients() { - - addRecipients(false); + toInput->isVisible() ? addRecipients(false) : addRecipients(true); } - + void WriteMail::addRecipients(bool ccField) { QString recipients = ""; mail.recipients.clear(); QListViewItem *item = addressView->firstChild(); while (item != NULL) { if ( item->isSelected() ) { if (recipients == "") { - recipients = item->text(0); + recipients = item->text(1); } else { - recipients += "; " + item->text(0); + recipients += "; " + item->text(1); } } item = item->nextSibling(); } ccField ? ccInput->setText(recipients):toInput->setText(recipients); addressView->hide(); okButton->hide(); emailInput->show(); addressButton->setOn(FALSE); showingAddressList = !showingAddressList; } void WriteMail::changeRecipients(int selection) { if (selection==0) { toInput->show(); ccInput->hide(); } else if (selection==1) { toInput->hide(); ccInput->show(); } } void WriteMail::setRecipient(const QString &recipient) { toInput->setText(recipient); } void WriteMail::newMail() { toInput->clear(); subjectInput->clear(); emailInput->clear(); - //to clear selected setAddressList(addressList); } |