author | alwin <alwin> | 2004-01-10 03:20:04 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-10 03:20:04 (UTC) |
commit | 6248e82bf1b077c54e3e2b85801a99fa0f86434d (patch) (side-by-side diff) | |
tree | d223c9984c9e0d296ba4ae57654c1b15795c1e70 | |
parent | dcfd6e5e2e2021bc5ed0bcf42b1b0a7002c59a17 (diff) | |
download | opie-6248e82bf1b077c54e3e2b85801a99fa0f86434d.zip opie-6248e82bf1b077c54e3e2b85801a99fa0f86434d.tar.gz opie-6248e82bf1b077c54e3e2b85801a99fa0f86434d.tar.bz2 |
mh wrapper fully functional.
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.cpp | 54 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.h | 7 |
2 files changed, 56 insertions, 5 deletions
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index 512f778..5090f4a 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp @@ -1,31 +1,33 @@ #include "mhwrapper.h" #include "mailtypes.h" #include "mailwrapper.h" #include <libetpan/libetpan.h> #include <qdir.h> +#include <qmessagebox.h> #include <stdlib.h> #include <qpe/global.h> +#include <opie/oprocess.h> const QString MHwrapper::wrapperType="MH"; MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) { if (MHPath.length()>0) { if (MHPath[MHPath.length()-1]=='/') { MHPath=MHPath.left(MHPath.length()-1); } qDebug(MHPath); QDir dir(MHPath); if (!dir.exists()) { dir.mkdir(MHPath); } init_storage(); } } void MHwrapper::init_storage() { int r; QString pre = MHPath; if (!m_storage) { @@ -59,48 +61,50 @@ MHwrapper::~MHwrapper() { clean_storage(); } void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) { init_storage(); if (!m_storage) { return; } QString f = buildPath(mailbox); int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); if (r!=MAIL_NO_ERROR) { qDebug("listMessages: error selecting folder!"); return; } parseList(target,m_storage->sto_session,f); Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); } QList<Folder>* MHwrapper::listFolders() { QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); + /* this is needed! */ + if (m_storage) mailstorage_disconnect(m_storage); init_storage(); if (!m_storage) { return folders; } mail_list*flist = 0; clistcell*current=0; int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); if (r != MAIL_NO_ERROR || !flist) { qDebug("error getting folder list"); return folders; } for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { QString t = (char*)current->data; t.replace(0,MHPath.length(),""); folders->append(new MHFolder(t,MHPath)); } mail_list_free(flist); return folders; } void MHwrapper::deleteMail(const RecMail&mail) { init_storage(); if (!m_storage) { @@ -146,62 +150,70 @@ RecBody MHwrapper::fetchBody( const RecMail &mail ) mailmessage_fetch_result_free(msg,data); return body; } void MHwrapper::mbox_progress( size_t current, size_t maximum ) { qDebug("MH %i von %i",current,maximum); } QString MHwrapper::buildPath(const QString&p) { QString f=""; if (p.length()==0||p=="/") return MHPath; if (!p.startsWith(MHPath)) { f+=MHPath; } if (!p.startsWith("/")) { f+="/"; } f+=p; return f; } -int MHwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) +int MHwrapper::createMbox(const QString&folder,const Folder*pfolder,const QString&,bool ) { init_storage(); if (!m_storage) { return 0; } - QString f = buildPath(folder); + QString f; + if (!pfolder) { + // toplevel folder + f = buildPath(folder); + } else { + f = pfolder->getName(); + f+="/"; + f+=folder; + } + qDebug(f); int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); if (r != MAIL_NO_ERROR) { - qDebug("error creating folder"); + qDebug("error creating folder %i",r); return 0; } qDebug("Folder created"); - mailstorage_disconnect(m_storage); return 1; } void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) { init_storage(); if (!m_storage) { return; } QString f = buildPath(Folder); int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); if (r!=MAIL_NO_ERROR) { qDebug("error selecting folder!"); return; } r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); if (r!=MAIL_NO_ERROR) { qDebug("error storing mail"); } return; } encodedString* MHwrapper::fetchRawBody(const RecMail&mail) { @@ -274,58 +286,90 @@ int MHwrapper::deleteAllMail(const Folder*tfolder) } unsigned j = 0; for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { mailmessage * msg; msg = (mailmessage*)carray_get(l->msg_tab, i); j = msg->msg_index; r = mailsession_remove_message(m_storage->sto_session,j); if (r != MAIL_NO_ERROR) { Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); res = 0; break; } } if (l) mailmessage_list_free(l); return res; } int MHwrapper::deleteMbox(const Folder*tfolder) { init_storage(); if (!m_storage) { return 0; } if (!tfolder) return 0; + if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; + int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); + if (r != MAIL_NO_ERROR) { qDebug("error deleting mail box"); return 0; } + QString cmd = "rm -rf "+tfolder->getName(); + QStringList command; + command << "/bin/sh"; + command << "-c"; + command << cmd.latin1(); + OProcess *process = new OProcess(); + + connect(process, SIGNAL(processExited(OProcess *)), + this, SLOT( processEnded(OProcess *))); + connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), + this, SLOT( oprocessStderr(OProcess *, char *, int))); + + *process << command; + removeMboxfailed = false; + if(!process->start(OProcess::Block, OProcess::All) ) { + qDebug("could not start process"); + return 0; + } qDebug("mail box deleted"); - mailstorage_disconnect(m_storage); return 1; } +void MHwrapper::processEnded(OProcess *p) +{ + if (p) delete p; +} + +void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) +{ + QString lineStr = buffer; + QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); + removeMboxfailed = true; +} + void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) { init_storage(); if (!m_storage) { return; } target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; QString f = buildPath(mailbox); int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, &target_stat.message_recent,&target_stat.message_unseen); if (r != MAIL_NO_ERROR) { Global::statusMessage(tr("Error retrieving status")); } } const QString&MHwrapper::getType()const { return wrapperType; } const QString&MHwrapper::getName()const { diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h index 79dec30..b8e380c 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.h +++ b/noncore/net/mail/libmailwrapper/mhwrapper.h @@ -1,52 +1,59 @@ #ifndef __MH_WRAPPER_H #define __MH_WRAPPER_H #include "genericwrapper.h" #include <qstring.h> class RecMail; class RecBody; class encodedString; struct mailmbox_folder; +class OProcess; class MHwrapper : public Genericwrapper { Q_OBJECT public: MHwrapper(const QString & dir,const QString&name); virtual ~MHwrapper(); virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); virtual QList<Folder>* listFolders(); virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); virtual int deleteMbox(const Folder*); virtual void storeMessage(const char*msg,size_t length, const QString&folder); virtual RecBody fetchBody( const RecMail &mail ); static void mbox_progress( size_t current, size_t maximum ); virtual encodedString* fetchRawBody(const RecMail&mail); virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); virtual int deleteAllMail(const Folder*); virtual const QString&getType()const; virtual const QString&getName()const; +public slots: + /* for deleting maildirs we are using a system call */ + virtual void oprocessStderr(OProcess*, char *buffer, int ); + virtual void processEnded(OProcess *); protected: QString buildPath(const QString&p); QString MHPath; QString MHName; static const QString wrapperType; void init_storage(); void clean_storage(); + + bool removeMboxfailed; }; #endif |