author | zautrix <zautrix> | 2004-08-31 21:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-31 21:01:18 (UTC) |
commit | 3f5c51234c8068f3d4826a2a0066648ace21a19f (patch) (unidiff) | |
tree | 91b76c1c7ddec6628c573e409070070747d99feb /kmicromail/libmailwrapper/imapwrapper.cpp | |
parent | 95f8d4f1de557bd25ae38807d970208399cec5d1 (diff) | |
download | kdepimpi-3f5c51234c8068f3d4826a2a0066648ace21a19f.zip kdepimpi-3f5c51234c8068f3d4826a2a0066648ace21a19f.tar.gz kdepimpi-3f5c51234c8068f3d4826a2a0066648ace21a19f.tar.bz2 |
Enhancements of kopiemail
Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index e0fb6f9..bb8bbfc 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,16 +1,17 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | ||
1 | #include <stdlib.h> | 2 | #include <stdlib.h> |
2 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
3 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
4 | #include <qapplication.h> | 5 | #include <qapplication.h> |
5 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
6 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
7 | #include "logindialog.h" | 8 | #include "logindialog.h" |
8 | 9 | ||
9 | using namespace Opie::Core; | 10 | using namespace Opie::Core; |
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 11 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 12 | : AbstractMail() |
12 | { | 13 | { |
13 | account = a; | 14 | account = a; |
14 | m_imap = 0; | 15 | m_imap = 0; |
15 | m_Lastmbox = ""; | 16 | m_Lastmbox = ""; |
16 | } | 17 | } |
@@ -189,33 +190,33 @@ void IMAPwrapper::login() | |||
189 | mailimap_free( m_imap ); | 190 | mailimap_free( m_imap ); |
190 | m_imap = 0; | 191 | m_imap = 0; |
191 | } | 192 | } |
192 | } | 193 | } |
193 | 194 | ||
194 | void IMAPwrapper::logout() | 195 | void IMAPwrapper::logout() |
195 | { | 196 | { |
196 | int err = MAILIMAP_NO_ERROR; | 197 | int err = MAILIMAP_NO_ERROR; |
197 | if (!m_imap) return; | 198 | if (!m_imap) return; |
198 | err = mailimap_logout( m_imap ); | 199 | err = mailimap_logout( m_imap ); |
199 | err = mailimap_close( m_imap ); | 200 | err = mailimap_close( m_imap ); |
200 | mailimap_free( m_imap ); | 201 | mailimap_free( m_imap ); |
201 | m_imap = 0; | 202 | m_imap = 0; |
202 | m_Lastmbox = ""; | 203 | m_Lastmbox = ""; |
203 | } | 204 | } |
204 | 205 | ||
205 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 206 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
206 | { | 207 | { |
207 | int err = MAILIMAP_NO_ERROR; | 208 | int err = MAILIMAP_NO_ERROR; |
208 | clist *result = 0; | 209 | clist *result = 0; |
209 | clistcell *current; | 210 | clistcell *current; |
210 | mailimap_fetch_type *fetchType = 0; | 211 | mailimap_fetch_type *fetchType = 0; |
211 | mailimap_set *set = 0; | 212 | mailimap_set *set = 0; |
212 | 213 | ||
213 | login(); | 214 | login(); |
214 | if (!m_imap) { | 215 | if (!m_imap) { |
215 | return; | 216 | return; |
216 | } | 217 | } |
217 | /* select mailbox READONLY for operations */ | 218 | /* select mailbox READONLY for operations */ |
218 | err = selectMbox(mailbox); | 219 | err = selectMbox(mailbox); |
219 | if ( err != MAILIMAP_NO_ERROR ) { | 220 | if ( err != MAILIMAP_NO_ERROR ) { |
220 | return; | 221 | return; |
221 | } | 222 | } |
@@ -237,36 +238,38 @@ void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSma | |||
237 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 238 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
238 | 239 | ||
239 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 240 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
240 | mailimap_set_free( set ); | 241 | mailimap_set_free( set ); |
241 | mailimap_fetch_type_free( fetchType ); | 242 | mailimap_fetch_type_free( fetchType ); |
242 | 243 | ||
243 | QString date,subject,from; | 244 | QString date,subject,from; |
244 | 245 | ||
245 | if ( err == MAILIMAP_NO_ERROR ) { | 246 | if ( err == MAILIMAP_NO_ERROR ) { |
246 | mailimap_msg_att * msg_att; | 247 | mailimap_msg_att * msg_att; |
247 | int i = 0; | 248 | int i = 0; |
248 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 249 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
249 | ++i; | 250 | ++i; |
250 | msg_att = (mailimap_msg_att*)current->data; | 251 | msg_att = (mailimap_msg_att*)current->data; |
251 | RecMail*m = parse_list_result(msg_att); | 252 | RecMail*m = parse_list_result(msg_att); |
252 | if (m) { | 253 | if (m) { |
253 | m->setNumber(i); | 254 | if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { |
254 | m->setMbox(mailbox); | 255 | m->setNumber(i); |
255 | m->setWrapper(this); | 256 | m->setMbox(mailbox); |
256 | target.append(m); | 257 | m->setWrapper(this); |
258 | target.append(m); | ||
259 | } | ||
257 | } | 260 | } |
258 | } | 261 | } |
259 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 262 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
260 | } else { | 263 | } else { |
261 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 264 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
262 | } | 265 | } |
263 | if (result) mailimap_fetch_list_free(result); | 266 | if (result) mailimap_fetch_list_free(result); |
264 | } | 267 | } |
265 | 268 | ||
266 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 269 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
267 | { | 270 | { |
268 | const char *path, *mask; | 271 | const char *path, *mask; |
269 | int err = MAILIMAP_NO_ERROR; | 272 | int err = MAILIMAP_NO_ERROR; |
270 | clist *result = 0; | 273 | clist *result = 0; |
271 | clistcell *current = 0; | 274 | clistcell *current = 0; |
272 | clistcell*cur_flag = 0; | 275 | clistcell*cur_flag = 0; |
@@ -853,66 +856,110 @@ void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which | |||
853 | break; | 856 | break; |
854 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 857 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
855 | default: | 858 | default: |
856 | if (enc->enc_value) { | 859 | if (enc->enc_value) { |
857 | char*t=enc->enc_value; | 860 | char*t=enc->enc_value; |
858 | encoding=QString(enc->enc_value); | 861 | encoding=QString(enc->enc_value); |
859 | enc->enc_value=0L; | 862 | enc->enc_value=0L; |
860 | free(t); | 863 | free(t); |
861 | } | 864 | } |
862 | } | 865 | } |
863 | if (which->bd_description) { | 866 | if (which->bd_description) { |
864 | target_part->setDescription(QString(which->bd_description)); | 867 | target_part->setDescription(QString(which->bd_description)); |
865 | } | 868 | } |
866 | target_part->setEncoding(encoding); | 869 | target_part->setEncoding(encoding); |
867 | target_part->setSize(which->bd_size); | 870 | target_part->setSize(which->bd_size); |
868 | } | 871 | } |
872 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) | ||
873 | { | ||
874 | mailimap_flag_list*flist; | ||
875 | mailimap_set *set; | ||
876 | mailimap_store_att_flags * store_flags; | ||
877 | int err; | ||
878 | login(); | ||
879 | if (!m_imap) { | ||
880 | return; | ||
881 | } | ||
882 | int iii = 0; | ||
883 | int count = target.count(); | ||
884 | qDebug("imap remove count %d ", count); | ||
885 | while (iii < count ) { | ||
886 | qDebug("IMAP remove %d ", iii); | ||
887 | RecMailP mail = (*target.at( iii )); | ||
869 | 888 | ||
889 | err = selectMbox(mail->getMbox()); | ||
890 | if ( err != MAILIMAP_NO_ERROR ) { | ||
891 | return; | ||
892 | } | ||
893 | flist = mailimap_flag_list_new_empty(); | ||
894 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | ||
895 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | ||
896 | set = mailimap_set_new_single(mail->getNumber()); | ||
897 | err = mailimap_store(m_imap,set,store_flags); | ||
898 | mailimap_set_free( set ); | ||
899 | mailimap_store_att_flags_free(store_flags); | ||
900 | |||
901 | if (err != MAILIMAP_NO_ERROR) { | ||
902 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | ||
903 | return; | ||
904 | } | ||
905 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | ||
906 | /* should we realy do that at this moment? */ | ||
907 | |||
908 | err = mailimap_expunge(m_imap); | ||
909 | if (err != MAILIMAP_NO_ERROR) { | ||
910 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | ||
911 | } | ||
912 | ++iii; | ||
913 | } | ||
914 | } | ||
870 | void IMAPwrapper::deleteMail(const RecMailP&mail) | 915 | void IMAPwrapper::deleteMail(const RecMailP&mail) |
871 | { | 916 | { |
872 | mailimap_flag_list*flist; | 917 | mailimap_flag_list*flist; |
873 | mailimap_set *set; | 918 | mailimap_set *set; |
874 | mailimap_store_att_flags * store_flags; | 919 | mailimap_store_att_flags * store_flags; |
875 | int err; | 920 | int err; |
876 | login(); | 921 | login(); |
877 | if (!m_imap) { | 922 | if (!m_imap) { |
878 | return; | 923 | return; |
879 | } | 924 | } |
880 | err = selectMbox(mail->getMbox()); | 925 | err = selectMbox(mail->getMbox()); |
881 | if ( err != MAILIMAP_NO_ERROR ) { | 926 | if ( err != MAILIMAP_NO_ERROR ) { |
882 | return; | 927 | return; |
883 | } | 928 | } |
884 | flist = mailimap_flag_list_new_empty(); | 929 | flist = mailimap_flag_list_new_empty(); |
885 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 930 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
886 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 931 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
887 | set = mailimap_set_new_single(mail->getNumber()); | 932 | set = mailimap_set_new_single(mail->getNumber()); |
888 | err = mailimap_store(m_imap,set,store_flags); | 933 | err = mailimap_store(m_imap,set,store_flags); |
889 | mailimap_set_free( set ); | 934 | mailimap_set_free( set ); |
890 | mailimap_store_att_flags_free(store_flags); | 935 | mailimap_store_att_flags_free(store_flags); |
891 | 936 | ||
892 | if (err != MAILIMAP_NO_ERROR) { | 937 | if (err != MAILIMAP_NO_ERROR) { |
893 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 938 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
894 | return; | 939 | return; |
895 | } | 940 | } |
896 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 941 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
897 | /* should we realy do that at this moment? */ | 942 | /* should we realy do that at this moment? */ |
943 | |||
898 | err = mailimap_expunge(m_imap); | 944 | err = mailimap_expunge(m_imap); |
899 | if (err != MAILIMAP_NO_ERROR) { | 945 | if (err != MAILIMAP_NO_ERROR) { |
900 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 946 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
901 | } | 947 | } |
902 | // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 948 | qDebug("IMAPwrapper::deleteMail "); |
949 | |||
903 | } | 950 | } |
904 | 951 | ||
905 | void IMAPwrapper::answeredMail(const RecMailP&mail) | 952 | void IMAPwrapper::answeredMail(const RecMailP&mail) |
906 | { | 953 | { |
907 | mailimap_flag_list*flist; | 954 | mailimap_flag_list*flist; |
908 | mailimap_set *set; | 955 | mailimap_set *set; |
909 | mailimap_store_att_flags * store_flags; | 956 | mailimap_store_att_flags * store_flags; |
910 | int err; | 957 | int err; |
911 | login(); | 958 | login(); |
912 | if (!m_imap) { | 959 | if (!m_imap) { |
913 | return; | 960 | return; |
914 | } | 961 | } |
915 | err = selectMbox(mail->getMbox()); | 962 | err = selectMbox(mail->getMbox()); |
916 | if ( err != MAILIMAP_NO_ERROR ) { | 963 | if ( err != MAILIMAP_NO_ERROR ) { |
917 | return; | 964 | return; |
918 | } | 965 | } |
@@ -1107,36 +1154,37 @@ MAILLIB::ATYPE IMAPwrapper::getType()const | |||
1107 | } | 1154 | } |
1108 | 1155 | ||
1109 | const QString&IMAPwrapper::getName()const | 1156 | const QString&IMAPwrapper::getName()const |
1110 | { | 1157 | { |
1111 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | 1158 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; |
1112 | return account->getAccountName(); | 1159 | return account->getAccountName(); |
1113 | } | 1160 | } |
1114 | 1161 | ||
1115 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1162 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1116 | { | 1163 | { |
1117 | // dummy | 1164 | // dummy |
1118 | QValueList<int> path; | 1165 | QValueList<int> path; |
1119 | return fetchRawPart(mail,path,false); | 1166 | return fetchRawPart(mail,path,false); |
1120 | } | 1167 | } |
1121 | 1168 | ||
1122 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1169 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1123 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1170 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
1124 | { | 1171 | { |
1125 | if (targetWrapper != this) { | 1172 | if (targetWrapper != this || maxSizeInKb > 0 ) { |
1126 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 1173 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); |
1174 | qDebug("IMAPwrapper::mvcpAllMails::Using generic"); | ||
1127 | // odebug << "Using generic" << oendl; | 1175 | // odebug << "Using generic" << oendl; |
1128 | return; | 1176 | return; |
1129 | } | 1177 | } |
1130 | mailimap_set *set = 0; | 1178 | mailimap_set *set = 0; |
1131 | login(); | 1179 | login(); |
1132 | if (!m_imap) { | 1180 | if (!m_imap) { |
1133 | return; | 1181 | return; |
1134 | } | 1182 | } |
1135 | int err = selectMbox(fromFolder->getName()); | 1183 | int err = selectMbox(fromFolder->getName()); |
1136 | if ( err != MAILIMAP_NO_ERROR ) { | 1184 | if ( err != MAILIMAP_NO_ERROR ) { |
1137 | return; | 1185 | return; |
1138 | } | 1186 | } |
1139 | int last = m_imap->imap_selection_info->sel_exists; | 1187 | int last = m_imap->imap_selection_info->sel_exists; |
1140 | set = mailimap_set_new_interval( 1, last ); | 1188 | set = mailimap_set_new_interval( 1, last ); |
1141 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1189 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1142 | mailimap_set_free( set ); | 1190 | mailimap_set_free( set ); |