author | alwin <alwin> | 2004-01-04 01:59:09 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-04 01:59:09 (UTC) |
commit | 16d8d88dc09477d871f92d283aa59c8206456a26 (patch) (unidiff) | |
tree | f9aa7a7d6861c81535810092eae8a1f93a9d2358 /noncore/net | |
parent | 6fd109ed595e4e28f49f5de0a26e9f9445e672f6 (diff) | |
download | opie-16d8d88dc09477d871f92d283aa59c8206456a26.zip opie-16d8d88dc09477d871f92d283aa59c8206456a26.tar.gz opie-16d8d88dc09477d871f92d283aa59c8206456a26.tar.bz2 |
moved to shared lib
-rw-r--r-- | noncore/net/mail/genericwrapper.cpp | 503 | ||||
-rw-r--r-- | noncore/net/mail/genericwrapper.h | 59 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.cpp | 137 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.h | 92 | ||||
-rw-r--r-- | noncore/net/mail/settings.cpp | 403 | ||||
-rw-r--r-- | noncore/net/mail/settings.h | 146 |
6 files changed, 0 insertions, 1340 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp deleted file mode 100644 index 714396b..0000000 --- a/noncore/net/mail/genericwrapper.cpp +++ b/dev/null | |||
@@ -1,503 +0,0 @@ | |||
1 | #include "genericwrapper.h" | ||
2 | #include <libetpan/libetpan.h> | ||
3 | #include "mailtypes.h" | ||
4 | |||
5 | Genericwrapper::Genericwrapper() | ||
6 | : AbstractMail() | ||
7 | { | ||
8 | bodyCache.clear(); | ||
9 | } | ||
10 | |||
11 | Genericwrapper::~Genericwrapper() | ||
12 | { | ||
13 | cleanMimeCache(); | ||
14 | } | ||
15 | |||
16 | void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | ||
17 | { | ||
18 | if (!mime) { | ||
19 | return; | ||
20 | } | ||
21 | mailmime_field*field = 0; | ||
22 | mailmime_single_fields fields; | ||
23 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | ||
24 | if (mime->mm_mime_fields != NULL) { | ||
25 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | ||
26 | mime->mm_content_type); | ||
27 | } | ||
28 | |||
29 | mailmime_content*type = fields.fld_content; | ||
30 | clistcell*current; | ||
31 | if (!type) { | ||
32 | target.setType("text"); | ||
33 | target.setSubtype("plain"); | ||
34 | } else { | ||
35 | target.setSubtype(type->ct_subtype); | ||
36 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | ||
37 | case MAILMIME_DISCRETE_TYPE_TEXT: | ||
38 | target.setType("text"); | ||
39 | break; | ||
40 | case MAILMIME_DISCRETE_TYPE_IMAGE: | ||
41 | target.setType("image"); | ||
42 | break; | ||
43 | case MAILMIME_DISCRETE_TYPE_AUDIO: | ||
44 | target.setType("audio"); | ||
45 | break; | ||
46 | case MAILMIME_DISCRETE_TYPE_VIDEO: | ||
47 | target.setType("video"); | ||
48 | break; | ||
49 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | ||
50 | target.setType("application"); | ||
51 | break; | ||
52 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | ||
53 | default: | ||
54 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | ||
55 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | ||
56 | } | ||
57 | break; | ||
58 | } | ||
59 | if (type->ct_parameters) { | ||
60 | fillParameters(target,type->ct_parameters); | ||
61 | } | ||
62 | } | ||
63 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | ||
64 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | ||
65 | field = (mailmime_field*)current->data; | ||
66 | switch(field->fld_type) { | ||
67 | case MAILMIME_FIELD_TRANSFER_ENCODING: | ||
68 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | ||
69 | break; | ||
70 | case MAILMIME_FIELD_ID: | ||
71 | target.setIdentifier(field->fld_data.fld_id); | ||
72 | break; | ||
73 | case MAILMIME_FIELD_DESCRIPTION: | ||
74 | target.setDescription(field->fld_data.fld_description); | ||
75 | break; | ||
76 | default: | ||
77 | break; | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | void Genericwrapper::fillParameters(RecPart&target,clist*parameters) | ||
84 | { | ||
85 | if (!parameters) {return;} | ||
86 | clistcell*current=0; | ||
87 | mailmime_parameter*param; | ||
88 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | ||
89 | param = (mailmime_parameter*)current->data; | ||
90 | if (param) { | ||
91 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
96 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | ||
97 | { | ||
98 | QString enc="7bit"; | ||
99 | if (!aEnc) return enc; | ||
100 | switch(aEnc->enc_type) { | ||
101 | case MAILMIME_MECHANISM_7BIT: | ||
102 | enc = "7bit"; | ||
103 | break; | ||
104 | case MAILMIME_MECHANISM_8BIT: | ||
105 | enc = "8bit"; | ||
106 | break; | ||
107 | case MAILMIME_MECHANISM_BINARY: | ||
108 | enc = "binary"; | ||
109 | break; | ||
110 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | ||
111 | enc = "quoted-printable"; | ||
112 | break; | ||
113 | case MAILMIME_MECHANISM_BASE64: | ||
114 | enc = "base64"; | ||
115 | break; | ||
116 | case MAILMIME_MECHANISM_TOKEN: | ||
117 | default: | ||
118 | if (aEnc->enc_token) { | ||
119 | enc = QString(aEnc->enc_token); | ||
120 | } | ||
121 | break; | ||
122 | } | ||
123 | return enc; | ||
124 | } | ||
125 | |||
126 | void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | ||
127 | { | ||
128 | if (current_rec >= 10) { | ||
129 | qDebug("too deep recursion!"); | ||
130 | } | ||
131 | if (!message || !mime) { | ||
132 | return; | ||
133 | } | ||
134 | int r; | ||
135 | char*data = 0; | ||
136 | size_t len; | ||
137 | clistiter * cur = 0; | ||
138 | QString b; | ||
139 | RecPart part; | ||
140 | |||
141 | switch (mime->mm_type) { | ||
142 | case MAILMIME_SINGLE: | ||
143 | { | ||
144 | QValueList<int>countlist = recList; | ||
145 | countlist.append(current_count); | ||
146 | r = mailmessage_fetch_section(message,mime,&data,&len); | ||
147 | part.setSize(len); | ||
148 | part.setPositionlist(countlist); | ||
149 | b = gen_attachment_id(); | ||
150 | part.setIdentifier(b); | ||
151 | fillSingleBody(part,message,mime); | ||
152 | if (part.Type()=="text" && target.Bodytext().isNull()) { | ||
153 | encodedString*r = new encodedString(); | ||
154 | r->setContent(data,len); | ||
155 | encodedString*res = decode_String(r,part.Encoding()); | ||
156 | if (countlist.count()>2) { | ||
157 | bodyCache[b]=r; | ||
158 | target.addPart(part); | ||
159 | } else { | ||
160 | delete r; | ||
161 | } | ||
162 | b = QString(res->Content()); | ||
163 | delete res; | ||
164 | target.setBodytext(b); | ||
165 | target.setDescription(part); | ||
166 | } else { | ||
167 | bodyCache[b]=new encodedString(data,len); | ||
168 | target.addPart(part); | ||
169 | } | ||
170 | } | ||
171 | break; | ||
172 | case MAILMIME_MULTIPLE: | ||
173 | { | ||
174 | unsigned int ccount = 1; | ||
175 | mailmime*cbody=0; | ||
176 | QValueList<int>countlist = recList; | ||
177 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | ||
178 | cbody = (mailmime*)clist_content(cur); | ||
179 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | ||
180 | RecPart targetPart; | ||
181 | targetPart.setType("multipart"); | ||
182 | countlist.append(current_count); | ||
183 | targetPart.setPositionlist(countlist); | ||
184 | target.addPart(targetPart); | ||
185 | } | ||
186 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | ||
187 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | ||
188 | countlist = recList; | ||
189 | } | ||
190 | ++ccount; | ||
191 | } | ||
192 | } | ||
193 | break; | ||
194 | case MAILMIME_MESSAGE: | ||
195 | { | ||
196 | QValueList<int>countlist = recList; | ||
197 | countlist.append(current_count); | ||
198 | /* the own header is always at recursion 0 - we don't need that */ | ||
199 | if (current_rec > 0) { | ||
200 | part.setPositionlist(countlist); | ||
201 | r = mailmessage_fetch_section(message,mime,&data,&len); | ||
202 | part.setSize(len); | ||
203 | part.setPositionlist(countlist); | ||
204 | b = gen_attachment_id(); | ||
205 | part.setIdentifier(b); | ||
206 | part.setType("message"); | ||
207 | part.setSubtype("rfc822"); | ||
208 | bodyCache[b]=new encodedString(data,len); | ||
209 | target.addPart(part); | ||
210 | } | ||
211 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | ||
212 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | ||
213 | } | ||
214 | } | ||
215 | break; | ||
216 | } | ||
217 | } | ||
218 | |||
219 | RecBody Genericwrapper::parseMail( mailmessage * msg ) | ||
220 | { | ||
221 | int err = MAILIMF_NO_ERROR; | ||
222 | mailmime_single_fields fields; | ||
223 | /* is bound to msg and will be freed there */ | ||
224 | mailmime * mime=0; | ||
225 | RecBody body; | ||
226 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | ||
227 | err = mailmessage_get_bodystructure(msg,&mime); | ||
228 | QValueList<int>recList; | ||
229 | traverseBody(body,msg,mime,recList); | ||
230 | return body; | ||
231 | } | ||
232 | |||
233 | RecMail *Genericwrapper::parseHeader( const char *header ) | ||
234 | { | ||
235 | int err = MAILIMF_NO_ERROR; | ||
236 | size_t curTok = 0; | ||
237 | RecMail *mail = new RecMail(); | ||
238 | mailimf_fields *fields = 0; | ||
239 | mailimf_references * refs = 0; | ||
240 | mailimf_keywords*keys = 0; | ||
241 | QString status; | ||
242 | QString value; | ||
243 | QBitArray mFlags(7); | ||
244 | |||
245 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | ||
246 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | ||
247 | mailimf_field *field = (mailimf_field *) current->data; | ||
248 | switch ( field->fld_type ) { | ||
249 | case MAILIMF_FIELD_FROM: | ||
250 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | ||
251 | break; | ||
252 | case MAILIMF_FIELD_TO: | ||
253 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | ||
254 | break; | ||
255 | case MAILIMF_FIELD_CC: | ||
256 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | ||
257 | break; | ||
258 | case MAILIMF_FIELD_BCC: | ||
259 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | ||
260 | break; | ||
261 | case MAILIMF_FIELD_SUBJECT: | ||
262 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); | ||
263 | break; | ||
264 | case MAILIMF_FIELD_ORIG_DATE: | ||
265 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | ||
266 | break; | ||
267 | case MAILIMF_FIELD_MESSAGE_ID: | ||
268 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | ||
269 | break; | ||
270 | case MAILIMF_FIELD_REFERENCES: | ||
271 | refs = field->fld_data.fld_references; | ||
272 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
273 | char * text = (char*)refs->mid_list->first->data; | ||
274 | mail->setReplyto(QString(text)); | ||
275 | } | ||
276 | break; | ||
277 | case MAILIMF_FIELD_KEYWORDS: | ||
278 | keys = field->fld_data.fld_keywords; | ||
279 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | ||
280 | qDebug("Keyword: %s",(char*)cur->data); | ||
281 | } | ||
282 | break; | ||
283 | case MAILIMF_FIELD_OPTIONAL_FIELD: | ||
284 | status = field->fld_data.fld_optional_field->fld_name; | ||
285 | value = field->fld_data.fld_optional_field->fld_value; | ||
286 | if (status.lower()=="status") { | ||
287 | if (value.lower()=="ro") { | ||
288 | mFlags.setBit(FLAG_SEEN); | ||
289 | } | ||
290 | } else if (status.lower()=="x-status") { | ||
291 | qDebug("X-Status: %s",value.latin1()); | ||
292 | if (value.lower()=="a") { | ||
293 | mFlags.setBit(FLAG_ANSWERED); | ||
294 | } | ||
295 | } else { | ||
296 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | ||
297 | // field->fld_data.fld_optional_field->fld_value); | ||
298 | } | ||
299 | break; | ||
300 | default: | ||
301 | qDebug("Non parsed field"); | ||
302 | break; | ||
303 | } | ||
304 | } | ||
305 | if (fields) mailimf_fields_free(fields); | ||
306 | mail->setFlags(mFlags); | ||
307 | return mail; | ||
308 | } | ||
309 | |||
310 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) | ||
311 | { | ||
312 | char tmp[23]; | ||
313 | |||
314 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | ||
315 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | ||
316 | |||
317 | return QString( tmp ); | ||
318 | } | ||
319 | |||
320 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | ||
321 | { | ||
322 | QString result( "" ); | ||
323 | |||
324 | bool first = true; | ||
325 | if (list == 0) return result; | ||
326 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | ||
327 | mailimf_address *addr = (mailimf_address *) current->data; | ||
328 | |||
329 | if ( !first ) { | ||
330 | result.append( "," ); | ||
331 | } else { | ||
332 | first = false; | ||
333 | } | ||
334 | |||
335 | switch ( addr->ad_type ) { | ||
336 | case MAILIMF_ADDRESS_MAILBOX: | ||
337 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | ||
338 | break; | ||
339 | case MAILIMF_ADDRESS_GROUP: | ||
340 | result.append( parseGroup( addr->ad_data.ad_group ) ); | ||
341 | break; | ||
342 | default: | ||
343 | qDebug( "Generic: unkown mailimf address type" ); | ||
344 | break; | ||
345 | } | ||
346 | } | ||
347 | |||
348 | return result; | ||
349 | } | ||
350 | |||
351 | QString Genericwrapper::parseGroup( mailimf_group *group ) | ||
352 | { | ||
353 | QString result( "" ); | ||
354 | |||
355 | result.append( group->grp_display_name ); | ||
356 | result.append( ": " ); | ||
357 | |||
358 | if ( group->grp_mb_list != NULL ) { | ||
359 | result.append( parseMailboxList( group->grp_mb_list ) ); | ||
360 | } | ||
361 | |||
362 | result.append( ";" ); | ||
363 | |||
364 | return result; | ||
365 | } | ||
366 | |||
367 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | ||
368 | { | ||
369 | QString result( "" ); | ||
370 | |||
371 | if ( box->mb_display_name == NULL ) { | ||
372 | result.append( box->mb_addr_spec ); | ||
373 | } else { | ||
374 | result.append( convert_String(box->mb_display_name).latin1() ); | ||
375 | result.append( " <" ); | ||
376 | result.append( box->mb_addr_spec ); | ||
377 | result.append( ">" ); | ||
378 | } | ||
379 | |||
380 | return result; | ||
381 | } | ||
382 | |||
383 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | ||
384 | { | ||
385 | QString result( "" ); | ||
386 | |||
387 | bool first = true; | ||
388 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | ||
389 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | ||
390 | |||
391 | if ( !first ) { | ||
392 | result.append( "," ); | ||
393 | } else { | ||
394 | first = false; | ||
395 | } | ||
396 | |||
397 | result.append( parseMailbox( box ) ); | ||
398 | } | ||
399 | |||
400 | return result; | ||
401 | } | ||
402 | |||
403 | encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) | ||
404 | { | ||
405 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | ||
406 | if (it==bodyCache.end()) return new encodedString(); | ||
407 | encodedString*t = decode_String(it.data(),part.Encoding()); | ||
408 | return t; | ||
409 | } | ||
410 | |||
411 | encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | ||
412 | { | ||
413 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | ||
414 | if (it==bodyCache.end()) return new encodedString(); | ||
415 | encodedString*t = it.data(); | ||
416 | return t; | ||
417 | } | ||
418 | |||
419 | QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | ||
420 | { | ||
421 | encodedString*t = fetchDecodedPart(mail,part); | ||
422 | QString text=t->Content(); | ||
423 | delete t; | ||
424 | return text; | ||
425 | } | ||
426 | |||
427 | void Genericwrapper::cleanMimeCache() | ||
428 | { | ||
429 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | ||
430 | for (;it!=bodyCache.end();++it) { | ||
431 | encodedString*t = it.data(); | ||
432 | //it.setValue(0); | ||
433 | if (t) delete t; | ||
434 | } | ||
435 | bodyCache.clear(); | ||
436 | qDebug("Genericwrapper: cache cleaned"); | ||
437 | } | ||
438 | |||
439 | void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) | ||
440 | { | ||
441 | int r; | ||
442 | mailmessage_list * env_list = 0; | ||
443 | r = mailsession_get_messages_list(session,&env_list); | ||
444 | if (r != MAIL_NO_ERROR) { | ||
445 | qDebug("Error message list"); | ||
446 | return; | ||
447 | } | ||
448 | r = mailsession_get_envelopes_list(session, env_list); | ||
449 | if (r != MAIL_NO_ERROR) { | ||
450 | qDebug("Error filling message list"); | ||
451 | if (env_list) { | ||
452 | mailmessage_list_free(env_list); | ||
453 | } | ||
454 | return; | ||
455 | } | ||
456 | mailimf_references * refs; | ||
457 | uint32_t i = 0; | ||
458 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | ||
459 | mailmessage * msg; | ||
460 | QBitArray mFlags(7); | ||
461 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | ||
462 | if (msg->msg_fields == NULL) { | ||
463 | qDebug("could not fetch envelope of message %i", i); | ||
464 | continue; | ||
465 | } | ||
466 | RecMail * mail = new RecMail(); | ||
467 | mail->setWrapper(this); | ||
468 | mail_flags * flag_result = 0; | ||
469 | r = mailmessage_get_flags(msg,&flag_result); | ||
470 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | ||
471 | mFlags.setBit(FLAG_SEEN); | ||
472 | } | ||
473 | mailimf_single_fields single_fields; | ||
474 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | ||
475 | mail->setMsgsize(msg->msg_size); | ||
476 | mail->setFlags(mFlags); | ||
477 | mail->setMbox(mailbox); | ||
478 | mail->setNumber(msg->msg_index); | ||
479 | if (single_fields.fld_subject) | ||
480 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | ||
481 | if (single_fields.fld_from) | ||
482 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | ||
483 | if (single_fields.fld_to) | ||
484 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | ||
485 | if (single_fields.fld_cc) | ||
486 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | ||
487 | if (single_fields.fld_bcc) | ||
488 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | ||
489 | if (single_fields.fld_orig_date) | ||
490 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | ||
491 | if (single_fields.fld_message_id->mid_value) | ||
492 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
493 | refs = single_fields.fld_references; | ||
494 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
495 | char * text = (char*)refs->mid_list->first->data; | ||
496 | mail->setReplyto(QString(text)); | ||
497 | } | ||
498 | target.append(mail); | ||
499 | } | ||
500 | if (env_list) { | ||
501 | mailmessage_list_free(env_list); | ||
502 | } | ||
503 | } | ||
diff --git a/noncore/net/mail/genericwrapper.h b/noncore/net/mail/genericwrapper.h deleted file mode 100644 index 32b75c8..0000000 --- a/noncore/net/mail/genericwrapper.h +++ b/dev/null | |||
@@ -1,59 +0,0 @@ | |||
1 | #ifndef __GENERIC_WRAPPER_H | ||
2 | #define __GENERIC_WRAPPER_H | ||
3 | |||
4 | #include "abstractmail.h" | ||
5 | #include <qmap.h> | ||
6 | #include <qstring.h> | ||
7 | #include <libetpan/clist.h> | ||
8 | |||
9 | class RecMail; | ||
10 | class RecBody; | ||
11 | class encodedString; | ||
12 | struct mailpop3; | ||
13 | struct mailmessage; | ||
14 | struct mailmime; | ||
15 | struct mailmime_mechanism; | ||
16 | struct mailimf_mailbox_list; | ||
17 | struct mailimf_mailbox; | ||
18 | struct mailimf_date_time; | ||
19 | struct mailimf_group; | ||
20 | struct mailimf_address_list; | ||
21 | struct mailsession; | ||
22 | |||
23 | /* this class hold just the funs shared between | ||
24 | * mbox and pop3 (later mh, too) mail access. | ||
25 | * it is not desigend to make a instance of it! | ||
26 | */ | ||
27 | class Genericwrapper : public AbstractMail | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | public: | ||
31 | Genericwrapper(); | ||
32 | virtual ~Genericwrapper(); | ||
33 | |||
34 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | ||
35 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | ||
36 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | ||
37 | virtual void cleanMimeCache(); | ||
38 | |||
39 | protected: | ||
40 | RecMail *parseHeader( const char *header ); | ||
41 | RecBody parseMail( mailmessage * msg ); | ||
42 | QString parseMailboxList( mailimf_mailbox_list *list ); | ||
43 | QString parseMailbox( mailimf_mailbox *box ); | ||
44 | QString parseGroup( mailimf_group *group ); | ||
45 | QString parseAddressList( mailimf_address_list *list ); | ||
46 | QString parseDateTime( mailimf_date_time *date ); | ||
47 | |||
48 | void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); | ||
49 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); | ||
50 | static void fillParameters(RecPart&target,clist*parameters); | ||
51 | static QString getencoding(mailmime_mechanism*aEnc); | ||
52 | virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); | ||
53 | |||
54 | QString msgTempName; | ||
55 | unsigned int last_msg_id; | ||
56 | QMap<QString,encodedString*> bodyCache; | ||
57 | }; | ||
58 | |||
59 | #endif | ||
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp deleted file mode 100644 index 9398823..0000000 --- a/noncore/net/mail/mailwrapper.cpp +++ b/dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <sys/stat.h> | ||
3 | #include <sys/types.h> | ||
4 | #include <unistd.h> | ||
5 | #include <fcntl.h> | ||
6 | #include <string.h> | ||
7 | #include <qdir.h> | ||
8 | |||
9 | #include "mailwrapper.h" | ||
10 | #include "logindialog.h" | ||
11 | #include "defines.h" | ||
12 | |||
13 | Attachment::Attachment( DocLnk lnk ) | ||
14 | { | ||
15 | doc = lnk; | ||
16 | size = QFileInfo( doc.file() ).size(); | ||
17 | } | ||
18 | |||
19 | Folder::Folder(const QString&tmp_name, const QString&sep ) | ||
20 | { | ||
21 | name = tmp_name; | ||
22 | nameDisplay = name; | ||
23 | separator = sep; | ||
24 | } | ||
25 | |||
26 | const QString& Folder::Separator()const | ||
27 | { | ||
28 | return separator; | ||
29 | } | ||
30 | |||
31 | IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) | ||
32 | : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) | ||
33 | { | ||
34 | // Decode IMAP foldername | ||
35 | nameDisplay = IMAPFolder::decodeFolderName( name ); | ||
36 | qDebug( "folder " + name + " - displayed as " + nameDisplay ); | ||
37 | |||
38 | if (prefix.length()>0) { | ||
39 | if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { | ||
40 | nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | static unsigned char base64chars[] = | ||
46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; | ||
47 | |||
48 | /** | ||
49 | * Decodes base64 encoded parts of the imapfolder name | ||
50 | * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc | ||
51 | */ | ||
52 | QString IMAPFolder::decodeFolderName( const QString &name ) | ||
53 | { | ||
54 | unsigned char c, i, bitcount; | ||
55 | unsigned long ucs4, utf16, bitbuf; | ||
56 | unsigned char base64[256], utf8[6]; | ||
57 | unsigned long srcPtr = 0; | ||
58 | QCString dst = ""; | ||
59 | QCString src = name.ascii(); | ||
60 | |||
61 | /* initialize modified base64 decoding table */ | ||
62 | memset(base64, UNDEFINED, sizeof(base64)); | ||
63 | for (i = 0; i < sizeof(base64chars); ++i) { | ||
64 | base64[(int)base64chars[i]] = i; | ||
65 | } | ||
66 | |||
67 | /* loop until end of string */ | ||
68 | while (srcPtr < src.length ()) { | ||
69 | c = src[srcPtr++]; | ||
70 | /* deal with literal characters and &- */ | ||
71 | if (c != '&' || src[srcPtr] == '-') { | ||
72 | /* encode literally */ | ||
73 | dst += c; | ||
74 | /* skip over the '-' if this is an &- sequence */ | ||
75 | if (c == '&') | ||
76 | srcPtr++; | ||
77 | } else { | ||
78 | /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ | ||
79 | bitbuf = 0; | ||
80 | bitcount = 0; | ||
81 | ucs4 = 0; | ||
82 | while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { | ||
83 | ++srcPtr; | ||
84 | bitbuf = (bitbuf << 6) | c; | ||
85 | bitcount += 6; | ||
86 | /* enough bits for a UTF-16 character? */ | ||
87 | if (bitcount >= 16) { | ||
88 | bitcount -= 16; | ||
89 | utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; | ||
90 | /* convert UTF16 to UCS4 */ | ||
91 | if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { | ||
92 | ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; | ||
93 | continue; | ||
94 | } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { | ||
95 | ucs4 += utf16 - UTF16LOSTART + UTF16BASE; | ||
96 | } else { | ||
97 | ucs4 = utf16; | ||
98 | } | ||
99 | /* convert UTF-16 range of UCS4 to UTF-8 */ | ||
100 | if (ucs4 <= 0x7fUL) { | ||
101 | utf8[0] = ucs4; | ||
102 | i = 1; | ||
103 | } else if (ucs4 <= 0x7ffUL) { | ||
104 | utf8[0] = 0xc0 | (ucs4 >> 6); | ||
105 | utf8[1] = 0x80 | (ucs4 & 0x3f); | ||
106 | i = 2; | ||
107 | } else if (ucs4 <= 0xffffUL) { | ||
108 | utf8[0] = 0xe0 | (ucs4 >> 12); | ||
109 | utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); | ||
110 | utf8[2] = 0x80 | (ucs4 & 0x3f); | ||
111 | i = 3; | ||
112 | } else { | ||
113 | utf8[0] = 0xf0 | (ucs4 >> 18); | ||
114 | utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); | ||
115 | utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); | ||
116 | utf8[3] = 0x80 | (ucs4 & 0x3f); | ||
117 | i = 4; | ||
118 | } | ||
119 | /* copy it */ | ||
120 | for (c = 0; c < i; ++c) { | ||
121 | dst += utf8[c]; | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | /* skip over trailing '-' in modified UTF-7 encoding */ | ||
126 | if (src[srcPtr] == '-') | ||
127 | ++srcPtr; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return QString::fromUtf8( dst.data() ); | ||
132 | } | ||
133 | |||
134 | Mail::Mail() | ||
135 | :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") | ||
136 | { | ||
137 | } | ||
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h deleted file mode 100644 index a60777d..0000000 --- a/noncore/net/mail/mailwrapper.h +++ b/dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | #ifndef MAILWRAPPER_H | ||
2 | #define MAILWRAPPER_H | ||
3 | |||
4 | #include <qpe/applnk.h> | ||
5 | |||
6 | #include <qbitarray.h> | ||
7 | #include <qdatetime.h> | ||
8 | |||
9 | #include "settings.h" | ||
10 | |||
11 | class Attachment | ||
12 | { | ||
13 | public: | ||
14 | Attachment( DocLnk lnk ); | ||
15 | virtual ~Attachment(){} | ||
16 | const QString getFileName()const{ return doc.file(); } | ||
17 | const QString getName()const{ return doc.name(); } | ||
18 | const QString getMimeType()const{ return doc.type(); } | ||
19 | const QPixmap getPixmap()const{ return doc.pixmap(); } | ||
20 | const int getSize()const { return size; } | ||
21 | DocLnk getDocLnk() { return doc; } | ||
22 | |||
23 | protected: | ||
24 | DocLnk doc; | ||
25 | int size; | ||
26 | |||
27 | }; | ||
28 | |||
29 | class Mail | ||
30 | { | ||
31 | public: | ||
32 | Mail(); | ||
33 | /* Possible that this destructor must not be declared virtual | ||
34 | * 'cause it seems that it will never have some child classes. | ||
35 | * in this case this object will not get a virtual table -> memory and | ||
36 | * speed will be a little bit better? | ||
37 | */ | ||
38 | virtual ~Mail(){} | ||
39 | void addAttachment( Attachment *att ) { attList.append( att ); } | ||
40 | const QList<Attachment>& getAttachments()const { return attList; } | ||
41 | void removeAttachment( Attachment *att ) { attList.remove( att ); } | ||
42 | const QString&getName()const { return name; } | ||
43 | void setName( QString s ) { name = s; } | ||
44 | const QString&getMail()const{ return mail; } | ||
45 | void setMail( const QString&s ) { mail = s; } | ||
46 | const QString&getTo()const{ return to; } | ||
47 | void setTo( const QString&s ) { to = s; } | ||
48 | const QString&getCC()const{ return cc; } | ||
49 | void setCC( const QString&s ) { cc = s; } | ||
50 | const QString&getBCC()const { return bcc; } | ||
51 | void setBCC( const QString&s ) { bcc = s; } | ||
52 | const QString&getMessage()const { return message; } | ||
53 | void setMessage( const QString&s ) { message = s; } | ||
54 | const QString&getSubject()const { return subject; } | ||
55 | void setSubject( const QString&s ) { subject = s; } | ||
56 | const QString&getReply()const{ return reply; } | ||
57 | void setReply( const QString&a ) { reply = a; } | ||
58 | |||
59 | private: | ||
60 | QList<Attachment> attList; | ||
61 | QString name, mail, to, cc, bcc, reply, subject, message; | ||
62 | }; | ||
63 | |||
64 | class Folder : public QObject | ||
65 | { | ||
66 | Q_OBJECT | ||
67 | |||
68 | public: | ||
69 | Folder( const QString&init_name,const QString&sep ); | ||
70 | const QString&getDisplayName()const { return nameDisplay; } | ||
71 | const QString&getName()const { return name; } | ||
72 | virtual bool may_select()const{return true;} | ||
73 | virtual bool no_inferior()const{return true;} | ||
74 | const QString&Separator()const; | ||
75 | |||
76 | protected: | ||
77 | QString nameDisplay, name, separator; | ||
78 | |||
79 | }; | ||
80 | |||
81 | class IMAPFolder : public Folder | ||
82 | { | ||
83 | public: | ||
84 | IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); | ||
85 | virtual bool may_select()const{return m_MaySelect;} | ||
86 | virtual bool no_inferior()const{return m_NoInferior;} | ||
87 | private: | ||
88 | static QString decodeFolderName( const QString &name ); | ||
89 | bool m_MaySelect,m_NoInferior; | ||
90 | }; | ||
91 | |||
92 | #endif | ||
diff --git a/noncore/net/mail/settings.cpp b/noncore/net/mail/settings.cpp deleted file mode 100644 index 17aa1b0..0000000 --- a/noncore/net/mail/settings.cpp +++ b/dev/null | |||
@@ -1,403 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <qdir.h> | ||
3 | |||
4 | #include <qpe/config.h> | ||
5 | |||
6 | #include "settings.h" | ||
7 | #include "defines.h" | ||
8 | |||
9 | Settings::Settings() | ||
10 | : QObject() | ||
11 | { | ||
12 | updateAccounts(); | ||
13 | } | ||
14 | |||
15 | void Settings::checkDirectory() | ||
16 | { | ||
17 | if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { | ||
18 | system( "mkdir -p $HOME/Applications/opiemail" ); | ||
19 | qDebug( "$HOME/Applications/opiemail created" ); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | QList<Account> Settings::getAccounts() | ||
24 | { | ||
25 | return accounts; | ||
26 | } | ||
27 | |||
28 | void Settings::addAccount( Account *account ) | ||
29 | { | ||
30 | accounts.append( account ); | ||
31 | } | ||
32 | |||
33 | void Settings::delAccount( Account *account ) | ||
34 | { | ||
35 | accounts.remove( account ); | ||
36 | account->remove(); | ||
37 | } | ||
38 | |||
39 | void Settings::updateAccounts() | ||
40 | { | ||
41 | accounts.clear(); | ||
42 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
43 | QStringList::Iterator it; | ||
44 | |||
45 | QStringList imap = dir.entryList( "imap-*" ); | ||
46 | for ( it = imap.begin(); it != imap.end(); it++ ) { | ||
47 | qDebug( "Added IMAP account" ); | ||
48 | IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); | ||
49 | accounts.append( account ); | ||
50 | } | ||
51 | |||
52 | QStringList pop3 = dir.entryList( "pop3-*" ); | ||
53 | for ( it = pop3.begin(); it != pop3.end(); it++ ) { | ||
54 | qDebug( "Added POP account" ); | ||
55 | POP3account *account = new POP3account( (*it).replace(0, 5, "") ); | ||
56 | accounts.append( account ); | ||
57 | } | ||
58 | |||
59 | QStringList smtp = dir.entryList( "smtp-*" ); | ||
60 | for ( it = smtp.begin(); it != smtp.end(); it++ ) { | ||
61 | qDebug( "Added SMTP account" ); | ||
62 | SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); | ||
63 | accounts.append( account ); | ||
64 | } | ||
65 | |||
66 | QStringList nntp = dir.entryList( "nntp-*" ); | ||
67 | for ( it = nntp.begin(); it != nntp.end(); it++ ) { | ||
68 | qDebug( "Added NNTP account" ); | ||
69 | NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); | ||
70 | accounts.append( account ); | ||
71 | } | ||
72 | |||
73 | readAccounts(); | ||
74 | } | ||
75 | |||
76 | void Settings::saveAccounts() | ||
77 | { | ||
78 | checkDirectory(); | ||
79 | Account *it; | ||
80 | |||
81 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
82 | it->save(); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void Settings::readAccounts() | ||
87 | { | ||
88 | checkDirectory(); | ||
89 | Account *it; | ||
90 | |||
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
92 | it->read(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | Account::Account() | ||
97 | { | ||
98 | accountName = "changeMe"; | ||
99 | type = "changeMe"; | ||
100 | ssl = false; | ||
101 | } | ||
102 | |||
103 | void Account::remove() | ||
104 | { | ||
105 | QFile file( getFileName() ); | ||
106 | file.remove(); | ||
107 | } | ||
108 | |||
109 | IMAPaccount::IMAPaccount() | ||
110 | : Account() | ||
111 | { | ||
112 | file = IMAPaccount::getUniqueFileName(); | ||
113 | accountName = "New IMAP Account"; | ||
114 | ssl = false; | ||
115 | type = "IMAP"; | ||
116 | port = IMAP_PORT; | ||
117 | } | ||
118 | |||
119 | IMAPaccount::IMAPaccount( QString filename ) | ||
120 | : Account() | ||
121 | { | ||
122 | file = filename; | ||
123 | accountName = "New IMAP Account"; | ||
124 | ssl = false; | ||
125 | type = "IMAP"; | ||
126 | port = IMAP_PORT; | ||
127 | } | ||
128 | |||
129 | QString IMAPaccount::getUniqueFileName() | ||
130 | { | ||
131 | int num = 0; | ||
132 | QString unique; | ||
133 | |||
134 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
135 | |||
136 | QStringList imap = dir.entryList( "imap-*" ); | ||
137 | do { | ||
138 | unique.setNum( num++ ); | ||
139 | } while ( imap.contains( "imap-" + unique ) > 0 ); | ||
140 | |||
141 | return unique; | ||
142 | } | ||
143 | |||
144 | void IMAPaccount::read() | ||
145 | { | ||
146 | Config *conf = new Config( getFileName(), Config::File ); | ||
147 | conf->setGroup( "IMAP Account" ); | ||
148 | accountName = conf->readEntry( "Account","" ); | ||
149 | if (accountName.isNull()) accountName = ""; | ||
150 | server = conf->readEntry( "Server","" ); | ||
151 | if (server.isNull()) server=""; | ||
152 | port = conf->readEntry( "Port","" ); | ||
153 | if (port.isNull()) port="143"; | ||
154 | ssl = conf->readBoolEntry( "SSL",false ); | ||
155 | user = conf->readEntry( "User","" ); | ||
156 | if (user.isNull()) user = ""; | ||
157 | password = conf->readEntryCrypt( "Password","" ); | ||
158 | if (password.isNull()) password = ""; | ||
159 | prefix = conf->readEntry("MailPrefix",""); | ||
160 | if (prefix.isNull()) prefix = ""; | ||
161 | } | ||
162 | |||
163 | void IMAPaccount::save() | ||
164 | { | ||
165 | qDebug( "saving " + getFileName() ); | ||
166 | Settings::checkDirectory(); | ||
167 | |||
168 | Config *conf = new Config( getFileName(), Config::File ); | ||
169 | conf->setGroup( "IMAP Account" ); | ||
170 | conf->writeEntry( "Account", accountName ); | ||
171 | conf->writeEntry( "Server", server ); | ||
172 | conf->writeEntry( "Port", port ); | ||
173 | conf->writeEntry( "SSL", ssl ); | ||
174 | conf->writeEntry( "User", user ); | ||
175 | conf->writeEntryCrypt( "Password", password ); | ||
176 | conf->writeEntry( "MailPrefix",prefix); | ||
177 | conf->write(); | ||
178 | } | ||
179 | |||
180 | |||
181 | QString IMAPaccount::getFileName() | ||
182 | { | ||
183 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/imap-" + file; | ||
184 | } | ||
185 | |||
186 | POP3account::POP3account() | ||
187 | : Account() | ||
188 | { | ||
189 | file = POP3account::getUniqueFileName(); | ||
190 | accountName = "New POP3 Account"; | ||
191 | ssl = false; | ||
192 | type = "POP3"; | ||
193 | port = POP3_PORT; | ||
194 | } | ||
195 | |||
196 | POP3account::POP3account( QString filename ) | ||
197 | : Account() | ||
198 | { | ||
199 | file = filename; | ||
200 | accountName = "New POP3 Account"; | ||
201 | ssl = false; | ||
202 | type = "POP3"; | ||
203 | port = POP3_PORT; | ||
204 | } | ||
205 | |||
206 | QString POP3account::getUniqueFileName() | ||
207 | { | ||
208 | int num = 0; | ||
209 | QString unique; | ||
210 | |||
211 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
212 | |||
213 | QStringList imap = dir.entryList( "pop3-*" ); | ||
214 | do { | ||
215 | unique.setNum( num++ ); | ||
216 | } while ( imap.contains( "pop3-" + unique ) > 0 ); | ||
217 | |||
218 | return unique; | ||
219 | } | ||
220 | |||
221 | void POP3account::read() | ||
222 | { | ||
223 | Config *conf = new Config( getFileName(), Config::File ); | ||
224 | conf->setGroup( "POP3 Account" ); | ||
225 | accountName = conf->readEntry( "Account" ); | ||
226 | server = conf->readEntry( "Server" ); | ||
227 | port = conf->readEntry( "Port" ); | ||
228 | ssl = conf->readBoolEntry( "SSL" ); | ||
229 | user = conf->readEntry( "User" ); | ||
230 | password = conf->readEntryCrypt( "Password" ); | ||
231 | } | ||
232 | |||
233 | void POP3account::save() | ||
234 | { | ||
235 | qDebug( "saving " + getFileName() ); | ||
236 | Settings::checkDirectory(); | ||
237 | |||
238 | Config *conf = new Config( getFileName(), Config::File ); | ||
239 | conf->setGroup( "POP3 Account" ); | ||
240 | conf->writeEntry( "Account", accountName ); | ||
241 | conf->writeEntry( "Server", server ); | ||
242 | conf->writeEntry( "Port", port ); | ||
243 | conf->writeEntry( "SSL", ssl ); | ||
244 | conf->writeEntry( "User", user ); | ||
245 | conf->writeEntryCrypt( "Password", password ); | ||
246 | conf->write(); | ||
247 | } | ||
248 | |||
249 | |||
250 | QString POP3account::getFileName() | ||
251 | { | ||
252 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/pop3-" + file; | ||
253 | } | ||
254 | |||
255 | SMTPaccount::SMTPaccount() | ||
256 | : Account() | ||
257 | { | ||
258 | file = SMTPaccount::getUniqueFileName(); | ||
259 | accountName = "New SMTP Account"; | ||
260 | ssl = false; | ||
261 | login = false; | ||
262 | useCC = false; | ||
263 | useBCC = false; | ||
264 | useReply = false; | ||
265 | type = "SMTP"; | ||
266 | port = SMTP_PORT; | ||
267 | } | ||
268 | |||
269 | SMTPaccount::SMTPaccount( QString filename ) | ||
270 | : Account() | ||
271 | { | ||
272 | file = filename; | ||
273 | accountName = "New SMTP Account"; | ||
274 | ssl = false; | ||
275 | login = false; | ||
276 | type = "SMTP"; | ||
277 | port = SMTP_PORT; | ||
278 | } | ||
279 | |||
280 | QString SMTPaccount::getUniqueFileName() | ||
281 | { | ||
282 | int num = 0; | ||
283 | QString unique; | ||
284 | |||
285 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
286 | |||
287 | QStringList imap = dir.entryList( "smtp-*" ); | ||
288 | do { | ||
289 | unique.setNum( num++ ); | ||
290 | } while ( imap.contains( "smtp-" + unique ) > 0 ); | ||
291 | |||
292 | return unique; | ||
293 | } | ||
294 | |||
295 | void SMTPaccount::read() | ||
296 | { | ||
297 | Config *conf = new Config( getFileName(), Config::File ); | ||
298 | conf->setGroup( "SMTP Account" ); | ||
299 | accountName = conf->readEntry( "Account" ); | ||
300 | server = conf->readEntry( "Server" ); | ||
301 | port = conf->readEntry( "Port" ); | ||
302 | ssl = conf->readBoolEntry( "SSL" ); | ||
303 | login = conf->readBoolEntry( "Login" ); | ||
304 | user = conf->readEntry( "User" ); | ||
305 | password = conf->readEntryCrypt( "Password" ); | ||
306 | } | ||
307 | |||
308 | void SMTPaccount::save() | ||
309 | { | ||
310 | qDebug( "saving " + getFileName() ); | ||
311 | Settings::checkDirectory(); | ||
312 | |||
313 | Config *conf = new Config( getFileName(), Config::File ); | ||
314 | conf->setGroup( "SMTP Account" ); | ||
315 | conf->writeEntry( "Account", accountName ); | ||
316 | conf->writeEntry( "Server", server ); | ||
317 | conf->writeEntry( "Port", port ); | ||
318 | conf->writeEntry( "SSL", ssl ); | ||
319 | conf->writeEntry( "Login", login ); | ||
320 | conf->writeEntry( "User", user ); | ||
321 | conf->writeEntryCrypt( "Password", password ); | ||
322 | conf->write(); | ||
323 | } | ||
324 | |||
325 | |||
326 | QString SMTPaccount::getFileName() | ||
327 | { | ||
328 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/smtp-" + file; | ||
329 | } | ||
330 | |||
331 | NNTPaccount::NNTPaccount() | ||
332 | : Account() | ||
333 | { | ||
334 | file = NNTPaccount::getUniqueFileName(); | ||
335 | accountName = "New NNTP Account"; | ||
336 | ssl = false; | ||
337 | login = false; | ||
338 | type = "NNTP"; | ||
339 | port = NNTP_PORT; | ||
340 | } | ||
341 | |||
342 | NNTPaccount::NNTPaccount( QString filename ) | ||
343 | : Account() | ||
344 | { | ||
345 | file = filename; | ||
346 | accountName = "New NNTP Account"; | ||
347 | ssl = false; | ||
348 | login = false; | ||
349 | type = "NNTP"; | ||
350 | port = NNTP_PORT; | ||
351 | } | ||
352 | |||
353 | QString NNTPaccount::getUniqueFileName() | ||
354 | { | ||
355 | int num = 0; | ||
356 | QString unique; | ||
357 | |||
358 | QDir dir( (QString) getenv( "HOME" ) + "/Applications/opiemail" ); | ||
359 | |||
360 | QStringList imap = dir.entryList( "nntp-*" ); | ||
361 | do { | ||
362 | unique.setNum( num++ ); | ||
363 | } while ( imap.contains( "nntp-" + unique ) > 0 ); | ||
364 | |||
365 | return unique; | ||
366 | } | ||
367 | |||
368 | void NNTPaccount::read() | ||
369 | { | ||
370 | Config *conf = new Config( getFileName(), Config::File ); | ||
371 | conf->setGroup( "NNTP Account" ); | ||
372 | accountName = conf->readEntry( "Account" ); | ||
373 | server = conf->readEntry( "Server" ); | ||
374 | port = conf->readEntry( "Port" ); | ||
375 | ssl = conf->readBoolEntry( "SSL" ); | ||
376 | login = conf->readBoolEntry( "Login" ); | ||
377 | user = conf->readEntry( "User" ); | ||
378 | password = conf->readEntryCrypt( "Password" ); | ||
379 | } | ||
380 | |||
381 | void NNTPaccount::save() | ||
382 | { | ||
383 | qDebug( "saving " + getFileName() ); | ||
384 | Settings::checkDirectory(); | ||
385 | |||
386 | Config *conf = new Config( getFileName(), Config::File ); | ||
387 | conf->setGroup( "NNTP Account" ); | ||
388 | conf->writeEntry( "Account", accountName ); | ||
389 | conf->writeEntry( "Server", server ); | ||
390 | conf->writeEntry( "Port", port ); | ||
391 | conf->writeEntry( "SSL", ssl ); | ||
392 | conf->writeEntry( "Login", login ); | ||
393 | conf->writeEntry( "User", user ); | ||
394 | conf->writeEntryCrypt( "Password", password ); | ||
395 | conf->write(); | ||
396 | } | ||
397 | |||
398 | |||
399 | QString NNTPaccount::getFileName() | ||
400 | { | ||
401 | return (QString) getenv( "HOME" ) + "/Applications/opiemail/nntp-" + file; | ||
402 | } | ||
403 | |||
diff --git a/noncore/net/mail/settings.h b/noncore/net/mail/settings.h deleted file mode 100644 index caa5dfc..0000000 --- a/noncore/net/mail/settings.h +++ b/dev/null | |||
@@ -1,146 +0,0 @@ | |||
1 | #ifndef SETTINGS_H | ||
2 | #define SETTINGS_H | ||
3 | |||
4 | #include <qobject.h> | ||
5 | #include <qlist.h> | ||
6 | |||
7 | class Account | ||
8 | { | ||
9 | |||
10 | public: | ||
11 | Account(); | ||
12 | virtual ~Account() {} | ||
13 | |||
14 | void remove(); | ||
15 | void setAccountName( QString name ) { accountName = name; } | ||
16 | const QString&getAccountName()const{ return accountName; } | ||
17 | const QString&getType()const{ return type; } | ||
18 | |||
19 | void setServer(const QString&str){ server = str; } | ||
20 | const QString&getServer()const{ return server; } | ||
21 | |||
22 | void setPort(const QString&str) { port = str; } | ||
23 | const QString&getPort()const{ return port; } | ||
24 | |||
25 | void setUser(const QString&str){ user = str; } | ||
26 | const QString&getUser()const{ return user; } | ||
27 | |||
28 | void setPassword(const QString&str) { password = str; } | ||
29 | const QString&getPassword()const { return password; } | ||
30 | |||
31 | void setSSL( bool b ) { ssl = b; } | ||
32 | bool getSSL() { return ssl; } | ||
33 | |||
34 | virtual QString getFileName() { return accountName; } | ||
35 | virtual void read() { qDebug( "base reading..." ); } | ||
36 | virtual void save() { qDebug( "base saving..." ); } | ||
37 | |||
38 | protected: | ||
39 | QString accountName, type, server, port, user, password; | ||
40 | bool ssl; | ||
41 | |||
42 | }; | ||
43 | |||
44 | class IMAPaccount : public Account | ||
45 | { | ||
46 | |||
47 | public: | ||
48 | IMAPaccount(); | ||
49 | IMAPaccount( QString filename ); | ||
50 | |||
51 | static QString getUniqueFileName(); | ||
52 | |||
53 | virtual void read(); | ||
54 | virtual void save(); | ||
55 | virtual QString getFileName(); | ||
56 | |||
57 | void setPrefix(const QString&str) {prefix=str;} | ||
58 | const QString&getPrefix()const{return prefix;} | ||
59 | |||
60 | private: | ||
61 | QString file,prefix; | ||
62 | |||
63 | }; | ||
64 | |||
65 | class POP3account : public Account | ||
66 | { | ||
67 | |||
68 | public: | ||
69 | POP3account(); | ||
70 | POP3account( QString filename ); | ||
71 | |||
72 | static QString getUniqueFileName(); | ||
73 | |||
74 | virtual void read(); | ||
75 | virtual void save(); | ||
76 | virtual QString getFileName(); | ||
77 | |||
78 | private: | ||
79 | QString file; | ||
80 | |||
81 | }; | ||
82 | |||
83 | class SMTPaccount : public Account | ||
84 | { | ||
85 | |||
86 | public: | ||
87 | SMTPaccount(); | ||
88 | SMTPaccount( QString filename ); | ||
89 | |||
90 | static QString getUniqueFileName(); | ||
91 | |||
92 | virtual void read(); | ||
93 | virtual void save(); | ||
94 | virtual QString getFileName(); | ||
95 | |||
96 | void setLogin( bool b ) { login = b; } | ||
97 | bool getLogin() { return login; } | ||
98 | |||
99 | private: | ||
100 | QString file, name, mail, org, cc, bcc, reply, signature; | ||
101 | bool useCC, useBCC, useReply, login; | ||
102 | |||
103 | }; | ||
104 | |||
105 | class NNTPaccount : public Account | ||
106 | { | ||
107 | |||
108 | public: | ||
109 | NNTPaccount(); | ||
110 | NNTPaccount( QString filename ); | ||
111 | |||
112 | static QString getUniqueFileName(); | ||
113 | |||
114 | virtual void read(); | ||
115 | virtual void save(); | ||
116 | virtual QString getFileName(); | ||
117 | |||
118 | void setLogin( bool b ) { login = b; } | ||
119 | bool getLogin() { return login; } | ||
120 | |||
121 | private: | ||
122 | QString file; | ||
123 | bool login; | ||
124 | |||
125 | }; | ||
126 | |||
127 | class Settings : public QObject | ||
128 | { | ||
129 | Q_OBJECT | ||
130 | |||
131 | public: | ||
132 | Settings(); | ||
133 | QList<Account> getAccounts(); | ||
134 | void addAccount(Account *account); | ||
135 | void delAccount(Account *account); | ||
136 | void saveAccounts(); | ||
137 | void readAccounts(); | ||
138 | static void checkDirectory(); | ||
139 | |||
140 | private: | ||
141 | void updateAccounts(); | ||
142 | QList<Account> accounts; | ||
143 | |||
144 | }; | ||
145 | |||
146 | #endif | ||