-rw-r--r-- | kmicromail/editaccounts.cpp | 17 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/settings.cpp | 85 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/settings.h | 3 |
3 files changed, 80 insertions, 25 deletions
diff --git a/kmicromail/editaccounts.cpp b/kmicromail/editaccounts.cpp index e7d2750..d43d23b 100644 --- a/kmicromail/editaccounts.cpp +++ b/kmicromail/editaccounts.cpp @@ -316,177 +316,192 @@ void SelectMailType::slotSelection( const QString &sel ) } /** * IMAPconfig */ IMAPconfig::IMAPconfig( IMAPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : IMAPconfigUI( parent, name, modal, flags ) { data = account; fillValues(); connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); ComboBox1->insertItem( "Only if available", 0 ); ComboBox1->insertItem( "Always, Negotiated", 1 ); ComboBox1->insertItem( "Connect on secure port", 2 ); ComboBox1->insertItem( "Run command instead", 3 ); CommandEdit->hide(); ComboBox1->setCurrentItem( data->ConnectionType() ); } void IMAPconfig::slotConnectionToggle( int index ) { if ( index == 2 ) { portLine->setText( IMAP_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( IMAP_PORT ); CommandEdit->show(); } else { portLine->setText( IMAP_PORT ); } } void IMAPconfig::fillValues() { accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); ComboBox1->setCurrentItem( data->ConnectionType() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); prefixLine->setText(data->getPrefix()); + localFolder->setText( data->getLocalFolder() ); + int max = data->getMaxMailSize() ; + if ( max ) { + CheckBoxDown->setChecked( true ); + SpinBoxDown->setValue ( max ); + } else { + CheckBoxDown->setChecked( false ); + SpinBoxDown->setValue ( 5 ); + } + CheckBoxLeaveOn->setChecked( data->getLeaveOnServer() ); } void IMAPconfig::accept() { data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setConnectionType( ComboBox1->currentItem() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); - data->setPrefix(prefixLine->text()); + data->setPrefix(prefixLine->text()); + data->setLocalFolder( localFolder->text() ); + data->setMaxMailSize( CheckBoxDown->isChecked()?SpinBoxDown->value():0 ) ; + data->setLeaveOnServer( CheckBoxLeaveOn->isChecked() ); QDialog::accept(); } /** * POP3config */ POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : POP3configUI( parent, name, modal, flags ) { data = account; fillValues(); connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); ComboBox1->insertItem( "Only if available", 0 ); ComboBox1->insertItem( "Always, Negotiated", 1 ); ComboBox1->insertItem( "Connect on secure port", 2 ); ComboBox1->insertItem( "Run command instead", 3 ); CommandEdit->hide(); ComboBox1->setCurrentItem( data->ConnectionType() ); } void POP3config::slotConnectionToggle( int index ) { // 2 is ssl connection if ( index == 2 ) { portLine->setText( POP3_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( POP3_PORT ); CommandEdit->show(); } else { portLine->setText( POP3_PORT ); } } void POP3config::fillValues() { accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); ComboBox1->setCurrentItem( data->ConnectionType() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); localFolder->setText( data->getLocalFolder() ); int max = data->getMaxMailSize() ; if ( max ) { CheckBoxDown->setChecked( true ); SpinBoxDown->setValue ( max ); } else { CheckBoxDown->setChecked( false ); SpinBoxDown->setValue ( 5 ); } + CheckBoxLeaveOn->setChecked( data->getLeaveOnServer() ); } void POP3config::accept() { data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); data->setConnectionType( ComboBox1->currentItem() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); data->setLocalFolder( localFolder->text() ); data->setMaxMailSize( CheckBoxDown->isChecked()?SpinBoxDown->value():0 ) ; + data->setLeaveOnServer( CheckBoxLeaveOn->isChecked() ); QDialog::accept(); } /** * SMTPconfig */ SMTPconfig::SMTPconfig( SMTPaccount *account, QWidget *parent, const char *name, bool modal, WFlags flags ) : SMTPconfigUI( parent, name, modal, flags ) { data = account; connect( loginBox, SIGNAL( toggled(bool) ), userLine, SLOT( setEnabled(bool) ) ); connect( loginBox, SIGNAL( toggled(bool) ), passLine, SLOT( setEnabled(bool) ) ); fillValues(); connect( ComboBox1, SIGNAL( activated(int) ), SLOT( slotConnectionToggle(int) ) ); ComboBox1->insertItem( "Only if available", 0 ); ComboBox1->insertItem( "Always, Negotiated", 1 ); ComboBox1->insertItem( "Connect on secure port", 2 ); ComboBox1->insertItem( "Run command instead", 3 ); CommandEdit->hide(); ComboBox1->setCurrentItem( data->ConnectionType() ); } void SMTPconfig::slotConnectionToggle( int index ) { // 2 is ssl connection if ( index == 2 ) { portLine->setText( SMTP_SSL_PORT ); } else if ( index == 3 ) { portLine->setText( SMTP_PORT ); CommandEdit->show(); } else { portLine->setText( SMTP_PORT ); } } void SMTPconfig::fillValues() { accountLine->setText( data->getAccountName() ); diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp index f996d9c..766eba0 100644 --- a/kmicromail/libmailwrapper/settings.cpp +++ b/kmicromail/libmailwrapper/settings.cpp @@ -1,53 +1,53 @@ #include <stdlib.h> #include <qdir.h> //#include <opie2/odebug.h> -#include <qpe/config.h> +#include <kconfig.h> #include <kstandarddirs.h> #include "settings.h" //#include "defines.h" #define IMAP_PORT "143" #define IMAP_SSL_PORT "993" #define SMTP_PORT "25" #define SMTP_SSL_PORT "465" #define POP3_PORT "110" #define POP3_SSL_PORT "995" #define NNTP_PORT "119" #define NNTP_SSL_PORT "563" Settings::Settings() : QObject() { updateAccounts(); } void Settings::checkDirectory() { qDebug("Settings::checkDirectory() "); return; locateLocal("data", "kopiemail" ); /* if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { system( "mkdir -p $HOME/Applications/opiemail" ); qDebug("$HOME/Applications/opiemail created "); } */ } QList<Account> Settings::getAccounts() { return accounts; } void Settings::addAccount( Account *account ) { accounts.append( account ); } void Settings::delAccount( Account *account ) { accounts.remove( account ); account->remove(); @@ -67,398 +67,435 @@ void Settings::updateAccounts() QStringList pop3 = dir.entryList( "pop3-*" ); for ( it = pop3.begin(); it != pop3.end(); it++ ) { POP3account *account = new POP3account( (*it).replace(0, 5, "") ); accounts.append( account ); } QStringList smtp = dir.entryList( "smtp-*" ); for ( it = smtp.begin(); it != smtp.end(); it++ ) { SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); accounts.append( account ); } QStringList nntp = dir.entryList( "nntp-*" ); for ( it = nntp.begin(); it != nntp.end(); it++ ) { NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); accounts.append( account ); } readAccounts(); } void Settings::saveAccounts() { checkDirectory(); Account *it; for ( it = accounts.first(); it; it = accounts.next() ) { it->save(); } } void Settings::readAccounts() { checkDirectory(); Account *it; for ( it = accounts.first(); it; it = accounts.next() ) { it->read(); } } Account::Account() { accountName = "changeMe"; type = MAILLIB::A_UNDEFINED; ssl = false; connectionType = 1; - offline = false; + offline = false; + maxMailSize = 0; + lastFetch; + leaveOnServer = false; } void Account::remove() { QFile file( getFileName() ); file.remove(); } +void Account::setPasswordList(const QStringList &str) +{ + password = ""; + int i; + for ( i = 0; i < str.count() ; ++i ) { + QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); + password.append( c ); + } + //qDebug("password %s ", password.latin1()); +} +QStringList Account::getPasswordList() +{ + int i; + int len = password.length(); + QStringList str; + + for ( i = 0; i < len ; ++i ) { + int val = password.at(i).unicode()*(len-(i%3))+131; + str.append( QString::number( val ) ); + // qDebug("append %s ", str[i].latin1()); + } + return str; +} + IMAPaccount::IMAPaccount() : Account() { file = IMAPaccount::getUniqueFileName(); accountName = "New IMAP Account"; ssl = false; connectionType = 1; type = MAILLIB::A_IMAP; port = IMAP_PORT; } IMAPaccount::IMAPaccount( QString filename ) : Account() { file = filename; accountName = "New IMAP Account"; ssl = false; connectionType = 1; type = MAILLIB::A_IMAP; port = IMAP_PORT; } QString IMAPaccount::getUniqueFileName() { int num = 0; QString unique; QDir dir( locateLocal("data", "kopiemail" ) ); QStringList imap = dir.entryList( "imap-*" ); do { unique.setNum( num++ ); } while ( imap.contains( "imap-" + unique ) > 0 ); return unique; } void IMAPaccount::read() { - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "IMAP Account" ); accountName = conf->readEntry( "Account","" ); if (accountName.isNull()) accountName = ""; server = conf->readEntry( "Server","" ); if (server.isNull()) server=""; port = conf->readEntry( "Port","" ); if (port.isNull()) port="143"; connectionType = conf->readNumEntry( "ConnectionType" ); ssl = conf->readBoolEntry( "SSL",false ); user = conf->readEntry( "User","" ); if (user.isNull()) user = ""; - password = conf->readEntryCrypt( "Password","" ); + //password = conf->readEntryCrypt( "Password","" ); + setPasswordList( conf->readListEntry( "FolderHistory")); if (password.isNull()) password = ""; prefix = conf->readEntry("MailPrefix",""); if (prefix.isNull()) prefix = ""; offline = conf->readBoolEntry("Offline",false); localFolder = conf->readEntry( "LocalFolder" ); maxMailSize = conf->readNumEntry( "MaxSize",0 ); int lf = conf->readNumEntry( "LastFetch",0 ); QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); + qDebug("reading last fetch: %d ", lf); + if ( lf < 0 ) lf = 0; lastFetch = dt.addSecs( lf ); delete conf; } void IMAPaccount::save() { qDebug("saving %s ",getFileName().latin1() ); Settings::checkDirectory(); - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "IMAP Account" ); conf->writeEntry( "Account", accountName ); conf->writeEntry( "Server", server ); conf->writeEntry( "Port", port ); conf->writeEntry( "SSL", ssl ); conf->writeEntry( "ConnectionType", connectionType ); conf->writeEntry( "User", user ); - conf->writeEntryCrypt( "Password", password ); + //conf->writeEntryCrypt( "Password", password ); + conf->writeEntry( "FolderHistory",getPasswordList() ); conf->writeEntry( "MailPrefix",prefix); conf->writeEntry( "Offline",offline); conf->writeEntry( "LocalFolder", localFolder ); conf->writeEntry( "MaxSize", maxMailSize ); QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); int lf = dt.secsTo ( lastFetch ); conf->writeEntry( "LastFetch", lf ); conf->writeEntry( "LeaveOnServer", leaveOnServer); - conf->write(); + conf->sync(); delete conf; } QString IMAPaccount::getFileName() { return locateLocal("data", "kopiemail" ) +"/imap-" + file; } POP3account::POP3account() : Account() { file = POP3account::getUniqueFileName(); accountName = "New POP3 Account"; ssl = false; connectionType = 1; type = MAILLIB::A_POP3; port = POP3_PORT; } POP3account::POP3account( QString filename ) : Account() { file = filename; accountName = "New POP3 Account"; ssl = false; connectionType = 1; type = MAILLIB::A_POP3; port = POP3_PORT; } QString POP3account::getUniqueFileName() { int num = 0; QString unique; QDir dir( locateLocal("data", "kopiemail" ) ); QStringList imap = dir.entryList( "pop3-*" ); do { unique.setNum( num++ ); } while ( imap.contains( "pop3-" + unique ) > 0 ); return unique; } void POP3account::read() { - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName()); conf->setGroup( "POP3 Account" ); accountName = conf->readEntry( "Account" ); server = conf->readEntry( "Server" ); port = conf->readEntry( "Port" ); ssl = conf->readBoolEntry( "SSL" ); connectionType = conf->readNumEntry( "ConnectionType" ); user = conf->readEntry( "User" ); - password = conf->readEntryCrypt( "Password" ); + //password = conf->readEntryCrypt( "Password" ); + setPasswordList( conf->readListEntry( "FolderHistory")); offline = conf->readBoolEntry("Offline",false); localFolder = conf->readEntry( "LocalFolder" ); maxMailSize = conf->readNumEntry( "MaxSize",0 ); int lf = conf->readNumEntry( "LastFetch",0 ); QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); lastFetch = dt.addSecs( lf ); delete conf; } void POP3account::save() { Settings::checkDirectory(); - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "POP3 Account" ); conf->writeEntry( "Account", accountName ); conf->writeEntry( "Server", server ); conf->writeEntry( "Port", port ); conf->writeEntry( "SSL", ssl ); conf->writeEntry( "ConnectionType", connectionType ); conf->writeEntry( "User", user ); - conf->writeEntryCrypt( "Password", password ); + //conf->writeEntryCrypt( "Password", password ); + conf->writeEntry( "FolderHistory",getPasswordList() ); conf->writeEntry( "Offline",offline); conf->writeEntry( "LocalFolder", localFolder ); conf->writeEntry( "MaxSize", maxMailSize ); QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); int lf = dt.secsTo ( lastFetch ); conf->writeEntry( "LastFetch", lf ); conf->writeEntry( "LeaveOnServer", leaveOnServer); - conf->write(); + conf->sync(); delete conf; } QString POP3account::getFileName() { return locateLocal("data", "kopiemail" ) +"/pop3-" + file; } SMTPaccount::SMTPaccount() : Account() { file = SMTPaccount::getUniqueFileName(); accountName = "New SMTP Account"; ssl = false; connectionType = 1; login = false; useCC = false; useBCC = false; useReply = false; type = MAILLIB::A_SMTP; port = SMTP_PORT; } SMTPaccount::SMTPaccount( QString filename ) : Account() { file = filename; accountName = "New SMTP Account"; ssl = false; connectionType = 1; login = false; type = MAILLIB::A_SMTP; port = SMTP_PORT; } QString SMTPaccount::getUniqueFileName() { int num = 0; QString unique; QDir dir( locateLocal("data", "kopiemail" ) ); QStringList imap = dir.entryList( "smtp-*" ); do { unique.setNum( num++ ); } while ( imap.contains( "smtp-" + unique ) > 0 ); return unique; } void SMTPaccount::read() { - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "SMTP Account" ); accountName = conf->readEntry( "Account" ); server = conf->readEntry( "Server" ); port = conf->readEntry( "Port" ); ssl = conf->readBoolEntry( "SSL" ); connectionType = conf->readNumEntry( "ConnectionType" ); login = conf->readBoolEntry( "Login" ); user = conf->readEntry( "User" ); - password = conf->readEntryCrypt( "Password" ); + //password = conf->readEntryCrypt( "Password" ); + setPasswordList( conf->readListEntry( "FolderHistory")); delete conf; } void SMTPaccount::save() { Settings::checkDirectory(); - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "SMTP Account" ); conf->writeEntry( "Account", accountName ); conf->writeEntry( "Server", server ); conf->writeEntry( "Port", port ); conf->writeEntry( "SSL", ssl ); conf->writeEntry( "ConnectionType", connectionType ); conf->writeEntry( "Login", login ); conf->writeEntry( "User", user ); - conf->writeEntryCrypt( "Password", password ); - conf->write(); + //conf->writeEntryCrypt( "Password", password ); + conf->writeEntry( "FolderHistory",getPasswordList() ); + conf->sync(); delete conf; } QString SMTPaccount::getFileName() { return locateLocal("data", "kopiemail" ) +"/smtp-" + file; } NNTPaccount::NNTPaccount() : Account() { file = NNTPaccount::getUniqueFileName(); accountName = "New NNTP Account"; ssl = false; login = false; type = MAILLIB::A_NNTP; port = NNTP_PORT; } NNTPaccount::NNTPaccount( QString filename ) : Account() { file = filename; accountName = "New NNTP Account"; ssl = false; login = false; type = MAILLIB::A_NNTP; port = NNTP_PORT; } QString NNTPaccount::getUniqueFileName() { int num = 0; QString unique; QDir dir( locateLocal("data", "kopiemail" ) ); QStringList imap = dir.entryList( "nntp-*" ); do { unique.setNum( num++ ); } while ( imap.contains( "nntp-" + unique ) > 0 ); return unique; } void NNTPaccount::read() { - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "NNTP Account" ); accountName = conf->readEntry( "Account" ); server = conf->readEntry( "Server" ); port = conf->readEntry( "Port" ); ssl = conf->readBoolEntry( "SSL" ); login = conf->readBoolEntry( "Login" ); user = conf->readEntry( "User" ); - password = conf->readEntryCrypt( "Password" ); - subscribedGroups = conf->readListEntry( "Subscribed", ',' ); + //password = conf->readEntryCrypt( "Password" ); + setPasswordList( conf->readListEntry( "FolderHistory")); + subscribedGroups = conf->readListEntry( "Subscribed"); delete conf; } void NNTPaccount::save() { Settings::checkDirectory(); - Config *conf = new Config( getFileName(), Config::File ); + KConfig *conf = new KConfig( getFileName() ); conf->setGroup( "NNTP Account" ); conf->writeEntry( "Account", accountName ); conf->writeEntry( "Server", server ); conf->writeEntry( "Port", port ); conf->writeEntry( "SSL", ssl ); conf->writeEntry( "Login", login ); conf->writeEntry( "User", user ); - conf->writeEntryCrypt( "Password", password ); - conf->writeEntry( "Subscribed" , subscribedGroups, ',' ); - conf->write(); + //conf->writeEntryCrypt( "Password", password ); + conf->writeEntry( "FolderHistory",getPasswordList() ); + conf->writeEntry( "Subscribed" , subscribedGroups ); + conf->sync(); delete conf; } QString NNTPaccount::getFileName() { return locateLocal("data", "kopiemail" ) +"/nntp-" + file; } diff --git a/kmicromail/libmailwrapper/settings.h b/kmicromail/libmailwrapper/settings.h index 85b817c..61051dd 100644 --- a/kmicromail/libmailwrapper/settings.h +++ b/kmicromail/libmailwrapper/settings.h @@ -1,87 +1,90 @@ #ifndef SETTINGS_H #define SETTINGS_H #include "maildefines.h" /* OPIE */ /* QT */ #include <qobject.h> #include <qlist.h> #include <qdatetime.h> class Account { public: Account(); virtual ~Account() {} void remove(); void setAccountName( QString name ) { accountName = name; } const QString&getAccountName()const{ return accountName; } MAILLIB::ATYPE getType()const{ return type; } void setServer(const QString&str){ server = str; } const QString&getServer()const{ return server; } void setLocalFolder( QString name ) { localFolder = name; } const QString& getLocalFolder()const{ return localFolder; } void setPort(const QString&str) { port = str; } const QString&getPort()const{ return port; } void setUser(const QString&str){ user = str; } const QString&getUser()const{ return user; } void setPassword(const QString&str) { password = str; } const QString&getPassword()const { return password; } + void setPasswordList(const QStringList &str); + QStringList getPasswordList(); + void setSSL( bool b ) { ssl = b; } bool getSSL() { return ssl; } void setConnectionType( int x ) { connectionType = x; } int ConnectionType() { return connectionType; } void setMaxMailSize( int x ) { maxMailSize = x; } int getMaxMailSize() { return maxMailSize; } void setOffline(bool b) {offline = b;} bool getOffline()const{return offline;} bool getLeaveOnServer(){ return leaveOnServer;} void setLeaveOnServer(bool b){ leaveOnServer = b;} virtual QString getFileName() { return accountName; } virtual void read() { ; } virtual void save() { ; } protected: QString accountName, server, port, user, password; bool ssl; int connectionType; bool offline; MAILLIB::ATYPE type; QString localFolder; int maxMailSize; QDateTime lastFetch; bool leaveOnServer; }; class IMAPaccount : public Account { public: IMAPaccount(); IMAPaccount( QString filename ); static QString getUniqueFileName(); virtual void read(); virtual void save(); virtual QString getFileName(); void setPrefix(const QString&str) {prefix=str;} const QString&getPrefix()const{return prefix;} private: |