summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp1
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp1
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp12
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h5
-rw-r--r--noncore/net/mail/mailtypes.cpp12
-rw-r--r--noncore/net/mail/mailtypes.h5
-rw-r--r--noncore/net/mail/viewmail.cpp94
-rw-r--r--noncore/net/mail/viewmail.h26
-rw-r--r--noncore/net/mail/viewmailbase.cpp7
9 files changed, 120 insertions, 43 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 3941cec..11bf3b8 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,694 +1,695 @@
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{ 9{
10 account = a; 10 account = a;
11 m_imap = 0; 11 m_imap = 0;
12} 12}
13 13
14IMAPwrapper::~IMAPwrapper() 14IMAPwrapper::~IMAPwrapper()
15{ 15{
16 logout(); 16 logout();
17} 17}
18 18
19void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 19void IMAPwrapper::imap_progress( size_t current, size_t maximum )
20{ 20{
21 qDebug( "IMAP: %i of %i", current, maximum ); 21 qDebug( "IMAP: %i of %i", current, maximum );
22} 22}
23 23
24void IMAPwrapper::login() 24void IMAPwrapper::login()
25{ 25{
26 const char *server, *user, *pass; 26 const char *server, *user, *pass;
27 uint16_t port; 27 uint16_t port;
28 int err = MAILIMAP_NO_ERROR; 28 int err = MAILIMAP_NO_ERROR;
29 29
30 /* we are connected this moment */ 30 /* we are connected this moment */
31 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 31 /* TODO: setup a timer holding the line or if connection closed - delete the value */
32 if (m_imap) { 32 if (m_imap) {
33 return; 33 return;
34 } 34 }
35 server = account->getServer().latin1(); 35 server = account->getServer().latin1();
36 port = account->getPort().toUInt(); 36 port = account->getPort().toUInt();
37 user = account->getUser().latin1(); 37 user = account->getUser().latin1();
38 pass = account->getPassword().latin1(); 38 pass = account->getPassword().latin1();
39 39
40 m_imap = mailimap_new( 20, &imap_progress ); 40 m_imap = mailimap_new( 20, &imap_progress );
41 /* connect */ 41 /* connect */
42 if (account->getSSL()) { 42 if (account->getSSL()) {
43 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 43 err = mailimap_ssl_connect( m_imap, (char*)server, port );
44 } else { 44 } else {
45 err = mailimap_socket_connect( m_imap, (char*)server, port ); 45 err = mailimap_socket_connect( m_imap, (char*)server, port );
46 } 46 }
47 47
48 if ( err != MAILIMAP_NO_ERROR && 48 if ( err != MAILIMAP_NO_ERROR &&
49 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 49 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
50 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 50 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
51 qDebug("error connecting server: %s",m_imap->imap_response); 51 qDebug("error connecting server: %s",m_imap->imap_response);
52 mailimap_free( m_imap ); 52 mailimap_free( m_imap );
53 m_imap = 0; 53 m_imap = 0;
54 return; 54 return;
55 } 55 }
56 56
57 /* login */ 57 /* login */
58 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 58 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
59 if ( err != MAILIMAP_NO_ERROR ) { 59 if ( err != MAILIMAP_NO_ERROR ) {
60 qDebug("error logging in imap: %s",m_imap->imap_response); 60 qDebug("error logging in imap: %s",m_imap->imap_response);
61 err = mailimap_close( m_imap ); 61 err = mailimap_close( m_imap );
62 mailimap_free( m_imap ); 62 mailimap_free( m_imap );
63 m_imap = 0; 63 m_imap = 0;
64 } 64 }
65} 65}
66 66
67void IMAPwrapper::logout() 67void IMAPwrapper::logout()
68{ 68{
69 int err = MAILIMAP_NO_ERROR; 69 int err = MAILIMAP_NO_ERROR;
70 if (!m_imap) return; 70 if (!m_imap) return;
71 err = mailimap_logout( m_imap ); 71 err = mailimap_logout( m_imap );
72 err = mailimap_close( m_imap ); 72 err = mailimap_close( m_imap );
73 mailimap_free( m_imap ); 73 mailimap_free( m_imap );
74 m_imap = 0; 74 m_imap = 0;
75} 75}
76 76
77void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 77void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
78{ 78{
79 const char *mb; 79 const char *mb;
80 int err = MAILIMAP_NO_ERROR; 80 int err = MAILIMAP_NO_ERROR;
81 clist *result; 81 clist *result;
82 clistcell *current; 82 clistcell *current;
83// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 83// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
84 mailimap_fetch_type *fetchType; 84 mailimap_fetch_type *fetchType;
85 mailimap_set *set; 85 mailimap_set *set;
86 86
87 mb = mailbox.latin1(); 87 mb = mailbox.latin1();
88 login(); 88 login();
89 if (!m_imap) { 89 if (!m_imap) {
90 return; 90 return;
91 } 91 }
92 /* select mailbox READONLY for operations */ 92 /* select mailbox READONLY for operations */
93 err = mailimap_examine( m_imap, (char*)mb); 93 err = mailimap_examine( m_imap, (char*)mb);
94 if ( err != MAILIMAP_NO_ERROR ) { 94 if ( err != MAILIMAP_NO_ERROR ) {
95 qDebug("error selecting mailbox: %s",m_imap->imap_response); 95 qDebug("error selecting mailbox: %s",m_imap->imap_response);
96 return; 96 return;
97 } 97 }
98 98
99 int last = m_imap->imap_selection_info->sel_exists; 99 int last = m_imap->imap_selection_info->sel_exists;
100 100
101 if (last == 0) { 101 if (last == 0) {
102 qDebug("mailbox has no mails"); 102 qDebug("mailbox has no mails");
103 return; 103 return;
104 } 104 }
105 105
106 result = clist_new(); 106 result = clist_new();
107 /* the range has to start at 1!!! not with 0!!!! */ 107 /* the range has to start at 1!!! not with 0!!!! */
108 set = mailimap_set_new_interval( 1, last ); 108 set = mailimap_set_new_interval( 1, last );
109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
114 114
115 err = mailimap_fetch( m_imap, set, fetchType, &result ); 115 err = mailimap_fetch( m_imap, set, fetchType, &result );
116 mailimap_set_free( set ); 116 mailimap_set_free( set );
117 mailimap_fetch_type_free( fetchType ); 117 mailimap_fetch_type_free( fetchType );
118 118
119 QString date,subject,from; 119 QString date,subject,from;
120 120
121 if ( err == MAILIMAP_NO_ERROR ) { 121 if ( err == MAILIMAP_NO_ERROR ) {
122 122
123 mailimap_msg_att * msg_att; 123 mailimap_msg_att * msg_att;
124 int i = 0; 124 int i = 0;
125 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 125 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
126 ++i; 126 ++i;
127 msg_att = (mailimap_msg_att*)current->data; 127 msg_att = (mailimap_msg_att*)current->data;
128 RecMail*m = parse_list_result(msg_att); 128 RecMail*m = parse_list_result(msg_att);
129 if (m) { 129 if (m) {
130 m->setNumber(i); 130 m->setNumber(i);
131 m->setMbox(mailbox); 131 m->setMbox(mailbox);
132 target.append(m); 132 target.append(m);
133 } 133 }
134 } 134 }
135 } else { 135 } else {
136 qDebug("Error fetching headers: %s",m_imap->imap_response); 136 qDebug("Error fetching headers: %s",m_imap->imap_response);
137 } 137 }
138 mailimap_fetch_list_free(result); 138 mailimap_fetch_list_free(result);
139} 139}
140 140
141QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 142{
143 const char *path, *mask; 143 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
145 clist *result; 145 clist *result;
146 clistcell *current; 146 clistcell *current;
147 147
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
150 login(); 150 login();
151 if (!m_imap) { 151 if (!m_imap) {
152 return folders; 152 return folders;
153 } 153 }
154 154
155/* 155/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
157 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
158 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 159 */
160 QString temp; 160 QString temp;
161 mask = "INBOX" ; 161 mask = "INBOX" ;
162 result = clist_new(); 162 result = clist_new();
163 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 166 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 170 // instead of using strdup!
171 temp = list->mb_name; 171 temp = list->mb_name;
172 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
173 current = current->next; 173 current = current->next;
174 } 174 }
175 } else { 175 } else {
176 qDebug("error fetching folders: %s",m_imap->imap_response); 176 qDebug("error fetching folders: %s",m_imap->imap_response);
177 } 177 }
178 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
179 179
180/* 180/*
181 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
182 */ 182 */
183 mask = "*" ; 183 mask = "*" ;
184 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
185 if (!path) path = ""; 185 if (!path) path = "";
186 result = clist_new(); 186 result = clist_new();
187 qDebug(path); 187 qDebug(path);
188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
189 if ( err == MAILIMAP_NO_ERROR ) { 189 if ( err == MAILIMAP_NO_ERROR ) {
190 current = result->first; 190 current = result->first;
191 for ( int i = result->count; i > 0; i-- ) { 191 for ( int i = result->count; i > 0; i-- ) {
192 list = (mailimap_mailbox_list *) current->data; 192 list = (mailimap_mailbox_list *) current->data;
193 // it is better use the deep copy mechanism of qt itself 193 // it is better use the deep copy mechanism of qt itself
194 // instead of using strdup! 194 // instead of using strdup!
195 temp = list->mb_name; 195 temp = list->mb_name;
196 current = current->next; 196 current = current->next;
197 if (temp.lower()=="inbox") 197 if (temp.lower()=="inbox")
198 continue; 198 continue;
199 folders->append(new IMAPFolder(temp)); 199 folders->append(new IMAPFolder(temp));
200 200
201 } 201 }
202 } else { 202 } else {
203 qDebug("error fetching folders %s",m_imap->imap_response); 203 qDebug("error fetching folders %s",m_imap->imap_response);
204 } 204 }
205 mailimap_list_result_free( result ); 205 mailimap_list_result_free( result );
206 return folders; 206 return folders;
207} 207}
208 208
209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
210{ 210{
211 RecMail * m = 0; 211 RecMail * m = 0;
212 mailimap_msg_att_item *item=0; 212 mailimap_msg_att_item *item=0;
213 clistcell *current,*c,*cf; 213 clistcell *current,*c,*cf;
214 mailimap_msg_att_dynamic*flist; 214 mailimap_msg_att_dynamic*flist;
215 mailimap_flag_fetch*cflag; 215 mailimap_flag_fetch*cflag;
216 int size; 216 int size;
217 QBitArray mFlags(7); 217 QBitArray mFlags(7);
218 QStringList addresslist; 218 QStringList addresslist;
219 219
220 if (!m_att) { 220 if (!m_att) {
221 return m; 221 return m;
222 } 222 }
223 m = new RecMail(); 223 m = new RecMail();
224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
225 current = c; 225 current = c;
226 size = 0; 226 size = 0;
227 item = (mailimap_msg_att_item*)current->data; 227 item = (mailimap_msg_att_item*)current->data;
228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
230 if (!flist->att_list) { 230 if (!flist->att_list) {
231 continue; 231 continue;
232 } 232 }
233 cf = flist->att_list->first; 233 cf = flist->att_list->first;
234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
235 cflag = (mailimap_flag_fetch*)cf->data; 235 cflag = (mailimap_flag_fetch*)cf->data;
236 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 236 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
237 switch (cflag->fl_flag->fl_type) { 237 switch (cflag->fl_flag->fl_type) {
238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
239 mFlags.setBit(FLAG_ANSWERED); 239 mFlags.setBit(FLAG_ANSWERED);
240 break; 240 break;
241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
242 mFlags.setBit(FLAG_FLAGGED); 242 mFlags.setBit(FLAG_FLAGGED);
243 break; 243 break;
244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
245 mFlags.setBit(FLAG_DELETED); 245 mFlags.setBit(FLAG_DELETED);
246 break; 246 break;
247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
248 mFlags.setBit(FLAG_SEEN); 248 mFlags.setBit(FLAG_SEEN);
249 break; 249 break;
250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
251 mFlags.setBit(FLAG_DRAFT); 251 mFlags.setBit(FLAG_DRAFT);
252 break; 252 break;
253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
254 break; 254 break;
255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
256 break; 256 break;
257 default: 257 default:
258 break; 258 break;
259 } 259 }
260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
261 mFlags.setBit(FLAG_RECENT); 261 mFlags.setBit(FLAG_RECENT);
262 } 262 }
263 } 263 }
264 continue; 264 continue;
265 } 265 }
266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
267 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 267 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
268 m->setDate(head->env_date); 268 m->setDate(head->env_date);
269 m->setSubject(head->env_subject); 269 m->setSubject(head->env_subject);
270 if (head->env_from!=NULL) { 270 if (head->env_from!=NULL) {
271 addresslist = address_list_to_stringlist(head->env_from->frm_list); 271 addresslist = address_list_to_stringlist(head->env_from->frm_list);
272 if (addresslist.count()) { 272 if (addresslist.count()) {
273 m->setFrom(addresslist.first()); 273 m->setFrom(addresslist.first());
274 } 274 }
275 } 275 }
276 if (head->env_to!=NULL) { 276 if (head->env_to!=NULL) {
277 addresslist = address_list_to_stringlist(head->env_to->to_list); 277 addresslist = address_list_to_stringlist(head->env_to->to_list);
278 m->setTo(addresslist); 278 m->setTo(addresslist);
279 } 279 }
280 if (head->env_cc!=NULL) { 280 if (head->env_cc!=NULL) {
281 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 281 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
282 m->setCC(addresslist); 282 m->setCC(addresslist);
283 } 283 }
284 if (head->env_bcc!=NULL) { 284 if (head->env_bcc!=NULL) {
285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
286 m->setBcc(addresslist); 286 m->setBcc(addresslist);
287 } 287 }
288 if (head->env_reply_to!=NULL) { 288 if (head->env_reply_to!=NULL) {
289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
290 if (addresslist.count()) { 290 if (addresslist.count()) {
291 m->setReplyto(addresslist.first()); 291 m->setReplyto(addresslist.first());
292 } 292 }
293 } 293 }
294 m->setMsgid(QString(head->env_message_id)); 294 m->setMsgid(QString(head->env_message_id));
295 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 295 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
296 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 296 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
297 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 297 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
298 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); 298 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);
299 qDebug(da.toString()); 299 qDebug(da.toString());
300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
301 size = item->att_data.att_static->att_data.att_rfc822_size; 301 size = item->att_data.att_static->att_data.att_rfc822_size;
302 } 302 }
303 } 303 }
304 /* msg is already deleted */ 304 /* msg is already deleted */
305 if (mFlags.testBit(FLAG_DELETED) && m) { 305 if (mFlags.testBit(FLAG_DELETED) && m) {
306 delete m; 306 delete m;
307 m = 0; 307 m = 0;
308 } 308 }
309 if (m) { 309 if (m) {
310 m->setFlags(mFlags); 310 m->setFlags(mFlags);
311 m->setMsgsize(size); 311 m->setMsgsize(size);
312 } 312 }
313 return m; 313 return m;
314} 314}
315 315
316RecBody IMAPwrapper::fetchBody(const RecMail&mail) 316RecBody IMAPwrapper::fetchBody(const RecMail&mail)
317{ 317{
318 RecBody body; 318 RecBody body;
319 const char *mb; 319 const char *mb;
320 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
321 clist *result; 321 clist *result;
322 clistcell *current; 322 clistcell *current;
323 mailimap_fetch_att *fetchAtt; 323 mailimap_fetch_att *fetchAtt;
324 mailimap_fetch_type *fetchType; 324 mailimap_fetch_type *fetchType;
325 mailimap_set *set; 325 mailimap_set *set;
326 mailimap_body*body_desc; 326 mailimap_body*body_desc;
327 327
328 mb = mail.getMbox().latin1(); 328 mb = mail.getMbox().latin1();
329 329
330 login(); 330 login();
331 if (!m_imap) { 331 if (!m_imap) {
332 return body; 332 return body;
333 } 333 }
334 334
335 err = mailimap_select( m_imap, (char*)mb); 335 err = mailimap_select( m_imap, (char*)mb);
336 if ( err != MAILIMAP_NO_ERROR ) { 336 if ( err != MAILIMAP_NO_ERROR ) {
337 qDebug("error selecting mailbox: %s",m_imap->imap_response); 337 qDebug("error selecting mailbox: %s",m_imap->imap_response);
338 return body; 338 return body;
339 } 339 }
340 340
341 result = clist_new(); 341 result = clist_new();
342 /* the range has to start at 1!!! not with 0!!!! */ 342 /* the range has to start at 1!!! not with 0!!!! */
343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
344 fetchAtt = mailimap_fetch_att_new_bodystructure(); 344 fetchAtt = mailimap_fetch_att_new_bodystructure();
345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
346 err = mailimap_fetch( m_imap, set, fetchType, &result ); 346 err = mailimap_fetch( m_imap, set, fetchType, &result );
347 mailimap_set_free( set ); 347 mailimap_set_free( set );
348 mailimap_fetch_type_free( fetchType ); 348 mailimap_fetch_type_free( fetchType );
349 349
350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
351 mailimap_msg_att * msg_att; 351 mailimap_msg_att * msg_att;
352 msg_att = (mailimap_msg_att*)current->data; 352 msg_att = (mailimap_msg_att*)current->data;
353 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 353 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
354 body_desc = item->att_data.att_static->att_data.att_body; 354 body_desc = item->att_data.att_static->att_data.att_body;
355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
358 qDebug("Mulitpart mail"); 358 qDebug("Mulitpart mail");
359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
360 } 360 }
361 } else { 361 } else {
362 qDebug("error fetching body: %s",m_imap->imap_response); 362 qDebug("error fetching body: %s",m_imap->imap_response);
363 } 363 }
364 mailimap_fetch_list_free(result); 364 mailimap_fetch_list_free(result);
365 return body; 365 return body;
366} 366}
367 367
368/* this routine is just called when the mail has only ONE part. 368/* this routine is just called when the mail has only ONE part.
369 for filling the parts of a multi-part-message there are other 369 for filling the parts of a multi-part-message there are other
370 routines 'cause we can not simply fetch the whole body. */ 370 routines 'cause we can not simply fetch the whole body. */
371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
372{ 372{
373 if (!mailDescription) { 373 if (!mailDescription) {
374 return; 374 return;
375 } 375 }
376 QString sub,body_text; 376 QString sub,body_text;
377 RecPart singlePart; 377 RecPart singlePart;
378 QValueList<int> path; 378 QValueList<int> path;
379 fillSinglePart(singlePart,mailDescription); 379 fillSinglePart(singlePart,mailDescription);
380 switch (mailDescription->bd_type) { 380 switch (mailDescription->bd_type) {
381 case MAILIMAP_BODY_TYPE_1PART_MSG: 381 case MAILIMAP_BODY_TYPE_1PART_MSG:
382 path.append(1); 382 path.append(1);
383 body_text = fetchPart(mail,path,true); 383 body_text = fetchPart(mail,path,true);
384 target_body.setBodytext(body_text); 384 target_body.setBodytext(body_text);
385 target_body.setDescription(singlePart); 385 target_body.setDescription(singlePart);
386 break; 386 break;
387 case MAILIMAP_BODY_TYPE_1PART_TEXT: 387 case MAILIMAP_BODY_TYPE_1PART_TEXT:
388 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 388 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
389 path.append(1); 389 path.append(1);
390 body_text = fetchPart(mail,path,true); 390 body_text = fetchPart(mail,path,true);
391 target_body.setBodytext(body_text); 391 target_body.setBodytext(body_text);
392 target_body.setDescription(singlePart); 392 target_body.setDescription(singlePart);
393 break; 393 break;
394 case MAILIMAP_BODY_TYPE_1PART_BASIC: 394 case MAILIMAP_BODY_TYPE_1PART_BASIC:
395 qDebug("Single attachment"); 395 qDebug("Single attachment");
396 target_body.setBodytext(""); 396 target_body.setBodytext("");
397 target_body.addPart(singlePart); 397 target_body.addPart(singlePart);
398 break; 398 break;
399 default: 399 default:
400 break; 400 break;
401 } 401 }
402 402
403 return; 403 return;
404} 404}
405 405
406QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 406QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
407{ 407{
408 QStringList l; 408 QStringList l;
409 QString from; 409 QString from;
410 bool named_from; 410 bool named_from;
411 clistcell *current = NULL; 411 clistcell *current = NULL;
412 mailimap_address * current_address=NULL; 412 mailimap_address * current_address=NULL;
413 if (!list) { 413 if (!list) {
414 return l; 414 return l;
415 } 415 }
416 unsigned int count = 0; 416 unsigned int count = 0;
417 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 417 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
418 from = ""; 418 from = "";
419 named_from = false; 419 named_from = false;
420 current_address=(mailimap_address*)current->data; 420 current_address=(mailimap_address*)current->data;
421 if (current_address->ad_personal_name){ 421 if (current_address->ad_personal_name){
422 from+=QString(current_address->ad_personal_name); 422 from+=QString(current_address->ad_personal_name);
423 from+=" "; 423 from+=" ";
424 named_from = true; 424 named_from = true;
425 } 425 }
426 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 426 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
427 from+="<"; 427 from+="<";
428 } 428 }
429 if (current_address->ad_mailbox_name) { 429 if (current_address->ad_mailbox_name) {
430 from+=QString(current_address->ad_mailbox_name); 430 from+=QString(current_address->ad_mailbox_name);
431 from+="@"; 431 from+="@";
432 } 432 }
433 if (current_address->ad_host_name) { 433 if (current_address->ad_host_name) {
434 from+=QString(current_address->ad_host_name); 434 from+=QString(current_address->ad_host_name);
435 } 435 }
436 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 436 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
437 from+=">"; 437 from+=">";
438 } 438 }
439 l.append(QString(from)); 439 l.append(QString(from));
440 if (++count > 99) { 440 if (++count > 99) {
441 break; 441 break;
442 } 442 }
443 } 443 }
444 return l; 444 return l;
445} 445}
446 446
447QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 447QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
448{ 448{
449 QString body(""); 449 QString body("");
450 const char*mb; 450 const char*mb;
451 int err; 451 int err;
452 mailimap_fetch_type *fetchType; 452 mailimap_fetch_type *fetchType;
453 mailimap_set *set; 453 mailimap_set *set;
454 clistcell*current,*cur; 454 clistcell*current,*cur;
455 455
456 login(); 456 login();
457 if (!m_imap) { 457 if (!m_imap) {
458 return body; 458 return body;
459 } 459 }
460 if (!internal_call) { 460 if (!internal_call) {
461 mb = mail.getMbox().latin1(); 461 mb = mail.getMbox().latin1();
462 err = mailimap_select( m_imap, (char*)mb); 462 err = mailimap_select( m_imap, (char*)mb);
463 if ( err != MAILIMAP_NO_ERROR ) { 463 if ( err != MAILIMAP_NO_ERROR ) {
464 qDebug("error selecting mailbox: %s",m_imap->imap_response); 464 qDebug("error selecting mailbox: %s",m_imap->imap_response);
465 return body; 465 return body;
466 } 466 }
467 } 467 }
468 set = mailimap_set_new_single(mail.getNumber()); 468 set = mailimap_set_new_single(mail.getNumber());
469 clist*id_list=clist_new(); 469 clist*id_list=clist_new();
470 for (unsigned j=0; j < path.count();++j) { 470 for (unsigned j=0; j < path.count();++j) {
471 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 471 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
472 *p_id = path[j]; 472 *p_id = path[j];
473 clist_append(id_list,p_id); 473 clist_append(id_list,p_id);
474 } 474 }
475 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 475 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
476 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 476 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
477 mailimap_section * section = mailimap_section_new(section_spec); 477 mailimap_section * section = mailimap_section_new(section_spec);
478 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 478 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
479 479
480 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 480 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
481 481
482 clist*result = clist_new(); 482 clist*result = clist_new();
483 483
484 err = mailimap_fetch( m_imap, set, fetchType, &result ); 484 err = mailimap_fetch( m_imap, set, fetchType, &result );
485 mailimap_set_free( set ); 485 mailimap_set_free( set );
486 mailimap_fetch_type_free( fetchType ); 486 mailimap_fetch_type_free( fetchType );
487 487
488 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 488 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
489 mailimap_msg_att * msg_att; 489 mailimap_msg_att * msg_att;
490 msg_att = (mailimap_msg_att*)current->data; 490 msg_att = (mailimap_msg_att*)current->data;
491 mailimap_msg_att_item*msg_att_item; 491 mailimap_msg_att_item*msg_att_item;
492 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 492 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
493 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 493 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
494 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 494 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
495 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 495 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
496 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 496 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
497 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 497 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
498 if (text) { 498 if (text) {
499 body = QString(text); 499 body = QString(text);
500 free(text); 500 free(text);
501 } else { 501 } else {
502 body = ""; 502 body = "";
503 } 503 }
504 } 504 }
505 } 505 }
506 } 506 }
507 507
508 } else { 508 } else {
509 qDebug("error fetching text: %s",m_imap->imap_response); 509 qDebug("error fetching text: %s",m_imap->imap_response);
510 } 510 }
511 mailimap_fetch_list_free(result); 511 mailimap_fetch_list_free(result);
512 return body; 512 return body;
513} 513}
514 514
515void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 515void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
516{ 516{
517 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 517 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
518 if (!mailDescription||current_recursion==10) { 518 if (!mailDescription||current_recursion==10) {
519 return; 519 return;
520 } 520 }
521 clistcell*current; 521 clistcell*current;
522 mailimap_body*current_body; 522 mailimap_body*current_body;
523 unsigned int count = 0; 523 unsigned int count = 0;
524 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 524 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
525 /* the point in the message */ 525 /* the point in the message */
526 ++count; 526 ++count;
527 current_body = (mailimap_body*)current->data; 527 current_body = (mailimap_body*)current->data;
528 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 528 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
529 QValueList<int>clist = recList; 529 QValueList<int>clist = recList;
530 clist.append(count); 530 clist.append(count);
531 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 531 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
532 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 532 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
533 RecPart currentPart; 533 RecPart currentPart;
534 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 534 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
535 QValueList<int>clist = recList; 535 QValueList<int>clist = recList;
536 clist.append(count); 536 clist.append(count);
537 /* important: Check for is NULL 'cause a body can be empty! */ 537 /* important: Check for is NULL 'cause a body can be empty! */
538 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 538 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
539 QString body_text = fetchPart(mail,clist,true); 539 QString body_text = fetchPart(mail,clist,true);
540 target_body.setDescription(currentPart); 540 target_body.setDescription(currentPart);
541 target_body.setBodytext(body_text); 541 target_body.setBodytext(body_text);
542 } else { 542 } else {
543 QString id(""); 543 QString id("");
544 for (unsigned int j = 0; j < clist.count();++j) { 544 for (unsigned int j = 0; j < clist.count();++j) {
545 id+=(j>0?" ":""); 545 id+=(j>0?" ":"");
546 id+=QString("%1").arg(clist[j]); 546 id+=QString("%1").arg(clist[j]);
547 } 547 }
548 qDebug("ID= %s",id.latin1()); 548 qDebug("ID= %s",id.latin1());
549 currentPart.setIdentifier(id); 549 currentPart.setIdentifier(id);
550 currentPart.setPositionlist(clist); 550 currentPart.setPositionlist(clist);
551 target_body.addPart(currentPart); 551 target_body.addPart(currentPart);
552 } 552 }
553 } 553 }
554 } 554 }
555} 555}
556 556
557void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 557void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
558{ 558{
559 if (!Description) { 559 if (!Description) {
560 return; 560 return;
561 } 561 }
562 switch (Description->bd_type) { 562 switch (Description->bd_type) {
563 case MAILIMAP_BODY_TYPE_1PART_TEXT: 563 case MAILIMAP_BODY_TYPE_1PART_TEXT:
564 target_part.setType("text"); 564 target_part.setType("text");
565 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 565 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
566 break; 566 break;
567 case MAILIMAP_BODY_TYPE_1PART_BASIC: 567 case MAILIMAP_BODY_TYPE_1PART_BASIC:
568 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 568 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
569 break; 569 break;
570 case MAILIMAP_BODY_TYPE_1PART_MSG: 570 case MAILIMAP_BODY_TYPE_1PART_MSG:
571 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 571 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
572 break; 572 break;
573 default: 573 default:
574 break; 574 break;
575 } 575 }
576} 576}
577 577
578void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 578void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
579{ 579{
580 if (!which) { 580 if (!which) {
581 return; 581 return;
582 } 582 }
583 QString sub; 583 QString sub;
584 sub = which->bd_media_text; 584 sub = which->bd_media_text;
585 target_part.setSubtype(sub.lower()); 585 target_part.setSubtype(sub.lower());
586 target_part.setLines(which->bd_lines); 586 target_part.setLines(which->bd_lines);
587 fillBodyFields(target_part,which->bd_fields); 587 fillBodyFields(target_part,which->bd_fields);
588} 588}
589 589
590void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 590void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
591{ 591{
592 if (!which) { 592 if (!which) {
593 return; 593 return;
594 } 594 }
595// QString sub; 595// QString sub;
596// sub = which->bd_media_text; 596// sub = which->bd_media_text;
597// target_part.setSubtype(sub.lower()); 597// target_part.setSubtype(sub.lower());
598 qDebug("Message part"); 598 qDebug("Message part");
599 /* we set this type to text/plain */ 599 /* we set this type to text/plain */
600 target_part.setType("text"); 600 target_part.setType("text");
601 target_part.setSubtype("plain"); 601 target_part.setSubtype("plain");
602 target_part.setLines(which->bd_lines); 602 target_part.setLines(which->bd_lines);
603 fillBodyFields(target_part,which->bd_fields); 603 fillBodyFields(target_part,which->bd_fields);
604} 604}
605 605
606void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 606void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
607{ 607{
608 if (!which) { 608 if (!which) {
609 return; 609 return;
610 } 610 }
611 QString type,sub; 611 QString type,sub;
612 switch (which->bd_media_basic->med_type) { 612 switch (which->bd_media_basic->med_type) {
613 case MAILIMAP_MEDIA_BASIC_APPLICATION: 613 case MAILIMAP_MEDIA_BASIC_APPLICATION:
614 type = "application"; 614 type = "application";
615 break; 615 break;
616 case MAILIMAP_MEDIA_BASIC_AUDIO: 616 case MAILIMAP_MEDIA_BASIC_AUDIO:
617 type = "audio"; 617 type = "audio";
618 break; 618 break;
619 case MAILIMAP_MEDIA_BASIC_IMAGE: 619 case MAILIMAP_MEDIA_BASIC_IMAGE:
620 type = "image"; 620 type = "image";
621 break; 621 break;
622 case MAILIMAP_MEDIA_BASIC_MESSAGE: 622 case MAILIMAP_MEDIA_BASIC_MESSAGE:
623 type = "message"; 623 type = "message";
624 break; 624 break;
625 case MAILIMAP_MEDIA_BASIC_VIDEO: 625 case MAILIMAP_MEDIA_BASIC_VIDEO:
626 type = "video"; 626 type = "video";
627 break; 627 break;
628 case MAILIMAP_MEDIA_BASIC_OTHER: 628 case MAILIMAP_MEDIA_BASIC_OTHER:
629 default: 629 default:
630 if (which->bd_media_basic->med_basic_type) { 630 if (which->bd_media_basic->med_basic_type) {
631 type = which->bd_media_basic->med_basic_type; 631 type = which->bd_media_basic->med_basic_type;
632 } else { 632 } else {
633 type = ""; 633 type = "";
634 } 634 }
635 break; 635 break;
636 } 636 }
637 if (which->bd_media_basic->med_subtype) { 637 if (which->bd_media_basic->med_subtype) {
638 sub = which->bd_media_basic->med_subtype; 638 sub = which->bd_media_basic->med_subtype;
639 } else { 639 } else {
640 sub = ""; 640 sub = "";
641 } 641 }
642 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 642 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
643 target_part.setType(type.lower()); 643 target_part.setType(type.lower());
644 target_part.setSubtype(sub.lower()); 644 target_part.setSubtype(sub.lower());
645 fillBodyFields(target_part,which->bd_fields); 645 fillBodyFields(target_part,which->bd_fields);
646} 646}
647 647
648void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 648void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
649{ 649{
650 if (!which) return; 650 if (!which) return;
651 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 651 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
652 clistcell*cur; 652 clistcell*cur;
653 mailimap_single_body_fld_param*param=0; 653 mailimap_single_body_fld_param*param=0;
654 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 654 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
655 param = (mailimap_single_body_fld_param*)cur->data; 655 param = (mailimap_single_body_fld_param*)cur->data;
656 if (param) { 656 if (param) {
657 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 657 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
658 } 658 }
659 } 659 }
660 } 660 }
661 mailimap_body_fld_enc*enc = which->bd_encoding; 661 mailimap_body_fld_enc*enc = which->bd_encoding;
662 QString encoding(""); 662 QString encoding("");
663 switch (enc->enc_type) { 663 switch (enc->enc_type) {
664 case MAILIMAP_BODY_FLD_ENC_7BIT: 664 case MAILIMAP_BODY_FLD_ENC_7BIT:
665 encoding = "7bit"; 665 encoding = "7bit";
666 break; 666 break;
667 case MAILIMAP_BODY_FLD_ENC_8BIT: 667 case MAILIMAP_BODY_FLD_ENC_8BIT:
668 encoding = "8bit"; 668 encoding = "8bit";
669 break; 669 break;
670 case MAILIMAP_BODY_FLD_ENC_BINARY: 670 case MAILIMAP_BODY_FLD_ENC_BINARY:
671 encoding="binary"; 671 encoding="binary";
672 break; 672 break;
673 case MAILIMAP_BODY_FLD_ENC_BASE64: 673 case MAILIMAP_BODY_FLD_ENC_BASE64:
674 encoding="base64"; 674 encoding="base64";
675 break; 675 break;
676 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 676 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
677 encoding="quoted-printable"; 677 encoding="quoted-printable";
678 break; 678 break;
679 case MAILIMAP_BODY_FLD_ENC_OTHER: 679 case MAILIMAP_BODY_FLD_ENC_OTHER:
680 default: 680 default:
681 if (enc->enc_value) { 681 if (enc->enc_value) {
682 char*t=enc->enc_value; 682 char*t=enc->enc_value;
683 encoding=QString(enc->enc_value); 683 encoding=QString(enc->enc_value);
684 enc->enc_value=0L; 684 enc->enc_value=0L;
685 free(t); 685 free(t);
686 } 686 }
687 } 687 }
688 target_part.setEncoding(encoding); 688 target_part.setEncoding(encoding);
689 target_part.setSize(which->bd_size);
689} 690}
690 691
691QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 692QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
692{ 693{
693 return fetchPart(mail,part.Positionlist(),false); 694 return fetchPart(mail,part.Positionlist(),false);
694} 695}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 3941cec..11bf3b8 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,694 +1,695 @@
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{ 9{
10 account = a; 10 account = a;
11 m_imap = 0; 11 m_imap = 0;
12} 12}
13 13
14IMAPwrapper::~IMAPwrapper() 14IMAPwrapper::~IMAPwrapper()
15{ 15{
16 logout(); 16 logout();
17} 17}
18 18
19void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 19void IMAPwrapper::imap_progress( size_t current, size_t maximum )
20{ 20{
21 qDebug( "IMAP: %i of %i", current, maximum ); 21 qDebug( "IMAP: %i of %i", current, maximum );
22} 22}
23 23
24void IMAPwrapper::login() 24void IMAPwrapper::login()
25{ 25{
26 const char *server, *user, *pass; 26 const char *server, *user, *pass;
27 uint16_t port; 27 uint16_t port;
28 int err = MAILIMAP_NO_ERROR; 28 int err = MAILIMAP_NO_ERROR;
29 29
30 /* we are connected this moment */ 30 /* we are connected this moment */
31 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 31 /* TODO: setup a timer holding the line or if connection closed - delete the value */
32 if (m_imap) { 32 if (m_imap) {
33 return; 33 return;
34 } 34 }
35 server = account->getServer().latin1(); 35 server = account->getServer().latin1();
36 port = account->getPort().toUInt(); 36 port = account->getPort().toUInt();
37 user = account->getUser().latin1(); 37 user = account->getUser().latin1();
38 pass = account->getPassword().latin1(); 38 pass = account->getPassword().latin1();
39 39
40 m_imap = mailimap_new( 20, &imap_progress ); 40 m_imap = mailimap_new( 20, &imap_progress );
41 /* connect */ 41 /* connect */
42 if (account->getSSL()) { 42 if (account->getSSL()) {
43 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 43 err = mailimap_ssl_connect( m_imap, (char*)server, port );
44 } else { 44 } else {
45 err = mailimap_socket_connect( m_imap, (char*)server, port ); 45 err = mailimap_socket_connect( m_imap, (char*)server, port );
46 } 46 }
47 47
48 if ( err != MAILIMAP_NO_ERROR && 48 if ( err != MAILIMAP_NO_ERROR &&
49 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 49 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
50 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 50 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
51 qDebug("error connecting server: %s",m_imap->imap_response); 51 qDebug("error connecting server: %s",m_imap->imap_response);
52 mailimap_free( m_imap ); 52 mailimap_free( m_imap );
53 m_imap = 0; 53 m_imap = 0;
54 return; 54 return;
55 } 55 }
56 56
57 /* login */ 57 /* login */
58 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 58 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
59 if ( err != MAILIMAP_NO_ERROR ) { 59 if ( err != MAILIMAP_NO_ERROR ) {
60 qDebug("error logging in imap: %s",m_imap->imap_response); 60 qDebug("error logging in imap: %s",m_imap->imap_response);
61 err = mailimap_close( m_imap ); 61 err = mailimap_close( m_imap );
62 mailimap_free( m_imap ); 62 mailimap_free( m_imap );
63 m_imap = 0; 63 m_imap = 0;
64 } 64 }
65} 65}
66 66
67void IMAPwrapper::logout() 67void IMAPwrapper::logout()
68{ 68{
69 int err = MAILIMAP_NO_ERROR; 69 int err = MAILIMAP_NO_ERROR;
70 if (!m_imap) return; 70 if (!m_imap) return;
71 err = mailimap_logout( m_imap ); 71 err = mailimap_logout( m_imap );
72 err = mailimap_close( m_imap ); 72 err = mailimap_close( m_imap );
73 mailimap_free( m_imap ); 73 mailimap_free( m_imap );
74 m_imap = 0; 74 m_imap = 0;
75} 75}
76 76
77void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 77void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
78{ 78{
79 const char *mb; 79 const char *mb;
80 int err = MAILIMAP_NO_ERROR; 80 int err = MAILIMAP_NO_ERROR;
81 clist *result; 81 clist *result;
82 clistcell *current; 82 clistcell *current;
83// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 83// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
84 mailimap_fetch_type *fetchType; 84 mailimap_fetch_type *fetchType;
85 mailimap_set *set; 85 mailimap_set *set;
86 86
87 mb = mailbox.latin1(); 87 mb = mailbox.latin1();
88 login(); 88 login();
89 if (!m_imap) { 89 if (!m_imap) {
90 return; 90 return;
91 } 91 }
92 /* select mailbox READONLY for operations */ 92 /* select mailbox READONLY for operations */
93 err = mailimap_examine( m_imap, (char*)mb); 93 err = mailimap_examine( m_imap, (char*)mb);
94 if ( err != MAILIMAP_NO_ERROR ) { 94 if ( err != MAILIMAP_NO_ERROR ) {
95 qDebug("error selecting mailbox: %s",m_imap->imap_response); 95 qDebug("error selecting mailbox: %s",m_imap->imap_response);
96 return; 96 return;
97 } 97 }
98 98
99 int last = m_imap->imap_selection_info->sel_exists; 99 int last = m_imap->imap_selection_info->sel_exists;
100 100
101 if (last == 0) { 101 if (last == 0) {
102 qDebug("mailbox has no mails"); 102 qDebug("mailbox has no mails");
103 return; 103 return;
104 } 104 }
105 105
106 result = clist_new(); 106 result = clist_new();
107 /* the range has to start at 1!!! not with 0!!!! */ 107 /* the range has to start at 1!!! not with 0!!!! */
108 set = mailimap_set_new_interval( 1, last ); 108 set = mailimap_set_new_interval( 1, last );
109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
114 114
115 err = mailimap_fetch( m_imap, set, fetchType, &result ); 115 err = mailimap_fetch( m_imap, set, fetchType, &result );
116 mailimap_set_free( set ); 116 mailimap_set_free( set );
117 mailimap_fetch_type_free( fetchType ); 117 mailimap_fetch_type_free( fetchType );
118 118
119 QString date,subject,from; 119 QString date,subject,from;
120 120
121 if ( err == MAILIMAP_NO_ERROR ) { 121 if ( err == MAILIMAP_NO_ERROR ) {
122 122
123 mailimap_msg_att * msg_att; 123 mailimap_msg_att * msg_att;
124 int i = 0; 124 int i = 0;
125 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 125 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
126 ++i; 126 ++i;
127 msg_att = (mailimap_msg_att*)current->data; 127 msg_att = (mailimap_msg_att*)current->data;
128 RecMail*m = parse_list_result(msg_att); 128 RecMail*m = parse_list_result(msg_att);
129 if (m) { 129 if (m) {
130 m->setNumber(i); 130 m->setNumber(i);
131 m->setMbox(mailbox); 131 m->setMbox(mailbox);
132 target.append(m); 132 target.append(m);
133 } 133 }
134 } 134 }
135 } else { 135 } else {
136 qDebug("Error fetching headers: %s",m_imap->imap_response); 136 qDebug("Error fetching headers: %s",m_imap->imap_response);
137 } 137 }
138 mailimap_fetch_list_free(result); 138 mailimap_fetch_list_free(result);
139} 139}
140 140
141QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 142{
143 const char *path, *mask; 143 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
145 clist *result; 145 clist *result;
146 clistcell *current; 146 clistcell *current;
147 147
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
150 login(); 150 login();
151 if (!m_imap) { 151 if (!m_imap) {
152 return folders; 152 return folders;
153 } 153 }
154 154
155/* 155/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
157 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
158 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 159 */
160 QString temp; 160 QString temp;
161 mask = "INBOX" ; 161 mask = "INBOX" ;
162 result = clist_new(); 162 result = clist_new();
163 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 166 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 170 // instead of using strdup!
171 temp = list->mb_name; 171 temp = list->mb_name;
172 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
173 current = current->next; 173 current = current->next;
174 } 174 }
175 } else { 175 } else {
176 qDebug("error fetching folders: %s",m_imap->imap_response); 176 qDebug("error fetching folders: %s",m_imap->imap_response);
177 } 177 }
178 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
179 179
180/* 180/*
181 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
182 */ 182 */
183 mask = "*" ; 183 mask = "*" ;
184 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
185 if (!path) path = ""; 185 if (!path) path = "";
186 result = clist_new(); 186 result = clist_new();
187 qDebug(path); 187 qDebug(path);
188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
189 if ( err == MAILIMAP_NO_ERROR ) { 189 if ( err == MAILIMAP_NO_ERROR ) {
190 current = result->first; 190 current = result->first;
191 for ( int i = result->count; i > 0; i-- ) { 191 for ( int i = result->count; i > 0; i-- ) {
192 list = (mailimap_mailbox_list *) current->data; 192 list = (mailimap_mailbox_list *) current->data;
193 // it is better use the deep copy mechanism of qt itself 193 // it is better use the deep copy mechanism of qt itself
194 // instead of using strdup! 194 // instead of using strdup!
195 temp = list->mb_name; 195 temp = list->mb_name;
196 current = current->next; 196 current = current->next;
197 if (temp.lower()=="inbox") 197 if (temp.lower()=="inbox")
198 continue; 198 continue;
199 folders->append(new IMAPFolder(temp)); 199 folders->append(new IMAPFolder(temp));
200 200
201 } 201 }
202 } else { 202 } else {
203 qDebug("error fetching folders %s",m_imap->imap_response); 203 qDebug("error fetching folders %s",m_imap->imap_response);
204 } 204 }
205 mailimap_list_result_free( result ); 205 mailimap_list_result_free( result );
206 return folders; 206 return folders;
207} 207}
208 208
209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
210{ 210{
211 RecMail * m = 0; 211 RecMail * m = 0;
212 mailimap_msg_att_item *item=0; 212 mailimap_msg_att_item *item=0;
213 clistcell *current,*c,*cf; 213 clistcell *current,*c,*cf;
214 mailimap_msg_att_dynamic*flist; 214 mailimap_msg_att_dynamic*flist;
215 mailimap_flag_fetch*cflag; 215 mailimap_flag_fetch*cflag;
216 int size; 216 int size;
217 QBitArray mFlags(7); 217 QBitArray mFlags(7);
218 QStringList addresslist; 218 QStringList addresslist;
219 219
220 if (!m_att) { 220 if (!m_att) {
221 return m; 221 return m;
222 } 222 }
223 m = new RecMail(); 223 m = new RecMail();
224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
225 current = c; 225 current = c;
226 size = 0; 226 size = 0;
227 item = (mailimap_msg_att_item*)current->data; 227 item = (mailimap_msg_att_item*)current->data;
228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
230 if (!flist->att_list) { 230 if (!flist->att_list) {
231 continue; 231 continue;
232 } 232 }
233 cf = flist->att_list->first; 233 cf = flist->att_list->first;
234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
235 cflag = (mailimap_flag_fetch*)cf->data; 235 cflag = (mailimap_flag_fetch*)cf->data;
236 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 236 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
237 switch (cflag->fl_flag->fl_type) { 237 switch (cflag->fl_flag->fl_type) {
238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
239 mFlags.setBit(FLAG_ANSWERED); 239 mFlags.setBit(FLAG_ANSWERED);
240 break; 240 break;
241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
242 mFlags.setBit(FLAG_FLAGGED); 242 mFlags.setBit(FLAG_FLAGGED);
243 break; 243 break;
244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
245 mFlags.setBit(FLAG_DELETED); 245 mFlags.setBit(FLAG_DELETED);
246 break; 246 break;
247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
248 mFlags.setBit(FLAG_SEEN); 248 mFlags.setBit(FLAG_SEEN);
249 break; 249 break;
250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
251 mFlags.setBit(FLAG_DRAFT); 251 mFlags.setBit(FLAG_DRAFT);
252 break; 252 break;
253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
254 break; 254 break;
255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
256 break; 256 break;
257 default: 257 default:
258 break; 258 break;
259 } 259 }
260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
261 mFlags.setBit(FLAG_RECENT); 261 mFlags.setBit(FLAG_RECENT);
262 } 262 }
263 } 263 }
264 continue; 264 continue;
265 } 265 }
266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
267 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 267 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
268 m->setDate(head->env_date); 268 m->setDate(head->env_date);
269 m->setSubject(head->env_subject); 269 m->setSubject(head->env_subject);
270 if (head->env_from!=NULL) { 270 if (head->env_from!=NULL) {
271 addresslist = address_list_to_stringlist(head->env_from->frm_list); 271 addresslist = address_list_to_stringlist(head->env_from->frm_list);
272 if (addresslist.count()) { 272 if (addresslist.count()) {
273 m->setFrom(addresslist.first()); 273 m->setFrom(addresslist.first());
274 } 274 }
275 } 275 }
276 if (head->env_to!=NULL) { 276 if (head->env_to!=NULL) {
277 addresslist = address_list_to_stringlist(head->env_to->to_list); 277 addresslist = address_list_to_stringlist(head->env_to->to_list);
278 m->setTo(addresslist); 278 m->setTo(addresslist);
279 } 279 }
280 if (head->env_cc!=NULL) { 280 if (head->env_cc!=NULL) {
281 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 281 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
282 m->setCC(addresslist); 282 m->setCC(addresslist);
283 } 283 }
284 if (head->env_bcc!=NULL) { 284 if (head->env_bcc!=NULL) {
285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
286 m->setBcc(addresslist); 286 m->setBcc(addresslist);
287 } 287 }
288 if (head->env_reply_to!=NULL) { 288 if (head->env_reply_to!=NULL) {
289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
290 if (addresslist.count()) { 290 if (addresslist.count()) {
291 m->setReplyto(addresslist.first()); 291 m->setReplyto(addresslist.first());
292 } 292 }
293 } 293 }
294 m->setMsgid(QString(head->env_message_id)); 294 m->setMsgid(QString(head->env_message_id));
295 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 295 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
296 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 296 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
297 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 297 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
298 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); 298 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);
299 qDebug(da.toString()); 299 qDebug(da.toString());
300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
301 size = item->att_data.att_static->att_data.att_rfc822_size; 301 size = item->att_data.att_static->att_data.att_rfc822_size;
302 } 302 }
303 } 303 }
304 /* msg is already deleted */ 304 /* msg is already deleted */
305 if (mFlags.testBit(FLAG_DELETED) && m) { 305 if (mFlags.testBit(FLAG_DELETED) && m) {
306 delete m; 306 delete m;
307 m = 0; 307 m = 0;
308 } 308 }
309 if (m) { 309 if (m) {
310 m->setFlags(mFlags); 310 m->setFlags(mFlags);
311 m->setMsgsize(size); 311 m->setMsgsize(size);
312 } 312 }
313 return m; 313 return m;
314} 314}
315 315
316RecBody IMAPwrapper::fetchBody(const RecMail&mail) 316RecBody IMAPwrapper::fetchBody(const RecMail&mail)
317{ 317{
318 RecBody body; 318 RecBody body;
319 const char *mb; 319 const char *mb;
320 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
321 clist *result; 321 clist *result;
322 clistcell *current; 322 clistcell *current;
323 mailimap_fetch_att *fetchAtt; 323 mailimap_fetch_att *fetchAtt;
324 mailimap_fetch_type *fetchType; 324 mailimap_fetch_type *fetchType;
325 mailimap_set *set; 325 mailimap_set *set;
326 mailimap_body*body_desc; 326 mailimap_body*body_desc;
327 327
328 mb = mail.getMbox().latin1(); 328 mb = mail.getMbox().latin1();
329 329
330 login(); 330 login();
331 if (!m_imap) { 331 if (!m_imap) {
332 return body; 332 return body;
333 } 333 }
334 334
335 err = mailimap_select( m_imap, (char*)mb); 335 err = mailimap_select( m_imap, (char*)mb);
336 if ( err != MAILIMAP_NO_ERROR ) { 336 if ( err != MAILIMAP_NO_ERROR ) {
337 qDebug("error selecting mailbox: %s",m_imap->imap_response); 337 qDebug("error selecting mailbox: %s",m_imap->imap_response);
338 return body; 338 return body;
339 } 339 }
340 340
341 result = clist_new(); 341 result = clist_new();
342 /* the range has to start at 1!!! not with 0!!!! */ 342 /* the range has to start at 1!!! not with 0!!!! */
343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
344 fetchAtt = mailimap_fetch_att_new_bodystructure(); 344 fetchAtt = mailimap_fetch_att_new_bodystructure();
345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
346 err = mailimap_fetch( m_imap, set, fetchType, &result ); 346 err = mailimap_fetch( m_imap, set, fetchType, &result );
347 mailimap_set_free( set ); 347 mailimap_set_free( set );
348 mailimap_fetch_type_free( fetchType ); 348 mailimap_fetch_type_free( fetchType );
349 349
350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
351 mailimap_msg_att * msg_att; 351 mailimap_msg_att * msg_att;
352 msg_att = (mailimap_msg_att*)current->data; 352 msg_att = (mailimap_msg_att*)current->data;
353 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 353 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
354 body_desc = item->att_data.att_static->att_data.att_body; 354 body_desc = item->att_data.att_static->att_data.att_body;
355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
358 qDebug("Mulitpart mail"); 358 qDebug("Mulitpart mail");
359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
360 } 360 }
361 } else { 361 } else {
362 qDebug("error fetching body: %s",m_imap->imap_response); 362 qDebug("error fetching body: %s",m_imap->imap_response);
363 } 363 }
364 mailimap_fetch_list_free(result); 364 mailimap_fetch_list_free(result);
365 return body; 365 return body;
366} 366}
367 367
368/* this routine is just called when the mail has only ONE part. 368/* this routine is just called when the mail has only ONE part.
369 for filling the parts of a multi-part-message there are other 369 for filling the parts of a multi-part-message there are other
370 routines 'cause we can not simply fetch the whole body. */ 370 routines 'cause we can not simply fetch the whole body. */
371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
372{ 372{
373 if (!mailDescription) { 373 if (!mailDescription) {
374 return; 374 return;
375 } 375 }
376 QString sub,body_text; 376 QString sub,body_text;
377 RecPart singlePart; 377 RecPart singlePart;
378 QValueList<int> path; 378 QValueList<int> path;
379 fillSinglePart(singlePart,mailDescription); 379 fillSinglePart(singlePart,mailDescription);
380 switch (mailDescription->bd_type) { 380 switch (mailDescription->bd_type) {
381 case MAILIMAP_BODY_TYPE_1PART_MSG: 381 case MAILIMAP_BODY_TYPE_1PART_MSG:
382 path.append(1); 382 path.append(1);
383 body_text = fetchPart(mail,path,true); 383 body_text = fetchPart(mail,path,true);
384 target_body.setBodytext(body_text); 384 target_body.setBodytext(body_text);
385 target_body.setDescription(singlePart); 385 target_body.setDescription(singlePart);
386 break; 386 break;
387 case MAILIMAP_BODY_TYPE_1PART_TEXT: 387 case MAILIMAP_BODY_TYPE_1PART_TEXT:
388 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 388 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
389 path.append(1); 389 path.append(1);
390 body_text = fetchPart(mail,path,true); 390 body_text = fetchPart(mail,path,true);
391 target_body.setBodytext(body_text); 391 target_body.setBodytext(body_text);
392 target_body.setDescription(singlePart); 392 target_body.setDescription(singlePart);
393 break; 393 break;
394 case MAILIMAP_BODY_TYPE_1PART_BASIC: 394 case MAILIMAP_BODY_TYPE_1PART_BASIC:
395 qDebug("Single attachment"); 395 qDebug("Single attachment");
396 target_body.setBodytext(""); 396 target_body.setBodytext("");
397 target_body.addPart(singlePart); 397 target_body.addPart(singlePart);
398 break; 398 break;
399 default: 399 default:
400 break; 400 break;
401 } 401 }
402 402
403 return; 403 return;
404} 404}
405 405
406QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 406QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
407{ 407{
408 QStringList l; 408 QStringList l;
409 QString from; 409 QString from;
410 bool named_from; 410 bool named_from;
411 clistcell *current = NULL; 411 clistcell *current = NULL;
412 mailimap_address * current_address=NULL; 412 mailimap_address * current_address=NULL;
413 if (!list) { 413 if (!list) {
414 return l; 414 return l;
415 } 415 }
416 unsigned int count = 0; 416 unsigned int count = 0;
417 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 417 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
418 from = ""; 418 from = "";
419 named_from = false; 419 named_from = false;
420 current_address=(mailimap_address*)current->data; 420 current_address=(mailimap_address*)current->data;
421 if (current_address->ad_personal_name){ 421 if (current_address->ad_personal_name){
422 from+=QString(current_address->ad_personal_name); 422 from+=QString(current_address->ad_personal_name);
423 from+=" "; 423 from+=" ";
424 named_from = true; 424 named_from = true;
425 } 425 }
426 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 426 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
427 from+="<"; 427 from+="<";
428 } 428 }
429 if (current_address->ad_mailbox_name) { 429 if (current_address->ad_mailbox_name) {
430 from+=QString(current_address->ad_mailbox_name); 430 from+=QString(current_address->ad_mailbox_name);
431 from+="@"; 431 from+="@";
432 } 432 }
433 if (current_address->ad_host_name) { 433 if (current_address->ad_host_name) {
434 from+=QString(current_address->ad_host_name); 434 from+=QString(current_address->ad_host_name);
435 } 435 }
436 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 436 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
437 from+=">"; 437 from+=">";
438 } 438 }
439 l.append(QString(from)); 439 l.append(QString(from));
440 if (++count > 99) { 440 if (++count > 99) {
441 break; 441 break;
442 } 442 }
443 } 443 }
444 return l; 444 return l;
445} 445}
446 446
447QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 447QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
448{ 448{
449 QString body(""); 449 QString body("");
450 const char*mb; 450 const char*mb;
451 int err; 451 int err;
452 mailimap_fetch_type *fetchType; 452 mailimap_fetch_type *fetchType;
453 mailimap_set *set; 453 mailimap_set *set;
454 clistcell*current,*cur; 454 clistcell*current,*cur;
455 455
456 login(); 456 login();
457 if (!m_imap) { 457 if (!m_imap) {
458 return body; 458 return body;
459 } 459 }
460 if (!internal_call) { 460 if (!internal_call) {
461 mb = mail.getMbox().latin1(); 461 mb = mail.getMbox().latin1();
462 err = mailimap_select( m_imap, (char*)mb); 462 err = mailimap_select( m_imap, (char*)mb);
463 if ( err != MAILIMAP_NO_ERROR ) { 463 if ( err != MAILIMAP_NO_ERROR ) {
464 qDebug("error selecting mailbox: %s",m_imap->imap_response); 464 qDebug("error selecting mailbox: %s",m_imap->imap_response);
465 return body; 465 return body;
466 } 466 }
467 } 467 }
468 set = mailimap_set_new_single(mail.getNumber()); 468 set = mailimap_set_new_single(mail.getNumber());
469 clist*id_list=clist_new(); 469 clist*id_list=clist_new();
470 for (unsigned j=0; j < path.count();++j) { 470 for (unsigned j=0; j < path.count();++j) {
471 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 471 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
472 *p_id = path[j]; 472 *p_id = path[j];
473 clist_append(id_list,p_id); 473 clist_append(id_list,p_id);
474 } 474 }
475 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 475 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
476 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 476 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
477 mailimap_section * section = mailimap_section_new(section_spec); 477 mailimap_section * section = mailimap_section_new(section_spec);
478 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 478 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
479 479
480 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 480 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
481 481
482 clist*result = clist_new(); 482 clist*result = clist_new();
483 483
484 err = mailimap_fetch( m_imap, set, fetchType, &result ); 484 err = mailimap_fetch( m_imap, set, fetchType, &result );
485 mailimap_set_free( set ); 485 mailimap_set_free( set );
486 mailimap_fetch_type_free( fetchType ); 486 mailimap_fetch_type_free( fetchType );
487 487
488 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 488 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
489 mailimap_msg_att * msg_att; 489 mailimap_msg_att * msg_att;
490 msg_att = (mailimap_msg_att*)current->data; 490 msg_att = (mailimap_msg_att*)current->data;
491 mailimap_msg_att_item*msg_att_item; 491 mailimap_msg_att_item*msg_att_item;
492 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 492 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
493 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 493 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
494 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 494 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
495 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 495 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
496 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 496 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
497 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 497 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
498 if (text) { 498 if (text) {
499 body = QString(text); 499 body = QString(text);
500 free(text); 500 free(text);
501 } else { 501 } else {
502 body = ""; 502 body = "";
503 } 503 }
504 } 504 }
505 } 505 }
506 } 506 }
507 507
508 } else { 508 } else {
509 qDebug("error fetching text: %s",m_imap->imap_response); 509 qDebug("error fetching text: %s",m_imap->imap_response);
510 } 510 }
511 mailimap_fetch_list_free(result); 511 mailimap_fetch_list_free(result);
512 return body; 512 return body;
513} 513}
514 514
515void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 515void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
516{ 516{
517 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 517 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
518 if (!mailDescription||current_recursion==10) { 518 if (!mailDescription||current_recursion==10) {
519 return; 519 return;
520 } 520 }
521 clistcell*current; 521 clistcell*current;
522 mailimap_body*current_body; 522 mailimap_body*current_body;
523 unsigned int count = 0; 523 unsigned int count = 0;
524 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 524 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
525 /* the point in the message */ 525 /* the point in the message */
526 ++count; 526 ++count;
527 current_body = (mailimap_body*)current->data; 527 current_body = (mailimap_body*)current->data;
528 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 528 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
529 QValueList<int>clist = recList; 529 QValueList<int>clist = recList;
530 clist.append(count); 530 clist.append(count);
531 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 531 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
532 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 532 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
533 RecPart currentPart; 533 RecPart currentPart;
534 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 534 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
535 QValueList<int>clist = recList; 535 QValueList<int>clist = recList;
536 clist.append(count); 536 clist.append(count);
537 /* important: Check for is NULL 'cause a body can be empty! */ 537 /* important: Check for is NULL 'cause a body can be empty! */
538 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 538 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
539 QString body_text = fetchPart(mail,clist,true); 539 QString body_text = fetchPart(mail,clist,true);
540 target_body.setDescription(currentPart); 540 target_body.setDescription(currentPart);
541 target_body.setBodytext(body_text); 541 target_body.setBodytext(body_text);
542 } else { 542 } else {
543 QString id(""); 543 QString id("");
544 for (unsigned int j = 0; j < clist.count();++j) { 544 for (unsigned int j = 0; j < clist.count();++j) {
545 id+=(j>0?" ":""); 545 id+=(j>0?" ":"");
546 id+=QString("%1").arg(clist[j]); 546 id+=QString("%1").arg(clist[j]);
547 } 547 }
548 qDebug("ID= %s",id.latin1()); 548 qDebug("ID= %s",id.latin1());
549 currentPart.setIdentifier(id); 549 currentPart.setIdentifier(id);
550 currentPart.setPositionlist(clist); 550 currentPart.setPositionlist(clist);
551 target_body.addPart(currentPart); 551 target_body.addPart(currentPart);
552 } 552 }
553 } 553 }
554 } 554 }
555} 555}
556 556
557void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 557void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
558{ 558{
559 if (!Description) { 559 if (!Description) {
560 return; 560 return;
561 } 561 }
562 switch (Description->bd_type) { 562 switch (Description->bd_type) {
563 case MAILIMAP_BODY_TYPE_1PART_TEXT: 563 case MAILIMAP_BODY_TYPE_1PART_TEXT:
564 target_part.setType("text"); 564 target_part.setType("text");
565 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 565 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
566 break; 566 break;
567 case MAILIMAP_BODY_TYPE_1PART_BASIC: 567 case MAILIMAP_BODY_TYPE_1PART_BASIC:
568 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 568 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
569 break; 569 break;
570 case MAILIMAP_BODY_TYPE_1PART_MSG: 570 case MAILIMAP_BODY_TYPE_1PART_MSG:
571 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 571 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
572 break; 572 break;
573 default: 573 default:
574 break; 574 break;
575 } 575 }
576} 576}
577 577
578void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 578void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
579{ 579{
580 if (!which) { 580 if (!which) {
581 return; 581 return;
582 } 582 }
583 QString sub; 583 QString sub;
584 sub = which->bd_media_text; 584 sub = which->bd_media_text;
585 target_part.setSubtype(sub.lower()); 585 target_part.setSubtype(sub.lower());
586 target_part.setLines(which->bd_lines); 586 target_part.setLines(which->bd_lines);
587 fillBodyFields(target_part,which->bd_fields); 587 fillBodyFields(target_part,which->bd_fields);
588} 588}
589 589
590void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 590void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
591{ 591{
592 if (!which) { 592 if (!which) {
593 return; 593 return;
594 } 594 }
595// QString sub; 595// QString sub;
596// sub = which->bd_media_text; 596// sub = which->bd_media_text;
597// target_part.setSubtype(sub.lower()); 597// target_part.setSubtype(sub.lower());
598 qDebug("Message part"); 598 qDebug("Message part");
599 /* we set this type to text/plain */ 599 /* we set this type to text/plain */
600 target_part.setType("text"); 600 target_part.setType("text");
601 target_part.setSubtype("plain"); 601 target_part.setSubtype("plain");
602 target_part.setLines(which->bd_lines); 602 target_part.setLines(which->bd_lines);
603 fillBodyFields(target_part,which->bd_fields); 603 fillBodyFields(target_part,which->bd_fields);
604} 604}
605 605
606void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 606void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
607{ 607{
608 if (!which) { 608 if (!which) {
609 return; 609 return;
610 } 610 }
611 QString type,sub; 611 QString type,sub;
612 switch (which->bd_media_basic->med_type) { 612 switch (which->bd_media_basic->med_type) {
613 case MAILIMAP_MEDIA_BASIC_APPLICATION: 613 case MAILIMAP_MEDIA_BASIC_APPLICATION:
614 type = "application"; 614 type = "application";
615 break; 615 break;
616 case MAILIMAP_MEDIA_BASIC_AUDIO: 616 case MAILIMAP_MEDIA_BASIC_AUDIO:
617 type = "audio"; 617 type = "audio";
618 break; 618 break;
619 case MAILIMAP_MEDIA_BASIC_IMAGE: 619 case MAILIMAP_MEDIA_BASIC_IMAGE:
620 type = "image"; 620 type = "image";
621 break; 621 break;
622 case MAILIMAP_MEDIA_BASIC_MESSAGE: 622 case MAILIMAP_MEDIA_BASIC_MESSAGE:
623 type = "message"; 623 type = "message";
624 break; 624 break;
625 case MAILIMAP_MEDIA_BASIC_VIDEO: 625 case MAILIMAP_MEDIA_BASIC_VIDEO:
626 type = "video"; 626 type = "video";
627 break; 627 break;
628 case MAILIMAP_MEDIA_BASIC_OTHER: 628 case MAILIMAP_MEDIA_BASIC_OTHER:
629 default: 629 default:
630 if (which->bd_media_basic->med_basic_type) { 630 if (which->bd_media_basic->med_basic_type) {
631 type = which->bd_media_basic->med_basic_type; 631 type = which->bd_media_basic->med_basic_type;
632 } else { 632 } else {
633 type = ""; 633 type = "";
634 } 634 }
635 break; 635 break;
636 } 636 }
637 if (which->bd_media_basic->med_subtype) { 637 if (which->bd_media_basic->med_subtype) {
638 sub = which->bd_media_basic->med_subtype; 638 sub = which->bd_media_basic->med_subtype;
639 } else { 639 } else {
640 sub = ""; 640 sub = "";
641 } 641 }
642 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 642 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
643 target_part.setType(type.lower()); 643 target_part.setType(type.lower());
644 target_part.setSubtype(sub.lower()); 644 target_part.setSubtype(sub.lower());
645 fillBodyFields(target_part,which->bd_fields); 645 fillBodyFields(target_part,which->bd_fields);
646} 646}
647 647
648void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 648void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
649{ 649{
650 if (!which) return; 650 if (!which) return;
651 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 651 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
652 clistcell*cur; 652 clistcell*cur;
653 mailimap_single_body_fld_param*param=0; 653 mailimap_single_body_fld_param*param=0;
654 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 654 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
655 param = (mailimap_single_body_fld_param*)cur->data; 655 param = (mailimap_single_body_fld_param*)cur->data;
656 if (param) { 656 if (param) {
657 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 657 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
658 } 658 }
659 } 659 }
660 } 660 }
661 mailimap_body_fld_enc*enc = which->bd_encoding; 661 mailimap_body_fld_enc*enc = which->bd_encoding;
662 QString encoding(""); 662 QString encoding("");
663 switch (enc->enc_type) { 663 switch (enc->enc_type) {
664 case MAILIMAP_BODY_FLD_ENC_7BIT: 664 case MAILIMAP_BODY_FLD_ENC_7BIT:
665 encoding = "7bit"; 665 encoding = "7bit";
666 break; 666 break;
667 case MAILIMAP_BODY_FLD_ENC_8BIT: 667 case MAILIMAP_BODY_FLD_ENC_8BIT:
668 encoding = "8bit"; 668 encoding = "8bit";
669 break; 669 break;
670 case MAILIMAP_BODY_FLD_ENC_BINARY: 670 case MAILIMAP_BODY_FLD_ENC_BINARY:
671 encoding="binary"; 671 encoding="binary";
672 break; 672 break;
673 case MAILIMAP_BODY_FLD_ENC_BASE64: 673 case MAILIMAP_BODY_FLD_ENC_BASE64:
674 encoding="base64"; 674 encoding="base64";
675 break; 675 break;
676 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 676 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
677 encoding="quoted-printable"; 677 encoding="quoted-printable";
678 break; 678 break;
679 case MAILIMAP_BODY_FLD_ENC_OTHER: 679 case MAILIMAP_BODY_FLD_ENC_OTHER:
680 default: 680 default:
681 if (enc->enc_value) { 681 if (enc->enc_value) {
682 char*t=enc->enc_value; 682 char*t=enc->enc_value;
683 encoding=QString(enc->enc_value); 683 encoding=QString(enc->enc_value);
684 enc->enc_value=0L; 684 enc->enc_value=0L;
685 free(t); 685 free(t);
686 } 686 }
687 } 687 }
688 target_part.setEncoding(encoding); 688 target_part.setEncoding(encoding);
689 target_part.setSize(which->bd_size);
689} 690}
690 691
691QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 692QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
692{ 693{
693 return fetchPart(mail,part.Positionlist(),false); 694 return fetchPart(mail,part.Positionlist(),false);
694} 695}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 9c312e9..5cd45ed 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,210 +1,220 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
15 qDebug("Copy constructor RecMail"); 15 qDebug("Copy constructor RecMail");
16} 16}
17 17
18void RecMail::copy_old(const RecMail&old) 18void RecMail::copy_old(const RecMail&old)
19{ 19{
20 subject = old.subject; 20 subject = old.subject;
21 date = old.date; 21 date = old.date;
22 mbox = old.mbox; 22 mbox = old.mbox;
23 msg_id = old.msg_id; 23 msg_id = old.msg_id;
24 msg_size = old.msg_size; 24 msg_size = old.msg_size;
25 msg_number = old.msg_number; 25 msg_number = old.msg_number;
26 from = old.from; 26 from = old.from;
27 msg_flags = old.msg_flags; 27 msg_flags = old.msg_flags;
28 to = old.to; 28 to = old.to;
29 cc = old.cc; 29 cc = old.cc;
30 bcc = old.bcc; 30 bcc = old.bcc;
31} 31}
32 32
33void RecMail::init() 33void RecMail::init()
34{ 34{
35 to.clear(); 35 to.clear();
36 cc.clear(); 36 cc.clear();
37 bcc.clear(); 37 bcc.clear();
38} 38}
39 39
40void RecMail::setTo(const QStringList&list) 40void RecMail::setTo(const QStringList&list)
41{ 41{
42 to = list; 42 to = list;
43} 43}
44 44
45const QStringList&RecMail::To()const 45const QStringList&RecMail::To()const
46{ 46{
47 return to; 47 return to;
48} 48}
49 49
50void RecMail::setCC(const QStringList&list) 50void RecMail::setCC(const QStringList&list)
51{ 51{
52 cc = list; 52 cc = list;
53} 53}
54 54
55const QStringList&RecMail::CC()const 55const QStringList&RecMail::CC()const
56{ 56{
57 return cc; 57 return cc;
58} 58}
59 59
60void RecMail::setBcc(const QStringList&list) 60void RecMail::setBcc(const QStringList&list)
61{ 61{
62 bcc = list; 62 bcc = list;
63} 63}
64 64
65const QStringList& RecMail::Bcc()const 65const QStringList& RecMail::Bcc()const
66{ 66{
67 return bcc; 67 return bcc;
68} 68}
69 69
70RecPart::RecPart() 70RecPart::RecPart()
71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0) 71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0)
72{ 72{
73 m_Parameters.clear(); 73 m_Parameters.clear();
74 m_poslist.clear(); 74 m_poslist.clear();
75} 75}
76 76
77RecPart::~RecPart() 77RecPart::~RecPart()
78{ 78{
79} 79}
80 80
81void RecPart::setSize(unsigned int size)
82{
83 m_size = size;
84}
85
86const unsigned int RecPart::Size()const
87{
88 return m_size;
89}
90
81void RecPart::setLines(unsigned int lines) 91void RecPart::setLines(unsigned int lines)
82{ 92{
83 m_lines = lines; 93 m_lines = lines;
84} 94}
85 95
86const unsigned int RecPart::Lines()const 96const unsigned int RecPart::Lines()const
87{ 97{
88 return m_lines; 98 return m_lines;
89} 99}
90 100
91const QString& RecPart::Type()const 101const QString& RecPart::Type()const
92{ 102{
93 return m_type; 103 return m_type;
94} 104}
95 105
96void RecPart::setType(const QString&type) 106void RecPart::setType(const QString&type)
97{ 107{
98 m_type = type; 108 m_type = type;
99} 109}
100 110
101const QString& RecPart::Subtype()const 111const QString& RecPart::Subtype()const
102{ 112{
103 return m_subtype; 113 return m_subtype;
104} 114}
105 115
106void RecPart::setSubtype(const QString&subtype) 116void RecPart::setSubtype(const QString&subtype)
107{ 117{
108 m_subtype = subtype; 118 m_subtype = subtype;
109} 119}
110 120
111const QString& RecPart::Identifier()const 121const QString& RecPart::Identifier()const
112{ 122{
113 return m_identifier; 123 return m_identifier;
114} 124}
115 125
116void RecPart::setIdentifier(const QString&identifier) 126void RecPart::setIdentifier(const QString&identifier)
117{ 127{
118 m_identifier = identifier; 128 m_identifier = identifier;
119} 129}
120 130
121const QString& RecPart::Encoding()const 131const QString& RecPart::Encoding()const
122{ 132{
123 return m_encoding; 133 return m_encoding;
124} 134}
125 135
126void RecPart::setEncoding(const QString&encoding) 136void RecPart::setEncoding(const QString&encoding)
127{ 137{
128 m_encoding = encoding; 138 m_encoding = encoding;
129} 139}
130 140
131void RecPart::setParameters(const part_plist_t&list) 141void RecPart::setParameters(const part_plist_t&list)
132{ 142{
133 m_Parameters = list; 143 m_Parameters = list;
134} 144}
135 145
136const part_plist_t& RecPart::Parameters()const 146const part_plist_t& RecPart::Parameters()const
137{ 147{
138 return m_Parameters; 148 return m_Parameters;
139} 149}
140 150
141void RecPart::addParameter(const QString&key,const QString&value) 151void RecPart::addParameter(const QString&key,const QString&value)
142{ 152{
143 m_Parameters[key]=value; 153 m_Parameters[key]=value;
144} 154}
145 155
146const QString RecPart::searchParamter(const QString&key)const 156const QString RecPart::searchParamter(const QString&key)const
147{ 157{
148 QString value(""); 158 QString value("");
149 part_plist_t::ConstIterator it = m_Parameters.find(key); 159 part_plist_t::ConstIterator it = m_Parameters.find(key);
150 if (it != m_Parameters.end()) { 160 if (it != m_Parameters.end()) {
151 value = it.data(); 161 value = it.data();
152 } 162 }
153 return value; 163 return value;
154} 164}
155 165
156void RecPart::setPositionlist(const QValueList<int>&poslist) 166void RecPart::setPositionlist(const QValueList<int>&poslist)
157{ 167{
158 m_poslist = poslist; 168 m_poslist = poslist;
159} 169}
160 170
161const QValueList<int>& RecPart::Positionlist()const 171const QValueList<int>& RecPart::Positionlist()const
162{ 172{
163 return m_poslist; 173 return m_poslist;
164} 174}
165 175
166RecBody::RecBody() 176RecBody::RecBody()
167 : m_BodyText(),m_PartsList(),m_description() 177 : m_BodyText(),m_PartsList(),m_description()
168{ 178{
169 m_PartsList.clear(); 179 m_PartsList.clear();
170} 180}
171 181
172RecBody::~RecBody() 182RecBody::~RecBody()
173{ 183{
174} 184}
175 185
176void RecBody::setBodytext(const QString&bodyText) 186void RecBody::setBodytext(const QString&bodyText)
177{ 187{
178 m_BodyText = bodyText; 188 m_BodyText = bodyText;
179} 189}
180 190
181const QString& RecBody::Bodytext()const 191const QString& RecBody::Bodytext()const
182{ 192{
183 return m_BodyText; 193 return m_BodyText;
184} 194}
185 195
186void RecBody::setParts(const QValueList<RecPart>&parts) 196void RecBody::setParts(const QValueList<RecPart>&parts)
187{ 197{
188 m_PartsList.clear(); 198 m_PartsList.clear();
189 m_PartsList = parts; 199 m_PartsList = parts;
190} 200}
191 201
192const QValueList<RecPart>& RecBody::Parts()const 202const QValueList<RecPart>& RecBody::Parts()const
193{ 203{
194 return m_PartsList; 204 return m_PartsList;
195} 205}
196 206
197void RecBody::addPart(const RecPart& part) 207void RecBody::addPart(const RecPart& part)
198{ 208{
199 m_PartsList.append(part); 209 m_PartsList.append(part);
200} 210}
201 211
202void RecBody::setDescription(const RecPart&des) 212void RecBody::setDescription(const RecPart&des)
203{ 213{
204 m_description = des; 214 m_description = des;
205} 215}
206 216
207const RecPart& RecBody::Description()const 217const RecPart& RecBody::Description()const
208{ 218{
209 return m_description; 219 return m_description;
210} 220}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index f308bc7..24518cf 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -1,128 +1,131 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <qlist.h> 11#include <qlist.h>
12#include <qbitarray.h> 12#include <qbitarray.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15#include <qmap.h> 15#include <qmap.h>
16#include <qvaluelist.h> 16#include <qvaluelist.h>
17 17
18/* a class to describe mails in a mailbox */ 18/* a class to describe mails in a mailbox */
19/* Attention! 19/* Attention!
20 From programmers point of view it would make sense to 20 From programmers point of view it would make sense to
21 store the mail body into this class, too. 21 store the mail body into this class, too.
22 But: not from the point of view of the device. 22 But: not from the point of view of the device.
23 Mailbodies can be real large. So we request them when 23 Mailbodies can be real large. So we request them when
24 needed from the mail-wrapper class direct from the server itself 24 needed from the mail-wrapper class direct from the server itself
25 (imap) or from a file-based cache (pop3?) 25 (imap) or from a file-based cache (pop3?)
26 So there is no interface "const QString&body()" but you should 26 So there is no interface "const QString&body()" but you should
27 make a request to the mailwrapper with this class as parameter to 27 make a request to the mailwrapper with this class as parameter to
28 get the body. Same words for the attachments. 28 get the body. Same words for the attachments.
29*/ 29*/
30class RecMail 30class RecMail
31{ 31{
32public: 32public:
33 RecMail(); 33 RecMail();
34 RecMail(const RecMail&old); 34 RecMail(const RecMail&old);
35 virtual ~RecMail(){} 35 virtual ~RecMail(){}
36 36
37 const int getNumber()const{return msg_number;} 37 const int getNumber()const{return msg_number;}
38 void setNumber(int number){msg_number=number;} 38 void setNumber(int number){msg_number=number;}
39 const QString&getDate()const{ return date; } 39 const QString&getDate()const{ return date; }
40 void setDate( const QString&a ) { date = a; } 40 void setDate( const QString&a ) { date = a; }
41 const QString&getFrom()const{ return from; } 41 const QString&getFrom()const{ return from; }
42 void setFrom( const QString&a ) { from = a; } 42 void setFrom( const QString&a ) { from = a; }
43 const QString&getSubject()const { return subject; } 43 const QString&getSubject()const { return subject; }
44 void setSubject( const QString&s ) { subject = s; } 44 void setSubject( const QString&s ) { subject = s; }
45 const QString&getMbox()const{return mbox;} 45 const QString&getMbox()const{return mbox;}
46 void setMbox(const QString&box){mbox = box;} 46 void setMbox(const QString&box){mbox = box;}
47 void setMsgid(const QString&id){msg_id=id;} 47 void setMsgid(const QString&id){msg_id=id;}
48 const QString&Msgid()const{return msg_id;} 48 const QString&Msgid()const{return msg_id;}
49 void setReplyto(const QString&reply){replyto=reply;} 49 void setReplyto(const QString&reply){replyto=reply;}
50 const QString&Replyto()const{return replyto;} 50 const QString&Replyto()const{return replyto;}
51 void setMsgsize(int size){msg_size = size;} 51 void setMsgsize(int size){msg_size = size;}
52 const int Msgsize()const{return msg_size;} 52 const int Msgsize()const{return msg_size;}
53 53
54 54
55 void setTo(const QStringList&list); 55 void setTo(const QStringList&list);
56 const QStringList&To()const; 56 const QStringList&To()const;
57 void setCC(const QStringList&list); 57 void setCC(const QStringList&list);
58 const QStringList&CC()const; 58 const QStringList&CC()const;
59 void setBcc(const QStringList&list); 59 void setBcc(const QStringList&list);
60 const QStringList&Bcc()const; 60 const QStringList&Bcc()const;
61 const QBitArray&getFlags()const{return msg_flags;} 61 const QBitArray&getFlags()const{return msg_flags;}
62 void setFlags(const QBitArray&flags){msg_flags = flags;} 62 void setFlags(const QBitArray&flags){msg_flags = flags;}
63 63
64protected: 64protected:
65 QString subject,date,from,mbox,msg_id,replyto; 65 QString subject,date,from,mbox,msg_id,replyto;
66 int msg_number,msg_size; 66 int msg_number,msg_size;
67 QBitArray msg_flags; 67 QBitArray msg_flags;
68 QStringList to,cc,bcc; 68 QStringList to,cc,bcc;
69 void init(); 69 void init();
70 void copy_old(const RecMail&old); 70 void copy_old(const RecMail&old);
71}; 71};
72 72
73typedef QMap<QString,QString> part_plist_t; 73typedef QMap<QString,QString> part_plist_t;
74 74
75class RecPart 75class RecPart
76{ 76{
77protected: 77protected:
78 QString m_type,m_subtype,m_identifier,m_encoding; 78 QString m_type,m_subtype,m_identifier,m_encoding;
79 unsigned int m_lines; 79 unsigned int m_lines,m_size;
80 part_plist_t m_Parameters; 80 part_plist_t m_Parameters;
81 /* describes the position in the mail */ 81 /* describes the position in the mail */
82 QValueList<int> m_poslist; 82 QValueList<int> m_poslist;
83 83
84public: 84public:
85 RecPart(); 85 RecPart();
86 virtual ~RecPart(); 86 virtual ~RecPart();
87 87
88 const QString&Type()const; 88 const QString&Type()const;
89 void setType(const QString&type); 89 void setType(const QString&type);
90 const QString&Subtype()const; 90 const QString&Subtype()const;
91 void setSubtype(const QString&subtype); 91 void setSubtype(const QString&subtype);
92 const QString&Identifier()const; 92 const QString&Identifier()const;
93 void setIdentifier(const QString&identifier); 93 void setIdentifier(const QString&identifier);
94 const QString&Encoding()const; 94 const QString&Encoding()const;
95 void setEncoding(const QString&encoding); 95 void setEncoding(const QString&encoding);
96 void setLines(unsigned int lines); 96 void setLines(unsigned int lines);
97 const unsigned int Lines()const; 97 const unsigned int Lines()const;
98 void setSize(unsigned int size);
99 const unsigned int Size()const;
100
98 101
99 void setParameters(const part_plist_t&list); 102 void setParameters(const part_plist_t&list);
100 const part_plist_t&Parameters()const; 103 const part_plist_t&Parameters()const;
101 void addParameter(const QString&key,const QString&value); 104 void addParameter(const QString&key,const QString&value);
102 const QString searchParamter(const QString&key)const; 105 const QString searchParamter(const QString&key)const;
103 void setPositionlist(const QValueList<int>&poslist); 106 void setPositionlist(const QValueList<int>&poslist);
104 const QValueList<int>& Positionlist()const; 107 const QValueList<int>& Positionlist()const;
105}; 108};
106 109
107class RecBody 110class RecBody
108{ 111{
109protected: 112protected:
110 QString m_BodyText; 113 QString m_BodyText;
111 QValueList<RecPart> m_PartsList; 114 QValueList<RecPart> m_PartsList;
112 RecPart m_description; 115 RecPart m_description;
113 116
114public: 117public:
115 RecBody(); 118 RecBody();
116 virtual ~RecBody(); 119 virtual ~RecBody();
117 void setBodytext(const QString&); 120 void setBodytext(const QString&);
118 const QString& Bodytext()const; 121 const QString& Bodytext()const;
119 122
120 void setDescription(const RecPart&des); 123 void setDescription(const RecPart&des);
121 const RecPart& Description()const; 124 const RecPart& Description()const;
122 125
123 void setParts(const QValueList<RecPart>&parts); 126 void setParts(const QValueList<RecPart>&parts);
124 const QValueList<RecPart>& Parts()const; 127 const QValueList<RecPart>& Parts()const;
125 void addPart(const RecPart&part); 128 void addPart(const RecPart&part);
126}; 129};
127 130
128#endif 131#endif
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
index 9c312e9..5cd45ed 100644
--- a/noncore/net/mail/mailtypes.cpp
+++ b/noncore/net/mail/mailtypes.cpp
@@ -1,210 +1,220 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
15 qDebug("Copy constructor RecMail"); 15 qDebug("Copy constructor RecMail");
16} 16}
17 17
18void RecMail::copy_old(const RecMail&old) 18void RecMail::copy_old(const RecMail&old)
19{ 19{
20 subject = old.subject; 20 subject = old.subject;
21 date = old.date; 21 date = old.date;
22 mbox = old.mbox; 22 mbox = old.mbox;
23 msg_id = old.msg_id; 23 msg_id = old.msg_id;
24 msg_size = old.msg_size; 24 msg_size = old.msg_size;
25 msg_number = old.msg_number; 25 msg_number = old.msg_number;
26 from = old.from; 26 from = old.from;
27 msg_flags = old.msg_flags; 27 msg_flags = old.msg_flags;
28 to = old.to; 28 to = old.to;
29 cc = old.cc; 29 cc = old.cc;
30 bcc = old.bcc; 30 bcc = old.bcc;
31} 31}
32 32
33void RecMail::init() 33void RecMail::init()
34{ 34{
35 to.clear(); 35 to.clear();
36 cc.clear(); 36 cc.clear();
37 bcc.clear(); 37 bcc.clear();
38} 38}
39 39
40void RecMail::setTo(const QStringList&list) 40void RecMail::setTo(const QStringList&list)
41{ 41{
42 to = list; 42 to = list;
43} 43}
44 44
45const QStringList&RecMail::To()const 45const QStringList&RecMail::To()const
46{ 46{
47 return to; 47 return to;
48} 48}
49 49
50void RecMail::setCC(const QStringList&list) 50void RecMail::setCC(const QStringList&list)
51{ 51{
52 cc = list; 52 cc = list;
53} 53}
54 54
55const QStringList&RecMail::CC()const 55const QStringList&RecMail::CC()const
56{ 56{
57 return cc; 57 return cc;
58} 58}
59 59
60void RecMail::setBcc(const QStringList&list) 60void RecMail::setBcc(const QStringList&list)
61{ 61{
62 bcc = list; 62 bcc = list;
63} 63}
64 64
65const QStringList& RecMail::Bcc()const 65const QStringList& RecMail::Bcc()const
66{ 66{
67 return bcc; 67 return bcc;
68} 68}
69 69
70RecPart::RecPart() 70RecPart::RecPart()
71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0) 71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0)
72{ 72{
73 m_Parameters.clear(); 73 m_Parameters.clear();
74 m_poslist.clear(); 74 m_poslist.clear();
75} 75}
76 76
77RecPart::~RecPart() 77RecPart::~RecPart()
78{ 78{
79} 79}
80 80
81void RecPart::setSize(unsigned int size)
82{
83 m_size = size;
84}
85
86const unsigned int RecPart::Size()const
87{
88 return m_size;
89}
90
81void RecPart::setLines(unsigned int lines) 91void RecPart::setLines(unsigned int lines)
82{ 92{
83 m_lines = lines; 93 m_lines = lines;
84} 94}
85 95
86const unsigned int RecPart::Lines()const 96const unsigned int RecPart::Lines()const
87{ 97{
88 return m_lines; 98 return m_lines;
89} 99}
90 100
91const QString& RecPart::Type()const 101const QString& RecPart::Type()const
92{ 102{
93 return m_type; 103 return m_type;
94} 104}
95 105
96void RecPart::setType(const QString&type) 106void RecPart::setType(const QString&type)
97{ 107{
98 m_type = type; 108 m_type = type;
99} 109}
100 110
101const QString& RecPart::Subtype()const 111const QString& RecPart::Subtype()const
102{ 112{
103 return m_subtype; 113 return m_subtype;
104} 114}
105 115
106void RecPart::setSubtype(const QString&subtype) 116void RecPart::setSubtype(const QString&subtype)
107{ 117{
108 m_subtype = subtype; 118 m_subtype = subtype;
109} 119}
110 120
111const QString& RecPart::Identifier()const 121const QString& RecPart::Identifier()const
112{ 122{
113 return m_identifier; 123 return m_identifier;
114} 124}
115 125
116void RecPart::setIdentifier(const QString&identifier) 126void RecPart::setIdentifier(const QString&identifier)
117{ 127{
118 m_identifier = identifier; 128 m_identifier = identifier;
119} 129}
120 130
121const QString& RecPart::Encoding()const 131const QString& RecPart::Encoding()const
122{ 132{
123 return m_encoding; 133 return m_encoding;
124} 134}
125 135
126void RecPart::setEncoding(const QString&encoding) 136void RecPart::setEncoding(const QString&encoding)
127{ 137{
128 m_encoding = encoding; 138 m_encoding = encoding;
129} 139}
130 140
131void RecPart::setParameters(const part_plist_t&list) 141void RecPart::setParameters(const part_plist_t&list)
132{ 142{
133 m_Parameters = list; 143 m_Parameters = list;
134} 144}
135 145
136const part_plist_t& RecPart::Parameters()const 146const part_plist_t& RecPart::Parameters()const
137{ 147{
138 return m_Parameters; 148 return m_Parameters;
139} 149}
140 150
141void RecPart::addParameter(const QString&key,const QString&value) 151void RecPart::addParameter(const QString&key,const QString&value)
142{ 152{
143 m_Parameters[key]=value; 153 m_Parameters[key]=value;
144} 154}
145 155
146const QString RecPart::searchParamter(const QString&key)const 156const QString RecPart::searchParamter(const QString&key)const
147{ 157{
148 QString value(""); 158 QString value("");
149 part_plist_t::ConstIterator it = m_Parameters.find(key); 159 part_plist_t::ConstIterator it = m_Parameters.find(key);
150 if (it != m_Parameters.end()) { 160 if (it != m_Parameters.end()) {
151 value = it.data(); 161 value = it.data();
152 } 162 }
153 return value; 163 return value;
154} 164}
155 165
156void RecPart::setPositionlist(const QValueList<int>&poslist) 166void RecPart::setPositionlist(const QValueList<int>&poslist)
157{ 167{
158 m_poslist = poslist; 168 m_poslist = poslist;
159} 169}
160 170
161const QValueList<int>& RecPart::Positionlist()const 171const QValueList<int>& RecPart::Positionlist()const
162{ 172{
163 return m_poslist; 173 return m_poslist;
164} 174}
165 175
166RecBody::RecBody() 176RecBody::RecBody()
167 : m_BodyText(),m_PartsList(),m_description() 177 : m_BodyText(),m_PartsList(),m_description()
168{ 178{
169 m_PartsList.clear(); 179 m_PartsList.clear();
170} 180}
171 181
172RecBody::~RecBody() 182RecBody::~RecBody()
173{ 183{
174} 184}
175 185
176void RecBody::setBodytext(const QString&bodyText) 186void RecBody::setBodytext(const QString&bodyText)
177{ 187{
178 m_BodyText = bodyText; 188 m_BodyText = bodyText;
179} 189}
180 190
181const QString& RecBody::Bodytext()const 191const QString& RecBody::Bodytext()const
182{ 192{
183 return m_BodyText; 193 return m_BodyText;
184} 194}
185 195
186void RecBody::setParts(const QValueList<RecPart>&parts) 196void RecBody::setParts(const QValueList<RecPart>&parts)
187{ 197{
188 m_PartsList.clear(); 198 m_PartsList.clear();
189 m_PartsList = parts; 199 m_PartsList = parts;
190} 200}
191 201
192const QValueList<RecPart>& RecBody::Parts()const 202const QValueList<RecPart>& RecBody::Parts()const
193{ 203{
194 return m_PartsList; 204 return m_PartsList;
195} 205}
196 206
197void RecBody::addPart(const RecPart& part) 207void RecBody::addPart(const RecPart& part)
198{ 208{
199 m_PartsList.append(part); 209 m_PartsList.append(part);
200} 210}
201 211
202void RecBody::setDescription(const RecPart&des) 212void RecBody::setDescription(const RecPart&des)
203{ 213{
204 m_description = des; 214 m_description = des;
205} 215}
206 216
207const RecPart& RecBody::Description()const 217const RecPart& RecBody::Description()const
208{ 218{
209 return m_description; 219 return m_description;
210} 220}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index f308bc7..24518cf 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -1,128 +1,131 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <qlist.h> 11#include <qlist.h>
12#include <qbitarray.h> 12#include <qbitarray.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15#include <qmap.h> 15#include <qmap.h>
16#include <qvaluelist.h> 16#include <qvaluelist.h>
17 17
18/* a class to describe mails in a mailbox */ 18/* a class to describe mails in a mailbox */
19/* Attention! 19/* Attention!
20 From programmers point of view it would make sense to 20 From programmers point of view it would make sense to
21 store the mail body into this class, too. 21 store the mail body into this class, too.
22 But: not from the point of view of the device. 22 But: not from the point of view of the device.
23 Mailbodies can be real large. So we request them when 23 Mailbodies can be real large. So we request them when
24 needed from the mail-wrapper class direct from the server itself 24 needed from the mail-wrapper class direct from the server itself
25 (imap) or from a file-based cache (pop3?) 25 (imap) or from a file-based cache (pop3?)
26 So there is no interface "const QString&body()" but you should 26 So there is no interface "const QString&body()" but you should
27 make a request to the mailwrapper with this class as parameter to 27 make a request to the mailwrapper with this class as parameter to
28 get the body. Same words for the attachments. 28 get the body. Same words for the attachments.
29*/ 29*/
30class RecMail 30class RecMail
31{ 31{
32public: 32public:
33 RecMail(); 33 RecMail();
34 RecMail(const RecMail&old); 34 RecMail(const RecMail&old);
35 virtual ~RecMail(){} 35 virtual ~RecMail(){}
36 36
37 const int getNumber()const{return msg_number;} 37 const int getNumber()const{return msg_number;}
38 void setNumber(int number){msg_number=number;} 38 void setNumber(int number){msg_number=number;}
39 const QString&getDate()const{ return date; } 39 const QString&getDate()const{ return date; }
40 void setDate( const QString&a ) { date = a; } 40 void setDate( const QString&a ) { date = a; }
41 const QString&getFrom()const{ return from; } 41 const QString&getFrom()const{ return from; }
42 void setFrom( const QString&a ) { from = a; } 42 void setFrom( const QString&a ) { from = a; }
43 const QString&getSubject()const { return subject; } 43 const QString&getSubject()const { return subject; }
44 void setSubject( const QString&s ) { subject = s; } 44 void setSubject( const QString&s ) { subject = s; }
45 const QString&getMbox()const{return mbox;} 45 const QString&getMbox()const{return mbox;}
46 void setMbox(const QString&box){mbox = box;} 46 void setMbox(const QString&box){mbox = box;}
47 void setMsgid(const QString&id){msg_id=id;} 47 void setMsgid(const QString&id){msg_id=id;}
48 const QString&Msgid()const{return msg_id;} 48 const QString&Msgid()const{return msg_id;}
49 void setReplyto(const QString&reply){replyto=reply;} 49 void setReplyto(const QString&reply){replyto=reply;}
50 const QString&Replyto()const{return replyto;} 50 const QString&Replyto()const{return replyto;}
51 void setMsgsize(int size){msg_size = size;} 51 void setMsgsize(int size){msg_size = size;}
52 const int Msgsize()const{return msg_size;} 52 const int Msgsize()const{return msg_size;}
53 53
54 54
55 void setTo(const QStringList&list); 55 void setTo(const QStringList&list);
56 const QStringList&To()const; 56 const QStringList&To()const;
57 void setCC(const QStringList&list); 57 void setCC(const QStringList&list);
58 const QStringList&CC()const; 58 const QStringList&CC()const;
59 void setBcc(const QStringList&list); 59 void setBcc(const QStringList&list);
60 const QStringList&Bcc()const; 60 const QStringList&Bcc()const;
61 const QBitArray&getFlags()const{return msg_flags;} 61 const QBitArray&getFlags()const{return msg_flags;}
62 void setFlags(const QBitArray&flags){msg_flags = flags;} 62 void setFlags(const QBitArray&flags){msg_flags = flags;}
63 63
64protected: 64protected:
65 QString subject,date,from,mbox,msg_id,replyto; 65 QString subject,date,from,mbox,msg_id,replyto;
66 int msg_number,msg_size; 66 int msg_number,msg_size;
67 QBitArray msg_flags; 67 QBitArray msg_flags;
68 QStringList to,cc,bcc; 68 QStringList to,cc,bcc;
69 void init(); 69 void init();
70 void copy_old(const RecMail&old); 70 void copy_old(const RecMail&old);
71}; 71};
72 72
73typedef QMap<QString,QString> part_plist_t; 73typedef QMap<QString,QString> part_plist_t;
74 74
75class RecPart 75class RecPart
76{ 76{
77protected: 77protected:
78 QString m_type,m_subtype,m_identifier,m_encoding; 78 QString m_type,m_subtype,m_identifier,m_encoding;
79 unsigned int m_lines; 79 unsigned int m_lines,m_size;
80 part_plist_t m_Parameters; 80 part_plist_t m_Parameters;
81 /* describes the position in the mail */ 81 /* describes the position in the mail */
82 QValueList<int> m_poslist; 82 QValueList<int> m_poslist;
83 83
84public: 84public:
85 RecPart(); 85 RecPart();
86 virtual ~RecPart(); 86 virtual ~RecPart();
87 87
88 const QString&Type()const; 88 const QString&Type()const;
89 void setType(const QString&type); 89 void setType(const QString&type);
90 const QString&Subtype()const; 90 const QString&Subtype()const;
91 void setSubtype(const QString&subtype); 91 void setSubtype(const QString&subtype);
92 const QString&Identifier()const; 92 const QString&Identifier()const;
93 void setIdentifier(const QString&identifier); 93 void setIdentifier(const QString&identifier);
94 const QString&Encoding()const; 94 const QString&Encoding()const;
95 void setEncoding(const QString&encoding); 95 void setEncoding(const QString&encoding);
96 void setLines(unsigned int lines); 96 void setLines(unsigned int lines);
97 const unsigned int Lines()const; 97 const unsigned int Lines()const;
98 void setSize(unsigned int size);
99 const unsigned int Size()const;
100
98 101
99 void setParameters(const part_plist_t&list); 102 void setParameters(const part_plist_t&list);
100 const part_plist_t&Parameters()const; 103 const part_plist_t&Parameters()const;
101 void addParameter(const QString&key,const QString&value); 104 void addParameter(const QString&key,const QString&value);
102 const QString searchParamter(const QString&key)const; 105 const QString searchParamter(const QString&key)const;
103 void setPositionlist(const QValueList<int>&poslist); 106 void setPositionlist(const QValueList<int>&poslist);
104 const QValueList<int>& Positionlist()const; 107 const QValueList<int>& Positionlist()const;
105}; 108};
106 109
107class RecBody 110class RecBody
108{ 111{
109protected: 112protected:
110 QString m_BodyText; 113 QString m_BodyText;
111 QValueList<RecPart> m_PartsList; 114 QValueList<RecPart> m_PartsList;
112 RecPart m_description; 115 RecPart m_description;
113 116
114public: 117public:
115 RecBody(); 118 RecBody();
116 virtual ~RecBody(); 119 virtual ~RecBody();
117 void setBodytext(const QString&); 120 void setBodytext(const QString&);
118 const QString& Bodytext()const; 121 const QString& Bodytext()const;
119 122
120 void setDescription(const RecPart&des); 123 void setDescription(const RecPart&des);
121 const RecPart& Description()const; 124 const RecPart& Description()const;
122 125
123 void setParts(const QValueList<RecPart>&parts); 126 void setParts(const QValueList<RecPart>&parts);
124 const QValueList<RecPart>& Parts()const; 127 const QValueList<RecPart>& Parts()const;
125 void addPart(const RecPart&part); 128 void addPart(const RecPart&part);
126}; 129};
127 130
128#endif 131#endif
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 7b8494d..39c9820 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -1,196 +1,264 @@
1#include <qtextbrowser.h> 1#include <qtextbrowser.h>
2#include <qmessagebox.h> 2#include <qmessagebox.h>
3#include <qtextstream.h>
3#include <qaction.h> 4#include <qaction.h>
4#include <qapplication.h> 5#include <qapplication.h>
5 6
6#include "settings.h" 7#include "settings.h"
7#include "composemail.h" 8#include "composemail.h"
8#include "viewmail.h" 9#include "viewmail.h"
9 10
10AttachItem::AttachItem(QListView *parent, AttachItemStore &attachItemStore) 11AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num)
11 : QListViewItem(parent), _attachItemStore(attachItemStore) 12 : QListViewItem(parent,after),_partNum(num)
12{ 13{
13 setText(0, _attachItemStore.mimeType()); 14 setText(0, mime);
14 setText(1, _attachItemStore.fileName()); 15 setText(1, file);
15 setText(2, _attachItemStore.description()); 16 setText(2, desc);
16}
17
18AttachItem::AttachItem(QListViewItem *parent, AttachItemStore &attachItemStore)
19 : QListViewItem(parent), _attachItemStore(attachItemStore)
20{
21 setText(0, _attachItemStore.mimeType());
22 setText(1, _attachItemStore.fileName());
23 setText(2, _attachItemStore.description());
24} 17}
25 18
26 19
27void ViewMail::setBody( RecBody body ) { 20void ViewMail::setBody( RecBody body ) {
28 21
29m_mail[2] = body.Bodytext(); 22m_mail[2] = body.Bodytext();
23attachbutton->setEnabled(body.Parts().count()>0);
24attachments->setEnabled(body.Parts().count()>0);
25if (body.Parts().count()==0) {
26 return;
27}
28AttachItem * curItem=0;
29QString type=body.Description().Type()+"/"+body.Description().Subtype();
30QString desc;
31double s = body.Description().Size();
32int w;
33w=0;
34
35while (s>1024) {
36 s/=1024;
37 ++w;
38 if (w>=2) break;
39}
30 40
41QString q="";
42switch(w) {
43case 1:
44 q="k";
45 break;
46case 2:
47 q="M";
48 break;
49default:
50 break;
51}
52
53{
54 /* I did not found a method to make a CONTENT reset on a QTextStream
55 so I use this construct that the stream will re-constructed in each
56 loop. To let it work, the textstream is packed into a own area of
57 code is it will be destructed after finishing its small job.
58 */
59 QTextOStream o(&desc);
60 if (w>0) o.precision(2); else o.precision(0);
61 o.setf(QTextStream::fixed);
62 o << s << " " << q << "Byte";
63}
64
65curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1);
66QString filename = "";
67for (unsigned int i = 0; i < body.Parts().count();++i) {
68 type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype();
69 part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin();
70 for (;it!=body.Parts()[i].Parameters().end();++it) {
71 if (it.key().lower()=="name") {
72 filename=it.data();
73 }
74 }
75 s = body.Parts()[i].Size();
76 w = 0;
77 while (s>1024) {
78 s/=1024;
79 ++w;
80 if (w>=2) break;
81 }
82 switch(w) {
83 case 1:
84 q="k";
85 break;
86 case 2:
87 q="M";
88 break;
89 default:
90 q="";
91 break;
92 }
93 QTextOStream o(&desc);
94 if (w>0) o.precision(2); else o.precision(0);
95 o.setf(QTextStream::fixed);
96 o << s << " " << q << "Byte";
97 curItem=new AttachItem(attachments,curItem,type,filename,desc,i);
98}
31} 99}
32 100
33void ViewMail::setMail( RecMail mail ) { 101void ViewMail::setMail( RecMail mail ) {
34 102
35m_mail[0] = mail.getFrom(); 103m_mail[0] = mail.getFrom();
36m_mail[1] = mail.getSubject(); 104m_mail[1] = mail.getSubject();
37m_mail[3] = mail.getDate(); 105m_mail[3] = mail.getDate();
38m_mail[4] = mail.Msgid(); 106m_mail[4] = mail.Msgid();
39 107
40m_mail2[0] = mail.To(); 108m_mail2[0] = mail.To();
41m_mail2[1] = mail.CC(); 109m_mail2[1] = mail.CC();
42m_mail2[2] = mail.Bcc(); 110m_mail2[2] = mail.Bcc();
43 111
44setText(); 112setText();
45} 113}
46 114
47 115
48 116
49ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) 117ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl)
50 : ViewMailBase(parent, name, fl), _inLoop(false) 118 : ViewMailBase(parent, name, fl), _inLoop(false)
51{ 119{
52 m_gotBody = false; 120 m_gotBody = false;
53 121
54 connect(reply, SIGNAL(activated()), SLOT(slotReply())); 122 connect(reply, SIGNAL(activated()), SLOT(slotReply()));
55 connect(forward, SIGNAL(activated()), SLOT(slotForward())); 123 connect(forward, SIGNAL(activated()), SLOT(slotForward()));
56 124
57 attachments->setEnabled(m_gotBody); 125 attachments->setEnabled(m_gotBody);
58} 126}
59 127
60void ViewMail::setText() 128void ViewMail::setText()
61{ 129{
62 130
63 QString toString; 131 QString toString;
64 QString ccString; 132 QString ccString;
65 QString bccString; 133 QString bccString;
66 134
67 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { 135 for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) {
68 toString += (*it); 136 toString += (*it);
69 } 137 }
70 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { 138 for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) {
71 ccString += (*it); 139 ccString += (*it);
72 } 140 }
73 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { 141 for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) {
74 bccString += (*it); 142 bccString += (*it);
75 } 143 }
76 144
77 setCaption( caption().arg( m_mail[0] ) ); 145 setCaption( caption().arg( m_mail[0] ) );
78 146
79 m_mailHtml = "<html><body>" 147 m_mailHtml = "<html><body>"
80 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" 148 "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>"
81 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" 149 "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>"
82 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" 150 "</td></tr><tr bgcolor=\"#EEEEE6\"><td>"
83 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" 151 "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>"
84 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + 152 "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" +
85 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" 153 tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>"
86 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + 154 "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] +
87 "</td></tr></table><font face=fixed>"; 155 "</td></tr></table><font face=fixed>";
88 156
89 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); 157 browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" );
90 // remove later in favor of a real handling 158 // remove later in favor of a real handling
91 m_gotBody = true; 159 m_gotBody = true;
92} 160}
93 161
94 162
95ViewMail::~ViewMail() 163ViewMail::~ViewMail()
96{ 164{
97 hide(); 165 hide();
98} 166}
99 167
100void ViewMail::hide() 168void ViewMail::hide()
101{ 169{
102 QWidget::hide(); 170 QWidget::hide();
103 171
104 if (_inLoop) { 172 if (_inLoop) {
105 _inLoop = false; 173 _inLoop = false;
106 qApp->exit_loop(); 174 qApp->exit_loop();
107 } 175 }
108} 176}
109 177
110void ViewMail::exec() 178void ViewMail::exec()
111{ 179{
112 show(); 180 show();
113 181
114 if (!_inLoop) { 182 if (!_inLoop) {
115 _inLoop = true; 183 _inLoop = true;
116 qApp->enter_loop(); 184 qApp->enter_loop();
117 } 185 }
118} 186}
119 187
120QString ViewMail::deHtml(const QString &string) 188QString ViewMail::deHtml(const QString &string)
121{ 189{
122 QString string_ = string; 190 QString string_ = string;
123 string_.replace(QRegExp("&"), "&amp;"); 191 string_.replace(QRegExp("&"), "&amp;");
124 string_.replace(QRegExp("<"), "&lt;"); 192 string_.replace(QRegExp("<"), "&lt;");
125 string_.replace(QRegExp(">"), "&gt;"); 193 string_.replace(QRegExp(">"), "&gt;");
126 string_.replace(QRegExp("\\n"), "<br>"); 194 string_.replace(QRegExp("\\n"), "<br>");
127 return string_; 195 return string_;
128} 196}
129 197
130void ViewMail::slotReply() 198void ViewMail::slotReply()
131{ 199{
132 if (!m_gotBody) { 200 if (!m_gotBody) {
133 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); 201 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok"));
134 return; 202 return;
135 } 203 }
136 204
137 QString rtext; 205 QString rtext;
138 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose 206 rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose
139 .arg( m_mail[1] ) 207 .arg( m_mail[1] )
140 .arg( m_mail[3] ); 208 .arg( m_mail[3] );
141 209
142 QString text = m_mail[2]; 210 QString text = m_mail[2];
143 QStringList lines = QStringList::split(QRegExp("\\n"), text); 211 QStringList lines = QStringList::split(QRegExp("\\n"), text);
144 QStringList::Iterator it; 212 QStringList::Iterator it;
145 for (it = lines.begin(); it != lines.end(); it++) { 213 for (it = lines.begin(); it != lines.end(); it++) {
146 rtext += "> " + *it + "\n"; 214 rtext += "> " + *it + "\n";
147 } 215 }
148 rtext += "\n"; 216 rtext += "\n";
149 217
150 QString prefix; 218 QString prefix;
151 if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; 219 if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = "";
152 else prefix = "Re: "; // no i18n on purpose 220 else prefix = "Re: "; // no i18n on purpose
153 221
154 Settings *settings = new Settings(); 222 Settings *settings = new Settings();
155 ComposeMail composer( settings ,this, 0, true); 223 ComposeMail composer( settings ,this, 0, true);
156 composer.setTo( m_mail[0] ); 224 composer.setTo( m_mail[0] );
157 composer.setSubject( "Re: " + m_mail[1] ); 225 composer.setSubject( "Re: " + m_mail[1] );
158 composer.setMessage( rtext ); 226 composer.setMessage( rtext );
159 composer.showMaximized(); 227 composer.showMaximized();
160 composer.exec(); 228 composer.exec();
161 229
162} 230}
163 231
164void ViewMail::slotForward() 232void ViewMail::slotForward()
165{ 233{
166 if (!m_gotBody) { 234 if (!m_gotBody) {
167 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); 235 QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok"));
168 return; 236 return;
169 } 237 }
170 238
171 QString ftext; 239 QString ftext;
172 ftext += QString("\n----- Forwarded message from %1 -----\n\n") 240 ftext += QString("\n----- Forwarded message from %1 -----\n\n")
173 .arg( m_mail[0] ); 241 .arg( m_mail[0] );
174 if (!m_mail[3].isNull()) 242 if (!m_mail[3].isNull())
175 ftext += QString("Date: %1\n") 243 ftext += QString("Date: %1\n")
176 .arg( m_mail[3] ); 244 .arg( m_mail[3] );
177 if (!m_mail[0].isNull()) 245 if (!m_mail[0].isNull())
178 ftext += QString("From: %1\n") 246 ftext += QString("From: %1\n")
179 .arg( m_mail[0] ); 247 .arg( m_mail[0] );
180 if (!m_mail[1].isNull()) 248 if (!m_mail[1].isNull())
181 ftext += QString("Subject: %1\n") 249 ftext += QString("Subject: %1\n")
182 .arg( m_mail[1] ); 250 .arg( m_mail[1] );
183 251
184 ftext += QString("\n%1\n") 252 ftext += QString("\n%1\n")
185 .arg( m_mail[2]); 253 .arg( m_mail[2]);
186 254
187 ftext += QString("----- End forwarded message -----\n"); 255 ftext += QString("----- End forwarded message -----\n");
188 256
189 Settings *settings = new Settings(); 257 Settings *settings = new Settings();
190 ComposeMail composer( settings ,this, 0, true); 258 ComposeMail composer( settings ,this, 0, true);
191 composer.setSubject( "Fwd: " + m_mail[1] ); 259 composer.setSubject( "Fwd: " + m_mail[1] );
192 composer.setMessage( ftext ); 260 composer.setMessage( ftext );
193 composer.showMaximized(); 261 composer.showMaximized();
194 composer.exec(); 262 composer.exec();
195} 263}
196 264
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h
index 61baa1d..b497434 100644
--- a/noncore/net/mail/viewmail.h
+++ b/noncore/net/mail/viewmail.h
@@ -1,74 +1,54 @@
1#ifndef VIEWMAIL_H 1#ifndef VIEWMAIL_H
2#define VIEWMAIL_H 2#define VIEWMAIL_H
3 3
4#include <qlistview.h> 4#include <qlistview.h>
5#include <qmap.h> 5#include <qmap.h>
6#include <qstringlist.h> 6#include <qstringlist.h>
7 7
8#include "viewmailbase.h" 8#include "viewmailbase.h"
9#include "mailtypes.h" 9#include "mailtypes.h"
10 10
11class AttachItemStore
12{
13public:
14 void setMimeType(QString mimeType) { _mimeType = mimeType; }
15 QString mimeType() { return _mimeType; }
16 void setFileName(QString fileName) { _fileName = fileName; }
17 QString fileName() { return _fileName; }
18 void setDescription(QString description) { _description = description; }
19 QString description() { return _description; }
20 void setPartNum(QString partNum) { _partNum = partNum; }
21 QString partNum() { return _partNum; }
22
23private:
24 QString _mimeType, _fileName, _description, _partNum;
25
26};
27
28class AttachItem : public QListViewItem 11class AttachItem : public QListViewItem
29{ 12{
30public: 13public:
31 AttachItem(QListView *parent, AttachItemStore &attachment); 14 AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num);
32 AttachItem(QListViewItem *parent, AttachItemStore &attachment); 15 int Partnumber() { return _partNum; }
33
34 AttachItemStore attachItemStore() { return _attachItemStore; }
35 16
36private: 17private:
37 AttachItemStore _attachItemStore; 18 int _partNum;
38
39}; 19};
40 20
41class ViewMail : public ViewMailBase 21class ViewMail : public ViewMailBase
42{ 22{
43 Q_OBJECT 23 Q_OBJECT
44 24
45public: 25public:
46 ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal); 26 ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal);
47 ~ViewMail(); 27 ~ViewMail();
48 28
49 void hide(); 29 void hide();
50 void exec(); 30 void exec();
51 void setMail( RecMail mail ); 31 void setMail( RecMail mail );
52 void setBody( RecBody body ); 32 void setBody( RecBody body );
53 33
54protected: 34protected:
55 QString deHtml(const QString &string); 35 QString deHtml(const QString &string);
56 36
57protected slots: 37protected slots:
58 void slotReply(); 38 void slotReply();
59 void slotForward(); 39 void slotForward();
60 void setText(); 40 void setText();
61 41
62private: 42private:
63 bool _inLoop; 43 bool _inLoop;
64 QString m_mailHtml; 44 QString m_mailHtml;
65 bool m_gotBody; 45 bool m_gotBody;
66 46
67 // 0 from 1 subject 2 bodytext 3 date 47 // 0 from 1 subject 2 bodytext 3 date
68 QMap <int,QString> m_mail; 48 QMap <int,QString> m_mail;
69 // 0 to 1 cc 2 bcc 49 // 0 to 1 cc 2 bcc
70 QMap <int,QStringList> m_mail2; 50 QMap <int,QStringList> m_mail2;
71 51
72}; 52};
73 53
74#endif 54#endif
diff --git a/noncore/net/mail/viewmailbase.cpp b/noncore/net/mail/viewmailbase.cpp
index 197a665..38f92b4 100644
--- a/noncore/net/mail/viewmailbase.cpp
+++ b/noncore/net/mail/viewmailbase.cpp
@@ -1,75 +1,76 @@
1#include <qtextbrowser.h> 1#include <qtextbrowser.h>
2#include <qlistview.h> 2#include <qlistview.h>
3#include <qaction.h> 3#include <qaction.h>
4#include <qlabel.h> 4#include <qlabel.h>
5#include <qvbox.h> 5#include <qvbox.h>
6#include <qpopupmenu.h> 6#include <qpopupmenu.h>
7 7
8#include <qpe/qpetoolbar.h> 8#include <qpe/qpetoolbar.h>
9#include <qmenubar.h> 9#include <qmenubar.h>
10#include <qpe/resource.h> 10#include <qpe/resource.h>
11 11
12#include "viewmailbase.h" 12#include "viewmailbase.h"
13//#include "opendiag.h" 13//#include "opendiag.h"
14 14
15ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl) 15ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl)
16 : QMainWindow(parent, name, fl) 16 : QMainWindow(parent, name, fl)
17{ 17{
18 setCaption(tr("E-Mail by %1")); 18 setCaption(tr("E-Mail by %1"));
19 setToolBarsMovable(false); 19 setToolBarsMovable(false);
20 20
21 toolbar = new QToolBar(this); 21 toolbar = new QToolBar(this);
22 menubar = new QMenuBar( toolbar ); 22 menubar = new QMenuBar( toolbar );
23 mailmenu = new QPopupMenu( menubar ); 23 mailmenu = new QPopupMenu( menubar );
24 menubar->insertItem( tr( "Mail" ), mailmenu ); 24 menubar->insertItem( tr( "Mail" ), mailmenu );
25 25
26 toolbar->setHorizontalStretchable(true); 26 toolbar->setHorizontalStretchable(true);
27 addToolBar(toolbar); 27 addToolBar(toolbar);
28 28
29 QLabel *spacer = new QLabel(toolbar); 29 QLabel *spacer = new QLabel(toolbar);
30 spacer->setBackgroundMode(QWidget::PaletteButton); 30 spacer->setBackgroundMode(QWidget::PaletteButton);
31 toolbar->setStretchableWidget(spacer); 31 toolbar->setStretchableWidget(spacer);
32 32
33 reply = new QAction(tr("Reply"), QIconSet(Resource::loadPixmap("mail/reply")), 0, 0, this); 33 reply = new QAction(tr("Reply"), QIconSet(Resource::loadPixmap("mail/reply")), 0, 0, this);
34 reply->addTo(toolbar); 34 reply->addTo(toolbar);
35 reply->addTo(mailmenu); 35 reply->addTo(mailmenu);
36 36
37 forward = new QAction(tr("Forward"), QIconSet(Resource::loadPixmap("mail/forward")), 0, 0, this); 37 forward = new QAction(tr("Forward"), QIconSet(Resource::loadPixmap("mail/forward")), 0, 0, this);
38 forward->addTo(toolbar); 38 forward->addTo(toolbar);
39 forward->addTo(mailmenu); 39 forward->addTo(mailmenu);
40 40
41 attachbutton = new QAction(tr("Attachments"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true); 41 attachbutton = new QAction(tr("Attachments"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true);
42 attachbutton->addTo(toolbar); 42 attachbutton->addTo(toolbar);
43 attachbutton->addTo(mailmenu); 43 attachbutton->addTo(mailmenu);
44 connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool))); 44 connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool)));
45 45
46 deleteMail = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); 46 deleteMail = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this);
47 deleteMail->addTo(toolbar); 47 deleteMail->addTo(toolbar);
48 deleteMail->addTo(mailmenu); 48 deleteMail->addTo(mailmenu);
49 49
50 QVBox *view = new QVBox(this); 50 QVBox *view = new QVBox(this);
51 setCentralWidget(view); 51 setCentralWidget(view);
52 52
53 attachments = new QListView(view); 53 attachments = new QListView(view);
54 attachments->setMinimumHeight(90); 54 attachments->setMinimumHeight(90);
55 attachments->setMaximumHeight(90); 55 attachments->setMaximumHeight(90);
56 attachments->setAllColumnsShowFocus(true); 56 attachments->setAllColumnsShowFocus(true);
57 attachments->addColumn("Mime Type", 100); 57 attachments->addColumn("Mime Type", 60);
58 attachments->addColumn("Filename", 100); 58 attachments->addColumn(tr("Filename"), 100);
59 attachments->addColumn("Description", 100); 59 attachments->addColumn(tr("Size"), 80);
60 attachments->setSorting(-1);
60 attachments->hide(); 61 attachments->hide();
61 62
62 browser = new QTextBrowser(view); 63 browser = new QTextBrowser(view);
63 64
64 //openDiag = new OpenDiag(view); 65 //openDiag = new OpenDiag(view);
65 //openDiag->hide(); 66 //openDiag->hide();
66 67
67} 68}
68 69
69void ViewMailBase::slotChangeAttachview(bool state) 70void ViewMailBase::slotChangeAttachview(bool state)
70{ 71{
71 if (state) attachments->show(); 72 if (state) attachments->show();
72 else attachments->hide(); 73 else attachments->hide();
73} 74}
74 75
75 76