diff --git a/kmaccount.h b/kmaccount.h index 703d19345..b06fe61aa 100644 --- a/kmaccount.h +++ b/kmaccount.h @@ -34,7 +34,7 @@ public: /** There can be exactly one folder that is fed by messages from an account. */ - KMFolder* folder(void) { return ((KMFolder*)mFolder); } + KMFolder* folder(void) const { return ((KMFolder*)mFolder); } virtual void setFolder(KMFolder*); /** Process new mail for this account if one arrived. Returns TRUE if new diff --git a/kmacctpop.cpp b/kmacctpop.cpp index 5c0e1b53f..3b2f9bcbf 100644 --- a/kmacctpop.cpp +++ b/kmacctpop.cpp @@ -31,7 +31,8 @@ KMAcctPop::KMAcctPop(KMAcctMgr* aOwner, const char* aAccountName): initMetaObject(); mStorePasswd = FALSE; - mLeaveOnServer = TRUE; + mLeaveOnServer = FALSE; + mRetrieveAll = TRUE; mProtocol = 3; mPort = 110; } @@ -59,18 +60,10 @@ void KMAcctPop::init(void) mPasswd = ""; mProtocol = 3; mStorePasswd = FALSE; - mLeaveOnServer = TRUE; + mLeaveOnServer = FALSE; + mRetrieveAll = TRUE; } -void KMAcctPop::setLeaveOnServer(bool b) -{ - mLeaveOnServer = b; -} - -bool KMAcctPop::leaveOnServer() -{ - return mLeaveOnServer; -} //----------------------------------------------------------------------------- bool KMAcctPop::processNewMail(void) @@ -127,60 +120,67 @@ bool KMAcctPop::doProcessNewMail(void) passwd = decryptStr(mPasswd); if(passwd.isEmpty() || mLogin.isEmpty()) - {KMPasswdDialog *d = new KMPasswdDialog(NULL,NULL,this, - "Please set Password and Username!", - mLogin, decryptStr(passwd)); + { + KMPasswdDialog *d = new KMPasswdDialog(NULL,NULL,this, + "Please set Password and Username", + mLogin, decryptStr(passwd)); if(!d->exec()) return FALSE; else - {mPasswd = encryptStr(mPasswd); + { + mPasswd = encryptStr(mPasswd); passwd = decryptStr(mPasswd); passwd = decryptStr(passwd); - } } + } // Now, we got to do something here. If you can resolve to the address // but cannot connect to the server like on some of our uni-machines // we end up with a lock up! Certainly not desirable! - if (client.Open(mHost,mPort) != '+') return popError("OPEN", client); - // It might not necessarly be a network error if User & Pass // reply != +. It's more likely that the username or the passwd is wrong while((replyCode = client.User(mLogin)) != '+') - {if(replyCode == '-') - {KMPasswdDialog *d = new KMPasswdDialog(NULL,NULL,this,"Incorrect Username!", - mLogin, decryptStr(passwd)); + { + if(replyCode == '-') + { + KMPasswdDialog *d = new KMPasswdDialog(NULL,NULL,this, + "Incorrect Username", + mLogin, decryptStr(passwd)); if(!d->exec()) return FALSE; else - {mPasswd = encryptStr(mPasswd); + { + mPasswd = encryptStr(mPasswd); passwd = decryptStr(mPasswd); passwd = decryptStr(passwd); - } } + } else return popError("USER", client); - } + } while((replyCode =client.Pass(decryptStr(passwd))) != '+') - {if(replyCode == '-') - {KMPasswdDialog *d = new KMPasswdDialog(NULL,NULL,this,"Incorrect Password!", - mLogin, decryptStr(passwd)); + { + if(replyCode == '-') + { + KMPasswdDialog *d = new KMPasswdDialog(NULL,NULL,this, + "Incorrect Password", + mLogin, decryptStr(passwd)); if(!d->exec()) return FALSE; else - {mPasswd = encryptStr(mPasswd); + { + mPasswd = encryptStr(mPasswd); passwd = decryptStr(mPasswd); passwd = decryptStr(passwd); - } + } } else return popError("PASS", client); - } - + } if (client.Stat() != '+') return popError("STAT", client); response = client.SingleLineResponse().c_str(); @@ -210,15 +210,18 @@ bool KMAcctPop::doProcessNewMail(void) msg = new KMMessage; msg->fromString(response); - mFolder->addMsg(msg); + if (mRetrieveAll || msg->status()!=KMMsgStatusOld) + mFolder->addMsg(msg); + else delete msg; if(!mLeaveOnServer) - {debug("Deleting mail: %i",id); + { + debug("Deleting mail: %i",id); if(client.Dele(id) != '+') return popError("DELE",client); else cout << client.SingleLineResponse().c_str(); - } + } else debug("Leaving mail on server\n"); @@ -233,39 +236,39 @@ bool KMAcctPop::doProcessNewMail(void) //----------------------------------------------------------------------------- bool KMAcctPop::popError(const QString aStage, DwPopClient& aClient) const { - QString str; + QString msg, caption; kbp->idle(); + + caption = nls->translate("Pop Mail Error"); + // First we assume the worst: A network error - if(aClient.LastFailure() != DwProtocolClient::kFailNoFailure) { - KMsgBox::message(0, "Pop-Mail Network Error:","Account: " + name() + - "\n" + nls->translate("In ")+ - aStage+":\n"+ aClient.LastFailureStr()); - kbp->busy(); - return FALSE;} + if (aClient.LastFailure() != DwProtocolClient::kFailNoFailure) + { + caption = nls->translate("Pop Mail Network Error"); + msg = aClient.LastFailureStr(); + } // Maybe it is an app specific error - if(aClient.LastError() != DwProtocolClient::kErrNoError) { - KMsgBox::message(0, "Pop-Mail Error","Account: " + name() + - "\n" + nls->translate("In ")+aStage+":\n"+ - aClient.LastErrorStr()); - kbp->busy(); - return FALSE;} + else if (aClient.LastError() != DwProtocolClient::kErrNoError) + { + msg = aClient.LastErrorStr(); + } // Not all commands return multiLineResponses. If they do not // they return singleLineResponses and the multiLR command return NULL - str = aClient.MultiLineResponse().c_str(); - if(str.isEmpty()) - str = aClient.SingleLineResponse().c_str(); - if(str.isEmpty()) - str = "Unknown error!"; - // Negative response by the server e.g STAT responses '- ....' - KMsgBox::message(0, "Pop-Mail Error","Account: " + name() + - "\n" + nls->translate("In ")+aStage+":\n"+ str); + else + { + msg = aClient.MultiLineResponse().c_str(); + if (msg.isEmpty()) msg = aClient.SingleLineResponse().c_str(); + if (msg.isEmpty()) msg = nls->translate("Unknown error"); + // Negative response by the server e.g STAT responses '- ....' + } + + KMsgBox::message(0, caption, nls->translate("Account: ") + name() + "\n" + + nls->translate("In ")+aStage+":\n"+ msg); kbp->busy(); aClient.Quit(); return FALSE; - - } @@ -283,7 +286,8 @@ void KMAcctPop::readConfig(KConfig& config) mHost = config.readEntry("host"); mPort = config.readNumEntry("port"); mProtocol = config.readNumEntry("protocol"); - mLeaveOnServer = config.readNumEntry("leave-on-server",TRUE); + mLeaveOnServer = config.readNumEntry("leave-on-server", FALSE); + mRetrieveAll = config.readNumEntry("retrieve-all", TRUE); } @@ -305,6 +309,7 @@ void KMAcctPop::writeConfig(KConfig& config) config.writeEntry("port", mPort); config.writeEntry("protocol", mProtocol); config.writeEntry("leave-on-server",mLeaveOnServer); + config.writeEntry("retrieve-all",mRetrieveAll); } @@ -334,6 +339,20 @@ const QString KMAcctPop::decryptStr(const QString aStr) } +//----------------------------------------------------------------------------- +void KMAcctPop::setLeaveOnServer(bool b) +{ + mLeaveOnServer = b; +} + + +//----------------------------------------------------------------------------- +void KMAcctPop::setRetrieveAll(bool b) +{ + mRetrieveAll = b; +} + + //----------------------------------------------------------------------------- void KMAcctPop::setLogin(const QString& aLogin) { diff --git a/kmacctpop.h b/kmacctpop.h index 34aa28a9b..559618f9c 100644 --- a/kmacctpop.h +++ b/kmacctpop.h @@ -43,9 +43,16 @@ public: short protocol(void) { return mProtocol; } virtual void setProtocol(short); - void setLeaveOnServer(bool); - bool leaveOnServer(); + /** Shall messages be left on the server upon retreival (TRUE) + or deleted (FALSE). */ + bool leaveOnServer(void) const { return mLeaveOnServer; } + virtual void setLeaveOnServer(bool); + /** Retrieve all messages from server (TRUE) or unread messages only. */ + bool retrieveAll(void) const { return mRetrieveAll; } + virtual void setRetrieveAll(bool); + + /** Inherited methods. */ virtual const char* type(void) const; virtual void readConfig(KConfig&); virtual void writeConfig(KConfig&); @@ -75,6 +82,7 @@ protected: short mProtocol; bool mStorePasswd; bool mLeaveOnServer; + bool mRetrieveAll; }; diff --git a/kmmsgpartdlg.cpp b/kmmsgpartdlg.cpp index dd7538c43..4c41665be 100644 --- a/kmmsgpartdlg.cpp +++ b/kmmsgpartdlg.cpp @@ -21,6 +21,7 @@ KMMsgPartDlg::KMMsgPartDlg(const char* aCaption): QGridLayout* grid = new QGridLayout(this, 6, 4, 8, 8); QPushButton *btnOk, *btnCancel; QLabel *label; + int h; mMsgPart = NULL; @@ -32,43 +33,75 @@ KMMsgPartDlg::KMMsgPartDlg(const char* aCaption): mLblIcon->resize(32, 32); grid->addMultiCellWidget(mLblIcon, 0, 1, 0, 0); + //----- mEdtMimetype = new QLineEdit(this); - grid->addWidget(mEdtMimetype, 0, 1); + mEdtMimetype->adjustSize(); + h = mEdtMimetype->sizeHint().height(); + mEdtMimetype->setMinimumSize(100, h); + mEdtMimetype->setMaximumSize(1024, h); + grid->addMultiCellWidget(mEdtMimetype, 0, 0, 1, 3); + //----- mLblSize = new QLabel(this); - grid->addWidget(mLblSize, 1, 1); + mLblSize->adjustSize(); + mLblSize->setMinimumSize(100, h); + grid->addMultiCellWidget(mLblSize, 1, 1, 1, 3); + //----- label = new QLabel(nls->translate("Name:"), this); + label->adjustSize(); + label->setMinimumSize(label->sizeHint().width(), h); grid->addWidget(label, 2, 0); mEdtName = new QLineEdit(this); + mEdtName->setMinimumSize(100, h); + mEdtName->setMaximumSize(1024, h); grid->addMultiCellWidget(mEdtName, 2, 2, 1, 3); + //----- label = new QLabel(nls->translate("Description:"), this); + label->adjustSize(); + label->setMinimumSize(label->sizeHint().width(), h); grid->addWidget(label, 3, 0); mEdtComment = new QLineEdit(this); + mEdtComment->setMinimumSize(100, h); + mEdtComment->setMaximumSize(1024, h); grid->addMultiCellWidget(mEdtComment, 3, 3, 1, 3); label = new QLabel(nls->translate("Encoding:"), this); + label->adjustSize(); + label->setMinimumSize(label->sizeHint().width(), h); grid->addWidget(label, 4, 0); mCbxEncoding = new QComboBox(this); mCbxEncoding->insertItem(nls->translate("none (8bit)")); mCbxEncoding->insertItem(nls->translate("base 64")); mCbxEncoding->insertItem(nls->translate("quoted printable")); + mCbxEncoding->setMinimumSize(100, h); + mCbxEncoding->setMaximumSize(1024, h); grid->addMultiCellWidget(mCbxEncoding, 4, 4, 1, 2); - + //----- btnOk = new QPushButton(nls->translate("Ok"), this); + btnOk->adjustSize(); + btnOk->setMinimumSize(btnOk->sizeHint()); connect(btnOk, SIGNAL(clicked()), SLOT(accept())); grid->addMultiCellWidget(btnOk, 5, 5, 0, 1); btnCancel = new QPushButton(nls->translate("Cancel"), this); + btnCancel->adjustSize(); + btnCancel->setMinimumSize(btnCancel->sizeHint()); connect(btnCancel, SIGNAL(clicked()), SLOT(reject())); grid->addMultiCellWidget(btnCancel, 5, 5, 2, 3); + //----- + grid->setColStretch(0, 0); + grid->setColStretch(1, 10); + grid->setColStretch(3, 10); grid->activate(); + + adjustSize(); } diff --git a/kmreaderwin.cpp b/kmreaderwin.cpp index 32abda8c8..bb87c1bff 100644 --- a/kmreaderwin.cpp +++ b/kmreaderwin.cpp @@ -478,10 +478,10 @@ void KMReaderWin::slotUrlOpen(const char* aUrl, int aButton) int id; id = msgPartFromUrl(aUrl); - if (id >= 0) + if (id > 0) { // clicked onto an attachment - mAtmCurrent = id; + mAtmCurrent = id-1; slotAtmSave(); } else emit urlClicked(aUrl, aButton); @@ -496,10 +496,10 @@ void KMReaderWin::slotUrlPopup(const char* aUrl, const QPoint& aPos) QPopupMenu *menu; id = msgPartFromUrl(aUrl); - if (id < 0) emit popupMenu(aPos); + if (id <= 0) emit popupMenu(aPos); else { - mAtmCurrent = id; + mAtmCurrent = id-1; menu = new QPopupMenu(); menu->insertItem(nls->translate("Open..."), this, SLOT(slotAtmOpen())); menu->insertItem(nls->translate("Save as..."), this, SLOT(slotAtmSave())); diff --git a/kmsettings.cpp b/kmsettings.cpp index 15a6f798e..35dbc279e 100644 --- a/kmsettings.cpp +++ b/kmsettings.cpp @@ -39,7 +39,7 @@ KMSettings::KMSettings(QWidget *parent, const char *name) : initMetaObject(); setCaption(nls->translate("Settings")); - resize(500,600); + resize(600,700); setOKButton(nls->translate("Ok")); setCancelButton(nls->translate("Cancel")); @@ -55,6 +55,7 @@ KMSettings::KMSettings(QWidget *parent, const char *name) : //----------------------------------------------------------------------------- KMSettings::~KMSettings() { + accountList->clear(); } @@ -243,7 +244,7 @@ void KMSettings::createTabNetwork(QWidget* parent) accountList->clear(); for (act=acctMgr->first(); act; act=acctMgr->next()) - tabNetworkAddAcct(accountList, act); + accountList->insertItem(tabNetworkAcctStr(act), -1); addTab(tab, nls->translate("Network")); box->addStretch(100); @@ -316,8 +317,7 @@ void KMSettings::createTabComposer(QWidget *parent) //----------------------------------------------------------------------------- -void KMSettings::tabNetworkAddAcct(KTabListBox* actList, KMAccount* act, - int idx) +const QString KMSettings::tabNetworkAcctStr(const KMAccount* act) const { QString str; @@ -328,7 +328,7 @@ void KMSettings::tabNetworkAddAcct(KTabListBox* actList, KMAccount* act, str += "\n"; if (act->folder()) str += act->folder()->name(); - actList->insertItem(str, idx); + return str; } @@ -369,7 +369,7 @@ void KMSettings::addAccount() acctSettings = new KMAccountSettings(this, NULL, acct); if (acctSettings->exec()) - tabNetworkAddAcct(accountList, acct); + accountList->insertItem(tabNetworkAcctStr(acct), -1); else acctMgr->remove(acct); @@ -409,9 +409,8 @@ void KMSettings::modifyAccount(int index,int) d->exec(); delete d; - accountList->removeItem(index); - tabNetworkAddAcct(accountList, acct, index); - accountList->setCurrentItem(-1); + accountList->changeItem(tabNetworkAcctStr(acct), index); + accountList->setCurrentItem(index); } //----------------------------------------------------------------------------- @@ -439,7 +438,9 @@ void KMSettings::removeAccount() removeButton->setEnabled(FALSE); } if (idx >= (int)accountList->count()) idx--; - accountList->setCurrentItem(idx); + if (idx >= 0) accountList->setCurrentItem(idx); + + accountList->update(); } //----------------------------------------------------------------------------- @@ -527,7 +528,7 @@ KMAccountSettings::KMAccountSettings(QWidget *parent, const char *name, acctType = mAcct->type(); setCaption("Configure Account"); - grid = new QGridLayout(this, 11, 3, 8, 4); + grid = new QGridLayout(this, 12, 3, 8, 4); grid->setColStretch(1, 5); lbl = new QLabel(nls->translate("Type:"), this); @@ -559,8 +560,8 @@ KMAccountSettings::KMAccountSettings(QWidget *parent, const char *name, mEdtPasswd = createLabeledEntry(this, grid, nls->translate("Password:"), ((KMAcctPop*)mAcct)->passwd(), 3, 0); - // markus: added this for security reasons. mEdtPasswd->setEchoMode(QLineEdit::Password); + mEdtHost = createLabeledEntry(this, grid, nls->translate("Host:"), ((KMAcctPop*)mAcct)->host(), 4, 0); @@ -569,17 +570,24 @@ KMAccountSettings::KMAccountSettings(QWidget *parent, const char *name, mEdtPort = createLabeledEntry(this, grid, nls->translate("Port:"), tmpStr, 5, 0); + chk = new QCheckBox(nls->translate("Delete mail from server"), this); + chk->setChecked(!((KMAcctPop*)mAcct)->leaveOnServer()); + grid->addMultiCellWidget(chk, 6, 6, 1, 2); + } else fatal("KMAccountSettings: unsupported account type"); + // label with "Local Account" or "Pop Account" created previously lbl->adjustSize(); lbl->setMinimumSize(lbl->sizeHint()); lbl = new QLabel(nls->translate("Store new mail in account:"), this); - grid->addMultiCellWidget(lbl, 6, 6, 0, 2); + lbl->adjustSize(); + lbl->setMinimumSize(lbl->sizeHint()); + grid->addMultiCellWidget(lbl, 7, 7, 0, 2); - // combo box of all folders with current account folder selected + // combobox of all folders with current account folder selected acctFolder = mAcct->folder(); mFolders = new QComboBox(this); mFolders->insertItem(nls->translate("")); @@ -590,16 +598,10 @@ KMAccountSettings::KMAccountSettings(QWidget *parent, const char *name, if (folder == acctFolder) mFolders->setCurrentItem(i); i++; } - grid->addWidget(mFolders, 7, 1); - - chk = new QCheckBox(nls->translate("Delete Mail from Server"), - this); - if(!((KMAcctPop*)mAcct)->leaveOnServer()) - chk->setChecked(TRUE); - else - chk->setChecked(FALSE); // just to make sure - grid->addMultiCellWidget(chk, 8, 8, 1, 2); - + mFolders->adjustSize(); + mFolders->setMinimumSize(100, mEdtName->minimumSize().height()); + mFolders->setMaximumSize(500, mEdtName->minimumSize().height()); + grid->addWidget(mFolders, 8, 1); // buttons at bottom btnBox = new QWidget(this); @@ -667,10 +669,7 @@ void KMAccountSettings::accept() ((KMAcctPop*)mAcct)->setPort(atoi(mEdtPort->text())); ((KMAcctPop*)mAcct)->setLogin(mEdtLogin->text()); ((KMAcctPop*)mAcct)->setPasswd(mEdtPasswd->text(), true); - if(chk->isChecked() == TRUE) - ((KMAcctPop*)mAcct)->setLeaveOnServer(FALSE); - else - ((KMAcctPop*)mAcct)->setLeaveOnServer(TRUE); + ((KMAcctPop*)mAcct)->setLeaveOnServer(!chk->isChecked()); } acctMgr->writeConfig(TRUE); diff --git a/kmsettings.h b/kmsettings.h index d57cdfeca..a3e76036a 100644 --- a/kmsettings.h +++ b/kmsettings.h @@ -35,9 +35,8 @@ protected: const char* label, int row, int col); - // Adds given account to given listbox after given index or at the end - // if none is specified. - void tabNetworkAddAcct(KTabListBox*, KMAccount*, int idx=-1); + // Returns a string suitable for account listbox + const QString tabNetworkAcctStr(const KMAccount* acct) const; protected slots: void doApply();