summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-28 12:57:44 (UTC)
committer alwin <alwin>2003-12-28 12:57:44 (UTC)
commitb41e3eb92eab8bf61fd20db70d0317c816b1c2f0 (patch) (unidiff)
tree5795854d7de75edc4385edc6ee7389809f98f4e1
parentb834b22bade330b2d684c59b7fc1031a8bf650c5 (diff)
downloadopie-b41e3eb92eab8bf61fd20db70d0317c816b1c2f0.zip
opie-b41e3eb92eab8bf61fd20db70d0317c816b1c2f0.tar.gz
opie-b41e3eb92eab8bf61fd20db70d0317c816b1c2f0.tar.bz2
basic folder handling for pop3 accounts
some code dups reduced
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.h2
-rw-r--r--noncore/net/mail/accountview.cpp76
-rw-r--r--noncore/net/mail/accountview.h6
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h2
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp31
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h1
-rw-r--r--noncore/net/mail/pop3wrapper.cpp31
-rw-r--r--noncore/net/mail/pop3wrapper.h1
8 files changed, 106 insertions, 44 deletions
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index b609aa7..5dc4cab 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -29,6 +29,7 @@ public:
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 virtual void cleanMimeCache(){}; 30 virtual void cleanMimeCache(){};
31 virtual int deleteAllMail(const Folder*){return 1;} 31 virtual int deleteAllMail(const Folder*){return 1;}
32 virtual int deleteMbox(const Folder*){return 1;}
32 33
33 /* mail box methods */ 34 /* mail box methods */
34 /* parameter is the box to create. 35 /* parameter is the box to create.
@@ -36,7 +37,6 @@ public:
36 * them has to be appended automatic. 37 * them has to be appended automatic.
37 */ 38 */
38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;} 39 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;}
39 virtual int deleteMbox(const Folder*){return 1;}
40 40
41 static AbstractMail* getWrapper(IMAPaccount *a); 41 static AbstractMail* getWrapper(IMAPaccount *a);
42 static AbstractMail* getWrapper(POP3account *a); 42 static AbstractMail* getWrapper(POP3account *a);
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 30765cf..f861c20 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -84,6 +84,31 @@ RecBody POP3folderItem::fetchBody(const RecMail&aMail)
84 return pop3->getWrapper()->fetchBody(aMail); 84 return pop3->getWrapper()->fetchBody(aMail);
85} 85}
86 86
87QPopupMenu * POP3folderItem::getContextMenu()
88{
89 QPopupMenu *m = new QPopupMenu(0);
90 if (m) {
91 m->insertItem(QObject::tr("Refresh header list",contextName),0);
92 m->insertItem(QObject::tr("Delete all mails",contextName),1);
93 }
94 return m;
95}
96
97void POP3folderItem::contextMenuSelected(int which)
98{
99 AccountView * view = (AccountView*)listView();
100 switch (which) {
101 case 0:
102 view->refreshCurrent();
103 break;
104 case 1:
105 deleteAllMail(pop3->getWrapper(),folder);
106 break;
107 default:
108 break;
109 }
110}
111
87/** 112/**
88 * IMAP Account stuff 113 * IMAP Account stuff
89 */ 114 */
@@ -304,21 +329,6 @@ QPopupMenu * IMAPfolderItem::getContextMenu()
304 return m; 329 return m;
305} 330}
306 331
307void IMAPfolderItem::deleteAllMails()
308{
309 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
310 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).arg(folder->getDisplayName()),
311 QObject::tr("Yes",contextName),
312 QObject::tr("No",contextName),QString::null,1,1);
313 qDebug("Auswahl: %i",yesno);
314 if (yesno == 0) {
315 if (imap->getWrapper()->deleteAllMail(folder)) {
316 AccountView * view = (AccountView*)listView();
317 if (view) view->refreshCurrent();
318 }
319 }
320}
321
322void IMAPfolderItem::createNewFolder() 332void IMAPfolderItem::createNewFolder()
323{ 333{
324 Newmdirdlg ndirdlg; 334 Newmdirdlg ndirdlg;
@@ -363,7 +373,7 @@ void IMAPfolderItem::contextMenuSelected(int id)
363 view->refreshCurrent(); 373 view->refreshCurrent();
364 break; 374 break;
365 case 1: 375 case 1:
366 deleteAllMails(); 376 deleteAllMail(imap->getWrapper(),folder);
367 break; 377 break;
368 case 2: 378 case 2:
369 createNewFolder(); 379 createNewFolder();
@@ -382,6 +392,23 @@ void IMAPfolderItem::contextMenuSelected(int id)
382 392
383const QString AccountViewItem::contextName="AccountViewItem"; 393const QString AccountViewItem::contextName="AccountViewItem";
384 394
395void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder)
396{
397 if (!wrapper) return;
398 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
399 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
400 arg((folder?folder->getDisplayName():"")),
401 QObject::tr("Yes",contextName),
402 QObject::tr("No",contextName),QString::null,1,1);
403 qDebug("Auswahl: %i",yesno);
404 if (yesno == 0) {
405 if (wrapper->deleteAllMail(folder)) {
406 AccountView * view = (AccountView*)listView();
407 if (view) view->refreshCurrent();
408 }
409 }
410}
411
385AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 412AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
386 : QListView( parent, name, flags ) 413 : QListView( parent, name, flags )
387{ 414{
@@ -594,21 +621,6 @@ RecBody MBOXfolderItem::fetchBody(const RecMail&aMail)
594 return mbox->getWrapper()->fetchBody(aMail); 621 return mbox->getWrapper()->fetchBody(aMail);
595} 622}
596 623
597void MBOXfolderItem::deleteAllMails()
598{
599 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
600 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).arg(folder->getDisplayName()),
601 QObject::tr("Yes",contextName),
602 QObject::tr("No",contextName),QString::null,1,1);
603 qDebug("Auswahl: %i",yesno);
604 if (yesno == 0) {
605 if (mbox->getWrapper()->deleteAllMail(folder)) {
606 AccountView * view = (AccountView*)listView();
607 if (view) view->refreshCurrent();
608 }
609 }
610}
611
612void MBOXfolderItem::deleteFolder() 624void MBOXfolderItem::deleteFolder()
613{ 625{
614 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 626 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
@@ -644,7 +656,7 @@ void MBOXfolderItem::contextMenuSelected(int which)
644{ 656{
645 switch(which) { 657 switch(which) {
646 case 0: 658 case 0:
647 deleteAllMails(); 659 deleteAllMail(mbox->getWrapper(),folder);
648 break; 660 break;
649 case 1: 661 case 1:
650 deleteFolder(); 662 deleteFolder();
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 98abf44..361dd86 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -25,6 +25,7 @@ public:
25 virtual QPopupMenu * getContextMenu(){return 0;}; 25 virtual QPopupMenu * getContextMenu(){return 0;};
26 virtual void contextMenuSelected(int){} 26 virtual void contextMenuSelected(int){}
27protected: 27protected:
28 virtual void deleteAllMail(AbstractMail*wrapper,Folder*f);
28 static const QString contextName; 29 static const QString contextName;
29}; 30};
30 31
@@ -51,6 +52,9 @@ public:
51 ~POP3folderItem(); 52 ~POP3folderItem();
52 virtual void refresh(QList<RecMail>&); 53 virtual void refresh(QList<RecMail>&);
53 virtual RecBody fetchBody(const RecMail&); 54 virtual RecBody fetchBody(const RecMail&);
55 virtual QPopupMenu * getContextMenu();
56 virtual void contextMenuSelected(int);
57
54private: 58private:
55 Folder *folder; 59 Folder *folder;
56 POP3viewItem *pop3; 60 POP3viewItem *pop3;
@@ -96,7 +100,6 @@ public:
96protected: 100protected:
97 virtual void createNewFolder(); 101 virtual void createNewFolder();
98 virtual void deleteFolder(); 102 virtual void deleteFolder();
99 virtual void deleteAllMails();
100 103
101private: 104private:
102 Folder *folder; 105 Folder *folder;
@@ -140,7 +143,6 @@ public:
140 virtual void contextMenuSelected(int); 143 virtual void contextMenuSelected(int);
141 144
142protected: 145protected:
143 virtual void deleteAllMails();
144 virtual void deleteFolder(); 146 virtual void deleteFolder();
145private: 147private:
146 Folder *folder; 148 Folder *folder;
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index b609aa7..5dc4cab 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -29,6 +29,7 @@ public:
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 virtual void cleanMimeCache(){}; 30 virtual void cleanMimeCache(){};
31 virtual int deleteAllMail(const Folder*){return 1;} 31 virtual int deleteAllMail(const Folder*){return 1;}
32 virtual int deleteMbox(const Folder*){return 1;}
32 33
33 /* mail box methods */ 34 /* mail box methods */
34 /* parameter is the box to create. 35 /* parameter is the box to create.
@@ -36,7 +37,6 @@ public:
36 * them has to be appended automatic. 37 * them has to be appended automatic.
37 */ 38 */
38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;} 39 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;}
39 virtual int deleteMbox(const Folder*){return 1;}
40 40
41 static AbstractMail* getWrapper(IMAPaccount *a); 41 static AbstractMail* getWrapper(IMAPaccount *a);
42 static AbstractMail* getWrapper(POP3account *a); 42 static AbstractMail* getWrapper(POP3account *a);
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index b85fbf6..2e70dee 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -206,9 +206,6 @@ void POP3wrapper::logout()
206 206
207QList<Folder>* POP3wrapper::listFolders() 207QList<Folder>* POP3wrapper::listFolders()
208{ 208{
209 /* TODO: integrate MH directories
210 but not before version 0.1 ;)
211 */
212 QList<Folder> * folders = new QList<Folder>(); 209 QList<Folder> * folders = new QList<Folder>();
213 folders->setAutoDelete( false ); 210 folders->setAutoDelete( false );
214 Folder*inb=new Folder("INBOX","/"); 211 Folder*inb=new Folder("INBOX","/");
@@ -222,10 +219,36 @@ void POP3wrapper::deleteMail(const RecMail&mail)
222 if (!m_pop3) return; 219 if (!m_pop3) return;
223 int err = mailpop3_dele(m_pop3,mail.getNumber()); 220 int err = mailpop3_dele(m_pop3,mail.getNumber());
224 if (err != MAILPOP3_NO_ERROR) { 221 if (err != MAILPOP3_NO_ERROR) {
225 qDebug("error deleting mail"); 222 Global::statusMessage(tr("error deleting mail"));
226 } 223 }
227} 224}
228 225
229void POP3wrapper::answeredMail(const RecMail&) 226void POP3wrapper::answeredMail(const RecMail&)
230{ 227{
231} 228}
229
230int POP3wrapper::deleteAllMail(const Folder*)
231{
232 login();
233 if (!m_pop3) return 0;
234 carray * messages = 0;
235
236 /* if connected this info is cached! */
237 int err = 0;
238 mailpop3_list( m_pop3, &messages );
239
240 int res = 1;
241 for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) {
242 mailpop3_msg_info *info;
243 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
244 if (info->msg_deleted)
245 continue;
246 err = mailpop3_dele(m_pop3,i+1);
247 if (err != MAILPOP3_NO_ERROR) {
248 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
249 res = 0;
250 break;
251 }
252 }
253 return res;
254}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 7502720..2efffdd 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -19,6 +19,7 @@ public:
19 19
20 virtual void deleteMail(const RecMail&mail); 20 virtual void deleteMail(const RecMail&mail);
21 virtual void answeredMail(const RecMail&mail); 21 virtual void answeredMail(const RecMail&mail);
22 virtual int deleteAllMail(const Folder*);
22 23
23 virtual RecBody fetchBody( const RecMail &mail ); 24 virtual RecBody fetchBody( const RecMail &mail );
24 static void pop3_progress( size_t current, size_t maximum ); 25 static void pop3_progress( size_t current, size_t maximum );
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index b85fbf6..2e70dee 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -206,9 +206,6 @@ void POP3wrapper::logout()
206 206
207QList<Folder>* POP3wrapper::listFolders() 207QList<Folder>* POP3wrapper::listFolders()
208{ 208{
209 /* TODO: integrate MH directories
210 but not before version 0.1 ;)
211 */
212 QList<Folder> * folders = new QList<Folder>(); 209 QList<Folder> * folders = new QList<Folder>();
213 folders->setAutoDelete( false ); 210 folders->setAutoDelete( false );
214 Folder*inb=new Folder("INBOX","/"); 211 Folder*inb=new Folder("INBOX","/");
@@ -222,10 +219,36 @@ void POP3wrapper::deleteMail(const RecMail&mail)
222 if (!m_pop3) return; 219 if (!m_pop3) return;
223 int err = mailpop3_dele(m_pop3,mail.getNumber()); 220 int err = mailpop3_dele(m_pop3,mail.getNumber());
224 if (err != MAILPOP3_NO_ERROR) { 221 if (err != MAILPOP3_NO_ERROR) {
225 qDebug("error deleting mail"); 222 Global::statusMessage(tr("error deleting mail"));
226 } 223 }
227} 224}
228 225
229void POP3wrapper::answeredMail(const RecMail&) 226void POP3wrapper::answeredMail(const RecMail&)
230{ 227{
231} 228}
229
230int POP3wrapper::deleteAllMail(const Folder*)
231{
232 login();
233 if (!m_pop3) return 0;
234 carray * messages = 0;
235
236 /* if connected this info is cached! */
237 int err = 0;
238 mailpop3_list( m_pop3, &messages );
239
240 int res = 1;
241 for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) {
242 mailpop3_msg_info *info;
243 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
244 if (info->msg_deleted)
245 continue;
246 err = mailpop3_dele(m_pop3,i+1);
247 if (err != MAILPOP3_NO_ERROR) {
248 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
249 res = 0;
250 break;
251 }
252 }
253 return res;
254}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 7502720..2efffdd 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -19,6 +19,7 @@ public:
19 19
20 virtual void deleteMail(const RecMail&mail); 20 virtual void deleteMail(const RecMail&mail);
21 virtual void answeredMail(const RecMail&mail); 21 virtual void answeredMail(const RecMail&mail);
22 virtual int deleteAllMail(const Folder*);
22 23
23 virtual RecBody fetchBody( const RecMail &mail ); 24 virtual RecBody fetchBody( const RecMail &mail );
24 static void pop3_progress( size_t current, size_t maximum ); 25 static void pop3_progress( size_t current, size_t maximum );