summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-18 14:23:15 (UTC)
committer alwin <alwin>2003-12-18 14:23:15 (UTC)
commit5cb08b0c69ffc7216405b552e17ff0541578bda0 (patch) (unidiff)
tree37ea5ec8747f82a90c068422fbb99662789380ec
parent51e56afac97c5254abfe76b65fd697a3e75e4bdd (diff)
downloadopie-5cb08b0c69ffc7216405b552e17ff0541578bda0.zip
opie-5cb08b0c69ffc7216405b552e17ff0541578bda0.tar.gz
opie-5cb08b0c69ffc7216405b552e17ff0541578bda0.tar.bz2
ok. char-translation enabled again.
make sure to have the decode patch applied to libetpan!!!!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp17
-rw-r--r--noncore/net/mail/imapwrapper.cpp6
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp17
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp6
4 files changed, 22 insertions, 24 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
index b7e5eaa..3d76c96 100644
--- a/noncore/net/mail/abstractmail.cpp
+++ b/noncore/net/mail/abstractmail.cpp
@@ -1,71 +1,68 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <qstring.h> 6#include <qstring.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <libetpan/mailmime_content.h> 8#include <libetpan/mailmime_content.h>
9 9
10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
11{ 11{
12 return new IMAPwrapper(a); 12 return new IMAPwrapper(a);
13} 13}
14 14
15AbstractMail* AbstractMail::getWrapper(POP3account *a) 15AbstractMail* AbstractMail::getWrapper(POP3account *a)
16{ 16{
17 return new POP3wrapper(a); 17 return new POP3wrapper(a);
18} 18}
19 19
20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
21{ 21{
22 qDebug("Decode string start"); 22 qDebug("Decode string start");
23 char*result_text; 23 char*result_text;
24 size_t index = 0; 24 size_t index = 0;
25 /* reset for recursive use! */ 25 /* reset for recursive use! */
26 size_t target_length = 0; 26 size_t target_length = 0;
27 result_text = 0; 27 result_text = 0;
28 int mimetype = MAILMIME_MECHANISM_7BIT; 28 int mimetype = MAILMIME_MECHANISM_7BIT;
29 if (enc.lower()=="quoted-printable") { 29 if (enc.lower()=="quoted-printable") {
30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
31 } else if (enc.lower()=="base64") { 31 } else if (enc.lower()=="base64") {
32 mimetype = MAILMIME_MECHANISM_BASE64; 32 mimetype = MAILMIME_MECHANISM_BASE64;
33 } else if (enc.lower()=="8bit") { 33 } else if (enc.lower()=="8bit") {
34 mimetype = MAILMIME_MECHANISM_8BIT; 34 mimetype = MAILMIME_MECHANISM_8BIT;
35 } else if (enc.lower()=="binary") { 35 } else if (enc.lower()=="binary") {
36 mimetype = MAILMIME_MECHANISM_BINARY; 36 mimetype = MAILMIME_MECHANISM_BINARY;
37 } 37 }
38 38
39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
40 &result_text,&target_length); 40 &result_text,&target_length);
41 41
42 encodedString* result = new encodedString(); 42 encodedString* result = new encodedString();
43 if (err == MAILIMF_NO_ERROR) { 43 if (err == MAILIMF_NO_ERROR) {
44 result->setContent(result_text,target_length); 44 result->setContent(result_text,target_length);
45 } 45 }
46 qDebug("Decode string finished"); 46 qDebug("Decode string finished");
47 return result; 47 return result;
48} 48}
49 49
50QString AbstractMail::convert_String(const char*text) 50QString AbstractMail::convert_String(const char*text)
51{ 51{
52#if 0
53 size_t index = 0; 52 size_t index = 0;
54 char*res = 0; 53 char*res = 0;
55 54
56 qDebug("encode start %s",text); 55 /* attention - doesn't work with arm systems! */
57 /* attention - doesn't work with arm systems! */
58 int err = mailmime_encoded_phrase_parse("iso-8859-1", 56 int err = mailmime_encoded_phrase_parse("iso-8859-1",
59 text, strlen(text),&index, "iso-8859-1",&res); 57 text, strlen(text),&index, "iso-8859-1",&res);
60 qDebug("encode end");
61 if (err != MAILIMF_NO_ERROR) { 58 if (err != MAILIMF_NO_ERROR) {
62 if (res) free(res); 59 if (res) free(res);
63 return QString(text); 60 return QString(text);
64 } 61 }
65 QString result(res); 62 if (res) {
66 free(res); 63 QString result(res);
67 return result; 64 free(res);
68#else 65 return result;
69 return QString(text); 66 }
70#endif 67 return QString(text);
71} 68}
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 8a86c95..838300a 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,803 +1,805 @@
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 QString del; 168 QString del;
169 if ( err == MAILIMAP_NO_ERROR ) { 169 if ( err == MAILIMAP_NO_ERROR ) {
170 current = result->first; 170 current = result->first;
171 for ( int i = result->count; i > 0; i-- ) { 171 for ( int i = result->count; i > 0; i-- ) {
172 list = (mailimap_mailbox_list *) current->data; 172 list = (mailimap_mailbox_list *) current->data;
173 // it is better use the deep copy mechanism of qt itself 173 // it is better use the deep copy mechanism of qt itself
174 // instead of using strdup! 174 // instead of using strdup!
175 temp = list->mb_name; 175 temp = list->mb_name;
176 del = list->mb_delimiter; 176 del = list->mb_delimiter;
177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
178 current = current->next; 178 current = current->next;
179 } 179 }
180 } else { 180 } else {
181 qDebug("error fetching folders: %s",m_imap->imap_response); 181 qDebug("error fetching folders: %s",m_imap->imap_response);
182 } 182 }
183 mailimap_list_result_free( result ); 183 mailimap_list_result_free( result );
184 184
185/* 185/*
186 * second stage - get the other then inbox folders 186 * second stage - get the other then inbox folders
187 */ 187 */
188 mask = "*" ; 188 mask = "*" ;
189 path = account->getPrefix().latin1(); 189 path = account->getPrefix().latin1();
190 if (!path) path = ""; 190 if (!path) path = "";
191 result = clist_new(); 191 result = clist_new();
192 qDebug(path); 192 qDebug(path);
193 bool selectable = true; 193 bool selectable = true;
194 mailimap_mbx_list_flags*bflags; 194 mailimap_mbx_list_flags*bflags;
195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
196 if ( err == MAILIMAP_NO_ERROR ) { 196 if ( err == MAILIMAP_NO_ERROR ) {
197 current = result->first; 197 current = result->first;
198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
199 list = (mailimap_mailbox_list *) current->data; 199 list = (mailimap_mailbox_list *) current->data;
200 // it is better use the deep copy mechanism of qt itself 200 // it is better use the deep copy mechanism of qt itself
201 // instead of using strdup! 201 // instead of using strdup!
202 temp = list->mb_name; 202 temp = list->mb_name;
203 if (temp.lower()=="inbox") 203 if (temp.lower()=="inbox")
204 continue; 204 continue;
205 if (temp.lower()==account->getPrefix().lower()) 205 if (temp.lower()==account->getPrefix().lower())
206 continue; 206 continue;
207 if ( (bflags = list->mb_flag) ) { 207 if ( (bflags = list->mb_flag) ) {
208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
210 } 210 }
211 del = list->mb_delimiter; 211 del = list->mb_delimiter;
212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
213 } 213 }
214 } else { 214 } else {
215 qDebug("error fetching folders %s",m_imap->imap_response); 215 qDebug("error fetching folders %s",m_imap->imap_response);
216 } 216 }
217 mailimap_list_result_free( result ); 217 mailimap_list_result_free( result );
218 return folders; 218 return folders;
219} 219}
220 220
221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
222{ 222{
223 RecMail * m = 0; 223 RecMail * m = 0;
224 mailimap_msg_att_item *item=0; 224 mailimap_msg_att_item *item=0;
225 clistcell *current,*c,*cf; 225 clistcell *current,*c,*cf;
226 mailimap_msg_att_dynamic*flist; 226 mailimap_msg_att_dynamic*flist;
227 mailimap_flag_fetch*cflag; 227 mailimap_flag_fetch*cflag;
228 int size; 228 int size;
229 QBitArray mFlags(7); 229 QBitArray mFlags(7);
230 QStringList addresslist; 230 QStringList addresslist;
231 231
232 if (!m_att) { 232 if (!m_att) {
233 return m; 233 return m;
234 } 234 }
235 m = new RecMail(); 235 m = new RecMail();
236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
237 current = c; 237 current = c;
238 size = 0; 238 size = 0;
239 item = (mailimap_msg_att_item*)current->data; 239 item = (mailimap_msg_att_item*)current->data;
240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
242 if (!flist->att_list) { 242 if (!flist->att_list) {
243 continue; 243 continue;
244 } 244 }
245 cf = flist->att_list->first; 245 cf = flist->att_list->first;
246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
247 cflag = (mailimap_flag_fetch*)cf->data; 247 cflag = (mailimap_flag_fetch*)cf->data;
248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
249 switch (cflag->fl_flag->fl_type) { 249 switch (cflag->fl_flag->fl_type) {
250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
251 mFlags.setBit(FLAG_ANSWERED); 251 mFlags.setBit(FLAG_ANSWERED);
252 break; 252 break;
253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
254 mFlags.setBit(FLAG_FLAGGED); 254 mFlags.setBit(FLAG_FLAGGED);
255 break; 255 break;
256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
257 mFlags.setBit(FLAG_DELETED); 257 mFlags.setBit(FLAG_DELETED);
258 break; 258 break;
259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
260 mFlags.setBit(FLAG_SEEN); 260 mFlags.setBit(FLAG_SEEN);
261 break; 261 break;
262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
263 mFlags.setBit(FLAG_DRAFT); 263 mFlags.setBit(FLAG_DRAFT);
264 break; 264 break;
265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
266 break; 266 break;
267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
268 break; 268 break;
269 default: 269 default:
270 break; 270 break;
271 } 271 }
272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
273 mFlags.setBit(FLAG_RECENT); 273 mFlags.setBit(FLAG_RECENT);
274 } 274 }
275 } 275 }
276 continue; 276 continue;
277 } 277 }
278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
280 m->setDate(head->env_date); 280 m->setDate(head->env_date);
281 m->setSubject(head->env_subject); 281 m->setSubject(convert_String((const char*)head->env_subject));
282 //m->setSubject(head->env_subject);
282 if (head->env_from!=NULL) { 283 if (head->env_from!=NULL) {
283 addresslist = address_list_to_stringlist(head->env_from->frm_list); 284 addresslist = address_list_to_stringlist(head->env_from->frm_list);
284 if (addresslist.count()) { 285 if (addresslist.count()) {
285 m->setFrom(addresslist.first()); 286 m->setFrom(addresslist.first());
286 } 287 }
287 } 288 }
288 if (head->env_to!=NULL) { 289 if (head->env_to!=NULL) {
289 addresslist = address_list_to_stringlist(head->env_to->to_list); 290 addresslist = address_list_to_stringlist(head->env_to->to_list);
290 m->setTo(addresslist); 291 m->setTo(addresslist);
291 } 292 }
292 if (head->env_cc!=NULL) { 293 if (head->env_cc!=NULL) {
293 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 294 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
294 m->setCC(addresslist); 295 m->setCC(addresslist);
295 } 296 }
296 if (head->env_bcc!=NULL) { 297 if (head->env_bcc!=NULL) {
297 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 298 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
298 m->setBcc(addresslist); 299 m->setBcc(addresslist);
299 } 300 }
300 if (head->env_reply_to!=NULL) { 301 if (head->env_reply_to!=NULL) {
301 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 302 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
302 if (addresslist.count()) { 303 if (addresslist.count()) {
303 m->setReplyto(addresslist.first()); 304 m->setReplyto(addresslist.first());
304 } 305 }
305 } 306 }
306 m->setMsgid(QString(head->env_message_id)); 307 m->setMsgid(QString(head->env_message_id));
307 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 308 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
308#if 0 309#if 0
309 310
310 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 311 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
311 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 312 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
312 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); 313 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);
313 qDebug(da.toString()); 314 qDebug(da.toString());
314#endif 315#endif
315 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 316 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
316 size = item->att_data.att_static->att_data.att_rfc822_size; 317 size = item->att_data.att_static->att_data.att_rfc822_size;
317 } 318 }
318 } 319 }
319 /* msg is already deleted */ 320 /* msg is already deleted */
320 if (mFlags.testBit(FLAG_DELETED) && m) { 321 if (mFlags.testBit(FLAG_DELETED) && m) {
321 delete m; 322 delete m;
322 m = 0; 323 m = 0;
323 } 324 }
324 if (m) { 325 if (m) {
325 m->setFlags(mFlags); 326 m->setFlags(mFlags);
326 m->setMsgsize(size); 327 m->setMsgsize(size);
327 } 328 }
328 return m; 329 return m;
329} 330}
330 331
331RecBody IMAPwrapper::fetchBody(const RecMail&mail) 332RecBody IMAPwrapper::fetchBody(const RecMail&mail)
332{ 333{
333 RecBody body; 334 RecBody body;
334 const char *mb; 335 const char *mb;
335 int err = MAILIMAP_NO_ERROR; 336 int err = MAILIMAP_NO_ERROR;
336 clist *result; 337 clist *result;
337 clistcell *current; 338 clistcell *current;
338 mailimap_fetch_att *fetchAtt; 339 mailimap_fetch_att *fetchAtt;
339 mailimap_fetch_type *fetchType; 340 mailimap_fetch_type *fetchType;
340 mailimap_set *set; 341 mailimap_set *set;
341 mailimap_body*body_desc; 342 mailimap_body*body_desc;
342 343
343 mb = mail.getMbox().latin1(); 344 mb = mail.getMbox().latin1();
344 345
345 login(); 346 login();
346 if (!m_imap) { 347 if (!m_imap) {
347 return body; 348 return body;
348 } 349 }
349 350
350 err = mailimap_select( m_imap, (char*)mb); 351 err = mailimap_select( m_imap, (char*)mb);
351 if ( err != MAILIMAP_NO_ERROR ) { 352 if ( err != MAILIMAP_NO_ERROR ) {
352 qDebug("error selecting mailbox: %s",m_imap->imap_response); 353 qDebug("error selecting mailbox: %s",m_imap->imap_response);
353 return body; 354 return body;
354 } 355 }
355 356
356 result = clist_new(); 357 result = clist_new();
357 /* the range has to start at 1!!! not with 0!!!! */ 358 /* the range has to start at 1!!! not with 0!!!! */
358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 359 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
359 fetchAtt = mailimap_fetch_att_new_bodystructure(); 360 fetchAtt = mailimap_fetch_att_new_bodystructure();
360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 361 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
361 err = mailimap_fetch( m_imap, set, fetchType, &result ); 362 err = mailimap_fetch( m_imap, set, fetchType, &result );
362 mailimap_set_free( set ); 363 mailimap_set_free( set );
363 mailimap_fetch_type_free( fetchType ); 364 mailimap_fetch_type_free( fetchType );
364 365
365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 366 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
366 mailimap_msg_att * msg_att; 367 mailimap_msg_att * msg_att;
367 msg_att = (mailimap_msg_att*)current->data; 368 msg_att = (mailimap_msg_att*)current->data;
368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 369 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
369 body_desc = item->att_data.att_static->att_data.att_body; 370 body_desc = item->att_data.att_static->att_data.att_body;
370 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 371 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
371 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 372 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
372 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 373 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
373 qDebug("Mulitpart mail"); 374 qDebug("Mulitpart mail");
374 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 375 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
375 } 376 }
376 } else { 377 } else {
377 qDebug("error fetching body: %s",m_imap->imap_response); 378 qDebug("error fetching body: %s",m_imap->imap_response);
378 } 379 }
379 mailimap_fetch_list_free(result); 380 mailimap_fetch_list_free(result);
380 return body; 381 return body;
381} 382}
382 383
383/* this routine is just called when the mail has only ONE part. 384/* this routine is just called when the mail has only ONE part.
384 for filling the parts of a multi-part-message there are other 385 for filling the parts of a multi-part-message there are other
385 routines 'cause we can not simply fetch the whole body. */ 386 routines 'cause we can not simply fetch the whole body. */
386void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 387void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
387{ 388{
388 if (!mailDescription) { 389 if (!mailDescription) {
389 return; 390 return;
390 } 391 }
391 QString sub,body_text; 392 QString sub,body_text;
392 RecPart singlePart; 393 RecPart singlePart;
393 QValueList<int> path; 394 QValueList<int> path;
394 fillSinglePart(singlePart,mailDescription); 395 fillSinglePart(singlePart,mailDescription);
395 switch (mailDescription->bd_type) { 396 switch (mailDescription->bd_type) {
396 case MAILIMAP_BODY_TYPE_1PART_MSG: 397 case MAILIMAP_BODY_TYPE_1PART_MSG:
397 path.append(1); 398 path.append(1);
398 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 399 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
399 target_body.setBodytext(body_text); 400 target_body.setBodytext(body_text);
400 target_body.setDescription(singlePart); 401 target_body.setDescription(singlePart);
401 break; 402 break;
402 case MAILIMAP_BODY_TYPE_1PART_TEXT: 403 case MAILIMAP_BODY_TYPE_1PART_TEXT:
403 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 404 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
404 path.append(1); 405 path.append(1);
405 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 406 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
406 target_body.setBodytext(body_text); 407 target_body.setBodytext(body_text);
407 target_body.setDescription(singlePart); 408 target_body.setDescription(singlePart);
408 break; 409 break;
409 case MAILIMAP_BODY_TYPE_1PART_BASIC: 410 case MAILIMAP_BODY_TYPE_1PART_BASIC:
410 qDebug("Single attachment"); 411 qDebug("Single attachment");
411 target_body.setBodytext(""); 412 target_body.setBodytext("");
412 target_body.addPart(singlePart); 413 target_body.addPart(singlePart);
413 break; 414 break;
414 default: 415 default:
415 break; 416 break;
416 } 417 }
417 418
418 return; 419 return;
419} 420}
420 421
421QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 422QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
422{ 423{
423 QStringList l; 424 QStringList l;
424 QString from; 425 QString from;
425 bool named_from; 426 bool named_from;
426 clistcell *current = NULL; 427 clistcell *current = NULL;
427 mailimap_address * current_address=NULL; 428 mailimap_address * current_address=NULL;
428 if (!list) { 429 if (!list) {
429 return l; 430 return l;
430 } 431 }
431 unsigned int count = 0; 432 unsigned int count = 0;
432 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 433 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
433 from = ""; 434 from = "";
434 named_from = false; 435 named_from = false;
435 current_address=(mailimap_address*)current->data; 436 current_address=(mailimap_address*)current->data;
436 if (current_address->ad_personal_name){ 437 if (current_address->ad_personal_name){
437 from+=QString(current_address->ad_personal_name); 438 from+=convert_String((const char*)current_address->ad_personal_name);
439 //from+=QString(current_address->ad_personal_name);
438 from+=" "; 440 from+=" ";
439 named_from = true; 441 named_from = true;
440 } 442 }
441 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)) {
442 from+="<"; 444 from+="<";
443 } 445 }
444 if (current_address->ad_mailbox_name) { 446 if (current_address->ad_mailbox_name) {
445 from+=QString(current_address->ad_mailbox_name); 447 from+=QString(current_address->ad_mailbox_name);
446 from+="@"; 448 from+="@";
447 } 449 }
448 if (current_address->ad_host_name) { 450 if (current_address->ad_host_name) {
449 from+=QString(current_address->ad_host_name); 451 from+=QString(current_address->ad_host_name);
450 } 452 }
451 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)) {
452 from+=">"; 454 from+=">";
453 } 455 }
454 l.append(QString(from)); 456 l.append(QString(from));
455 if (++count > 99) { 457 if (++count > 99) {
456 break; 458 break;
457 } 459 }
458 } 460 }
459 return l; 461 return l;
460} 462}
461 463
462encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 464encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
463{ 465{
464 encodedString*res=new encodedString; 466 encodedString*res=new encodedString;
465 const char*mb; 467 const char*mb;
466 int err; 468 int err;
467 mailimap_fetch_type *fetchType; 469 mailimap_fetch_type *fetchType;
468 mailimap_set *set; 470 mailimap_set *set;
469 clistcell*current,*cur; 471 clistcell*current,*cur;
470 472
471 login(); 473 login();
472 if (!m_imap) { 474 if (!m_imap) {
473 return res; 475 return res;
474 } 476 }
475 if (!internal_call) { 477 if (!internal_call) {
476 mb = mail.getMbox().latin1(); 478 mb = mail.getMbox().latin1();
477 err = mailimap_select( m_imap, (char*)mb); 479 err = mailimap_select( m_imap, (char*)mb);
478 if ( err != MAILIMAP_NO_ERROR ) { 480 if ( err != MAILIMAP_NO_ERROR ) {
479 qDebug("error selecting mailbox: %s",m_imap->imap_response); 481 qDebug("error selecting mailbox: %s",m_imap->imap_response);
480 return res; 482 return res;
481 } 483 }
482 } 484 }
483 set = mailimap_set_new_single(mail.getNumber()); 485 set = mailimap_set_new_single(mail.getNumber());
484 clist*id_list=clist_new(); 486 clist*id_list=clist_new();
485 for (unsigned j=0; j < path.count();++j) { 487 for (unsigned j=0; j < path.count();++j) {
486 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
487 *p_id = path[j]; 489 *p_id = path[j];
488 clist_append(id_list,p_id); 490 clist_append(id_list,p_id);
489 } 491 }
490 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 492 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
491 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);
492 mailimap_section * section = mailimap_section_new(section_spec); 494 mailimap_section * section = mailimap_section_new(section_spec);
493 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);
494 496
495 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 497 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
496 498
497 clist*result = clist_new(); 499 clist*result = clist_new();
498 500
499 err = mailimap_fetch( m_imap, set, fetchType, &result ); 501 err = mailimap_fetch( m_imap, set, fetchType, &result );
500 mailimap_set_free( set ); 502 mailimap_set_free( set );
501 mailimap_fetch_type_free( fetchType ); 503 mailimap_fetch_type_free( fetchType );
502 504
503 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
504 mailimap_msg_att * msg_att; 506 mailimap_msg_att * msg_att;
505 msg_att = (mailimap_msg_att*)current->data; 507 msg_att = (mailimap_msg_att*)current->data;
506 mailimap_msg_att_item*msg_att_item; 508 mailimap_msg_att_item*msg_att_item;
507 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)) {
508 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
509 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
510 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) {
511 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;
512 /* detach - we take over the content */ 514 /* detach - we take over the content */
513 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 515 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
514 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 516 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
515 } 517 }
516 } 518 }
517 } 519 }
518 } else { 520 } else {
519 qDebug("error fetching text: %s",m_imap->imap_response); 521 qDebug("error fetching text: %s",m_imap->imap_response);
520 } 522 }
521 mailimap_fetch_list_free(result); 523 mailimap_fetch_list_free(result);
522 return res; 524 return res;
523} 525}
524 526
525void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 527void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
526{ 528{
527 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 529 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
528 if (!mailDescription||current_recursion==10) { 530 if (!mailDescription||current_recursion==10) {
529 return; 531 return;
530 } 532 }
531 clistcell*current; 533 clistcell*current;
532 mailimap_body*current_body; 534 mailimap_body*current_body;
533 unsigned int count = 0; 535 unsigned int count = 0;
534 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 536 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
535 /* the point in the message */ 537 /* the point in the message */
536 ++count; 538 ++count;
537 current_body = (mailimap_body*)current->data; 539 current_body = (mailimap_body*)current->data;
538 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 540 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
539 QValueList<int>clist = recList; 541 QValueList<int>clist = recList;
540 clist.append(count); 542 clist.append(count);
541 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 543 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
542 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 544 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
543 RecPart currentPart; 545 RecPart currentPart;
544 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 546 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
545 QValueList<int>clist = recList; 547 QValueList<int>clist = recList;
546 clist.append(count); 548 clist.append(count);
547 /* important: Check for is NULL 'cause a body can be empty! */ 549 /* important: Check for is NULL 'cause a body can be empty! */
548 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 550 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
549 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 551 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
550 target_body.setDescription(currentPart); 552 target_body.setDescription(currentPart);
551 target_body.setBodytext(body_text); 553 target_body.setBodytext(body_text);
552 } else { 554 } else {
553 QString id(""); 555 QString id("");
554 for (unsigned int j = 0; j < clist.count();++j) { 556 for (unsigned int j = 0; j < clist.count();++j) {
555 id+=(j>0?" ":""); 557 id+=(j>0?" ":"");
556 id+=QString("%1").arg(clist[j]); 558 id+=QString("%1").arg(clist[j]);
557 } 559 }
558 qDebug("ID= %s",id.latin1()); 560 qDebug("ID= %s",id.latin1());
559 currentPart.setIdentifier(id); 561 currentPart.setIdentifier(id);
560 currentPart.setPositionlist(clist); 562 currentPart.setPositionlist(clist);
561 target_body.addPart(currentPart); 563 target_body.addPart(currentPart);
562 } 564 }
563 } 565 }
564 } 566 }
565} 567}
566 568
567void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 569void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
568{ 570{
569 if (!Description) { 571 if (!Description) {
570 return; 572 return;
571 } 573 }
572 switch (Description->bd_type) { 574 switch (Description->bd_type) {
573 case MAILIMAP_BODY_TYPE_1PART_TEXT: 575 case MAILIMAP_BODY_TYPE_1PART_TEXT:
574 target_part.setType("text"); 576 target_part.setType("text");
575 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 577 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
576 break; 578 break;
577 case MAILIMAP_BODY_TYPE_1PART_BASIC: 579 case MAILIMAP_BODY_TYPE_1PART_BASIC:
578 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 580 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
579 break; 581 break;
580 case MAILIMAP_BODY_TYPE_1PART_MSG: 582 case MAILIMAP_BODY_TYPE_1PART_MSG:
581 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 583 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
582 break; 584 break;
583 default: 585 default:
584 break; 586 break;
585 } 587 }
586} 588}
587 589
588void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 590void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
589{ 591{
590 if (!which) { 592 if (!which) {
591 return; 593 return;
592 } 594 }
593 QString sub; 595 QString sub;
594 sub = which->bd_media_text; 596 sub = which->bd_media_text;
595 target_part.setSubtype(sub.lower()); 597 target_part.setSubtype(sub.lower());
596 target_part.setLines(which->bd_lines); 598 target_part.setLines(which->bd_lines);
597 fillBodyFields(target_part,which->bd_fields); 599 fillBodyFields(target_part,which->bd_fields);
598} 600}
599 601
600void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 602void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
601{ 603{
602 if (!which) { 604 if (!which) {
603 return; 605 return;
604 } 606 }
605// QString sub; 607// QString sub;
606// sub = which->bd_media_text; 608// sub = which->bd_media_text;
607// target_part.setSubtype(sub.lower()); 609// target_part.setSubtype(sub.lower());
608 qDebug("Message part"); 610 qDebug("Message part");
609 /* we set this type to text/plain */ 611 /* we set this type to text/plain */
610 target_part.setType("text"); 612 target_part.setType("text");
611 target_part.setSubtype("plain"); 613 target_part.setSubtype("plain");
612 target_part.setLines(which->bd_lines); 614 target_part.setLines(which->bd_lines);
613 fillBodyFields(target_part,which->bd_fields); 615 fillBodyFields(target_part,which->bd_fields);
614} 616}
615 617
616void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 618void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
617{ 619{
618 if (!which) { 620 if (!which) {
619 return; 621 return;
620 } 622 }
621 QString type,sub; 623 QString type,sub;
622 switch (which->bd_media_basic->med_type) { 624 switch (which->bd_media_basic->med_type) {
623 case MAILIMAP_MEDIA_BASIC_APPLICATION: 625 case MAILIMAP_MEDIA_BASIC_APPLICATION:
624 type = "application"; 626 type = "application";
625 break; 627 break;
626 case MAILIMAP_MEDIA_BASIC_AUDIO: 628 case MAILIMAP_MEDIA_BASIC_AUDIO:
627 type = "audio"; 629 type = "audio";
628 break; 630 break;
629 case MAILIMAP_MEDIA_BASIC_IMAGE: 631 case MAILIMAP_MEDIA_BASIC_IMAGE:
630 type = "image"; 632 type = "image";
631 break; 633 break;
632 case MAILIMAP_MEDIA_BASIC_MESSAGE: 634 case MAILIMAP_MEDIA_BASIC_MESSAGE:
633 type = "message"; 635 type = "message";
634 break; 636 break;
635 case MAILIMAP_MEDIA_BASIC_VIDEO: 637 case MAILIMAP_MEDIA_BASIC_VIDEO:
636 type = "video"; 638 type = "video";
637 break; 639 break;
638 case MAILIMAP_MEDIA_BASIC_OTHER: 640 case MAILIMAP_MEDIA_BASIC_OTHER:
639 default: 641 default:
640 if (which->bd_media_basic->med_basic_type) { 642 if (which->bd_media_basic->med_basic_type) {
641 type = which->bd_media_basic->med_basic_type; 643 type = which->bd_media_basic->med_basic_type;
642 } else { 644 } else {
643 type = ""; 645 type = "";
644 } 646 }
645 break; 647 break;
646 } 648 }
647 if (which->bd_media_basic->med_subtype) { 649 if (which->bd_media_basic->med_subtype) {
648 sub = which->bd_media_basic->med_subtype; 650 sub = which->bd_media_basic->med_subtype;
649 } else { 651 } else {
650 sub = ""; 652 sub = "";
651 } 653 }
652 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 654 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
653 target_part.setType(type.lower()); 655 target_part.setType(type.lower());
654 target_part.setSubtype(sub.lower()); 656 target_part.setSubtype(sub.lower());
655 fillBodyFields(target_part,which->bd_fields); 657 fillBodyFields(target_part,which->bd_fields);
656} 658}
657 659
658void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 660void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
659{ 661{
660 if (!which) return; 662 if (!which) return;
661 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 663 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
662 clistcell*cur; 664 clistcell*cur;
663 mailimap_single_body_fld_param*param=0; 665 mailimap_single_body_fld_param*param=0;
664 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 666 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
665 param = (mailimap_single_body_fld_param*)cur->data; 667 param = (mailimap_single_body_fld_param*)cur->data;
666 if (param) { 668 if (param) {
667 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 669 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
668 } 670 }
669 } 671 }
670 } 672 }
671 mailimap_body_fld_enc*enc = which->bd_encoding; 673 mailimap_body_fld_enc*enc = which->bd_encoding;
672 QString encoding(""); 674 QString encoding("");
673 switch (enc->enc_type) { 675 switch (enc->enc_type) {
674 case MAILIMAP_BODY_FLD_ENC_7BIT: 676 case MAILIMAP_BODY_FLD_ENC_7BIT:
675 encoding = "7bit"; 677 encoding = "7bit";
676 break; 678 break;
677 case MAILIMAP_BODY_FLD_ENC_8BIT: 679 case MAILIMAP_BODY_FLD_ENC_8BIT:
678 encoding = "8bit"; 680 encoding = "8bit";
679 break; 681 break;
680 case MAILIMAP_BODY_FLD_ENC_BINARY: 682 case MAILIMAP_BODY_FLD_ENC_BINARY:
681 encoding="binary"; 683 encoding="binary";
682 break; 684 break;
683 case MAILIMAP_BODY_FLD_ENC_BASE64: 685 case MAILIMAP_BODY_FLD_ENC_BASE64:
684 encoding="base64"; 686 encoding="base64";
685 break; 687 break;
686 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 688 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
687 encoding="quoted-printable"; 689 encoding="quoted-printable";
688 break; 690 break;
689 case MAILIMAP_BODY_FLD_ENC_OTHER: 691 case MAILIMAP_BODY_FLD_ENC_OTHER:
690 default: 692 default:
691 if (enc->enc_value) { 693 if (enc->enc_value) {
692 char*t=enc->enc_value; 694 char*t=enc->enc_value;
693 encoding=QString(enc->enc_value); 695 encoding=QString(enc->enc_value);
694 enc->enc_value=0L; 696 enc->enc_value=0L;
695 free(t); 697 free(t);
696 } 698 }
697 } 699 }
698 if (which->bd_description) { 700 if (which->bd_description) {
699 target_part.setDescription(QString(which->bd_description)); 701 target_part.setDescription(QString(which->bd_description));
700 } 702 }
701 target_part.setEncoding(encoding); 703 target_part.setEncoding(encoding);
702 target_part.setSize(which->bd_size); 704 target_part.setSize(which->bd_size);
703} 705}
704 706
705void IMAPwrapper::deleteMail(const RecMail&mail) 707void IMAPwrapper::deleteMail(const RecMail&mail)
706{ 708{
707 mailimap_flag_list*flist; 709 mailimap_flag_list*flist;
708 mailimap_set *set; 710 mailimap_set *set;
709 mailimap_store_att_flags * store_flags; 711 mailimap_store_att_flags * store_flags;
710 int err; 712 int err;
711 login(); 713 login();
712 if (!m_imap) { 714 if (!m_imap) {
713 return; 715 return;
714 } 716 }
715 const char *mb = mail.getMbox().latin1(); 717 const char *mb = mail.getMbox().latin1();
716 err = mailimap_select( m_imap, (char*)mb); 718 err = mailimap_select( m_imap, (char*)mb);
717 if ( err != MAILIMAP_NO_ERROR ) { 719 if ( err != MAILIMAP_NO_ERROR ) {
718 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 720 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
719 return; 721 return;
720 } 722 }
721 flist = mailimap_flag_list_new_empty(); 723 flist = mailimap_flag_list_new_empty();
722 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 724 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
723 store_flags = mailimap_store_att_flags_new_set_flags(flist); 725 store_flags = mailimap_store_att_flags_new_set_flags(flist);
724 set = mailimap_set_new_single(mail.getNumber()); 726 set = mailimap_set_new_single(mail.getNumber());
725 err = mailimap_store(m_imap,set,store_flags); 727 err = mailimap_store(m_imap,set,store_flags);
726 mailimap_set_free( set ); 728 mailimap_set_free( set );
727 mailimap_store_att_flags_free(store_flags); 729 mailimap_store_att_flags_free(store_flags);
728 730
729 if (err != MAILIMAP_NO_ERROR) { 731 if (err != MAILIMAP_NO_ERROR) {
730 qDebug("error deleting mail: %s",m_imap->imap_response); 732 qDebug("error deleting mail: %s",m_imap->imap_response);
731 return; 733 return;
732 } 734 }
733 qDebug("deleting mail: %s",m_imap->imap_response); 735 qDebug("deleting mail: %s",m_imap->imap_response);
734 /* should we realy do that at this moment? */ 736 /* should we realy do that at this moment? */
735 err = mailimap_expunge(m_imap); 737 err = mailimap_expunge(m_imap);
736 if (err != MAILIMAP_NO_ERROR) { 738 if (err != MAILIMAP_NO_ERROR) {
737 qDebug("error deleting mail: %s",m_imap->imap_response); 739 qDebug("error deleting mail: %s",m_imap->imap_response);
738 } 740 }
739 qDebug("Delete successfull %s",m_imap->imap_response); 741 qDebug("Delete successfull %s",m_imap->imap_response);
740} 742}
741 743
742void IMAPwrapper::answeredMail(const RecMail&mail) 744void IMAPwrapper::answeredMail(const RecMail&mail)
743{ 745{
744 mailimap_flag_list*flist; 746 mailimap_flag_list*flist;
745 mailimap_set *set; 747 mailimap_set *set;
746 mailimap_store_att_flags * store_flags; 748 mailimap_store_att_flags * store_flags;
747 int err; 749 int err;
748 login(); 750 login();
749 if (!m_imap) { 751 if (!m_imap) {
750 return; 752 return;
751 } 753 }
752 const char *mb = mail.getMbox().latin1(); 754 const char *mb = mail.getMbox().latin1();
753 err = mailimap_select( m_imap, (char*)mb); 755 err = mailimap_select( m_imap, (char*)mb);
754 if ( err != MAILIMAP_NO_ERROR ) { 756 if ( err != MAILIMAP_NO_ERROR ) {
755 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 757 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
756 return; 758 return;
757 } 759 }
758 flist = mailimap_flag_list_new_empty(); 760 flist = mailimap_flag_list_new_empty();
759 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 761 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
760 store_flags = mailimap_store_att_flags_new_add_flags(flist); 762 store_flags = mailimap_store_att_flags_new_add_flags(flist);
761 set = mailimap_set_new_single(mail.getNumber()); 763 set = mailimap_set_new_single(mail.getNumber());
762 err = mailimap_store(m_imap,set,store_flags); 764 err = mailimap_store(m_imap,set,store_flags);
763 mailimap_set_free( set ); 765 mailimap_set_free( set );
764 mailimap_store_att_flags_free(store_flags); 766 mailimap_store_att_flags_free(store_flags);
765 767
766 if (err != MAILIMAP_NO_ERROR) { 768 if (err != MAILIMAP_NO_ERROR) {
767 qDebug("error marking mail: %s",m_imap->imap_response); 769 qDebug("error marking mail: %s",m_imap->imap_response);
768 return; 770 return;
769 } 771 }
770} 772}
771 773
772QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 774QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
773{ 775{
774 QString body(""); 776 QString body("");
775 encodedString*res = fetchRawPart(mail,path,internal_call); 777 encodedString*res = fetchRawPart(mail,path,internal_call);
776 encodedString*r = decode_String(res,enc); 778 encodedString*r = decode_String(res,enc);
777 delete res; 779 delete res;
778 if (r) { 780 if (r) {
779 if (r->Length()>0) { 781 if (r->Length()>0) {
780 body = r->Content(); 782 body = r->Content();
781 } 783 }
782 delete r; 784 delete r;
783 } 785 }
784 return body; 786 return body;
785} 787}
786 788
787QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
788{ 790{
789 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 791 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
790} 792}
791 793
792encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 794encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
793{ 795{
794 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 796 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
795 encodedString*r = decode_String(res,part.Encoding()); 797 encodedString*r = decode_String(res,part.Encoding());
796 delete res; 798 delete res;
797 return r; 799 return r;
798} 800}
799 801
800encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 802encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
801{ 803{
802 return fetchRawPart(mail,part.Positionlist(),false); 804 return fetchRawPart(mail,part.Positionlist(),false);
803} 805}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index b7e5eaa..3d76c96 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,71 +1,68 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <qstring.h> 6#include <qstring.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <libetpan/mailmime_content.h> 8#include <libetpan/mailmime_content.h>
9 9
10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
11{ 11{
12 return new IMAPwrapper(a); 12 return new IMAPwrapper(a);
13} 13}
14 14
15AbstractMail* AbstractMail::getWrapper(POP3account *a) 15AbstractMail* AbstractMail::getWrapper(POP3account *a)
16{ 16{
17 return new POP3wrapper(a); 17 return new POP3wrapper(a);
18} 18}
19 19
20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
21{ 21{
22 qDebug("Decode string start"); 22 qDebug("Decode string start");
23 char*result_text; 23 char*result_text;
24 size_t index = 0; 24 size_t index = 0;
25 /* reset for recursive use! */ 25 /* reset for recursive use! */
26 size_t target_length = 0; 26 size_t target_length = 0;
27 result_text = 0; 27 result_text = 0;
28 int mimetype = MAILMIME_MECHANISM_7BIT; 28 int mimetype = MAILMIME_MECHANISM_7BIT;
29 if (enc.lower()=="quoted-printable") { 29 if (enc.lower()=="quoted-printable") {
30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
31 } else if (enc.lower()=="base64") { 31 } else if (enc.lower()=="base64") {
32 mimetype = MAILMIME_MECHANISM_BASE64; 32 mimetype = MAILMIME_MECHANISM_BASE64;
33 } else if (enc.lower()=="8bit") { 33 } else if (enc.lower()=="8bit") {
34 mimetype = MAILMIME_MECHANISM_8BIT; 34 mimetype = MAILMIME_MECHANISM_8BIT;
35 } else if (enc.lower()=="binary") { 35 } else if (enc.lower()=="binary") {
36 mimetype = MAILMIME_MECHANISM_BINARY; 36 mimetype = MAILMIME_MECHANISM_BINARY;
37 } 37 }
38 38
39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
40 &result_text,&target_length); 40 &result_text,&target_length);
41 41
42 encodedString* result = new encodedString(); 42 encodedString* result = new encodedString();
43 if (err == MAILIMF_NO_ERROR) { 43 if (err == MAILIMF_NO_ERROR) {
44 result->setContent(result_text,target_length); 44 result->setContent(result_text,target_length);
45 } 45 }
46 qDebug("Decode string finished"); 46 qDebug("Decode string finished");
47 return result; 47 return result;
48} 48}
49 49
50QString AbstractMail::convert_String(const char*text) 50QString AbstractMail::convert_String(const char*text)
51{ 51{
52#if 0
53 size_t index = 0; 52 size_t index = 0;
54 char*res = 0; 53 char*res = 0;
55 54
56 qDebug("encode start %s",text); 55 /* attention - doesn't work with arm systems! */
57 /* attention - doesn't work with arm systems! */
58 int err = mailmime_encoded_phrase_parse("iso-8859-1", 56 int err = mailmime_encoded_phrase_parse("iso-8859-1",
59 text, strlen(text),&index, "iso-8859-1",&res); 57 text, strlen(text),&index, "iso-8859-1",&res);
60 qDebug("encode end");
61 if (err != MAILIMF_NO_ERROR) { 58 if (err != MAILIMF_NO_ERROR) {
62 if (res) free(res); 59 if (res) free(res);
63 return QString(text); 60 return QString(text);
64 } 61 }
65 QString result(res); 62 if (res) {
66 free(res); 63 QString result(res);
67 return result; 64 free(res);
68#else 65 return result;
69 return QString(text); 66 }
70#endif 67 return QString(text);
71} 68}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 8a86c95..838300a 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,803 +1,805 @@
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 QString del; 168 QString del;
169 if ( err == MAILIMAP_NO_ERROR ) { 169 if ( err == MAILIMAP_NO_ERROR ) {
170 current = result->first; 170 current = result->first;
171 for ( int i = result->count; i > 0; i-- ) { 171 for ( int i = result->count; i > 0; i-- ) {
172 list = (mailimap_mailbox_list *) current->data; 172 list = (mailimap_mailbox_list *) current->data;
173 // it is better use the deep copy mechanism of qt itself 173 // it is better use the deep copy mechanism of qt itself
174 // instead of using strdup! 174 // instead of using strdup!
175 temp = list->mb_name; 175 temp = list->mb_name;
176 del = list->mb_delimiter; 176 del = list->mb_delimiter;
177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
178 current = current->next; 178 current = current->next;
179 } 179 }
180 } else { 180 } else {
181 qDebug("error fetching folders: %s",m_imap->imap_response); 181 qDebug("error fetching folders: %s",m_imap->imap_response);
182 } 182 }
183 mailimap_list_result_free( result ); 183 mailimap_list_result_free( result );
184 184
185/* 185/*
186 * second stage - get the other then inbox folders 186 * second stage - get the other then inbox folders
187 */ 187 */
188 mask = "*" ; 188 mask = "*" ;
189 path = account->getPrefix().latin1(); 189 path = account->getPrefix().latin1();
190 if (!path) path = ""; 190 if (!path) path = "";
191 result = clist_new(); 191 result = clist_new();
192 qDebug(path); 192 qDebug(path);
193 bool selectable = true; 193 bool selectable = true;
194 mailimap_mbx_list_flags*bflags; 194 mailimap_mbx_list_flags*bflags;
195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
196 if ( err == MAILIMAP_NO_ERROR ) { 196 if ( err == MAILIMAP_NO_ERROR ) {
197 current = result->first; 197 current = result->first;
198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
199 list = (mailimap_mailbox_list *) current->data; 199 list = (mailimap_mailbox_list *) current->data;
200 // it is better use the deep copy mechanism of qt itself 200 // it is better use the deep copy mechanism of qt itself
201 // instead of using strdup! 201 // instead of using strdup!
202 temp = list->mb_name; 202 temp = list->mb_name;
203 if (temp.lower()=="inbox") 203 if (temp.lower()=="inbox")
204 continue; 204 continue;
205 if (temp.lower()==account->getPrefix().lower()) 205 if (temp.lower()==account->getPrefix().lower())
206 continue; 206 continue;
207 if ( (bflags = list->mb_flag) ) { 207 if ( (bflags = list->mb_flag) ) {
208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
210 } 210 }
211 del = list->mb_delimiter; 211 del = list->mb_delimiter;
212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
213 } 213 }
214 } else { 214 } else {
215 qDebug("error fetching folders %s",m_imap->imap_response); 215 qDebug("error fetching folders %s",m_imap->imap_response);
216 } 216 }
217 mailimap_list_result_free( result ); 217 mailimap_list_result_free( result );
218 return folders; 218 return folders;
219} 219}
220 220
221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
222{ 222{
223 RecMail * m = 0; 223 RecMail * m = 0;
224 mailimap_msg_att_item *item=0; 224 mailimap_msg_att_item *item=0;
225 clistcell *current,*c,*cf; 225 clistcell *current,*c,*cf;
226 mailimap_msg_att_dynamic*flist; 226 mailimap_msg_att_dynamic*flist;
227 mailimap_flag_fetch*cflag; 227 mailimap_flag_fetch*cflag;
228 int size; 228 int size;
229 QBitArray mFlags(7); 229 QBitArray mFlags(7);
230 QStringList addresslist; 230 QStringList addresslist;
231 231
232 if (!m_att) { 232 if (!m_att) {
233 return m; 233 return m;
234 } 234 }
235 m = new RecMail(); 235 m = new RecMail();
236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
237 current = c; 237 current = c;
238 size = 0; 238 size = 0;
239 item = (mailimap_msg_att_item*)current->data; 239 item = (mailimap_msg_att_item*)current->data;
240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
242 if (!flist->att_list) { 242 if (!flist->att_list) {
243 continue; 243 continue;
244 } 244 }
245 cf = flist->att_list->first; 245 cf = flist->att_list->first;
246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
247 cflag = (mailimap_flag_fetch*)cf->data; 247 cflag = (mailimap_flag_fetch*)cf->data;
248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
249 switch (cflag->fl_flag->fl_type) { 249 switch (cflag->fl_flag->fl_type) {
250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
251 mFlags.setBit(FLAG_ANSWERED); 251 mFlags.setBit(FLAG_ANSWERED);
252 break; 252 break;
253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
254 mFlags.setBit(FLAG_FLAGGED); 254 mFlags.setBit(FLAG_FLAGGED);
255 break; 255 break;
256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
257 mFlags.setBit(FLAG_DELETED); 257 mFlags.setBit(FLAG_DELETED);
258 break; 258 break;
259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
260 mFlags.setBit(FLAG_SEEN); 260 mFlags.setBit(FLAG_SEEN);
261 break; 261 break;
262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
263 mFlags.setBit(FLAG_DRAFT); 263 mFlags.setBit(FLAG_DRAFT);
264 break; 264 break;
265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
266 break; 266 break;
267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
268 break; 268 break;
269 default: 269 default:
270 break; 270 break;
271 } 271 }
272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
273 mFlags.setBit(FLAG_RECENT); 273 mFlags.setBit(FLAG_RECENT);
274 } 274 }
275 } 275 }
276 continue; 276 continue;
277 } 277 }
278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
280 m->setDate(head->env_date); 280 m->setDate(head->env_date);
281 m->setSubject(head->env_subject); 281 m->setSubject(convert_String((const char*)head->env_subject));
282 //m->setSubject(head->env_subject);
282 if (head->env_from!=NULL) { 283 if (head->env_from!=NULL) {
283 addresslist = address_list_to_stringlist(head->env_from->frm_list); 284 addresslist = address_list_to_stringlist(head->env_from->frm_list);
284 if (addresslist.count()) { 285 if (addresslist.count()) {
285 m->setFrom(addresslist.first()); 286 m->setFrom(addresslist.first());
286 } 287 }
287 } 288 }
288 if (head->env_to!=NULL) { 289 if (head->env_to!=NULL) {
289 addresslist = address_list_to_stringlist(head->env_to->to_list); 290 addresslist = address_list_to_stringlist(head->env_to->to_list);
290 m->setTo(addresslist); 291 m->setTo(addresslist);
291 } 292 }
292 if (head->env_cc!=NULL) { 293 if (head->env_cc!=NULL) {
293 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 294 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
294 m->setCC(addresslist); 295 m->setCC(addresslist);
295 } 296 }
296 if (head->env_bcc!=NULL) { 297 if (head->env_bcc!=NULL) {
297 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 298 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
298 m->setBcc(addresslist); 299 m->setBcc(addresslist);
299 } 300 }
300 if (head->env_reply_to!=NULL) { 301 if (head->env_reply_to!=NULL) {
301 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 302 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
302 if (addresslist.count()) { 303 if (addresslist.count()) {
303 m->setReplyto(addresslist.first()); 304 m->setReplyto(addresslist.first());
304 } 305 }
305 } 306 }
306 m->setMsgid(QString(head->env_message_id)); 307 m->setMsgid(QString(head->env_message_id));
307 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 308 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
308#if 0 309#if 0
309 310
310 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 311 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
311 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 312 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
312 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); 313 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);
313 qDebug(da.toString()); 314 qDebug(da.toString());
314#endif 315#endif
315 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 316 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
316 size = item->att_data.att_static->att_data.att_rfc822_size; 317 size = item->att_data.att_static->att_data.att_rfc822_size;
317 } 318 }
318 } 319 }
319 /* msg is already deleted */ 320 /* msg is already deleted */
320 if (mFlags.testBit(FLAG_DELETED) && m) { 321 if (mFlags.testBit(FLAG_DELETED) && m) {
321 delete m; 322 delete m;
322 m = 0; 323 m = 0;
323 } 324 }
324 if (m) { 325 if (m) {
325 m->setFlags(mFlags); 326 m->setFlags(mFlags);
326 m->setMsgsize(size); 327 m->setMsgsize(size);
327 } 328 }
328 return m; 329 return m;
329} 330}
330 331
331RecBody IMAPwrapper::fetchBody(const RecMail&mail) 332RecBody IMAPwrapper::fetchBody(const RecMail&mail)
332{ 333{
333 RecBody body; 334 RecBody body;
334 const char *mb; 335 const char *mb;
335 int err = MAILIMAP_NO_ERROR; 336 int err = MAILIMAP_NO_ERROR;
336 clist *result; 337 clist *result;
337 clistcell *current; 338 clistcell *current;
338 mailimap_fetch_att *fetchAtt; 339 mailimap_fetch_att *fetchAtt;
339 mailimap_fetch_type *fetchType; 340 mailimap_fetch_type *fetchType;
340 mailimap_set *set; 341 mailimap_set *set;
341 mailimap_body*body_desc; 342 mailimap_body*body_desc;
342 343
343 mb = mail.getMbox().latin1(); 344 mb = mail.getMbox().latin1();
344 345
345 login(); 346 login();
346 if (!m_imap) { 347 if (!m_imap) {
347 return body; 348 return body;
348 } 349 }
349 350
350 err = mailimap_select( m_imap, (char*)mb); 351 err = mailimap_select( m_imap, (char*)mb);
351 if ( err != MAILIMAP_NO_ERROR ) { 352 if ( err != MAILIMAP_NO_ERROR ) {
352 qDebug("error selecting mailbox: %s",m_imap->imap_response); 353 qDebug("error selecting mailbox: %s",m_imap->imap_response);
353 return body; 354 return body;
354 } 355 }
355 356
356 result = clist_new(); 357 result = clist_new();
357 /* the range has to start at 1!!! not with 0!!!! */ 358 /* the range has to start at 1!!! not with 0!!!! */
358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 359 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
359 fetchAtt = mailimap_fetch_att_new_bodystructure(); 360 fetchAtt = mailimap_fetch_att_new_bodystructure();
360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 361 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
361 err = mailimap_fetch( m_imap, set, fetchType, &result ); 362 err = mailimap_fetch( m_imap, set, fetchType, &result );
362 mailimap_set_free( set ); 363 mailimap_set_free( set );
363 mailimap_fetch_type_free( fetchType ); 364 mailimap_fetch_type_free( fetchType );
364 365
365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 366 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
366 mailimap_msg_att * msg_att; 367 mailimap_msg_att * msg_att;
367 msg_att = (mailimap_msg_att*)current->data; 368 msg_att = (mailimap_msg_att*)current->data;
368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 369 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
369 body_desc = item->att_data.att_static->att_data.att_body; 370 body_desc = item->att_data.att_static->att_data.att_body;
370 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 371 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
371 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 372 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
372 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 373 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
373 qDebug("Mulitpart mail"); 374 qDebug("Mulitpart mail");
374 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 375 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
375 } 376 }
376 } else { 377 } else {
377 qDebug("error fetching body: %s",m_imap->imap_response); 378 qDebug("error fetching body: %s",m_imap->imap_response);
378 } 379 }
379 mailimap_fetch_list_free(result); 380 mailimap_fetch_list_free(result);
380 return body; 381 return body;
381} 382}
382 383
383/* this routine is just called when the mail has only ONE part. 384/* this routine is just called when the mail has only ONE part.
384 for filling the parts of a multi-part-message there are other 385 for filling the parts of a multi-part-message there are other
385 routines 'cause we can not simply fetch the whole body. */ 386 routines 'cause we can not simply fetch the whole body. */
386void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 387void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
387{ 388{
388 if (!mailDescription) { 389 if (!mailDescription) {
389 return; 390 return;
390 } 391 }
391 QString sub,body_text; 392 QString sub,body_text;
392 RecPart singlePart; 393 RecPart singlePart;
393 QValueList<int> path; 394 QValueList<int> path;
394 fillSinglePart(singlePart,mailDescription); 395 fillSinglePart(singlePart,mailDescription);
395 switch (mailDescription->bd_type) { 396 switch (mailDescription->bd_type) {
396 case MAILIMAP_BODY_TYPE_1PART_MSG: 397 case MAILIMAP_BODY_TYPE_1PART_MSG:
397 path.append(1); 398 path.append(1);
398 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 399 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
399 target_body.setBodytext(body_text); 400 target_body.setBodytext(body_text);
400 target_body.setDescription(singlePart); 401 target_body.setDescription(singlePart);
401 break; 402 break;
402 case MAILIMAP_BODY_TYPE_1PART_TEXT: 403 case MAILIMAP_BODY_TYPE_1PART_TEXT:
403 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 404 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
404 path.append(1); 405 path.append(1);
405 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 406 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
406 target_body.setBodytext(body_text); 407 target_body.setBodytext(body_text);
407 target_body.setDescription(singlePart); 408 target_body.setDescription(singlePart);
408 break; 409 break;
409 case MAILIMAP_BODY_TYPE_1PART_BASIC: 410 case MAILIMAP_BODY_TYPE_1PART_BASIC:
410 qDebug("Single attachment"); 411 qDebug("Single attachment");
411 target_body.setBodytext(""); 412 target_body.setBodytext("");
412 target_body.addPart(singlePart); 413 target_body.addPart(singlePart);
413 break; 414 break;
414 default: 415 default:
415 break; 416 break;
416 } 417 }
417 418
418 return; 419 return;
419} 420}
420 421
421QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 422QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
422{ 423{
423 QStringList l; 424 QStringList l;
424 QString from; 425 QString from;
425 bool named_from; 426 bool named_from;
426 clistcell *current = NULL; 427 clistcell *current = NULL;
427 mailimap_address * current_address=NULL; 428 mailimap_address * current_address=NULL;
428 if (!list) { 429 if (!list) {
429 return l; 430 return l;
430 } 431 }
431 unsigned int count = 0; 432 unsigned int count = 0;
432 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 433 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
433 from = ""; 434 from = "";
434 named_from = false; 435 named_from = false;
435 current_address=(mailimap_address*)current->data; 436 current_address=(mailimap_address*)current->data;
436 if (current_address->ad_personal_name){ 437 if (current_address->ad_personal_name){
437 from+=QString(current_address->ad_personal_name); 438 from+=convert_String((const char*)current_address->ad_personal_name);
439 //from+=QString(current_address->ad_personal_name);
438 from+=" "; 440 from+=" ";
439 named_from = true; 441 named_from = true;
440 } 442 }
441 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)) {
442 from+="<"; 444 from+="<";
443 } 445 }
444 if (current_address->ad_mailbox_name) { 446 if (current_address->ad_mailbox_name) {
445 from+=QString(current_address->ad_mailbox_name); 447 from+=QString(current_address->ad_mailbox_name);
446 from+="@"; 448 from+="@";
447 } 449 }
448 if (current_address->ad_host_name) { 450 if (current_address->ad_host_name) {
449 from+=QString(current_address->ad_host_name); 451 from+=QString(current_address->ad_host_name);
450 } 452 }
451 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)) {
452 from+=">"; 454 from+=">";
453 } 455 }
454 l.append(QString(from)); 456 l.append(QString(from));
455 if (++count > 99) { 457 if (++count > 99) {
456 break; 458 break;
457 } 459 }
458 } 460 }
459 return l; 461 return l;
460} 462}
461 463
462encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 464encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
463{ 465{
464 encodedString*res=new encodedString; 466 encodedString*res=new encodedString;
465 const char*mb; 467 const char*mb;
466 int err; 468 int err;
467 mailimap_fetch_type *fetchType; 469 mailimap_fetch_type *fetchType;
468 mailimap_set *set; 470 mailimap_set *set;
469 clistcell*current,*cur; 471 clistcell*current,*cur;
470 472
471 login(); 473 login();
472 if (!m_imap) { 474 if (!m_imap) {
473 return res; 475 return res;
474 } 476 }
475 if (!internal_call) { 477 if (!internal_call) {
476 mb = mail.getMbox().latin1(); 478 mb = mail.getMbox().latin1();
477 err = mailimap_select( m_imap, (char*)mb); 479 err = mailimap_select( m_imap, (char*)mb);
478 if ( err != MAILIMAP_NO_ERROR ) { 480 if ( err != MAILIMAP_NO_ERROR ) {
479 qDebug("error selecting mailbox: %s",m_imap->imap_response); 481 qDebug("error selecting mailbox: %s",m_imap->imap_response);
480 return res; 482 return res;
481 } 483 }
482 } 484 }
483 set = mailimap_set_new_single(mail.getNumber()); 485 set = mailimap_set_new_single(mail.getNumber());
484 clist*id_list=clist_new(); 486 clist*id_list=clist_new();
485 for (unsigned j=0; j < path.count();++j) { 487 for (unsigned j=0; j < path.count();++j) {
486 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
487 *p_id = path[j]; 489 *p_id = path[j];
488 clist_append(id_list,p_id); 490 clist_append(id_list,p_id);
489 } 491 }
490 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 492 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
491 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);
492 mailimap_section * section = mailimap_section_new(section_spec); 494 mailimap_section * section = mailimap_section_new(section_spec);
493 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);
494 496
495 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 497 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
496 498
497 clist*result = clist_new(); 499 clist*result = clist_new();
498 500
499 err = mailimap_fetch( m_imap, set, fetchType, &result ); 501 err = mailimap_fetch( m_imap, set, fetchType, &result );
500 mailimap_set_free( set ); 502 mailimap_set_free( set );
501 mailimap_fetch_type_free( fetchType ); 503 mailimap_fetch_type_free( fetchType );
502 504
503 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
504 mailimap_msg_att * msg_att; 506 mailimap_msg_att * msg_att;
505 msg_att = (mailimap_msg_att*)current->data; 507 msg_att = (mailimap_msg_att*)current->data;
506 mailimap_msg_att_item*msg_att_item; 508 mailimap_msg_att_item*msg_att_item;
507 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)) {
508 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
509 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
510 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) {
511 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;
512 /* detach - we take over the content */ 514 /* detach - we take over the content */
513 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 515 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
514 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 516 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
515 } 517 }
516 } 518 }
517 } 519 }
518 } else { 520 } else {
519 qDebug("error fetching text: %s",m_imap->imap_response); 521 qDebug("error fetching text: %s",m_imap->imap_response);
520 } 522 }
521 mailimap_fetch_list_free(result); 523 mailimap_fetch_list_free(result);
522 return res; 524 return res;
523} 525}
524 526
525void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 527void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
526{ 528{
527 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 529 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
528 if (!mailDescription||current_recursion==10) { 530 if (!mailDescription||current_recursion==10) {
529 return; 531 return;
530 } 532 }
531 clistcell*current; 533 clistcell*current;
532 mailimap_body*current_body; 534 mailimap_body*current_body;
533 unsigned int count = 0; 535 unsigned int count = 0;
534 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 536 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
535 /* the point in the message */ 537 /* the point in the message */
536 ++count; 538 ++count;
537 current_body = (mailimap_body*)current->data; 539 current_body = (mailimap_body*)current->data;
538 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 540 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
539 QValueList<int>clist = recList; 541 QValueList<int>clist = recList;
540 clist.append(count); 542 clist.append(count);
541 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 543 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
542 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 544 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
543 RecPart currentPart; 545 RecPart currentPart;
544 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 546 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
545 QValueList<int>clist = recList; 547 QValueList<int>clist = recList;
546 clist.append(count); 548 clist.append(count);
547 /* important: Check for is NULL 'cause a body can be empty! */ 549 /* important: Check for is NULL 'cause a body can be empty! */
548 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 550 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
549 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 551 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
550 target_body.setDescription(currentPart); 552 target_body.setDescription(currentPart);
551 target_body.setBodytext(body_text); 553 target_body.setBodytext(body_text);
552 } else { 554 } else {
553 QString id(""); 555 QString id("");
554 for (unsigned int j = 0; j < clist.count();++j) { 556 for (unsigned int j = 0; j < clist.count();++j) {
555 id+=(j>0?" ":""); 557 id+=(j>0?" ":"");
556 id+=QString("%1").arg(clist[j]); 558 id+=QString("%1").arg(clist[j]);
557 } 559 }
558 qDebug("ID= %s",id.latin1()); 560 qDebug("ID= %s",id.latin1());
559 currentPart.setIdentifier(id); 561 currentPart.setIdentifier(id);
560 currentPart.setPositionlist(clist); 562 currentPart.setPositionlist(clist);
561 target_body.addPart(currentPart); 563 target_body.addPart(currentPart);
562 } 564 }
563 } 565 }
564 } 566 }
565} 567}
566 568
567void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 569void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
568{ 570{
569 if (!Description) { 571 if (!Description) {
570 return; 572 return;
571 } 573 }
572 switch (Description->bd_type) { 574 switch (Description->bd_type) {
573 case MAILIMAP_BODY_TYPE_1PART_TEXT: 575 case MAILIMAP_BODY_TYPE_1PART_TEXT:
574 target_part.setType("text"); 576 target_part.setType("text");
575 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 577 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
576 break; 578 break;
577 case MAILIMAP_BODY_TYPE_1PART_BASIC: 579 case MAILIMAP_BODY_TYPE_1PART_BASIC:
578 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 580 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
579 break; 581 break;
580 case MAILIMAP_BODY_TYPE_1PART_MSG: 582 case MAILIMAP_BODY_TYPE_1PART_MSG:
581 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 583 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
582 break; 584 break;
583 default: 585 default:
584 break; 586 break;
585 } 587 }
586} 588}
587 589
588void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 590void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
589{ 591{
590 if (!which) { 592 if (!which) {
591 return; 593 return;
592 } 594 }
593 QString sub; 595 QString sub;
594 sub = which->bd_media_text; 596 sub = which->bd_media_text;
595 target_part.setSubtype(sub.lower()); 597 target_part.setSubtype(sub.lower());
596 target_part.setLines(which->bd_lines); 598 target_part.setLines(which->bd_lines);
597 fillBodyFields(target_part,which->bd_fields); 599 fillBodyFields(target_part,which->bd_fields);
598} 600}
599 601
600void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 602void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
601{ 603{
602 if (!which) { 604 if (!which) {
603 return; 605 return;
604 } 606 }
605// QString sub; 607// QString sub;
606// sub = which->bd_media_text; 608// sub = which->bd_media_text;
607// target_part.setSubtype(sub.lower()); 609// target_part.setSubtype(sub.lower());
608 qDebug("Message part"); 610 qDebug("Message part");
609 /* we set this type to text/plain */ 611 /* we set this type to text/plain */
610 target_part.setType("text"); 612 target_part.setType("text");
611 target_part.setSubtype("plain"); 613 target_part.setSubtype("plain");
612 target_part.setLines(which->bd_lines); 614 target_part.setLines(which->bd_lines);
613 fillBodyFields(target_part,which->bd_fields); 615 fillBodyFields(target_part,which->bd_fields);
614} 616}
615 617
616void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 618void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
617{ 619{
618 if (!which) { 620 if (!which) {
619 return; 621 return;
620 } 622 }
621 QString type,sub; 623 QString type,sub;
622 switch (which->bd_media_basic->med_type) { 624 switch (which->bd_media_basic->med_type) {
623 case MAILIMAP_MEDIA_BASIC_APPLICATION: 625 case MAILIMAP_MEDIA_BASIC_APPLICATION:
624 type = "application"; 626 type = "application";
625 break; 627 break;
626 case MAILIMAP_MEDIA_BASIC_AUDIO: 628 case MAILIMAP_MEDIA_BASIC_AUDIO:
627 type = "audio"; 629 type = "audio";
628 break; 630 break;
629 case MAILIMAP_MEDIA_BASIC_IMAGE: 631 case MAILIMAP_MEDIA_BASIC_IMAGE:
630 type = "image"; 632 type = "image";
631 break; 633 break;
632 case MAILIMAP_MEDIA_BASIC_MESSAGE: 634 case MAILIMAP_MEDIA_BASIC_MESSAGE:
633 type = "message"; 635 type = "message";
634 break; 636 break;
635 case MAILIMAP_MEDIA_BASIC_VIDEO: 637 case MAILIMAP_MEDIA_BASIC_VIDEO:
636 type = "video"; 638 type = "video";
637 break; 639 break;
638 case MAILIMAP_MEDIA_BASIC_OTHER: 640 case MAILIMAP_MEDIA_BASIC_OTHER:
639 default: 641 default:
640 if (which->bd_media_basic->med_basic_type) { 642 if (which->bd_media_basic->med_basic_type) {
641 type = which->bd_media_basic->med_basic_type; 643 type = which->bd_media_basic->med_basic_type;
642 } else { 644 } else {
643 type = ""; 645 type = "";
644 } 646 }
645 break; 647 break;
646 } 648 }
647 if (which->bd_media_basic->med_subtype) { 649 if (which->bd_media_basic->med_subtype) {
648 sub = which->bd_media_basic->med_subtype; 650 sub = which->bd_media_basic->med_subtype;
649 } else { 651 } else {
650 sub = ""; 652 sub = "";
651 } 653 }
652 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 654 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
653 target_part.setType(type.lower()); 655 target_part.setType(type.lower());
654 target_part.setSubtype(sub.lower()); 656 target_part.setSubtype(sub.lower());
655 fillBodyFields(target_part,which->bd_fields); 657 fillBodyFields(target_part,which->bd_fields);
656} 658}
657 659
658void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 660void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
659{ 661{
660 if (!which) return; 662 if (!which) return;
661 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 663 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
662 clistcell*cur; 664 clistcell*cur;
663 mailimap_single_body_fld_param*param=0; 665 mailimap_single_body_fld_param*param=0;
664 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 666 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
665 param = (mailimap_single_body_fld_param*)cur->data; 667 param = (mailimap_single_body_fld_param*)cur->data;
666 if (param) { 668 if (param) {
667 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 669 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
668 } 670 }
669 } 671 }
670 } 672 }
671 mailimap_body_fld_enc*enc = which->bd_encoding; 673 mailimap_body_fld_enc*enc = which->bd_encoding;
672 QString encoding(""); 674 QString encoding("");
673 switch (enc->enc_type) { 675 switch (enc->enc_type) {
674 case MAILIMAP_BODY_FLD_ENC_7BIT: 676 case MAILIMAP_BODY_FLD_ENC_7BIT:
675 encoding = "7bit"; 677 encoding = "7bit";
676 break; 678 break;
677 case MAILIMAP_BODY_FLD_ENC_8BIT: 679 case MAILIMAP_BODY_FLD_ENC_8BIT:
678 encoding = "8bit"; 680 encoding = "8bit";
679 break; 681 break;
680 case MAILIMAP_BODY_FLD_ENC_BINARY: 682 case MAILIMAP_BODY_FLD_ENC_BINARY:
681 encoding="binary"; 683 encoding="binary";
682 break; 684 break;
683 case MAILIMAP_BODY_FLD_ENC_BASE64: 685 case MAILIMAP_BODY_FLD_ENC_BASE64:
684 encoding="base64"; 686 encoding="base64";
685 break; 687 break;
686 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 688 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
687 encoding="quoted-printable"; 689 encoding="quoted-printable";
688 break; 690 break;
689 case MAILIMAP_BODY_FLD_ENC_OTHER: 691 case MAILIMAP_BODY_FLD_ENC_OTHER:
690 default: 692 default:
691 if (enc->enc_value) { 693 if (enc->enc_value) {
692 char*t=enc->enc_value; 694 char*t=enc->enc_value;
693 encoding=QString(enc->enc_value); 695 encoding=QString(enc->enc_value);
694 enc->enc_value=0L; 696 enc->enc_value=0L;
695 free(t); 697 free(t);
696 } 698 }
697 } 699 }
698 if (which->bd_description) { 700 if (which->bd_description) {
699 target_part.setDescription(QString(which->bd_description)); 701 target_part.setDescription(QString(which->bd_description));
700 } 702 }
701 target_part.setEncoding(encoding); 703 target_part.setEncoding(encoding);
702 target_part.setSize(which->bd_size); 704 target_part.setSize(which->bd_size);
703} 705}
704 706
705void IMAPwrapper::deleteMail(const RecMail&mail) 707void IMAPwrapper::deleteMail(const RecMail&mail)
706{ 708{
707 mailimap_flag_list*flist; 709 mailimap_flag_list*flist;
708 mailimap_set *set; 710 mailimap_set *set;
709 mailimap_store_att_flags * store_flags; 711 mailimap_store_att_flags * store_flags;
710 int err; 712 int err;
711 login(); 713 login();
712 if (!m_imap) { 714 if (!m_imap) {
713 return; 715 return;
714 } 716 }
715 const char *mb = mail.getMbox().latin1(); 717 const char *mb = mail.getMbox().latin1();
716 err = mailimap_select( m_imap, (char*)mb); 718 err = mailimap_select( m_imap, (char*)mb);
717 if ( err != MAILIMAP_NO_ERROR ) { 719 if ( err != MAILIMAP_NO_ERROR ) {
718 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 720 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
719 return; 721 return;
720 } 722 }
721 flist = mailimap_flag_list_new_empty(); 723 flist = mailimap_flag_list_new_empty();
722 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 724 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
723 store_flags = mailimap_store_att_flags_new_set_flags(flist); 725 store_flags = mailimap_store_att_flags_new_set_flags(flist);
724 set = mailimap_set_new_single(mail.getNumber()); 726 set = mailimap_set_new_single(mail.getNumber());
725 err = mailimap_store(m_imap,set,store_flags); 727 err = mailimap_store(m_imap,set,store_flags);
726 mailimap_set_free( set ); 728 mailimap_set_free( set );
727 mailimap_store_att_flags_free(store_flags); 729 mailimap_store_att_flags_free(store_flags);
728 730
729 if (err != MAILIMAP_NO_ERROR) { 731 if (err != MAILIMAP_NO_ERROR) {
730 qDebug("error deleting mail: %s",m_imap->imap_response); 732 qDebug("error deleting mail: %s",m_imap->imap_response);
731 return; 733 return;
732 } 734 }
733 qDebug("deleting mail: %s",m_imap->imap_response); 735 qDebug("deleting mail: %s",m_imap->imap_response);
734 /* should we realy do that at this moment? */ 736 /* should we realy do that at this moment? */
735 err = mailimap_expunge(m_imap); 737 err = mailimap_expunge(m_imap);
736 if (err != MAILIMAP_NO_ERROR) { 738 if (err != MAILIMAP_NO_ERROR) {
737 qDebug("error deleting mail: %s",m_imap->imap_response); 739 qDebug("error deleting mail: %s",m_imap->imap_response);
738 } 740 }
739 qDebug("Delete successfull %s",m_imap->imap_response); 741 qDebug("Delete successfull %s",m_imap->imap_response);
740} 742}
741 743
742void IMAPwrapper::answeredMail(const RecMail&mail) 744void IMAPwrapper::answeredMail(const RecMail&mail)
743{ 745{
744 mailimap_flag_list*flist; 746 mailimap_flag_list*flist;
745 mailimap_set *set; 747 mailimap_set *set;
746 mailimap_store_att_flags * store_flags; 748 mailimap_store_att_flags * store_flags;
747 int err; 749 int err;
748 login(); 750 login();
749 if (!m_imap) { 751 if (!m_imap) {
750 return; 752 return;
751 } 753 }
752 const char *mb = mail.getMbox().latin1(); 754 const char *mb = mail.getMbox().latin1();
753 err = mailimap_select( m_imap, (char*)mb); 755 err = mailimap_select( m_imap, (char*)mb);
754 if ( err != MAILIMAP_NO_ERROR ) { 756 if ( err != MAILIMAP_NO_ERROR ) {
755 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 757 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
756 return; 758 return;
757 } 759 }
758 flist = mailimap_flag_list_new_empty(); 760 flist = mailimap_flag_list_new_empty();
759 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 761 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
760 store_flags = mailimap_store_att_flags_new_add_flags(flist); 762 store_flags = mailimap_store_att_flags_new_add_flags(flist);
761 set = mailimap_set_new_single(mail.getNumber()); 763 set = mailimap_set_new_single(mail.getNumber());
762 err = mailimap_store(m_imap,set,store_flags); 764 err = mailimap_store(m_imap,set,store_flags);
763 mailimap_set_free( set ); 765 mailimap_set_free( set );
764 mailimap_store_att_flags_free(store_flags); 766 mailimap_store_att_flags_free(store_flags);
765 767
766 if (err != MAILIMAP_NO_ERROR) { 768 if (err != MAILIMAP_NO_ERROR) {
767 qDebug("error marking mail: %s",m_imap->imap_response); 769 qDebug("error marking mail: %s",m_imap->imap_response);
768 return; 770 return;
769 } 771 }
770} 772}
771 773
772QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 774QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
773{ 775{
774 QString body(""); 776 QString body("");
775 encodedString*res = fetchRawPart(mail,path,internal_call); 777 encodedString*res = fetchRawPart(mail,path,internal_call);
776 encodedString*r = decode_String(res,enc); 778 encodedString*r = decode_String(res,enc);
777 delete res; 779 delete res;
778 if (r) { 780 if (r) {
779 if (r->Length()>0) { 781 if (r->Length()>0) {
780 body = r->Content(); 782 body = r->Content();
781 } 783 }
782 delete r; 784 delete r;
783 } 785 }
784 return body; 786 return body;
785} 787}
786 788
787QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
788{ 790{
789 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 791 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
790} 792}
791 793
792encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 794encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
793{ 795{
794 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 796 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
795 encodedString*r = decode_String(res,part.Encoding()); 797 encodedString*r = decode_String(res,part.Encoding());
796 delete res; 798 delete res;
797 return r; 799 return r;
798} 800}
799 801
800encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 802encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
801{ 803{
802 return fetchRawPart(mail,part.Positionlist(),false); 804 return fetchRawPart(mail,part.Positionlist(),false);
803} 805}