-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 | |||
@@ -46,51 +46,51 @@ void MHwrapper::init_storage() | |||
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(),""); |
@@ -215,60 +215,63 @@ encodedString* MHwrapper::fetchRawBody(const RecMail&mail) | |||
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; |