-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,13 +1,15 @@ | |||
1 | #include "mhwrapper.h" | 1 | #include "mhwrapper.h" |
2 | #include "mailtypes.h" | 2 | #include "mailtypes.h" |
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qmessagebox.h> | ||
6 | #include <stdlib.h> | 7 | #include <stdlib.h> |
7 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | #include <opie/oprocess.h> | ||
8 | 10 | ||
9 | const QString MHwrapper::wrapperType="MH"; | 11 | const QString MHwrapper::wrapperType="MH"; |
10 | 12 | ||
11 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 13 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
12 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 14 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
13 | { | 15 | { |
@@ -77,12 +79,14 @@ void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
77 | } | 79 | } |
78 | 80 | ||
79 | QList<Folder>* MHwrapper::listFolders() | 81 | QList<Folder>* MHwrapper::listFolders() |
80 | { | 82 | { |
81 | QList<Folder> * folders = new QList<Folder>(); | 83 | QList<Folder> * folders = new QList<Folder>(); |
82 | folders->setAutoDelete( false ); | 84 | folders->setAutoDelete( false ); |
85 | /* this is needed! */ | ||
86 | if (m_storage) mailstorage_disconnect(m_storage); | ||
83 | init_storage(); | 87 | init_storage(); |
84 | if (!m_storage) { | 88 | if (!m_storage) { |
85 | return folders; | 89 | return folders; |
86 | } | 90 | } |
87 | mail_list*flist = 0; | 91 | mail_list*flist = 0; |
88 | clistcell*current=0; | 92 | clistcell*current=0; |
@@ -164,26 +168,34 @@ QString MHwrapper::buildPath(const QString&p) | |||
164 | f+="/"; | 168 | f+="/"; |
165 | } | 169 | } |
166 | f+=p; | 170 | f+=p; |
167 | return f; | 171 | return f; |
168 | } | 172 | } |
169 | 173 | ||
170 | int MHwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) | 174 | int MHwrapper::createMbox(const QString&folder,const Folder*pfolder,const QString&,bool ) |
171 | { | 175 | { |
172 | init_storage(); | 176 | init_storage(); |
173 | if (!m_storage) { | 177 | if (!m_storage) { |
174 | return 0; | 178 | return 0; |
175 | } | 179 | } |
176 | QString f = buildPath(folder); | 180 | QString f; |
181 | if (!pfolder) { | ||
182 | // toplevel folder | ||
183 | f = buildPath(folder); | ||
184 | } else { | ||
185 | f = pfolder->getName(); | ||
186 | f+="/"; | ||
187 | f+=folder; | ||
188 | } | ||
189 | qDebug(f); | ||
177 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 190 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
178 | if (r != MAIL_NO_ERROR) { | 191 | if (r != MAIL_NO_ERROR) { |
179 | qDebug("error creating folder"); | 192 | qDebug("error creating folder %i",r); |
180 | return 0; | 193 | return 0; |
181 | } | 194 | } |
182 | qDebug("Folder created"); | 195 | qDebug("Folder created"); |
183 | mailstorage_disconnect(m_storage); | ||
184 | return 1; | 196 | return 1; |
185 | } | 197 | } |
186 | 198 | ||
187 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 199 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
188 | { | 200 | { |
189 | init_storage(); | 201 | init_storage(); |
@@ -292,22 +304,54 @@ int MHwrapper::deleteMbox(const Folder*tfolder) | |||
292 | { | 304 | { |
293 | init_storage(); | 305 | init_storage(); |
294 | if (!m_storage) { | 306 | if (!m_storage) { |
295 | return 0; | 307 | return 0; |
296 | } | 308 | } |
297 | if (!tfolder) return 0; | 309 | if (!tfolder) return 0; |
310 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; | ||
311 | |||
298 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 312 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
313 | |||
299 | if (r != MAIL_NO_ERROR) { | 314 | if (r != MAIL_NO_ERROR) { |
300 | qDebug("error deleting mail box"); | 315 | qDebug("error deleting mail box"); |
301 | return 0; | 316 | return 0; |
302 | } | 317 | } |
318 | QString cmd = "rm -rf "+tfolder->getName(); | ||
319 | QStringList command; | ||
320 | command << "/bin/sh"; | ||
321 | command << "-c"; | ||
322 | command << cmd.latin1(); | ||
323 | OProcess *process = new OProcess(); | ||
324 | |||
325 | connect(process, SIGNAL(processExited(OProcess *)), | ||
326 | this, SLOT( processEnded(OProcess *))); | ||
327 | connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), | ||
328 | this, SLOT( oprocessStderr(OProcess *, char *, int))); | ||
329 | |||
330 | *process << command; | ||
331 | removeMboxfailed = false; | ||
332 | if(!process->start(OProcess::Block, OProcess::All) ) { | ||
333 | qDebug("could not start process"); | ||
334 | return 0; | ||
335 | } | ||
303 | qDebug("mail box deleted"); | 336 | qDebug("mail box deleted"); |
304 | mailstorage_disconnect(m_storage); | ||
305 | return 1; | 337 | return 1; |
306 | } | 338 | } |
307 | 339 | ||
340 | void MHwrapper::processEnded(OProcess *p) | ||
341 | { | ||
342 | if (p) delete p; | ||
343 | } | ||
344 | |||
345 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) | ||
346 | { | ||
347 | QString lineStr = buffer; | ||
348 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); | ||
349 | removeMboxfailed = true; | ||
350 | } | ||
351 | |||
308 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 352 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
309 | { | 353 | { |
310 | init_storage(); | 354 | init_storage(); |
311 | if (!m_storage) { | 355 | if (!m_storage) { |
312 | return; | 356 | return; |
313 | } | 357 | } |
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 | |||
@@ -5,12 +5,13 @@ | |||
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | 6 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailmbox_folder; | 10 | struct mailmbox_folder; |
11 | class OProcess; | ||
11 | 12 | ||
12 | class MHwrapper : public Genericwrapper | 13 | class MHwrapper : public Genericwrapper |
13 | { | 14 | { |
14 | Q_OBJECT | 15 | Q_OBJECT |
15 | public: | 16 | public: |
16 | MHwrapper(const QString & dir,const QString&name); | 17 | MHwrapper(const QString & dir,const QString&name); |
@@ -36,17 +37,23 @@ public: | |||
36 | virtual encodedString* fetchRawBody(const RecMail&mail); | 37 | virtual encodedString* fetchRawBody(const RecMail&mail); |
37 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); | 38 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); |
38 | virtual int deleteAllMail(const Folder*); | 39 | virtual int deleteAllMail(const Folder*); |
39 | virtual const QString&getType()const; | 40 | virtual const QString&getType()const; |
40 | virtual const QString&getName()const; | 41 | virtual const QString&getName()const; |
41 | 42 | ||
43 | public slots: | ||
44 | /* for deleting maildirs we are using a system call */ | ||
45 | virtual void oprocessStderr(OProcess*, char *buffer, int ); | ||
46 | virtual void processEnded(OProcess *); | ||
42 | protected: | 47 | protected: |
43 | QString buildPath(const QString&p); | 48 | QString buildPath(const QString&p); |
44 | QString MHPath; | 49 | QString MHPath; |
45 | QString MHName; | 50 | QString MHName; |
46 | static const QString wrapperType; | 51 | static const QString wrapperType; |
47 | 52 | ||
48 | void init_storage(); | 53 | void init_storage(); |
49 | void clean_storage(); | 54 | void clean_storage(); |
55 | |||
56 | bool removeMboxfailed; | ||
50 | }; | 57 | }; |
51 | 58 | ||
52 | #endif | 59 | #endif |