Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 127 |
1 files changed, 72 insertions, 55 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index b0dd1b8..a6688ed 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp @@ -32,72 +32,73 @@ IMAPwrapper::~IMAPwrapper() /* 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 ) { //qDebug("imap progress %d of %d ",current,maximum ); //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum)); //qApp->processEvents() static 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 = 0; + mCurrent = 1; return; } QString mess; //qDebug("progress "); if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax); else mess = mProgrMess +tr(" 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; 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(tr("Server has no TLS support!")); try_tls = false; @@ -204,125 +205,141 @@ void IMAPwrapper::login() } /* login */ if (ok) { err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); if ( err != MAILIMAP_NO_ERROR ) { Global::statusMessage(tr("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 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); - if ( err != MAILIMAP_NO_ERROR ) { - return; - } - int last = m_imap->imap_selection_info->sel_exists; + 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; - if (last == 0) { - Global::statusMessage(tr("Mailbox has no mails")); - return; - } else { - } - - Global::statusMessage(tr("Fetching header list")); - qApp->processEvents(); - /* the range has to start at 1!!! not with 0!!!! */ - set = mailimap_set_new_interval( 1, last ); - fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); - mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); - mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); - mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); - mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); - - err = mailimap_fetch( m_imap, set, fetchType, &result ); - mailimap_set_free( set ); - mailimap_fetch_type_free( fetchType ); + login(); + if (!m_imap) { + return; + } + /* select mailbox READONLY for operations */ + err = selectMbox(mailbox); + if ( err != MAILIMAP_NO_ERROR ) { + return; + } - QString date,subject,from; + int last = m_imap->imap_selection_info->sel_exists; - if ( err == MAILIMAP_NO_ERROR ) { - mailimap_msg_att * msg_att; - int i = 0; - for (current = clist_begin(result); current != 0; current=clist_next(current)) { - ++i; - msg_att = (mailimap_msg_att*)current->data; - RecMail*m = parse_list_result(msg_att); - if (m) { - if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { - m->setNumber(i); - m->setMbox(mailbox); - m->setWrapper(this); - target.append(m); + if (last == 0) { + Global::statusMessage(tr("Mailbox has no mails")); + return; + } else { + } + progress( tr("Fetch ")); + mMax = last; + //qDebug("last %d ", last); + Global::statusMessage(tr("Fetching header list")); + qApp->processEvents(); + /* the range has to start at 1!!! not with 0!!!! */ + //LR the access to web.de imap server is no working with value 1 + qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); + set = mailimap_set_new_interval( tryAgain, last ); + fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); + mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); + mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); + mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); + mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); + + err = mailimap_fetch( m_imap, set, fetchType, &result ); + mailimap_set_free( set ); + mailimap_fetch_type_free( fetchType ); + + QString date,subject,from; + + if ( err == MAILIMAP_NO_ERROR ) { + tryAgain = -1; + mailimap_msg_att * msg_att; + int i = 0; + for (current = clist_begin(result); current != 0; current=clist_next(current)) { + ++i; + //qDebug("iii %d ",i); + msg_att = (mailimap_msg_att*)current->data; + RecMail*m = parse_list_result(msg_att); + if (m) { + if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { + m->setNumber(i); + m->setMbox(mailbox); + m->setWrapper(this); + target.append(m); + } } } + Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); + } else { + --tryAgain; + --tryAgain; + if ( tryAgain < 0 ) + Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); + else + qDebug("try again... "); } - Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); - } else { - Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); + + if (result) mailimap_fetch_list_free(result); } - if (result) mailimap_fetch_list_free(result); } QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() { const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current = 0; clistcell*cur_flag = 0; mailimap_mbx_list_flags*bflags = 0; QValueList<FolderP>* folders = new QValueList<FolderP>(); login(); if (!m_imap) { return folders; } /* * First we have to check for INBOX 'cause it sometimes it's not inside the path. * We must not forget to filter them out in next loop! * it seems like ugly code. and yes - it is ugly code. but the best way. */ Global::statusMessage(tr("Fetching folder list")); qApp->processEvents(); QString temp; mask = "INBOX" ; mailimap_mailbox_list *list; err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); QString del; bool selectable = true; bool no_inferiors = false; if ( err == MAILIMAP_NO_ERROR ) { @@ -923,65 +940,65 @@ void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which default: if (enc->enc_value) { char*t=enc->enc_value; encoding=QString(enc->enc_value); enc->enc_value=0L; free(t); } } if (which->bd_description) { target_part->setDescription(QString(which->bd_description)); } target_part->setEncoding(encoding); target_part->setSize(which->bd_size); } void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) { //#if 0 mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err; login(); //#endif if (!m_imap) { return; } int iii = 0; int count = target.count(); // qDebug("imap remove count %d ", count); mMax = count; - //progress( tr("Delete")); + progress( tr("Delete")); QProgressBar wid ( count ); wid.setCaption( tr("Deleting ...")); wid.show(); while (iii < count ) { Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); wid.setProgress( iii ); wid.raise(); qApp->processEvents(); RecMailP mail = (*target.at( iii )); //#if 0 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); store_flags = mailimap_store_att_flags_new_set_flags(flist); set = mailimap_set_new_single(mail->getNumber()); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); if (err != MAILIMAP_NO_ERROR) { // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; return; } // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; /* should we realy do that at this moment? */ // err = mailimap_expunge(m_imap); |