Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 021633b..be825ef 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,29 +1,34 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | #include <qprogressbar.h> | 9 | #include <qprogressbar.h> |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | int IMAPwrapper::mMax = 0; | ||
13 | int IMAPwrapper::mCurrent = 0; | ||
14 | |||
12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 15 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
13 | : AbstractMail() | 16 | : AbstractMail() |
14 | { | 17 | { |
15 | account = a; | 18 | account = a; |
16 | m_imap = 0; | 19 | m_imap = 0; |
17 | m_Lastmbox = ""; | 20 | m_Lastmbox = ""; |
21 | mCurrent = 0; | ||
22 | mMax = 0; | ||
18 | } | 23 | } |
19 | 24 | ||
20 | IMAPwrapper::~IMAPwrapper() | 25 | IMAPwrapper::~IMAPwrapper() |
21 | { | 26 | { |
22 | logout(); | 27 | logout(); |
23 | } | 28 | } |
24 | 29 | ||
25 | /* to avoid to often select statements in loops etc. | 30 | /* to avoid to often select statements in loops etc. |
26 | we trust that we are logged in and connection is established!*/ | 31 | we trust that we are logged in and connection is established!*/ |
27 | int IMAPwrapper::selectMbox(const QString&mbox) | 32 | int IMAPwrapper::selectMbox(const QString&mbox) |
28 | { | 33 | { |
29 | if (mbox == m_Lastmbox) { | 34 | if (mbox == m_Lastmbox) { |
@@ -31,28 +36,48 @@ int IMAPwrapper::selectMbox(const QString&mbox) | |||
31 | } | 36 | } |
32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 37 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
33 | if ( err != MAILIMAP_NO_ERROR ) { | 38 | if ( err != MAILIMAP_NO_ERROR ) { |
34 | m_Lastmbox = ""; | 39 | m_Lastmbox = ""; |
35 | return err; | 40 | return err; |
36 | } | 41 | } |
37 | m_Lastmbox = mbox; | 42 | m_Lastmbox = mbox; |
38 | return err; | 43 | return err; |
39 | } | 44 | } |
40 | 45 | ||
41 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 46 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
42 | { | 47 | { |
48 | //qDebug("imap progress %d of %d ",current,maximum ); | ||
49 | //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum)); | ||
50 | //qApp->processEvents() | ||
51 | static int last = 0; | ||
52 | if ( last != current ) | ||
53 | IMAPwrapper::progress(); | ||
54 | last = current; | ||
55 | } | ||
56 | void IMAPwrapper::progress( QString m ) | ||
57 | { | ||
58 | |||
59 | static QString mProgrMess; | ||
60 | if ( m != QString::null ) { | ||
61 | mProgrMess = m; | ||
62 | mCurrent = 0; | ||
63 | return; | ||
64 | } | ||
65 | QString mess; | ||
66 | //qDebug("progress "); | ||
67 | if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax); | ||
68 | else mess = mProgrMess +tr(" message %1").arg( mCurrent++); | ||
69 | Global::statusMessage(mess); | ||
43 | qApp->processEvents(); | 70 | qApp->processEvents(); |
44 | qDebug("imap progress %d of %d ",current,maximum ); | ||
45 | } | 71 | } |
46 | |||
47 | bool IMAPwrapper::start_tls(bool force_tls) | 72 | bool IMAPwrapper::start_tls(bool force_tls) |
48 | { | 73 | { |
49 | int err; | 74 | int err; |
50 | bool try_tls; | 75 | bool try_tls; |
51 | mailimap_capability_data * cap_data = 0; | 76 | mailimap_capability_data * cap_data = 0; |
52 | 77 | ||
53 | err = mailimap_capability(m_imap,&cap_data); | 78 | err = mailimap_capability(m_imap,&cap_data); |
54 | if (err != MAILIMAP_NO_ERROR) { | 79 | if (err != MAILIMAP_NO_ERROR) { |
55 | Global::statusMessage("error getting capabilities!"); | 80 | Global::statusMessage("error getting capabilities!"); |
56 | return false; | 81 | return false; |
57 | } | 82 | } |
58 | clistiter * cur; | 83 | clistiter * cur; |
@@ -456,26 +481,25 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
456 | } | 481 | } |
457 | if (h.length()>0) { | 482 | if (h.length()>0) { |
458 | m->setInreply(QStringList(h)); | 483 | m->setInreply(QStringList(h)); |
459 | } | 484 | } |
460 | } | 485 | } |
461 | if (head->env_message_id) { | 486 | if (head->env_message_id) { |
462 | m->setMsgid(QString(head->env_message_id)); | 487 | m->setMsgid(QString(head->env_message_id)); |
463 | } | 488 | } |
464 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 489 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
465 | #if 0 | 490 | #if 0 |
466 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 491 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
467 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 492 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
468 | //odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; | 493 | qDebug("time %s ",da.toString().latin1() ); |
469 | //odebug << da.toString() << oendl; | ||
470 | #endif | 494 | #endif |
471 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 495 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
472 | size = item->att_data.att_static->att_data.att_rfc822_size; | 496 | size = item->att_data.att_static->att_data.att_rfc822_size; |
473 | } | 497 | } |
474 | } | 498 | } |
475 | /* msg is already deleted */ | 499 | /* msg is already deleted */ |
476 | if (mFlags.testBit(FLAG_DELETED) && m) { | 500 | if (mFlags.testBit(FLAG_DELETED) && m) { |
477 | delete m; | 501 | delete m; |
478 | m = 0; | 502 | m = 0; |
479 | } | 503 | } |
480 | if (m) { | 504 | if (m) { |
481 | m->setFlags(mFlags); | 505 | m->setFlags(mFlags); |
@@ -877,43 +901,32 @@ void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) | |||
877 | mailimap_set *set; | 901 | mailimap_set *set; |
878 | mailimap_store_att_flags * store_flags; | 902 | mailimap_store_att_flags * store_flags; |
879 | int err; | 903 | int err; |
880 | login(); | 904 | login(); |
881 | //#endif | 905 | //#endif |
882 | if (!m_imap) { | 906 | if (!m_imap) { |
883 | return; | 907 | return; |
884 | } | 908 | } |
885 | int iii = 0; | 909 | int iii = 0; |
886 | int count = target.count(); | 910 | int count = target.count(); |
887 | // qDebug("imap remove count %d ", count); | 911 | // qDebug("imap remove count %d ", count); |
888 | 912 | ||
889 | QProgressBar bar( count,0 ); | 913 | |
890 | bar.setCaption (("Removing mails - close to abort!") ); | 914 | mMax = count; |
891 | int w = 300; | 915 | //progress( tr("Delete")); |
892 | if ( QApplication::desktop()->width() < 320 ) | 916 | QWidget wid; |
893 | w = 220; | 917 | wid.show(); |
894 | int h = bar.sizeHint().height() ; | ||
895 | int dw = QApplication::desktop()->width(); | ||
896 | int dh = QApplication::desktop()->height(); | ||
897 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
898 | bar.show(); | ||
899 | int modulo = (count/10)+1; | ||
900 | int incCounter = 0; | ||
901 | |||
902 | while (iii < count ) { | 918 | while (iii < count ) { |
903 | if ( ! bar.isVisible() ) | 919 | Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); |
904 | return ; | 920 | wid.raise(); |
905 | if ( incCounter % modulo == 0 ) | ||
906 | bar.setProgress( incCounter ); | ||
907 | ++incCounter; | ||
908 | qApp->processEvents(); | 921 | qApp->processEvents(); |
909 | RecMailP mail = (*target.at( iii )); | 922 | RecMailP mail = (*target.at( iii )); |
910 | //#if 0 | 923 | //#if 0 |
911 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); | 924 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); |
912 | err = selectMbox(mail->getMbox()); | 925 | err = selectMbox(mail->getMbox()); |
913 | if ( err != MAILIMAP_NO_ERROR ) { | 926 | if ( err != MAILIMAP_NO_ERROR ) { |
914 | return; | 927 | return; |
915 | } | 928 | } |
916 | flist = mailimap_flag_list_new_empty(); | 929 | flist = mailimap_flag_list_new_empty(); |
917 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 930 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
918 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 931 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
919 | set = mailimap_set_new_single(mail->getNumber()); | 932 | set = mailimap_set_new_single(mail->getNumber()); |
@@ -1190,39 +1203,42 @@ const QString&IMAPwrapper::getName()const | |||
1190 | } | 1203 | } |
1191 | 1204 | ||
1192 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1205 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1193 | { | 1206 | { |
1194 | // dummy | 1207 | // dummy |
1195 | QValueList<int> path; | 1208 | QValueList<int> path; |
1196 | return fetchRawPart(mail,path,false); | 1209 | return fetchRawPart(mail,path,false); |
1197 | } | 1210 | } |
1198 | 1211 | ||
1199 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1212 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1200 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 1213 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
1201 | { | 1214 | { |
1202 | if (targetWrapper != this || maxSizeInKb > 0 ) { | 1215 | if (targetWrapper != this || maxSizeInKb > 0 ) { |
1216 | mMax = 0; | ||
1217 | progress( tr("Copy")); | ||
1203 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); | 1218 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); |
1204 | qDebug("IMAPwrapper::mvcpAllMails::Using generic"); | 1219 | qDebug("IMAPwrapper::mvcpAllMails::Using generic"); |
1205 | // odebug << "Using generic" << oendl; | 1220 | // odebug << "Using generic" << oendl; |
1206 | return; | 1221 | return; |
1207 | } | 1222 | } |
1208 | mailimap_set *set = 0; | 1223 | mailimap_set *set = 0; |
1209 | login(); | 1224 | login(); |
1210 | if (!m_imap) { | 1225 | if (!m_imap) { |
1211 | return; | 1226 | return; |
1212 | } | 1227 | } |
1213 | int err = selectMbox(fromFolder->getName()); | 1228 | int err = selectMbox(fromFolder->getName()); |
1214 | if ( err != MAILIMAP_NO_ERROR ) { | 1229 | if ( err != MAILIMAP_NO_ERROR ) { |
1215 | return; | 1230 | return; |
1216 | } | 1231 | } |
1232 | Global::statusMessage( tr("Copying mails on server...") ); | ||
1217 | int last = m_imap->imap_selection_info->sel_exists; | 1233 | int last = m_imap->imap_selection_info->sel_exists; |
1218 | set = mailimap_set_new_interval( 1, last ); | 1234 | set = mailimap_set_new_interval( 1, last ); |
1219 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1235 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1220 | mailimap_set_free( set ); | 1236 | mailimap_set_free( set ); |
1221 | if ( err != MAILIMAP_NO_ERROR ) { | 1237 | if ( err != MAILIMAP_NO_ERROR ) { |
1222 | QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); | 1238 | QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); |
1223 | Global::statusMessage(error_msg); | 1239 | Global::statusMessage(error_msg); |
1224 | // odebug << error_msg << oendl; | 1240 | // odebug << error_msg << oendl; |
1225 | return; | 1241 | return; |
1226 | } | 1242 | } |
1227 | if (moveit) { | 1243 | if (moveit) { |
1228 | deleteAllMail(fromFolder); | 1244 | deleteAllMail(fromFolder); |