From eeb69efb4e0639429e5f6fd15e65b1b6fbaa5c35 Mon Sep 17 00:00:00 2001 From: harlekin Date: Thu, 08 Jan 2004 17:42:16 +0000 Subject: added support for pop3 tls --- (limited to 'noncore') diff --git a/noncore/net/mail/editaccounts.cpp b/noncore/net/mail/editaccounts.cpp index de36e0d..439b619 100644 --- a/noncore/net/mail/editaccounts.cpp +++ b/noncore/net/mail/editaccounts.cpp @@ -312,13 +312,23 @@ POP3config::POP3config( POP3account *account, QWidget *parent, const char *name, data = account; fillValues(); - connect( sslBox, SIGNAL( toggled( bool ) ), SLOT( slotSSL( bool ) ) ); + 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::slotSSL( bool enabled ) +void POP3config::slotConnectionToggle( int index ) { - if ( enabled ) { - portLine->setText( POP3_SSL_PORT ); + // 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 ); } @@ -329,7 +339,7 @@ void POP3config::fillValues() accountLine->setText( data->getAccountName() ); serverLine->setText( data->getServer() ); portLine->setText( data->getPort() ); - sslBox->setChecked( data->getSSL() ); + ComboBox1->setCurrentItem( data->ConnectionType() ); userLine->setText( data->getUser() ); passLine->setText( data->getPassword() ); } @@ -339,7 +349,7 @@ void POP3config::accept() data->setAccountName( accountLine->text() ); data->setServer( serverLine->text() ); data->setPort( portLine->text() ); - data->setSSL( sslBox->isChecked() ); + data->setConnectionType( ComboBox1->currentItem() ); data->setUser( userLine->text() ); data->setPassword( passLine->text() ); diff --git a/noncore/net/mail/editaccounts.h b/noncore/net/mail/editaccounts.h index 6022eef..fb4be71 100644 --- a/noncore/net/mail/editaccounts.h +++ b/noncore/net/mail/editaccounts.h @@ -98,7 +98,7 @@ public slots: void fillValues(); protected slots: - void slotSSL( bool enabled ); + void slotConnectionToggle( int index ); void accept(); private: diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 67bde38..f5eca4a 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -11,8 +11,7 @@ #define HARD_MSG_SIZE_LIMIT 5242880 POP3wrapper::POP3wrapper( POP3account *a ) - : Genericwrapper() -{ +: Genericwrapper() { account = a; m_pop3 = NULL; m_folder = NULL; @@ -20,8 +19,7 @@ POP3wrapper::POP3wrapper( POP3account *a ) last_msg_id = 0; } -POP3wrapper::~POP3wrapper() -{ +POP3wrapper::~POP3wrapper() { logout(); QFile msg_cache(msgTempName); if (msg_cache.exists()) { @@ -29,13 +27,11 @@ POP3wrapper::~POP3wrapper() } } -void POP3wrapper::pop3_progress( size_t current, size_t maximum ) -{ +void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { qDebug( "POP3: %i of %i", current, maximum ); } -RecBody POP3wrapper::fetchBody( const RecMail &mail ) -{ +RecBody POP3wrapper::fetchBody( const RecMail &mail ) { int err = MAILPOP3_NO_ERROR; char *message = 0; size_t length = 0; @@ -90,27 +86,30 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) body = parseMail(mailmsg); /* clean up */ - if (mailmsg) mailmessage_free(mailmsg); - if (message) free(message); + if (mailmsg) + mailmessage_free(mailmsg); + if (message) + free(message); return body; } -void POP3wrapper::listMessages(const QString &, QList &target ) -{ +void POP3wrapper::listMessages(const QString &, QList &target ) { login(); - if (!m_pop3) return; + if (!m_pop3) + return; uint32_t res_messages,res_recent,res_unseen; mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); parseList(target,m_folder->fld_session,"INBOX"); Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); } -void POP3wrapper::login() -{ - if (account->getOffline()) return; +void POP3wrapper::login() { + if (account->getOffline()) + return; /* we'll hold the line */ - if ( m_pop3 != NULL ) return; + if ( m_pop3 != NULL ) + return; const char *server, *user, *pass; uint16_t port; @@ -119,30 +118,45 @@ void POP3wrapper::login() server = account->getServer().latin1(); port = account->getPort().toUInt(); - if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { - LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); - login.show(); - if ( QDialog::Accepted == login.exec() ) { - // ok - user = login.getUser().latin1(); - pass = login.getPassword().latin1(); - } else { - // cancel - qDebug( "POP3: Login canceled" ); - return; - } - } else { - user = account->getUser().latin1(); - pass = account->getPassword().latin1(); - } - - bool ssl = account->getSSL(); + if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { + LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); + login.show(); + if ( QDialog::Accepted == login.exec() ) { + // ok + user = login.getUser().latin1(); + pass = login.getPassword().latin1(); + } else { + // cancel + qDebug( "POP3: Login canceled" ); + return; + } + } else { + user = account->getUser().latin1(); + pass = account->getPassword().latin1(); + } + + // bool ssl = account->getSSL(); m_pop3=mailstorage_new(NULL); - int conntype = (ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); - - pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,conntype,POP3_AUTH_TYPE_PLAIN, - (char*)user,(char*)pass,0,0,0); + + int conntypeset = account->ConnectionType(); + int conntype = 0; + if ( conntypeset == 3 ) { + conntype = CONNECTION_TYPE_COMMAND; + } else if ( conntypeset == 2 ) { + conntype = CONNECTION_TYPE_TLS; + } else if ( conntypeset == 1 ) { + conntype = CONNECTION_TYPE_STARTTLS; + } else if ( conntypeset == 0 ) { + conntype = CONNECTION_TYPE_TRY_STARTTLS; + } + + //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); + + pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, + (char*)user,(char*)pass,0,0,0); + + m_folder = mailfolder_new(m_pop3, NULL, NULL); @@ -163,10 +177,10 @@ void POP3wrapper::login() } } -void POP3wrapper::logout() -{ +void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; - if ( m_pop3 == NULL ) return; + if ( m_pop3 == NULL ) + return; mailfolder_free(m_folder); m_folder = 0; mailstorage_free(m_pop3); @@ -174,8 +188,7 @@ void POP3wrapper::logout() } -QList* POP3wrapper::listFolders() -{ +QList* POP3wrapper::listFolders() { QList * folders = new QList(); folders->setAutoDelete( false ); Folder*inb=new Folder("INBOX","/"); @@ -183,24 +196,22 @@ QList* POP3wrapper::listFolders() return folders; } -void POP3wrapper::deleteMail(const RecMail&mail) -{ +void POP3wrapper::deleteMail(const RecMail&mail) { login(); - if (!m_pop3) return; + if (!m_pop3) + return; int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("error deleting mail")); } } -void POP3wrapper::answeredMail(const RecMail&) -{ -} +void POP3wrapper::answeredMail(const RecMail&) {} -int POP3wrapper::deleteAllMail(const Folder*) -{ +int POP3wrapper::deleteAllMail(const Folder*) { login(); - if (!m_pop3) return 0; + if (!m_pop3) + return 0; int res = 1; uint32_t result = 0; @@ -220,38 +231,36 @@ int POP3wrapper::deleteAllMail(const Folder*) return res; } -void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) -{ +void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { login(); target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; - if (!m_pop3) return; + if (!m_pop3) + return; int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, - &target_stat.message_recent,&target_stat.message_unseen); + &target_stat.message_recent,&target_stat.message_unseen); } -encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) -{ +encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { char*target=0; size_t length=0; encodedString*res = 0; mailmessage * mailmsg = 0; int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&target,&length); - if (mailmsg) mailmessage_free(mailmsg); + if (mailmsg) + mailmessage_free(mailmsg); if (target) { res = new encodedString(target,length); } return res; } -const QString&POP3wrapper::getType()const -{ +const QString&POP3wrapper::getType()const { return account->getType(); } -const QString&POP3wrapper::getName()const -{ +const QString&POP3wrapper::getName()const { return account->getAccountName(); } diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp index 02a80a3..83e51e3 100644 --- a/noncore/net/mail/libmailwrapper/settings.cpp +++ b/noncore/net/mail/libmailwrapper/settings.cpp @@ -108,6 +108,7 @@ Account::Account() accountName = "changeMe"; type = "changeMe"; ssl = false; + connectionType = 1; } void Account::remove() @@ -122,6 +123,7 @@ IMAPaccount::IMAPaccount() file = IMAPaccount::getUniqueFileName(); accountName = "New IMAP Account"; ssl = false; + connectionType = 1; type = "IMAP"; port = IMAP_PORT; } @@ -132,6 +134,7 @@ IMAPaccount::IMAPaccount( QString filename ) file = filename; accountName = "New IMAP Account"; ssl = false; + connectionType = 1; type = "IMAP"; port = IMAP_PORT; } @@ -203,6 +206,7 @@ POP3account::POP3account() file = POP3account::getUniqueFileName(); accountName = "New POP3 Account"; ssl = false; + connectionType = 1; type = "POP3"; port = POP3_PORT; } @@ -213,6 +217,7 @@ POP3account::POP3account( QString filename ) file = filename; accountName = "New POP3 Account"; ssl = false; + connectionType = 1; type = "POP3"; port = POP3_PORT; } @@ -240,6 +245,7 @@ void POP3account::read() server = conf->readEntry( "Server" ); port = conf->readEntry( "Port" ); ssl = conf->readBoolEntry( "SSL" ); + connectionType = conf->readNumEntry( "ConnectionType" ); user = conf->readEntry( "User" ); password = conf->readEntryCrypt( "Password" ); offline = conf->readBoolEntry("Offline",false); @@ -257,6 +263,7 @@ void POP3account::save() 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->writeEntry( "Offline",offline); diff --git a/noncore/net/mail/libmailwrapper/settings.h b/noncore/net/mail/libmailwrapper/settings.h index 2104997..8d7df92 100644 --- a/noncore/net/mail/libmailwrapper/settings.h +++ b/noncore/net/mail/libmailwrapper/settings.h @@ -31,6 +31,10 @@ public: void setSSL( bool b ) { ssl = b; } bool getSSL() { return ssl; } + void setConnectionType( int x ) { connectionType = x; } + int ConnectionType() { return connectionType; } + + void setOffline(bool b) {offline = b;} bool getOffline()const{return offline;} @@ -41,6 +45,7 @@ public: protected: QString accountName, type, server, port, user, password; bool ssl; + int connectionType; bool offline; }; diff --git a/noncore/net/mail/pop3configui.ui b/noncore/net/mail/pop3configui.ui index 8fdb4ba..95cbdc2 100644 --- a/noncore/net/mail/pop3configui.ui +++ b/noncore/net/mail/pop3configui.ui @@ -11,7 +11,7 @@ 0 0 - 236 + 232 320 @@ -25,174 +25,380 @@ layoutSpacing - + + QLayoutWidget - margin - 4 + name + Layout12 - spacing - 3 + geometry + + 3 + 3 + 226 + 32 + - - QLineEdit + - name - userLine + margin + 0 - - - QLabel - name - passLabel - - - text - Password - - - - QLineEdit - - name - passLine - - - echoMode - Password - - - - QLineEdit - - name - portLine - - - - QLineEdit - - name - serverLine - - - - QLabel - - name - serverLabel - - - text - Server - - - - QCheckBox - - name - sslBox - - - text - Use SSL - - - - QLabel - - name - portLabel - - - text - Port - - - - QLabel - - name - userLabel - - - text - User - - - - - name - spacer - - - orientation - Vertical - - - sizeType - Expanding - - - sizeHint - - 20 - 20 - - - - - Line - - name - line2 + spacing + 6 + + QLabel + + name + accountLabel + + + text + Account + + + + QLineEdit + + name + accountLine + + + toolTip + Name of the Account + + + + + + Line + + name + line1 + + + geometry + + 3 + 38 + 226 + 16 + + + + orientation + Horizontal + + + + QLayoutWidget + + name + Layout11 + + + geometry + + 3 + 44 + 226 + 70 + + + - orientation - Horizontal + margin + 0 - - - QLabel - name - accountLabel + spacing + 6 + + QLayoutWidget + + name + Layout9 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + serverLabel + + + text + Server + + + + QLabel + + name + portLabel + + + text + Port + + + + + + QLayoutWidget + + name + Layout10 + + + + margin + 0 + + + spacing + 6 + + + QLineEdit + + name + serverLine + + + + QLineEdit + + name + portLine + + + + + + + + QLayoutWidget + + name + Layout13 + + + geometry + + 3 + 117 + 226 + 64 + + + - text - Account + margin + 0 - - - QLineEdit - name - accountLine + spacing + 6 - - toolTip - Name of the Account - - - - Line + + QLabel + + name + TextLabel1 + + + text + Use secure sockets: + + + + QComboBox + + name + ComboBox1 + + + + + + QLayoutWidget + + name + Layout6 + + + geometry + + 3 + 223 + 226 + 70 + + + - name - line1 + margin + 0 - orientation - Horizontal + spacing + 6 - - + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + userLabel + + + text + User + + + + QLabel + + name + passLabel + + + text + Password + + + + + + QLayoutWidget + + name + Layout5 + + + + margin + 0 + + + spacing + 6 + + + QLineEdit + + name + userLine + + + + QLineEdit + + name + passLine + + + echoMode + Password + + + + + + + + + name + spacer + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QLineEdit + + name + CommandEdit + + + geometry + + 0 + 180 + 226 + 30 + + + + text + ssh $SERVER exec imapd + + + + Line + + name + line2 + + + geometry + + 3 + 204 + 226 + 16 + + + + orientation + Horizontal + + accountLine serverLine portLine - sslBox userLine passLine -- cgit v0.9.0.2