Diffstat (limited to 'kmicromail/libmailwrapper/pop3wrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/pop3wrapper.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
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,34 +1,36 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | #include "logindialog.h" | 5 | #include "logindialog.h" |
6 | #include <libetpan/libetpan.h> | 6 | #include <libetpan/libetpan.h> |
7 | 7 | ||
8 | 8 | ||
9 | #include <qpe/global.h> | 9 | #include <qpe/global.h> |
10 | #include <qfile.h> | 10 | #include <qfile.h> |
11 | #include <qprogressbar.h> | ||
12 | #include <qapplication.h> | ||
11 | 13 | ||
12 | /* we don't fetch messages larger than 5 MB */ | 14 | /* we don't fetch messages larger than 5 MB */ |
13 | #define HARD_MSG_SIZE_LIMIT 5242880 | 15 | #define HARD_MSG_SIZE_LIMIT 5242880 |
14 | 16 | ||
15 | using namespace Opie::Core; | 17 | using namespace Opie::Core; |
16 | POP3wrapper::POP3wrapper( POP3account *a ) | 18 | POP3wrapper::POP3wrapper( POP3account *a ) |
17 | : Genericwrapper() { | 19 | : Genericwrapper() { |
18 | account = a; | 20 | account = a; |
19 | m_pop3 = NULL; | 21 | m_pop3 = NULL; |
20 | msgTempName = a->getFileName()+"_msg_cache"; | 22 | msgTempName = a->getFileName()+"_msg_cache"; |
21 | last_msg_id = 0; | 23 | last_msg_id = 0; |
22 | } | 24 | } |
23 | 25 | ||
24 | POP3wrapper::~POP3wrapper() { | 26 | POP3wrapper::~POP3wrapper() { |
25 | logout(); | 27 | logout(); |
26 | QFile msg_cache(msgTempName); | 28 | QFile msg_cache(msgTempName); |
27 | if (msg_cache.exists()) { | 29 | if (msg_cache.exists()) { |
28 | msg_cache.remove(); | 30 | msg_cache.remove(); |
29 | } | 31 | } |
30 | } | 32 | } |
31 | 33 | ||
32 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 34 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
33 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; | 35 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; |
34 | } | 36 | } |
@@ -172,89 +174,126 @@ void POP3wrapper::login() | |||
172 | mailsession * session = m_pop3->sto_session; | 174 | mailsession * session = m_pop3->sto_session; |
173 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; | 175 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; |
174 | if (mail) { | 176 | if (mail) { |
175 | mail->pop3_progr_fun = &pop3_progress; | 177 | mail->pop3_progr_fun = &pop3_progress; |
176 | } | 178 | } |
177 | } | 179 | } |
178 | } | 180 | } |
179 | 181 | ||
180 | void POP3wrapper::logout() | 182 | void POP3wrapper::logout() |
181 | { | 183 | { |
182 | if ( m_pop3 == NULL ) | 184 | if ( m_pop3 == NULL ) |
183 | return; | 185 | return; |
184 | mailstorage_free(m_pop3); | 186 | mailstorage_free(m_pop3); |
185 | m_pop3 = 0; | 187 | m_pop3 = 0; |
186 | } | 188 | } |
187 | 189 | ||
188 | 190 | ||
189 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { | 191 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { |
190 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); | 192 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); |
191 | FolderP inb=new Folder("INBOX","/"); | 193 | FolderP inb=new Folder("INBOX","/"); |
192 | folders->append(inb); | 194 | folders->append(inb); |
193 | return folders; | 195 | return folders; |
194 | } | 196 | } |
195 | 197 | ||
196 | void POP3wrapper::deleteMailList(QValueList<RecMailP>&target) | 198 | void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) |
197 | { | 199 | { |
198 | login(); | 200 | login(); |
199 | if (!m_pop3) | 201 | if (!m_pop3) |
200 | return; | 202 | return; |
201 | int iii = 0; | 203 | int iii = 0; |
202 | int count = target.count(); | 204 | int count = target.count(); |
205 | QProgressBar bar( count,0 ); | ||
206 | bar.setCaption (("Removing mails - close to abort!") ); | ||
207 | int w = 300; | ||
208 | if ( QApplication::desktop()->width() < 320 ) | ||
209 | w = 220; | ||
210 | int h = bar.sizeHint().height() ; | ||
211 | int dw = QApplication::desktop()->width(); | ||
212 | int dh = QApplication::desktop()->height(); | ||
213 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
214 | bar.show(); | ||
215 | int modulo = (count/10)+1; | ||
216 | int incCounter = 0; | ||
203 | while (iii < count ) { | 217 | while (iii < count ) { |
218 | if ( ! bar.isVisible() ) | ||
219 | return ; | ||
220 | if ( incCounter % modulo == 0 ) | ||
221 | bar.setProgress( incCounter ); | ||
222 | ++incCounter; | ||
223 | qApp->processEvents(); | ||
224 | //qDebug("delete "); | ||
204 | RecMailP mail = (*target.at( iii )); | 225 | RecMailP mail = (*target.at( iii )); |
205 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 226 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
206 | if (err != MAIL_NO_ERROR) { | 227 | if (err != MAIL_NO_ERROR) { |
207 | Global::statusMessage(tr("error deleting mail")); | 228 | Global::statusMessage(tr("Error deleting mail")); |
208 | } | 229 | } |
209 | ++iii; | 230 | ++iii; |
210 | } | 231 | } |
211 | } | 232 | } |
212 | void POP3wrapper::deleteMail(const RecMailP&mail) { | 233 | void POP3wrapper::deleteMail(const RecMailP&mail) { |
213 | login(); | 234 | login(); |
214 | if (!m_pop3) | 235 | if (!m_pop3) |
215 | return; | 236 | return; |
216 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 237 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
217 | if (err != MAIL_NO_ERROR) { | 238 | if (err != MAIL_NO_ERROR) { |
218 | Global::statusMessage(tr("error deleting mail")); | 239 | Global::statusMessage(tr("error deleting mail")); |
219 | } | 240 | } |
220 | } | 241 | } |
221 | 242 | ||
222 | void POP3wrapper::answeredMail(const RecMailP&) {} | 243 | void POP3wrapper::answeredMail(const RecMailP&) {} |
223 | 244 | ||
224 | int POP3wrapper::deleteAllMail(const FolderP&) { | 245 | int POP3wrapper::deleteAllMail(const FolderP&) { |
225 | login(); | 246 | login(); |
226 | if (!m_pop3) | 247 | if (!m_pop3) |
227 | return 0; | 248 | return 0; |
228 | int res = 1; | 249 | int res = 1; |
229 | 250 | ||
230 | uint32_t result = 0; | 251 | uint32_t result = 0; |
231 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); | 252 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); |
232 | if (err != MAIL_NO_ERROR) { | 253 | if (err != MAIL_NO_ERROR) { |
233 | Global::statusMessage(tr("Error getting folder info")); | 254 | Global::statusMessage(tr("Error getting folder info")); |
234 | return 0; | 255 | return 0; |
235 | } | 256 | } |
257 | QProgressBar bar( result,0 ); | ||
258 | bar.setCaption (("Deleting mails - close to abort!") ); | ||
259 | int w = 300; | ||
260 | if ( QApplication::desktop()->width() < 320 ) | ||
261 | w = 220; | ||
262 | int h = bar.sizeHint().height() ; | ||
263 | int dw = QApplication::desktop()->width(); | ||
264 | int dh = QApplication::desktop()->height(); | ||
265 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
266 | bar.show(); | ||
267 | int modulo = (result/10)+1; | ||
268 | int incCounter = 0; | ||
236 | for (unsigned int i = 0; i < result; ++i) { | 269 | for (unsigned int i = 0; i < result; ++i) { |
270 | if ( ! bar.isVisible() ) | ||
271 | return 0; | ||
272 | if ( incCounter % modulo == 0 ) | ||
273 | bar.setProgress( incCounter ); | ||
274 | ++incCounter; | ||
275 | qApp->processEvents(); | ||
237 | err = mailsession_remove_message(m_pop3->sto_session,i+1); | 276 | err = mailsession_remove_message(m_pop3->sto_session,i+1); |
238 | if (err != MAIL_NO_ERROR) { | 277 | if (err != MAIL_NO_ERROR) { |
239 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 278 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
240 | res=0; | 279 | res=0; |
241 | } | 280 | } |
242 | break; | 281 | break; |
243 | } | 282 | } |
244 | return res; | 283 | return res; |
245 | } | 284 | } |
246 | 285 | ||
247 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | 286 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { |
248 | login(); | 287 | login(); |
249 | target_stat.message_count = 0; | 288 | target_stat.message_count = 0; |
250 | target_stat.message_unseen = 0; | 289 | target_stat.message_unseen = 0; |
251 | target_stat.message_recent = 0; | 290 | target_stat.message_recent = 0; |
252 | if (!m_pop3) | 291 | if (!m_pop3) |
253 | return; | 292 | return; |
254 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, | 293 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, |
255 | &target_stat.message_recent,&target_stat.message_unseen); | 294 | &target_stat.message_recent,&target_stat.message_unseen); |
256 | if (r != MAIL_NO_ERROR) { | 295 | if (r != MAIL_NO_ERROR) { |
257 | ; // odebug << "error getting folter status." << oendl; | 296 | ; // odebug << "error getting folter status." << oendl; |
258 | } | 297 | } |
259 | } | 298 | } |
260 | 299 | ||