-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.h | 1 |
4 files changed, 2 insertions, 8 deletions
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 11ffd92..abe4bb6 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,337 +1,335 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.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 <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <qpe/global.h> | 7 | #include <qpe/global.h> |
8 | 8 | ||
9 | const MAILLIB::ATYPE MBOXwrapper::wrapperType=MAILLIB::MBOX; | ||
10 | |||
11 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) | 9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) |
12 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) | 10 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) |
13 | { | 11 | { |
14 | QDir dir(MBOXPath); | 12 | QDir dir(MBOXPath); |
15 | if (!dir.exists()) { | 13 | if (!dir.exists()) { |
16 | dir.mkdir(MBOXPath); | 14 | dir.mkdir(MBOXPath); |
17 | } | 15 | } |
18 | } | 16 | } |
19 | 17 | ||
20 | MBOXwrapper::~MBOXwrapper() | 18 | MBOXwrapper::~MBOXwrapper() |
21 | { | 19 | { |
22 | } | 20 | } |
23 | 21 | ||
24 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
25 | { | 23 | { |
26 | mailstorage*storage = mailstorage_new(NULL); | 24 | mailstorage*storage = mailstorage_new(NULL); |
27 | QString p = MBOXPath+"/"; | 25 | QString p = MBOXPath+"/"; |
28 | p+=mailbox; | 26 | p+=mailbox; |
29 | 27 | ||
30 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
31 | mailfolder*folder; | 29 | mailfolder*folder; |
32 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
33 | r = mailfolder_connect(folder); | 31 | r = mailfolder_connect(folder); |
34 | if (r != MAIL_NO_ERROR) { | 32 | if (r != MAIL_NO_ERROR) { |
35 | qDebug("Error initializing mbox"); | 33 | qDebug("Error initializing mbox"); |
36 | mailfolder_free(folder); | 34 | mailfolder_free(folder); |
37 | mailstorage_free(storage); | 35 | mailstorage_free(storage); |
38 | return; | 36 | return; |
39 | } | 37 | } |
40 | 38 | ||
41 | parseList(target,folder->fld_session,mailbox); | 39 | parseList(target,folder->fld_session,mailbox); |
42 | 40 | ||
43 | mailfolder_disconnect(folder); | 41 | mailfolder_disconnect(folder); |
44 | mailfolder_free(folder); | 42 | mailfolder_free(folder); |
45 | mailstorage_free(storage); | 43 | mailstorage_free(storage); |
46 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
47 | } | 45 | } |
48 | 46 | ||
49 | QList<Folder>* MBOXwrapper::listFolders() | 47 | QList<Folder>* MBOXwrapper::listFolders() |
50 | { | 48 | { |
51 | QList<Folder> * folders = new QList<Folder>(); | 49 | QList<Folder> * folders = new QList<Folder>(); |
52 | folders->setAutoDelete( false ); | 50 | folders->setAutoDelete( false ); |
53 | QDir dir(MBOXPath); | 51 | QDir dir(MBOXPath); |
54 | if (!dir.exists()) return folders; | 52 | if (!dir.exists()) return folders; |
55 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
56 | QStringList entries = dir.entryList(); | 54 | QStringList entries = dir.entryList(); |
57 | QStringList::ConstIterator it = entries.begin(); | 55 | QStringList::ConstIterator it = entries.begin(); |
58 | for (;it!=entries.end();++it) { | 56 | for (;it!=entries.end();++it) { |
59 | Folder*inb=new Folder(*it,"/"); | 57 | Folder*inb=new Folder(*it,"/"); |
60 | folders->append(inb); | 58 | folders->append(inb); |
61 | } | 59 | } |
62 | return folders; | 60 | return folders; |
63 | } | 61 | } |
64 | 62 | ||
65 | void MBOXwrapper::deleteMail(const RecMail&mail) | 63 | void MBOXwrapper::deleteMail(const RecMail&mail) |
66 | { | 64 | { |
67 | mailstorage*storage = mailstorage_new(NULL); | 65 | mailstorage*storage = mailstorage_new(NULL); |
68 | QString p = MBOXPath+"/"; | 66 | QString p = MBOXPath+"/"; |
69 | p+=mail.getMbox(); | 67 | p+=mail.getMbox(); |
70 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
71 | mailfolder*folder; | 69 | mailfolder*folder; |
72 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
73 | r = mailfolder_connect(folder); | 71 | r = mailfolder_connect(folder); |
74 | if (r != MAIL_NO_ERROR) { | 72 | if (r != MAIL_NO_ERROR) { |
75 | qDebug("Error initializing mbox"); | 73 | qDebug("Error initializing mbox"); |
76 | mailfolder_free(folder); | 74 | mailfolder_free(folder); |
77 | mailstorage_free(storage); | 75 | mailstorage_free(storage); |
78 | return; | 76 | return; |
79 | } | 77 | } |
80 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 78 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
81 | if (r != MAIL_NO_ERROR) { | 79 | if (r != MAIL_NO_ERROR) { |
82 | qDebug("error deleting mail"); | 80 | qDebug("error deleting mail"); |
83 | } | 81 | } |
84 | mailfolder_free(folder); | 82 | mailfolder_free(folder); |
85 | mailstorage_free(storage); | 83 | mailstorage_free(storage); |
86 | } | 84 | } |
87 | 85 | ||
88 | void MBOXwrapper::answeredMail(const RecMail&) | 86 | void MBOXwrapper::answeredMail(const RecMail&) |
89 | { | 87 | { |
90 | } | 88 | } |
91 | 89 | ||
92 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 90 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
93 | { | 91 | { |
94 | RecBody body; | 92 | RecBody body; |
95 | mailstorage*storage = mailstorage_new(NULL); | 93 | mailstorage*storage = mailstorage_new(NULL); |
96 | QString p = MBOXPath+"/"; | 94 | QString p = MBOXPath+"/"; |
97 | p+=mail.getMbox(); | 95 | p+=mail.getMbox(); |
98 | mailmessage * msg; | 96 | mailmessage * msg; |
99 | char*data=0; | 97 | char*data=0; |
100 | size_t size; | 98 | size_t size; |
101 | 99 | ||
102 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
103 | mailfolder*folder; | 101 | mailfolder*folder; |
104 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
105 | r = mailfolder_connect(folder); | 103 | r = mailfolder_connect(folder); |
106 | if (r != MAIL_NO_ERROR) { | 104 | if (r != MAIL_NO_ERROR) { |
107 | qDebug("Error initializing mbox"); | 105 | qDebug("Error initializing mbox"); |
108 | mailfolder_free(folder); | 106 | mailfolder_free(folder); |
109 | mailstorage_free(storage); | 107 | mailstorage_free(storage); |
110 | return body; | 108 | return body; |
111 | } | 109 | } |
112 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 110 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
113 | if (r != MAIL_NO_ERROR) { | 111 | if (r != MAIL_NO_ERROR) { |
114 | qDebug("Error fetching mail %i",mail.getNumber()); | 112 | qDebug("Error fetching mail %i",mail.getNumber()); |
115 | mailfolder_free(folder); | 113 | mailfolder_free(folder); |
116 | mailstorage_free(storage); | 114 | mailstorage_free(storage); |
117 | return body; | 115 | return body; |
118 | } | 116 | } |
119 | r = mailmessage_fetch(msg,&data,&size); | 117 | r = mailmessage_fetch(msg,&data,&size); |
120 | if (r != MAIL_NO_ERROR) { | 118 | if (r != MAIL_NO_ERROR) { |
121 | qDebug("Error fetching mail %i",mail.getNumber()); | 119 | qDebug("Error fetching mail %i",mail.getNumber()); |
122 | mailfolder_free(folder); | 120 | mailfolder_free(folder); |
123 | mailstorage_free(storage); | 121 | mailstorage_free(storage); |
124 | mailmessage_free(msg); | 122 | mailmessage_free(msg); |
125 | return body; | 123 | return body; |
126 | } | 124 | } |
127 | body = parseMail(msg); | 125 | body = parseMail(msg); |
128 | mailmessage_fetch_result_free(msg,data); | 126 | mailmessage_fetch_result_free(msg,data); |
129 | mailfolder_free(folder); | 127 | mailfolder_free(folder); |
130 | mailstorage_free(storage); | 128 | mailstorage_free(storage); |
131 | 129 | ||
132 | return body; | 130 | return body; |
133 | } | 131 | } |
134 | 132 | ||
135 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
136 | { | 134 | { |
137 | qDebug("MBOX %i von %i",current,maximum); | 135 | qDebug("MBOX %i von %i",current,maximum); |
138 | } | 136 | } |
139 | 137 | ||
140 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) | 138 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) |
141 | { | 139 | { |
142 | QString p = MBOXPath+"/"; | 140 | QString p = MBOXPath+"/"; |
143 | p+=folder; | 141 | p+=folder; |
144 | QFileInfo fi(p); | 142 | QFileInfo fi(p); |
145 | if (fi.exists()) { | 143 | if (fi.exists()) { |
146 | Global::statusMessage(tr("Mailbox exists.")); | 144 | Global::statusMessage(tr("Mailbox exists.")); |
147 | return 0; | 145 | return 0; |
148 | } | 146 | } |
149 | mailmbox_folder*f = 0; | 147 | mailmbox_folder*f = 0; |
150 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | 148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { |
151 | Global::statusMessage(tr("Error init folder")); | 149 | Global::statusMessage(tr("Error init folder")); |
152 | return 0; | 150 | return 0; |
153 | } | 151 | } |
154 | if (f) mailmbox_done(f); | 152 | if (f) mailmbox_done(f); |
155 | return 1; | 153 | return 1; |
156 | } | 154 | } |
157 | 155 | ||
158 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
159 | { | 157 | { |
160 | QString p = MBOXPath+"/"; | 158 | QString p = MBOXPath+"/"; |
161 | p+=folder; | 159 | p+=folder; |
162 | mailmbox_folder*f = 0; | 160 | mailmbox_folder*f = 0; |
163 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
164 | if (r != MAIL_NO_ERROR) { | 162 | if (r != MAIL_NO_ERROR) { |
165 | Global::statusMessage(tr("Error init folder")); | 163 | Global::statusMessage(tr("Error init folder")); |
166 | return; | 164 | return; |
167 | } | 165 | } |
168 | r = mailmbox_append_message(f,msg,length); | 166 | r = mailmbox_append_message(f,msg,length); |
169 | if (r != MAIL_NO_ERROR) { | 167 | if (r != MAIL_NO_ERROR) { |
170 | Global::statusMessage(tr("Error writing to message folder")); | 168 | Global::statusMessage(tr("Error writing to message folder")); |
171 | } | 169 | } |
172 | mailmbox_done(f); | 170 | mailmbox_done(f); |
173 | } | 171 | } |
174 | 172 | ||
175 | encodedString* MBOXwrapper::fetchRawBody(const RecMail&mail) | 173 | encodedString* MBOXwrapper::fetchRawBody(const RecMail&mail) |
176 | { | 174 | { |
177 | RecBody body; | 175 | RecBody body; |
178 | mailstorage*storage = mailstorage_new(NULL); | 176 | mailstorage*storage = mailstorage_new(NULL); |
179 | QString p = MBOXPath+"/"; | 177 | QString p = MBOXPath+"/"; |
180 | p+=mail.getMbox(); | 178 | p+=mail.getMbox(); |
181 | mailmessage * msg; | 179 | mailmessage * msg; |
182 | char*data=0; | 180 | char*data=0; |
183 | size_t size; | 181 | size_t size; |
184 | 182 | ||
185 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
186 | mailfolder*folder; | 184 | mailfolder*folder; |
187 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
188 | r = mailfolder_connect(folder); | 186 | r = mailfolder_connect(folder); |
189 | if (r != MAIL_NO_ERROR) { | 187 | if (r != MAIL_NO_ERROR) { |
190 | Global::statusMessage(tr("Error initializing mbox")); | 188 | Global::statusMessage(tr("Error initializing mbox")); |
191 | mailfolder_free(folder); | 189 | mailfolder_free(folder); |
192 | mailstorage_free(storage); | 190 | mailstorage_free(storage); |
193 | return 0; | 191 | return 0; |
194 | } | 192 | } |
195 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 193 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
196 | if (r != MAIL_NO_ERROR) { | 194 | if (r != MAIL_NO_ERROR) { |
197 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
198 | mailfolder_free(folder); | 196 | mailfolder_free(folder); |
199 | mailstorage_free(storage); | 197 | mailstorage_free(storage); |
200 | return 0; | 198 | return 0; |
201 | } | 199 | } |
202 | r = mailmessage_fetch(msg,&data,&size); | 200 | r = mailmessage_fetch(msg,&data,&size); |
203 | if (r != MAIL_NO_ERROR) { | 201 | if (r != MAIL_NO_ERROR) { |
204 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
205 | mailfolder_free(folder); | 203 | mailfolder_free(folder); |
206 | mailstorage_free(storage); | 204 | mailstorage_free(storage); |
207 | mailmessage_free(msg); | 205 | mailmessage_free(msg); |
208 | return 0; | 206 | return 0; |
209 | } | 207 | } |
210 | encodedString*result = new encodedString(data,size); | 208 | encodedString*result = new encodedString(data,size); |
211 | 209 | ||
212 | mailfolder_free(folder); | 210 | mailfolder_free(folder); |
213 | mailstorage_free(storage); | 211 | mailstorage_free(storage); |
214 | mailmessage_free(msg); | 212 | mailmessage_free(msg); |
215 | return result; | 213 | return result; |
216 | } | 214 | } |
217 | 215 | ||
218 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 216 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
219 | { | 217 | { |
220 | QString p = MBOXPath+"/"; | 218 | QString p = MBOXPath+"/"; |
221 | p+=mailbox; | 219 | p+=mailbox; |
222 | mailmbox_folder*f = 0; | 220 | mailmbox_folder*f = 0; |
223 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 221 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
224 | if (r != MAIL_NO_ERROR) { | 222 | if (r != MAIL_NO_ERROR) { |
225 | qDebug("Error init folder"); | 223 | qDebug("Error init folder"); |
226 | return; | 224 | return; |
227 | } | 225 | } |
228 | deleteMails(f,target); | 226 | deleteMails(f,target); |
229 | mailmbox_done(f); | 227 | mailmbox_done(f); |
230 | } | 228 | } |
231 | 229 | ||
232 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) | 230 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) |
233 | { | 231 | { |
234 | if (!f) return; | 232 | if (!f) return; |
235 | int r; | 233 | int r; |
236 | for (unsigned int i=0; i < target.count();++i) { | 234 | for (unsigned int i=0; i < target.count();++i) { |
237 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | 235 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); |
238 | if (r!=MAILMBOX_NO_ERROR) { | 236 | if (r!=MAILMBOX_NO_ERROR) { |
239 | qDebug("error delete mail"); | 237 | qDebug("error delete mail"); |
240 | } | 238 | } |
241 | } | 239 | } |
242 | r = mailmbox_expunge(f); | 240 | r = mailmbox_expunge(f); |
243 | if (r != MAILMBOX_NO_ERROR) { | 241 | if (r != MAILMBOX_NO_ERROR) { |
244 | qDebug("error expunge mailbox"); | 242 | qDebug("error expunge mailbox"); |
245 | } | 243 | } |
246 | } | 244 | } |
247 | 245 | ||
248 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) | 246 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) |
249 | { | 247 | { |
250 | if (!tfolder) return 0; | 248 | if (!tfolder) return 0; |
251 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 249 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
252 | int res = 1; | 250 | int res = 1; |
253 | 251 | ||
254 | mailfolder*folder = 0; | 252 | mailfolder*folder = 0; |
255 | mailmessage_list*l=0; | 253 | mailmessage_list*l=0; |
256 | mailstorage*storage = mailstorage_new(NULL); | 254 | mailstorage*storage = mailstorage_new(NULL); |
257 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 255 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
258 | if (r != MAIL_NO_ERROR) { | 256 | if (r != MAIL_NO_ERROR) { |
259 | Global::statusMessage(tr("Error initializing mbox")); | 257 | Global::statusMessage(tr("Error initializing mbox")); |
260 | res = 0; | 258 | res = 0; |
261 | } | 259 | } |
262 | if (res) { | 260 | if (res) { |
263 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 261 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
264 | r = mailfolder_connect(folder); | 262 | r = mailfolder_connect(folder); |
265 | if (r != MAIL_NO_ERROR) { | 263 | if (r != MAIL_NO_ERROR) { |
266 | Global::statusMessage(tr("Error initializing mbox")); | 264 | Global::statusMessage(tr("Error initializing mbox")); |
267 | res = 0; | 265 | res = 0; |
268 | } | 266 | } |
269 | } | 267 | } |
270 | if (res) { | 268 | if (res) { |
271 | r = mailsession_get_messages_list(folder->fld_session,&l); | 269 | r = mailsession_get_messages_list(folder->fld_session,&l); |
272 | if (r != MAIL_NO_ERROR) { | 270 | if (r != MAIL_NO_ERROR) { |
273 | qDebug("Error message list"); | 271 | qDebug("Error message list"); |
274 | res=0; | 272 | res=0; |
275 | } | 273 | } |
276 | } | 274 | } |
277 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 275 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
278 | r = mailsession_remove_message(folder->fld_session,i+1); | 276 | r = mailsession_remove_message(folder->fld_session,i+1); |
279 | if (r != MAIL_NO_ERROR) { | 277 | if (r != MAIL_NO_ERROR) { |
280 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 278 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
281 | res = 0; | 279 | res = 0; |
282 | break; | 280 | break; |
283 | } | 281 | } |
284 | } | 282 | } |
285 | if (l) mailmessage_list_free(l); | 283 | if (l) mailmessage_list_free(l); |
286 | if (folder) mailfolder_free(folder); | 284 | if (folder) mailfolder_free(folder); |
287 | if (storage) mailstorage_free(storage); | 285 | if (storage) mailstorage_free(storage); |
288 | return res; | 286 | return res; |
289 | } | 287 | } |
290 | 288 | ||
291 | int MBOXwrapper::deleteMbox(const Folder*tfolder) | 289 | int MBOXwrapper::deleteMbox(const Folder*tfolder) |
292 | { | 290 | { |
293 | if (!tfolder) return 0; | 291 | if (!tfolder) return 0; |
294 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 292 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
295 | QFile fi(p); | 293 | QFile fi(p); |
296 | if (!fi.exists()) { | 294 | if (!fi.exists()) { |
297 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 295 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
298 | return 0; | 296 | return 0; |
299 | } | 297 | } |
300 | if (!fi.remove()) { | 298 | if (!fi.remove()) { |
301 | Global::statusMessage(tr("Error deleting Mailbox.")); | 299 | Global::statusMessage(tr("Error deleting Mailbox.")); |
302 | return 0; | 300 | return 0; |
303 | } | 301 | } |
304 | return 1; | 302 | return 1; |
305 | } | 303 | } |
306 | 304 | ||
307 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 305 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
308 | { | 306 | { |
309 | mailfolder*folder = 0; | 307 | mailfolder*folder = 0; |
310 | mailstorage*storage = mailstorage_new(NULL); | 308 | mailstorage*storage = mailstorage_new(NULL); |
311 | target_stat.message_count = 0; | 309 | target_stat.message_count = 0; |
312 | target_stat.message_unseen = 0; | 310 | target_stat.message_unseen = 0; |
313 | target_stat.message_recent = 0; | 311 | target_stat.message_recent = 0; |
314 | QString p = MBOXPath+"/"+mailbox; | 312 | QString p = MBOXPath+"/"+mailbox; |
315 | QFile fi(p); | 313 | QFile fi(p); |
316 | if (!fi.exists()) { | 314 | if (!fi.exists()) { |
317 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 315 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
318 | return; | 316 | return; |
319 | } | 317 | } |
320 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 318 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
321 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 319 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
322 | r = mailfolder_connect(folder); | 320 | r = mailfolder_connect(folder); |
323 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, | 321 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, |
324 | &target_stat.message_recent,&target_stat.message_unseen); | 322 | &target_stat.message_recent,&target_stat.message_unseen); |
325 | if (folder) mailfolder_free(folder); | 323 | if (folder) mailfolder_free(folder); |
326 | if (storage) mailstorage_free(storage); | 324 | if (storage) mailstorage_free(storage); |
327 | } | 325 | } |
328 | 326 | ||
329 | MAILLIB::ATYPE MBOXwrapper::getType()const | 327 | MAILLIB::ATYPE MBOXwrapper::getType()const |
330 | { | 328 | { |
331 | return wrapperType; | 329 | return MAILLIB::A_MBOX; |
332 | } | 330 | } |
333 | 331 | ||
334 | const QString&MBOXwrapper::getName()const | 332 | const QString&MBOXwrapper::getName()const |
335 | { | 333 | { |
336 | return MBOXName; | 334 | return MBOXName; |
337 | } | 335 | } |
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index a12a1dd..7e7f359 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h | |||
@@ -1,48 +1,47 @@ | |||
1 | #ifndef __MBOX_WRAPPER_H | 1 | #ifndef __MBOX_WRAPPER_H |
2 | #define __MBOX_WRAPPER_H | 2 | #define __MBOX_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 | 11 | ||
12 | class MBOXwrapper : public Genericwrapper | 12 | class MBOXwrapper : public Genericwrapper |
13 | { | 13 | { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | 15 | ||
16 | public: | 16 | public: |
17 | MBOXwrapper(const QString & dir,const QString&name); | 17 | MBOXwrapper(const QString & dir,const QString&name); |
18 | virtual ~MBOXwrapper(); | 18 | virtual ~MBOXwrapper(); |
19 | 19 | ||
20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 20 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
21 | virtual QList<Folder>* listFolders(); | 21 | virtual QList<Folder>* listFolders(); |
22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
23 | 23 | ||
24 | virtual void deleteMail(const RecMail&mail); | 24 | virtual void deleteMail(const RecMail&mail); |
25 | virtual void answeredMail(const RecMail&mail); | 25 | virtual void answeredMail(const RecMail&mail); |
26 | 26 | ||
27 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); | 27 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); |
28 | virtual int deleteMbox(const Folder*); | 28 | virtual int deleteMbox(const Folder*); |
29 | 29 | ||
30 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 30 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
31 | 31 | ||
32 | virtual RecBody fetchBody( const RecMail &mail ); | 32 | virtual RecBody fetchBody( const RecMail &mail ); |
33 | static void mbox_progress( size_t current, size_t maximum ); | 33 | static void mbox_progress( size_t current, size_t maximum ); |
34 | 34 | ||
35 | virtual encodedString* fetchRawBody(const RecMail&mail); | 35 | virtual encodedString* fetchRawBody(const RecMail&mail); |
36 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); | 36 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); |
37 | virtual int deleteAllMail(const Folder*); | 37 | virtual int deleteAllMail(const Folder*); |
38 | virtual MAILLIB::ATYPE getType()const; | 38 | virtual MAILLIB::ATYPE getType()const; |
39 | virtual const QString&getName()const; | 39 | virtual const QString&getName()const; |
40 | 40 | ||
41 | protected: | 41 | protected: |
42 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); | 42 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); |
43 | QString MBOXPath; | 43 | QString MBOXPath; |
44 | QString MBOXName; | 44 | QString MBOXName; |
45 | static const MAILLIB::ATYPE wrapperType; | ||
46 | }; | 45 | }; |
47 | 46 | ||
48 | #endif | 47 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index 179bd34..560eab0 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp | |||
@@ -1,445 +1,443 @@ | |||
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 <qmessagebox.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | #include <opie2/oprocess.h> | 9 | #include <opie2/oprocess.h> |
10 | 10 | ||
11 | const MAILLIB::ATYPE MHwrapper::wrapperType=MAILLIB::A_MH; | ||
12 | |||
13 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 11 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
14 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 12 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
15 | { | 13 | { |
16 | if (MHPath.length()>0) { | 14 | if (MHPath.length()>0) { |
17 | if (MHPath[MHPath.length()-1]=='/') { | 15 | if (MHPath[MHPath.length()-1]=='/') { |
18 | MHPath=MHPath.left(MHPath.length()-1); | 16 | MHPath=MHPath.left(MHPath.length()-1); |
19 | } | 17 | } |
20 | qDebug(MHPath); | 18 | qDebug(MHPath); |
21 | QDir dir(MHPath); | 19 | QDir dir(MHPath); |
22 | if (!dir.exists()) { | 20 | if (!dir.exists()) { |
23 | dir.mkdir(MHPath); | 21 | dir.mkdir(MHPath); |
24 | } | 22 | } |
25 | init_storage(); | 23 | init_storage(); |
26 | } | 24 | } |
27 | } | 25 | } |
28 | 26 | ||
29 | void MHwrapper::init_storage() | 27 | void MHwrapper::init_storage() |
30 | { | 28 | { |
31 | int r; | 29 | int r; |
32 | QString pre = MHPath; | 30 | QString pre = MHPath; |
33 | if (!m_storage) { | 31 | if (!m_storage) { |
34 | m_storage = mailstorage_new(NULL); | 32 | m_storage = mailstorage_new(NULL); |
35 | 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); |
36 | if (r != MAIL_NO_ERROR) { | 34 | if (r != MAIL_NO_ERROR) { |
37 | qDebug("error initializing storage"); | 35 | qDebug("error initializing storage"); |
38 | mailstorage_free(m_storage); | 36 | mailstorage_free(m_storage); |
39 | m_storage = 0; | 37 | m_storage = 0; |
40 | return; | 38 | return; |
41 | } | 39 | } |
42 | } | 40 | } |
43 | r = mailstorage_connect(m_storage); | 41 | r = mailstorage_connect(m_storage); |
44 | if (r!=MAIL_NO_ERROR) { | 42 | if (r!=MAIL_NO_ERROR) { |
45 | qDebug("error connecting storage"); | 43 | qDebug("error connecting storage"); |
46 | mailstorage_free(m_storage); | 44 | mailstorage_free(m_storage); |
47 | m_storage = 0; | 45 | m_storage = 0; |
48 | } | 46 | } |
49 | } | 47 | } |
50 | 48 | ||
51 | void MHwrapper::clean_storage() | 49 | void MHwrapper::clean_storage() |
52 | { | 50 | { |
53 | if (m_storage) { | 51 | if (m_storage) { |
54 | mailstorage_disconnect(m_storage); | 52 | mailstorage_disconnect(m_storage); |
55 | mailstorage_free(m_storage); | 53 | mailstorage_free(m_storage); |
56 | m_storage = 0; | 54 | m_storage = 0; |
57 | } | 55 | } |
58 | } | 56 | } |
59 | 57 | ||
60 | MHwrapper::~MHwrapper() | 58 | MHwrapper::~MHwrapper() |
61 | { | 59 | { |
62 | clean_storage(); | 60 | clean_storage(); |
63 | } | 61 | } |
64 | 62 | ||
65 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 63 | void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
66 | { | 64 | { |
67 | init_storage(); | 65 | init_storage(); |
68 | if (!m_storage) { | 66 | if (!m_storage) { |
69 | return; | 67 | return; |
70 | } | 68 | } |
71 | QString f = buildPath(mailbox); | 69 | QString f = buildPath(mailbox); |
72 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 70 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
73 | if (r!=MAIL_NO_ERROR) { | 71 | if (r!=MAIL_NO_ERROR) { |
74 | qDebug("listMessages: error selecting folder!"); | 72 | qDebug("listMessages: error selecting folder!"); |
75 | return; | 73 | return; |
76 | } | 74 | } |
77 | parseList(target,m_storage->sto_session,f); | 75 | parseList(target,m_storage->sto_session,f); |
78 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 76 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
79 | } | 77 | } |
80 | 78 | ||
81 | QList<Folder>* MHwrapper::listFolders() | 79 | QList<Folder>* MHwrapper::listFolders() |
82 | { | 80 | { |
83 | QList<Folder> * folders = new QList<Folder>(); | 81 | QList<Folder> * folders = new QList<Folder>(); |
84 | folders->setAutoDelete( false ); | 82 | folders->setAutoDelete( false ); |
85 | /* this is needed! */ | 83 | /* this is needed! */ |
86 | if (m_storage) mailstorage_disconnect(m_storage); | 84 | if (m_storage) mailstorage_disconnect(m_storage); |
87 | init_storage(); | 85 | init_storage(); |
88 | if (!m_storage) { | 86 | if (!m_storage) { |
89 | return folders; | 87 | return folders; |
90 | } | 88 | } |
91 | mail_list*flist = 0; | 89 | mail_list*flist = 0; |
92 | clistcell*current=0; | 90 | clistcell*current=0; |
93 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 91 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
94 | if (r != MAIL_NO_ERROR || !flist) { | 92 | if (r != MAIL_NO_ERROR || !flist) { |
95 | qDebug("error getting folder list"); | 93 | qDebug("error getting folder list"); |
96 | return folders; | 94 | return folders; |
97 | } | 95 | } |
98 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 96 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
99 | QString t = (char*)current->data; | 97 | QString t = (char*)current->data; |
100 | t.replace(0,MHPath.length(),""); | 98 | t.replace(0,MHPath.length(),""); |
101 | folders->append(new MHFolder(t,MHPath)); | 99 | folders->append(new MHFolder(t,MHPath)); |
102 | } | 100 | } |
103 | mail_list_free(flist); | 101 | mail_list_free(flist); |
104 | return folders; | 102 | return folders; |
105 | } | 103 | } |
106 | 104 | ||
107 | void MHwrapper::deleteMail(const RecMail&mail) | 105 | void MHwrapper::deleteMail(const RecMail&mail) |
108 | { | 106 | { |
109 | init_storage(); | 107 | init_storage(); |
110 | if (!m_storage) { | 108 | if (!m_storage) { |
111 | return; | 109 | return; |
112 | } | 110 | } |
113 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 111 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
114 | if (r!=MAIL_NO_ERROR) { | 112 | if (r!=MAIL_NO_ERROR) { |
115 | qDebug("error selecting folder!"); | 113 | qDebug("error selecting folder!"); |
116 | return; | 114 | return; |
117 | } | 115 | } |
118 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); | 116 | r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); |
119 | if (r != MAIL_NO_ERROR) { | 117 | if (r != MAIL_NO_ERROR) { |
120 | qDebug("error deleting mail"); | 118 | qDebug("error deleting mail"); |
121 | } | 119 | } |
122 | } | 120 | } |
123 | 121 | ||
124 | void MHwrapper::answeredMail(const RecMail&) | 122 | void MHwrapper::answeredMail(const RecMail&) |
125 | { | 123 | { |
126 | } | 124 | } |
127 | 125 | ||
128 | RecBody MHwrapper::fetchBody( const RecMail &mail ) | 126 | RecBody MHwrapper::fetchBody( const RecMail &mail ) |
129 | { | 127 | { |
130 | RecBody body; | 128 | RecBody body; |
131 | init_storage(); | 129 | init_storage(); |
132 | if (!m_storage) { | 130 | if (!m_storage) { |
133 | return body; | 131 | return body; |
134 | } | 132 | } |
135 | mailmessage * msg; | 133 | mailmessage * msg; |
136 | char*data=0; | 134 | char*data=0; |
137 | size_t size; | 135 | size_t size; |
138 | 136 | ||
139 | /* mail should hold the complete path! */ | 137 | /* mail should hold the complete path! */ |
140 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 138 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
141 | if (r != MAIL_NO_ERROR) { | 139 | if (r != MAIL_NO_ERROR) { |
142 | return body; | 140 | return body; |
143 | } | 141 | } |
144 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); | 142 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); |
145 | if (r != MAIL_NO_ERROR) { | 143 | if (r != MAIL_NO_ERROR) { |
146 | qDebug("Error fetching mail %i",mail.getNumber()); | 144 | qDebug("Error fetching mail %i",mail.getNumber()); |
147 | return body; | 145 | return body; |
148 | } | 146 | } |
149 | body = parseMail(msg); | 147 | body = parseMail(msg); |
150 | mailmessage_fetch_result_free(msg,data); | 148 | mailmessage_fetch_result_free(msg,data); |
151 | return body; | 149 | return body; |
152 | } | 150 | } |
153 | 151 | ||
154 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) | 152 | void MHwrapper::mbox_progress( size_t current, size_t maximum ) |
155 | { | 153 | { |
156 | qDebug("MH %i von %i",current,maximum); | 154 | qDebug("MH %i von %i",current,maximum); |
157 | } | 155 | } |
158 | 156 | ||
159 | QString MHwrapper::buildPath(const QString&p) | 157 | QString MHwrapper::buildPath(const QString&p) |
160 | { | 158 | { |
161 | QString f=""; | 159 | QString f=""; |
162 | if (p.length()==0||p=="/") | 160 | if (p.length()==0||p=="/") |
163 | return MHPath; | 161 | return MHPath; |
164 | if (!p.startsWith(MHPath)) { | 162 | if (!p.startsWith(MHPath)) { |
165 | f+=MHPath; | 163 | f+=MHPath; |
166 | } | 164 | } |
167 | if (!p.startsWith("/")) { | 165 | if (!p.startsWith("/")) { |
168 | f+="/"; | 166 | f+="/"; |
169 | } | 167 | } |
170 | f+=p; | 168 | f+=p; |
171 | return f; | 169 | return f; |
172 | } | 170 | } |
173 | 171 | ||
174 | int MHwrapper::createMbox(const QString&folder,const Folder*pfolder,const QString&,bool ) | 172 | int MHwrapper::createMbox(const QString&folder,const Folder*pfolder,const QString&,bool ) |
175 | { | 173 | { |
176 | init_storage(); | 174 | init_storage(); |
177 | if (!m_storage) { | 175 | if (!m_storage) { |
178 | return 0; | 176 | return 0; |
179 | } | 177 | } |
180 | QString f; | 178 | QString f; |
181 | if (!pfolder) { | 179 | if (!pfolder) { |
182 | // toplevel folder | 180 | // toplevel folder |
183 | f = buildPath(folder); | 181 | f = buildPath(folder); |
184 | } else { | 182 | } else { |
185 | f = pfolder->getName(); | 183 | f = pfolder->getName(); |
186 | f+="/"; | 184 | f+="/"; |
187 | f+=folder; | 185 | f+=folder; |
188 | } | 186 | } |
189 | qDebug(f); | 187 | qDebug(f); |
190 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); | 188 | int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); |
191 | if (r != MAIL_NO_ERROR) { | 189 | if (r != MAIL_NO_ERROR) { |
192 | qDebug("error creating folder %i",r); | 190 | qDebug("error creating folder %i",r); |
193 | return 0; | 191 | return 0; |
194 | } | 192 | } |
195 | qDebug("Folder created"); | 193 | qDebug("Folder created"); |
196 | return 1; | 194 | return 1; |
197 | } | 195 | } |
198 | 196 | ||
199 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | 197 | void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) |
200 | { | 198 | { |
201 | init_storage(); | 199 | init_storage(); |
202 | if (!m_storage) { | 200 | if (!m_storage) { |
203 | return; | 201 | return; |
204 | } | 202 | } |
205 | QString f = buildPath(Folder); | 203 | QString f = buildPath(Folder); |
206 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 204 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
207 | if (r!=MAIL_NO_ERROR) { | 205 | if (r!=MAIL_NO_ERROR) { |
208 | qDebug("error selecting folder!"); | 206 | qDebug("error selecting folder!"); |
209 | return; | 207 | return; |
210 | } | 208 | } |
211 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); | 209 | r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); |
212 | if (r!=MAIL_NO_ERROR) { | 210 | if (r!=MAIL_NO_ERROR) { |
213 | qDebug("error storing mail"); | 211 | qDebug("error storing mail"); |
214 | } | 212 | } |
215 | return; | 213 | return; |
216 | } | 214 | } |
217 | 215 | ||
218 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) | 216 | encodedString* MHwrapper::fetchRawBody(const RecMail&mail) |
219 | { | 217 | { |
220 | encodedString*result = 0; | 218 | encodedString*result = 0; |
221 | init_storage(); | 219 | init_storage(); |
222 | if (!m_storage) { | 220 | if (!m_storage) { |
223 | return result; | 221 | return result; |
224 | } | 222 | } |
225 | mailmessage * msg = 0; | 223 | mailmessage * msg = 0; |
226 | char*data=0; | 224 | char*data=0; |
227 | size_t size; | 225 | size_t size; |
228 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 226 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
229 | if (r!=MAIL_NO_ERROR) { | 227 | if (r!=MAIL_NO_ERROR) { |
230 | qDebug("error selecting folder!"); | 228 | qDebug("error selecting folder!"); |
231 | return result; | 229 | return result; |
232 | } | 230 | } |
233 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); | 231 | r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); |
234 | if (r != MAIL_NO_ERROR) { | 232 | if (r != MAIL_NO_ERROR) { |
235 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 233 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
236 | return 0; | 234 | return 0; |
237 | } | 235 | } |
238 | r = mailmessage_fetch(msg,&data,&size); | 236 | r = mailmessage_fetch(msg,&data,&size); |
239 | if (r != MAIL_NO_ERROR) { | 237 | if (r != MAIL_NO_ERROR) { |
240 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 238 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
241 | if (msg) mailmessage_free(msg); | 239 | if (msg) mailmessage_free(msg); |
242 | return 0; | 240 | return 0; |
243 | } | 241 | } |
244 | result = new encodedString(data,size); | 242 | result = new encodedString(data,size); |
245 | if (msg) mailmessage_free(msg); | 243 | if (msg) mailmessage_free(msg); |
246 | return result; | 244 | return result; |
247 | } | 245 | } |
248 | 246 | ||
249 | void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 247 | void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
250 | { | 248 | { |
251 | QString f = buildPath(mailbox); | 249 | QString f = buildPath(mailbox); |
252 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 250 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
253 | if (r!=MAIL_NO_ERROR) { | 251 | if (r!=MAIL_NO_ERROR) { |
254 | qDebug("deleteMails: error selecting folder!"); | 252 | qDebug("deleteMails: error selecting folder!"); |
255 | return; | 253 | return; |
256 | } | 254 | } |
257 | RecMail*c = 0; | 255 | RecMail*c = 0; |
258 | for (unsigned int i=0; i < target.count();++i) { | 256 | for (unsigned int i=0; i < target.count();++i) { |
259 | c = target.at(i); | 257 | c = target.at(i); |
260 | r = mailsession_remove_message(m_storage->sto_session,c->getNumber()); | 258 | r = mailsession_remove_message(m_storage->sto_session,c->getNumber()); |
261 | if (r != MAIL_NO_ERROR) { | 259 | if (r != MAIL_NO_ERROR) { |
262 | qDebug("error deleting mail"); | 260 | qDebug("error deleting mail"); |
263 | break; | 261 | break; |
264 | } | 262 | } |
265 | } | 263 | } |
266 | } | 264 | } |
267 | 265 | ||
268 | int MHwrapper::deleteAllMail(const Folder*tfolder) | 266 | int MHwrapper::deleteAllMail(const Folder*tfolder) |
269 | { | 267 | { |
270 | init_storage(); | 268 | init_storage(); |
271 | if (!m_storage) { | 269 | if (!m_storage) { |
272 | return 0; | 270 | return 0; |
273 | } | 271 | } |
274 | int res = 1; | 272 | int res = 1; |
275 | if (!tfolder) return 0; | 273 | if (!tfolder) return 0; |
276 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 274 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
277 | if (r!=MAIL_NO_ERROR) { | 275 | if (r!=MAIL_NO_ERROR) { |
278 | qDebug("error selecting folder!"); | 276 | qDebug("error selecting folder!"); |
279 | return 0; | 277 | return 0; |
280 | } | 278 | } |
281 | mailmessage_list*l=0; | 279 | mailmessage_list*l=0; |
282 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 280 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
283 | if (r != MAIL_NO_ERROR) { | 281 | if (r != MAIL_NO_ERROR) { |
284 | qDebug("Error message list"); | 282 | qDebug("Error message list"); |
285 | res = 0; | 283 | res = 0; |
286 | } | 284 | } |
287 | unsigned j = 0; | 285 | unsigned j = 0; |
288 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 286 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
289 | mailmessage * msg; | 287 | mailmessage * msg; |
290 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 288 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
291 | j = msg->msg_index; | 289 | j = msg->msg_index; |
292 | r = mailsession_remove_message(m_storage->sto_session,j); | 290 | r = mailsession_remove_message(m_storage->sto_session,j); |
293 | if (r != MAIL_NO_ERROR) { | 291 | if (r != MAIL_NO_ERROR) { |
294 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 292 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
295 | res = 0; | 293 | res = 0; |
296 | break; | 294 | break; |
297 | } | 295 | } |
298 | } | 296 | } |
299 | if (l) mailmessage_list_free(l); | 297 | if (l) mailmessage_list_free(l); |
300 | return res; | 298 | return res; |
301 | } | 299 | } |
302 | 300 | ||
303 | int MHwrapper::deleteMbox(const Folder*tfolder) | 301 | int MHwrapper::deleteMbox(const Folder*tfolder) |
304 | { | 302 | { |
305 | init_storage(); | 303 | init_storage(); |
306 | if (!m_storage) { | 304 | if (!m_storage) { |
307 | return 0; | 305 | return 0; |
308 | } | 306 | } |
309 | if (!tfolder) return 0; | 307 | if (!tfolder) return 0; |
310 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; | 308 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; |
311 | 309 | ||
312 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 310 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
313 | 311 | ||
314 | if (r != MAIL_NO_ERROR) { | 312 | if (r != MAIL_NO_ERROR) { |
315 | qDebug("error deleting mail box"); | 313 | qDebug("error deleting mail box"); |
316 | return 0; | 314 | return 0; |
317 | } | 315 | } |
318 | QString cmd = "rm -rf "+tfolder->getName(); | 316 | QString cmd = "rm -rf "+tfolder->getName(); |
319 | QStringList command; | 317 | QStringList command; |
320 | command << "/bin/sh"; | 318 | command << "/bin/sh"; |
321 | command << "-c"; | 319 | command << "-c"; |
322 | command << cmd.latin1(); | 320 | command << cmd.latin1(); |
323 | OProcess *process = new OProcess(); | 321 | OProcess *process = new OProcess(); |
324 | 322 | ||
325 | connect(process, SIGNAL(processExited(OProcess*)), | 323 | connect(process, SIGNAL(processExited(OProcess*)), |
326 | this, SLOT( processEnded(OProcess*))); | 324 | this, SLOT( processEnded(OProcess*))); |
327 | connect(process, SIGNAL( receivedStderr(OProcess*,char*,int)), | 325 | connect(process, SIGNAL( receivedStderr(OProcess*,char*,int)), |
328 | this, SLOT( oprocessStderr(OProcess*,char*,int))); | 326 | this, SLOT( oprocessStderr(OProcess*,char*,int))); |
329 | 327 | ||
330 | *process << command; | 328 | *process << command; |
331 | removeMboxfailed = false; | 329 | removeMboxfailed = false; |
332 | if(!process->start(OProcess::Block, OProcess::All) ) { | 330 | if(!process->start(OProcess::Block, OProcess::All) ) { |
333 | qDebug("could not start process"); | 331 | qDebug("could not start process"); |
334 | return 0; | 332 | return 0; |
335 | } | 333 | } |
336 | qDebug("mail box deleted"); | 334 | qDebug("mail box deleted"); |
337 | return 1; | 335 | return 1; |
338 | } | 336 | } |
339 | 337 | ||
340 | void MHwrapper::processEnded(OProcess *p) | 338 | void MHwrapper::processEnded(OProcess *p) |
341 | { | 339 | { |
342 | if (p) delete p; | 340 | if (p) delete p; |
343 | } | 341 | } |
344 | 342 | ||
345 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) | 343 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) |
346 | { | 344 | { |
347 | QString lineStr = buffer; | 345 | QString lineStr = buffer; |
348 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); | 346 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); |
349 | removeMboxfailed = true; | 347 | removeMboxfailed = true; |
350 | } | 348 | } |
351 | 349 | ||
352 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 350 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
353 | { | 351 | { |
354 | init_storage(); | 352 | init_storage(); |
355 | if (!m_storage) { | 353 | if (!m_storage) { |
356 | return; | 354 | return; |
357 | } | 355 | } |
358 | target_stat.message_count = 0; | 356 | target_stat.message_count = 0; |
359 | target_stat.message_unseen = 0; | 357 | target_stat.message_unseen = 0; |
360 | target_stat.message_recent = 0; | 358 | target_stat.message_recent = 0; |
361 | QString f = buildPath(mailbox); | 359 | QString f = buildPath(mailbox); |
362 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, | 360 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, |
363 | &target_stat.message_recent,&target_stat.message_unseen); | 361 | &target_stat.message_recent,&target_stat.message_unseen); |
364 | if (r != MAIL_NO_ERROR) { | 362 | if (r != MAIL_NO_ERROR) { |
365 | Global::statusMessage(tr("Error retrieving status")); | 363 | Global::statusMessage(tr("Error retrieving status")); |
366 | } | 364 | } |
367 | } | 365 | } |
368 | 366 | ||
369 | MAILLIB::ATYPE MHwrapper::getType()const | 367 | MAILLIB::ATYPE MHwrapper::getType()const |
370 | { | 368 | { |
371 | return wrapperType; | 369 | return MAILLIB::A_MH; |
372 | } | 370 | } |
373 | 371 | ||
374 | const QString&MHwrapper::getName()const | 372 | const QString&MHwrapper::getName()const |
375 | { | 373 | { |
376 | return MHName; | 374 | return MHName; |
377 | } | 375 | } |
378 | void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 376 | void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
379 | { | 377 | { |
380 | init_storage(); | 378 | init_storage(); |
381 | if (!m_storage) { | 379 | if (!m_storage) { |
382 | return; | 380 | return; |
383 | } | 381 | } |
384 | if (targetWrapper != this) { | 382 | if (targetWrapper != this) { |
385 | qDebug("Using generic"); | 383 | qDebug("Using generic"); |
386 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 384 | Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
387 | return; | 385 | return; |
388 | } | 386 | } |
389 | qDebug("Using internal routines for move/copy"); | 387 | qDebug("Using internal routines for move/copy"); |
390 | QString tf = buildPath(targetFolder); | 388 | QString tf = buildPath(targetFolder); |
391 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); | 389 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); |
392 | if (r != MAIL_NO_ERROR) { | 390 | if (r != MAIL_NO_ERROR) { |
393 | qDebug("Error selecting source mailbox"); | 391 | qDebug("Error selecting source mailbox"); |
394 | return; | 392 | return; |
395 | } | 393 | } |
396 | if (moveit) { | 394 | if (moveit) { |
397 | r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | 395 | r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); |
398 | } else { | 396 | } else { |
399 | r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); | 397 | r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); |
400 | } | 398 | } |
401 | if (r != MAIL_NO_ERROR) { | 399 | if (r != MAIL_NO_ERROR) { |
402 | qDebug("Error copy/moving mail internal (%i)",r); | 400 | qDebug("Error copy/moving mail internal (%i)",r); |
403 | } | 401 | } |
404 | } | 402 | } |
405 | 403 | ||
406 | void MHwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 404 | void MHwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
407 | { | 405 | { |
408 | init_storage(); | 406 | init_storage(); |
409 | if (!m_storage) { | 407 | if (!m_storage) { |
410 | return; | 408 | return; |
411 | } | 409 | } |
412 | if (targetWrapper != this) { | 410 | if (targetWrapper != this) { |
413 | qDebug("Using generic"); | 411 | qDebug("Using generic"); |
414 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 412 | Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
415 | return; | 413 | return; |
416 | } | 414 | } |
417 | if (!fromFolder) return; | 415 | if (!fromFolder) return; |
418 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); | 416 | int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); |
419 | if (r!=MAIL_NO_ERROR) { | 417 | if (r!=MAIL_NO_ERROR) { |
420 | qDebug("error selecting source folder!"); | 418 | qDebug("error selecting source folder!"); |
421 | return; | 419 | return; |
422 | } | 420 | } |
423 | QString tf = buildPath(targetFolder); | 421 | QString tf = buildPath(targetFolder); |
424 | mailmessage_list*l=0; | 422 | mailmessage_list*l=0; |
425 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 423 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
426 | if (r != MAIL_NO_ERROR) { | 424 | if (r != MAIL_NO_ERROR) { |
427 | qDebug("Error message list"); | 425 | qDebug("Error message list"); |
428 | } | 426 | } |
429 | unsigned j = 0; | 427 | unsigned j = 0; |
430 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { | 428 | for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { |
431 | mailmessage * msg; | 429 | mailmessage * msg; |
432 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 430 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
433 | j = msg->msg_index; | 431 | j = msg->msg_index; |
434 | if (moveit) { | 432 | if (moveit) { |
435 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); | 433 | r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); |
436 | } else { | 434 | } else { |
437 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); | 435 | r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); |
438 | } | 436 | } |
439 | if (r != MAIL_NO_ERROR) { | 437 | if (r != MAIL_NO_ERROR) { |
440 | qDebug("Error copy/moving mail internal (%i)",r); | 438 | qDebug("Error copy/moving mail internal (%i)",r); |
441 | break; | 439 | break; |
442 | } | 440 | } |
443 | } | 441 | } |
444 | if (l) mailmessage_list_free(l); | 442 | if (l) mailmessage_list_free(l); |
445 | } | 443 | } |
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h index c1ba78d..b7c23af 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.h +++ b/noncore/net/mail/libmailwrapper/mhwrapper.h | |||
@@ -1,61 +1,60 @@ | |||
1 | #ifndef __MH_WRAPPER_H | 1 | #ifndef __MH_WRAPPER_H |
2 | #define __MH_WRAPPER_H | 2 | #define __MH_WRAPPER_H |
3 | 3 | ||
4 | #include "maildefines.h" | 4 | #include "maildefines.h" |
5 | 5 | ||
6 | #include "genericwrapper.h" | 6 | #include "genericwrapper.h" |
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | 8 | ||
9 | class RecMail; | 9 | class RecMail; |
10 | class RecBody; | 10 | class RecBody; |
11 | class encodedString; | 11 | class encodedString; |
12 | struct mailmbox_folder; | 12 | struct mailmbox_folder; |
13 | class OProcess; | 13 | class OProcess; |
14 | 14 | ||
15 | class MHwrapper : public Genericwrapper | 15 | class MHwrapper : public Genericwrapper |
16 | { | 16 | { |
17 | Q_OBJECT | 17 | Q_OBJECT |
18 | public: | 18 | public: |
19 | MHwrapper(const QString & dir,const QString&name); | 19 | MHwrapper(const QString & dir,const QString&name); |
20 | virtual ~MHwrapper(); | 20 | virtual ~MHwrapper(); |
21 | 21 | ||
22 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 22 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
23 | virtual QList<Folder>* listFolders(); | 23 | virtual QList<Folder>* listFolders(); |
24 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 24 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
25 | 25 | ||
26 | virtual void deleteMail(const RecMail&mail); | 26 | virtual void deleteMail(const RecMail&mail); |
27 | virtual void answeredMail(const RecMail&mail); | 27 | virtual void answeredMail(const RecMail&mail); |
28 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 28 | virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
29 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 29 | virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
30 | 30 | ||
31 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); | 31 | virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); |
32 | virtual int deleteMbox(const Folder*); | 32 | virtual int deleteMbox(const Folder*); |
33 | 33 | ||
34 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 34 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
35 | 35 | ||
36 | virtual RecBody fetchBody( const RecMail &mail ); | 36 | virtual RecBody fetchBody( const RecMail &mail ); |
37 | static void mbox_progress( size_t current, size_t maximum ); | 37 | static void mbox_progress( size_t current, size_t maximum ); |
38 | 38 | ||
39 | virtual encodedString* fetchRawBody(const RecMail&mail); | 39 | virtual encodedString* fetchRawBody(const RecMail&mail); |
40 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); | 40 | virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); |
41 | virtual int deleteAllMail(const Folder*); | 41 | virtual int deleteAllMail(const Folder*); |
42 | virtual MAILLIB::ATYPE getType()const; | 42 | virtual MAILLIB::ATYPE getType()const; |
43 | virtual const QString&getName()const; | 43 | virtual const QString&getName()const; |
44 | 44 | ||
45 | public slots: | 45 | public slots: |
46 | /* for deleting maildirs we are using a system call */ | 46 | /* for deleting maildirs we are using a system call */ |
47 | virtual void oprocessStderr(OProcess*, char *buffer, int ); | 47 | virtual void oprocessStderr(OProcess*, char *buffer, int ); |
48 | virtual void processEnded(OProcess *); | 48 | virtual void processEnded(OProcess *); |
49 | protected: | 49 | protected: |
50 | QString buildPath(const QString&p); | 50 | QString buildPath(const QString&p); |
51 | QString MHPath; | 51 | QString MHPath; |
52 | QString MHName; | 52 | QString MHName; |
53 | static const MAILLIB::ATYPE wrapperType; | ||
54 | 53 | ||
55 | void init_storage(); | 54 | void init_storage(); |
56 | void clean_storage(); | 55 | void clean_storage(); |
57 | 56 | ||
58 | bool removeMboxfailed; | 57 | bool removeMboxfailed; |
59 | }; | 58 | }; |
60 | 59 | ||
61 | #endif | 60 | #endif |