Diffstat (limited to 'noncore/net/mail/mboxwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 324 |
1 files changed, 0 insertions, 324 deletions
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp deleted file mode 100644 index 540a971..0000000 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/dev/null | |||
@@ -1,324 +0,0 @@ | |||
1 | #include "mboxwrapper.h" | ||
2 | #include "mailtypes.h" | ||
3 | #include "mailwrapper.h" | ||
4 | #include <libetpan/libetpan.h> | ||
5 | #include <qdir.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <qpe/global.h> | ||
8 | |||
9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | ||
10 | : Genericwrapper(),MBOXPath(mbox_dir) | ||
11 | { | ||
12 | QDir dir(MBOXPath); | ||
13 | if (!dir.exists()) { | ||
14 | dir.mkdir(MBOXPath); | ||
15 | } | ||
16 | } | ||
17 | |||
18 | MBOXwrapper::~MBOXwrapper() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | ||
23 | { | ||
24 | mailstorage*storage = mailstorage_new(NULL); | ||
25 | QString p = MBOXPath+"/"; | ||
26 | p+=mailbox; | ||
27 | |||
28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
29 | mailfolder*folder; | ||
30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
31 | r = mailfolder_connect(folder); | ||
32 | if (r != MAIL_NO_ERROR) { | ||
33 | qDebug("Error initializing mbox"); | ||
34 | mailfolder_free(folder); | ||
35 | mailstorage_free(storage); | ||
36 | return; | ||
37 | } | ||
38 | |||
39 | parseList(target,folder->fld_session,mailbox); | ||
40 | |||
41 | mailfolder_disconnect(folder); | ||
42 | mailfolder_free(folder); | ||
43 | mailstorage_free(storage); | ||
44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | ||
45 | } | ||
46 | |||
47 | QList<Folder>* MBOXwrapper::listFolders() | ||
48 | { | ||
49 | QList<Folder> * folders = new QList<Folder>(); | ||
50 | folders->setAutoDelete( false ); | ||
51 | QDir dir(MBOXPath); | ||
52 | if (!dir.exists()) return folders; | ||
53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | ||
54 | QStringList entries = dir.entryList(); | ||
55 | QStringList::ConstIterator it = entries.begin(); | ||
56 | for (;it!=entries.end();++it) { | ||
57 | Folder*inb=new Folder(*it,"/"); | ||
58 | folders->append(inb); | ||
59 | } | ||
60 | return folders; | ||
61 | } | ||
62 | |||
63 | void MBOXwrapper::deleteMail(const RecMail&mail) | ||
64 | { | ||
65 | mailstorage*storage = mailstorage_new(NULL); | ||
66 | QString p = MBOXPath+"/"; | ||
67 | p+=mail.getMbox(); | ||
68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
69 | mailfolder*folder; | ||
70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
71 | r = mailfolder_connect(folder); | ||
72 | if (r != MAIL_NO_ERROR) { | ||
73 | qDebug("Error initializing mbox"); | ||
74 | mailfolder_free(folder); | ||
75 | mailstorage_free(storage); | ||
76 | return; | ||
77 | } | ||
78 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | ||
79 | if (r != MAIL_NO_ERROR) { | ||
80 | qDebug("error deleting mail"); | ||
81 | } | ||
82 | mailfolder_free(folder); | ||
83 | mailstorage_free(storage); | ||
84 | } | ||
85 | |||
86 | void MBOXwrapper::answeredMail(const RecMail&) | ||
87 | { | ||
88 | } | ||
89 | |||
90 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | ||
91 | { | ||
92 | RecBody body; | ||
93 | mailstorage*storage = mailstorage_new(NULL); | ||
94 | QString p = MBOXPath+"/"; | ||
95 | p+=mail.getMbox(); | ||
96 | mailmessage * msg; | ||
97 | char*data=0; | ||
98 | size_t size; | ||
99 | |||
100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
101 | mailfolder*folder; | ||
102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
103 | r = mailfolder_connect(folder); | ||
104 | if (r != MAIL_NO_ERROR) { | ||
105 | qDebug("Error initializing mbox"); | ||
106 | mailfolder_free(folder); | ||
107 | mailstorage_free(storage); | ||
108 | return body; | ||
109 | } | ||
110 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | ||
111 | if (r != MAIL_NO_ERROR) { | ||
112 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
113 | mailfolder_free(folder); | ||
114 | mailstorage_free(storage); | ||
115 | return body; | ||
116 | } | ||
117 | r = mailmessage_fetch(msg,&data,&size); | ||
118 | if (r != MAIL_NO_ERROR) { | ||
119 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
120 | mailfolder_free(folder); | ||
121 | mailstorage_free(storage); | ||
122 | mailmessage_free(msg); | ||
123 | return body; | ||
124 | } | ||
125 | body = parseMail(msg); | ||
126 | mailmessage_fetch_result_free(msg,data); | ||
127 | mailfolder_free(folder); | ||
128 | mailstorage_free(storage); | ||
129 | |||
130 | return body; | ||
131 | } | ||
132 | |||
133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | ||
134 | { | ||
135 | qDebug("MBOX %i von %i",current,maximum); | ||
136 | } | ||
137 | |||
138 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) | ||
139 | { | ||
140 | QString p = MBOXPath+"/"; | ||
141 | p+=folder; | ||
142 | QFileInfo fi(p); | ||
143 | if (fi.exists()) { | ||
144 | Global::statusMessage(tr("Mailbox exists.")); | ||
145 | return 0; | ||
146 | } | ||
147 | mailmbox_folder*f = 0; | ||
148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | ||
149 | Global::statusMessage(tr("Error init folder")); | ||
150 | return 0; | ||
151 | } | ||
152 | if (f) mailmbox_done(f); | ||
153 | return 1; | ||
154 | } | ||
155 | |||
156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | ||
157 | { | ||
158 | QString p = MBOXPath+"/"; | ||
159 | p+=folder; | ||
160 | mailmbox_folder*f = 0; | ||
161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
162 | if (r != MAIL_NO_ERROR) { | ||
163 | Global::statusMessage(tr("Error init folder")); | ||
164 | return; | ||
165 | } | ||
166 | r = mailmbox_append_message(f,msg,length); | ||
167 | if (r != MAIL_NO_ERROR) { | ||
168 | Global::statusMessage(tr("Error writing to message folder")); | ||
169 | } | ||
170 | mailmbox_done(f); | ||
171 | } | ||
172 | |||
173 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | ||
174 | { | ||
175 | RecBody body; | ||
176 | mailstorage*storage = mailstorage_new(NULL); | ||
177 | QString p = MBOXPath+"/"; | ||
178 | p+=mail.getMbox(); | ||
179 | mailmessage * msg; | ||
180 | char*data=0; | ||
181 | size_t size; | ||
182 | |||
183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
184 | mailfolder*folder; | ||
185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
186 | r = mailfolder_connect(folder); | ||
187 | if (r != MAIL_NO_ERROR) { | ||
188 | Global::statusMessage(tr("Error initializing mbox")); | ||
189 | mailfolder_free(folder); | ||
190 | mailstorage_free(storage); | ||
191 | return; | ||
192 | } | ||
193 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | ||
194 | if (r != MAIL_NO_ERROR) { | ||
195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | ||
196 | mailfolder_free(folder); | ||
197 | mailstorage_free(storage); | ||
198 | return; | ||
199 | } | ||
200 | r = mailmessage_fetch(msg,&data,&size); | ||
201 | if (r != MAIL_NO_ERROR) { | ||
202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | ||
203 | mailfolder_free(folder); | ||
204 | mailstorage_free(storage); | ||
205 | mailmessage_free(msg); | ||
206 | return; | ||
207 | } | ||
208 | *target = data; | ||
209 | *length = size; | ||
210 | mailfolder_free(folder); | ||
211 | mailstorage_free(storage); | ||
212 | mailmessage_free(msg); | ||
213 | } | ||
214 | |||
215 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | ||
216 | { | ||
217 | QString p = MBOXPath+"/"; | ||
218 | p+=mailbox; | ||
219 | mailmbox_folder*f = 0; | ||
220 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
221 | if (r != MAIL_NO_ERROR) { | ||
222 | qDebug("Error init folder"); | ||
223 | return; | ||
224 | } | ||
225 | deleteMails(f,target); | ||
226 | mailmbox_done(f); | ||
227 | } | ||
228 | |||
229 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) | ||
230 | { | ||
231 | if (!f) return; | ||
232 | int r; | ||
233 | for (unsigned int i=0; i < target.count();++i) { | ||
234 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | ||
235 | if (r!=MAILMBOX_NO_ERROR) { | ||
236 | qDebug("error delete mail"); | ||
237 | } | ||
238 | } | ||
239 | r = mailmbox_expunge(f); | ||
240 | if (r != MAILMBOX_NO_ERROR) { | ||
241 | qDebug("error expunge mailbox"); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) | ||
246 | { | ||
247 | if (!tfolder) return 0; | ||
248 | QString p = MBOXPath+tfolder->getDisplayName(); | ||
249 | int res = 1; | ||
250 | |||
251 | mailfolder*folder = 0; | ||
252 | mailmessage_list*l=0; | ||
253 | mailstorage*storage = mailstorage_new(NULL); | ||
254 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
255 | if (r != MAIL_NO_ERROR) { | ||
256 | Global::statusMessage(tr("Error initializing mbox")); | ||
257 | res = 0; | ||
258 | } | ||
259 | if (res) { | ||
260 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
261 | r = mailfolder_connect(folder); | ||
262 | if (r != MAIL_NO_ERROR) { | ||
263 | Global::statusMessage(tr("Error initializing mbox")); | ||
264 | res = 0; | ||
265 | } | ||
266 | } | ||
267 | if (res) { | ||
268 | r = mailsession_get_messages_list(folder->fld_session,&l); | ||
269 | if (r != MAIL_NO_ERROR) { | ||
270 | qDebug("Error message list"); | ||
271 | res=0; | ||
272 | } | ||
273 | } | ||
274 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | ||
275 | r = mailsession_remove_message(folder->fld_session,i+1); | ||
276 | if (r != MAIL_NO_ERROR) { | ||
277 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | ||
278 | res = 0; | ||
279 | break; | ||
280 | } | ||
281 | } | ||
282 | if (l) mailmessage_list_free(l); | ||
283 | if (folder) mailfolder_free(folder); | ||
284 | if (storage) mailstorage_free(storage); | ||
285 | return res; | ||
286 | } | ||
287 | |||
288 | int MBOXwrapper::deleteMbox(const Folder*tfolder) | ||
289 | { | ||
290 | if (!tfolder) return 0; | ||
291 | QString p = MBOXPath+tfolder->getDisplayName(); | ||
292 | QFile fi(p); | ||
293 | if (!fi.exists()) { | ||
294 | Global::statusMessage(tr("Mailbox doesn't exist.")); | ||
295 | return 0; | ||
296 | } | ||
297 | if (!fi.remove()) { | ||
298 | Global::statusMessage(tr("Error deleting Mailbox.")); | ||
299 | return 0; | ||
300 | } | ||
301 | return 1; | ||
302 | } | ||
303 | |||
304 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
305 | { | ||
306 | mailfolder*folder = 0; | ||
307 | mailstorage*storage = mailstorage_new(NULL); | ||
308 | target_stat.message_count = 0; | ||
309 | target_stat.message_unseen = 0; | ||
310 | target_stat.message_recent = 0; | ||
311 | QString p = MBOXPath+"/"+mailbox; | ||
312 | QFile fi(p); | ||
313 | if (!fi.exists()) { | ||
314 | Global::statusMessage(tr("Mailbox doesn't exist.")); | ||
315 | return; | ||
316 | } | ||
317 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
318 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
319 | r = mailfolder_connect(folder); | ||
320 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, | ||
321 | &target_stat.message_recent,&target_stat.message_unseen); | ||
322 | if (folder) mailfolder_free(folder); | ||
323 | if (storage) mailstorage_free(storage); | ||
324 | } | ||