author | zautrix <zautrix> | 2004-09-01 10:23:29 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-01 10:23:29 (UTC) |
commit | 6cefbdc9c8f3f3001373f10715361e2740c45395 (patch) (side-by-side diff) | |
tree | cb2c36f57620e698913c27ca4ebe59e4a7c9d46e /kmicromail/libmailwrapper | |
parent | b9257cb225cd29bab5d96fcdaf557926603ee587 (diff) | |
download | kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.zip kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.gz kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.bz2 |
Mail fixes and libetpan updated
-rw-r--r-- | kmicromail/libmailwrapper/abstractmail.cpp | 56 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 46 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/pop3wrapper.cpp | 43 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/pop3wrapper.h | 2 |
4 files changed, 133 insertions, 14 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp index 3998abd..3b0ca1f 100644 --- a/kmicromail/libmailwrapper/abstractmail.cpp +++ b/kmicromail/libmailwrapper/abstractmail.cpp @@ -1,73 +1,75 @@ // CHANGED 2004-09-31 Lutz Rogowski #include "abstractmail.h" #include "imapwrapper.h" #include "pop3wrapper.h" #include "nntpwrapper.h" #include "mhwrapper.h" #include "mailtypes.h" +#include <qprogressbar.h> +#include <qapplication.h> #include <kdecore/kstandarddirs.h> #include <qfile.h> #include <qtextstream.h> #include <stdlib.h> #include <libetpan/mailmime_content.h> #include <libetpan/mailmime.h> using namespace Opie::Core; AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) { return new IMAPwrapper(a); } AbstractMail* AbstractMail::getWrapper(POP3account *a) { return new POP3wrapper(a); } AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) { return new NNTPwrapper(a); } AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) { return new MHwrapper(a,name); } AbstractMail* AbstractMail::getWrapper(Account*a) { if (!a) return 0; switch (a->getType()) { case MAILLIB::A_IMAP: return new IMAPwrapper((IMAPaccount*)a); break; case MAILLIB::A_POP3: return new POP3wrapper((POP3account*)a); break; case MAILLIB::A_NNTP: return new NNTPwrapper((NNTPaccount*)a); break; default: return 0; } } encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) { // odebug << "Decode string start" << oendl; char*result_text; size_t index = 0; /* reset for recursive use! */ size_t target_length = 0; result_text = 0; int mimetype = MAILMIME_MECHANISM_7BIT; if (enc.lower()=="quoted-printable") { mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; } else if (enc.lower()=="base64") { mimetype = MAILMIME_MECHANISM_BASE64; } else if (enc.lower()=="8bit") { mimetype = MAILMIME_MECHANISM_8BIT; } else if (enc.lower()=="binary") { mimetype = MAILMIME_MECHANISM_BINARY; @@ -79,109 +81,157 @@ encodedString* AbstractMail::decode_String(const encodedString*text,const QStrin encodedString* result = new encodedString(); if (err == MAILIMF_NO_ERROR) { result->setContent(result_text,target_length); } //odebug << "Decode string finished" << oendl; return result; } QString AbstractMail::convert_String(const char*text) { //size_t index = 0; char*res = 0; int err = MAILIMF_NO_ERROR; QString result(text); /* due a bug in libetpan it isn't usable this moment */ /* int err = mailmime_encoded_phrase_parse("iso-8859-1", text, strlen(text),&index, "iso-8859-1",&res);*/ //odebug << "Input: " << text << "" << oendl; if (err == MAILIMF_NO_ERROR && res && strlen(res)) { // result = QString(res); // odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; } if (res) free(res); return result; } /* cp & paste from launcher */ QString AbstractMail::gen_attachment_id() { QFile file( "/proc/sys/kernel/random/uuid" ); if (!file.open(IO_ReadOnly ) ) return QString::null; QTextStream stream(&file); return "{" + stream.read().stripWhiteSpace() + "}"; } int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) { return 0; } QString AbstractMail::defaultLocalfolder() { // QString f = getenv( "HOME" ); QString f = locateLocal( "data", "kmicromail/localmail"); // f += "/Applications/opiemail/localmail"; return f; } QString AbstractMail::draftFolder() { return QString("Drafts"); } /* temporary - will be removed when implemented in all classes */ void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) { } void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) { - qDebug("AbstractMail::deleteMailList:: Please reimplement! "); - + //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); + // this is currently re-implemented in pop3wrapper and imapwrapper + int iii = 0; + int count = target.count(); + QProgressBar bar( count,0 ); + bar.setCaption (("Removing mails - close to abort!") ); + int w = 300; + if ( QApplication::desktop()->width() < 320 ) + w = 220; + int h = bar.sizeHint().height() ; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + bar.show(); + int modulo = (count/10)+1; + int incCounter = 0; + while (iii < count ) { + if ( ! bar.isVisible() ) + return ; + if ( incCounter % modulo == 0 ) + bar.setProgress( incCounter ); + ++incCounter; + qApp->processEvents(); + RecMailP mail = (*target.at( iii )); + deleteMail(mail); + ++iii; + } } void AbstractMail::mvcpAllMails(const FolderP&fromFolder, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) { QValueList<RecMailP> t; listMessages(fromFolder->getName(),t, maxSizeInKb); mvcpMailList( t,targetFolder,targetWrapper,moveit); } void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) { - encodedString*st = 0; int iii = 0; int count = t.count(); + if ( count == 0 ) + return; + + QProgressBar bar( count,0 ); + bar.setCaption (("Copying mails - close to abort!") ); + int w = 300; + if ( QApplication::desktop()->width() < 320 ) + w = 220; + int h = bar.sizeHint().height() ; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + bar.show(); + int modulo = (count/10)+1; + int incCounter = 0; while (iii < count ) { + if ( ! bar.isVisible() ) + return ; + if ( incCounter % modulo == 0 ) + bar.setProgress( incCounter ); + ++incCounter; + bar.raise(); + qApp->processEvents(); + //qDebug("copy "); RecMailP r = (*t.at( iii )); st = fetchRawBody(r); if (st) { targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); delete st; } ++iii; } + bar.hide(); if (moveit) { deleteMailList( t ); //deleteAllMail(fromFolder); } } void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) { encodedString*st = 0; st = fetchRawBody(mail); if (st) { targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); delete st; } if (moveit) { deleteMail(mail); } } diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index bb8bbfc..11d3343 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp @@ -1,72 +1,73 @@ // 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> using namespace Opie::Core; IMAPwrapper::IMAPwrapper( IMAPaccount *a ) : AbstractMail() { account = a; m_imap = 0; m_Lastmbox = ""; } 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(); qDebug("imap progress %d of %d ",current,maximum ); } 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); @@ -810,203 +811,232 @@ void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_ba } else { type = ""; } break; } if (which->bd_media_basic->med_subtype) { sub = which->bd_media_basic->med_subtype; } else { sub = ""; } // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; target_part->setType(type.lower()); target_part->setSubtype(sub.lower()); fillBodyFields(target_part,which->bd_fields); } void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) { if (!which) return; if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { clistcell*cur; mailimap_single_body_fld_param*param=0; for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { param = (mailimap_single_body_fld_param*)cur->data; if (param) { target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); } } } mailimap_body_fld_enc*enc = which->bd_encoding; QString encoding(""); switch (enc->enc_type) { case MAILIMAP_BODY_FLD_ENC_7BIT: encoding = "7bit"; break; case MAILIMAP_BODY_FLD_ENC_8BIT: encoding = "8bit"; break; case MAILIMAP_BODY_FLD_ENC_BINARY: encoding="binary"; break; case MAILIMAP_BODY_FLD_ENC_BASE64: encoding="base64"; break; case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: encoding="quoted-printable"; break; case MAILIMAP_BODY_FLD_ENC_OTHER: 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); + // qDebug("imap remove count %d ", count); + + QProgressBar bar( count,0 ); + bar.setCaption (("Removing mails - close to abort!") ); + int w = 300; + if ( QApplication::desktop()->width() < 320 ) + w = 220; + int h = bar.sizeHint().height() ; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + bar.show(); + int modulo = (count/10)+1; + int incCounter = 0; + while (iii < count ) { - qDebug("IMAP remove %d ", iii); + if ( ! bar.isVisible() ) + return ; + if ( incCounter % modulo == 0 ) + bar.setProgress( incCounter ); + ++incCounter; + 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); + //if (err != MAILIMAP_NO_ERROR) { + // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); + // } + //#endif + //deleteMail( mail); + ++iii; + } + //qDebug("Deleting imap mails... "); err = mailimap_expunge(m_imap); if (err != MAILIMAP_NO_ERROR) { - Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); - } - ++iii; + Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); } } void IMAPwrapper::deleteMail(const RecMailP&mail) { mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err; login(); if (!m_imap) { return; } 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); if (err != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); } - qDebug("IMAPwrapper::deleteMail "); + //qDebug("IMAPwrapper::deleteMail 2"); } void IMAPwrapper::answeredMail(const RecMailP&mail) { mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err; login(); if (!m_imap) { return; } err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_answered()); store_flags = mailimap_store_att_flags_new_add_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 marking mail: " << m_imap->imap_response << "" << oendl; return; } } QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) { QString body(""); encodedString*res = fetchRawPart(mail,path,internal_call); encodedString*r = decode_String(res,enc); delete res; if (r) { if (r->Length()>0) { body = r->Content(); } delete r; } return body; } QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) { return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); } encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) { encodedString*res = fetchRawPart(mail,part->Positionlist(),false); encodedString*r = decode_String(res,part->Encoding()); delete res; return r; } encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) { return fetchRawPart(mail,part->Positionlist(),false); } @@ -1128,103 +1158,103 @@ void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) case MAILIMAP_STATUS_ATT_UNSEEN: target_stat.message_unseen = status_info->st_value; break; } } } else { // odebug << "Error retrieving status" << oendl; } if (status) mailimap_mailbox_data_status_free(status); if (att_list) mailimap_status_att_list_free(att_list); } void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) { login(); if (!m_imap) return; if (!msg) return; int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); if (r != MAILIMAP_NO_ERROR) { Global::statusMessage("Error storing mail!"); } } MAILLIB::ATYPE IMAPwrapper::getType()const { return account->getType(); } const QString&IMAPwrapper::getName()const { // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; return account->getAccountName(); } encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) { // dummy QValueList<int> path; return fetchRawPart(mail,path,false); } void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) { if (targetWrapper != this || maxSizeInKb > 0 ) { AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); qDebug("IMAPwrapper::mvcpAllMails::Using generic"); // odebug << "Using generic" << oendl; return; } mailimap_set *set = 0; login(); if (!m_imap) { return; } int err = selectMbox(fromFolder->getName()); if ( err != MAILIMAP_NO_ERROR ) { return; } int last = m_imap->imap_selection_info->sel_exists; set = mailimap_set_new_interval( 1, last ); err = mailimap_copy(m_imap,set,targetFolder.latin1()); mailimap_set_free( set ); if ( err != MAILIMAP_NO_ERROR ) { - QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); + QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); Global::statusMessage(error_msg); // odebug << error_msg << oendl; return; } if (moveit) { deleteAllMail(fromFolder); } } void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) { if (targetWrapper != this) { // odebug << "Using generic" << oendl; AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); return; } mailimap_set *set = 0; login(); if (!m_imap) { return; } int err = selectMbox(mail->getMbox()); if ( err != MAILIMAP_NO_ERROR ) { return; } set = mailimap_set_new_single(mail->getNumber()); err = mailimap_copy(m_imap,set,targetFolder.latin1()); mailimap_set_free( set ); if ( err != MAILIMAP_NO_ERROR ) { QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); Global::statusMessage(error_msg); // odebug << error_msg << oendl; return; } if (moveit) { deleteMail(mail); } } diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp index 7a84b30..0e6612c 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.cpp +++ b/kmicromail/libmailwrapper/pop3wrapper.cpp @@ -1,74 +1,76 @@ // CHANGED 2004-09-31 Lutz Rogowski #include <stdlib.h> #include "pop3wrapper.h" #include "mailtypes.h" #include "logindialog.h" #include <libetpan/libetpan.h> #include <qpe/global.h> #include <qfile.h> +#include <qprogressbar.h> +#include <qapplication.h> /* we don't fetch messages larger than 5 MB */ #define HARD_MSG_SIZE_LIMIT 5242880 using namespace Opie::Core; POP3wrapper::POP3wrapper( POP3account *a ) : Genericwrapper() { account = a; m_pop3 = NULL; msgTempName = a->getFileName()+"_msg_cache"; last_msg_id = 0; } POP3wrapper::~POP3wrapper() { logout(); QFile msg_cache(msgTempName); if (msg_cache.exists()) { msg_cache.remove(); } } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; } RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { int err = MAILPOP3_NO_ERROR; char *message = 0; size_t length = 0; RecBodyP body = new RecBody(); login(); if ( !m_pop3 ) { return body; } mailmessage * mailmsg; if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; return body; } QFile msg_cache(msgTempName); cleanMimeCache(); if (mail->getNumber()!=last_msg_id) { if (msg_cache.exists()) { msg_cache.remove(); } msg_cache.open(IO_ReadWrite|IO_Truncate); last_msg_id = mail->getNumber(); err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&message,&length); msg_cache.writeBlock(message,length); } else { QString msg=""; msg_cache.open(IO_ReadOnly); message = new char[4096]; memset(message,0,4096); while (msg_cache.readBlock(message,4095)>0) { msg+=message; memset(message,0,4096); @@ -132,151 +134,188 @@ void POP3wrapper::login() pass = login.getPassword().latin1(); } else { // cancel ; // odebug << "POP3: Login canceled" << oendl; return; } } else { user = account->getUser().latin1(); pass = account->getPassword().latin1(); } // bool ssl = account->getSSL(); m_pop3=mailstorage_new(NULL); 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); err = mailstorage_connect(m_pop3); if (err != MAIL_NO_ERROR) { ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; Global::statusMessage(tr("Error initializing folder")); mailstorage_free(m_pop3); m_pop3 = 0; } else { mailsession * session = m_pop3->sto_session; mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; if (mail) { mail->pop3_progr_fun = &pop3_progress; } } } void POP3wrapper::logout() { if ( m_pop3 == NULL ) return; mailstorage_free(m_pop3); m_pop3 = 0; } QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); FolderP inb=new Folder("INBOX","/"); folders->append(inb); return folders; } -void POP3wrapper::deleteMailList(QValueList<RecMailP>&target) +void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) { login(); if (!m_pop3) return; int iii = 0; int count = target.count(); + QProgressBar bar( count,0 ); + bar.setCaption (("Removing mails - close to abort!") ); + int w = 300; + if ( QApplication::desktop()->width() < 320 ) + w = 220; + int h = bar.sizeHint().height() ; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + bar.show(); + int modulo = (count/10)+1; + int incCounter = 0; while (iii < count ) { + if ( ! bar.isVisible() ) + return ; + if ( incCounter % modulo == 0 ) + bar.setProgress( incCounter ); + ++incCounter; + qApp->processEvents(); + //qDebug("delete "); RecMailP mail = (*target.at( iii )); int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); if (err != MAIL_NO_ERROR) { - Global::statusMessage(tr("error deleting mail")); + Global::statusMessage(tr("Error deleting mail")); } ++iii; } } void POP3wrapper::deleteMail(const RecMailP&mail) { login(); if (!m_pop3) return; int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("error deleting mail")); } } void POP3wrapper::answeredMail(const RecMailP&) {} int POP3wrapper::deleteAllMail(const FolderP&) { login(); if (!m_pop3) return 0; int res = 1; uint32_t result = 0; int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("Error getting folder info")); return 0; } + QProgressBar bar( result,0 ); + bar.setCaption (("Deleting mails - close to abort!") ); + int w = 300; + if ( QApplication::desktop()->width() < 320 ) + w = 220; + int h = bar.sizeHint().height() ; + int dw = QApplication::desktop()->width(); + int dh = QApplication::desktop()->height(); + bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); + bar.show(); + int modulo = (result/10)+1; + int incCounter = 0; for (unsigned int i = 0; i < result; ++i) { + if ( ! bar.isVisible() ) + return 0; + if ( incCounter % modulo == 0 ) + bar.setProgress( incCounter ); + ++incCounter; + qApp->processEvents(); err = mailsession_remove_message(m_pop3->sto_session,i+1); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); res=0; } break; } return res; } 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; int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, &target_stat.message_recent,&target_stat.message_unseen); if (r != MAIL_NO_ERROR) { ; // odebug << "error getting folter status." << oendl; } } encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { char*target=0; size_t length=0; encodedString*res = 0; mailmessage * mailmsg = 0; int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&target,&length); if (mailmsg) mailmessage_free(mailmsg); if (target) { res = new encodedString(target,length); } return res; } MAILLIB::ATYPE POP3wrapper::getType()const { return account->getType(); } const QString&POP3wrapper::getName()const{ return account->getAccountName(); } diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h index ee754a4..7c70942 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.h +++ b/kmicromail/libmailwrapper/pop3wrapper.h @@ -1,44 +1,44 @@ // CHANGED 2004-09-31 Lutz Rogowski #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" #include "genericwrapper.h" #include <qstring.h> class encodedString; struct mailstorage; struct mailfolder; class POP3wrapper : public Genericwrapper { Q_OBJECT public: POP3wrapper( POP3account *a ); virtual ~POP3wrapper(); /* mailbox will be ignored */ virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); /* mailbox will be ignored */ virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMailP&mail); + virtual void deleteMailList(const QValueList<RecMailP>&target); virtual void answeredMail(const RecMailP&mail); - virtual void deleteMailList(QValueList<RecMailP>&target); virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); virtual RecBodyP fetchBody( const RecMailP &mail ); virtual encodedString* fetchRawBody(const RecMailP&mail); virtual void logout(); virtual MAILLIB::ATYPE getType()const; virtual const QString&getName()const; static void pop3_progress( size_t current, size_t maximum ); protected: void login(); POP3account *account; mailstorage*m_pop3; }; #endif |