summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-16 02:13:09 (UTC)
committer alwin <alwin>2003-12-16 02:13:09 (UTC)
commitf42c15f884d4377bc99d73e16fa1722b0fb2a4d3 (patch) (unidiff)
tree0ecd625c8a5913285fa31a050a9a6e49c13fbe4b
parent32d48372f7b5ec9e4586ea74cc444838b157248e (diff)
downloadopie-f42c15f884d4377bc99d73e16fa1722b0fb2a4d3.zip
opie-f42c15f884d4377bc99d73e16fa1722b0fb2a4d3.tar.gz
opie-f42c15f884d4377bc99d73e16fa1722b0fb2a4d3.tar.bz2
quoted-printable text will be decoded for display
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp21
-rw-r--r--noncore/net/mail/abstractmail.h4
-rw-r--r--noncore/net/mail/imapwrapper.cpp18
-rw-r--r--noncore/net/mail/imapwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp21
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h4
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp18
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h4
8 files changed, 78 insertions, 16 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
index 7380c31..0bb2525 100644
--- a/noncore/net/mail/abstractmail.cpp
+++ b/noncore/net/mail/abstractmail.cpp
@@ -1,13 +1,34 @@
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 4
5#include <qstring.h>
6#include <stdlib.h>
7#include <libetpan/mailmime_content.h>
8
5AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 9AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
6{ 10{
7 return new IMAPwrapper(a); 11 return new IMAPwrapper(a);
8} 12}
9 13
10AbstractMail* AbstractMail::getWrapper(POP3account *a) 14AbstractMail* AbstractMail::getWrapper(POP3account *a)
11{ 15{
12 return new POP3wrapper(a); 16 return new POP3wrapper(a);
13} 17}
18
19QString AbstractMail::decode_quoted_printable(const char*text)
20{
21 char*result_text;
22 size_t index = 0;
23 QString result = "";
24 /* reset for recursive use! */
25 size_t target_length = 0;
26 result_text = 0;
27 int err = mailmime_quoted_printable_body_parse(text,strlen(text),
28 &index,&result_text,&target_length,0);
29 if (result_text) {
30 result = result_text;
31 free(result_text);
32 }
33 return result;
34}
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index 62e0715..4473ad2 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -1,31 +1,31 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13 13
14class AbstractMail:public QObject 14class AbstractMail:public QObject
15{ 15{
16 Q_OBJECT 16 Q_OBJECT
17public: 17public:
18 AbstractMail(){}; 18 AbstractMail(){};
19 virtual ~AbstractMail(){} 19 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0; 20 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0; 22 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; 23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
24 virtual void deleteMail(const RecMail&mail)=0; 24 virtual void deleteMail(const RecMail&mail)=0;
25 virtual void answeredMail(const RecMail&mail)=0; 25 virtual void answeredMail(const RecMail&mail)=0;
26 26
27 static AbstractMail* getWrapper(IMAPaccount *a); 27 static AbstractMail* getWrapper(IMAPaccount *a);
28 static AbstractMail* getWrapper(POP3account *a); 28 static AbstractMail* getWrapper(POP3account *a);
29 static QString decode_quoted_printable(const char*text);
29}; 30};
30
31#endif 31#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index ad95384..a4e6228 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,776 +1,786 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 152 folders->setAutoDelete( false );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 169 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 173 // instead of using strdup!
174 temp = list->mb_name; 174 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
176 current = current->next; 176 current = current->next;
177 } 177 }
178 } else { 178 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 180 }
181 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
182 182
183/* 183/*
184 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
185 */ 185 */
186 mask = "*" ; 186 mask = "*" ;
187 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
188 if (!path) path = ""; 188 if (!path) path = "";
189 result = clist_new(); 189 result = clist_new();
190 qDebug(path); 190 qDebug(path);
191 bool selectable = true; 191 bool selectable = true;
192 mailimap_mbx_list_flags*bflags; 192 mailimap_mbx_list_flags*bflags;
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 194 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 195 current = result->first;
196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
197 list = (mailimap_mailbox_list *) current->data; 197 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 198 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 199 // instead of using strdup!
200 temp = list->mb_name; 200 temp = list->mb_name;
201 if (temp.lower()=="inbox") 201 if (temp.lower()=="inbox")
202 continue; 202 continue;
203 if (temp.lower()==account->getPrefix().lower()) 203 if (temp.lower()==account->getPrefix().lower())
204 continue; 204 continue;
205 if ( (bflags = list->mb_flag) ) { 205 if ( (bflags = list->mb_flag) ) {
206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
208 } 208 }
209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); 209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix()));
210 } 210 }
211 } else { 211 } else {
212 qDebug("error fetching folders %s",m_imap->imap_response); 212 qDebug("error fetching folders %s",m_imap->imap_response);
213 } 213 }
214 mailimap_list_result_free( result ); 214 mailimap_list_result_free( result );
215 return folders; 215 return folders;
216} 216}
217 217
218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
219{ 219{
220 RecMail * m = 0; 220 RecMail * m = 0;
221 mailimap_msg_att_item *item=0; 221 mailimap_msg_att_item *item=0;
222 clistcell *current,*c,*cf; 222 clistcell *current,*c,*cf;
223 mailimap_msg_att_dynamic*flist; 223 mailimap_msg_att_dynamic*flist;
224 mailimap_flag_fetch*cflag; 224 mailimap_flag_fetch*cflag;
225 int size; 225 int size;
226 QBitArray mFlags(7); 226 QBitArray mFlags(7);
227 QStringList addresslist; 227 QStringList addresslist;
228 228
229 if (!m_att) { 229 if (!m_att) {
230 return m; 230 return m;
231 } 231 }
232 m = new RecMail(); 232 m = new RecMail();
233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
234 current = c; 234 current = c;
235 size = 0; 235 size = 0;
236 item = (mailimap_msg_att_item*)current->data; 236 item = (mailimap_msg_att_item*)current->data;
237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
239 if (!flist->att_list) { 239 if (!flist->att_list) {
240 continue; 240 continue;
241 } 241 }
242 cf = flist->att_list->first; 242 cf = flist->att_list->first;
243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
244 cflag = (mailimap_flag_fetch*)cf->data; 244 cflag = (mailimap_flag_fetch*)cf->data;
245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
246 switch (cflag->fl_flag->fl_type) { 246 switch (cflag->fl_flag->fl_type) {
247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
248 mFlags.setBit(FLAG_ANSWERED); 248 mFlags.setBit(FLAG_ANSWERED);
249 break; 249 break;
250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
251 mFlags.setBit(FLAG_FLAGGED); 251 mFlags.setBit(FLAG_FLAGGED);
252 break; 252 break;
253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
254 mFlags.setBit(FLAG_DELETED); 254 mFlags.setBit(FLAG_DELETED);
255 break; 255 break;
256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
257 mFlags.setBit(FLAG_SEEN); 257 mFlags.setBit(FLAG_SEEN);
258 break; 258 break;
259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
260 mFlags.setBit(FLAG_DRAFT); 260 mFlags.setBit(FLAG_DRAFT);
261 break; 261 break;
262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
263 break; 263 break;
264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
265 break; 265 break;
266 default: 266 default:
267 break; 267 break;
268 } 268 }
269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
270 mFlags.setBit(FLAG_RECENT); 270 mFlags.setBit(FLAG_RECENT);
271 } 271 }
272 } 272 }
273 continue; 273 continue;
274 } 274 }
275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
277 m->setDate(head->env_date); 277 m->setDate(head->env_date);
278 m->setSubject(head->env_subject); 278 m->setSubject(head->env_subject);
279 if (head->env_from!=NULL) { 279 if (head->env_from!=NULL) {
280 addresslist = address_list_to_stringlist(head->env_from->frm_list); 280 addresslist = address_list_to_stringlist(head->env_from->frm_list);
281 if (addresslist.count()) { 281 if (addresslist.count()) {
282 m->setFrom(addresslist.first()); 282 m->setFrom(addresslist.first());
283 } 283 }
284 } 284 }
285 if (head->env_to!=NULL) { 285 if (head->env_to!=NULL) {
286 addresslist = address_list_to_stringlist(head->env_to->to_list); 286 addresslist = address_list_to_stringlist(head->env_to->to_list);
287 m->setTo(addresslist); 287 m->setTo(addresslist);
288 } 288 }
289 if (head->env_cc!=NULL) { 289 if (head->env_cc!=NULL) {
290 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 290 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
291 m->setCC(addresslist); 291 m->setCC(addresslist);
292 } 292 }
293 if (head->env_bcc!=NULL) { 293 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 295 m->setBcc(addresslist);
296 } 296 }
297 if (head->env_reply_to!=NULL) { 297 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 299 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
301 } 301 }
302 } 302 }
303 m->setMsgid(QString(head->env_message_id)); 303 m->setMsgid(QString(head->env_message_id));
304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
306#if 0 306#if 0
307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
309 qDebug(da.toString()); 309 qDebug(da.toString());
310#endif 310#endif
311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
312 size = item->att_data.att_static->att_data.att_rfc822_size; 312 size = item->att_data.att_static->att_data.att_rfc822_size;
313 } 313 }
314 } 314 }
315 /* msg is already deleted */ 315 /* msg is already deleted */
316 if (mFlags.testBit(FLAG_DELETED) && m) { 316 if (mFlags.testBit(FLAG_DELETED) && m) {
317 delete m; 317 delete m;
318 m = 0; 318 m = 0;
319 } 319 }
320 if (m) { 320 if (m) {
321 m->setFlags(mFlags); 321 m->setFlags(mFlags);
322 m->setMsgsize(size); 322 m->setMsgsize(size);
323 } 323 }
324 return m; 324 return m;
325} 325}
326 326
327RecBody IMAPwrapper::fetchBody(const RecMail&mail) 327RecBody IMAPwrapper::fetchBody(const RecMail&mail)
328{ 328{
329 RecBody body; 329 RecBody body;
330 const char *mb; 330 const char *mb;
331 int err = MAILIMAP_NO_ERROR; 331 int err = MAILIMAP_NO_ERROR;
332 clist *result; 332 clist *result;
333 clistcell *current; 333 clistcell *current;
334 mailimap_fetch_att *fetchAtt; 334 mailimap_fetch_att *fetchAtt;
335 mailimap_fetch_type *fetchType; 335 mailimap_fetch_type *fetchType;
336 mailimap_set *set; 336 mailimap_set *set;
337 mailimap_body*body_desc; 337 mailimap_body*body_desc;
338 338
339 mb = mail.getMbox().latin1(); 339 mb = mail.getMbox().latin1();
340 340
341 login(); 341 login();
342 if (!m_imap) { 342 if (!m_imap) {
343 return body; 343 return body;
344 } 344 }
345 345
346 err = mailimap_select( m_imap, (char*)mb); 346 err = mailimap_select( m_imap, (char*)mb);
347 if ( err != MAILIMAP_NO_ERROR ) { 347 if ( err != MAILIMAP_NO_ERROR ) {
348 qDebug("error selecting mailbox: %s",m_imap->imap_response); 348 qDebug("error selecting mailbox: %s",m_imap->imap_response);
349 return body; 349 return body;
350 } 350 }
351 351
352 result = clist_new(); 352 result = clist_new();
353 /* the range has to start at 1!!! not with 0!!!! */ 353 /* the range has to start at 1!!! not with 0!!!! */
354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
355 fetchAtt = mailimap_fetch_att_new_bodystructure(); 355 fetchAtt = mailimap_fetch_att_new_bodystructure();
356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
357 err = mailimap_fetch( m_imap, set, fetchType, &result ); 357 err = mailimap_fetch( m_imap, set, fetchType, &result );
358 mailimap_set_free( set ); 358 mailimap_set_free( set );
359 mailimap_fetch_type_free( fetchType ); 359 mailimap_fetch_type_free( fetchType );
360 360
361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
362 mailimap_msg_att * msg_att; 362 mailimap_msg_att * msg_att;
363 msg_att = (mailimap_msg_att*)current->data; 363 msg_att = (mailimap_msg_att*)current->data;
364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
365 body_desc = item->att_data.att_static->att_data.att_body; 365 body_desc = item->att_data.att_static->att_data.att_body;
366 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 366 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
367 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 367 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
368 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 368 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
369 qDebug("Mulitpart mail"); 369 qDebug("Mulitpart mail");
370 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 370 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
371 } 371 }
372 } else { 372 } else {
373 qDebug("error fetching body: %s",m_imap->imap_response); 373 qDebug("error fetching body: %s",m_imap->imap_response);
374 } 374 }
375 mailimap_fetch_list_free(result); 375 mailimap_fetch_list_free(result);
376 return body; 376 return body;
377} 377}
378 378
379/* this routine is just called when the mail has only ONE part. 379/* this routine is just called when the mail has only ONE part.
380 for filling the parts of a multi-part-message there are other 380 for filling the parts of a multi-part-message there are other
381 routines 'cause we can not simply fetch the whole body. */ 381 routines 'cause we can not simply fetch the whole body. */
382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
383{ 383{
384 if (!mailDescription) { 384 if (!mailDescription) {
385 return; 385 return;
386 } 386 }
387 QString sub,body_text; 387 QString sub,body_text;
388 RecPart singlePart; 388 RecPart singlePart;
389 QValueList<int> path; 389 QValueList<int> path;
390 fillSinglePart(singlePart,mailDescription); 390 fillSinglePart(singlePart,mailDescription);
391 switch (mailDescription->bd_type) { 391 switch (mailDescription->bd_type) {
392 case MAILIMAP_BODY_TYPE_1PART_MSG: 392 case MAILIMAP_BODY_TYPE_1PART_MSG:
393 path.append(1); 393 path.append(1);
394 body_text = fetchPart(mail,path,true); 394 body_text = fetchPart(mail,path,true);
395 if (singlePart.Encoding()=="quoted-printable") {
396 body_text = decode_quoted_printable(body_text.latin1());
397 }
395 target_body.setBodytext(body_text); 398 target_body.setBodytext(body_text);
396 target_body.setDescription(singlePart); 399 target_body.setDescription(singlePart);
397 break; 400 break;
398 case MAILIMAP_BODY_TYPE_1PART_TEXT: 401 case MAILIMAP_BODY_TYPE_1PART_TEXT:
399 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 402 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
400 path.append(1); 403 path.append(1);
401 body_text = fetchPart(mail,path,true); 404 body_text = fetchPart(mail,path,true);
405 if (singlePart.Encoding()=="quoted-printable") {
406 body_text = decode_quoted_printable(body_text.latin1());
407 }
402 target_body.setBodytext(body_text); 408 target_body.setBodytext(body_text);
403 target_body.setDescription(singlePart); 409 target_body.setDescription(singlePart);
404 break; 410 break;
405 case MAILIMAP_BODY_TYPE_1PART_BASIC: 411 case MAILIMAP_BODY_TYPE_1PART_BASIC:
406 qDebug("Single attachment"); 412 qDebug("Single attachment");
407 target_body.setBodytext(""); 413 target_body.setBodytext("");
408 target_body.addPart(singlePart); 414 target_body.addPart(singlePart);
409 break; 415 break;
410 default: 416 default:
411 break; 417 break;
412 } 418 }
413 419
414 return; 420 return;
415} 421}
416 422
417QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 423QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
418{ 424{
419 QStringList l; 425 QStringList l;
420 QString from; 426 QString from;
421 bool named_from; 427 bool named_from;
422 clistcell *current = NULL; 428 clistcell *current = NULL;
423 mailimap_address * current_address=NULL; 429 mailimap_address * current_address=NULL;
424 if (!list) { 430 if (!list) {
425 return l; 431 return l;
426 } 432 }
427 unsigned int count = 0; 433 unsigned int count = 0;
428 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 434 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
429 from = ""; 435 from = "";
430 named_from = false; 436 named_from = false;
431 current_address=(mailimap_address*)current->data; 437 current_address=(mailimap_address*)current->data;
432 if (current_address->ad_personal_name){ 438 if (current_address->ad_personal_name){
433 from+=QString(current_address->ad_personal_name); 439 from+=QString(current_address->ad_personal_name);
434 from+=" "; 440 from+=" ";
435 named_from = true; 441 named_from = true;
436 } 442 }
437 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 443 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
438 from+="<"; 444 from+="<";
439 } 445 }
440 if (current_address->ad_mailbox_name) { 446 if (current_address->ad_mailbox_name) {
441 from+=QString(current_address->ad_mailbox_name); 447 from+=QString(current_address->ad_mailbox_name);
442 from+="@"; 448 from+="@";
443 } 449 }
444 if (current_address->ad_host_name) { 450 if (current_address->ad_host_name) {
445 from+=QString(current_address->ad_host_name); 451 from+=QString(current_address->ad_host_name);
446 } 452 }
447 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
448 from+=">"; 454 from+=">";
449 } 455 }
450 l.append(QString(from)); 456 l.append(QString(from));
451 if (++count > 99) { 457 if (++count > 99) {
452 break; 458 break;
453 } 459 }
454 } 460 }
455 return l; 461 return l;
456} 462}
457 463
458QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 464QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
459{ 465{
460 QString body(""); 466 QString body("");
461 const char*mb; 467 const char*mb;
462 int err; 468 int err;
463 mailimap_fetch_type *fetchType; 469 mailimap_fetch_type *fetchType;
464 mailimap_set *set; 470 mailimap_set *set;
465 clistcell*current,*cur; 471 clistcell*current,*cur;
466 472
467 login(); 473 login();
468 if (!m_imap) { 474 if (!m_imap) {
469 return body; 475 return body;
470 } 476 }
471 if (!internal_call) { 477 if (!internal_call) {
472 mb = mail.getMbox().latin1(); 478 mb = mail.getMbox().latin1();
473 err = mailimap_select( m_imap, (char*)mb); 479 err = mailimap_select( m_imap, (char*)mb);
474 if ( err != MAILIMAP_NO_ERROR ) { 480 if ( err != MAILIMAP_NO_ERROR ) {
475 qDebug("error selecting mailbox: %s",m_imap->imap_response); 481 qDebug("error selecting mailbox: %s",m_imap->imap_response);
476 return body; 482 return body;
477 } 483 }
478 } 484 }
479 set = mailimap_set_new_single(mail.getNumber()); 485 set = mailimap_set_new_single(mail.getNumber());
480 clist*id_list=clist_new(); 486 clist*id_list=clist_new();
481 for (unsigned j=0; j < path.count();++j) { 487 for (unsigned j=0; j < path.count();++j) {
482 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
483 *p_id = path[j]; 489 *p_id = path[j];
484 clist_append(id_list,p_id); 490 clist_append(id_list,p_id);
485 } 491 }
486 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 492 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
487 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 493 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
488 mailimap_section * section = mailimap_section_new(section_spec); 494 mailimap_section * section = mailimap_section_new(section_spec);
489 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 495 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
490 496
491 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 497 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
492 498
493 clist*result = clist_new(); 499 clist*result = clist_new();
494 500
495 err = mailimap_fetch( m_imap, set, fetchType, &result ); 501 err = mailimap_fetch( m_imap, set, fetchType, &result );
496 mailimap_set_free( set ); 502 mailimap_set_free( set );
497 mailimap_fetch_type_free( fetchType ); 503 mailimap_fetch_type_free( fetchType );
498 504
499 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
500 mailimap_msg_att * msg_att; 506 mailimap_msg_att * msg_att;
501 msg_att = (mailimap_msg_att*)current->data; 507 msg_att = (mailimap_msg_att*)current->data;
502 mailimap_msg_att_item*msg_att_item; 508 mailimap_msg_att_item*msg_att_item;
503 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 509 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
504 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
505 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
506 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 512 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
507 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 513 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
508 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 514 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
509 if (text) { 515 if (text) {
510 body = QString(text); 516 if (enc=="quoted-printable") {
517 body = decode_quoted_printable(text);
518 } else {
519 body = QString(text);
520 }
511 free(text); 521 free(text);
512 } else { 522 } else {
513 body = ""; 523 body = "";
514 } 524 }
515 } 525 }
516 } 526 }
517 } 527 }
518 528
519 } else { 529 } else {
520 qDebug("error fetching text: %s",m_imap->imap_response); 530 qDebug("error fetching text: %s",m_imap->imap_response);
521 } 531 }
522 mailimap_fetch_list_free(result); 532 mailimap_fetch_list_free(result);
523 return body; 533 return body;
524} 534}
525 535
526void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 536void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
527{ 537{
528 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 538 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
529 if (!mailDescription||current_recursion==10) { 539 if (!mailDescription||current_recursion==10) {
530 return; 540 return;
531 } 541 }
532 clistcell*current; 542 clistcell*current;
533 mailimap_body*current_body; 543 mailimap_body*current_body;
534 unsigned int count = 0; 544 unsigned int count = 0;
535 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 545 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
536 /* the point in the message */ 546 /* the point in the message */
537 ++count; 547 ++count;
538 current_body = (mailimap_body*)current->data; 548 current_body = (mailimap_body*)current->data;
539 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 549 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
540 QValueList<int>clist = recList; 550 QValueList<int>clist = recList;
541 clist.append(count); 551 clist.append(count);
542 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 552 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
543 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 553 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
544 RecPart currentPart; 554 RecPart currentPart;
545 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 555 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
546 QValueList<int>clist = recList; 556 QValueList<int>clist = recList;
547 clist.append(count); 557 clist.append(count);
548 /* important: Check for is NULL 'cause a body can be empty! */ 558 /* important: Check for is NULL 'cause a body can be empty! */
549 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 559 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
550 QString body_text = fetchPart(mail,clist,true); 560 QString body_text = fetchPart(mail,clist,true,currentPart.Encoding());
551 target_body.setDescription(currentPart); 561 target_body.setDescription(currentPart);
552 target_body.setBodytext(body_text); 562 target_body.setBodytext(body_text);
553 } else { 563 } else {
554 QString id(""); 564 QString id("");
555 for (unsigned int j = 0; j < clist.count();++j) { 565 for (unsigned int j = 0; j < clist.count();++j) {
556 id+=(j>0?" ":""); 566 id+=(j>0?" ":"");
557 id+=QString("%1").arg(clist[j]); 567 id+=QString("%1").arg(clist[j]);
558 } 568 }
559 qDebug("ID= %s",id.latin1()); 569 qDebug("ID= %s",id.latin1());
560 currentPart.setIdentifier(id); 570 currentPart.setIdentifier(id);
561 currentPart.setPositionlist(clist); 571 currentPart.setPositionlist(clist);
562 target_body.addPart(currentPart); 572 target_body.addPart(currentPart);
563 } 573 }
564 } 574 }
565 } 575 }
566} 576}
567 577
568void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 578void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
569{ 579{
570 if (!Description) { 580 if (!Description) {
571 return; 581 return;
572 } 582 }
573 switch (Description->bd_type) { 583 switch (Description->bd_type) {
574 case MAILIMAP_BODY_TYPE_1PART_TEXT: 584 case MAILIMAP_BODY_TYPE_1PART_TEXT:
575 target_part.setType("text"); 585 target_part.setType("text");
576 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 586 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
577 break; 587 break;
578 case MAILIMAP_BODY_TYPE_1PART_BASIC: 588 case MAILIMAP_BODY_TYPE_1PART_BASIC:
579 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 589 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
580 break; 590 break;
581 case MAILIMAP_BODY_TYPE_1PART_MSG: 591 case MAILIMAP_BODY_TYPE_1PART_MSG:
582 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 592 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
583 break; 593 break;
584 default: 594 default:
585 break; 595 break;
586 } 596 }
587} 597}
588 598
589void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 599void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
590{ 600{
591 if (!which) { 601 if (!which) {
592 return; 602 return;
593 } 603 }
594 QString sub; 604 QString sub;
595 sub = which->bd_media_text; 605 sub = which->bd_media_text;
596 target_part.setSubtype(sub.lower()); 606 target_part.setSubtype(sub.lower());
597 target_part.setLines(which->bd_lines); 607 target_part.setLines(which->bd_lines);
598 fillBodyFields(target_part,which->bd_fields); 608 fillBodyFields(target_part,which->bd_fields);
599} 609}
600 610
601void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 611void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
602{ 612{
603 if (!which) { 613 if (!which) {
604 return; 614 return;
605 } 615 }
606// QString sub; 616// QString sub;
607// sub = which->bd_media_text; 617// sub = which->bd_media_text;
608// target_part.setSubtype(sub.lower()); 618// target_part.setSubtype(sub.lower());
609 qDebug("Message part"); 619 qDebug("Message part");
610 /* we set this type to text/plain */ 620 /* we set this type to text/plain */
611 target_part.setType("text"); 621 target_part.setType("text");
612 target_part.setSubtype("plain"); 622 target_part.setSubtype("plain");
613 target_part.setLines(which->bd_lines); 623 target_part.setLines(which->bd_lines);
614 fillBodyFields(target_part,which->bd_fields); 624 fillBodyFields(target_part,which->bd_fields);
615} 625}
616 626
617void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 627void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
618{ 628{
619 if (!which) { 629 if (!which) {
620 return; 630 return;
621 } 631 }
622 QString type,sub; 632 QString type,sub;
623 switch (which->bd_media_basic->med_type) { 633 switch (which->bd_media_basic->med_type) {
624 case MAILIMAP_MEDIA_BASIC_APPLICATION: 634 case MAILIMAP_MEDIA_BASIC_APPLICATION:
625 type = "application"; 635 type = "application";
626 break; 636 break;
627 case MAILIMAP_MEDIA_BASIC_AUDIO: 637 case MAILIMAP_MEDIA_BASIC_AUDIO:
628 type = "audio"; 638 type = "audio";
629 break; 639 break;
630 case MAILIMAP_MEDIA_BASIC_IMAGE: 640 case MAILIMAP_MEDIA_BASIC_IMAGE:
631 type = "image"; 641 type = "image";
632 break; 642 break;
633 case MAILIMAP_MEDIA_BASIC_MESSAGE: 643 case MAILIMAP_MEDIA_BASIC_MESSAGE:
634 type = "message"; 644 type = "message";
635 break; 645 break;
636 case MAILIMAP_MEDIA_BASIC_VIDEO: 646 case MAILIMAP_MEDIA_BASIC_VIDEO:
637 type = "video"; 647 type = "video";
638 break; 648 break;
639 case MAILIMAP_MEDIA_BASIC_OTHER: 649 case MAILIMAP_MEDIA_BASIC_OTHER:
640 default: 650 default:
641 if (which->bd_media_basic->med_basic_type) { 651 if (which->bd_media_basic->med_basic_type) {
642 type = which->bd_media_basic->med_basic_type; 652 type = which->bd_media_basic->med_basic_type;
643 } else { 653 } else {
644 type = ""; 654 type = "";
645 } 655 }
646 break; 656 break;
647 } 657 }
648 if (which->bd_media_basic->med_subtype) { 658 if (which->bd_media_basic->med_subtype) {
649 sub = which->bd_media_basic->med_subtype; 659 sub = which->bd_media_basic->med_subtype;
650 } else { 660 } else {
651 sub = ""; 661 sub = "";
652 } 662 }
653 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 663 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
654 target_part.setType(type.lower()); 664 target_part.setType(type.lower());
655 target_part.setSubtype(sub.lower()); 665 target_part.setSubtype(sub.lower());
656 fillBodyFields(target_part,which->bd_fields); 666 fillBodyFields(target_part,which->bd_fields);
657} 667}
658 668
659void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 669void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
660{ 670{
661 if (!which) return; 671 if (!which) return;
662 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 672 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
663 clistcell*cur; 673 clistcell*cur;
664 mailimap_single_body_fld_param*param=0; 674 mailimap_single_body_fld_param*param=0;
665 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 675 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
666 param = (mailimap_single_body_fld_param*)cur->data; 676 param = (mailimap_single_body_fld_param*)cur->data;
667 if (param) { 677 if (param) {
668 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 678 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
669 } 679 }
670 } 680 }
671 } 681 }
672 mailimap_body_fld_enc*enc = which->bd_encoding; 682 mailimap_body_fld_enc*enc = which->bd_encoding;
673 QString encoding(""); 683 QString encoding("");
674 switch (enc->enc_type) { 684 switch (enc->enc_type) {
675 case MAILIMAP_BODY_FLD_ENC_7BIT: 685 case MAILIMAP_BODY_FLD_ENC_7BIT:
676 encoding = "7bit"; 686 encoding = "7bit";
677 break; 687 break;
678 case MAILIMAP_BODY_FLD_ENC_8BIT: 688 case MAILIMAP_BODY_FLD_ENC_8BIT:
679 encoding = "8bit"; 689 encoding = "8bit";
680 break; 690 break;
681 case MAILIMAP_BODY_FLD_ENC_BINARY: 691 case MAILIMAP_BODY_FLD_ENC_BINARY:
682 encoding="binary"; 692 encoding="binary";
683 break; 693 break;
684 case MAILIMAP_BODY_FLD_ENC_BASE64: 694 case MAILIMAP_BODY_FLD_ENC_BASE64:
685 encoding="base64"; 695 encoding="base64";
686 break; 696 break;
687 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 697 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
688 encoding="quoted-printable"; 698 encoding="quoted-printable";
689 break; 699 break;
690 case MAILIMAP_BODY_FLD_ENC_OTHER: 700 case MAILIMAP_BODY_FLD_ENC_OTHER:
691 default: 701 default:
692 if (enc->enc_value) { 702 if (enc->enc_value) {
693 char*t=enc->enc_value; 703 char*t=enc->enc_value;
694 encoding=QString(enc->enc_value); 704 encoding=QString(enc->enc_value);
695 enc->enc_value=0L; 705 enc->enc_value=0L;
696 free(t); 706 free(t);
697 } 707 }
698 } 708 }
699 if (which->bd_description) { 709 if (which->bd_description) {
700 target_part.setDescription(QString(which->bd_description)); 710 target_part.setDescription(QString(which->bd_description));
701 } 711 }
702 target_part.setEncoding(encoding); 712 target_part.setEncoding(encoding);
703 target_part.setSize(which->bd_size); 713 target_part.setSize(which->bd_size);
704} 714}
705 715
706QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 716QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
707{ 717{
708 return fetchPart(mail,part.Positionlist(),false); 718 return fetchPart(mail,part.Positionlist(),false,part.Encoding());
709} 719}
710 720
711void IMAPwrapper::deleteMail(const RecMail&mail) 721void IMAPwrapper::deleteMail(const RecMail&mail)
712{ 722{
713 mailimap_flag_list*flist; 723 mailimap_flag_list*flist;
714 mailimap_set *set; 724 mailimap_set *set;
715 mailimap_store_att_flags * store_flags; 725 mailimap_store_att_flags * store_flags;
716 int err; 726 int err;
717 login(); 727 login();
718 if (!m_imap) { 728 if (!m_imap) {
719 return; 729 return;
720 } 730 }
721 const char *mb = mail.getMbox().latin1(); 731 const char *mb = mail.getMbox().latin1();
722 err = mailimap_select( m_imap, (char*)mb); 732 err = mailimap_select( m_imap, (char*)mb);
723 if ( err != MAILIMAP_NO_ERROR ) { 733 if ( err != MAILIMAP_NO_ERROR ) {
724 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 734 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
725 return; 735 return;
726 } 736 }
727 flist = mailimap_flag_list_new_empty(); 737 flist = mailimap_flag_list_new_empty();
728 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 738 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
729 store_flags = mailimap_store_att_flags_new_set_flags(flist); 739 store_flags = mailimap_store_att_flags_new_set_flags(flist);
730 set = mailimap_set_new_single(mail.getNumber()); 740 set = mailimap_set_new_single(mail.getNumber());
731 err = mailimap_store(m_imap,set,store_flags); 741 err = mailimap_store(m_imap,set,store_flags);
732 mailimap_set_free( set ); 742 mailimap_set_free( set );
733 mailimap_store_att_flags_free(store_flags); 743 mailimap_store_att_flags_free(store_flags);
734 744
735 if (err != MAILIMAP_NO_ERROR) { 745 if (err != MAILIMAP_NO_ERROR) {
736 qDebug("error deleting mail: %s",m_imap->imap_response); 746 qDebug("error deleting mail: %s",m_imap->imap_response);
737 return; 747 return;
738 } 748 }
739 qDebug("deleting mail: %s",m_imap->imap_response); 749 qDebug("deleting mail: %s",m_imap->imap_response);
740 /* should we realy do that at this moment? */ 750 /* should we realy do that at this moment? */
741 err = mailimap_expunge(m_imap); 751 err = mailimap_expunge(m_imap);
742 if (err != MAILIMAP_NO_ERROR) { 752 if (err != MAILIMAP_NO_ERROR) {
743 qDebug("error deleting mail: %s",m_imap->imap_response); 753 qDebug("error deleting mail: %s",m_imap->imap_response);
744 } 754 }
745 qDebug("Delete successfull %s",m_imap->imap_response); 755 qDebug("Delete successfull %s",m_imap->imap_response);
746} 756}
747 757
748void IMAPwrapper::answeredMail(const RecMail&mail) 758void IMAPwrapper::answeredMail(const RecMail&mail)
749{ 759{
750 mailimap_flag_list*flist; 760 mailimap_flag_list*flist;
751 mailimap_set *set; 761 mailimap_set *set;
752 mailimap_store_att_flags * store_flags; 762 mailimap_store_att_flags * store_flags;
753 int err; 763 int err;
754 login(); 764 login();
755 if (!m_imap) { 765 if (!m_imap) {
756 return; 766 return;
757 } 767 }
758 const char *mb = mail.getMbox().latin1(); 768 const char *mb = mail.getMbox().latin1();
759 err = mailimap_select( m_imap, (char*)mb); 769 err = mailimap_select( m_imap, (char*)mb);
760 if ( err != MAILIMAP_NO_ERROR ) { 770 if ( err != MAILIMAP_NO_ERROR ) {
761 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 771 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
762 return; 772 return;
763 } 773 }
764 flist = mailimap_flag_list_new_empty(); 774 flist = mailimap_flag_list_new_empty();
765 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 775 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
766 store_flags = mailimap_store_att_flags_new_add_flags(flist); 776 store_flags = mailimap_store_att_flags_new_add_flags(flist);
767 set = mailimap_set_new_single(mail.getNumber()); 777 set = mailimap_set_new_single(mail.getNumber());
768 err = mailimap_store(m_imap,set,store_flags); 778 err = mailimap_store(m_imap,set,store_flags);
769 mailimap_set_free( set ); 779 mailimap_set_free( set );
770 mailimap_store_att_flags_free(store_flags); 780 mailimap_store_att_flags_free(store_flags);
771 781
772 if (err != MAILIMAP_NO_ERROR) { 782 if (err != MAILIMAP_NO_ERROR) {
773 qDebug("error marking mail: %s",m_imap->imap_response); 783 qDebug("error marking mail: %s",m_imap->imap_response);
774 return; 784 return;
775 } 785 }
776} 786}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 700d512..768a517 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,56 +1,56 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7 7
8struct mailimap; 8struct mailimap;
9struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
10struct mailimap_body_type_text; 10struct mailimap_body_type_text;
11struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
12struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
13struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
14struct mailimap_body_fields; 14struct mailimap_body_fields;
15struct mailimap_msg_att; 15struct mailimap_msg_att;
16 16
17class IMAPwrapper : public AbstractMail 17class IMAPwrapper : public AbstractMail
18{ 18{
19 Q_OBJECT 19 Q_OBJECT
20public: 20public:
21 IMAPwrapper( IMAPaccount *a ); 21 IMAPwrapper( IMAPaccount *a );
22 virtual ~IMAPwrapper(); 22 virtual ~IMAPwrapper();
23 virtual QList<Folder>* listFolders(); 23 virtual QList<Folder>* listFolders();
24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
25 virtual RecBody fetchBody(const RecMail&mail); 25 virtual RecBody fetchBody(const RecMail&mail);
26 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 26 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
27 virtual void deleteMail(const RecMail&mail); 27 virtual void deleteMail(const RecMail&mail);
28 virtual void answeredMail(const RecMail&mail); 28 virtual void answeredMail(const RecMail&mail);
29 29
30 static void imap_progress( size_t current, size_t maximum ); 30 static void imap_progress( size_t current, size_t maximum );
31 31
32protected: 32protected:
33 RecMail*parse_list_result(mailimap_msg_att*); 33 RecMail*parse_list_result(mailimap_msg_att*);
34 void login(); 34 void login();
35 void logout(); 35 void logout();
36 36
37 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); 37 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
38 38
39 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 39 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
40 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 40 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
41 41
42 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 42 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
43 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 43 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
44 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 44 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
45 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 45 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
46 46
47 /* just helpers */ 47 /* just helpers */
48 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 48 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
49 static QStringList address_list_to_stringlist(clist*list); 49 static QStringList address_list_to_stringlist(clist*list);
50 50
51private: 51
52 IMAPaccount *account; 52 IMAPaccount *account;
53 mailimap *m_imap; 53 mailimap *m_imap;
54}; 54};
55 55
56#endif 56#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 7380c31..0bb2525 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,13 +1,34 @@
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 4
5#include <qstring.h>
6#include <stdlib.h>
7#include <libetpan/mailmime_content.h>
8
5AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 9AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
6{ 10{
7 return new IMAPwrapper(a); 11 return new IMAPwrapper(a);
8} 12}
9 13
10AbstractMail* AbstractMail::getWrapper(POP3account *a) 14AbstractMail* AbstractMail::getWrapper(POP3account *a)
11{ 15{
12 return new POP3wrapper(a); 16 return new POP3wrapper(a);
13} 17}
18
19QString AbstractMail::decode_quoted_printable(const char*text)
20{
21 char*result_text;
22 size_t index = 0;
23 QString result = "";
24 /* reset for recursive use! */
25 size_t target_length = 0;
26 result_text = 0;
27 int err = mailmime_quoted_printable_body_parse(text,strlen(text),
28 &index,&result_text,&target_length,0);
29 if (result_text) {
30 result = result_text;
31 free(result_text);
32 }
33 return result;
34}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index 62e0715..4473ad2 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,31 +1,31 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13 13
14class AbstractMail:public QObject 14class AbstractMail:public QObject
15{ 15{
16 Q_OBJECT 16 Q_OBJECT
17public: 17public:
18 AbstractMail(){}; 18 AbstractMail(){};
19 virtual ~AbstractMail(){} 19 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0; 20 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0; 22 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; 23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
24 virtual void deleteMail(const RecMail&mail)=0; 24 virtual void deleteMail(const RecMail&mail)=0;
25 virtual void answeredMail(const RecMail&mail)=0; 25 virtual void answeredMail(const RecMail&mail)=0;
26 26
27 static AbstractMail* getWrapper(IMAPaccount *a); 27 static AbstractMail* getWrapper(IMAPaccount *a);
28 static AbstractMail* getWrapper(POP3account *a); 28 static AbstractMail* getWrapper(POP3account *a);
29 static QString decode_quoted_printable(const char*text);
29}; 30};
30
31#endif 31#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index ad95384..a4e6228 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,776 +1,786 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 152 folders->setAutoDelete( false );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 169 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 173 // instead of using strdup!
174 temp = list->mb_name; 174 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
176 current = current->next; 176 current = current->next;
177 } 177 }
178 } else { 178 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 180 }
181 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
182 182
183/* 183/*
184 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
185 */ 185 */
186 mask = "*" ; 186 mask = "*" ;
187 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
188 if (!path) path = ""; 188 if (!path) path = "";
189 result = clist_new(); 189 result = clist_new();
190 qDebug(path); 190 qDebug(path);
191 bool selectable = true; 191 bool selectable = true;
192 mailimap_mbx_list_flags*bflags; 192 mailimap_mbx_list_flags*bflags;
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 194 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 195 current = result->first;
196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
197 list = (mailimap_mailbox_list *) current->data; 197 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 198 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 199 // instead of using strdup!
200 temp = list->mb_name; 200 temp = list->mb_name;
201 if (temp.lower()=="inbox") 201 if (temp.lower()=="inbox")
202 continue; 202 continue;
203 if (temp.lower()==account->getPrefix().lower()) 203 if (temp.lower()==account->getPrefix().lower())
204 continue; 204 continue;
205 if ( (bflags = list->mb_flag) ) { 205 if ( (bflags = list->mb_flag) ) {
206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
208 } 208 }
209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix())); 209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix()));
210 } 210 }
211 } else { 211 } else {
212 qDebug("error fetching folders %s",m_imap->imap_response); 212 qDebug("error fetching folders %s",m_imap->imap_response);
213 } 213 }
214 mailimap_list_result_free( result ); 214 mailimap_list_result_free( result );
215 return folders; 215 return folders;
216} 216}
217 217
218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
219{ 219{
220 RecMail * m = 0; 220 RecMail * m = 0;
221 mailimap_msg_att_item *item=0; 221 mailimap_msg_att_item *item=0;
222 clistcell *current,*c,*cf; 222 clistcell *current,*c,*cf;
223 mailimap_msg_att_dynamic*flist; 223 mailimap_msg_att_dynamic*flist;
224 mailimap_flag_fetch*cflag; 224 mailimap_flag_fetch*cflag;
225 int size; 225 int size;
226 QBitArray mFlags(7); 226 QBitArray mFlags(7);
227 QStringList addresslist; 227 QStringList addresslist;
228 228
229 if (!m_att) { 229 if (!m_att) {
230 return m; 230 return m;
231 } 231 }
232 m = new RecMail(); 232 m = new RecMail();
233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
234 current = c; 234 current = c;
235 size = 0; 235 size = 0;
236 item = (mailimap_msg_att_item*)current->data; 236 item = (mailimap_msg_att_item*)current->data;
237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
239 if (!flist->att_list) { 239 if (!flist->att_list) {
240 continue; 240 continue;
241 } 241 }
242 cf = flist->att_list->first; 242 cf = flist->att_list->first;
243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
244 cflag = (mailimap_flag_fetch*)cf->data; 244 cflag = (mailimap_flag_fetch*)cf->data;
245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
246 switch (cflag->fl_flag->fl_type) { 246 switch (cflag->fl_flag->fl_type) {
247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
248 mFlags.setBit(FLAG_ANSWERED); 248 mFlags.setBit(FLAG_ANSWERED);
249 break; 249 break;
250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
251 mFlags.setBit(FLAG_FLAGGED); 251 mFlags.setBit(FLAG_FLAGGED);
252 break; 252 break;
253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
254 mFlags.setBit(FLAG_DELETED); 254 mFlags.setBit(FLAG_DELETED);
255 break; 255 break;
256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
257 mFlags.setBit(FLAG_SEEN); 257 mFlags.setBit(FLAG_SEEN);
258 break; 258 break;
259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
260 mFlags.setBit(FLAG_DRAFT); 260 mFlags.setBit(FLAG_DRAFT);
261 break; 261 break;
262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
263 break; 263 break;
264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
265 break; 265 break;
266 default: 266 default:
267 break; 267 break;
268 } 268 }
269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
270 mFlags.setBit(FLAG_RECENT); 270 mFlags.setBit(FLAG_RECENT);
271 } 271 }
272 } 272 }
273 continue; 273 continue;
274 } 274 }
275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
277 m->setDate(head->env_date); 277 m->setDate(head->env_date);
278 m->setSubject(head->env_subject); 278 m->setSubject(head->env_subject);
279 if (head->env_from!=NULL) { 279 if (head->env_from!=NULL) {
280 addresslist = address_list_to_stringlist(head->env_from->frm_list); 280 addresslist = address_list_to_stringlist(head->env_from->frm_list);
281 if (addresslist.count()) { 281 if (addresslist.count()) {
282 m->setFrom(addresslist.first()); 282 m->setFrom(addresslist.first());
283 } 283 }
284 } 284 }
285 if (head->env_to!=NULL) { 285 if (head->env_to!=NULL) {
286 addresslist = address_list_to_stringlist(head->env_to->to_list); 286 addresslist = address_list_to_stringlist(head->env_to->to_list);
287 m->setTo(addresslist); 287 m->setTo(addresslist);
288 } 288 }
289 if (head->env_cc!=NULL) { 289 if (head->env_cc!=NULL) {
290 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 290 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
291 m->setCC(addresslist); 291 m->setCC(addresslist);
292 } 292 }
293 if (head->env_bcc!=NULL) { 293 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 295 m->setBcc(addresslist);
296 } 296 }
297 if (head->env_reply_to!=NULL) { 297 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 299 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
301 } 301 }
302 } 302 }
303 m->setMsgid(QString(head->env_message_id)); 303 m->setMsgid(QString(head->env_message_id));
304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
306#if 0 306#if 0
307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
309 qDebug(da.toString()); 309 qDebug(da.toString());
310#endif 310#endif
311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
312 size = item->att_data.att_static->att_data.att_rfc822_size; 312 size = item->att_data.att_static->att_data.att_rfc822_size;
313 } 313 }
314 } 314 }
315 /* msg is already deleted */ 315 /* msg is already deleted */
316 if (mFlags.testBit(FLAG_DELETED) && m) { 316 if (mFlags.testBit(FLAG_DELETED) && m) {
317 delete m; 317 delete m;
318 m = 0; 318 m = 0;
319 } 319 }
320 if (m) { 320 if (m) {
321 m->setFlags(mFlags); 321 m->setFlags(mFlags);
322 m->setMsgsize(size); 322 m->setMsgsize(size);
323 } 323 }
324 return m; 324 return m;
325} 325}
326 326
327RecBody IMAPwrapper::fetchBody(const RecMail&mail) 327RecBody IMAPwrapper::fetchBody(const RecMail&mail)
328{ 328{
329 RecBody body; 329 RecBody body;
330 const char *mb; 330 const char *mb;
331 int err = MAILIMAP_NO_ERROR; 331 int err = MAILIMAP_NO_ERROR;
332 clist *result; 332 clist *result;
333 clistcell *current; 333 clistcell *current;
334 mailimap_fetch_att *fetchAtt; 334 mailimap_fetch_att *fetchAtt;
335 mailimap_fetch_type *fetchType; 335 mailimap_fetch_type *fetchType;
336 mailimap_set *set; 336 mailimap_set *set;
337 mailimap_body*body_desc; 337 mailimap_body*body_desc;
338 338
339 mb = mail.getMbox().latin1(); 339 mb = mail.getMbox().latin1();
340 340
341 login(); 341 login();
342 if (!m_imap) { 342 if (!m_imap) {
343 return body; 343 return body;
344 } 344 }
345 345
346 err = mailimap_select( m_imap, (char*)mb); 346 err = mailimap_select( m_imap, (char*)mb);
347 if ( err != MAILIMAP_NO_ERROR ) { 347 if ( err != MAILIMAP_NO_ERROR ) {
348 qDebug("error selecting mailbox: %s",m_imap->imap_response); 348 qDebug("error selecting mailbox: %s",m_imap->imap_response);
349 return body; 349 return body;
350 } 350 }
351 351
352 result = clist_new(); 352 result = clist_new();
353 /* the range has to start at 1!!! not with 0!!!! */ 353 /* the range has to start at 1!!! not with 0!!!! */
354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
355 fetchAtt = mailimap_fetch_att_new_bodystructure(); 355 fetchAtt = mailimap_fetch_att_new_bodystructure();
356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
357 err = mailimap_fetch( m_imap, set, fetchType, &result ); 357 err = mailimap_fetch( m_imap, set, fetchType, &result );
358 mailimap_set_free( set ); 358 mailimap_set_free( set );
359 mailimap_fetch_type_free( fetchType ); 359 mailimap_fetch_type_free( fetchType );
360 360
361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
362 mailimap_msg_att * msg_att; 362 mailimap_msg_att * msg_att;
363 msg_att = (mailimap_msg_att*)current->data; 363 msg_att = (mailimap_msg_att*)current->data;
364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
365 body_desc = item->att_data.att_static->att_data.att_body; 365 body_desc = item->att_data.att_static->att_data.att_body;
366 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 366 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
367 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 367 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
368 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 368 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
369 qDebug("Mulitpart mail"); 369 qDebug("Mulitpart mail");
370 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 370 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
371 } 371 }
372 } else { 372 } else {
373 qDebug("error fetching body: %s",m_imap->imap_response); 373 qDebug("error fetching body: %s",m_imap->imap_response);
374 } 374 }
375 mailimap_fetch_list_free(result); 375 mailimap_fetch_list_free(result);
376 return body; 376 return body;
377} 377}
378 378
379/* this routine is just called when the mail has only ONE part. 379/* this routine is just called when the mail has only ONE part.
380 for filling the parts of a multi-part-message there are other 380 for filling the parts of a multi-part-message there are other
381 routines 'cause we can not simply fetch the whole body. */ 381 routines 'cause we can not simply fetch the whole body. */
382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
383{ 383{
384 if (!mailDescription) { 384 if (!mailDescription) {
385 return; 385 return;
386 } 386 }
387 QString sub,body_text; 387 QString sub,body_text;
388 RecPart singlePart; 388 RecPart singlePart;
389 QValueList<int> path; 389 QValueList<int> path;
390 fillSinglePart(singlePart,mailDescription); 390 fillSinglePart(singlePart,mailDescription);
391 switch (mailDescription->bd_type) { 391 switch (mailDescription->bd_type) {
392 case MAILIMAP_BODY_TYPE_1PART_MSG: 392 case MAILIMAP_BODY_TYPE_1PART_MSG:
393 path.append(1); 393 path.append(1);
394 body_text = fetchPart(mail,path,true); 394 body_text = fetchPart(mail,path,true);
395 if (singlePart.Encoding()=="quoted-printable") {
396 body_text = decode_quoted_printable(body_text.latin1());
397 }
395 target_body.setBodytext(body_text); 398 target_body.setBodytext(body_text);
396 target_body.setDescription(singlePart); 399 target_body.setDescription(singlePart);
397 break; 400 break;
398 case MAILIMAP_BODY_TYPE_1PART_TEXT: 401 case MAILIMAP_BODY_TYPE_1PART_TEXT:
399 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 402 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
400 path.append(1); 403 path.append(1);
401 body_text = fetchPart(mail,path,true); 404 body_text = fetchPart(mail,path,true);
405 if (singlePart.Encoding()=="quoted-printable") {
406 body_text = decode_quoted_printable(body_text.latin1());
407 }
402 target_body.setBodytext(body_text); 408 target_body.setBodytext(body_text);
403 target_body.setDescription(singlePart); 409 target_body.setDescription(singlePart);
404 break; 410 break;
405 case MAILIMAP_BODY_TYPE_1PART_BASIC: 411 case MAILIMAP_BODY_TYPE_1PART_BASIC:
406 qDebug("Single attachment"); 412 qDebug("Single attachment");
407 target_body.setBodytext(""); 413 target_body.setBodytext("");
408 target_body.addPart(singlePart); 414 target_body.addPart(singlePart);
409 break; 415 break;
410 default: 416 default:
411 break; 417 break;
412 } 418 }
413 419
414 return; 420 return;
415} 421}
416 422
417QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 423QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
418{ 424{
419 QStringList l; 425 QStringList l;
420 QString from; 426 QString from;
421 bool named_from; 427 bool named_from;
422 clistcell *current = NULL; 428 clistcell *current = NULL;
423 mailimap_address * current_address=NULL; 429 mailimap_address * current_address=NULL;
424 if (!list) { 430 if (!list) {
425 return l; 431 return l;
426 } 432 }
427 unsigned int count = 0; 433 unsigned int count = 0;
428 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 434 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
429 from = ""; 435 from = "";
430 named_from = false; 436 named_from = false;
431 current_address=(mailimap_address*)current->data; 437 current_address=(mailimap_address*)current->data;
432 if (current_address->ad_personal_name){ 438 if (current_address->ad_personal_name){
433 from+=QString(current_address->ad_personal_name); 439 from+=QString(current_address->ad_personal_name);
434 from+=" "; 440 from+=" ";
435 named_from = true; 441 named_from = true;
436 } 442 }
437 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 443 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
438 from+="<"; 444 from+="<";
439 } 445 }
440 if (current_address->ad_mailbox_name) { 446 if (current_address->ad_mailbox_name) {
441 from+=QString(current_address->ad_mailbox_name); 447 from+=QString(current_address->ad_mailbox_name);
442 from+="@"; 448 from+="@";
443 } 449 }
444 if (current_address->ad_host_name) { 450 if (current_address->ad_host_name) {
445 from+=QString(current_address->ad_host_name); 451 from+=QString(current_address->ad_host_name);
446 } 452 }
447 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
448 from+=">"; 454 from+=">";
449 } 455 }
450 l.append(QString(from)); 456 l.append(QString(from));
451 if (++count > 99) { 457 if (++count > 99) {
452 break; 458 break;
453 } 459 }
454 } 460 }
455 return l; 461 return l;
456} 462}
457 463
458QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 464QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
459{ 465{
460 QString body(""); 466 QString body("");
461 const char*mb; 467 const char*mb;
462 int err; 468 int err;
463 mailimap_fetch_type *fetchType; 469 mailimap_fetch_type *fetchType;
464 mailimap_set *set; 470 mailimap_set *set;
465 clistcell*current,*cur; 471 clistcell*current,*cur;
466 472
467 login(); 473 login();
468 if (!m_imap) { 474 if (!m_imap) {
469 return body; 475 return body;
470 } 476 }
471 if (!internal_call) { 477 if (!internal_call) {
472 mb = mail.getMbox().latin1(); 478 mb = mail.getMbox().latin1();
473 err = mailimap_select( m_imap, (char*)mb); 479 err = mailimap_select( m_imap, (char*)mb);
474 if ( err != MAILIMAP_NO_ERROR ) { 480 if ( err != MAILIMAP_NO_ERROR ) {
475 qDebug("error selecting mailbox: %s",m_imap->imap_response); 481 qDebug("error selecting mailbox: %s",m_imap->imap_response);
476 return body; 482 return body;
477 } 483 }
478 } 484 }
479 set = mailimap_set_new_single(mail.getNumber()); 485 set = mailimap_set_new_single(mail.getNumber());
480 clist*id_list=clist_new(); 486 clist*id_list=clist_new();
481 for (unsigned j=0; j < path.count();++j) { 487 for (unsigned j=0; j < path.count();++j) {
482 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
483 *p_id = path[j]; 489 *p_id = path[j];
484 clist_append(id_list,p_id); 490 clist_append(id_list,p_id);
485 } 491 }
486 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 492 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
487 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 493 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
488 mailimap_section * section = mailimap_section_new(section_spec); 494 mailimap_section * section = mailimap_section_new(section_spec);
489 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 495 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
490 496
491 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 497 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
492 498
493 clist*result = clist_new(); 499 clist*result = clist_new();
494 500
495 err = mailimap_fetch( m_imap, set, fetchType, &result ); 501 err = mailimap_fetch( m_imap, set, fetchType, &result );
496 mailimap_set_free( set ); 502 mailimap_set_free( set );
497 mailimap_fetch_type_free( fetchType ); 503 mailimap_fetch_type_free( fetchType );
498 504
499 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
500 mailimap_msg_att * msg_att; 506 mailimap_msg_att * msg_att;
501 msg_att = (mailimap_msg_att*)current->data; 507 msg_att = (mailimap_msg_att*)current->data;
502 mailimap_msg_att_item*msg_att_item; 508 mailimap_msg_att_item*msg_att_item;
503 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 509 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
504 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
505 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
506 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 512 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
507 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 513 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
508 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 514 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
509 if (text) { 515 if (text) {
510 body = QString(text); 516 if (enc=="quoted-printable") {
517 body = decode_quoted_printable(text);
518 } else {
519 body = QString(text);
520 }
511 free(text); 521 free(text);
512 } else { 522 } else {
513 body = ""; 523 body = "";
514 } 524 }
515 } 525 }
516 } 526 }
517 } 527 }
518 528
519 } else { 529 } else {
520 qDebug("error fetching text: %s",m_imap->imap_response); 530 qDebug("error fetching text: %s",m_imap->imap_response);
521 } 531 }
522 mailimap_fetch_list_free(result); 532 mailimap_fetch_list_free(result);
523 return body; 533 return body;
524} 534}
525 535
526void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 536void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
527{ 537{
528 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 538 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
529 if (!mailDescription||current_recursion==10) { 539 if (!mailDescription||current_recursion==10) {
530 return; 540 return;
531 } 541 }
532 clistcell*current; 542 clistcell*current;
533 mailimap_body*current_body; 543 mailimap_body*current_body;
534 unsigned int count = 0; 544 unsigned int count = 0;
535 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 545 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
536 /* the point in the message */ 546 /* the point in the message */
537 ++count; 547 ++count;
538 current_body = (mailimap_body*)current->data; 548 current_body = (mailimap_body*)current->data;
539 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 549 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
540 QValueList<int>clist = recList; 550 QValueList<int>clist = recList;
541 clist.append(count); 551 clist.append(count);
542 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 552 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
543 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 553 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
544 RecPart currentPart; 554 RecPart currentPart;
545 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 555 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
546 QValueList<int>clist = recList; 556 QValueList<int>clist = recList;
547 clist.append(count); 557 clist.append(count);
548 /* important: Check for is NULL 'cause a body can be empty! */ 558 /* important: Check for is NULL 'cause a body can be empty! */
549 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 559 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
550 QString body_text = fetchPart(mail,clist,true); 560 QString body_text = fetchPart(mail,clist,true,currentPart.Encoding());
551 target_body.setDescription(currentPart); 561 target_body.setDescription(currentPart);
552 target_body.setBodytext(body_text); 562 target_body.setBodytext(body_text);
553 } else { 563 } else {
554 QString id(""); 564 QString id("");
555 for (unsigned int j = 0; j < clist.count();++j) { 565 for (unsigned int j = 0; j < clist.count();++j) {
556 id+=(j>0?" ":""); 566 id+=(j>0?" ":"");
557 id+=QString("%1").arg(clist[j]); 567 id+=QString("%1").arg(clist[j]);
558 } 568 }
559 qDebug("ID= %s",id.latin1()); 569 qDebug("ID= %s",id.latin1());
560 currentPart.setIdentifier(id); 570 currentPart.setIdentifier(id);
561 currentPart.setPositionlist(clist); 571 currentPart.setPositionlist(clist);
562 target_body.addPart(currentPart); 572 target_body.addPart(currentPart);
563 } 573 }
564 } 574 }
565 } 575 }
566} 576}
567 577
568void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 578void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
569{ 579{
570 if (!Description) { 580 if (!Description) {
571 return; 581 return;
572 } 582 }
573 switch (Description->bd_type) { 583 switch (Description->bd_type) {
574 case MAILIMAP_BODY_TYPE_1PART_TEXT: 584 case MAILIMAP_BODY_TYPE_1PART_TEXT:
575 target_part.setType("text"); 585 target_part.setType("text");
576 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 586 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
577 break; 587 break;
578 case MAILIMAP_BODY_TYPE_1PART_BASIC: 588 case MAILIMAP_BODY_TYPE_1PART_BASIC:
579 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 589 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
580 break; 590 break;
581 case MAILIMAP_BODY_TYPE_1PART_MSG: 591 case MAILIMAP_BODY_TYPE_1PART_MSG:
582 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 592 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
583 break; 593 break;
584 default: 594 default:
585 break; 595 break;
586 } 596 }
587} 597}
588 598
589void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 599void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
590{ 600{
591 if (!which) { 601 if (!which) {
592 return; 602 return;
593 } 603 }
594 QString sub; 604 QString sub;
595 sub = which->bd_media_text; 605 sub = which->bd_media_text;
596 target_part.setSubtype(sub.lower()); 606 target_part.setSubtype(sub.lower());
597 target_part.setLines(which->bd_lines); 607 target_part.setLines(which->bd_lines);
598 fillBodyFields(target_part,which->bd_fields); 608 fillBodyFields(target_part,which->bd_fields);
599} 609}
600 610
601void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 611void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
602{ 612{
603 if (!which) { 613 if (!which) {
604 return; 614 return;
605 } 615 }
606// QString sub; 616// QString sub;
607// sub = which->bd_media_text; 617// sub = which->bd_media_text;
608// target_part.setSubtype(sub.lower()); 618// target_part.setSubtype(sub.lower());
609 qDebug("Message part"); 619 qDebug("Message part");
610 /* we set this type to text/plain */ 620 /* we set this type to text/plain */
611 target_part.setType("text"); 621 target_part.setType("text");
612 target_part.setSubtype("plain"); 622 target_part.setSubtype("plain");
613 target_part.setLines(which->bd_lines); 623 target_part.setLines(which->bd_lines);
614 fillBodyFields(target_part,which->bd_fields); 624 fillBodyFields(target_part,which->bd_fields);
615} 625}
616 626
617void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 627void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
618{ 628{
619 if (!which) { 629 if (!which) {
620 return; 630 return;
621 } 631 }
622 QString type,sub; 632 QString type,sub;
623 switch (which->bd_media_basic->med_type) { 633 switch (which->bd_media_basic->med_type) {
624 case MAILIMAP_MEDIA_BASIC_APPLICATION: 634 case MAILIMAP_MEDIA_BASIC_APPLICATION:
625 type = "application"; 635 type = "application";
626 break; 636 break;
627 case MAILIMAP_MEDIA_BASIC_AUDIO: 637 case MAILIMAP_MEDIA_BASIC_AUDIO:
628 type = "audio"; 638 type = "audio";
629 break; 639 break;
630 case MAILIMAP_MEDIA_BASIC_IMAGE: 640 case MAILIMAP_MEDIA_BASIC_IMAGE:
631 type = "image"; 641 type = "image";
632 break; 642 break;
633 case MAILIMAP_MEDIA_BASIC_MESSAGE: 643 case MAILIMAP_MEDIA_BASIC_MESSAGE:
634 type = "message"; 644 type = "message";
635 break; 645 break;
636 case MAILIMAP_MEDIA_BASIC_VIDEO: 646 case MAILIMAP_MEDIA_BASIC_VIDEO:
637 type = "video"; 647 type = "video";
638 break; 648 break;
639 case MAILIMAP_MEDIA_BASIC_OTHER: 649 case MAILIMAP_MEDIA_BASIC_OTHER:
640 default: 650 default:
641 if (which->bd_media_basic->med_basic_type) { 651 if (which->bd_media_basic->med_basic_type) {
642 type = which->bd_media_basic->med_basic_type; 652 type = which->bd_media_basic->med_basic_type;
643 } else { 653 } else {
644 type = ""; 654 type = "";
645 } 655 }
646 break; 656 break;
647 } 657 }
648 if (which->bd_media_basic->med_subtype) { 658 if (which->bd_media_basic->med_subtype) {
649 sub = which->bd_media_basic->med_subtype; 659 sub = which->bd_media_basic->med_subtype;
650 } else { 660 } else {
651 sub = ""; 661 sub = "";
652 } 662 }
653 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 663 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
654 target_part.setType(type.lower()); 664 target_part.setType(type.lower());
655 target_part.setSubtype(sub.lower()); 665 target_part.setSubtype(sub.lower());
656 fillBodyFields(target_part,which->bd_fields); 666 fillBodyFields(target_part,which->bd_fields);
657} 667}
658 668
659void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 669void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
660{ 670{
661 if (!which) return; 671 if (!which) return;
662 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 672 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
663 clistcell*cur; 673 clistcell*cur;
664 mailimap_single_body_fld_param*param=0; 674 mailimap_single_body_fld_param*param=0;
665 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 675 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
666 param = (mailimap_single_body_fld_param*)cur->data; 676 param = (mailimap_single_body_fld_param*)cur->data;
667 if (param) { 677 if (param) {
668 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 678 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
669 } 679 }
670 } 680 }
671 } 681 }
672 mailimap_body_fld_enc*enc = which->bd_encoding; 682 mailimap_body_fld_enc*enc = which->bd_encoding;
673 QString encoding(""); 683 QString encoding("");
674 switch (enc->enc_type) { 684 switch (enc->enc_type) {
675 case MAILIMAP_BODY_FLD_ENC_7BIT: 685 case MAILIMAP_BODY_FLD_ENC_7BIT:
676 encoding = "7bit"; 686 encoding = "7bit";
677 break; 687 break;
678 case MAILIMAP_BODY_FLD_ENC_8BIT: 688 case MAILIMAP_BODY_FLD_ENC_8BIT:
679 encoding = "8bit"; 689 encoding = "8bit";
680 break; 690 break;
681 case MAILIMAP_BODY_FLD_ENC_BINARY: 691 case MAILIMAP_BODY_FLD_ENC_BINARY:
682 encoding="binary"; 692 encoding="binary";
683 break; 693 break;
684 case MAILIMAP_BODY_FLD_ENC_BASE64: 694 case MAILIMAP_BODY_FLD_ENC_BASE64:
685 encoding="base64"; 695 encoding="base64";
686 break; 696 break;
687 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 697 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
688 encoding="quoted-printable"; 698 encoding="quoted-printable";
689 break; 699 break;
690 case MAILIMAP_BODY_FLD_ENC_OTHER: 700 case MAILIMAP_BODY_FLD_ENC_OTHER:
691 default: 701 default:
692 if (enc->enc_value) { 702 if (enc->enc_value) {
693 char*t=enc->enc_value; 703 char*t=enc->enc_value;
694 encoding=QString(enc->enc_value); 704 encoding=QString(enc->enc_value);
695 enc->enc_value=0L; 705 enc->enc_value=0L;
696 free(t); 706 free(t);
697 } 707 }
698 } 708 }
699 if (which->bd_description) { 709 if (which->bd_description) {
700 target_part.setDescription(QString(which->bd_description)); 710 target_part.setDescription(QString(which->bd_description));
701 } 711 }
702 target_part.setEncoding(encoding); 712 target_part.setEncoding(encoding);
703 target_part.setSize(which->bd_size); 713 target_part.setSize(which->bd_size);
704} 714}
705 715
706QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 716QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
707{ 717{
708 return fetchPart(mail,part.Positionlist(),false); 718 return fetchPart(mail,part.Positionlist(),false,part.Encoding());
709} 719}
710 720
711void IMAPwrapper::deleteMail(const RecMail&mail) 721void IMAPwrapper::deleteMail(const RecMail&mail)
712{ 722{
713 mailimap_flag_list*flist; 723 mailimap_flag_list*flist;
714 mailimap_set *set; 724 mailimap_set *set;
715 mailimap_store_att_flags * store_flags; 725 mailimap_store_att_flags * store_flags;
716 int err; 726 int err;
717 login(); 727 login();
718 if (!m_imap) { 728 if (!m_imap) {
719 return; 729 return;
720 } 730 }
721 const char *mb = mail.getMbox().latin1(); 731 const char *mb = mail.getMbox().latin1();
722 err = mailimap_select( m_imap, (char*)mb); 732 err = mailimap_select( m_imap, (char*)mb);
723 if ( err != MAILIMAP_NO_ERROR ) { 733 if ( err != MAILIMAP_NO_ERROR ) {
724 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 734 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
725 return; 735 return;
726 } 736 }
727 flist = mailimap_flag_list_new_empty(); 737 flist = mailimap_flag_list_new_empty();
728 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 738 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
729 store_flags = mailimap_store_att_flags_new_set_flags(flist); 739 store_flags = mailimap_store_att_flags_new_set_flags(flist);
730 set = mailimap_set_new_single(mail.getNumber()); 740 set = mailimap_set_new_single(mail.getNumber());
731 err = mailimap_store(m_imap,set,store_flags); 741 err = mailimap_store(m_imap,set,store_flags);
732 mailimap_set_free( set ); 742 mailimap_set_free( set );
733 mailimap_store_att_flags_free(store_flags); 743 mailimap_store_att_flags_free(store_flags);
734 744
735 if (err != MAILIMAP_NO_ERROR) { 745 if (err != MAILIMAP_NO_ERROR) {
736 qDebug("error deleting mail: %s",m_imap->imap_response); 746 qDebug("error deleting mail: %s",m_imap->imap_response);
737 return; 747 return;
738 } 748 }
739 qDebug("deleting mail: %s",m_imap->imap_response); 749 qDebug("deleting mail: %s",m_imap->imap_response);
740 /* should we realy do that at this moment? */ 750 /* should we realy do that at this moment? */
741 err = mailimap_expunge(m_imap); 751 err = mailimap_expunge(m_imap);
742 if (err != MAILIMAP_NO_ERROR) { 752 if (err != MAILIMAP_NO_ERROR) {
743 qDebug("error deleting mail: %s",m_imap->imap_response); 753 qDebug("error deleting mail: %s",m_imap->imap_response);
744 } 754 }
745 qDebug("Delete successfull %s",m_imap->imap_response); 755 qDebug("Delete successfull %s",m_imap->imap_response);
746} 756}
747 757
748void IMAPwrapper::answeredMail(const RecMail&mail) 758void IMAPwrapper::answeredMail(const RecMail&mail)
749{ 759{
750 mailimap_flag_list*flist; 760 mailimap_flag_list*flist;
751 mailimap_set *set; 761 mailimap_set *set;
752 mailimap_store_att_flags * store_flags; 762 mailimap_store_att_flags * store_flags;
753 int err; 763 int err;
754 login(); 764 login();
755 if (!m_imap) { 765 if (!m_imap) {
756 return; 766 return;
757 } 767 }
758 const char *mb = mail.getMbox().latin1(); 768 const char *mb = mail.getMbox().latin1();
759 err = mailimap_select( m_imap, (char*)mb); 769 err = mailimap_select( m_imap, (char*)mb);
760 if ( err != MAILIMAP_NO_ERROR ) { 770 if ( err != MAILIMAP_NO_ERROR ) {
761 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 771 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
762 return; 772 return;
763 } 773 }
764 flist = mailimap_flag_list_new_empty(); 774 flist = mailimap_flag_list_new_empty();
765 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 775 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
766 store_flags = mailimap_store_att_flags_new_add_flags(flist); 776 store_flags = mailimap_store_att_flags_new_add_flags(flist);
767 set = mailimap_set_new_single(mail.getNumber()); 777 set = mailimap_set_new_single(mail.getNumber());
768 err = mailimap_store(m_imap,set,store_flags); 778 err = mailimap_store(m_imap,set,store_flags);
769 mailimap_set_free( set ); 779 mailimap_set_free( set );
770 mailimap_store_att_flags_free(store_flags); 780 mailimap_store_att_flags_free(store_flags);
771 781
772 if (err != MAILIMAP_NO_ERROR) { 782 if (err != MAILIMAP_NO_ERROR) {
773 qDebug("error marking mail: %s",m_imap->imap_response); 783 qDebug("error marking mail: %s",m_imap->imap_response);
774 return; 784 return;
775 } 785 }
776} 786}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 700d512..768a517 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,56 +1,56 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7 7
8struct mailimap; 8struct mailimap;
9struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
10struct mailimap_body_type_text; 10struct mailimap_body_type_text;
11struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
12struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
13struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
14struct mailimap_body_fields; 14struct mailimap_body_fields;
15struct mailimap_msg_att; 15struct mailimap_msg_att;
16 16
17class IMAPwrapper : public AbstractMail 17class IMAPwrapper : public AbstractMail
18{ 18{
19 Q_OBJECT 19 Q_OBJECT
20public: 20public:
21 IMAPwrapper( IMAPaccount *a ); 21 IMAPwrapper( IMAPaccount *a );
22 virtual ~IMAPwrapper(); 22 virtual ~IMAPwrapper();
23 virtual QList<Folder>* listFolders(); 23 virtual QList<Folder>* listFolders();
24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
25 virtual RecBody fetchBody(const RecMail&mail); 25 virtual RecBody fetchBody(const RecMail&mail);
26 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 26 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
27 virtual void deleteMail(const RecMail&mail); 27 virtual void deleteMail(const RecMail&mail);
28 virtual void answeredMail(const RecMail&mail); 28 virtual void answeredMail(const RecMail&mail);
29 29
30 static void imap_progress( size_t current, size_t maximum ); 30 static void imap_progress( size_t current, size_t maximum );
31 31
32protected: 32protected:
33 RecMail*parse_list_result(mailimap_msg_att*); 33 RecMail*parse_list_result(mailimap_msg_att*);
34 void login(); 34 void login();
35 void logout(); 35 void logout();
36 36
37 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); 37 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
38 38
39 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 39 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
40 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 40 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
41 41
42 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 42 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
43 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 43 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
44 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 44 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
45 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 45 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
46 46
47 /* just helpers */ 47 /* just helpers */
48 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 48 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
49 static QStringList address_list_to_stringlist(clist*list); 49 static QStringList address_list_to_stringlist(clist*list);
50 50
51private: 51
52 IMAPaccount *account; 52 IMAPaccount *account;
53 mailimap *m_imap; 53 mailimap *m_imap;
54}; 54};
55 55
56#endif 56#endif