-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index 85f9cf0..5adba55 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp | |||
@@ -6,131 +6,131 @@ | |||
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <qpe/global.h> | 7 | #include <qpe/global.h> |
8 | 8 | ||
9 | const QString MHwrapper::wrapperType="MH"; | 9 | const QString MHwrapper::wrapperType="MH"; |
10 | 10 | ||
11 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 11 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
12 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 12 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
13 | { | 13 | { |
14 | if (MHPath.length()>0) { | 14 | if (MHPath.length()>0) { |
15 | if (MHPath[MHPath.length()-1]=='/') { | 15 | if (MHPath[MHPath.length()-1]=='/') { |
16 | MHPath=MHPath.left(MHPath.length()-1); | 16 | MHPath=MHPath.left(MHPath.length()-1); |
17 | } | 17 | } |
18 | qDebug(MHPath); | 18 | qDebug(MHPath); |
19 | QDir dir(MHPath); | 19 | QDir dir(MHPath); |
20 | if (!dir.exists()) { | 20 | if (!dir.exists()) { |
21 | dir.mkdir(MHPath); | 21 | dir.mkdir(MHPath); |
22 | } | 22 | } |
23 | init_storage(); | 23 | init_storage(); |
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | void MHwrapper::init_storage() | 27 | void MHwrapper::init_storage() |
28 | { | 28 | { |
29 | int r; | 29 | int r; |
30 | QString pre = MHPath; | 30 | QString pre = MHPath; |
31 | if (!m_storage) { | 31 | if (!m_storage) { |
32 | m_storage = mailstorage_new(NULL); | 32 | m_storage = mailstorage_new(NULL); |
33 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 33 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
34 | if (r != MAIL_NO_ERROR) { | 34 | if (r != MAIL_NO_ERROR) { |
35 | qDebug("error initializing storage"); | 35 | qDebug("error initializing storage"); |
36 | mailstorage_free(m_storage); | 36 | mailstorage_free(m_storage); |
37 | m_storage = 0; | 37 | m_storage = 0; |
38 | return; | 38 | return; |
39 | } | 39 | } |
40 | } | 40 | } |
41 | r = mailstorage_connect(m_storage); | 41 | r = mailstorage_connect(m_storage); |
42 | if (r!=MAIL_NO_ERROR) { | 42 | if (r!=MAIL_NO_ERROR) { |
43 | qDebug("error connecting storage"); | 43 | qDebug("error connecting storage"); |
44 | mailstorage_free(m_storage); | 44 | mailstorage_free(m_storage); |
45 | m_storage = 0; | 45 | m_storage = 0; |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | void MHwrapper::clean_storage() | 49 | void MHwrapper::clean_storage() |
50 | { | 50 | { |
51 | if (m_storage) { | 51 | if (m_storage) { |
52 | mailstorage_disconnect(m_storage); | 52 | mailstorage_disconnect(m_storage); |
53 | mailstorage_free(m_storage); | 53 | mailstorage_free(m_storage); |
54 | m_storage = 0; | 54 | m_storage = 0; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | MHwrapper::~MHwrapper() | 58 | MHwrapper::~MHwrapper() |
59 | { | 59 | { |
60 | clean_storage(); | 60 | clean_storage(); |
61 | } | 61 | } |
62 | 62 | ||
63 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 63 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
64 | { | 64 | { |
65 | init_storage(); | 65 | init_storage(); |
66 | if (!m_storage) { | 66 | if (!m_storage) { |
67 | return; | 67 | return; |
68 | } | 68 | } |
69 | QString f = buildPath(mailbox); | 69 | QString f = buildPath(mailbox); |
70 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mailbox.latin1()); | 70 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
71 | if (r!=MAIL_NO_ERROR) { | 71 | if (r!=MAIL_NO_ERROR) { |
72 | qDebug("error selecting folder!"); | 72 | qDebug("listMessages: error selecting folder!"); |
73 | return; | 73 | return; |
74 | } | 74 | } |
75 | parseList(target,m_storage->sto_session,f); | 75 | parseList(target,m_storage->sto_session,f); |
76 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 76 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
77 | } | 77 | } |
78 | 78 | ||
79 | QList<Folder>* MHwrapper::listFolders() | 79 | QList<Folder>* MHwrapper::listFolders() |
80 | { | 80 | { |
81 | QList<Folder> * folders = new QList<Folder>(); | 81 | QList<Folder> * folders = new QList<Folder>(); |
82 | folders->setAutoDelete( false ); | 82 | folders->setAutoDelete( false ); |
83 | init_storage(); | 83 | init_storage(); |
84 | if (!m_storage) { | 84 | if (!m_storage) { |
85 | return folders; | 85 | return folders; |
86 | } | 86 | } |
87 | mail_list*flist = 0; | 87 | mail_list*flist = 0; |
88 | clistcell*current=0; | 88 | clistcell*current=0; |
89 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 89 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
90 | if (r != MAIL_NO_ERROR || !flist) { | 90 | if (r != MAIL_NO_ERROR || !flist) { |
91 | qDebug("error getting folder list"); | 91 | qDebug("error getting folder list"); |
92 | return folders; | 92 | return folders; |
93 | } | 93 | } |
94 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 94 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
95 | QString t = (char*)current->data; | 95 | QString t = (char*)current->data; |
96 | t.replace(0,MHPath.length(),""); | 96 | t.replace(0,MHPath.length(),""); |
97 | folders->append(new MHFolder(t,MHPath)); | 97 | folders->append(new MHFolder(t,MHPath)); |
98 | } | 98 | } |
99 | mail_list_free(flist); | 99 | mail_list_free(flist); |
100 | return folders; | 100 | return folders; |
101 | } | 101 | } |
102 | 102 | ||
103 | void MHwrapper::deleteMail(const RecMail&mail) | 103 | void MHwrapper::deleteMail(const RecMail&mail) |
104 | { | 104 | { |
105 | init_storage(); | 105 | init_storage(); |
106 | if (!m_storage) { | 106 | if (!m_storage) { |
107 | return; | 107 | return; |
108 | } | 108 | } |
109 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 109 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
110 | if (r!=MAIL_NO_ERROR) { | 110 | if (r!=MAIL_NO_ERROR) { |
111 | qDebug("error selecting folder!"); | 111 | qDebug("error selecting folder!"); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); | 114 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); |
115 | if (r != MAIL_NO_ERROR) { | 115 | if (r != MAIL_NO_ERROR) { |
116 | qDebug("error deleting mail"); | 116 | qDebug("error deleting mail"); |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | void MHwrapper::answeredMail(const RecMail&) | 120 | void MHwrapper::answeredMail(const RecMail&) |
121 | { | 121 | { |
122 | } | 122 | } |
123 | 123 | ||
124 | RecBody MHwrapper::fetchBody( const RecMail &mail ) | 124 | RecBody MHwrapper::fetchBody( const RecMail &mail ) |
125 | { | 125 | { |
126 | RecBody body; | 126 | RecBody body; |
127 | init_storage(); | 127 | init_storage(); |
128 | if (!m_storage) { | 128 | if (!m_storage) { |
129 | return body; | 129 | return body; |
130 | } | 130 | } |
131 | mailmessage * msg; | 131 | mailmessage * msg; |
132 | char*data=0; | 132 | char*data=0; |
133 | size_t size; | 133 | size_t size; |
134 | 134 | ||
135 | /* mail should hold the complete path! */ | 135 | /* mail should hold the complete path! */ |
136 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 136 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
@@ -175,140 +175,143 @@ int MHwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool | |||
175 | } | 175 | } |
176 | QString f = buildPath(folder); | 176 | QString f = buildPath(folder); |
177 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 177 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
178 | if (r != MAIL_NO_ERROR) { | 178 | if (r != MAIL_NO_ERROR) { |
179 | qDebug("error creating folder"); | 179 | qDebug("error creating folder"); |
180 | return 0; | 180 | return 0; |
181 | } | 181 | } |
182 | qDebug("Folder created"); | 182 | qDebug("Folder created"); |
183 | mailstorage_disconnect(m_storage); | 183 | mailstorage_disconnect(m_storage); |
184 | return 1; | 184 | return 1; |
185 | } | 185 | } |
186 | 186 | ||
187 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 187 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
188 | { | 188 | { |
189 | init_storage(); | 189 | init_storage(); |
190 | if (!m_storage) { | 190 | if (!m_storage) { |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | QString f = buildPath(Folder); | 193 | QString f = buildPath(Folder); |
194 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 194 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
195 | if (r!=MAIL_NO_ERROR) { | 195 | if (r!=MAIL_NO_ERROR) { |
196 | qDebug("error selecting folder!"); | 196 | qDebug("error selecting folder!"); |
197 | return; | 197 | return; |
198 | } | 198 | } |
199 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 199 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
200 | if (r!=MAIL_NO_ERROR) { | 200 | if (r!=MAIL_NO_ERROR) { |
201 | qDebug("error storing mail"); | 201 | qDebug("error storing mail"); |
202 | } | 202 | } |
203 | return; | 203 | return; |
204 | } | 204 | } |
205 | 205 | ||
206 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) | 206 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) |
207 | { | 207 | { |
208 | encodedString*result = 0; | 208 | encodedString*result = 0; |
209 | init_storage(); | 209 | init_storage(); |
210 | if (!m_storage) { | 210 | if (!m_storage) { |
211 | return result; | 211 | return result; |
212 | } | 212 | } |
213 | mailmessage * msg = 0; | 213 | mailmessage * msg = 0; |
214 | char*data=0; | 214 | char*data=0; |
215 | size_t size; | 215 | size_t size; |
216 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 216 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
217 | if (r!=MAIL_NO_ERROR) { | 217 | if (r!=MAIL_NO_ERROR) { |
218 | qDebug("error selecting folder!"); | 218 | qDebug("error selecting folder!"); |
219 | return result; | 219 | return result; |
220 | } | 220 | } |
221 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); | 221 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); |
222 | if (r != MAIL_NO_ERROR) { | 222 | if (r != MAIL_NO_ERROR) { |
223 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 223 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
224 | return 0; | 224 | return 0; |
225 | } | 225 | } |
226 | r = mailmessage_fetch(msg,&data,&size); | 226 | r = mailmessage_fetch(msg,&data,&size); |
227 | if (r != MAIL_NO_ERROR) { | 227 | if (r != MAIL_NO_ERROR) { |
228 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 228 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
229 | if (msg) mailmessage_free(msg); | 229 | if (msg) mailmessage_free(msg); |
230 | return 0; | 230 | return 0; |
231 | } | 231 | } |
232 | result = new encodedString(data,size); | 232 | result = new encodedString(data,size); |
233 | if (msg) mailmessage_free(msg); | 233 | if (msg) mailmessage_free(msg); |
234 | return result; | 234 | return result; |
235 | } | 235 | } |
236 | 236 | ||
237 | void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 237 | void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
238 | { | 238 | { |
239 | #if 0 | 239 | QString f = buildPath(mailbox); |
240 | QString p = MHPath+"/"; | 240 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
241 | p+=mailbox; | 241 | if (r!=MAIL_NO_ERROR) { |
242 | mailmbox_folder*f = 0; | 242 | qDebug("deleteMails: error selecting folder!"); |
243 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
244 | if (r != MAIL_NO_ERROR) { | ||
245 | qDebug("Error init folder"); | ||
246 | return; | 243 | return; |
247 | } | 244 | } |
248 | deleteMails(f,target); | 245 | RecMail*c = 0; |
249 | mailmbox_done(f); | 246 | for (unsigned int i=0; i < target.count();++i) { |
250 | #endif | 247 | c = target.at(i); |
248 | r = mailsession_remove_message(m_storage->sto_session,c->getNumber()); | ||
249 | if (r != MAIL_NO_ERROR) { | ||
250 | qDebug("error deleting mail"); | ||
251 | break; | ||
252 | } | ||
253 | } | ||
251 | } | 254 | } |
252 | 255 | ||
253 | int MHwrapper::deleteAllMail(const Folder*tfolder) | 256 | int MHwrapper::deleteAllMail(const Folder*tfolder) |
254 | { | 257 | { |
255 | init_storage(); | 258 | init_storage(); |
256 | if (!m_storage) { | 259 | if (!m_storage) { |
257 | return 0; | 260 | return 0; |
258 | } | 261 | } |
259 | int res = 1; | 262 | int res = 1; |
260 | if (!tfolder) return 0; | 263 | if (!tfolder) return 0; |
261 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 264 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
262 | if (r!=MAIL_NO_ERROR) { | 265 | if (r!=MAIL_NO_ERROR) { |
263 | qDebug("error selecting folder!"); | 266 | qDebug("error selecting folder!"); |
264 | return 0; | 267 | return 0; |
265 | } | 268 | } |
266 | mailmessage_list*l=0; | 269 | mailmessage_list*l=0; |
267 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 270 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
268 | if (r != MAIL_NO_ERROR) { | 271 | if (r != MAIL_NO_ERROR) { |
269 | qDebug("Error message list"); | 272 | qDebug("Error message list"); |
270 | res = 0; | 273 | res = 0; |
271 | } | 274 | } |
272 | unsigned j = 0; | 275 | unsigned j = 0; |
273 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 276 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
274 | mailmessage * msg; | 277 | mailmessage * msg; |
275 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 278 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
276 | j = msg->msg_index; | 279 | j = msg->msg_index; |
277 | r = mailsession_remove_message(m_storage->sto_session,j); | 280 | r = mailsession_remove_message(m_storage->sto_session,j); |
278 | if (r != MAIL_NO_ERROR) { | 281 | if (r != MAIL_NO_ERROR) { |
279 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 282 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
280 | res = 0; | 283 | res = 0; |
281 | break; | 284 | break; |
282 | } | 285 | } |
283 | } | 286 | } |
284 | if (l) mailmessage_list_free(l); | 287 | if (l) mailmessage_list_free(l); |
285 | return res; | 288 | return res; |
286 | } | 289 | } |
287 | 290 | ||
288 | int MHwrapper::deleteMbox(const Folder*tfolder) | 291 | int MHwrapper::deleteMbox(const Folder*tfolder) |
289 | { | 292 | { |
290 | init_storage(); | 293 | init_storage(); |
291 | if (!m_storage) { | 294 | if (!m_storage) { |
292 | return 0; | 295 | return 0; |
293 | } | 296 | } |
294 | if (!tfolder) return 0; | 297 | if (!tfolder) return 0; |
295 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 298 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
296 | if (r != MAIL_NO_ERROR) { | 299 | if (r != MAIL_NO_ERROR) { |
297 | qDebug("error deleting mail box"); | 300 | qDebug("error deleting mail box"); |
298 | return 0; | 301 | return 0; |
299 | } | 302 | } |
300 | qDebug("mail box deleted"); | 303 | qDebug("mail box deleted"); |
301 | mailstorage_disconnect(m_storage); | 304 | mailstorage_disconnect(m_storage); |
302 | return 1; | 305 | return 1; |
303 | } | 306 | } |
304 | 307 | ||
305 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 308 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
306 | { | 309 | { |
307 | init_storage(); | 310 | init_storage(); |
308 | if (!m_storage) { | 311 | if (!m_storage) { |
309 | return; | 312 | return; |
310 | } | 313 | } |
311 | target_stat.message_count = 0; | 314 | target_stat.message_count = 0; |
312 | target_stat.message_unseen = 0; | 315 | target_stat.message_unseen = 0; |
313 | target_stat.message_recent = 0; | 316 | target_stat.message_recent = 0; |
314 | QString f = buildPath(mailbox); | 317 | QString f = buildPath(mailbox); |