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,231 +1,243 @@ | |||
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); |
20 | if (!dir.exists()) { | 22 | if (!dir.exists()) { |
21 | dir.mkdir(MHPath); | 23 | dir.mkdir(MHPath); |
22 | } | 24 | } |
23 | init_storage(); | 25 | init_storage(); |
24 | } | 26 | } |
25 | } | 27 | } |
26 | 28 | ||
27 | void MHwrapper::init_storage() | 29 | void MHwrapper::init_storage() |
28 | { | 30 | { |
29 | int r; | 31 | int r; |
30 | QString pre = MHPath; | 32 | QString pre = MHPath; |
31 | if (!m_storage) { | 33 | if (!m_storage) { |
32 | m_storage = mailstorage_new(NULL); | 34 | m_storage = mailstorage_new(NULL); |
33 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 35 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
34 | if (r != MAIL_NO_ERROR) { | 36 | if (r != MAIL_NO_ERROR) { |
35 | qDebug("error initializing storage"); | 37 | qDebug("error initializing storage"); |
36 | mailstorage_free(m_storage); | 38 | mailstorage_free(m_storage); |
37 | m_storage = 0; | 39 | m_storage = 0; |
38 | return; | 40 | return; |
39 | } | 41 | } |
40 | } | 42 | } |
41 | r = mailstorage_connect(m_storage); | 43 | r = mailstorage_connect(m_storage); |
42 | if (r!=MAIL_NO_ERROR) { | 44 | if (r!=MAIL_NO_ERROR) { |
43 | qDebug("error connecting storage"); | 45 | qDebug("error connecting storage"); |
44 | mailstorage_free(m_storage); | 46 | mailstorage_free(m_storage); |
45 | m_storage = 0; | 47 | m_storage = 0; |
46 | } | 48 | } |
47 | } | 49 | } |
48 | 50 | ||
49 | void MHwrapper::clean_storage() | 51 | void MHwrapper::clean_storage() |
50 | { | 52 | { |
51 | if (m_storage) { | 53 | if (m_storage) { |
52 | mailstorage_disconnect(m_storage); | 54 | mailstorage_disconnect(m_storage); |
53 | mailstorage_free(m_storage); | 55 | mailstorage_free(m_storage); |
54 | m_storage = 0; | 56 | m_storage = 0; |
55 | } | 57 | } |
56 | } | 58 | } |
57 | 59 | ||
58 | MHwrapper::~MHwrapper() | 60 | MHwrapper::~MHwrapper() |
59 | { | 61 | { |
60 | clean_storage(); | 62 | clean_storage(); |
61 | } | 63 | } |
62 | 64 | ||
63 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 65 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
64 | { | 66 | { |
65 | init_storage(); | 67 | init_storage(); |
66 | if (!m_storage) { | 68 | if (!m_storage) { |
67 | return; | 69 | return; |
68 | } | 70 | } |
69 | QString f = buildPath(mailbox); | 71 | QString f = buildPath(mailbox); |
70 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 72 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
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)) { |
95 | QString t = (char*)current->data; | 99 | QString t = (char*)current->data; |
96 | t.replace(0,MHPath.length(),""); | 100 | t.replace(0,MHPath.length(),""); |
97 | folders->append(new MHFolder(t,MHPath)); | 101 | folders->append(new MHFolder(t,MHPath)); |
98 | } | 102 | } |
99 | mail_list_free(flist); | 103 | mail_list_free(flist); |
100 | return folders; | 104 | return folders; |
101 | } | 105 | } |
102 | 106 | ||
103 | void MHwrapper::deleteMail(const RecMail&mail) | 107 | void MHwrapper::deleteMail(const RecMail&mail) |
104 | { | 108 | { |
105 | init_storage(); | 109 | init_storage(); |
106 | if (!m_storage) { | 110 | if (!m_storage) { |
107 | return; | 111 | return; |
108 | } | 112 | } |
109 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 113 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
110 | if (r!=MAIL_NO_ERROR) { | 114 | if (r!=MAIL_NO_ERROR) { |
111 | qDebug("error selecting folder!"); | 115 | qDebug("error selecting folder!"); |
112 | return; | 116 | return; |
113 | } | 117 | } |
114 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); | 118 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); |
115 | if (r != MAIL_NO_ERROR) { | 119 | if (r != MAIL_NO_ERROR) { |
116 | qDebug("error deleting mail"); | 120 | qDebug("error deleting mail"); |
117 | } | 121 | } |
118 | } | 122 | } |
119 | 123 | ||
120 | void MHwrapper::answeredMail(const RecMail&) | 124 | void MHwrapper::answeredMail(const RecMail&) |
121 | { | 125 | { |
122 | } | 126 | } |
123 | 127 | ||
124 | RecBody MHwrapper::fetchBody( const RecMail &mail ) | 128 | RecBody MHwrapper::fetchBody( const RecMail &mail ) |
125 | { | 129 | { |
126 | RecBody body; | 130 | RecBody body; |
127 | init_storage(); | 131 | init_storage(); |
128 | if (!m_storage) { | 132 | if (!m_storage) { |
129 | return body; | 133 | return body; |
130 | } | 134 | } |
131 | mailmessage * msg; | 135 | mailmessage * msg; |
132 | char*data=0; | 136 | char*data=0; |
133 | size_t size; | 137 | size_t size; |
134 | 138 | ||
135 | /* mail should hold the complete path! */ | 139 | /* mail should hold the complete path! */ |
136 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 140 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
137 | if (r != MAIL_NO_ERROR) { | 141 | if (r != MAIL_NO_ERROR) { |
138 | return body; | 142 | return body; |
139 | } | 143 | } |
140 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); | 144 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); |
141 | if (r != MAIL_NO_ERROR) { | 145 | if (r != MAIL_NO_ERROR) { |
142 | qDebug("Error fetching mail %i",mail.getNumber()); | 146 | qDebug("Error fetching mail %i",mail.getNumber()); |
143 | return body; | 147 | return body; |
144 | } | 148 | } |
145 | body = parseMail(msg); | 149 | body = parseMail(msg); |
146 | mailmessage_fetch_result_free(msg,data); | 150 | mailmessage_fetch_result_free(msg,data); |
147 | return body; | 151 | return body; |
148 | } | 152 | } |
149 | 153 | ||
150 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 154 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
151 | { | 155 | { |
152 | qDebug("MH %i von %i",current,maximum); | 156 | qDebug("MH %i von %i",current,maximum); |
153 | } | 157 | } |
154 | 158 | ||
155 | QString MHwrapper::buildPath(const QString&p) | 159 | QString MHwrapper::buildPath(const QString&p) |
156 | { | 160 | { |
157 | QString f=""; | 161 | QString f=""; |
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) { |
196 | qDebug("error selecting folder!"); | 208 | qDebug("error selecting folder!"); |
197 | return; | 209 | return; |
198 | } | 210 | } |
199 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 211 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
200 | if (r!=MAIL_NO_ERROR) { | 212 | if (r!=MAIL_NO_ERROR) { |
201 | qDebug("error storing mail"); | 213 | qDebug("error storing mail"); |
202 | } | 214 | } |
203 | return; | 215 | return; |
204 | } | 216 | } |
205 | 217 | ||
206 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) | 218 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) |
207 | { | 219 | { |
208 | encodedString*result = 0; | 220 | encodedString*result = 0; |
209 | init_storage(); | 221 | init_storage(); |
210 | if (!m_storage) { | 222 | if (!m_storage) { |
211 | return result; | 223 | return result; |
212 | } | 224 | } |
213 | mailmessage * msg = 0; | 225 | mailmessage * msg = 0; |
214 | char*data=0; | 226 | char*data=0; |
215 | size_t size; | 227 | size_t size; |
216 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 228 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
217 | if (r!=MAIL_NO_ERROR) { | 229 | if (r!=MAIL_NO_ERROR) { |
218 | qDebug("error selecting folder!"); | 230 | qDebug("error selecting folder!"); |
219 | return result; | 231 | return result; |
220 | } | 232 | } |
221 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); | 233 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); |
222 | if (r != MAIL_NO_ERROR) { | 234 | if (r != MAIL_NO_ERROR) { |
223 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 235 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
224 | return 0; | 236 | return 0; |
225 | } | 237 | } |
226 | r = mailmessage_fetch(msg,&data,&size); | 238 | r = mailmessage_fetch(msg,&data,&size); |
227 | if (r != MAIL_NO_ERROR) { | 239 | if (r != MAIL_NO_ERROR) { |
228 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 240 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
229 | if (msg) mailmessage_free(msg); | 241 | if (msg) mailmessage_free(msg); |
230 | return 0; | 242 | return 0; |
231 | } | 243 | } |
@@ -250,106 +262,138 @@ void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | |||
250 | qDebug("error deleting mail"); | 262 | qDebug("error deleting mail"); |
251 | break; | 263 | break; |
252 | } | 264 | } |
253 | } | 265 | } |
254 | } | 266 | } |
255 | 267 | ||
256 | int MHwrapper::deleteAllMail(const Folder*tfolder) | 268 | int MHwrapper::deleteAllMail(const Folder*tfolder) |
257 | { | 269 | { |
258 | init_storage(); | 270 | init_storage(); |
259 | if (!m_storage) { | 271 | if (!m_storage) { |
260 | return 0; | 272 | return 0; |
261 | } | 273 | } |
262 | int res = 1; | 274 | int res = 1; |
263 | if (!tfolder) return 0; | 275 | if (!tfolder) return 0; |
264 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 276 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
265 | if (r!=MAIL_NO_ERROR) { | 277 | if (r!=MAIL_NO_ERROR) { |
266 | qDebug("error selecting folder!"); | 278 | qDebug("error selecting folder!"); |
267 | return 0; | 279 | return 0; |
268 | } | 280 | } |
269 | mailmessage_list*l=0; | 281 | mailmessage_list*l=0; |
270 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 282 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
271 | if (r != MAIL_NO_ERROR) { | 283 | if (r != MAIL_NO_ERROR) { |
272 | qDebug("Error message list"); | 284 | qDebug("Error message list"); |
273 | res = 0; | 285 | res = 0; |
274 | } | 286 | } |
275 | unsigned j = 0; | 287 | unsigned j = 0; |
276 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 288 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
277 | mailmessage * msg; | 289 | mailmessage * msg; |
278 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 290 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
279 | j = msg->msg_index; | 291 | j = msg->msg_index; |
280 | r = mailsession_remove_message(m_storage->sto_session,j); | 292 | r = mailsession_remove_message(m_storage->sto_session,j); |
281 | if (r != MAIL_NO_ERROR) { | 293 | if (r != MAIL_NO_ERROR) { |
282 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 294 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
283 | res = 0; | 295 | res = 0; |
284 | break; | 296 | break; |
285 | } | 297 | } |
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); |
320 | if (r != MAIL_NO_ERROR) { | 364 | if (r != MAIL_NO_ERROR) { |
321 | Global::statusMessage(tr("Error retrieving status")); | 365 | Global::statusMessage(tr("Error retrieving status")); |
322 | } | 366 | } |
323 | } | 367 | } |
324 | 368 | ||
325 | const QString&MHwrapper::getType()const | 369 | const QString&MHwrapper::getType()const |
326 | { | 370 | { |
327 | return wrapperType; | 371 | return wrapperType; |
328 | } | 372 | } |
329 | 373 | ||
330 | const QString&MHwrapper::getName()const | 374 | const QString&MHwrapper::getName()const |
331 | { | 375 | { |
332 | return MHName; | 376 | return MHName; |
333 | } | 377 | } |
334 | void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 378 | void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
335 | { | 379 | { |
336 | init_storage(); | 380 | init_storage(); |
337 | if (!m_storage) { | 381 | if (!m_storage) { |
338 | return; | 382 | return; |
339 | } | 383 | } |
340 | if (targetWrapper != this) { | 384 | if (targetWrapper != this) { |
341 | qDebug("Using generic"); | 385 | qDebug("Using generic"); |
342 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 386 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
343 | return; | 387 | return; |
344 | } | 388 | } |
345 | qDebug("Using internal routines for move/copy"); | 389 | qDebug("Using internal routines for move/copy"); |
346 | QString tf = buildPath(targetFolder); | 390 | QString tf = buildPath(targetFolder); |
347 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 391 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
348 | if (r != MAIL_NO_ERROR) { | 392 | if (r != MAIL_NO_ERROR) { |
349 | qDebug("Error selecting source mailbox"); | 393 | qDebug("Error selecting source mailbox"); |
350 | return; | 394 | return; |
351 | } | 395 | } |
352 | if (moveit) { | 396 | if (moveit) { |
353 | r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | 397 | r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); |
354 | } else { | 398 | } else { |
355 | r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | 399 | r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); |
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 @@ | |||
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 | ||
23 | virtual void deleteMail(const RecMail&mail); | 24 | virtual void deleteMail(const RecMail&mail); |
24 | virtual void answeredMail(const RecMail&mail); | 25 | virtual void answeredMail(const RecMail&mail); |
25 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 26 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
26 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 27 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
27 | 28 | ||
28 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); | 29 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); |
29 | virtual int deleteMbox(const Folder*); | 30 | virtual int deleteMbox(const Folder*); |
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 |