summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-21 21:33:49 (UTC)
committer alwin <alwin>2003-12-21 21:33:49 (UTC)
commit6e7358f954618d8fdbbe852df7df862c3c132bbd (patch) (unidiff)
tree0e2a94a0a42393b811d85172677c117517db5fd4
parentfafcc882ba0d797d5aa8ed7f2f8d5518ba6d2960 (diff)
downloadopie-6e7358f954618d8fdbbe852df7df862c3c132bbd.zip
opie-6e7358f954618d8fdbbe852df7df862c3c132bbd.tar.gz
opie-6e7358f954618d8fdbbe852df7df862c3c132bbd.tar.bz2
- mbox-wrapper mostly finished
- special-folders "Local Folders" will be displayed ToDo: "STORE" - method for all wrapper, but mostly for mbox for send queue.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp6
-rw-r--r--noncore/net/mail/abstractmail.h3
-rw-r--r--noncore/net/mail/accountview.cpp86
-rw-r--r--noncore/net/mail/accountview.h30
-rw-r--r--noncore/net/mail/genericwrapper.cpp393
-rw-r--r--noncore/net/mail/genericwrapper.h59
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp6
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h3
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp393
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h59
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp418
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h43
-rw-r--r--noncore/net/mail/mail.pro48
-rw-r--r--noncore/net/mail/pop3wrapper.cpp418
-rw-r--r--noncore/net/mail/pop3wrapper.h43
-rw-r--r--noncore/net/mail/viewmail.cpp1
16 files changed, 1100 insertions, 909 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
index 3cb8f7d..416795b 100644
--- a/noncore/net/mail/abstractmail.cpp
+++ b/noncore/net/mail/abstractmail.cpp
@@ -1,34 +1,40 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mboxwrapper.h"
4#include "mailtypes.h" 5#include "mailtypes.h"
5 6
6#include <qstring.h> 7#include <qstring.h>
7#include <qfile.h> 8#include <qfile.h>
8#include <qtextstream.h> 9#include <qtextstream.h>
9#include <stdlib.h> 10#include <stdlib.h>
10#include <libetpan/mailmime_content.h> 11#include <libetpan/mailmime_content.h>
11#include <libetpan/mailmime.h> 12#include <libetpan/mailmime.h>
12 13
13AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
14{ 15{
15 return new IMAPwrapper(a); 16 return new IMAPwrapper(a);
16} 17}
17 18
18AbstractMail* AbstractMail::getWrapper(POP3account *a) 19AbstractMail* AbstractMail::getWrapper(POP3account *a)
19{ 20{
20 return new POP3wrapper(a); 21 return new POP3wrapper(a);
21} 22}
22 23
24AbstractMail* AbstractMail::getWrapper(const QString&a)
25{
26 return new MBOXwrapper(a);
27}
28
23encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
24{ 30{
25 qDebug("Decode string start"); 31 qDebug("Decode string start");
26 char*result_text; 32 char*result_text;
27 size_t index = 0; 33 size_t index = 0;
28 /* reset for recursive use! */ 34 /* reset for recursive use! */
29 size_t target_length = 0; 35 size_t target_length = 0;
30 result_text = 0; 36 result_text = 0;
31 int mimetype = MAILMIME_MECHANISM_7BIT; 37 int mimetype = MAILMIME_MECHANISM_7BIT;
32 if (enc.lower()=="quoted-printable") { 38 if (enc.lower()=="quoted-printable") {
33 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
34 } else if (enc.lower()=="base64") { 40 } else if (enc.lower()=="base64") {
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index 8dd2e12..509b68e 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -18,22 +18,25 @@ class AbstractMail:public QObject
18public: 18public:
19 AbstractMail(){}; 19 AbstractMail(){};
20 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
21 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
23 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27 27
28 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 virtual void cleanMimeCache(){};
30 31
31 static AbstractMail* getWrapper(IMAPaccount *a); 32 static AbstractMail* getWrapper(IMAPaccount *a);
32 static AbstractMail* getWrapper(POP3account *a); 33 static AbstractMail* getWrapper(POP3account *a);
34 /* mbox only! */
35 static AbstractMail* getWrapper(const QString&a);
33 36
34protected: 37protected:
35 static encodedString*decode_String(const encodedString*text,const QString&enc); 38 static encodedString*decode_String(const encodedString*text,const QString&enc);
36 static QString convert_String(const char*text); 39 static QString convert_String(const char*text);
37 static QString gen_attachment_id(); 40 static QString gen_attachment_id();
38}; 41};
39#endif 42#endif
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 71a0d74..6bc8b8b 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -1,17 +1,17 @@
1#include <stdlib.h>
1#include "accountview.h" 2#include "accountview.h"
2#include "mailtypes.h" 3#include "mailtypes.h"
3#include "defines.h" 4#include "defines.h"
4 5
5
6/** 6/**
7 * POP3 Account stuff 7 * POP3 Account stuff
8 */ 8 */
9 9
10POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) 10POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
11 : AccountViewItem( parent ) 11 : AccountViewItem( parent )
12{ 12{
13 account = a; 13 account = a;
14 wrapper = AbstractMail::getWrapper( account ); 14 wrapper = AbstractMail::getWrapper( account );
15 setPixmap( 0, PIXMAP_POP3FOLDER ); 15 setPixmap( 0, PIXMAP_POP3FOLDER );
16 setText( 0, account->getAccountName() ); 16 setText( 0, account->getAccountName() );
17 setOpen( true ); 17 setOpen( true );
@@ -219,40 +219,44 @@ bool IMAPfolderItem::matchName(const QString&name)const
219 219
220void IMAPfolderItem::refresh(QList<RecMail>&target) 220void IMAPfolderItem::refresh(QList<RecMail>&target)
221{ 221{
222 if (folder->may_select()) 222 if (folder->may_select())
223 imap->getWrapper()->listMessages( folder->getName(),target ); 223 imap->getWrapper()->listMessages( folder->getName(),target );
224} 224}
225 225
226RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) 226RecBody IMAPfolderItem::fetchBody(const RecMail&aMail)
227{ 227{
228 return imap->getWrapper()->fetchBody(aMail); 228 return imap->getWrapper()->fetchBody(aMail);
229} 229}
230 230
231
231/** 232/**
232 * Generic stuff 233 * Generic stuff
233 */ 234 */
234 235
235AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 236AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
236 : QListView( parent, name, flags ) 237 : QListView( parent, name, flags )
237{ 238{
238 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), 239 connect( this, SIGNAL( selectionChanged( QListViewItem * ) ),
239 SLOT( refresh( QListViewItem * ) ) ); 240 SLOT( refresh( QListViewItem * ) ) );
240 setSorting(0); 241 setSorting(0);
241} 242}
242 243
243void AccountView::populate( QList<Account> list ) 244void AccountView::populate( QList<Account> list )
244{ 245{
245 clear(); 246 clear();
246 247
248 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
249 (void) new MBOXviewItem(localfolders,this);
250
247 Account *it; 251 Account *it;
248 for ( it = list.first(); it; it = list.next() ) { 252 for ( it = list.first(); it; it = list.next() ) {
249 if ( it->getType().compare( "IMAP" ) == 0 ) { 253 if ( it->getType().compare( "IMAP" ) == 0 ) {
250 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 254 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
251 qDebug( "added IMAP " + imap->getAccountName() ); 255 qDebug( "added IMAP " + imap->getAccountName() );
252 (void) new IMAPviewItem( imap, this ); 256 (void) new IMAPviewItem( imap, this );
253 } else if ( it->getType().compare( "POP3" ) == 0 ) { 257 } else if ( it->getType().compare( "POP3" ) == 0 ) {
254 POP3account *pop3 = static_cast<POP3account *>(it); 258 POP3account *pop3 = static_cast<POP3account *>(it);
255 qDebug( "added POP3 " + pop3->getAccountName() ); 259 qDebug( "added POP3 " + pop3->getAccountName() );
256 (void) new POP3viewItem( pop3, this ); 260 (void) new POP3viewItem( pop3, this );
257 } 261 }
258 } 262 }
@@ -284,12 +288,92 @@ void AccountView::refreshCurrent()
284void AccountView::refreshAll() 288void AccountView::refreshAll()
285{ 289{
286 290
287} 291}
288 292
289RecBody AccountView::fetchBody(const RecMail&aMail) 293RecBody AccountView::fetchBody(const RecMail&aMail)
290{ 294{
291 QListViewItem*item = selectedItem (); 295 QListViewItem*item = selectedItem ();
292 if (!item) return RecBody(); 296 if (!item) return RecBody();
293 AccountViewItem *view = static_cast<AccountViewItem *>(item); 297 AccountViewItem *view = static_cast<AccountViewItem *>(item);
294 return view->fetchBody(aMail); 298 return view->fetchBody(aMail);
295} 299}
300
301/**
302 * MBOX Account stuff
303 */
304
305MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent )
306 : AccountViewItem( parent )
307{
308 m_Path = aPath;
309 wrapper = AbstractMail::getWrapper( m_Path );
310 setPixmap( 0, PIXMAP_POP3FOLDER );
311 setText( 0, " Local Folders" );
312 setOpen( true );
313}
314
315MBOXviewItem::~MBOXviewItem()
316{
317 delete wrapper;
318}
319
320AbstractMail *MBOXviewItem::getWrapper()
321{
322 return wrapper;
323}
324
325void MBOXviewItem::refresh( QList<RecMail> & )
326{
327 QList<Folder> *folders = wrapper->listFolders();
328 QListViewItem *child = firstChild();
329 while ( child ) {
330 QListViewItem *tmp = child;
331 child = child->nextSibling();
332 delete tmp;
333 }
334 Folder *it;
335 QListViewItem*item = 0;
336 for ( it = folders->first(); it; it = folders->next() ) {
337 item = new MBOXfolderItem( it, this , item );
338 item->setSelectable(it->may_select());
339 }
340 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
341 folders->setAutoDelete(false);
342 delete folders;
343}
344
345RecBody MBOXviewItem::fetchBody( const RecMail &mail )
346{
347 qDebug( "POP3 fetchBody" );
348 return wrapper->fetchBody( mail );
349}
350
351MBOXfolderItem::~MBOXfolderItem()
352{
353 delete folder;
354}
355
356MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after )
357 : AccountViewItem( parent,after )
358{
359 folder = folderInit;
360 mbox = parent;
361 if (folder->getDisplayName().lower()!="inbox") {
362 setPixmap( 0, PIXMAP_POP3FOLDER );
363 } else {
364 setPixmap( 0, PIXMAP_INBOXFOLDER);
365 }
366 setText( 0, folder->getDisplayName() );
367}
368
369void MBOXfolderItem::refresh(QList<RecMail>&target)
370{
371 if (folder->may_select())
372 mbox->getWrapper()->listMessages( folder->getName(),target );
373}
374
375RecBody MBOXfolderItem::fetchBody(const RecMail&aMail)
376{
377 return mbox->getWrapper()->fetchBody(aMail);
378}
379
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index 64abed9..35499ac 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -77,24 +77,54 @@ class IMAPfolderItem : public AccountViewItem
77public: 77public:
78 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); 78 IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
79 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); 79 IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master );
80 ~IMAPfolderItem(); 80 ~IMAPfolderItem();
81 virtual void refresh(QList<RecMail>&); 81 virtual void refresh(QList<RecMail>&);
82 virtual RecBody fetchBody(const RecMail&); 82 virtual RecBody fetchBody(const RecMail&);
83 bool matchName(const QString&name)const; 83 bool matchName(const QString&name)const;
84private: 84private:
85 Folder *folder; 85 Folder *folder;
86 IMAPviewItem *imap; 86 IMAPviewItem *imap;
87}; 87};
88 88
89class MBOXviewItem : public AccountViewItem
90{
91
92public:
93// MBOXviewItem( MBOXaccount *a, QListView *parent );
94 MBOXviewItem( const QString&aMboxPath, QListView *parent );
95 ~MBOXviewItem();
96 virtual void refresh( QList<RecMail> &target );
97 virtual RecBody fetchBody( const RecMail &mail );
98 AbstractMail *getWrapper();
99private:
100// MBOXaccount *account;
101 QString m_Path;
102 AbstractMail *wrapper;
103
104};
105
106class MBOXfolderItem : public AccountViewItem
107{
108
109public:
110 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after );
111 ~MBOXfolderItem();
112 virtual void refresh(QList<RecMail>&);
113 virtual RecBody fetchBody(const RecMail&);
114private:
115 Folder *folder;
116 MBOXviewItem *mbox;
117};
118
89class AccountView : public QListView 119class AccountView : public QListView
90{ 120{
91 Q_OBJECT 121 Q_OBJECT
92 122
93public: 123public:
94 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 124 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
95 void populate( QList<Account> list ); 125 void populate( QList<Account> list );
96 RecBody fetchBody(const RecMail&aMail); 126 RecBody fetchBody(const RecMail&aMail);
97 127
98public slots: 128public slots:
99 void refreshAll(); 129 void refreshAll();
100 void refresh(QListViewItem *item); 130 void refresh(QListViewItem *item);
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp
new file mode 100644
index 0000000..447cad0
--- a/dev/null
+++ b/noncore/net/mail/genericwrapper.cpp
@@ -0,0 +1,393 @@
1#include "genericwrapper.h"
2#include <libetpan/mailmime.h>
3#include <libetpan/data_message_driver.h>
4#include "mailtypes.h"
5
6Genericwrapper::Genericwrapper()
7 : AbstractMail()
8{
9 bodyCache.clear();
10}
11
12Genericwrapper::~Genericwrapper()
13{
14 cleanMimeCache();
15}
16
17void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
18{
19 if (!mime) {
20 return;
21 }
22 mailmime_field*field = 0;
23 mailmime_single_fields fields;
24 memset(&fields, 0, sizeof(struct mailmime_single_fields));
25 if (mime->mm_mime_fields != NULL) {
26 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
27 mime->mm_content_type);
28 }
29
30 mailmime_content*type = fields.fld_content;
31 clistcell*current;
32 if (!type) {
33 target.setType("text");
34 target.setSubtype("plain");
35 } else {
36 target.setSubtype(type->ct_subtype);
37 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
38 case MAILMIME_DISCRETE_TYPE_TEXT:
39 target.setType("text");
40 break;
41 case MAILMIME_DISCRETE_TYPE_IMAGE:
42 target.setType("image");
43 break;
44 case MAILMIME_DISCRETE_TYPE_AUDIO:
45 target.setType("audio");
46 break;
47 case MAILMIME_DISCRETE_TYPE_VIDEO:
48 target.setType("video");
49 break;
50 case MAILMIME_DISCRETE_TYPE_APPLICATION:
51 target.setType("application");
52 break;
53 case MAILMIME_DISCRETE_TYPE_EXTENSION:
54 default:
55 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
56 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
57 }
58 break;
59 }
60 if (type->ct_parameters) {
61 fillParameters(target,type->ct_parameters);
62 }
63 }
64 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
65 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
66 field = (mailmime_field*)current->data;
67 switch(field->fld_type) {
68 case MAILMIME_FIELD_TRANSFER_ENCODING:
69 target.setEncoding(getencoding(field->fld_data.fld_encoding));
70 break;
71 case MAILMIME_FIELD_ID:
72 target.setIdentifier(field->fld_data.fld_id);
73 break;
74 case MAILMIME_FIELD_DESCRIPTION:
75 target.setDescription(field->fld_data.fld_description);
76 break;
77 default:
78 break;
79 }
80 }
81 }
82}
83
84void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
85{
86 if (!parameters) {return;}
87 clistcell*current=0;
88 mailmime_parameter*param;
89 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
90 param = (mailmime_parameter*)current->data;
91 if (param) {
92 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
93 }
94 }
95}
96
97QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
98{
99 QString enc="7bit";
100 if (!aEnc) return enc;
101 switch(aEnc->enc_type) {
102 case MAILMIME_MECHANISM_7BIT:
103 enc = "7bit";
104 break;
105 case MAILMIME_MECHANISM_8BIT:
106 enc = "8bit";
107 break;
108 case MAILMIME_MECHANISM_BINARY:
109 enc = "binary";
110 break;
111 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
112 enc = "quoted-printable";
113 break;
114 case MAILMIME_MECHANISM_BASE64:
115 enc = "base64";
116 break;
117 case MAILMIME_MECHANISM_TOKEN:
118 default:
119 if (aEnc->enc_token) {
120 enc = QString(aEnc->enc_token);
121 }
122 break;
123 }
124 return enc;
125}
126
127void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
128{
129 if (current_rec >= 10) {
130 qDebug("too deep recursion!");
131 }
132 if (!message || !mime) {
133 return;
134 }
135 int r;
136 char*data = 0;
137 size_t len;
138 clistiter * cur = 0;
139 QString b;
140 RecPart part;
141
142 switch (mime->mm_type) {
143 case MAILMIME_SINGLE:
144 r = mailmessage_fetch_section(message,mime,&data,&len);
145 part.setSize(len);
146 fillSingleBody(part,message,mime);
147 if (part.Type()=="text" && target.Bodytext().isNull()) {
148 encodedString*r = new encodedString();
149 r->setContent(data,len);
150 encodedString*res = decode_String(r,part.Encoding());
151 b = QString(res->Content());
152 delete r;
153 delete res;
154 target.setBodytext(b);
155 target.setDescription(part);
156 } else {
157 b = gen_attachment_id();
158 part.setIdentifier(b);
159 bodyCache[b]=new encodedString(data,len);
160 target.addPart(part);
161 }
162 break;
163 case MAILMIME_MULTIPLE:
164 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
165 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
166 }
167 break;
168 case MAILMIME_MESSAGE:
169 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
170 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1);
171 }
172 break;
173 }
174}
175
176RecBody Genericwrapper::parseMail( mailmessage * msg )
177{
178 int err = MAILIMF_NO_ERROR;
179 mailmime_single_fields fields;
180 /* is bound to msg and will be freed there */
181 mailmime * mime=0;
182 RecBody body;
183 memset(&fields, 0, sizeof(struct mailmime_single_fields));
184 err = mailmessage_get_bodystructure(msg,&mime);
185 traverseBody(body,msg,mime);
186 return body;
187}
188
189RecMail *Genericwrapper::parseHeader( const char *header )
190{
191 int err = MAILIMF_NO_ERROR;
192 size_t curTok = 0;
193 RecMail *mail = new RecMail();
194 mailimf_fields *fields;
195 mailimf_references * refs;
196 mailimf_keywords*keys;
197 QString status;
198 QString value;
199 QBitArray mFlags(7);
200
201 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
202 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
203 mailimf_field *field = (mailimf_field *) current->data;
204 switch ( field->fld_type ) {
205 case MAILIMF_FIELD_FROM:
206 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
207 break;
208 case MAILIMF_FIELD_TO:
209 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
210 break;
211 case MAILIMF_FIELD_CC:
212 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
213 break;
214 case MAILIMF_FIELD_BCC:
215 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
216 break;
217 case MAILIMF_FIELD_SUBJECT:
218 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
219 break;
220 case MAILIMF_FIELD_ORIG_DATE:
221 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
222 break;
223 case MAILIMF_FIELD_MESSAGE_ID:
224 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
225 break;
226 case MAILIMF_FIELD_REFERENCES:
227 refs = field->fld_data.fld_references;
228 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
229 char * text = (char*)refs->mid_list->first->data;
230 mail->setReplyto(QString(text));
231 }
232 break;
233 case MAILIMF_FIELD_KEYWORDS:
234 keys = field->fld_data.fld_keywords;
235 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
236 qDebug("Keyword: %s",(char*)cur->data);
237 }
238 break;
239 case MAILIMF_FIELD_OPTIONAL_FIELD:
240 status = field->fld_data.fld_optional_field->fld_name;
241 value = field->fld_data.fld_optional_field->fld_value;
242 if (status.lower()=="status") {
243 if (value.lower()=="ro") {
244 mFlags.setBit(FLAG_SEEN);
245 }
246 } else if (status.lower()=="x-status") {
247 qDebug("X-Status: %s",value.latin1());
248 if (value.lower()=="a") {
249 mFlags.setBit(FLAG_ANSWERED);
250 }
251 } else {
252// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
253// field->fld_data.fld_optional_field->fld_value);
254 }
255 break;
256 default:
257 qDebug("Non parsed field");
258 break;
259 }
260 }
261 if (fields) mailimf_fields_free(fields);
262 mail->setFlags(mFlags);
263 return mail;
264}
265
266QString Genericwrapper::parseDateTime( mailimf_date_time *date )
267{
268 char tmp[23];
269
270 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
271 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
272
273 return QString( tmp );
274}
275
276QString Genericwrapper::parseAddressList( mailimf_address_list *list )
277{
278 QString result( "" );
279
280 bool first = true;
281 if (list == 0) return result;
282 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
283 mailimf_address *addr = (mailimf_address *) current->data;
284
285 if ( !first ) {
286 result.append( "," );
287 } else {
288 first = false;
289 }
290
291 switch ( addr->ad_type ) {
292 case MAILIMF_ADDRESS_MAILBOX:
293 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
294 break;
295 case MAILIMF_ADDRESS_GROUP:
296 result.append( parseGroup( addr->ad_data.ad_group ) );
297 break;
298 default:
299 qDebug( "Generic: unkown mailimf address type" );
300 break;
301 }
302 }
303
304 return result;
305}
306
307QString Genericwrapper::parseGroup( mailimf_group *group )
308{
309 QString result( "" );
310
311 result.append( group->grp_display_name );
312 result.append( ": " );
313
314 if ( group->grp_mb_list != NULL ) {
315 result.append( parseMailboxList( group->grp_mb_list ) );
316 }
317
318 result.append( ";" );
319
320 return result;
321}
322
323QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
324{
325 QString result( "" );
326
327 if ( box->mb_display_name == NULL ) {
328 result.append( box->mb_addr_spec );
329 } else {
330 result.append( convert_String(box->mb_display_name).latin1() );
331 result.append( " <" );
332 result.append( box->mb_addr_spec );
333 result.append( ">" );
334 }
335
336 return result;
337}
338
339QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
340{
341 QString result( "" );
342
343 bool first = true;
344 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
345 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
346
347 if ( !first ) {
348 result.append( "," );
349 } else {
350 first = false;
351 }
352
353 result.append( parseMailbox( box ) );
354 }
355
356 return result;
357}
358
359encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
360{
361 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
362 if (it==bodyCache.end()) return new encodedString();
363 encodedString*t = decode_String(it.data(),part.Encoding());
364 return t;
365}
366
367encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
368{
369 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
370 if (it==bodyCache.end()) return new encodedString();
371 encodedString*t = it.data();
372 return t;
373}
374
375QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
376{
377 encodedString*t = fetchDecodedPart(mail,part);
378 QString text=t->Content();
379 delete t;
380 return text;
381}
382
383void Genericwrapper::cleanMimeCache()
384{
385 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
386 for (;it!=bodyCache.end();++it) {
387 encodedString*t = it.data();
388 //it.setValue(0);
389 if (t) delete t;
390 }
391 bodyCache.clear();
392 qDebug("Genericwrapper: cache cleaned");
393}
diff --git a/noncore/net/mail/genericwrapper.h b/noncore/net/mail/genericwrapper.h
new file mode 100644
index 0000000..12f6928
--- a/dev/null
+++ b/noncore/net/mail/genericwrapper.h
@@ -0,0 +1,59 @@
1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H
3
4#include "abstractmail.h"
5#include <qmap.h>
6#include <qstring.h>
7#include <libetpan/clist.h>
8
9class RecMail;
10class RecBody;
11class encodedString;
12struct mailpop3;
13struct mailmessage;
14struct mailmime;
15struct mailmime_mechanism;
16struct mailimf_mailbox_list;
17struct mailimf_mailbox;
18struct mailimf_date_time;
19struct mailimf_group;
20struct mailimf_address_list;
21
22/* this class hold just the funs shared between
23 * mbox and pop3 (later mh, too) mail access.
24 * it is not desigend to make a instance of it!
25 */
26class Genericwrapper : public AbstractMail
27{
28 Q_OBJECT
29public:
30 Genericwrapper();
31 virtual ~Genericwrapper();
32
33 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
35 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
36 virtual void cleanMimeCache();
37
38protected:
39 RecMail *parseHeader( const char *header );
40 RecBody parseMail( mailmessage * msg );
41 QString parseMailboxList( mailimf_mailbox_list *list );
42 QString parseMailbox( mailimf_mailbox *box );
43 QString parseGroup( mailimf_group *group );
44 QString parseAddressList( mailimf_address_list *list );
45 QString parseDateTime( mailimf_date_time *date );
46
47 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0);
48 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
49 static void fillParameters(RecPart&target,clist*parameters);
50 static QString getencoding(mailmime_mechanism*aEnc);
51
52 POP3account *account;
53 mailpop3 *m_pop3;
54 QString msgTempName;
55 unsigned int last_msg_id;
56 QMap<QString,encodedString*> bodyCache;
57};
58
59#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 3cb8f7d..416795b 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,34 +1,40 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mboxwrapper.h"
4#include "mailtypes.h" 5#include "mailtypes.h"
5 6
6#include <qstring.h> 7#include <qstring.h>
7#include <qfile.h> 8#include <qfile.h>
8#include <qtextstream.h> 9#include <qtextstream.h>
9#include <stdlib.h> 10#include <stdlib.h>
10#include <libetpan/mailmime_content.h> 11#include <libetpan/mailmime_content.h>
11#include <libetpan/mailmime.h> 12#include <libetpan/mailmime.h>
12 13
13AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 14AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
14{ 15{
15 return new IMAPwrapper(a); 16 return new IMAPwrapper(a);
16} 17}
17 18
18AbstractMail* AbstractMail::getWrapper(POP3account *a) 19AbstractMail* AbstractMail::getWrapper(POP3account *a)
19{ 20{
20 return new POP3wrapper(a); 21 return new POP3wrapper(a);
21} 22}
22 23
24AbstractMail* AbstractMail::getWrapper(const QString&a)
25{
26 return new MBOXwrapper(a);
27}
28
23encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 29encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
24{ 30{
25 qDebug("Decode string start"); 31 qDebug("Decode string start");
26 char*result_text; 32 char*result_text;
27 size_t index = 0; 33 size_t index = 0;
28 /* reset for recursive use! */ 34 /* reset for recursive use! */
29 size_t target_length = 0; 35 size_t target_length = 0;
30 result_text = 0; 36 result_text = 0;
31 int mimetype = MAILMIME_MECHANISM_7BIT; 37 int mimetype = MAILMIME_MECHANISM_7BIT;
32 if (enc.lower()=="quoted-printable") { 38 if (enc.lower()=="quoted-printable") {
33 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 39 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
34 } else if (enc.lower()=="base64") { 40 } else if (enc.lower()=="base64") {
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index 8dd2e12..509b68e 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -18,22 +18,25 @@ class AbstractMail:public QObject
18public: 18public:
19 AbstractMail(){}; 19 AbstractMail(){};
20 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
21 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
23 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27 27
28 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 virtual void cleanMimeCache(){};
30 31
31 static AbstractMail* getWrapper(IMAPaccount *a); 32 static AbstractMail* getWrapper(IMAPaccount *a);
32 static AbstractMail* getWrapper(POP3account *a); 33 static AbstractMail* getWrapper(POP3account *a);
34 /* mbox only! */
35 static AbstractMail* getWrapper(const QString&a);
33 36
34protected: 37protected:
35 static encodedString*decode_String(const encodedString*text,const QString&enc); 38 static encodedString*decode_String(const encodedString*text,const QString&enc);
36 static QString convert_String(const char*text); 39 static QString convert_String(const char*text);
37 static QString gen_attachment_id(); 40 static QString gen_attachment_id();
38}; 41};
39#endif 42#endif
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
new file mode 100644
index 0000000..447cad0
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -0,0 +1,393 @@
1#include "genericwrapper.h"
2#include <libetpan/mailmime.h>
3#include <libetpan/data_message_driver.h>
4#include "mailtypes.h"
5
6Genericwrapper::Genericwrapper()
7 : AbstractMail()
8{
9 bodyCache.clear();
10}
11
12Genericwrapper::~Genericwrapper()
13{
14 cleanMimeCache();
15}
16
17void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
18{
19 if (!mime) {
20 return;
21 }
22 mailmime_field*field = 0;
23 mailmime_single_fields fields;
24 memset(&fields, 0, sizeof(struct mailmime_single_fields));
25 if (mime->mm_mime_fields != NULL) {
26 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
27 mime->mm_content_type);
28 }
29
30 mailmime_content*type = fields.fld_content;
31 clistcell*current;
32 if (!type) {
33 target.setType("text");
34 target.setSubtype("plain");
35 } else {
36 target.setSubtype(type->ct_subtype);
37 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
38 case MAILMIME_DISCRETE_TYPE_TEXT:
39 target.setType("text");
40 break;
41 case MAILMIME_DISCRETE_TYPE_IMAGE:
42 target.setType("image");
43 break;
44 case MAILMIME_DISCRETE_TYPE_AUDIO:
45 target.setType("audio");
46 break;
47 case MAILMIME_DISCRETE_TYPE_VIDEO:
48 target.setType("video");
49 break;
50 case MAILMIME_DISCRETE_TYPE_APPLICATION:
51 target.setType("application");
52 break;
53 case MAILMIME_DISCRETE_TYPE_EXTENSION:
54 default:
55 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
56 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
57 }
58 break;
59 }
60 if (type->ct_parameters) {
61 fillParameters(target,type->ct_parameters);
62 }
63 }
64 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
65 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
66 field = (mailmime_field*)current->data;
67 switch(field->fld_type) {
68 case MAILMIME_FIELD_TRANSFER_ENCODING:
69 target.setEncoding(getencoding(field->fld_data.fld_encoding));
70 break;
71 case MAILMIME_FIELD_ID:
72 target.setIdentifier(field->fld_data.fld_id);
73 break;
74 case MAILMIME_FIELD_DESCRIPTION:
75 target.setDescription(field->fld_data.fld_description);
76 break;
77 default:
78 break;
79 }
80 }
81 }
82}
83
84void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
85{
86 if (!parameters) {return;}
87 clistcell*current=0;
88 mailmime_parameter*param;
89 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
90 param = (mailmime_parameter*)current->data;
91 if (param) {
92 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
93 }
94 }
95}
96
97QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
98{
99 QString enc="7bit";
100 if (!aEnc) return enc;
101 switch(aEnc->enc_type) {
102 case MAILMIME_MECHANISM_7BIT:
103 enc = "7bit";
104 break;
105 case MAILMIME_MECHANISM_8BIT:
106 enc = "8bit";
107 break;
108 case MAILMIME_MECHANISM_BINARY:
109 enc = "binary";
110 break;
111 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
112 enc = "quoted-printable";
113 break;
114 case MAILMIME_MECHANISM_BASE64:
115 enc = "base64";
116 break;
117 case MAILMIME_MECHANISM_TOKEN:
118 default:
119 if (aEnc->enc_token) {
120 enc = QString(aEnc->enc_token);
121 }
122 break;
123 }
124 return enc;
125}
126
127void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
128{
129 if (current_rec >= 10) {
130 qDebug("too deep recursion!");
131 }
132 if (!message || !mime) {
133 return;
134 }
135 int r;
136 char*data = 0;
137 size_t len;
138 clistiter * cur = 0;
139 QString b;
140 RecPart part;
141
142 switch (mime->mm_type) {
143 case MAILMIME_SINGLE:
144 r = mailmessage_fetch_section(message,mime,&data,&len);
145 part.setSize(len);
146 fillSingleBody(part,message,mime);
147 if (part.Type()=="text" && target.Bodytext().isNull()) {
148 encodedString*r = new encodedString();
149 r->setContent(data,len);
150 encodedString*res = decode_String(r,part.Encoding());
151 b = QString(res->Content());
152 delete r;
153 delete res;
154 target.setBodytext(b);
155 target.setDescription(part);
156 } else {
157 b = gen_attachment_id();
158 part.setIdentifier(b);
159 bodyCache[b]=new encodedString(data,len);
160 target.addPart(part);
161 }
162 break;
163 case MAILMIME_MULTIPLE:
164 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
165 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
166 }
167 break;
168 case MAILMIME_MESSAGE:
169 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
170 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1);
171 }
172 break;
173 }
174}
175
176RecBody Genericwrapper::parseMail( mailmessage * msg )
177{
178 int err = MAILIMF_NO_ERROR;
179 mailmime_single_fields fields;
180 /* is bound to msg and will be freed there */
181 mailmime * mime=0;
182 RecBody body;
183 memset(&fields, 0, sizeof(struct mailmime_single_fields));
184 err = mailmessage_get_bodystructure(msg,&mime);
185 traverseBody(body,msg,mime);
186 return body;
187}
188
189RecMail *Genericwrapper::parseHeader( const char *header )
190{
191 int err = MAILIMF_NO_ERROR;
192 size_t curTok = 0;
193 RecMail *mail = new RecMail();
194 mailimf_fields *fields;
195 mailimf_references * refs;
196 mailimf_keywords*keys;
197 QString status;
198 QString value;
199 QBitArray mFlags(7);
200
201 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
202 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
203 mailimf_field *field = (mailimf_field *) current->data;
204 switch ( field->fld_type ) {
205 case MAILIMF_FIELD_FROM:
206 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
207 break;
208 case MAILIMF_FIELD_TO:
209 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
210 break;
211 case MAILIMF_FIELD_CC:
212 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
213 break;
214 case MAILIMF_FIELD_BCC:
215 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
216 break;
217 case MAILIMF_FIELD_SUBJECT:
218 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
219 break;
220 case MAILIMF_FIELD_ORIG_DATE:
221 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
222 break;
223 case MAILIMF_FIELD_MESSAGE_ID:
224 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
225 break;
226 case MAILIMF_FIELD_REFERENCES:
227 refs = field->fld_data.fld_references;
228 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
229 char * text = (char*)refs->mid_list->first->data;
230 mail->setReplyto(QString(text));
231 }
232 break;
233 case MAILIMF_FIELD_KEYWORDS:
234 keys = field->fld_data.fld_keywords;
235 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
236 qDebug("Keyword: %s",(char*)cur->data);
237 }
238 break;
239 case MAILIMF_FIELD_OPTIONAL_FIELD:
240 status = field->fld_data.fld_optional_field->fld_name;
241 value = field->fld_data.fld_optional_field->fld_value;
242 if (status.lower()=="status") {
243 if (value.lower()=="ro") {
244 mFlags.setBit(FLAG_SEEN);
245 }
246 } else if (status.lower()=="x-status") {
247 qDebug("X-Status: %s",value.latin1());
248 if (value.lower()=="a") {
249 mFlags.setBit(FLAG_ANSWERED);
250 }
251 } else {
252// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
253// field->fld_data.fld_optional_field->fld_value);
254 }
255 break;
256 default:
257 qDebug("Non parsed field");
258 break;
259 }
260 }
261 if (fields) mailimf_fields_free(fields);
262 mail->setFlags(mFlags);
263 return mail;
264}
265
266QString Genericwrapper::parseDateTime( mailimf_date_time *date )
267{
268 char tmp[23];
269
270 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
271 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
272
273 return QString( tmp );
274}
275
276QString Genericwrapper::parseAddressList( mailimf_address_list *list )
277{
278 QString result( "" );
279
280 bool first = true;
281 if (list == 0) return result;
282 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
283 mailimf_address *addr = (mailimf_address *) current->data;
284
285 if ( !first ) {
286 result.append( "," );
287 } else {
288 first = false;
289 }
290
291 switch ( addr->ad_type ) {
292 case MAILIMF_ADDRESS_MAILBOX:
293 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
294 break;
295 case MAILIMF_ADDRESS_GROUP:
296 result.append( parseGroup( addr->ad_data.ad_group ) );
297 break;
298 default:
299 qDebug( "Generic: unkown mailimf address type" );
300 break;
301 }
302 }
303
304 return result;
305}
306
307QString Genericwrapper::parseGroup( mailimf_group *group )
308{
309 QString result( "" );
310
311 result.append( group->grp_display_name );
312 result.append( ": " );
313
314 if ( group->grp_mb_list != NULL ) {
315 result.append( parseMailboxList( group->grp_mb_list ) );
316 }
317
318 result.append( ";" );
319
320 return result;
321}
322
323QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
324{
325 QString result( "" );
326
327 if ( box->mb_display_name == NULL ) {
328 result.append( box->mb_addr_spec );
329 } else {
330 result.append( convert_String(box->mb_display_name).latin1() );
331 result.append( " <" );
332 result.append( box->mb_addr_spec );
333 result.append( ">" );
334 }
335
336 return result;
337}
338
339QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
340{
341 QString result( "" );
342
343 bool first = true;
344 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
345 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
346
347 if ( !first ) {
348 result.append( "," );
349 } else {
350 first = false;
351 }
352
353 result.append( parseMailbox( box ) );
354 }
355
356 return result;
357}
358
359encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
360{
361 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
362 if (it==bodyCache.end()) return new encodedString();
363 encodedString*t = decode_String(it.data(),part.Encoding());
364 return t;
365}
366
367encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
368{
369 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
370 if (it==bodyCache.end()) return new encodedString();
371 encodedString*t = it.data();
372 return t;
373}
374
375QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
376{
377 encodedString*t = fetchDecodedPart(mail,part);
378 QString text=t->Content();
379 delete t;
380 return text;
381}
382
383void Genericwrapper::cleanMimeCache()
384{
385 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
386 for (;it!=bodyCache.end();++it) {
387 encodedString*t = it.data();
388 //it.setValue(0);
389 if (t) delete t;
390 }
391 bodyCache.clear();
392 qDebug("Genericwrapper: cache cleaned");
393}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
new file mode 100644
index 0000000..12f6928
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -0,0 +1,59 @@
1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H
3
4#include "abstractmail.h"
5#include <qmap.h>
6#include <qstring.h>
7#include <libetpan/clist.h>
8
9class RecMail;
10class RecBody;
11class encodedString;
12struct mailpop3;
13struct mailmessage;
14struct mailmime;
15struct mailmime_mechanism;
16struct mailimf_mailbox_list;
17struct mailimf_mailbox;
18struct mailimf_date_time;
19struct mailimf_group;
20struct mailimf_address_list;
21
22/* this class hold just the funs shared between
23 * mbox and pop3 (later mh, too) mail access.
24 * it is not desigend to make a instance of it!
25 */
26class Genericwrapper : public AbstractMail
27{
28 Q_OBJECT
29public:
30 Genericwrapper();
31 virtual ~Genericwrapper();
32
33 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
35 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
36 virtual void cleanMimeCache();
37
38protected:
39 RecMail *parseHeader( const char *header );
40 RecBody parseMail( mailmessage * msg );
41 QString parseMailboxList( mailimf_mailbox_list *list );
42 QString parseMailbox( mailimf_mailbox *box );
43 QString parseGroup( mailimf_group *group );
44 QString parseAddressList( mailimf_address_list *list );
45 QString parseDateTime( mailimf_date_time *date );
46
47 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0);
48 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
49 static void fillParameters(RecPart&target,clist*parameters);
50 static QString getencoding(mailmime_mechanism*aEnc);
51
52 POP3account *account;
53 mailpop3 *m_pop3;
54 QString msgTempName;
55 unsigned int last_msg_id;
56 QMap<QString,encodedString*> bodyCache;
57};
58
59#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index d3447f4..efd83ba 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -2,78 +2,67 @@
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/mailpop3.h> 5#include <libetpan/mailpop3.h>
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/data_message_driver.h> 7#include <libetpan/data_message_driver.h>
8#include <qfile.h> 8#include <qfile.h>
9 9
10/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
12 12
13POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
14 : Genericwrapper()
14{ 15{
15 account = a; 16 account = a;
16 m_pop3 = NULL; 17 m_pop3 = NULL;
17 msgTempName = a->getFileName()+"_msg_cache"; 18 msgTempName = a->getFileName()+"_msg_cache";
18 last_msg_id = 0; 19 last_msg_id = 0;
19 bodyCache.clear();
20} 20}
21 21
22POP3wrapper::~POP3wrapper() 22POP3wrapper::~POP3wrapper()
23{ 23{
24 logout(); 24 logout();
25 QFile msg_cache(msgTempName); 25 QFile msg_cache(msgTempName);
26 if (msg_cache.exists()) { 26 if (msg_cache.exists()) {
27 msg_cache.remove(); 27 msg_cache.remove();
28 } 28 }
29 cleanUpCache();
30}
31
32void POP3wrapper::cleanUpCache()
33{
34 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
35 for (;it!=bodyCache.end();++it) {
36 encodedString*t = it.data();
37 //it.setValue(0);
38 if (t) delete t;
39 }
40 bodyCache.clear();
41} 29}
42 30
43void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 31void POP3wrapper::pop3_progress( size_t current, size_t maximum )
44{ 32{
45 //qDebug( "POP3: %i of %i", current, maximum ); 33 //qDebug( "POP3: %i of %i", current, maximum );
46} 34}
47 35
48RecBody POP3wrapper::fetchBody( const RecMail &mail ) 36RecBody POP3wrapper::fetchBody( const RecMail &mail )
49{ 37{
50 int err = MAILPOP3_NO_ERROR; 38 int err = MAILPOP3_NO_ERROR;
51 char *message; 39 char *message;
52 size_t length = 0; 40 size_t length = 0;
53 41
54 login(); 42 login();
55 if ( !m_pop3 ) { 43 if ( !m_pop3 ) {
56 return RecBody(); 44 return RecBody();
57 } 45 }
58 46
59 RecBody body; 47 RecBody body;
60 48 mailmessage * msg = 0;
49
61 QFile msg_cache(msgTempName); 50 QFile msg_cache(msgTempName);
62 51
63 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 52 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
64 qDebug("Message to large: %i",mail.Msgsize()); 53 qDebug("Message to large: %i",mail.Msgsize());
65 return body; 54 return body;
66 } 55 }
67 cleanUpCache(); 56 cleanMimeCache();
68 if (mail.getNumber()!=last_msg_id) { 57 if (mail.getNumber()!=last_msg_id) {
69 if (msg_cache.exists()) { 58 if (msg_cache.exists()) {
70 msg_cache.remove(); 59 msg_cache.remove();
71 } 60 }
72 msg_cache.open(IO_ReadWrite|IO_Truncate); 61 msg_cache.open(IO_ReadWrite|IO_Truncate);
73 last_msg_id = mail.getNumber(); 62 last_msg_id = mail.getNumber();
74 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 63 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
75 if ( err != MAILPOP3_NO_ERROR ) { 64 if ( err != MAILPOP3_NO_ERROR ) {
76 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 65 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
77 last_msg_id = 0; 66 last_msg_id = 0;
78 return RecBody(); 67 return RecBody();
79 } 68 }
@@ -83,66 +72,42 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
83 msg_cache.open(IO_ReadOnly); 72 msg_cache.open(IO_ReadOnly);
84 message = new char[4096]; 73 message = new char[4096];
85 memset(message,0,4096); 74 memset(message,0,4096);
86 while (msg_cache.readBlock(message,4095)>0) { 75 while (msg_cache.readBlock(message,4095)>0) {
87 msg+=message; 76 msg+=message;
88 memset(message,0,4096); 77 memset(message,0,4096);
89 } 78 }
90 delete message; 79 delete message;
91 message = (char*)malloc(msg.length()+1*sizeof(char)); 80 message = (char*)malloc(msg.length()+1*sizeof(char));
92 memset(message,0,msg.length()+1); 81 memset(message,0,msg.length()+1);
93 memcpy(message,msg.latin1(),msg.length()); 82 memcpy(message,msg.latin1(),msg.length());
94 } 83 }
95 body = parseMail(message);
96 free(message);
97 return body;
98}
99
100RecBody POP3wrapper::parseMail( char *message )
101{
102 int err = MAILIMF_NO_ERROR;
103 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
104 size_t curTok = 0;
105 mailimf_message *result = 0;
106 mailmessage * msg=0;
107 mailmime_single_fields fields;
108 84
109 /* is bound to msg and will be freed there */ 85 /* transform to libetpan stuff */
110 struct mailmime * mime=0;
111
112 RecBody body;
113
114
115 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
116 if ( err != MAILIMF_NO_ERROR ) {
117 if (result) mailimf_message_free(result);
118 return body;
119 }
120
121 char*body_msg = message;
122 msg = mailmessage_new(); 86 msg = mailmessage_new();
123 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); 87 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message));
124 generic_message_t * msg_data; 88 generic_message_t * msg_data;
125 msg_data = (generic_message_t *)msg->msg_data; 89 msg_data = (generic_message_t *)msg->msg_data;
126 msg_data->msg_fetched = 1; 90 msg_data->msg_fetched = 1;
127 msg_data->msg_message = body_msg; 91 msg_data->msg_message = message;
128 msg_data->msg_length = strlen(body_msg); 92 msg_data->msg_length = strlen(message);
129 93
94 /* parse the mail */
95 body = parseMail(msg);
130 96
131 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 97 /* clean up */
132 err = mailmessage_get_bodystructure(msg,&mime); 98 mailmessage_free(msg);
133 traverseBody(body,msg,mime); 99 free(message);
134
135 mailmessage_free(msg);
136 100
101 /* finish */
137 return body; 102 return body;
138} 103}
139 104
140void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 105void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
141{ 106{
142 int err = MAILPOP3_NO_ERROR; 107 int err = MAILPOP3_NO_ERROR;
143 char * header = 0; 108 char * header = 0;
144 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 109 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
145 size_t length = 0; 110 size_t length = 0;
146 carray * messages = 0; 111 carray * messages = 0;
147 112
148 login(); 113 login();
@@ -160,193 +125,24 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
160 free(header); 125 free(header);
161 return; 126 return;
162 } 127 }
163 RecMail *mail = parseHeader( header ); 128 RecMail *mail = parseHeader( header );
164 mail->setNumber( info->msg_index ); 129 mail->setNumber( info->msg_index );
165 mail->setWrapper(this); 130 mail->setWrapper(this);
166 mail->setMsgsize(info->msg_size); 131 mail->setMsgsize(info->msg_size);
167 target.append( mail ); 132 target.append( mail );
168 free(header); 133 free(header);
169 } 134 }
170} 135}
171 136
172RecMail *POP3wrapper::parseHeader( const char *header )
173{
174 int err = MAILIMF_NO_ERROR;
175 size_t curTok = 0;
176 RecMail *mail = new RecMail();
177 mailimf_fields *fields;
178 mailimf_references * refs;
179 mailimf_keywords*keys;
180 QString status;
181 QString value;
182 QBitArray mFlags(7);
183
184 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
185 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
186 mailimf_field *field = (mailimf_field *) current->data;
187 switch ( field->fld_type ) {
188 case MAILIMF_FIELD_FROM:
189 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
190 break;
191 case MAILIMF_FIELD_TO:
192 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
193 break;
194 case MAILIMF_FIELD_CC:
195 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
196 break;
197 case MAILIMF_FIELD_BCC:
198 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
199 break;
200 case MAILIMF_FIELD_SUBJECT:
201 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
202 break;
203 case MAILIMF_FIELD_ORIG_DATE:
204 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
205 break;
206 case MAILIMF_FIELD_MESSAGE_ID:
207 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
208 break;
209 case MAILIMF_FIELD_REFERENCES:
210 refs = field->fld_data.fld_references;
211 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
212 char * text = (char*)refs->mid_list->first->data;
213 mail->setReplyto(QString(text));
214 }
215 break;
216 case MAILIMF_FIELD_KEYWORDS:
217 keys = field->fld_data.fld_keywords;
218 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
219 qDebug("Keyword: %s",(char*)cur->data);
220 }
221 break;
222 case MAILIMF_FIELD_OPTIONAL_FIELD:
223 status = field->fld_data.fld_optional_field->fld_name;
224 value = field->fld_data.fld_optional_field->fld_value;
225 if (status.lower()=="status") {
226 if (value.lower()=="ro") {
227 mFlags.setBit(FLAG_SEEN);
228 }
229 } else if (status.lower()=="x-status") {
230 qDebug("X-Status: %s",value.latin1());
231 if (value.lower()=="a") {
232 mFlags.setBit(FLAG_ANSWERED);
233 }
234 } else {
235// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
236// field->fld_data.fld_optional_field->fld_value);
237 }
238 break;
239 default:
240 qDebug("Non parsed field");
241 break;
242 }
243 }
244 if (fields) mailimf_fields_free(fields);
245 mail->setFlags(mFlags);
246 return mail;
247}
248
249QString POP3wrapper::parseDateTime( mailimf_date_time *date )
250{
251 char tmp[23];
252
253 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
254 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
255
256 return QString( tmp );
257}
258
259QString POP3wrapper::parseAddressList( mailimf_address_list *list )
260{
261 QString result( "" );
262
263 bool first = true;
264 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
265 mailimf_address *addr = (mailimf_address *) current->data;
266
267 if ( !first ) {
268 result.append( "," );
269 } else {
270 first = false;
271 }
272
273 switch ( addr->ad_type ) {
274 case MAILIMF_ADDRESS_MAILBOX:
275 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
276 break;
277 case MAILIMF_ADDRESS_GROUP:
278 result.append( parseGroup( addr->ad_data.ad_group ) );
279 break;
280 default:
281 qDebug( "POP3: unkown mailimf address type" );
282 break;
283 }
284 }
285
286 return result;
287}
288
289QString POP3wrapper::parseGroup( mailimf_group *group )
290{
291 QString result( "" );
292
293 result.append( group->grp_display_name );
294 result.append( ": " );
295
296 if ( group->grp_mb_list != NULL ) {
297 result.append( parseMailboxList( group->grp_mb_list ) );
298 }
299
300 result.append( ";" );
301
302 return result;
303}
304
305QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
306{
307 QString result( "" );
308
309 if ( box->mb_display_name == NULL ) {
310 result.append( box->mb_addr_spec );
311 } else {
312 result.append( convert_String(box->mb_display_name).latin1() );
313 result.append( " <" );
314 result.append( box->mb_addr_spec );
315 result.append( ">" );
316 }
317
318 return result;
319}
320
321QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
322{
323 QString result( "" );
324
325 bool first = true;
326 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
327 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
328
329 if ( !first ) {
330 result.append( "," );
331 } else {
332 first = false;
333 }
334
335 result.append( parseMailbox( box ) );
336 }
337
338 return result;
339}
340
341void POP3wrapper::login() 137void POP3wrapper::login()
342{ 138{
343 /* we'll hold the line */ 139 /* we'll hold the line */
344 if ( m_pop3 != NULL ) return; 140 if ( m_pop3 != NULL ) return;
345 141
346 const char *server, *user, *pass; 142 const char *server, *user, *pass;
347 uint16_t port; 143 uint16_t port;
348 int err = MAILPOP3_NO_ERROR; 144 int err = MAILPOP3_NO_ERROR;
349 145
350 server = account->getServer().latin1(); 146 server = account->getServer().latin1();
351 port = account->getPort().toUInt(); 147 port = account->getPort().toUInt();
352 148
@@ -410,209 +206,25 @@ void POP3wrapper::logout()
410QList<Folder>* POP3wrapper::listFolders() 206QList<Folder>* POP3wrapper::listFolders()
411{ 207{
412 /* TODO: integrate MH directories 208 /* TODO: integrate MH directories
413 but not before version 0.1 ;) 209 but not before version 0.1 ;)
414 */ 210 */
415 QList<Folder> * folders = new QList<Folder>(); 211 QList<Folder> * folders = new QList<Folder>();
416 folders->setAutoDelete( false ); 212 folders->setAutoDelete( false );
417 Folder*inb=new Folder("INBOX","/"); 213 Folder*inb=new Folder("INBOX","/");
418 folders->append(inb); 214 folders->append(inb);
419 return folders; 215 return folders;
420} 216}
421 217
422QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
423{
424 encodedString*t = fetchDecodedPart(mail,part);
425 QString text=t->Content();
426 delete t;
427 return text;
428}
429
430void POP3wrapper::deleteMail(const RecMail&mail) 218void POP3wrapper::deleteMail(const RecMail&mail)
431{ 219{
432 login(); 220 login();
433 if (!m_pop3) return; 221 if (!m_pop3) return;
434 int err = mailpop3_dele(m_pop3,mail.getNumber()); 222 int err = mailpop3_dele(m_pop3,mail.getNumber());
435 if (err != MAILPOP3_NO_ERROR) { 223 if (err != MAILPOP3_NO_ERROR) {
436 qDebug("error deleting mail"); 224 qDebug("error deleting mail");
437 } 225 }
438} 226}
439 227
440void POP3wrapper::answeredMail(const RecMail&) 228void POP3wrapper::answeredMail(const RecMail&)
441{ 229{
442} 230}
443
444encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
445{
446 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
447 if (it==bodyCache.end()) return new encodedString();
448 encodedString*t = decode_String(it.data(),part.Encoding());
449 return t;
450}
451
452encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
453{
454 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
455 if (it==bodyCache.end()) return new encodedString();
456 encodedString*t = it.data();
457 return t;
458}
459
460void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
461{
462 if (current_rec >= 10) {
463 qDebug("too deep recursion!");
464 }
465 if (!message || !mime) {
466 return;
467 }
468 int r;
469 char*data = 0;
470 size_t len;
471 clistiter * cur = 0;
472 int res;
473 QString b;
474 RecPart part;
475
476 switch (mime->mm_type) {
477 case MAILMIME_SINGLE:
478 r = mailmessage_fetch_section(message,mime,&data,&len);
479 part.setSize(len);
480 fillSingleBody(part,message,mime);
481 if (part.Type()=="text" && target.Bodytext().isNull()) {
482 encodedString*r = new encodedString();
483 r->setContent(data,len);
484 encodedString*res = decode_String(r,part.Encoding());
485 b = QString(res->Content());
486 delete r;
487 delete res;
488 target.setBodytext(b);
489 target.setDescription(part);
490 } else {
491 b = gen_attachment_id();
492 part.setIdentifier(b);
493 bodyCache[b]=new encodedString(data,len);
494 target.addPart(part);
495 }
496 break;
497 case MAILMIME_MULTIPLE:
498 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
499 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
500 }
501 break;
502 case MAILMIME_MESSAGE:
503 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
504 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1);
505 }
506 break;
507 }
508}
509
510QString POP3wrapper::getencoding(mailmime_mechanism*aEnc)
511{
512 QString enc="7bit";
513 if (!aEnc) return enc;
514 switch(aEnc->enc_type) {
515 case MAILMIME_MECHANISM_7BIT:
516 enc = "7bit";
517 break;
518 case MAILMIME_MECHANISM_8BIT:
519 enc = "8bit";
520 break;
521 case MAILMIME_MECHANISM_BINARY:
522 enc = "binary";
523 break;
524 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
525 enc = "quoted-printable";
526 break;
527 case MAILMIME_MECHANISM_BASE64:
528 enc = "base64";
529 break;
530 case MAILMIME_MECHANISM_TOKEN:
531 default:
532 if (aEnc->enc_token) {
533 enc = QString(aEnc->enc_token);
534 }
535 break;
536 }
537 return enc;
538}
539
540void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
541{
542 if (!mime) {
543 return;
544 }
545 mailmime_field*field = 0;
546 mailmime_single_fields fields;
547 memset(&fields, 0, sizeof(struct mailmime_single_fields));
548 if (mime->mm_mime_fields != NULL) {
549 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
550 mime->mm_content_type);
551 }
552
553 mailmime_content*type = fields.fld_content;
554 clistcell*current;
555 if (!type) {
556 target.setType("text");
557 target.setSubtype("plain");
558 } else {
559 target.setSubtype(type->ct_subtype);
560 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
561 case MAILMIME_DISCRETE_TYPE_TEXT:
562 target.setType("text");
563 break;
564 case MAILMIME_DISCRETE_TYPE_IMAGE:
565 target.setType("image");
566 break;
567 case MAILMIME_DISCRETE_TYPE_AUDIO:
568 target.setType("audio");
569 break;
570 case MAILMIME_DISCRETE_TYPE_VIDEO:
571 target.setType("video");
572 break;
573 case MAILMIME_DISCRETE_TYPE_APPLICATION:
574 target.setType("application");
575 break;
576 case MAILMIME_DISCRETE_TYPE_EXTENSION:
577 default:
578 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
579 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
580 }
581 break;
582 }
583 if (type->ct_parameters) {
584 fillParameters(target,type->ct_parameters);
585 }
586 }
587 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
588 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
589 field = (mailmime_field*)current->data;
590 switch(field->fld_type) {
591 case MAILMIME_FIELD_TRANSFER_ENCODING:
592 target.setEncoding(getencoding(field->fld_data.fld_encoding));
593 break;
594 case MAILMIME_FIELD_ID:
595 target.setIdentifier(field->fld_data.fld_id);
596 break;
597 case MAILMIME_FIELD_DESCRIPTION:
598 target.setDescription(field->fld_data.fld_description);
599 break;
600 default:
601 break;
602 }
603 }
604 }
605}
606
607void POP3wrapper::fillParameters(RecPart&target,clist*parameters)
608{
609 if (!parameters) {return;}
610 clistcell*current=0;
611 mailmime_parameter*param;
612 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
613 param = (mailmime_parameter*)current->data;
614 if (param) {
615 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
616 }
617 }
618}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 75d70f8..b738cca 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,69 +1,32 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include <libetpan/clist.h>
5#include "mailwrapper.h" 4#include "mailwrapper.h"
6#include "abstractmail.h" 5#include "genericwrapper.h"
7#include <qmap.h>
8#include <qstring.h> 6#include <qstring.h>
9 7
10class RecMail;
11class RecBody;
12class encodedString;
13struct mailpop3;
14struct mailmessage;
15struct mailmime;
16struct mailmime_mechanism;
17struct mailimf_mailbox_list;
18struct mailimf_mailbox;
19struct mailimf_date_time;
20struct mailimf_group;
21struct mailimf_address_list;
22 8
23class POP3wrapper : public AbstractMail 9class POP3wrapper : public Genericwrapper
24{ 10{
25 Q_OBJECT 11 Q_OBJECT
26 12
27public: 13public:
28 POP3wrapper( POP3account *a ); 14 POP3wrapper( POP3account *a );
29 virtual ~POP3wrapper(); 15 virtual ~POP3wrapper();
30 /* mailbox will be ignored */ 16 /* mailbox will be ignored */
31 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
32 virtual QList<Folder>* listFolders(); 18 virtual QList<Folder>* listFolders();
33 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
36 19
37 virtual void deleteMail(const RecMail&mail); 20 virtual void deleteMail(const RecMail&mail);
38 virtual void answeredMail(const RecMail&mail); 21 virtual void answeredMail(const RecMail&mail);
39 22
40 RecBody fetchBody( const RecMail &mail ); 23 virtual RecBody fetchBody( const RecMail &mail );
41 static void pop3_progress( size_t current, size_t maximum ); 24 static void pop3_progress( size_t current, size_t maximum );
42 25
43protected: 26protected:
44 void login(); 27 void login();
45 void logout(); 28 void logout();
46 29
47 RecMail *parseHeader( const char *header );
48 RecBody parseMail( char *message );
49 QString parseMailboxList( mailimf_mailbox_list *list );
50 QString parseMailbox( mailimf_mailbox *box );
51 QString parseGroup( mailimf_group *group );
52 QString parseAddressList( mailimf_address_list *list );
53 QString parseDateTime( mailimf_date_time *date );
54
55 void cleanUpCache();
56
57 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0);
58 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
59 static void fillParameters(RecPart&target,clist*parameters);
60 static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc);
61
62 POP3account *account;
63 mailpop3 *m_pop3;
64 QString msgTempName;
65 unsigned int last_msg_id;
66 QMap<QString,encodedString*> bodyCache;
67}; 30};
68 31
69#endif 32#endif
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index 2542344..dd3c337 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -1,66 +1,70 @@
1 CONFIG += qt warn_on debug quick-app 1CONFIG += qt warn_on debug quick-app
2 2
3 HEADERS = defines.h \ 3HEADERS = defines.h \
4 logindialog.h \ 4 logindialog.h \
5 settings.h \ 5 settings.h \
6 editaccounts.h \ 6 editaccounts.h \
7 mailwrapper.h \ 7 mailwrapper.h \
8 composemail.h \ 8 composemail.h \
9 accountview.h \ 9 accountview.h \
10 mainwindow.h \ 10 mainwindow.h \
11 viewmail.h \ 11 viewmail.h \
12 viewmailbase.h \ 12 viewmailbase.h \
13 opiemail.h \ 13 opiemail.h \
14 imapwrapper.h \ 14 imapwrapper.h \
15 mailtypes.h \ 15 mailtypes.h \
16 mailistviewitem.h \ 16 mailistviewitem.h \
17 pop3wrapper.h \ 17 pop3wrapper.h \
18 abstractmail.h \ 18 abstractmail.h \
19 settingsdialog.h \ 19 settingsdialog.h \
20 statuswidget.h \ 20 statuswidget.h \
21 smtpwrapper.h 21 smtpwrapper.h \
22 genericwrapper.h \
23 mboxwrapper.h
22 24
23 SOURCES = main.cpp \ 25SOURCES = main.cpp \
24 opiemail.cpp \ 26 opiemail.cpp \
25 mainwindow.cpp \ 27 mainwindow.cpp \
26 accountview.cpp \ 28 accountview.cpp \
27 composemail.cpp \ 29 composemail.cpp \
28 mailwrapper.cpp \ 30 mailwrapper.cpp \
29 imapwrapper.cpp \ 31 imapwrapper.cpp \
30 addresspicker.cpp \ 32 addresspicker.cpp \
31 editaccounts.cpp \ 33 editaccounts.cpp \
32 logindialog.cpp \ 34 logindialog.cpp \
33 viewmail.cpp \ 35 viewmail.cpp \
34 viewmailbase.cpp \ 36 viewmailbase.cpp \
35 settings.cpp \ 37 settings.cpp \
36 mailtypes.cpp \ 38 mailtypes.cpp \
37 pop3wrapper.cpp \ 39 pop3wrapper.cpp \
38 abstractmail.cpp \ 40 abstractmail.cpp \
39 settingsdialog.cpp \ 41 settingsdialog.cpp \
40 statuswidget.cpp \ 42 statuswidget.cpp \
41 smtpwrapper.cpp 43 smtpwrapper.cpp \
44 genericwrapper.cpp \
45 mboxwrapper.cpp
42 46
43 INTERFACES = editaccountsui.ui \ 47INTERFACES = editaccountsui.ui \
44 selectmailtypeui.ui \ 48 selectmailtypeui.ui \
45 imapconfigui.ui \ 49 imapconfigui.ui \
46 pop3configui.ui \ 50 pop3configui.ui \
47 nntpconfigui.ui \ 51 nntpconfigui.ui \
48 smtpconfigui.ui \ 52 smtpconfigui.ui \
49 addresspickerui.ui \ 53 addresspickerui.ui \
50 logindialogui.ui \ 54 logindialogui.ui \
51 composemailui.ui \ 55 composemailui.ui \
52 settingsdialogui.ui \ 56 settingsdialogui.ui \
53 statuswidgetui.ui 57 statuswidgetui.ui
54 58
55INCLUDEPATH += $(OPIEDIR)/include 59INCLUDEPATH += $(OPIEDIR)/include
56 60
57CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 61CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
58contains( CONFTEST, y ){ 62contains( CONFTEST, y ){
59 LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv 63 LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv
60}else{ 64}else{
61 LIBS += -lqpe -letpan -lssl -lcrypto -lopie 65 LIBS += -lqpe -letpan -lssl -lcrypto -lopie
62} 66}
63 67
64TARGET = opiemail 68TARGET = opiemail
65 69
66include ( $(OPIEDIR)/include.pro ) 70include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index d3447f4..efd83ba 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -2,78 +2,67 @@
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/mailpop3.h> 5#include <libetpan/mailpop3.h>
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/data_message_driver.h> 7#include <libetpan/data_message_driver.h>
8#include <qfile.h> 8#include <qfile.h>
9 9
10/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
12 12
13POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
14 : Genericwrapper()
14{ 15{
15 account = a; 16 account = a;
16 m_pop3 = NULL; 17 m_pop3 = NULL;
17 msgTempName = a->getFileName()+"_msg_cache"; 18 msgTempName = a->getFileName()+"_msg_cache";
18 last_msg_id = 0; 19 last_msg_id = 0;
19 bodyCache.clear();
20} 20}
21 21
22POP3wrapper::~POP3wrapper() 22POP3wrapper::~POP3wrapper()
23{ 23{
24 logout(); 24 logout();
25 QFile msg_cache(msgTempName); 25 QFile msg_cache(msgTempName);
26 if (msg_cache.exists()) { 26 if (msg_cache.exists()) {
27 msg_cache.remove(); 27 msg_cache.remove();
28 } 28 }
29 cleanUpCache();
30}
31
32void POP3wrapper::cleanUpCache()
33{
34 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
35 for (;it!=bodyCache.end();++it) {
36 encodedString*t = it.data();
37 //it.setValue(0);
38 if (t) delete t;
39 }
40 bodyCache.clear();
41} 29}
42 30
43void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 31void POP3wrapper::pop3_progress( size_t current, size_t maximum )
44{ 32{
45 //qDebug( "POP3: %i of %i", current, maximum ); 33 //qDebug( "POP3: %i of %i", current, maximum );
46} 34}
47 35
48RecBody POP3wrapper::fetchBody( const RecMail &mail ) 36RecBody POP3wrapper::fetchBody( const RecMail &mail )
49{ 37{
50 int err = MAILPOP3_NO_ERROR; 38 int err = MAILPOP3_NO_ERROR;
51 char *message; 39 char *message;
52 size_t length = 0; 40 size_t length = 0;
53 41
54 login(); 42 login();
55 if ( !m_pop3 ) { 43 if ( !m_pop3 ) {
56 return RecBody(); 44 return RecBody();
57 } 45 }
58 46
59 RecBody body; 47 RecBody body;
60 48 mailmessage * msg = 0;
49
61 QFile msg_cache(msgTempName); 50 QFile msg_cache(msgTempName);
62 51
63 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 52 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
64 qDebug("Message to large: %i",mail.Msgsize()); 53 qDebug("Message to large: %i",mail.Msgsize());
65 return body; 54 return body;
66 } 55 }
67 cleanUpCache(); 56 cleanMimeCache();
68 if (mail.getNumber()!=last_msg_id) { 57 if (mail.getNumber()!=last_msg_id) {
69 if (msg_cache.exists()) { 58 if (msg_cache.exists()) {
70 msg_cache.remove(); 59 msg_cache.remove();
71 } 60 }
72 msg_cache.open(IO_ReadWrite|IO_Truncate); 61 msg_cache.open(IO_ReadWrite|IO_Truncate);
73 last_msg_id = mail.getNumber(); 62 last_msg_id = mail.getNumber();
74 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 63 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
75 if ( err != MAILPOP3_NO_ERROR ) { 64 if ( err != MAILPOP3_NO_ERROR ) {
76 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 65 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
77 last_msg_id = 0; 66 last_msg_id = 0;
78 return RecBody(); 67 return RecBody();
79 } 68 }
@@ -83,66 +72,42 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
83 msg_cache.open(IO_ReadOnly); 72 msg_cache.open(IO_ReadOnly);
84 message = new char[4096]; 73 message = new char[4096];
85 memset(message,0,4096); 74 memset(message,0,4096);
86 while (msg_cache.readBlock(message,4095)>0) { 75 while (msg_cache.readBlock(message,4095)>0) {
87 msg+=message; 76 msg+=message;
88 memset(message,0,4096); 77 memset(message,0,4096);
89 } 78 }
90 delete message; 79 delete message;
91 message = (char*)malloc(msg.length()+1*sizeof(char)); 80 message = (char*)malloc(msg.length()+1*sizeof(char));
92 memset(message,0,msg.length()+1); 81 memset(message,0,msg.length()+1);
93 memcpy(message,msg.latin1(),msg.length()); 82 memcpy(message,msg.latin1(),msg.length());
94 } 83 }
95 body = parseMail(message);
96 free(message);
97 return body;
98}
99
100RecBody POP3wrapper::parseMail( char *message )
101{
102 int err = MAILIMF_NO_ERROR;
103 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
104 size_t curTok = 0;
105 mailimf_message *result = 0;
106 mailmessage * msg=0;
107 mailmime_single_fields fields;
108 84
109 /* is bound to msg and will be freed there */ 85 /* transform to libetpan stuff */
110 struct mailmime * mime=0;
111
112 RecBody body;
113
114
115 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
116 if ( err != MAILIMF_NO_ERROR ) {
117 if (result) mailimf_message_free(result);
118 return body;
119 }
120
121 char*body_msg = message;
122 msg = mailmessage_new(); 86 msg = mailmessage_new();
123 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); 87 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message));
124 generic_message_t * msg_data; 88 generic_message_t * msg_data;
125 msg_data = (generic_message_t *)msg->msg_data; 89 msg_data = (generic_message_t *)msg->msg_data;
126 msg_data->msg_fetched = 1; 90 msg_data->msg_fetched = 1;
127 msg_data->msg_message = body_msg; 91 msg_data->msg_message = message;
128 msg_data->msg_length = strlen(body_msg); 92 msg_data->msg_length = strlen(message);
129 93
94 /* parse the mail */
95 body = parseMail(msg);
130 96
131 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 97 /* clean up */
132 err = mailmessage_get_bodystructure(msg,&mime); 98 mailmessage_free(msg);
133 traverseBody(body,msg,mime); 99 free(message);
134
135 mailmessage_free(msg);
136 100
101 /* finish */
137 return body; 102 return body;
138} 103}
139 104
140void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 105void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
141{ 106{
142 int err = MAILPOP3_NO_ERROR; 107 int err = MAILPOP3_NO_ERROR;
143 char * header = 0; 108 char * header = 0;
144 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 109 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
145 size_t length = 0; 110 size_t length = 0;
146 carray * messages = 0; 111 carray * messages = 0;
147 112
148 login(); 113 login();
@@ -160,193 +125,24 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
160 free(header); 125 free(header);
161 return; 126 return;
162 } 127 }
163 RecMail *mail = parseHeader( header ); 128 RecMail *mail = parseHeader( header );
164 mail->setNumber( info->msg_index ); 129 mail->setNumber( info->msg_index );
165 mail->setWrapper(this); 130 mail->setWrapper(this);
166 mail->setMsgsize(info->msg_size); 131 mail->setMsgsize(info->msg_size);
167 target.append( mail ); 132 target.append( mail );
168 free(header); 133 free(header);
169 } 134 }
170} 135}
171 136
172RecMail *POP3wrapper::parseHeader( const char *header )
173{
174 int err = MAILIMF_NO_ERROR;
175 size_t curTok = 0;
176 RecMail *mail = new RecMail();
177 mailimf_fields *fields;
178 mailimf_references * refs;
179 mailimf_keywords*keys;
180 QString status;
181 QString value;
182 QBitArray mFlags(7);
183
184 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
185 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
186 mailimf_field *field = (mailimf_field *) current->data;
187 switch ( field->fld_type ) {
188 case MAILIMF_FIELD_FROM:
189 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
190 break;
191 case MAILIMF_FIELD_TO:
192 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
193 break;
194 case MAILIMF_FIELD_CC:
195 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
196 break;
197 case MAILIMF_FIELD_BCC:
198 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
199 break;
200 case MAILIMF_FIELD_SUBJECT:
201 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
202 break;
203 case MAILIMF_FIELD_ORIG_DATE:
204 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
205 break;
206 case MAILIMF_FIELD_MESSAGE_ID:
207 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
208 break;
209 case MAILIMF_FIELD_REFERENCES:
210 refs = field->fld_data.fld_references;
211 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
212 char * text = (char*)refs->mid_list->first->data;
213 mail->setReplyto(QString(text));
214 }
215 break;
216 case MAILIMF_FIELD_KEYWORDS:
217 keys = field->fld_data.fld_keywords;
218 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
219 qDebug("Keyword: %s",(char*)cur->data);
220 }
221 break;
222 case MAILIMF_FIELD_OPTIONAL_FIELD:
223 status = field->fld_data.fld_optional_field->fld_name;
224 value = field->fld_data.fld_optional_field->fld_value;
225 if (status.lower()=="status") {
226 if (value.lower()=="ro") {
227 mFlags.setBit(FLAG_SEEN);
228 }
229 } else if (status.lower()=="x-status") {
230 qDebug("X-Status: %s",value.latin1());
231 if (value.lower()=="a") {
232 mFlags.setBit(FLAG_ANSWERED);
233 }
234 } else {
235// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
236// field->fld_data.fld_optional_field->fld_value);
237 }
238 break;
239 default:
240 qDebug("Non parsed field");
241 break;
242 }
243 }
244 if (fields) mailimf_fields_free(fields);
245 mail->setFlags(mFlags);
246 return mail;
247}
248
249QString POP3wrapper::parseDateTime( mailimf_date_time *date )
250{
251 char tmp[23];
252
253 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
254 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
255
256 return QString( tmp );
257}
258
259QString POP3wrapper::parseAddressList( mailimf_address_list *list )
260{
261 QString result( "" );
262
263 bool first = true;
264 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
265 mailimf_address *addr = (mailimf_address *) current->data;
266
267 if ( !first ) {
268 result.append( "," );
269 } else {
270 first = false;
271 }
272
273 switch ( addr->ad_type ) {
274 case MAILIMF_ADDRESS_MAILBOX:
275 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
276 break;
277 case MAILIMF_ADDRESS_GROUP:
278 result.append( parseGroup( addr->ad_data.ad_group ) );
279 break;
280 default:
281 qDebug( "POP3: unkown mailimf address type" );
282 break;
283 }
284 }
285
286 return result;
287}
288
289QString POP3wrapper::parseGroup( mailimf_group *group )
290{
291 QString result( "" );
292
293 result.append( group->grp_display_name );
294 result.append( ": " );
295
296 if ( group->grp_mb_list != NULL ) {
297 result.append( parseMailboxList( group->grp_mb_list ) );
298 }
299
300 result.append( ";" );
301
302 return result;
303}
304
305QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
306{
307 QString result( "" );
308
309 if ( box->mb_display_name == NULL ) {
310 result.append( box->mb_addr_spec );
311 } else {
312 result.append( convert_String(box->mb_display_name).latin1() );
313 result.append( " <" );
314 result.append( box->mb_addr_spec );
315 result.append( ">" );
316 }
317
318 return result;
319}
320
321QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
322{
323 QString result( "" );
324
325 bool first = true;
326 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
327 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
328
329 if ( !first ) {
330 result.append( "," );
331 } else {
332 first = false;
333 }
334
335 result.append( parseMailbox( box ) );
336 }
337
338 return result;
339}
340
341void POP3wrapper::login() 137void POP3wrapper::login()
342{ 138{
343 /* we'll hold the line */ 139 /* we'll hold the line */
344 if ( m_pop3 != NULL ) return; 140 if ( m_pop3 != NULL ) return;
345 141
346 const char *server, *user, *pass; 142 const char *server, *user, *pass;
347 uint16_t port; 143 uint16_t port;
348 int err = MAILPOP3_NO_ERROR; 144 int err = MAILPOP3_NO_ERROR;
349 145
350 server = account->getServer().latin1(); 146 server = account->getServer().latin1();
351 port = account->getPort().toUInt(); 147 port = account->getPort().toUInt();
352 148
@@ -410,209 +206,25 @@ void POP3wrapper::logout()
410QList<Folder>* POP3wrapper::listFolders() 206QList<Folder>* POP3wrapper::listFolders()
411{ 207{
412 /* TODO: integrate MH directories 208 /* TODO: integrate MH directories
413 but not before version 0.1 ;) 209 but not before version 0.1 ;)
414 */ 210 */
415 QList<Folder> * folders = new QList<Folder>(); 211 QList<Folder> * folders = new QList<Folder>();
416 folders->setAutoDelete( false ); 212 folders->setAutoDelete( false );
417 Folder*inb=new Folder("INBOX","/"); 213 Folder*inb=new Folder("INBOX","/");
418 folders->append(inb); 214 folders->append(inb);
419 return folders; 215 return folders;
420} 216}
421 217
422QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
423{
424 encodedString*t = fetchDecodedPart(mail,part);
425 QString text=t->Content();
426 delete t;
427 return text;
428}
429
430void POP3wrapper::deleteMail(const RecMail&mail) 218void POP3wrapper::deleteMail(const RecMail&mail)
431{ 219{
432 login(); 220 login();
433 if (!m_pop3) return; 221 if (!m_pop3) return;
434 int err = mailpop3_dele(m_pop3,mail.getNumber()); 222 int err = mailpop3_dele(m_pop3,mail.getNumber());
435 if (err != MAILPOP3_NO_ERROR) { 223 if (err != MAILPOP3_NO_ERROR) {
436 qDebug("error deleting mail"); 224 qDebug("error deleting mail");
437 } 225 }
438} 226}
439 227
440void POP3wrapper::answeredMail(const RecMail&) 228void POP3wrapper::answeredMail(const RecMail&)
441{ 229{
442} 230}
443
444encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
445{
446 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
447 if (it==bodyCache.end()) return new encodedString();
448 encodedString*t = decode_String(it.data(),part.Encoding());
449 return t;
450}
451
452encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
453{
454 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
455 if (it==bodyCache.end()) return new encodedString();
456 encodedString*t = it.data();
457 return t;
458}
459
460void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
461{
462 if (current_rec >= 10) {
463 qDebug("too deep recursion!");
464 }
465 if (!message || !mime) {
466 return;
467 }
468 int r;
469 char*data = 0;
470 size_t len;
471 clistiter * cur = 0;
472 int res;
473 QString b;
474 RecPart part;
475
476 switch (mime->mm_type) {
477 case MAILMIME_SINGLE:
478 r = mailmessage_fetch_section(message,mime,&data,&len);
479 part.setSize(len);
480 fillSingleBody(part,message,mime);
481 if (part.Type()=="text" && target.Bodytext().isNull()) {
482 encodedString*r = new encodedString();
483 r->setContent(data,len);
484 encodedString*res = decode_String(r,part.Encoding());
485 b = QString(res->Content());
486 delete r;
487 delete res;
488 target.setBodytext(b);
489 target.setDescription(part);
490 } else {
491 b = gen_attachment_id();
492 part.setIdentifier(b);
493 bodyCache[b]=new encodedString(data,len);
494 target.addPart(part);
495 }
496 break;
497 case MAILMIME_MULTIPLE:
498 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
499 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
500 }
501 break;
502 case MAILMIME_MESSAGE:
503 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
504 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1);
505 }
506 break;
507 }
508}
509
510QString POP3wrapper::getencoding(mailmime_mechanism*aEnc)
511{
512 QString enc="7bit";
513 if (!aEnc) return enc;
514 switch(aEnc->enc_type) {
515 case MAILMIME_MECHANISM_7BIT:
516 enc = "7bit";
517 break;
518 case MAILMIME_MECHANISM_8BIT:
519 enc = "8bit";
520 break;
521 case MAILMIME_MECHANISM_BINARY:
522 enc = "binary";
523 break;
524 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
525 enc = "quoted-printable";
526 break;
527 case MAILMIME_MECHANISM_BASE64:
528 enc = "base64";
529 break;
530 case MAILMIME_MECHANISM_TOKEN:
531 default:
532 if (aEnc->enc_token) {
533 enc = QString(aEnc->enc_token);
534 }
535 break;
536 }
537 return enc;
538}
539
540void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
541{
542 if (!mime) {
543 return;
544 }
545 mailmime_field*field = 0;
546 mailmime_single_fields fields;
547 memset(&fields, 0, sizeof(struct mailmime_single_fields));
548 if (mime->mm_mime_fields != NULL) {
549 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
550 mime->mm_content_type);
551 }
552
553 mailmime_content*type = fields.fld_content;
554 clistcell*current;
555 if (!type) {
556 target.setType("text");
557 target.setSubtype("plain");
558 } else {
559 target.setSubtype(type->ct_subtype);
560 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
561 case MAILMIME_DISCRETE_TYPE_TEXT:
562 target.setType("text");
563 break;
564 case MAILMIME_DISCRETE_TYPE_IMAGE:
565 target.setType("image");
566 break;
567 case MAILMIME_DISCRETE_TYPE_AUDIO:
568 target.setType("audio");
569 break;
570 case MAILMIME_DISCRETE_TYPE_VIDEO:
571 target.setType("video");
572 break;
573 case MAILMIME_DISCRETE_TYPE_APPLICATION:
574 target.setType("application");
575 break;
576 case MAILMIME_DISCRETE_TYPE_EXTENSION:
577 default:
578 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
579 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
580 }
581 break;
582 }
583 if (type->ct_parameters) {
584 fillParameters(target,type->ct_parameters);
585 }
586 }
587 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
588 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
589 field = (mailmime_field*)current->data;
590 switch(field->fld_type) {
591 case MAILMIME_FIELD_TRANSFER_ENCODING:
592 target.setEncoding(getencoding(field->fld_data.fld_encoding));
593 break;
594 case MAILMIME_FIELD_ID:
595 target.setIdentifier(field->fld_data.fld_id);
596 break;
597 case MAILMIME_FIELD_DESCRIPTION:
598 target.setDescription(field->fld_data.fld_description);
599 break;
600 default:
601 break;
602 }
603 }
604 }
605}
606
607void POP3wrapper::fillParameters(RecPart&target,clist*parameters)
608{
609 if (!parameters) {return;}
610 clistcell*current=0;
611 mailmime_parameter*param;
612 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
613 param = (mailmime_parameter*)current->data;
614 if (param) {
615 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
616 }
617 }
618}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 75d70f8..b738cca 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,69 +1,32 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include <libetpan/clist.h>
5#include "mailwrapper.h" 4#include "mailwrapper.h"
6#include "abstractmail.h" 5#include "genericwrapper.h"
7#include <qmap.h>
8#include <qstring.h> 6#include <qstring.h>
9 7
10class RecMail;
11class RecBody;
12class encodedString;
13struct mailpop3;
14struct mailmessage;
15struct mailmime;
16struct mailmime_mechanism;
17struct mailimf_mailbox_list;
18struct mailimf_mailbox;
19struct mailimf_date_time;
20struct mailimf_group;
21struct mailimf_address_list;
22 8
23class POP3wrapper : public AbstractMail 9class POP3wrapper : public Genericwrapper
24{ 10{
25 Q_OBJECT 11 Q_OBJECT
26 12
27public: 13public:
28 POP3wrapper( POP3account *a ); 14 POP3wrapper( POP3account *a );
29 virtual ~POP3wrapper(); 15 virtual ~POP3wrapper();
30 /* mailbox will be ignored */ 16 /* mailbox will be ignored */
31 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
32 virtual QList<Folder>* listFolders(); 18 virtual QList<Folder>* listFolders();
33 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
36 19
37 virtual void deleteMail(const RecMail&mail); 20 virtual void deleteMail(const RecMail&mail);
38 virtual void answeredMail(const RecMail&mail); 21 virtual void answeredMail(const RecMail&mail);
39 22
40 RecBody fetchBody( const RecMail &mail ); 23 virtual RecBody fetchBody( const RecMail &mail );
41 static void pop3_progress( size_t current, size_t maximum ); 24 static void pop3_progress( size_t current, size_t maximum );
42 25
43protected: 26protected:
44 void login(); 27 void login();
45 void logout(); 28 void logout();
46 29
47 RecMail *parseHeader( const char *header );
48 RecBody parseMail( char *message );
49 QString parseMailboxList( mailimf_mailbox_list *list );
50 QString parseMailbox( mailimf_mailbox *box );
51 QString parseGroup( mailimf_group *group );
52 QString parseAddressList( mailimf_address_list *list );
53 QString parseDateTime( mailimf_date_time *date );
54
55 void cleanUpCache();
56
57 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0);
58 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
59 static void fillParameters(RecPart&target,clist*parameters);
60 static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc);
61
62 POP3account *account;
63 mailpop3 *m_pop3;
64 QString msgTempName;
65 unsigned int last_msg_id;
66 QMap<QString,encodedString*> bodyCache;
67}; 30};
68 31
69#endif 32#endif
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index e11fe1f..0ad7359 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -245,24 +245,25 @@ void ViewMail::setText()
245 if ( !m_showHtml ) { 245 if ( !m_showHtml ) {
246 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); 246 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" );
247 } else { 247 } else {
248 browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" ); 248 browser->setText( QString( m_mailHtml) + m_mail[2] + "</font></html>" );
249 } 249 }
250 // remove later in favor of a real handling 250 // remove later in favor of a real handling
251 m_gotBody = true; 251 m_gotBody = true;
252} 252}
253 253
254 254
255ViewMail::~ViewMail() 255ViewMail::~ViewMail()
256{ 256{
257 m_recMail.Wrapper()->cleanMimeCache();
257 hide(); 258 hide();
258} 259}
259 260
260void ViewMail::hide() 261void ViewMail::hide()
261{ 262{
262 QWidget::hide(); 263 QWidget::hide();
263 264
264 if (_inLoop) { 265 if (_inLoop) {
265 _inLoop = false; 266 _inLoop = false;
266 qApp->exit_loop(); 267 qApp->exit_loop();
267 268
268 } 269 }