summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-04 01:53:04 (UTC)
committer alwin <alwin>2004-01-04 01:53:04 (UTC)
commit6fd109ed595e4e28f49f5de0a26e9f9445e672f6 (patch) (unidiff)
tree4bbd79045d003701bd6bdd649b1057fee9549fc6
parent4c9f71fba68fcf98b0b4c9b14b699282dfe962e5 (diff)
downloadopie-6fd109ed595e4e28f49f5de0a26e9f9445e672f6.zip
opie-6fd109ed595e4e28f49f5de0a26e9f9445e672f6.tar.gz
opie-6fd109ed595e4e28f49f5de0a26e9f9445e672f6.tar.bz2
moved to shared lib for usage with tody and taskbar plugin
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp94
-rw-r--r--noncore/net/mail/abstractmail.h53
-rw-r--r--noncore/net/mail/imapwrapper.cpp976
-rw-r--r--noncore/net/mail/imapwrapper.h68
-rw-r--r--noncore/net/mail/mailtypes.cpp335
-rw-r--r--noncore/net/mail/mailtypes.h192
-rw-r--r--noncore/net/mail/mboxwrapper.cpp324
-rw-r--r--noncore/net/mail/mboxwrapper.h42
-rw-r--r--noncore/net/mail/pop3wrapper.cpp229
-rw-r--r--noncore/net/mail/pop3wrapper.h39
-rw-r--r--noncore/net/mail/smtpwrapper.cpp732
-rw-r--r--noncore/net/mail/smtpwrapper.h71
12 files changed, 0 insertions, 3155 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
deleted file mode 100644
index f303d72..0000000
--- a/noncore/net/mail/abstractmail.cpp
+++ b/dev/null
@@ -1,94 +0,0 @@
1#include "abstractmail.h"
2#include "imapwrapper.h"
3#include "pop3wrapper.h"
4#include "mboxwrapper.h"
5#include "mailtypes.h"
6
7#include <qstring.h>
8#include <qfile.h>
9#include <qtextstream.h>
10#include <stdlib.h>
11#include <libetpan/mailmime_content.h>
12#include <libetpan/mailmime.h>
13
14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
15{
16 return new IMAPwrapper(a);
17}
18
19AbstractMail* AbstractMail::getWrapper(POP3account *a)
20{
21 return new POP3wrapper(a);
22}
23
24AbstractMail* AbstractMail::getWrapper(const QString&a)
25{
26 return new MBOXwrapper(a);
27}
28
29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
30{
31 qDebug("Decode string start");
32 char*result_text;
33 size_t index = 0;
34 /* reset for recursive use! */
35 size_t target_length = 0;
36 result_text = 0;
37 int mimetype = MAILMIME_MECHANISM_7BIT;
38 if (enc.lower()=="quoted-printable") {
39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
40 } else if (enc.lower()=="base64") {
41 mimetype = MAILMIME_MECHANISM_BASE64;
42 } else if (enc.lower()=="8bit") {
43 mimetype = MAILMIME_MECHANISM_8BIT;
44 } else if (enc.lower()=="binary") {
45 mimetype = MAILMIME_MECHANISM_BINARY;
46 }
47
48 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
49 &result_text,&target_length);
50
51 encodedString* result = new encodedString();
52 if (err == MAILIMF_NO_ERROR) {
53 result->setContent(result_text,target_length);
54 }
55 qDebug("Decode string finished");
56 return result;
57}
58
59QString AbstractMail::convert_String(const char*text)
60{
61 size_t index = 0;
62 char*res = 0;
63
64 /* attention - doesn't work with arm systems! */
65 int err = mailmime_encoded_phrase_parse("iso-8859-1",
66 text, strlen(text),&index, "iso-8859-1",&res);
67 if (err != MAILIMF_NO_ERROR) {
68 if (res) free(res);
69 return QString(text);
70 }
71 if (res) {
72 QString result(res);
73 free(res);
74 return result;
75 }
76 return QString(text);
77}
78
79/* cp & paste from launcher */
80QString AbstractMail::gen_attachment_id()
81{
82 QFile file( "/proc/sys/kernel/random/uuid" );
83 if (!file.open(IO_ReadOnly ) )
84 return QString::null;
85
86 QTextStream stream(&file);
87
88 return "{" + stream.read().stripWhiteSpace() + "}";
89}
90
91int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool)
92{
93 return 0;
94}
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
deleted file mode 100644
index dab9e10..0000000
--- a/noncore/net/mail/abstractmail.h
+++ b/dev/null
@@ -1,53 +0,0 @@
1#ifndef __abstract_mail_
2#define __abstract_mail_
3
4#include <qobject.h>
5#include "settings.h"
6
7class RecMail;
8class RecBody;
9class RecPart;
10class IMAPwrapper;
11class POP3wrapper;
12class Folder;
13class encodedString;
14struct folderStat;
15
16class AbstractMail:public QObject
17{
18 Q_OBJECT
19public:
20 AbstractMail(){};
21 virtual ~AbstractMail(){}
22 virtual QList<Folder>* listFolders()=0;
23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
25 virtual RecBody fetchBody(const RecMail&mail)=0;
26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
29
30 virtual void deleteMail(const RecMail&mail)=0;
31 virtual void answeredMail(const RecMail&mail)=0;
32 virtual void cleanMimeCache(){};
33 virtual int deleteAllMail(const Folder*){return 1;}
34 virtual int deleteMbox(const Folder*){return 1;}
35
36 /* mail box methods */
37 /* parameter is the box to create.
38 * if the implementing subclass has prefixes,
39 * them has to be appended automatic.
40 */
41 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
42
43 static AbstractMail* getWrapper(IMAPaccount *a);
44 static AbstractMail* getWrapper(POP3account *a);
45 /* mbox only! */
46 static AbstractMail* getWrapper(const QString&a);
47
48protected:
49 static encodedString*decode_String(const encodedString*text,const QString&enc);
50 static QString convert_String(const char*text);
51 static QString gen_attachment_id();
52};
53#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
deleted file mode 100644
index f1d42c2..0000000
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/dev/null
@@ -1,976 +0,0 @@
1#include <stdlib.h>
2#include <libetpan/libetpan.h>
3#include <qpe/global.h>
4
5#include "imapwrapper.h"
6#include "mailtypes.h"
7#include "logindialog.h"
8
9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
10 : AbstractMail()
11{
12 account = a;
13 m_imap = 0;
14}
15
16IMAPwrapper::~IMAPwrapper()
17{
18 logout();
19}
20
21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
22{
23 qDebug( "IMAP: %i of %i", current, maximum );
24}
25
26void IMAPwrapper::login()
27{
28 const char *server, *user, *pass;
29 uint16_t port;
30 int err = MAILIMAP_NO_ERROR;
31
32 /* we are connected this moment */
33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
34 if (m_imap) {
35 err = mailimap_noop(m_imap);
36 if (err!=MAILIMAP_NO_ERROR) {
37 logout();
38 } else {
39 mailstream_flush(m_imap->imap_stream);
40 return;
41 }
42 }
43 server = account->getServer().latin1();
44 port = account->getPort().toUInt();
45 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
46 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
47 login.show();
48 if ( QDialog::Accepted == login.exec() ) {
49 // ok
50 user = strdup( login.getUser().latin1() );
51 pass = strdup( login.getPassword().latin1() );
52 } else {
53 // cancel
54 qDebug( "IMAP: Login canceled" );
55 return;
56 }
57 } else {
58 user = account->getUser().latin1();
59 pass = account->getPassword().latin1();
60 }
61
62 m_imap = mailimap_new( 20, &imap_progress );
63
64 /* connect */
65 if (account->getSSL()) {
66 err = mailimap_ssl_connect( m_imap, (char*)server, port );
67 } else {
68 err = mailimap_socket_connect( m_imap, (char*)server, port );
69 }
70
71 if ( err != MAILIMAP_NO_ERROR &&
72 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
73 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
74 QString failure = "";
75 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
76 failure="Connection refused";
77 } else {
78 failure="Unknown failure";
79 }
80 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
81 mailimap_free( m_imap );
82 m_imap = 0;
83 return;
84 }
85
86 /* login */
87 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
88 if ( err != MAILIMAP_NO_ERROR ) {
89 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
90 err = mailimap_close( m_imap );
91 mailimap_free( m_imap );
92 m_imap = 0;
93 }
94}
95
96void IMAPwrapper::logout()
97{
98 int err = MAILIMAP_NO_ERROR;
99 if (!m_imap) return;
100 err = mailimap_logout( m_imap );
101 err = mailimap_close( m_imap );
102 mailimap_free( m_imap );
103 m_imap = 0;
104}
105
106void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
107{
108 const char *mb = 0;
109 int err = MAILIMAP_NO_ERROR;
110 clist *result = 0;
111 clistcell *current;
112// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
113 mailimap_fetch_type *fetchType = 0;
114 mailimap_set *set = 0;
115
116 mb = mailbox.latin1();
117 login();
118 if (!m_imap) {
119 return;
120 }
121 /* select mailbox READONLY for operations */
122 err = mailimap_examine( m_imap, (char*)mb);
123 if ( err != MAILIMAP_NO_ERROR ) {
124 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
125 return;
126 }
127
128 int last = m_imap->imap_selection_info->sel_exists;
129
130 if (last == 0) {
131 Global::statusMessage(tr("Mailbox has no mails"));
132 return;
133 } else {
134 Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
135 }
136
137 /* the range has to start at 1!!! not with 0!!!! */
138 set = mailimap_set_new_interval( 1, last );
139 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
140 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
141 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
142 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
143 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
144
145 err = mailimap_fetch( m_imap, set, fetchType, &result );
146 mailimap_set_free( set );
147 mailimap_fetch_type_free( fetchType );
148
149 QString date,subject,from;
150
151 if ( err == MAILIMAP_NO_ERROR ) {
152 mailimap_msg_att * msg_att;
153 int i = 0;
154 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
155 ++i;
156 msg_att = (mailimap_msg_att*)current->data;
157 RecMail*m = parse_list_result(msg_att);
158 if (m) {
159 m->setNumber(i);
160 m->setMbox(mailbox);
161 m->setWrapper(this);
162 target.append(m);
163 }
164 }
165 } else {
166 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
167 }
168 if (result) mailimap_fetch_list_free(result);
169}
170
171QList<Folder>* IMAPwrapper::listFolders()
172{
173 const char *path, *mask;
174 int err = MAILIMAP_NO_ERROR;
175 clist *result = 0;
176 clistcell *current = 0;
177 clistcell*cur_flag = 0;
178 mailimap_mbx_list_flags*bflags = 0;
179
180 QList<Folder> * folders = new QList<Folder>();
181 folders->setAutoDelete( false );
182 login();
183 if (!m_imap) {
184 return folders;
185 }
186
187/*
188 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
189 * We must not forget to filter them out in next loop!
190 * it seems like ugly code. and yes - it is ugly code. but the best way.
191 */
192 QString temp;
193 mask = "INBOX" ;
194 mailimap_mailbox_list *list;
195 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
196 QString del;
197 bool selectable = true;
198 bool no_inferiors = false;
199 if ( err == MAILIMAP_NO_ERROR ) {
200 current = result->first;
201 for ( int i = result->count; i > 0; i-- ) {
202 list = (mailimap_mailbox_list *) current->data;
203 // it is better use the deep copy mechanism of qt itself
204 // instead of using strdup!
205 temp = list->mb_name;
206 del = list->mb_delimiter;
207 current = current->next;
208 if ( (bflags = list->mb_flag) ) {
209 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
210 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
211 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
212 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
213 no_inferiors = true;
214 }
215 }
216 }
217 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
218 }
219 } else {
220 qDebug("error fetching folders: %s",m_imap->imap_response);
221 }
222 mailimap_list_result_free( result );
223
224/*
225 * second stage - get the other then inbox folders
226 */
227 mask = "*" ;
228 path = account->getPrefix().latin1();
229 if (!path) path = "";
230 qDebug(path);
231 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
232 if ( err == MAILIMAP_NO_ERROR ) {
233 current = result->first;
234 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
235 no_inferiors = false;
236 list = (mailimap_mailbox_list *) current->data;
237 // it is better use the deep copy mechanism of qt itself
238 // instead of using strdup!
239 temp = list->mb_name;
240 if (temp.lower()=="inbox")
241 continue;
242 if (temp.lower()==account->getPrefix().lower())
243 continue;
244 if ( (bflags = list->mb_flag) ) {
245 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
246 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
247 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
248 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
249 no_inferiors = true;
250 }
251 }
252 }
253 del = list->mb_delimiter;
254 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
255 }
256 } else {
257 qDebug("error fetching folders %s",m_imap->imap_response);
258 }
259 if (result) mailimap_list_result_free( result );
260 return folders;
261}
262
263RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
264{
265 RecMail * m = 0;
266 mailimap_msg_att_item *item=0;
267 clistcell *current,*c,*cf;
268 mailimap_msg_att_dynamic*flist;
269 mailimap_flag_fetch*cflag;
270 int size;
271 QBitArray mFlags(7);
272 QStringList addresslist;
273
274 if (!m_att) {
275 return m;
276 }
277 m = new RecMail();
278 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
279 current = c;
280 size = 0;
281 item = (mailimap_msg_att_item*)current->data;
282 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
283 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
284 if (!flist->att_list) {
285 continue;
286 }
287 cf = flist->att_list->first;
288 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
289 cflag = (mailimap_flag_fetch*)cf->data;
290 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
291 switch (cflag->fl_flag->fl_type) {
292 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
293 mFlags.setBit(FLAG_ANSWERED);
294 break;
295 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
296 mFlags.setBit(FLAG_FLAGGED);
297 break;
298 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
299 mFlags.setBit(FLAG_DELETED);
300 break;
301 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
302 mFlags.setBit(FLAG_SEEN);
303 break;
304 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
305 mFlags.setBit(FLAG_DRAFT);
306 break;
307 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
308 break;
309 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
310 break;
311 default:
312 break;
313 }
314 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
315 mFlags.setBit(FLAG_RECENT);
316 }
317 }
318 continue;
319 }
320 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
321 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
322 m->setDate(head->env_date);
323 m->setSubject(convert_String((const char*)head->env_subject));
324 //m->setSubject(head->env_subject);
325 if (head->env_from!=NULL) {
326 addresslist = address_list_to_stringlist(head->env_from->frm_list);
327 if (addresslist.count()) {
328 m->setFrom(addresslist.first());
329 }
330 }
331 if (head->env_to!=NULL) {
332 addresslist = address_list_to_stringlist(head->env_to->to_list);
333 m->setTo(addresslist);
334 }
335 if (head->env_cc!=NULL) {
336 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
337 m->setCC(addresslist);
338 }
339 if (head->env_bcc!=NULL) {
340 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
341 m->setBcc(addresslist);
342 }
343 if (head->env_reply_to!=NULL) {
344 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
345 if (addresslist.count()) {
346 m->setReplyto(addresslist.first());
347 }
348 }
349 m->setMsgid(QString(head->env_message_id));
350 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
351#if 0
352 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
353 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
354 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
355 qDebug(da.toString());
356#endif
357 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
358 size = item->att_data.att_static->att_data.att_rfc822_size;
359 }
360 }
361 /* msg is already deleted */
362 if (mFlags.testBit(FLAG_DELETED) && m) {
363 delete m;
364 m = 0;
365 }
366 if (m) {
367 m->setFlags(mFlags);
368 m->setMsgsize(size);
369 }
370 return m;
371}
372
373RecBody IMAPwrapper::fetchBody(const RecMail&mail)
374{
375 RecBody body;
376 const char *mb;
377 int err = MAILIMAP_NO_ERROR;
378 clist *result = 0;
379 clistcell *current;
380 mailimap_fetch_att *fetchAtt = 0;
381 mailimap_fetch_type *fetchType = 0;
382 mailimap_set *set = 0;
383 mailimap_body*body_desc = 0;
384
385 mb = mail.getMbox().latin1();
386
387 login();
388 if (!m_imap) {
389 return body;
390 }
391
392 err = mailimap_select( m_imap, (char*)mb);
393 if ( err != MAILIMAP_NO_ERROR ) {
394 qDebug("error selecting mailbox: %s",m_imap->imap_response);
395 return body;
396 }
397
398 /* the range has to start at 1!!! not with 0!!!! */
399 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
400 fetchAtt = mailimap_fetch_att_new_bodystructure();
401 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
402 err = mailimap_fetch( m_imap, set, fetchType, &result );
403 mailimap_set_free( set );
404 mailimap_fetch_type_free( fetchType );
405
406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
407 mailimap_msg_att * msg_att;
408 msg_att = (mailimap_msg_att*)current->data;
409 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
410 QValueList<int> path;
411 body_desc = item->att_data.att_static->att_data.att_body;
412 traverseBody(mail,body_desc,body,0,path);
413 } else {
414 qDebug("error fetching body: %s",m_imap->imap_response);
415 }
416 if (result) mailimap_fetch_list_free(result);
417 return body;
418}
419
420QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
421{
422 QStringList l;
423 QString from;
424 bool named_from;
425 clistcell *current = NULL;
426 mailimap_address * current_address=NULL;
427 if (!list) {
428 return l;
429 }
430 unsigned int count = 0;
431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
432 from = "";
433 named_from = false;
434 current_address=(mailimap_address*)current->data;
435 if (current_address->ad_personal_name){
436 from+=convert_String((const char*)current_address->ad_personal_name);
437 from+=" ";
438 named_from = true;
439 }
440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
441 from+="<";
442 }
443 if (current_address->ad_mailbox_name) {
444 from+=QString(current_address->ad_mailbox_name);
445 from+="@";
446 }
447 if (current_address->ad_host_name) {
448 from+=QString(current_address->ad_host_name);
449 }
450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
451 from+=">";
452 }
453 l.append(QString(from));
454 if (++count > 99) {
455 break;
456 }
457 }
458 return l;
459}
460
461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
462{
463 encodedString*res=new encodedString;
464 const char*mb;
465 int err;
466 mailimap_fetch_type *fetchType;
467 mailimap_set *set;
468 clistcell*current,*cur;
469
470 login();
471 if (!m_imap) {
472 return res;
473 }
474 if (!internal_call) {
475 mb = mail.getMbox().latin1();
476 err = mailimap_select( m_imap, (char*)mb);
477 if ( err != MAILIMAP_NO_ERROR ) {
478 qDebug("error selecting mailbox: %s",m_imap->imap_response);
479 return res;
480 }
481 }
482 set = mailimap_set_new_single(mail.getNumber());
483 clist*id_list=clist_new();
484 for (unsigned j=0; j < path.count();++j) {
485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
486 *p_id = path[j];
487 clist_append(id_list,p_id);
488 }
489 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
491 mailimap_section * section = mailimap_section_new(section_spec);
492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
493
494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
495
496 clist*result = 0;
497
498 err = mailimap_fetch( m_imap, set, fetchType, &result );
499 mailimap_set_free( set );
500 mailimap_fetch_type_free( fetchType );
501
502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
503 mailimap_msg_att * msg_att;
504 msg_att = (mailimap_msg_att*)current->data;
505 mailimap_msg_att_item*msg_att_item;
506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
511 /* detach - we take over the content */
512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
514 }
515 }
516 }
517 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response);
519 }
520 if (result) mailimap_fetch_list_free(result);
521 return res;
522}
523
524/* current_recursion is for recursive calls.
525 current_count means the position inside the internal loop! */
526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
527 int current_recursion,QValueList<int>recList,int current_count)
528{
529 if (!body || current_recursion>=10) {
530 return;
531 }
532 switch (body->bd_type) {
533 case MAILIMAP_BODY_1PART:
534 {
535 QValueList<int>countlist = recList;
536 countlist.append(current_count);
537 RecPart currentPart;
538 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
539 QString id("");
540 currentPart.setPositionlist(countlist);
541 for (unsigned int j = 0; j < countlist.count();++j) {
542 id+=(j>0?" ":"");
543 id+=QString("%1").arg(countlist[j]);
544 }
545 qDebug("ID = %s",id.latin1());
546 currentPart.setIdentifier(id);
547 fillSinglePart(currentPart,part1);
548 /* important: Check for is NULL 'cause a body can be empty!
549 And we put it only into the mail if it is the FIRST part */
550 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
551 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
552 target_body.setDescription(currentPart);
553 target_body.setBodytext(body_text);
554 if (countlist.count()>1) {
555 target_body.addPart(currentPart);
556 }
557 } else {
558 target_body.addPart(currentPart);
559 }
560 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
561 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
562 }
563 }
564 break;
565 case MAILIMAP_BODY_MPART:
566 {
567 QValueList<int>countlist = recList;
568 clistcell*current=0;
569 mailimap_body*current_body=0;
570 unsigned int ccount = 1;
571 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
572 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
573 current_body = (mailimap_body*)current->data;
574 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
575 RecPart targetPart;
576 targetPart.setType("multipart");
577 fillMultiPart(targetPart,mailDescription);
578 countlist.append(current_count);
579 targetPart.setPositionlist(countlist);
580 target_body.addPart(targetPart);
581 QString id("");
582 for (unsigned int j = 0; j < countlist.count();++j) {
583 id+=(j>0?" ":"");
584 id+=QString("%1").arg(countlist[j]);
585 }
586 qDebug("ID(mpart) = %s",id.latin1());
587 }
588 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
589 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
590 countlist = recList;
591 }
592 ++ccount;
593 }
594 }
595 break;
596 default:
597 break;
598 }
599}
600
601void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
602{
603 if (!Description) {
604 return;
605 }
606 switch (Description->bd_type) {
607 case MAILIMAP_BODY_TYPE_1PART_TEXT:
608 target_part.setType("text");
609 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
610 break;
611 case MAILIMAP_BODY_TYPE_1PART_BASIC:
612 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
613 break;
614 case MAILIMAP_BODY_TYPE_1PART_MSG:
615 target_part.setType("message");
616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
617 break;
618 default:
619 break;
620 }
621}
622
623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
624{
625 if (!which) {
626 return;
627 }
628 QString sub;
629 sub = which->bd_media_text;
630 qDebug("Type= text/%s",which->bd_media_text);
631 target_part.setSubtype(sub.lower());
632 target_part.setLines(which->bd_lines);
633 fillBodyFields(target_part,which->bd_fields);
634}
635
636void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
637{
638 if (!which) {
639 return;
640 }
641 target_part.setSubtype("rfc822");
642 qDebug("Message part");
643 /* we set this type to text/plain */
644 target_part.setLines(which->bd_lines);
645 fillBodyFields(target_part,which->bd_fields);
646}
647
648void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
649{
650 if (!which) return;
651 QString sub = which->bd_media_subtype;
652 target_part.setSubtype(sub.lower());
653 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
654 clistcell*cur = 0;
655 mailimap_single_body_fld_param*param=0;
656 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
657 param = (mailimap_single_body_fld_param*)cur->data;
658 if (param) {
659 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
660 }
661 }
662 }
663}
664
665void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
666{
667 if (!which) {
668 return;
669 }
670 QString type,sub;
671 switch (which->bd_media_basic->med_type) {
672 case MAILIMAP_MEDIA_BASIC_APPLICATION:
673 type = "application";
674 break;
675 case MAILIMAP_MEDIA_BASIC_AUDIO:
676 type = "audio";
677 break;
678 case MAILIMAP_MEDIA_BASIC_IMAGE:
679 type = "image";
680 break;
681 case MAILIMAP_MEDIA_BASIC_MESSAGE:
682 type = "message";
683 break;
684 case MAILIMAP_MEDIA_BASIC_VIDEO:
685 type = "video";
686 break;
687 case MAILIMAP_MEDIA_BASIC_OTHER:
688 default:
689 if (which->bd_media_basic->med_basic_type) {
690 type = which->bd_media_basic->med_basic_type;
691 } else {
692 type = "";
693 }
694 break;
695 }
696 if (which->bd_media_basic->med_subtype) {
697 sub = which->bd_media_basic->med_subtype;
698 } else {
699 sub = "";
700 }
701 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
702 target_part.setType(type.lower());
703 target_part.setSubtype(sub.lower());
704 fillBodyFields(target_part,which->bd_fields);
705}
706
707void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
708{
709 if (!which) return;
710 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
711 clistcell*cur;
712 mailimap_single_body_fld_param*param=0;
713 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
714 param = (mailimap_single_body_fld_param*)cur->data;
715 if (param) {
716 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
717 }
718 }
719 }
720 mailimap_body_fld_enc*enc = which->bd_encoding;
721 QString encoding("");
722 switch (enc->enc_type) {
723 case MAILIMAP_BODY_FLD_ENC_7BIT:
724 encoding = "7bit";
725 break;
726 case MAILIMAP_BODY_FLD_ENC_8BIT:
727 encoding = "8bit";
728 break;
729 case MAILIMAP_BODY_FLD_ENC_BINARY:
730 encoding="binary";
731 break;
732 case MAILIMAP_BODY_FLD_ENC_BASE64:
733 encoding="base64";
734 break;
735 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
736 encoding="quoted-printable";
737 break;
738 case MAILIMAP_BODY_FLD_ENC_OTHER:
739 default:
740 if (enc->enc_value) {
741 char*t=enc->enc_value;
742 encoding=QString(enc->enc_value);
743 enc->enc_value=0L;
744 free(t);
745 }
746 }
747 if (which->bd_description) {
748 target_part.setDescription(QString(which->bd_description));
749 }
750 target_part.setEncoding(encoding);
751 target_part.setSize(which->bd_size);
752}
753
754void IMAPwrapper::deleteMail(const RecMail&mail)
755{
756 mailimap_flag_list*flist;
757 mailimap_set *set;
758 mailimap_store_att_flags * store_flags;
759 int err;
760 login();
761 if (!m_imap) {
762 return;
763 }
764 const char *mb = mail.getMbox().latin1();
765 err = mailimap_select( m_imap, (char*)mb);
766 if ( err != MAILIMAP_NO_ERROR ) {
767 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
768 return;
769 }
770 flist = mailimap_flag_list_new_empty();
771 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
772 store_flags = mailimap_store_att_flags_new_set_flags(flist);
773 set = mailimap_set_new_single(mail.getNumber());
774 err = mailimap_store(m_imap,set,store_flags);
775 mailimap_set_free( set );
776 mailimap_store_att_flags_free(store_flags);
777
778 if (err != MAILIMAP_NO_ERROR) {
779 qDebug("error deleting mail: %s",m_imap->imap_response);
780 return;
781 }
782 qDebug("deleting mail: %s",m_imap->imap_response);
783 /* should we realy do that at this moment? */
784 err = mailimap_expunge(m_imap);
785 if (err != MAILIMAP_NO_ERROR) {
786 qDebug("error deleting mail: %s",m_imap->imap_response);
787 }
788 qDebug("Delete successfull %s",m_imap->imap_response);
789}
790
791void IMAPwrapper::answeredMail(const RecMail&mail)
792{
793 mailimap_flag_list*flist;
794 mailimap_set *set;
795 mailimap_store_att_flags * store_flags;
796 int err;
797 login();
798 if (!m_imap) {
799 return;
800 }
801 const char *mb = mail.getMbox().latin1();
802 err = mailimap_select( m_imap, (char*)mb);
803 if ( err != MAILIMAP_NO_ERROR ) {
804 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
805 return;
806 }
807 flist = mailimap_flag_list_new_empty();
808 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
809 store_flags = mailimap_store_att_flags_new_add_flags(flist);
810 set = mailimap_set_new_single(mail.getNumber());
811 err = mailimap_store(m_imap,set,store_flags);
812 mailimap_set_free( set );
813 mailimap_store_att_flags_free(store_flags);
814
815 if (err != MAILIMAP_NO_ERROR) {
816 qDebug("error marking mail: %s",m_imap->imap_response);
817 return;
818 }
819}
820
821QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
822{
823 QString body("");
824 encodedString*res = fetchRawPart(mail,path,internal_call);
825 encodedString*r = decode_String(res,enc);
826 delete res;
827 if (r) {
828 if (r->Length()>0) {
829 body = r->Content();
830 }
831 delete r;
832 }
833 return body;
834}
835
836QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
837{
838 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
839}
840
841encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
842{
843 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
844 encodedString*r = decode_String(res,part.Encoding());
845 delete res;
846 return r;
847}
848
849encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
850{
851 return fetchRawPart(mail,part.Positionlist(),false);
852}
853
854int IMAPwrapper::deleteAllMail(const Folder*folder)
855{
856 login();
857 if (!m_imap) {
858 return 0;
859 }
860 mailimap_flag_list*flist;
861 mailimap_set *set;
862 mailimap_store_att_flags * store_flags;
863 int err = mailimap_select( m_imap, folder->getName().latin1());
864 if ( err != MAILIMAP_NO_ERROR ) {
865 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
866 return 0;
867 }
868 int last = m_imap->imap_selection_info->sel_exists;
869 if (last == 0) {
870 Global::statusMessage(tr("Mailbox has no mails!"));
871 return 0;
872 }
873 flist = mailimap_flag_list_new_empty();
874 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
875 store_flags = mailimap_store_att_flags_new_set_flags(flist);
876 set = mailimap_set_new_interval( 1, last );
877 err = mailimap_store(m_imap,set,store_flags);
878 mailimap_set_free( set );
879 mailimap_store_att_flags_free(store_flags);
880 if (err != MAILIMAP_NO_ERROR) {
881 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
882 return 0;
883 }
884 qDebug("deleting mail: %s",m_imap->imap_response);
885 /* should we realy do that at this moment? */
886 err = mailimap_expunge(m_imap);
887 if (err != MAILIMAP_NO_ERROR) {
888 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
889 return 0;
890 }
891 qDebug("Delete successfull %s",m_imap->imap_response);
892 return 1;
893}
894
895int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
896{
897 if (folder.length()==0) return 0;
898 login();
899 if (!m_imap) {return 0;}
900 QString pre = account->getPrefix();
901 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
902 pre+=delemiter;
903 }
904 if (parentfolder) {
905 pre += parentfolder->getDisplayName()+delemiter;
906 }
907 pre+=folder;
908 if (getsubfolder) {
909 if (delemiter.length()>0) {
910 pre+=delemiter;
911 } else {
912 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
913 return 0;
914 }
915 }
916 qDebug("Creating %s",pre.latin1());
917 int res = mailimap_create(m_imap,pre.latin1());
918 if (res != MAILIMAP_NO_ERROR) {
919 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
920 return 0;
921 }
922 return 1;
923}
924
925int IMAPwrapper::deleteMbox(const Folder*folder)
926{
927 if (!folder) return 0;
928 login();
929 if (!m_imap) {return 0;}
930 int res = mailimap_delete(m_imap,folder->getName());
931 if (res != MAILIMAP_NO_ERROR) {
932 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
933 return 0;
934 }
935 return 1;
936}
937
938void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
939{
940 mailimap_status_att_list * att_list =0;
941 mailimap_mailbox_data_status * status=0;
942 clistiter * cur = 0;
943 int r = 0;
944 int res = 0;
945 target_stat.message_count = 0;
946 target_stat.message_unseen = 0;
947 target_stat.message_recent = 0;
948 login();
949 if (!m_imap) {
950 return;
951 }
952 att_list = mailimap_status_att_list_new_empty();
953 if (!att_list) return;
954 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
955 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
956 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
957 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
958 for (cur = clist_begin(status->st_info_list);
959 cur != NULL ; cur = clist_next(cur)) {
960 mailimap_status_info * status_info;
961 status_info = (mailimap_status_info *)clist_content(cur);
962 switch (status_info->st_att) {
963 case MAILIMAP_STATUS_ATT_MESSAGES:
964 target_stat.message_count = status_info->st_value;
965 break;
966 case MAILIMAP_STATUS_ATT_RECENT:
967 target_stat.message_recent = status_info->st_value;
968 break;
969 case MAILIMAP_STATUS_ATT_UNSEEN:
970 target_stat.message_unseen = status_info->st_value;
971 break;
972 }
973 }
974 mailimap_mailbox_data_status_free(status);
975 mailimap_status_att_list_free(att_list);
976}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
deleted file mode 100644
index 8f5a2b5..0000000
--- a/noncore/net/mail/imapwrapper.h
+++ b/dev/null
@@ -1,68 +0,0 @@
1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER
3
4#include <qlist.h>
5#include "mailwrapper.h"
6#include "abstractmail.h"
7#include <libetpan/clist.h>
8
9struct mailimap;
10struct mailimap_body;
11struct mailimap_body_type_1part;
12struct mailimap_body_type_text;
13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart;
16struct mailimap_body_fields;
17struct mailimap_msg_att;
18class encodedString;
19
20class IMAPwrapper : public AbstractMail
21{
22 Q_OBJECT
23public:
24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29
30 virtual void deleteMail(const RecMail&mail);
31 virtual void answeredMail(const RecMail&mail);
32 virtual int deleteAllMail(const Folder*folder);
33
34 virtual RecBody fetchBody(const RecMail&mail);
35 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
36 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
37 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
38
39 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
40 virtual int deleteMbox(const Folder*folder);
41
42 static void imap_progress( size_t current, size_t maximum );
43
44protected:
45 RecMail*parse_list_result(mailimap_msg_att*);
46 void login();
47 void logout();
48
49 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
50 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
51
52 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
53 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
54 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
55 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
56 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
57 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
58
59 /* just helpers */
60 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
61 static QStringList address_list_to_stringlist(clist*list);
62
63
64 IMAPaccount *account;
65 mailimap *m_imap;
66};
67
68#endif
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
deleted file mode 100644
index d8a36e7..0000000
--- a/noncore/net/mail/mailtypes.cpp
+++ b/dev/null
@@ -1,335 +0,0 @@
1#include "mailtypes.h"
2#include <stdlib.h>
3
4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{
7 init();
8}
9
10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{
13 init();
14 copy_old(old);
15 qDebug("Copy constructor RecMail");
16}
17
18RecMail::~RecMail()
19{
20 wrapper = 0;
21}
22
23void RecMail::copy_old(const RecMail&old)
24{
25 subject = old.subject;
26 date = old.date;
27 mbox = old.mbox;
28 msg_id = old.msg_id;
29 msg_size = old.msg_size;
30 msg_number = old.msg_number;
31 from = old.from;
32 msg_flags = old.msg_flags;
33 to = old.to;
34 cc = old.cc;
35 bcc = old.bcc;
36 wrapper = old.wrapper;
37}
38
39void RecMail::init()
40{
41 to.clear();
42 cc.clear();
43 bcc.clear();
44 wrapper = 0;
45}
46
47void RecMail::setWrapper(AbstractMail*awrapper)
48{
49 wrapper = awrapper;
50}
51
52AbstractMail* RecMail::Wrapper()
53{
54 return wrapper;
55}
56
57void RecMail::setTo(const QStringList&list)
58{
59 to = list;
60}
61
62const QStringList&RecMail::To()const
63{
64 return to;
65}
66
67void RecMail::setCC(const QStringList&list)
68{
69 cc = list;
70}
71
72const QStringList&RecMail::CC()const
73{
74 return cc;
75}
76
77void RecMail::setBcc(const QStringList&list)
78{
79 bcc = list;
80}
81
82const QStringList& RecMail::Bcc()const
83{
84 return bcc;
85}
86
87RecPart::RecPart()
88 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
89{
90 m_Parameters.clear();
91 m_poslist.clear();
92}
93
94RecPart::~RecPart()
95{
96}
97
98void RecPart::setSize(unsigned int size)
99{
100 m_size = size;
101}
102
103const unsigned int RecPart::Size()const
104{
105 return m_size;
106}
107
108void RecPart::setLines(unsigned int lines)
109{
110 m_lines = lines;
111}
112
113const unsigned int RecPart::Lines()const
114{
115 return m_lines;
116}
117
118const QString& RecPart::Type()const
119{
120 return m_type;
121}
122
123void RecPart::setType(const QString&type)
124{
125 m_type = type;
126}
127
128const QString& RecPart::Subtype()const
129{
130 return m_subtype;
131}
132
133void RecPart::setSubtype(const QString&subtype)
134{
135 m_subtype = subtype;
136}
137
138const QString& RecPart::Identifier()const
139{
140 return m_identifier;
141}
142
143void RecPart::setIdentifier(const QString&identifier)
144{
145 m_identifier = identifier;
146}
147
148const QString& RecPart::Encoding()const
149{
150 return m_encoding;
151}
152
153void RecPart::setEncoding(const QString&encoding)
154{
155 m_encoding = encoding;
156}
157
158const QString& RecPart::Description()const
159{
160 return m_description;
161}
162
163void RecPart::setDescription(const QString&desc)
164{
165 m_description = desc;
166}
167
168void RecPart::setParameters(const part_plist_t&list)
169{
170 m_Parameters = list;
171}
172
173const part_plist_t& RecPart::Parameters()const
174{
175 return m_Parameters;
176}
177
178void RecPart::addParameter(const QString&key,const QString&value)
179{
180 m_Parameters[key]=value;
181}
182
183const QString RecPart::searchParamter(const QString&key)const
184{
185 QString value("");
186 part_plist_t::ConstIterator it = m_Parameters.find(key);
187 if (it != m_Parameters.end()) {
188 value = it.data();
189 }
190 return value;
191}
192
193void RecPart::setPositionlist(const QValueList<int>&poslist)
194{
195 m_poslist = poslist;
196}
197
198const QValueList<int>& RecPart::Positionlist()const
199{
200 return m_poslist;
201}
202
203RecBody::RecBody()
204 : m_BodyText(),m_PartsList(),m_description()
205{
206 m_PartsList.clear();
207}
208
209RecBody::~RecBody()
210{
211}
212
213void RecBody::setBodytext(const QString&bodyText)
214{
215 m_BodyText = bodyText;
216}
217
218const QString& RecBody::Bodytext()const
219{
220 return m_BodyText;
221}
222
223void RecBody::setParts(const QValueList<RecPart>&parts)
224{
225 m_PartsList.clear();
226 m_PartsList = parts;
227}
228
229const QValueList<RecPart>& RecBody::Parts()const
230{
231 return m_PartsList;
232}
233
234void RecBody::addPart(const RecPart& part)
235{
236 m_PartsList.append(part);
237}
238
239void RecBody::setDescription(const RecPart&des)
240{
241 m_description = des;
242}
243
244const RecPart& RecBody::Description()const
245{
246 return m_description;
247}
248
249/* handling encoded content */
250encodedString::encodedString()
251{
252 init();
253}
254
255encodedString::encodedString(const char*nContent,unsigned int nSize)
256{
257 init();
258 setContent(nContent,nSize);
259}
260
261encodedString::encodedString(char*nContent,unsigned int nSize)
262{
263 init();
264 setContent(nContent,nSize);
265}
266
267encodedString::encodedString(const encodedString&old)
268{
269 init();
270 copy_old(old);
271 qDebug("encodedeString: copy constructor!");
272}
273
274encodedString& encodedString::operator=(const encodedString&old)
275{
276 init();
277 copy_old(old);
278 qDebug("encodedString: assign operator!");
279 return *this;
280}
281
282encodedString::~encodedString()
283{
284 clean();
285}
286
287void encodedString::init()
288{
289 content = 0;
290 size = 0;
291}
292
293void encodedString::clean()
294{
295 if (content) {
296 free(content);
297 }
298 content = 0;
299 size = 0;
300}
301
302void encodedString::copy_old(const encodedString&old)
303{
304 clean();
305 if (old.size>0 && old.content) {
306 content = (char*)malloc(old.size*sizeof(char));
307 memcpy(content,old.content,size);
308 size = old.size;
309 }
310}
311
312const char*encodedString::Content()const
313{
314 return content;
315}
316
317const int encodedString::Length()const
318{
319 return size;
320}
321
322void encodedString::setContent(const char*nContent,int nSize)
323{
324 if (nSize>0 && nContent) {
325 content = (char*)malloc(nSize*sizeof(char));
326 memcpy(content,nContent,nSize);
327 size = nSize;
328 }
329}
330
331void encodedString::setContent(char*nContent,int nSize)
332{
333 content = nContent;
334 size = nSize;
335}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
deleted file mode 100644
index 05c4816..0000000
--- a/noncore/net/mail/mailtypes.h
+++ b/dev/null
@@ -1,192 +0,0 @@
1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H
3
4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2
7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5
10
11#include <qlist.h>
12#include <qbitarray.h>
13#include <qstring.h>
14#include <qstringlist.h>
15#include <qmap.h>
16#include <qvaluelist.h>
17
18class AbstractMail;
19/* a class to describe mails in a mailbox */
20/* Attention!
21 From programmers point of view it would make sense to
22 store the mail body into this class, too.
23 But: not from the point of view of the device.
24 Mailbodies can be real large. So we request them when
25 needed from the mail-wrapper class direct from the server itself
26 (imap) or from a file-based cache (pop3?)
27 So there is no interface "const QString&body()" but you should
28 make a request to the mailwrapper with this class as parameter to
29 get the body. Same words for the attachments.
30*/
31class RecMail
32{
33public:
34 RecMail();
35 RecMail(const RecMail&old);
36 virtual ~RecMail();
37
38 const int getNumber()const{return msg_number;}
39 void setNumber(int number){msg_number=number;}
40 const QString&getDate()const{ return date; }
41 void setDate( const QString&a ) { date = a; }
42 const QString&getFrom()const{ return from; }
43 void setFrom( const QString&a ) { from = a; }
44 const QString&getSubject()const { return subject; }
45 void setSubject( const QString&s ) { subject = s; }
46 const QString&getMbox()const{return mbox;}
47 void setMbox(const QString&box){mbox = box;}
48 void setMsgid(const QString&id){msg_id=id;}
49 const QString&Msgid()const{return msg_id;}
50 void setReplyto(const QString&reply){replyto=reply;}
51 const QString&Replyto()const{return replyto;}
52 void setMsgsize(int size){msg_size = size;}
53 const int Msgsize()const{return msg_size;}
54
55
56 void setTo(const QStringList&list);
57 const QStringList&To()const;
58 void setCC(const QStringList&list);
59 const QStringList&CC()const;
60 void setBcc(const QStringList&list);
61 const QStringList&Bcc()const;
62 const QBitArray&getFlags()const{return msg_flags;}
63 void setFlags(const QBitArray&flags){msg_flags = flags;}
64
65 void setWrapper(AbstractMail*wrapper);
66 AbstractMail* Wrapper();
67
68protected:
69 QString subject,date,from,mbox,msg_id,replyto;
70 int msg_number,msg_size;
71 QBitArray msg_flags;
72 QStringList to,cc,bcc;
73 AbstractMail*wrapper;
74 void init();
75 void copy_old(const RecMail&old);
76};
77
78typedef QMap<QString,QString> part_plist_t;
79
80class RecPart
81{
82protected:
83 QString m_type,m_subtype,m_identifier,m_encoding,m_description;
84 unsigned int m_lines,m_size;
85 part_plist_t m_Parameters;
86 /* describes the position in the mail */
87 QValueList<int> m_poslist;
88
89public:
90 RecPart();
91 virtual ~RecPart();
92
93 const QString&Type()const;
94 void setType(const QString&type);
95 const QString&Subtype()const;
96 void setSubtype(const QString&subtype);
97 const QString&Identifier()const;
98 void setIdentifier(const QString&identifier);
99 const QString&Encoding()const;
100 void setEncoding(const QString&encoding);
101 const QString&Description()const;
102 void setDescription(const QString&desc);
103 void setLines(unsigned int lines);
104 const unsigned int Lines()const;
105 void setSize(unsigned int size);
106 const unsigned int Size()const;
107
108
109 void setParameters(const part_plist_t&list);
110 const part_plist_t&Parameters()const;
111 void addParameter(const QString&key,const QString&value);
112 const QString searchParamter(const QString&key)const;
113 void setPositionlist(const QValueList<int>&poslist);
114 const QValueList<int>& Positionlist()const;
115};
116
117class RecBody
118{
119protected:
120 QString m_BodyText;
121 QValueList<RecPart> m_PartsList;
122 RecPart m_description;
123
124public:
125 RecBody();
126 virtual ~RecBody();
127 void setBodytext(const QString&);
128 const QString& Bodytext()const;
129
130 void setDescription(const RecPart&des);
131 const RecPart& Description()const;
132
133 void setParts(const QValueList<RecPart>&parts);
134 const QValueList<RecPart>& Parts()const;
135 void addPart(const RecPart&part);
136};
137
138class encodedString
139{
140public:
141 encodedString();
142 /*
143 creates an new content string.
144 it makes a deep copy of it!
145 */
146 encodedString(const char*nContent,unsigned int length);
147 /*
148 Take over the nContent. Means: it will just copy the pointer, not the content.
149 so make sure: No one else frees the string, the string has allocated with
150 malloc for compatibility with c-based libs
151 */
152 encodedString(char*nContent,unsigned int nSize);
153 /* copy construkor - makes ALWAYS a deep copy!!!! */
154 encodedString(const encodedString&old);
155 /* assign operator - makes ALWAYS a deep copy!!!! */
156 encodedString& operator=(const encodedString&old);
157 /* destructor - cleans the content */
158 virtual ~encodedString();
159
160 /* returns a pointer to the content - do not delete yoursel! */
161 const char*Content()const;
162 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
163 const int Length()const;
164
165 /*
166 makes a deep copy of nContent!
167 */
168 void setContent(const char*nContent,int nSize);
169 /*
170 Take over the nContent. Means: it will just copy the pointer, not the content.
171 so make sure: No one else frees the string, the string has allocated with
172 malloc for compatibility with c-based libs
173 */
174 void setContent(char*nContent,int nSize);
175
176protected:
177 char * content;
178 unsigned int size;
179
180 void init();
181 void copy_old(const encodedString&old);
182 void clean();
183};
184
185struct folderStat
186{
187 unsigned int message_count;
188 unsigned int message_unseen;
189 unsigned int message_recent;
190};
191
192#endif
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
9MBOXwrapper::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
18MBOXwrapper::~MBOXwrapper()
19{
20}
21
22void 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
47QList<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
63void 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
86void MBOXwrapper::answeredMail(const RecMail&)
87{
88}
89
90RecBody 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
133void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
134{
135 qDebug("MBOX %i von %i",current,maximum);
136}
137
138int 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
156void 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
173void 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
215void 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
229void 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
245int 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
288int 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
304void 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}
diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h
deleted file mode 100644
index f822997..0000000
--- a/noncore/net/mail/mboxwrapper.h
+++ b/dev/null
@@ -1,42 +0,0 @@
1#ifndef __MBOX_WRAPPER_H
2#define __MBOX_WRAPPER_H
3
4#include "genericwrapper.h"
5#include <qstring.h>
6
7class RecMail;
8class RecBody;
9struct mailmbox_folder;
10
11class MBOXwrapper : public Genericwrapper
12{
13 Q_OBJECT
14public:
15 MBOXwrapper(const QString & dir);
16 virtual ~MBOXwrapper();
17
18 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
19 virtual QList<Folder>* listFolders();
20 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
21
22 virtual void deleteMail(const RecMail&mail);
23 virtual void answeredMail(const RecMail&mail);
24
25 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
26 virtual int deleteMbox(const Folder*);
27
28 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
29
30 virtual RecBody fetchBody( const RecMail &mail );
31 static void mbox_progress( size_t current, size_t maximum );
32
33 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length);
34 virtual void deleteMails(const QString & mailbox,QList<RecMail> &target);
35 virtual int deleteAllMail(const Folder*);
36
37protected:
38 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target);
39 QString MBOXPath;
40};
41
42#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
deleted file mode 100644
index d76d82a..0000000
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/dev/null
@@ -1,229 +0,0 @@
1#include <stdlib.h>
2#include "pop3wrapper.h"
3#include "mailtypes.h"
4#include "logindialog.h"
5#include <libetpan/libetpan.h>
6#include <qpe/global.h>
7#include <qfile.h>
8#include <qstring.h>
9
10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880
12
13POP3wrapper::POP3wrapper( POP3account *a )
14 : Genericwrapper()
15{
16 account = a;
17 m_pop3 = NULL;
18 m_folder = NULL;
19 msgTempName = a->getFileName()+"_msg_cache";
20 last_msg_id = 0;
21}
22
23POP3wrapper::~POP3wrapper()
24{
25 logout();
26 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) {
28 msg_cache.remove();
29 }
30}
31
32void POP3wrapper::pop3_progress( size_t current, size_t maximum )
33{
34 qDebug( "POP3: %i of %i", current, maximum );
35}
36
37RecBody POP3wrapper::fetchBody( const RecMail &mail )
38{
39 int err = MAILPOP3_NO_ERROR;
40 char *message = 0;
41 size_t length = 0;
42
43 login();
44 if ( !m_pop3 ) {
45 return RecBody();
46 }
47
48 RecBody body;
49 mailmessage * mailmsg;
50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
51 qDebug("Message to large: %i",mail.Msgsize());
52 return body;
53 }
54
55 QFile msg_cache(msgTempName);
56
57 cleanMimeCache();
58
59 if (mail.getNumber()!=last_msg_id) {
60 if (msg_cache.exists()) {
61 msg_cache.remove();
62 }
63 msg_cache.open(IO_ReadWrite|IO_Truncate);
64 last_msg_id = mail.getNumber();
65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
66 err = mailmessage_fetch(mailmsg,&message,&length);
67 msg_cache.writeBlock(message,length);
68 } else {
69 QString msg="";
70 msg_cache.open(IO_ReadOnly);
71 message = new char[4096];
72 memset(message,0,4096);
73 while (msg_cache.readBlock(message,4095)>0) {
74 msg+=message;
75 memset(message,0,4096);
76 }
77 delete message;
78 message = (char*)malloc(msg.length()+1*sizeof(char));
79 memset(message,0,msg.length()+1);
80 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message);
89 }
90 body = parseMail(mailmsg);
91
92 /* clean up */
93 if (mailmsg) mailmessage_free(mailmsg);
94 if (message) free(message);
95
96 return body;
97}
98
99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
100{
101 login();
102 if (!m_pop3) return;
103 uint32_t res_messages,res_recent,res_unseen;
104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
105 parseList(target,m_folder->fld_session,"INBOX");
106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
107}
108
109void POP3wrapper::login()
110{
111 /* we'll hold the line */
112 if ( m_pop3 != NULL ) return;
113
114 const char *server, *user, *pass;
115 uint16_t port;
116 int err = MAILPOP3_NO_ERROR;
117
118 server = account->getServer().latin1();
119 port = account->getPort().toUInt();
120
121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
123 login.show();
124 if ( QDialog::Accepted == login.exec() ) {
125 // ok
126 user = login.getUser().latin1();
127 pass = login.getPassword().latin1();
128 } else {
129 // cancel
130 qDebug( "POP3: Login canceled" );
131 return;
132 }
133 } else {
134 user = account->getUser().latin1();
135 pass = account->getPassword().latin1();
136 }
137
138 bool ssl = account->getSSL();
139
140 m_pop3=mailstorage_new(NULL);
141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
142 (char*)user,(char*)pass,0,0,0);
143
144 m_folder = mailfolder_new(m_pop3, NULL, NULL);
145
146 if (m_folder==0) {
147 Global::statusMessage(tr("Error initializing folder"));
148 mailstorage_free(m_pop3);
149 m_pop3 = NULL;
150 return;
151 }
152 err = mailfolder_connect(m_folder);
153 if (err != MAIL_NO_ERROR) {
154 Global::statusMessage(tr("Error initializing folder"));
155 mailfolder_free(m_folder);
156 m_folder = 0;
157 mailstorage_free(m_pop3);
158 m_pop3 = 0;
159 }
160 qDebug( "POP3: logged in!" );
161}
162
163void POP3wrapper::logout()
164{
165 int err = MAILPOP3_NO_ERROR;
166 if ( m_pop3 == NULL ) return;
167 mailfolder_free(m_folder);
168 m_folder = 0;
169 mailstorage_free(m_pop3);
170 m_pop3 = 0;
171}
172
173
174QList<Folder>* POP3wrapper::listFolders()
175{
176 QList<Folder> * folders = new QList<Folder>();
177 folders->setAutoDelete( false );
178 Folder*inb=new Folder("INBOX","/");
179 folders->append(inb);
180 return folders;
181}
182
183void POP3wrapper::deleteMail(const RecMail&mail)
184{
185 login();
186 if (!m_pop3) return;
187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
188 if (err != MAIL_NO_ERROR) {
189 Global::statusMessage(tr("error deleting mail"));
190 }
191}
192
193void POP3wrapper::answeredMail(const RecMail&)
194{
195}
196
197int POP3wrapper::deleteAllMail(const Folder*)
198{
199 login();
200 if (!m_pop3) return 0;
201 int res = 1;
202
203 uint32_t result = 0;
204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
205 if (err != MAIL_NO_ERROR) {
206 Global::statusMessage(tr("Error getting folder info"));
207 return 0;
208 }
209 for (unsigned int i = 0; i < result; ++i) {
210 err = mailsession_remove_message(m_folder->fld_session,i+1);
211 if (err != MAIL_NO_ERROR) {
212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
213 res=0;
214 }
215 break;
216 }
217 return res;
218}
219
220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&)
221{
222 login();
223 target_stat.message_count = 0;
224 target_stat.message_unseen = 0;
225 target_stat.message_recent = 0;
226 if (!m_pop3) return;
227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count,
228 &target_stat.message_recent,&target_stat.message_unseen);
229}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
deleted file mode 100644
index 536cadc..0000000
--- a/noncore/net/mail/pop3wrapper.h
+++ b/dev/null
@@ -1,39 +0,0 @@
1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER
3
4#include "mailwrapper.h"
5#include "genericwrapper.h"
6#include <qstring.h>
7
8struct mailstorage;
9struct mailfolder;
10
11class POP3wrapper : public Genericwrapper
12{
13 Q_OBJECT
14
15public:
16 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper();
18 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders();
21 /* mailbox will be ignored */
22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
23
24 virtual void deleteMail(const RecMail&mail);
25 virtual void answeredMail(const RecMail&mail);
26 virtual int deleteAllMail(const Folder*);
27
28 virtual RecBody fetchBody( const RecMail &mail );
29 static void pop3_progress( size_t current, size_t maximum );
30
31protected:
32 void login();
33 void logout();
34 POP3account *account;
35 mailstorage*m_pop3;
36 mailfolder*m_folder;
37};
38
39#endif
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp
deleted file mode 100644
index 7e03af9..0000000
--- a/noncore/net/mail/smtpwrapper.cpp
+++ b/dev/null
@@ -1,732 +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#include <qt.h>
9
10#include <qpe/config.h>
11#include <qpe/qcopenvelope_qws.h>
12
13#include <libetpan/libetpan.h>
14
15#include "smtpwrapper.h"
16#include "mailwrapper.h"
17#include "mboxwrapper.h"
18#include "logindialog.h"
19#include "mailtypes.h"
20#include "defines.h"
21#include "sendmailprogress.h"
22
23progressMailSend*SMTPwrapper::sendProgress = 0;
24
25SMTPwrapper::SMTPwrapper( Settings *s )
26 : QObject()
27{
28 settings = s;
29 Config cfg( "mail" );
30 cfg.setGroup( "Status" );
31 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
32 emit queuedMails( m_queuedMail );
33 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
34}
35
36void SMTPwrapper::emitQCop( int queued ) {
37 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
38 env << queued;
39}
40
41QString SMTPwrapper::mailsmtpError( int errnum )
42{
43 switch ( errnum ) {
44 case MAILSMTP_NO_ERROR:
45 return tr( "No error" );
46 case MAILSMTP_ERROR_UNEXPECTED_CODE:
47 return tr( "Unexpected error code" );
48 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
49 return tr( "Service not available" );
50 case MAILSMTP_ERROR_STREAM:
51 return tr( "Stream error" );
52 case MAILSMTP_ERROR_HOSTNAME:
53 return tr( "gethostname() failed" );
54 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
55 return tr( "Not implemented" );
56 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
57 return tr( "Error, action not taken" );
58 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
59 return tr( "Data exceeds storage allocation" );
60 case MAILSMTP_ERROR_IN_PROCESSING:
61 return tr( "Error in processing" );
62 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
63 // return tr( "Insufficient system storage" );
64 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
65 return tr( "Mailbox unavailable" );
66 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
67 return tr( "Mailbox name not allowed" );
68 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
69 return tr( "Bad command sequence" );
70 case MAILSMTP_ERROR_USER_NOT_LOCAL:
71 return tr( "User not local" );
72 case MAILSMTP_ERROR_TRANSACTION_FAILED:
73 return tr( "Transaction failed" );
74 case MAILSMTP_ERROR_MEMORY:
75 return tr( "Memory error" );
76 case MAILSMTP_ERROR_CONNECTION_REFUSED:
77 return tr( "Connection refused" );
78 default:
79 return tr( "Unknown error code" );
80 }
81}
82
83mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail )
84{
85 return mailimf_mailbox_new( strdup( name.latin1() ),
86 strdup( mail.latin1() ) );
87}
88
89mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
90{
91 mailimf_address_list *addresses;
92
93 if ( addr.isEmpty() ) return NULL;
94
95 addresses = mailimf_address_list_new_empty();
96
97 bool literal_open = false;
98 unsigned int startpos = 0;
99 QStringList list;
100 QString s;
101 unsigned int i = 0;
102 for (; i < addr.length();++i) {
103 switch (addr[i]) {
104 case '\"':
105 literal_open = !literal_open;
106 break;
107 case ',':
108 if (!literal_open) {
109 s = addr.mid(startpos,i-startpos);
110 if (!s.isEmpty()) {
111 list.append(s);
112 qDebug("Appended %s",s.latin1());
113 }
114 // !!!! this is a MUST BE!
115 startpos = ++i;
116 }
117 break;
118 default:
119 break;
120 }
121 }
122 s = addr.mid(startpos,i-startpos);
123 if (!s.isEmpty()) {
124 list.append(s);
125 qDebug("Appended %s",s.latin1());
126 }
127 QStringList::Iterator it;
128 for ( it = list.begin(); it != list.end(); it++ ) {
129 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
130 if ( err != MAILIMF_NO_ERROR ) {
131 qDebug( "Error parsing" );
132 qDebug( *it );
133 } else {
134 qDebug( "Parse success! %s",(*it).latin1());
135 }
136 }
137 return addresses;
138}
139
140mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
141{
142 mailimf_fields *fields;
143 mailimf_field *xmailer;
144 mailimf_mailbox *sender=0,*fromBox=0;
145 mailimf_mailbox_list *from=0;
146 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
147 char *subject = strdup( mail.getSubject().latin1() );
148 int err;
149
150 sender = newMailbox( mail.getName(), mail.getMail() );
151 if ( sender == NULL ) goto err_free;
152
153 fromBox = newMailbox( mail.getName(), mail.getMail() );
154 if ( fromBox == NULL ) goto err_free_sender;
155
156 from = mailimf_mailbox_list_new_empty();
157 if ( from == NULL ) goto err_free_fromBox;
158
159 err = mailimf_mailbox_list_add( from, fromBox );
160 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
161
162 to = parseAddresses( mail.getTo() );
163 if ( to == NULL ) goto err_free_from;
164
165 cc = parseAddresses( mail.getCC() );
166 bcc = parseAddresses( mail.getBCC() );
167 reply = parseAddresses( mail.getReply() );
168
169 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
170 NULL, NULL, subject );
171 if ( fields == NULL ) goto err_free_reply;
172
173 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
174 strdup( USER_AGENT ) );
175 if ( xmailer == NULL ) goto err_free_fields;
176
177 err = mailimf_fields_add( fields, xmailer );
178 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
179
180 return fields; // Success :)
181
182err_free_xmailer:
183 if (xmailer) mailimf_field_free( xmailer );
184err_free_fields:
185 if (fields) mailimf_fields_free( fields );
186err_free_reply:
187 if (reply) mailimf_address_list_free( reply );
188 if (bcc) mailimf_address_list_free( bcc );
189 if (cc) mailimf_address_list_free( cc );
190 if (to) mailimf_address_list_free( to );
191err_free_from:
192 if (from) mailimf_mailbox_list_free( from );
193err_free_fromBox:
194 mailimf_mailbox_free( fromBox );
195err_free_sender:
196 if (sender) mailimf_mailbox_free( sender );
197err_free:
198 if (subject) free( subject );
199 qDebug( "createImfFields - error" );
200
201 return NULL; // Error :(
202}
203
204mailmime *SMTPwrapper::buildTxtPart(const QString&str )
205{
206 mailmime *txtPart;
207 mailmime_fields *fields;
208 mailmime_content *content;
209 mailmime_parameter *param;
210 int err;
211
212 param = mailmime_parameter_new( strdup( "charset" ),
213 strdup( "iso-8859-1" ) );
214 if ( param == NULL ) goto err_free;
215
216 content = mailmime_content_new_with_str( "text/plain" );
217 if ( content == NULL ) goto err_free_param;
218
219 err = clist_append( content->ct_parameters, param );
220 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
221
222 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
223 if ( fields == NULL ) goto err_free_content;
224
225 txtPart = mailmime_new_empty( content, fields );
226 if ( txtPart == NULL ) goto err_free_fields;
227
228 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
229 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
230
231 return txtPart; // Success :)
232
233err_free_txtPart:
234 mailmime_free( txtPart );
235err_free_fields:
236 mailmime_fields_free( fields );
237err_free_content:
238 mailmime_content_free( content );
239err_free_param:
240 mailmime_parameter_free( param );
241err_free:
242 qDebug( "buildTxtPart - error" );
243
244 return NULL; // Error :(
245}
246
247mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent )
248{
249 mailmime * filePart = 0;
250 mailmime_fields * fields = 0;
251 mailmime_content * content = 0;
252 mailmime_parameter * param = 0;
253 char*name = 0;
254 char*file = 0;
255 int err;
256
257 int pos = filename.findRev( '/' );
258
259 if (filename.length()>0) {
260 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
261 name = strdup( tmp.latin1() ); // just filename
262 file = strdup( filename.latin1() ); // full name with path
263 }
264
265 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
266 int mechanism = MAILMIME_MECHANISM_BASE64;
267
268 if ( mimetype.startsWith( "text/" ) ) {
269 param = mailmime_parameter_new( strdup( "charset" ),
270 strdup( "iso-8859-1" ) );
271 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
272 }
273
274 fields = mailmime_fields_new_filename(
275 disptype, name,
276 mechanism );
277 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
278 if (content!=0 && fields != 0) {
279 if (param) {
280 clist_append(content->ct_parameters,param);
281 param = 0;
282 }
283 if (filename.length()>0) {
284 QFileInfo f(filename);
285 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
286 clist_append(content->ct_parameters,param);
287 param = 0;
288 }
289 filePart = mailmime_new_empty( content, fields );
290 }
291 if (filePart) {
292 if (filename.length()>0) {
293 err = mailmime_set_body_file( filePart, file );
294 } else {
295 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
296 }
297 if (err != MAILIMF_NO_ERROR) {
298 qDebug("Error setting body with file %s",file);
299 mailmime_free( filePart );
300 filePart = 0;
301 }
302 }
303
304 if (!filePart) {
305 if ( param != NULL ) {
306 mailmime_parameter_free( param );
307 }
308 if (content) {
309 mailmime_content_free( content );
310 }
311 if (fields) {
312 mailmime_fields_free( fields );
313 } else {
314 if (name) {
315 free( name );
316 }
317 if (file) {
318 free( file );
319 }
320 }
321 }
322 return filePart; // Success :)
323
324}
325
326void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files )
327{
328 const Attachment *it;
329 unsigned int count = files.count();
330 qDebug("List contains %i values",count);
331 for ( unsigned int i = 0; i < count; ++i ) {
332 qDebug( "Adding file" );
333 mailmime *filePart;
334 int err;
335 it = ((QList<Attachment>)files).at(i);
336
337 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
338 if ( filePart == NULL ) {
339 qDebug( "addFileParts: error adding file:" );
340 qDebug( it->getFileName() );
341 continue;
342 }
343 err = mailmime_smart_add_part( message, filePart );
344 if ( err != MAILIMF_NO_ERROR ) {
345 mailmime_free( filePart );
346 qDebug("error smart add");
347 }
348 }
349}
350
351mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
352{
353 mailmime *message, *txtPart;
354 mailimf_fields *fields;
355 int err;
356
357 fields = createImfFields( mail );
358 if ( fields == NULL ) goto err_free;
359
360 message = mailmime_new_message_data( NULL );
361 if ( message == NULL ) goto err_free_fields;
362
363 mailmime_set_imf_fields( message, fields );
364
365 txtPart = buildTxtPart( mail.getMessage() );
366
367 if ( txtPart == NULL ) goto err_free_message;
368
369 err = mailmime_smart_add_part( message, txtPart );
370 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
371
372 addFileParts( message, mail.getAttachments() );
373
374 return message; // Success :)
375
376err_free_txtPart:
377 mailmime_free( txtPart );
378err_free_message:
379 mailmime_free( message );
380err_free_fields:
381 mailimf_fields_free( fields );
382err_free:
383 qDebug( "createMimeMail: error" );
384
385 return NULL; // Error :(
386}
387
388mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type )
389{
390 mailimf_field *field;
391 clistiter *it;
392
393 it = clist_begin( fields->fld_list );
394 while ( it ) {
395 field = (mailimf_field *) it->data;
396 if ( field->fld_type == type ) {
397 return field;
398 }
399 it = it->next;
400 }
401
402 return NULL;
403}
404
405void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list )
406{
407 clistiter *it, *it2;
408
409 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
410 mailimf_address *addr;
411 addr = (mailimf_address *) it->data;
412
413 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
414 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
415 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
416 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
417 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
418 mailimf_mailbox *mbox;
419 mbox = (mailimf_mailbox *) it2->data;
420 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
421 }
422 }
423 }
424}
425
426clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
427{
428 clist *rcptList;
429 mailimf_field *field;
430
431 rcptList = esmtp_address_list_new();
432
433 field = getField( fields, MAILIMF_FIELD_TO );
434 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
435 && field->fld_data.fld_to->to_addr_list ) {
436 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
437 }
438
439 field = getField( fields, MAILIMF_FIELD_CC );
440 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
441 && field->fld_data.fld_cc->cc_addr_list ) {
442 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
443 }
444
445 field = getField( fields, MAILIMF_FIELD_BCC );
446 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
447 && field->fld_data.fld_bcc->bcc_addr_list ) {
448 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
449 }
450
451 return rcptList;
452}
453
454char *SMTPwrapper::getFrom( mailimf_field *ffrom)
455{
456 char *from = NULL;
457 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
458 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
459 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
460 clistiter *it;
461 for ( it = clist_begin( cl ); it; it = it->next ) {
462 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
463 from = strdup( mb->mb_addr_spec );
464 }
465 }
466
467 return from;
468}
469
470char *SMTPwrapper::getFrom( mailmime *mail )
471{
472 /* no need to delete - its just a pointer to structure content */
473 mailimf_field *ffrom = 0;
474 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
475 return getFrom(ffrom);
476}
477
478void SMTPwrapper::progress( size_t current, size_t maximum )
479{
480 if (SMTPwrapper::sendProgress) {
481 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
482 qApp->processEvents();
483 }
484}
485
486void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
487{
488 if (!mail) return;
489 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
490 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
491 wrap->storeMessage(mail,length,box);
492 delete wrap;
493}
494
495void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
496{
497 clist *rcpts = 0;
498 char *from, *data;
499 size_t size;
500
501 if ( smtp == NULL ) {
502 return;
503 }
504 from = data = 0;
505
506 mailmessage * msg = 0;
507 msg = mime_message_init(mail);
508 mime_message_set_tmpdir(msg,getenv( "HOME" ));
509 int r = mailmessage_fetch(msg,&data,&size);
510 mime_message_detach_mime(msg);
511 mailmessage_free(msg);
512 if (r != MAIL_NO_ERROR || !data) {
513 if (data) free(data);
514 qDebug("Error fetching mime...");
515 return;
516 }
517 QString tmp = data;
518 tmp.replace(QRegExp("\r+",true,false),"");
519 msg = 0;
520 if (later) {
521 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
522 if (data) free( data );
523 Config cfg( "mail" );
524 cfg.setGroup( "Status" );
525 cfg.writeEntry( "outgoing", ++m_queuedMail );
526 emit queuedMails( m_queuedMail );
527 return;
528 }
529 from = getFrom( mail );
530 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
531 smtpSend(from,rcpts,data,size,smtp);
532 if (data) {free(data);}
533 if (from) {free(from);}
534 if (rcpts) smtp_address_list_free( rcpts );
535}
536
537int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
538{
539 char *server, *user, *pass;
540 bool ssl;
541 uint16_t port;
542 mailsmtp *session;
543 int err,result;
544
545 result = 1;
546 server = user = pass = 0;
547 server = strdup( smtp->getServer().latin1() );
548 ssl = smtp->getSSL();
549 port = smtp->getPort().toUInt();
550
551 session = mailsmtp_new( 20, &progress );
552 if ( session == NULL ) goto free_mem;
553
554 qDebug( "Servername %s at port %i", server, port );
555 if ( ssl ) {
556 qDebug( "SSL session" );
557 err = mailsmtp_ssl_connect( session, server, port );
558 } else {
559 qDebug( "No SSL session" );
560 err = mailsmtp_socket_connect( session, server, port );
561 }
562 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;}
563
564 err = mailsmtp_init( session );
565 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
566
567 qDebug( "INIT OK" );
568
569 if ( smtp->getLogin() ) {
570 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
571 // get'em
572 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
573 login.show();
574 if ( QDialog::Accepted == login.exec() ) {
575 // ok
576 user = strdup( login.getUser().latin1() );
577 pass = strdup( login.getPassword().latin1() );
578 } else {
579 result = 0; goto free_con_session;
580 }
581 } else {
582 user = strdup( smtp->getUser().latin1() );
583 pass = strdup( smtp->getPassword().latin1() );
584 }
585 qDebug( "session->auth: %i", session->auth);
586 err = mailsmtp_auth( session, user, pass );
587 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
588 qDebug( "Done auth!" );
589 }
590
591 err = mailsmtp_send( session, from, rcpts, data, size );
592 if ( err != MAILSMTP_NO_ERROR ) {
593 qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
594 result = 0; goto free_con_session;
595 }
596
597 qDebug( "Mail sent." );
598 storeMail(data,size,"Sent");
599
600free_con_session:
601 mailsmtp_quit( session );
602free_mem_session:
603 mailsmtp_free( session );
604free_mem:
605 if (server) free( server );
606 if ( smtp->getLogin() ) {
607 free( user );
608 free( pass );
609 }
610 return result;
611}
612
613void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later )
614{
615 mailmime * mimeMail;
616
617 SMTPaccount *smtp = aSmtp;
618
619 if (!later && !smtp) {
620 qDebug("Didn't get any send method - giving up");
621 return;
622 }
623 mimeMail = createMimeMail(mail );
624 if ( mimeMail == NULL ) {
625 qDebug( "sendMail: error creating mime mail" );
626 } else {
627 sendProgress = new progressMailSend();
628 sendProgress->show();
629 sendProgress->setMaxMails(1);
630 smtpSend( mimeMail,later,smtp);
631 qDebug("Clean up done");
632 sendProgress->hide();
633 delete sendProgress;
634 sendProgress = 0;
635 mailmime_free( mimeMail );
636 }
637}
638
639int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
640{
641 char*data = 0;
642 size_t length = 0;
643 size_t curTok = 0;
644 mailimf_fields *fields = 0;
645 mailimf_field*ffrom = 0;
646 clist *rcpts = 0;
647 char*from = 0;
648 int res = 0;
649
650 wrap->fetchRawBody(*which,&data,&length);
651 if (!data) return 0;
652 int err = mailimf_fields_parse( data, length, &curTok, &fields );
653 if (err != MAILIMF_NO_ERROR) {
654 free(data);
655 delete wrap;
656 return 0;
657 }
658
659 rcpts = createRcptList( fields );
660 ffrom = getField(fields, MAILIMF_FIELD_FROM );
661 from = getFrom(ffrom);
662
663 qDebug("Size: %i vs. %i",length,strlen(data));
664 if (rcpts && from) {
665 res = smtpSend(from,rcpts,data,length,smtp );
666 }
667 if (fields) {
668 mailimf_fields_free(fields);
669 fields = 0;
670 }
671 if (data) {
672 free(data);
673 }
674 if (from) {
675 free(from);
676 }
677 if (rcpts) {
678 smtp_address_list_free( rcpts );
679 }
680 return res;
681}
682
683/* this is a special fun */
684bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
685{
686 bool returnValue = true;
687
688 if (!smtp) return false;
689
690 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
691 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
692 if (!wrap) {
693 qDebug("memory error");
694 return false;
695 }
696 QList<RecMail> mailsToSend;
697 QList<RecMail> mailsToRemove;
698 QString mbox("Outgoing");
699 wrap->listMessages(mbox,mailsToSend);
700 if (mailsToSend.count()==0) {
701 delete wrap;
702 return false;
703 }
704 mailsToSend.setAutoDelete(false);
705 sendProgress = new progressMailSend();
706 sendProgress->show();
707 sendProgress->setMaxMails(mailsToSend.count());
708
709 while (mailsToSend.count()>0) {
710 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
711 QMessageBox::critical(0,tr("Error sending mail"),
712 tr("Error sending queued mail - breaking"));
713 returnValue = false;
714 break;
715 }
716 mailsToRemove.append(mailsToSend.at(0));
717 mailsToSend.removeFirst();
718 sendProgress->setCurrentMails(mailsToRemove.count());
719 }
720 Config cfg( "mail" );
721 cfg.setGroup( "Status" );
722 m_queuedMail = 0;
723 cfg.writeEntry( "outgoing", m_queuedMail );
724 emit queuedMails( m_queuedMail );
725 sendProgress->hide();
726 delete sendProgress;
727 sendProgress = 0;
728 wrap->deleteMails(mbox,mailsToRemove);
729 mailsToSend.setAutoDelete(true);
730 delete wrap;
731 return returnValue;
732}
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h
deleted file mode 100644
index 05becf2..0000000
--- a/noncore/net/mail/smtpwrapper.h
+++ b/dev/null
@@ -1,71 +0,0 @@
1#ifndef SMTPwrapper_H
2#define SMTPwrapper_H
3
4#include <qpe/applnk.h>
5
6#include <qbitarray.h>
7#include <qdatetime.h>
8#include <libetpan/clist.h>
9
10#include "settings.h"
11
12class Mail;
13class MBOXwrapper;
14class RecMail;
15class Attachment;
16struct mailimf_fields;
17struct mailimf_field;
18struct mailimf_mailbox;
19struct mailmime;
20struct mailimf_address_list;
21class progressMailSend;
22
23class SMTPwrapper : public QObject
24{
25 Q_OBJECT
26
27public:
28 SMTPwrapper( Settings *s );
29 virtual ~SMTPwrapper(){}
30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false );
31 bool flushOutbox(SMTPaccount*smtp);
32
33 static progressMailSend*sendProgress;
34
35signals:
36 void queuedMails( int );
37
38protected:
39 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
40 mailimf_fields *createImfFields(const Mail &mail );
41 mailmime *createMimeMail(const Mail&mail );
42
43 mailimf_address_list *parseAddresses(const QString&addr );
44 void addFileParts( mailmime *message,const QList<Attachment>&files );
45 mailmime *buildTxtPart(const QString&str );
46 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
47 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
48 clist *createRcptList( mailimf_fields *fields );
49
50 static void storeMail(char*mail, size_t length, const QString&box);
51 static QString mailsmtpError( int err );
52 static void progress( size_t current, size_t maximum );
53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
54 static char *getFrom( mailmime *mail );
55 static char *getFrom( mailimf_field *ffrom);
56 static mailimf_field *getField( mailimf_fields *fields, int type );
57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp );
58
59 void storeMail(mailmime*mail, const QString&box);
60 Settings *settings;
61
62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
63
64 int m_queuedMail;
65
66protected slots:
67 void emitQCop( int queued );
68
69};
70
71#endif