Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index b890725..d9496af 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp @@ -1,254 +1,253 @@ // CHANGED 2004-09-31 Lutz Rogowski #include <stdlib.h> #include <libetpan/libetpan.h> #include <qpe/global.h> #include <qapplication.h> #include "imapwrapper.h" #include "mailtypes.h" #include "logindialog.h" #include <qprogressbar.h> #include "genericwrapper.h" #include <kglobal.h> using namespace Opie::Core; int IMAPwrapper::mMax = 0; int IMAPwrapper::mCurrent = 0; IMAPwrapper::IMAPwrapper( IMAPaccount *a ) : AbstractMail() { account = a; m_imap = 0; m_Lastmbox = ""; mCurrent = 0; mMax = 0; } IMAPwrapper::~IMAPwrapper() { logout(); } /* to avoid to often select statements in loops etc. we trust that we are logged in and connection is established!*/ int IMAPwrapper::selectMbox(const QString&mbox) { if (mbox == m_Lastmbox) { return MAILIMAP_NO_ERROR; } int err = mailimap_select( m_imap, (char*)mbox.latin1()); if ( err != MAILIMAP_NO_ERROR ) { m_Lastmbox = ""; return err; } m_Lastmbox = mbox; return err; } void IMAPwrapper::imap_progress( size_t current, size_t maximum ) { qApp->processEvents(); return; //qDebug("imap progress %d of %d ",current,maximum ); //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); //qApp->processEvents() static unsigned int last = 0; if ( last != current ) IMAPwrapper::progress(); last = current; } void IMAPwrapper::progress( QString m ) { - static QString mProgrMess; if ( m != QString::null ) { mProgrMess = m; mCurrent = 1; return; } QString mess; //qDebug("progress "); if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); Global::statusMessage(mess); //qDebug("Progress %s %s", mess.latin1(), m.latin1()); qApp->processEvents(); } bool IMAPwrapper::start_tls(bool force_tls) { int err; bool try_tls = force_tls; mailimap_capability_data * cap_data = 0; err = mailimap_capability(m_imap,&cap_data); if (err != MAILIMAP_NO_ERROR) { Global::statusMessage("error getting capabilities!"); return false; } clistiter * cur; for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { struct mailimap_capability * cap; cap = (struct mailimap_capability *)clist_content(cur); if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { try_tls = true; break; } } } if (cap_data) { mailimap_capability_data_free(cap_data); } if (try_tls) { err = mailimap_starttls(m_imap); if (err != MAILIMAP_NO_ERROR && force_tls) { Global::statusMessage(i18n("Server has no TLS support!")); try_tls = false; } else { mailstream_low * low; mailstream_low * new_low; low = mailstream_get_low(m_imap->imap_stream); if (!low) { try_tls = false; } else { int fd = mailstream_low_get_fd(low); if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { mailstream_low_free(low); mailstream_set_low(m_imap->imap_stream, new_low); } else { try_tls = false; } } } } return try_tls; } void IMAPwrapper::login() { QString server, user, pass; uint16_t port; int err = MAILIMAP_NO_ERROR; if (account->getOffline()) return; /* we are connected this moment */ /* TODO: setup a timer holding the line or if connection closed - delete the value */ if (m_imap) { err = mailimap_noop(m_imap); if (err!=MAILIMAP_NO_ERROR) { logout(); } else { mailstream_flush(m_imap->imap_stream); return; } } server = account->getServer(); 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(); pass = login.getPassword(); } else { // cancel return; } } else { user = account->getUser(); pass = account->getPassword(); } m_imap = mailimap_new( 20, &imap_progress ); /* connect */ bool ssl = false; bool try_tls = false; bool force_tls = false; if ( account->ConnectionType() == 2 ) { ssl = true; } if (account->ConnectionType()==1) { force_tls = true; } if ( ssl ) { qDebug("using ssl "); err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); qDebug("back "); } else { err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); } if ( err != MAILIMAP_NO_ERROR && err != MAILIMAP_NO_ERROR_AUTHENTICATED && err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { QString failure = ""; if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { failure="Connection refused"; } else { failure="Unknown failure"; } Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); mailimap_free( m_imap ); m_imap = 0; return; } if (!ssl) { try_tls = start_tls(force_tls); } bool ok = true; if (force_tls && !try_tls) { Global::statusMessage(i18n("Server has no TLS support!")); ok = false; } /* login */ if (ok) { err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); if ( err != MAILIMAP_NO_ERROR ) { Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); ok = false; } } if (!ok) { err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; } } void IMAPwrapper::logout() { int err = MAILIMAP_NO_ERROR; if (!m_imap) return; err = mailimap_logout( m_imap ); err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; m_Lastmbox = ""; } void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) { int tryAgain = 1; while ( tryAgain >= 0 ) { int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current; mailimap_fetch_type *fetchType = 0; mailimap_set *set = 0; login(); if (!m_imap) { return; } /* select mailbox READONLY for operations */ err = selectMbox(mailbox); |