summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-08 21:51:32 (UTC)
committer alwin <alwin>2004-01-08 21:51:32 (UTC)
commitfb30e3e116d8616cb05b3765ae1aed5f7e96c74e (patch) (unidiff)
tree393ebb7b913c01697146ac804d980f8b8713f81a
parentb672058ac470a1b9534296fa8bc4b8725ab7913b (diff)
downloadopie-fb30e3e116d8616cb05b3765ae1aed5f7e96c74e.zip
opie-fb30e3e116d8616cb05b3765ae1aed5f7e96c74e.tar.gz
opie-fb30e3e116d8616cb05b3765ae1aed5f7e96c74e.tar.bz2
- last functions re-implemented
- small bugfix TODO: remove twice code within pop3/mh/mbox wrapper
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.cpp27
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
@@ -38,67 +38,67 @@ void MHwrapper::init_storage()
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
49void MHwrapper::clean_storage() 49void 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
58MHwrapper::~MHwrapper() 58MHwrapper::~MHwrapper()
59{ 59{
60 clean_storage(); 60 clean_storage();
61} 61}
62 62
63void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 63void 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
79QList<Folder>* MHwrapper::listFolders() 79QList<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
103void MHwrapper::deleteMail(const RecMail&mail) 103void MHwrapper::deleteMail(const RecMail&mail)
104{ 104{
@@ -207,76 +207,79 @@ 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
237void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 237void 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
253int MHwrapper::deleteAllMail(const Folder*tfolder) 256int 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 }