summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-28 12:57:44 (UTC)
committer alwin <alwin>2003-12-28 12:57:44 (UTC)
commitb41e3eb92eab8bf61fd20db70d0317c816b1c2f0 (patch) (side-by-side diff)
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
@@ -8,44 +8,44 @@ class RecMail;
class RecBody;
class RecPart;
class IMAPwrapper;
class POP3wrapper;
class Folder;
class encodedString;
class AbstractMail:public QObject
{
Q_OBJECT
public:
AbstractMail(){};
virtual ~AbstractMail(){}
virtual QList<Folder>* listFolders()=0;
virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
virtual RecBody fetchBody(const RecMail&mail)=0;
virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
virtual void deleteMail(const RecMail&mail)=0;
virtual void answeredMail(const RecMail&mail)=0;
virtual void cleanMimeCache(){};
virtual int deleteAllMail(const Folder*){return 1;}
+ virtual int deleteMbox(const Folder*){return 1;}
/* mail box methods */
/* parameter is the box to create.
* if the implementing subclass has prefixes,
* them has to be appended automatic.
*/
virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;}
- virtual int deleteMbox(const Folder*){return 1;}
static AbstractMail* getWrapper(IMAPaccount *a);
static AbstractMail* getWrapper(POP3account *a);
/* mbox only! */
static AbstractMail* getWrapper(const QString&a);
protected:
static encodedString*decode_String(const encodedString*text,const QString&enc);
static QString convert_String(const char*text);
static QString gen_attachment_id();
};
#endif
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
@@ -63,48 +63,73 @@ POP3folderItem::~POP3folderItem()
POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after )
: AccountViewItem( parent,after )
{
folder = folderInit;
pop3 = parent;
if (folder->getDisplayName().lower()!="inbox") {
setPixmap( 0, PIXMAP_POP3FOLDER );
} else {
setPixmap( 0, PIXMAP_INBOXFOLDER);
}
setText( 0, folder->getDisplayName() );
}
void POP3folderItem::refresh(QList<RecMail>&target)
{
if (folder->may_select())
pop3->getWrapper()->listMessages( folder->getName(),target );
}
RecBody POP3folderItem::fetchBody(const RecMail&aMail)
{
return pop3->getWrapper()->fetchBody(aMail);
}
+QPopupMenu * POP3folderItem::getContextMenu()
+{
+ QPopupMenu *m = new QPopupMenu(0);
+ if (m) {
+ m->insertItem(QObject::tr("Refresh header list",contextName),0);
+ m->insertItem(QObject::tr("Delete all mails",contextName),1);
+ }
+ return m;
+}
+
+void POP3folderItem::contextMenuSelected(int which)
+{
+ AccountView * view = (AccountView*)listView();
+ switch (which) {
+ case 0:
+ view->refreshCurrent();
+ break;
+ case 1:
+ deleteAllMail(pop3->getWrapper(),folder);
+ break;
+ default:
+ break;
+ }
+}
+
/**
* IMAP Account stuff
*/
IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
: AccountViewItem( parent )
{
account = a;
wrapper = AbstractMail::getWrapper( account );
setPixmap( 0, PIXMAP_IMAPFOLDER );
setText( 0, account->getAccountName() );
setOpen( true );
}
IMAPviewItem::~IMAPviewItem()
{
delete wrapper;
}
AbstractMail *IMAPviewItem::getWrapper()
{
return wrapper;
}
IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start)
@@ -283,126 +308,128 @@ void IMAPfolderItem::refresh(QList<RecMail>&target)
RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
{
return imap->getWrapper()->fetchBody(aMail);
}
QPopupMenu * IMAPfolderItem::getContextMenu()
{
QPopupMenu *m = new QPopupMenu(0);
if (m) {
if (folder->may_select()) {
m->insertItem(QObject::tr("Refresh header list",contextName),0);
m->insertItem(QObject::tr("Delete all mails",contextName),1);
}
if (folder->no_inferior()==false) {
m->insertItem(QObject::tr("Create new subfolder",contextName),2);
}
if (folder->getDisplayName().lower()!="inbox") {
m->insertItem(QObject::tr("Delete folder",contextName),3);
}
}
return m;
}
-void IMAPfolderItem::deleteAllMails()
-{
- int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
- QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).arg(folder->getDisplayName()),
- QObject::tr("Yes",contextName),
- QObject::tr("No",contextName),QString::null,1,1);
- qDebug("Auswahl: %i",yesno);
- if (yesno == 0) {
- if (imap->getWrapper()->deleteAllMail(folder)) {
- AccountView * view = (AccountView*)listView();
- if (view) view->refreshCurrent();
- }
- }
-}
-
void IMAPfolderItem::createNewFolder()
{
Newmdirdlg ndirdlg;
ndirdlg.showMaximized();
if (ndirdlg.exec()) {
QString ndir = ndirdlg.Newdir();
bool makesubs = ndirdlg.subpossible();
QString delemiter = Delemiter();
if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) {
imap->refreshFolders(true);
}
}
}
void IMAPfolderItem::deleteFolder()
{
int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
QObject::tr("Yes",contextName),
QObject::tr("No",contextName),QString::null,1,1);
qDebug("Auswahl: %i",yesno);
if (yesno == 0) {
if (imap->getWrapper()->deleteMbox(folder)) {
QListView*v=listView();
IMAPviewItem * box = imap;
/* be carefull - after that this object is destroyd so don't use
* any member of it after that call!!*/
imap->refreshFolders(true);
if (v) {
v->setSelected(box,true);
}
}
}
}
void IMAPfolderItem::contextMenuSelected(int id)
{
qDebug("Selected id: %i",id);
AccountView * view = (AccountView*)listView();
switch(id) {
case 0:
view->refreshCurrent();
break;
case 1:
- deleteAllMails();
+ deleteAllMail(imap->getWrapper(),folder);
break;
case 2:
createNewFolder();
break;
case 3:
deleteFolder();
break;
default:
break;
}
}
/**
* Generic stuff
*/
const QString AccountViewItem::contextName="AccountViewItem";
+void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder)
+{
+ if (!wrapper) return;
+ int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
+ QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
+ arg((folder?folder->getDisplayName():"")),
+ QObject::tr("Yes",contextName),
+ QObject::tr("No",contextName),QString::null,1,1);
+ qDebug("Auswahl: %i",yesno);
+ if (yesno == 0) {
+ if (wrapper->deleteAllMail(folder)) {
+ AccountView * view = (AccountView*)listView();
+ if (view) view->refreshCurrent();
+ }
+ }
+}
+
AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
: QListView( parent, name, flags )
{
connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
SLOT( refresh( QListViewItem * ) ) );
connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this,
SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) );
setSorting(0);
}
void AccountView::slotContextMenu(int id)
{
AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
if (!view) return;
view->contextMenuSelected(id);
}
void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
{
if (button==1) {return;}
if (!item) return;
AccountViewItem *view = static_cast<AccountViewItem *>(item);
QPopupMenu*m = view->getContextMenu();
@@ -573,83 +600,68 @@ MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QList
{
folder = folderInit;
mbox = parent;
if (folder->getDisplayName().lower() == "outgoing") {
setPixmap( 0, PIXMAP_OUTBOXFOLDER );
} else if (folder->getDisplayName().lower() == "inbox") {
setPixmap( 0, PIXMAP_INBOXFOLDER);
} else {
setPixmap( 0, PIXMAP_MBOXFOLDER );
}
setText( 0, folder->getDisplayName() );
}
void MBOXfolderItem::refresh(QList<RecMail>&target)
{
if (folder->may_select())
mbox->getWrapper()->listMessages( folder->getName(),target );
}
RecBody MBOXfolderItem::fetchBody(const RecMail&aMail)
{
return mbox->getWrapper()->fetchBody(aMail);
}
-void MBOXfolderItem::deleteAllMails()
-{
- int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
- QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).arg(folder->getDisplayName()),
- QObject::tr("Yes",contextName),
- QObject::tr("No",contextName),QString::null,1,1);
- qDebug("Auswahl: %i",yesno);
- if (yesno == 0) {
- if (mbox->getWrapper()->deleteAllMail(folder)) {
- AccountView * view = (AccountView*)listView();
- if (view) view->refreshCurrent();
- }
- }
-}
-
void MBOXfolderItem::deleteFolder()
{
int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
QObject::tr("Yes",contextName),
QObject::tr("No",contextName),QString::null,1,1);
qDebug("Auswahl: %i",yesno);
if (yesno == 0) {
if (mbox->getWrapper()->deleteMbox(folder)) {
QListView*v=listView();
MBOXviewItem * box = mbox;
/* be carefull - after that this object is destroyd so don't use
* any member of it after that call!!*/
mbox->refresh(true);
if (v) {
v->setSelected(box,true);
}
}
}
}
QPopupMenu * MBOXfolderItem::getContextMenu()
{
QPopupMenu *m = new QPopupMenu(0);
if (m) {
m->insertItem(QObject::tr("Delete all mails",contextName),0);
m->insertItem(QObject::tr("Delete folder",contextName),1);
}
return m;
}
void MBOXfolderItem::contextMenuSelected(int which)
{
switch(which) {
case 0:
- deleteAllMails();
+ deleteAllMail(mbox->getWrapper(),folder);
break;
case 1:
deleteFolder();
break;
default:
break;
}
}
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
@@ -4,164 +4,166 @@
#include <qlistview.h>
#include <qlist.h>
#include "settings.h"
#include "mailwrapper.h"
#include "abstractmail.h"
class POP3wrapper;
class RecMail;
class RecBody;
class QPopupMenu;
class AccountViewItem : public QListViewItem
{
public:
AccountViewItem( QListView *parent ) : QListViewItem( parent ) {}
AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {}
AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {}
virtual void refresh(QList<RecMail>&)=0;
virtual RecBody fetchBody(const RecMail&)=0;
virtual QPopupMenu * getContextMenu(){return 0;};
virtual void contextMenuSelected(int){}
protected:
+ virtual void deleteAllMail(AbstractMail*wrapper,Folder*f);
static const QString contextName;
};
class POP3viewItem : public AccountViewItem
{
public:
POP3viewItem( POP3account *a, QListView *parent );
~POP3viewItem();
virtual void refresh( QList<RecMail> &target );
virtual RecBody fetchBody( const RecMail &mail );
AbstractMail *getWrapper();
private:
POP3account *account;
AbstractMail *wrapper;
};
class POP3folderItem : public AccountViewItem
{
public:
POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after );
~POP3folderItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
+ virtual QPopupMenu * getContextMenu();
+ virtual void contextMenuSelected(int);
+
private:
Folder *folder;
POP3viewItem *pop3;
};
class IMAPfolderItem;
class IMAPviewItem : public AccountViewItem
{
friend class IMAPfolderItem;
public:
IMAPviewItem( IMAPaccount *a, QListView *parent );
~IMAPviewItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
AbstractMail *getWrapper();
virtual QPopupMenu * getContextMenu();
virtual void contextMenuSelected(int);
protected:
IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0);
virtual void refreshFolders(bool force=false);
virtual void createNewFolder();
private:
IMAPaccount *account;
AbstractMail *wrapper;
};
class IMAPfolderItem : public AccountViewItem
{
public:
IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
~IMAPfolderItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
bool matchName(const QString&name)const;
virtual QPopupMenu * getContextMenu();
virtual void contextMenuSelected(int);
virtual const QString& Delemiter()const;
protected:
virtual void createNewFolder();
virtual void deleteFolder();
- virtual void deleteAllMails();
private:
Folder *folder;
IMAPviewItem *imap;
};
class MBOXviewItem : public AccountViewItem
{
friend class MBOXfolderItem;
public:
// MBOXviewItem( MBOXaccount *a, QListView *parent );
MBOXviewItem( const QString&aMboxPath, QListView *parent );
~MBOXviewItem();
virtual void refresh( QList<RecMail> &target );
virtual RecBody fetchBody( const RecMail &mail );
AbstractMail *getWrapper();
virtual QPopupMenu * getContextMenu();
virtual void contextMenuSelected(int);
protected:
virtual void refresh(bool force=false);
virtual void createFolder();
private:
// MBOXaccount *account;
QString m_Path;
AbstractMail *wrapper;
};
class MBOXfolderItem : public AccountViewItem
{
public:
MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after );
~MBOXfolderItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
virtual QPopupMenu * getContextMenu();
virtual void contextMenuSelected(int);
protected:
- virtual void deleteAllMails();
virtual void deleteFolder();
private:
Folder *folder;
MBOXviewItem *mbox;
};
class AccountView : public QListView
{
Q_OBJECT
public:
AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
void populate( QList<Account> list );
RecBody fetchBody(const RecMail&aMail);
public slots:
virtual void refreshAll();
virtual void refresh(QListViewItem *item);
virtual void refreshCurrent();
virtual void slotHold(int, QListViewItem *,const QPoint&,int);
virtual void slotContextMenu(int id);
signals:
void refreshMailview(QList<RecMail>*);
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
@@ -8,44 +8,44 @@ class RecMail;
class RecBody;
class RecPart;
class IMAPwrapper;
class POP3wrapper;
class Folder;
class encodedString;
class AbstractMail:public QObject
{
Q_OBJECT
public:
AbstractMail(){};
virtual ~AbstractMail(){}
virtual QList<Folder>* listFolders()=0;
virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
virtual RecBody fetchBody(const RecMail&mail)=0;
virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
virtual void deleteMail(const RecMail&mail)=0;
virtual void answeredMail(const RecMail&mail)=0;
virtual void cleanMimeCache(){};
virtual int deleteAllMail(const Folder*){return 1;}
+ virtual int deleteMbox(const Folder*){return 1;}
/* mail box methods */
/* parameter is the box to create.
* if the implementing subclass has prefixes,
* them has to be appended automatic.
*/
virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;}
- virtual int deleteMbox(const Folder*){return 1;}
static AbstractMail* getWrapper(IMAPaccount *a);
static AbstractMail* getWrapper(POP3account *a);
/* mbox only! */
static AbstractMail* getWrapper(const QString&a);
protected:
static encodedString*decode_String(const encodedString*text,const QString&enc);
static QString convert_String(const char*text);
static QString gen_attachment_id();
};
#endif
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
@@ -185,47 +185,70 @@ void POP3wrapper::login()
// login
// TODO: decide if apop or plain login should be used
err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
if ( err != MAILPOP3_NO_ERROR ) {
qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
logout();
return;
}
qDebug( "POP3: logged in!" );
}
void POP3wrapper::logout()
{
int err = MAILPOP3_NO_ERROR;
if ( m_pop3 == NULL ) return;
err = mailpop3_quit( m_pop3 );
mailpop3_free( m_pop3 );
m_pop3 = NULL;
}
QList<Folder>* POP3wrapper::listFolders()
{
- /* TODO: integrate MH directories
- but not before version 0.1 ;)
- */
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();
if (!m_pop3) return;
int err = mailpop3_dele(m_pop3,mail.getNumber());
if (err != MAILPOP3_NO_ERROR) {
- qDebug("error deleting mail");
+ Global::statusMessage(tr("error deleting mail"));
}
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
+
+int POP3wrapper::deleteAllMail(const Folder*)
+{
+ login();
+ if (!m_pop3) return 0;
+ carray * messages = 0;
+
+ /* if connected this info is cached! */
+ int err = 0;
+ mailpop3_list( m_pop3, &messages );
+
+ int res = 1;
+ for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) {
+ mailpop3_msg_info *info;
+ err = mailpop3_get_msg_info(m_pop3,i+1,&info);
+ if (info->msg_deleted)
+ continue;
+ err = mailpop3_dele(m_pop3,i+1);
+ if (err != MAILPOP3_NO_ERROR) {
+ Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
+ res = 0;
+ break;
+ }
+ }
+ return res;
+}
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
@@ -1,33 +1,34 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
#include "genericwrapper.h"
#include <qstring.h>
class POP3wrapper : public Genericwrapper
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
/* mailbox will be ignored */
virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
virtual QList<Folder>* listFolders();
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
+ virtual int deleteAllMail(const Folder*);
virtual RecBody fetchBody( const RecMail &mail );
static void pop3_progress( size_t current, size_t maximum );
protected:
void login();
void logout();
POP3account *account;
mailpop3 *m_pop3;
};
#endif
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
@@ -185,47 +185,70 @@ void POP3wrapper::login()
// login
// TODO: decide if apop or plain login should be used
err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
if ( err != MAILPOP3_NO_ERROR ) {
qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
logout();
return;
}
qDebug( "POP3: logged in!" );
}
void POP3wrapper::logout()
{
int err = MAILPOP3_NO_ERROR;
if ( m_pop3 == NULL ) return;
err = mailpop3_quit( m_pop3 );
mailpop3_free( m_pop3 );
m_pop3 = NULL;
}
QList<Folder>* POP3wrapper::listFolders()
{
- /* TODO: integrate MH directories
- but not before version 0.1 ;)
- */
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();
if (!m_pop3) return;
int err = mailpop3_dele(m_pop3,mail.getNumber());
if (err != MAILPOP3_NO_ERROR) {
- qDebug("error deleting mail");
+ Global::statusMessage(tr("error deleting mail"));
}
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
+
+int POP3wrapper::deleteAllMail(const Folder*)
+{
+ login();
+ if (!m_pop3) return 0;
+ carray * messages = 0;
+
+ /* if connected this info is cached! */
+ int err = 0;
+ mailpop3_list( m_pop3, &messages );
+
+ int res = 1;
+ for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) {
+ mailpop3_msg_info *info;
+ err = mailpop3_get_msg_info(m_pop3,i+1,&info);
+ if (info->msg_deleted)
+ continue;
+ err = mailpop3_dele(m_pop3,i+1);
+ if (err != MAILPOP3_NO_ERROR) {
+ Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
+ res = 0;
+ break;
+ }
+ }
+ return res;
+}
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
@@ -1,33 +1,34 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
#include "genericwrapper.h"
#include <qstring.h>
class POP3wrapper : public Genericwrapper
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
/* mailbox will be ignored */
virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
virtual QList<Folder>* listFolders();
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
+ virtual int deleteAllMail(const Folder*);
virtual RecBody fetchBody( const RecMail &mail );
static void pop3_progress( size_t current, size_t maximum );
protected:
void login();
void logout();
POP3account *account;
mailpop3 *m_pop3;
};
#endif