author | alwin <alwin> | 2004-01-10 03:20:04 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-10 03:20:04 (UTC) |
commit | 6248e82bf1b077c54e3e2b85801a99fa0f86434d (patch) (unidiff) | |
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,19 +1,21 @@ | |||
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 | { |
14 | if (MHPath.length()>0) { | 16 | if (MHPath.length()>0) { |
15 | if (MHPath[MHPath.length()-1]=='/') { | 17 | if (MHPath[MHPath.length()-1]=='/') { |
16 | MHPath=MHPath.left(MHPath.length()-1); | 18 | MHPath=MHPath.left(MHPath.length()-1); |
17 | } | 19 | } |
18 | qDebug(MHPath); | 20 | qDebug(MHPath); |
19 | QDir dir(MHPath); | 21 | QDir dir(MHPath); |
@@ -71,24 +73,26 @@ void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
71 | if (r!=MAIL_NO_ERROR) { | 73 | if (r!=MAIL_NO_ERROR) { |
72 | qDebug("listMessages: error selecting folder!"); | 74 | qDebug("listMessages: error selecting folder!"); |
73 | return; | 75 | return; |
74 | } | 76 | } |
75 | parseList(target,m_storage->sto_session,f); | 77 | parseList(target,m_storage->sto_session,f); |
76 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 78 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
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; |
89 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 93 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
90 | if (r != MAIL_NO_ERROR || !flist) { | 94 | if (r != MAIL_NO_ERROR || !flist) { |
91 | qDebug("error getting folder list"); | 95 | qDebug("error getting folder list"); |
92 | return folders; | 96 | return folders; |
93 | } | 97 | } |
94 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 98 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
@@ -158,38 +162,46 @@ QString MHwrapper::buildPath(const QString&p) | |||
158 | if (p.length()==0||p=="/") | 162 | if (p.length()==0||p=="/") |
159 | return MHPath; | 163 | return MHPath; |
160 | if (!p.startsWith(MHPath)) { | 164 | if (!p.startsWith(MHPath)) { |
161 | f+=MHPath; | 165 | f+=MHPath; |
162 | } | 166 | } |
163 | if (!p.startsWith("/")) { | 167 | if (!p.startsWith("/")) { |
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(); |
190 | if (!m_storage) { | 202 | if (!m_storage) { |
191 | return; | 203 | return; |
192 | } | 204 | } |
193 | QString f = buildPath(Folder); | 205 | QString f = buildPath(Folder); |
194 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 206 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
195 | if (r!=MAIL_NO_ERROR) { | 207 | if (r!=MAIL_NO_ERROR) { |
@@ -286,34 +298,66 @@ int MHwrapper::deleteAllMail(const Folder*tfolder) | |||
286 | } | 298 | } |
287 | if (l) mailmessage_list_free(l); | 299 | if (l) mailmessage_list_free(l); |
288 | return res; | 300 | return res; |
289 | } | 301 | } |
290 | 302 | ||
291 | int MHwrapper::deleteMbox(const Folder*tfolder) | 303 | 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 | } |
314 | target_stat.message_count = 0; | 358 | target_stat.message_count = 0; |
315 | target_stat.message_unseen = 0; | 359 | target_stat.message_unseen = 0; |
316 | target_stat.message_recent = 0; | 360 | target_stat.message_recent = 0; |
317 | QString f = buildPath(mailbox); | 361 | QString f = buildPath(mailbox); |
318 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, | 362 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, |
319 | &target_stat.message_recent,&target_stat.message_unseen); | 363 | &target_stat.message_recent,&target_stat.message_unseen); |
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,22 +1,23 @@ | |||
1 | #ifndef __MH_WRAPPER_H | 1 | #ifndef __MH_WRAPPER_H |
2 | #define __MH_WRAPPER_H | 2 | #define __MH_WRAPPER_H |
3 | 3 | ||
4 | #include "genericwrapper.h" | 4 | #include "genericwrapper.h" |
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); |
17 | virtual ~MHwrapper(); | 18 | virtual ~MHwrapper(); |
18 | 19 | ||
19 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
20 | virtual QList<Folder>* listFolders(); | 21 | virtual QList<Folder>* listFolders(); |
21 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
22 | 23 | ||
@@ -30,23 +31,29 @@ public: | |||
30 | 31 | ||
31 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 32 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
32 | 33 | ||
33 | virtual RecBody fetchBody( const RecMail &mail ); | 34 | virtual RecBody fetchBody( const RecMail &mail ); |
34 | static void mbox_progress( size_t current, size_t maximum ); | 35 | static void mbox_progress( size_t current, size_t maximum ); |
35 | 36 | ||
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 |