summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp214
-rw-r--r--noncore/net/mail/imapwrapper.h15
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp214
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h15
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp39
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h16
-rw-r--r--noncore/net/mail/mailtypes.cpp39
-rw-r--r--noncore/net/mail/mailtypes.h16
8 files changed, 456 insertions, 112 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index e6e9fc9..27f1410 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,487 +1,605 @@
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 logout();
27 const char *server, *user, *pass; 26 const char *server, *user, *pass;
28 uint16_t port; 27 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 28 int err = MAILIMAP_NO_ERROR;
30 29
30 /* we are connected this moment */
31 /* TODO: setup a timer holding the line or if connection closed - delete the value */
32 if (m_imap) {
33 return;
34 }
31 server = account->getServer().latin1(); 35 server = account->getServer().latin1();
32 port = account->getPort().toUInt(); 36 port = account->getPort().toUInt();
33 user = account->getUser().latin1(); 37 user = account->getUser().latin1();
34 pass = account->getPassword().latin1(); 38 pass = account->getPassword().latin1();
35 39
36 m_imap = mailimap_new( 20, &imap_progress ); 40 m_imap = mailimap_new( 20, &imap_progress );
37 /* connect */ 41 /* connect */
38 // err = mailimap_socket_connect( m_imap, (char*)server, port ); 42 if (account->getSSL()) {
39 if (account->getSSL()) {
40 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 43 err = mailimap_ssl_connect( m_imap, (char*)server, port );
41 } else { 44 } else {
42 err = mailimap_socket_connect( m_imap, (char*)server, port ); 45 err = mailimap_socket_connect( m_imap, (char*)server, port );
43 } 46 }
44 47
45 if ( err != MAILIMAP_NO_ERROR && 48 if ( err != MAILIMAP_NO_ERROR &&
46 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 49 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 50 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
48 qDebug("error connecting server: %s",m_imap->imap_response); 51 qDebug("error connecting server: %s",m_imap->imap_response);
49 mailimap_free( m_imap ); 52 mailimap_free( m_imap );
50 m_imap = 0; 53 m_imap = 0;
51 return; 54 return;
52 } 55 }
53 56
54 /* login */ 57 /* login */
55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 58 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
56 if ( err != MAILIMAP_NO_ERROR ) { 59 if ( err != MAILIMAP_NO_ERROR ) {
57 qDebug("error logging in imap: %s",m_imap->imap_response); 60 qDebug("error logging in imap: %s",m_imap->imap_response);
58 err = mailimap_close( m_imap ); 61 err = mailimap_close( m_imap );
59 mailimap_free( m_imap ); 62 mailimap_free( m_imap );
60 m_imap = 0; 63 m_imap = 0;
61 } 64 }
62} 65}
63 66
64void IMAPwrapper::logout() 67void IMAPwrapper::logout()
65{ 68{
66 int err = MAILIMAP_NO_ERROR; 69 int err = MAILIMAP_NO_ERROR;
67 if (!m_imap) return; 70 if (!m_imap) return;
68 err = mailimap_logout( m_imap ); 71 err = mailimap_logout( m_imap );
69 err = mailimap_close( m_imap ); 72 err = mailimap_close( m_imap );
70 mailimap_free( m_imap ); 73 mailimap_free( m_imap );
71 m_imap = 0; 74 m_imap = 0;
72} 75}
73 76
74void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 77void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
75{ 78{
76 const char *mb; 79 const char *mb;
77 int err = MAILIMAP_NO_ERROR; 80 int err = MAILIMAP_NO_ERROR;
78 clist *result; 81 clist *result;
79 clistcell *current; 82 clistcell *current;
80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 83// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
81 mailimap_fetch_type *fetchType; 84 mailimap_fetch_type *fetchType;
82 mailimap_set *set; 85 mailimap_set *set;
83 86
84 mb = mailbox.latin1(); 87 mb = mailbox.latin1();
85 login(); 88 login();
86 if (!m_imap) { 89 if (!m_imap) {
87 return; 90 return;
88 } 91 }
89 /* select mailbox READONLY for operations */ 92 /* select mailbox READONLY for operations */
90 err = mailimap_examine( m_imap, (char*)mb); 93 err = mailimap_examine( m_imap, (char*)mb);
91 if ( err != MAILIMAP_NO_ERROR ) { 94 if ( err != MAILIMAP_NO_ERROR ) {
92 qDebug("error selecting mailbox: %s",m_imap->imap_response); 95 qDebug("error selecting mailbox: %s",m_imap->imap_response);
93 logout();
94 return; 96 return;
95 } 97 }
96 98
97 int last = m_imap->imap_selection_info->sel_exists; 99 int last = m_imap->imap_selection_info->sel_exists;
98 100
99 if (last == 0) { 101 if (last == 0) {
100 qDebug("mailbox has no mails"); 102 qDebug("mailbox has no mails");
101 logout();
102 return; 103 return;
103 } 104 }
104 105
105 result = clist_new(); 106 result = clist_new();
106 /* the range has to start at 1!!! not with 0!!!! */ 107 /* the range has to start at 1!!! not with 0!!!! */
107 set = mailimap_set_new_interval( 1, last ); 108 set = mailimap_set_new_interval( 1, last );
108 fetchAtt = mailimap_fetch_att_new_envelope();
109 fetchAttFlags = mailimap_fetch_att_new_flags();
110 fetchAttDate = mailimap_fetch_att_new_internaldate();
111
112 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
113 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
116 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 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());
117 114
118 err = mailimap_fetch( m_imap, set, fetchType, &result ); 115 err = mailimap_fetch( m_imap, set, fetchType, &result );
119 mailimap_set_free( set ); 116 mailimap_set_free( set );
120 /* cleans up the fetch_att's too! */
121 mailimap_fetch_type_free( fetchType ); 117 mailimap_fetch_type_free( fetchType );
122 118
123 QString date,subject,from; 119 QString date,subject,from;
124 120
125 if ( err == MAILIMAP_NO_ERROR ) { 121 if ( err == MAILIMAP_NO_ERROR ) {
126 current = clist_begin(result); 122
127 mailimap_msg_att * msg_att; 123 mailimap_msg_att * msg_att;
128 int i = 0; 124 int i = 0;
129 while ( current != 0 ) { 125 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
130 ++i; 126 ++i;
131 msg_att = (mailimap_msg_att*)current->data; 127 msg_att = (mailimap_msg_att*)current->data;
132 RecMail*m = parse_list_result(msg_att); 128 RecMail*m = parse_list_result(msg_att);
133 if (m) { 129 if (m) {
134 m->setNumber(i); 130 m->setNumber(i);
135 m->setMbox(mailbox); 131 m->setMbox(mailbox);
136 target.append(m); 132 target.append(m);
137 } 133 }
138 current = current->next;
139 } 134 }
140 } else { 135 } else {
141 qDebug("Error fetching headers: %s",m_imap->imap_response); 136 qDebug("Error fetching headers: %s",m_imap->imap_response);
142 } 137 }
143 logout(); 138 mailimap_fetch_list_free(result);
144 clist_free(result);
145} 139}
146 140
147QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
148{ 142{
149 const char *path, *mask; 143 const char *path, *mask;
150 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
151 clist *result; 145 clist *result;
152 clistcell *current; 146 clistcell *current;
153 147
154 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
155 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
156 login(); 150 login();
157 if (!m_imap) { 151 if (!m_imap) {
158 return folders; 152 return folders;
159 } 153 }
160 154
161/* 155/*
162 * 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.
163 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
164 * 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.
165 */ 159 */
166 QString temp; 160 QString temp;
167 mask = "INBOX" ; 161 mask = "INBOX" ;
168 result = clist_new(); 162 result = clist_new();
169 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
171 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
172 current = result->first; 166 current = result->first;
173 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
174 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
175 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
176 // instead of using strdup! 170 // instead of using strdup!
177 temp = list->mb_name; 171 temp = list->mb_name;
178 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
179 current = current->next; 173 current = current->next;
180 } 174 }
181 } else { 175 } else {
182 qDebug("error fetching folders: %s",m_imap->imap_response); 176 qDebug("error fetching folders: %s",m_imap->imap_response);
183 } 177 }
184 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
185 179
186/* 180/*
187 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
188 */ 182 */
189 mask = "*" ; 183 mask = "*" ;
190 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
191 if (!path) path = ""; 185 if (!path) path = "";
192 result = clist_new(); 186 result = clist_new();
193 qDebug(path); 187 qDebug(path);
194 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
195 if ( err == MAILIMAP_NO_ERROR ) { 189 if ( err == MAILIMAP_NO_ERROR ) {
196 current = result->first; 190 current = result->first;
197 for ( int i = result->count; i > 0; i-- ) { 191 for ( int i = result->count; i > 0; i-- ) {
198 list = (mailimap_mailbox_list *) current->data; 192 list = (mailimap_mailbox_list *) current->data;
199 // it is better use the deep copy mechanism of qt itself 193 // it is better use the deep copy mechanism of qt itself
200 // instead of using strdup! 194 // instead of using strdup!
201 temp = list->mb_name; 195 temp = list->mb_name;
202 current = current->next; 196 current = current->next;
203 if (temp.lower()=="inbox") 197 if (temp.lower()=="inbox")
204 continue; 198 continue;
205 folders->append(new IMAPFolder(temp)); 199 folders->append(new IMAPFolder(temp));
206 200
207 } 201 }
208 } else { 202 } else {
209 qDebug("error fetching folders %s",m_imap->imap_response); 203 qDebug("error fetching folders %s",m_imap->imap_response);
210 } 204 }
211 mailimap_list_result_free( result ); 205 mailimap_list_result_free( result );
212 return folders; 206 return folders;
213} 207}
214 208
215RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
216{ 210{
217 RecMail * m = 0; 211 RecMail * m = 0;
218 mailimap_msg_att_item *item=0; 212 mailimap_msg_att_item *item=0;
219 clistcell *current,*c,*cf; 213 clistcell *current,*c,*cf;
220 mailimap_msg_att_dynamic*flist; 214 mailimap_msg_att_dynamic*flist;
221 mailimap_flag_fetch*cflag; 215 mailimap_flag_fetch*cflag;
216 int size;
222 QBitArray mFlags(7); 217 QBitArray mFlags(7);
223 QStringList addresslist; 218 QStringList addresslist;
224 219
225 if (!m_att) { 220 if (!m_att) {
226 return m; 221 return m;
227 } 222 }
228 223 m = new RecMail();
229 c = clist_begin(m_att->att_list); 224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
230 while ( c ) {
231 current = c; 225 current = c;
232 c = c->next; 226 size = 0;
233 item = (mailimap_msg_att_item*)current->data; 227 item = (mailimap_msg_att_item*)current->data;
234 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
235 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
236 if (!flist->att_list) { 230 if (!flist->att_list) {
237 continue; 231 continue;
238 } 232 }
239 cf = flist->att_list->first; 233 cf = flist->att_list->first;
240 while (cf) { 234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
241 cflag = (mailimap_flag_fetch*)cf->data; 235 cflag = (mailimap_flag_fetch*)cf->data;
242 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) {
243 switch (cflag->fl_flag->fl_type) { 237 switch (cflag->fl_flag->fl_type) {
244 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
245 mFlags.setBit(FLAG_ANSWERED); 239 mFlags.setBit(FLAG_ANSWERED);
246 break; 240 break;
247 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
248 mFlags.setBit(FLAG_FLAGGED); 242 mFlags.setBit(FLAG_FLAGGED);
249 break; 243 break;
250 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
251 mFlags.setBit(FLAG_DELETED); 245 mFlags.setBit(FLAG_DELETED);
252 break; 246 break;
253 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
254 mFlags.setBit(FLAG_SEEN); 248 mFlags.setBit(FLAG_SEEN);
255 break; 249 break;
256 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
257 mFlags.setBit(FLAG_DRAFT); 251 mFlags.setBit(FLAG_DRAFT);
258 break; 252 break;
259 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
260 break; 254 break;
261 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
262 break; 256 break;
263 default: 257 default:
264 break; 258 break;
265 } 259 }
266 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
267 mFlags.setBit(FLAG_RECENT); 261 mFlags.setBit(FLAG_RECENT);
268 } 262 }
269 cf = cf->next;
270 } 263 }
271 continue; 264 continue;
272 } 265 }
273 if ( item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
274 qDebug( "header: \n%s", item->att_data.att_static->att_data.att_rfc822_header );
275 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 267 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
277 m = new RecMail();
278 m->setDate(head->env_date); 268 m->setDate(head->env_date);
279 m->setSubject(head->env_subject); 269 m->setSubject(head->env_subject);
280 if (head->env_from!=NULL) { 270 if (head->env_from!=NULL) {
281 addresslist = address_list_to_stringlist(head->env_from->frm_list); 271 addresslist = address_list_to_stringlist(head->env_from->frm_list);
282 if (addresslist.count()) { 272 if (addresslist.count()) {
283 m->setFrom(addresslist.first()); 273 m->setFrom(addresslist.first());
284 } 274 }
285 } 275 }
286 if (head->env_to!=NULL) { 276 if (head->env_to!=NULL) {
287 addresslist = address_list_to_stringlist(head->env_to->to_list); 277 addresslist = address_list_to_stringlist(head->env_to->to_list);
288 m->setTo(addresslist); 278 m->setTo(addresslist);
289 } 279 }
290 if (head->env_cc!=NULL) { 280 if (head->env_cc!=NULL) {
291 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 281 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
292 m->setCC(addresslist); 282 m->setCC(addresslist);
293 } 283 }
294 if (head->env_bcc!=NULL) { 284 if (head->env_bcc!=NULL) {
295 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
296 m->setBcc(addresslist); 286 m->setBcc(addresslist);
297 } 287 }
298 if (head->env_reply_to!=NULL) { 288 if (head->env_reply_to!=NULL) {
299 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
300 if (addresslist.count()) { 290 if (addresslist.count()) {
301 m->setReplyto(addresslist.first()); 291 m->setReplyto(addresslist.first());
302 } 292 }
303 } 293 }
304 m->setMsgid(QString(head->env_message_id)); 294 m->setMsgid(QString(head->env_message_id));
305 } 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) {
306 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;
307 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));
308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 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);
309 qDebug(da.toString()); 299 qDebug(da.toString());
310 } else { 300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
311 qDebug("Another type"); 301 size = item->att_data.att_static->att_data.att_rfc822_size;
312 } 302 }
313 } 303 }
314 /* msg is already deleted */ 304 /* msg is already deleted */
315 if (mFlags.testBit(FLAG_DELETED) && m) { 305 if (mFlags.testBit(FLAG_DELETED) && m) {
316 delete m; 306 delete m;
317 m = 0; 307 m = 0;
318 } 308 }
319 if (m) { 309 if (m) {
320 m->setFlags(mFlags); 310 m->setFlags(mFlags);
311 m->setMsgsize(size);
321 } 312 }
322 return m; 313 return m;
323} 314}
324 315
325RecBody IMAPwrapper::fetchBody(const RecMail&mail) 316RecBody IMAPwrapper::fetchBody(const RecMail&mail)
326{ 317{
327 RecBody body; 318 RecBody body;
328 const char *mb; 319 const char *mb;
329 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
330 clist *result; 321 clist *result;
331 clistcell *current; 322 clistcell *current;
332 mailimap_fetch_att *fetchAtt; 323 mailimap_fetch_att *fetchAtt;
333 mailimap_fetch_type *fetchType; 324 mailimap_fetch_type *fetchType;
334 mailimap_set *set; 325 mailimap_set *set;
335 mailimap_body*body_desc; 326 mailimap_body*body_desc;
336 327
337 mb = mail.getMbox().latin1(); 328 mb = mail.getMbox().latin1();
338 329
339 login(); 330 login();
340 if (!m_imap) { 331 if (!m_imap) {
341 return body; 332 return body;
342 } 333 }
343 /* select mailbox READONLY for operations */ 334 /* select mailbox READONLY for operations */
344 err = mailimap_examine( m_imap, (char*)mb); 335 err = mailimap_examine( m_imap, (char*)mb);
345 if ( err != MAILIMAP_NO_ERROR ) { 336 if ( err != MAILIMAP_NO_ERROR ) {
346 qDebug("error selecting mailbox: %s",m_imap->imap_response); 337 qDebug("error selecting mailbox: %s",m_imap->imap_response);
347 logout();
348 return body; 338 return body;
349 } 339 }
340
350 result = clist_new(); 341 result = clist_new();
351 /* the range has to start at 1!!! not with 0!!!! */ 342 /* the range has to start at 1!!! not with 0!!!! */
352 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
353 fetchAtt = mailimap_fetch_att_new_body(); 344 fetchAtt = mailimap_fetch_att_new_bodystructure();
354 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
355 err = mailimap_fetch( m_imap, set, fetchType, &result ); 346 err = mailimap_fetch( m_imap, set, fetchType, &result );
356 mailimap_set_free( set ); 347 mailimap_set_free( set );
357 mailimap_fetch_type_free( fetchType ); 348 mailimap_fetch_type_free( fetchType );
358 349
359 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
360 mailimap_msg_att * msg_att; 351 mailimap_msg_att * msg_att;
361 msg_att = (mailimap_msg_att*)current->data; 352 msg_att = (mailimap_msg_att*)current->data;
362 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;
363 body_desc = item->att_data.att_static->att_data.att_body; 354 body_desc = item->att_data.att_static->att_data.att_body;
364 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
365 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
366 } else { 357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
358 qDebug("Mulitpart mail");
359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body,0);
367 } 360 }
368
369 } else { 361 } else {
370 qDebug("error fetching body: %s",m_imap->imap_response); 362 qDebug("error fetching body: %s",m_imap->imap_response);
371 } 363 }
372 364 mailimap_fetch_list_free(result);
373 clist_free(result);
374 logout();
375 return body; 365 return body;
376} 366}
377 367
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
370 routines 'cause we can not simply fetch the whole body. */
378void 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)
379{ 372{
380 if (!mailDescription) { 373 if (!mailDescription) {
381 return; 374 return;
382 } 375 }
376 QString sub;
383 switch (mailDescription->bd_type) { 377 switch (mailDescription->bd_type) {
378 case MAILIMAP_BODY_TYPE_1PART_MSG:
379 target_body.setType("text");
380 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
381 target_body.setSubtype(sub.lower());
382 fillPlainBody(mail,target_body);
383 break;
384 case MAILIMAP_BODY_TYPE_1PART_TEXT: 384 case MAILIMAP_BODY_TYPE_1PART_TEXT:
385 fillPlainBody(mail,target_body,mailDescription->bd_data.bd_type_text); 385 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
386 target_body.setType("text");
387 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
388 target_body.setSubtype(sub.lower());
389 fillPlainBody(mail,target_body);
386 break; 390 break;
387 default: 391 default:
388 break; 392 break;
389 } 393 }
390 return; 394 return;
391} 395}
392 396
393void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * bd) 397void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body)
394{ 398{
395 const char *mb; 399 const char *mb;
396 QString body=""; 400 QString body="";
397 int err = MAILIMAP_NO_ERROR; 401 int err = MAILIMAP_NO_ERROR;
398 clist *result; 402 clist *result;
399 clistcell *current,*cur; 403 clistcell *current,*cur;
400 mailimap_fetch_att *fetchAtt; 404 mailimap_fetch_att *fetchAtt;
401 mailimap_fetch_type *fetchType; 405 mailimap_fetch_type *fetchType;
402 mailimap_set *set; 406 mailimap_set *set;
403 407
404 mb = mail.getMbox().latin1(); 408 mb = mail.getMbox().latin1();
405 409
406 if (!m_imap) { 410 if (!m_imap) {
407 return; 411 return;
408 } 412 }
409 413
410 result = clist_new(); 414 result = clist_new();
411 set = set = mailimap_set_new_single(mail.getNumber()); 415 set = set = mailimap_set_new_single(mail.getNumber());
412 mailimap_section * section = mailimap_section_new_text(); 416 mailimap_section * section = mailimap_section_new_text();
413 fetchAtt = mailimap_fetch_att_new_body_peek_section(section); 417 fetchAtt = mailimap_fetch_att_new_body_peek_section(section);
414 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 418 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
415 err = mailimap_fetch( m_imap, set, fetchType, &result ); 419 err = mailimap_fetch( m_imap, set, fetchType, &result );
416 mailimap_set_free( set ); 420 mailimap_set_free( set );
417 mailimap_fetch_type_free( fetchType ); 421 mailimap_fetch_type_free( fetchType );
418 422
419 423
420 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 424 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
421 mailimap_msg_att * msg_att; 425 mailimap_msg_att * msg_att;
422 msg_att = (mailimap_msg_att*)current->data; 426 msg_att = (mailimap_msg_att*)current->data;
423 mailimap_msg_att_item*msg_att_item; 427 mailimap_msg_att_item*msg_att_item;
424 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 428 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
425 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 429 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
426 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 430 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
427 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 431 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
428 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 432 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
429 int length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
430 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 433 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
431 body = QString(text); 434 if (text) {
432 free(text); 435 body = QString(text);
436 free(text);
437 } else {
438 body = "";
439 }
433 } 440 }
434 } 441 }
435 } 442 }
436 443
437 } else { 444 } else {
438 qDebug("error fetching text: %s",m_imap->imap_response); 445 qDebug("error fetching text: %s",m_imap->imap_response);
439 } 446 }
440 //clist_free(result);
441 mailimap_fetch_list_free(result); 447 mailimap_fetch_list_free(result);
442 target_body.setBodytext(body); 448 target_body.setBodytext(body);
443 return; 449 return;
444} 450}
445 451
446QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 452QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
447{ 453{
448 QStringList l; 454 QStringList l;
449 QString from; 455 QString from;
450 bool named_from; 456 bool named_from;
451 clistcell *current = NULL; 457 clistcell *current = NULL;
452 mailimap_address * current_address=NULL; 458 mailimap_address * current_address=NULL;
453 if (!list) { 459 if (!list) {
454 return l; 460 return l;
455 } 461 }
456 current = clist_begin(list);
457 unsigned int count = 0; 462 unsigned int count = 0;
458 while (current!= NULL) { 463 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
459 from = ""; 464 from = "";
460 named_from = false; 465 named_from = false;
461 current_address=(mailimap_address*)current->data; 466 current_address=(mailimap_address*)current->data;
462 current = current->next;
463 if (current_address->ad_personal_name){ 467 if (current_address->ad_personal_name){
464 from+=QString(current_address->ad_personal_name); 468 from+=QString(current_address->ad_personal_name);
465 from+=" "; 469 from+=" ";
466 named_from = true; 470 named_from = true;
467 } 471 }
468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 472 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
469 from+="<"; 473 from+="<";
470 } 474 }
471 if (current_address->ad_mailbox_name) { 475 if (current_address->ad_mailbox_name) {
472 from+=QString(current_address->ad_mailbox_name); 476 from+=QString(current_address->ad_mailbox_name);
473 from+="@"; 477 from+="@";
474 } 478 }
475 if (current_address->ad_host_name) { 479 if (current_address->ad_host_name) {
476 from+=QString(current_address->ad_host_name); 480 from+=QString(current_address->ad_host_name);
477 } 481 }
478 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 482 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
479 from+=">"; 483 from+=">";
480 } 484 }
481 l.append(QString(from)); 485 l.append(QString(from));
482 if (++count > 99) { 486 if (++count > 99) {
483 break; 487 break;
484 } 488 }
485 } 489 }
486 return l; 490 return l;
487} 491}
492
493void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion)
494{
495 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
496 if (!mailDescription||current_recursion==2) {
497 return;
498 }
499 qDebug("Mediatype: %s",mailDescription->bd_media_subtype);
500 clistcell*current;
501 mailimap_body*current_body;
502 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
503 current_body = (mailimap_body*)current->data;
504 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
505 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1);
506 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
507 RecPart currentPart;
508 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
509 target_body.addPart(currentPart);
510 }
511 }
512 if (current_recursion==0) {
513
514 }
515}
516
517void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
518{
519 if (!Description) {
520 return;
521 }
522 switch (Description->bd_type) {
523 case MAILIMAP_BODY_TYPE_1PART_TEXT:
524 target_part.setType("text");
525 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
526 break;
527 case MAILIMAP_BODY_TYPE_1PART_BASIC:
528 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
529 break;
530 default:
531 break;
532 }
533}
534
535void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
536{
537 if (!which) {
538 return;
539 }
540 QString sub;
541 sub = which->bd_media_text;
542 target_part.setSubtype(sub.lower());
543 target_part.setLines(which->bd_lines);
544 fillBodyFields(target_part,which->bd_fields);
545}
546
547void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
548{
549 if (!which) {
550 return;
551 }
552 QString type,sub;
553 switch (which->bd_media_basic->med_type) {
554 case MAILIMAP_MEDIA_BASIC_APPLICATION:
555 type = "application";
556 break;
557 case MAILIMAP_MEDIA_BASIC_AUDIO:
558 type = "audio";
559 break;
560 case MAILIMAP_MEDIA_BASIC_IMAGE:
561 type = "image";
562 break;
563 case MAILIMAP_MEDIA_BASIC_MESSAGE:
564 type = "message";
565 break;
566 case MAILIMAP_MEDIA_BASIC_VIDEO:
567 type = "video";
568 break;
569 case MAILIMAP_MEDIA_BASIC_OTHER:
570 default:
571 if (which->bd_media_basic->med_basic_type) {
572 type = which->bd_media_basic->med_basic_type;
573 } else {
574 type = "";
575 }
576 break;
577 }
578 if (which->bd_media_basic->med_subtype) {
579 sub = which->bd_media_basic->med_subtype;
580 } else {
581 sub = "";
582 }
583 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
584 target_part.setType(type.lower());
585 target_part.setSubtype(sub.lower());
586 fillBodyFields(target_part,which->bd_fields);
587}
588
589void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
590{
591 if (!which) return;
592 if (which->bd_id) {
593 qDebug("Part ID = %s",which->bd_id);
594 target_part.setIdentifier(which->bd_id);
595 } else {
596 qDebug("ID empty");
597 target_part.setIdentifier("");
598 }
599
600 clistcell*cur;
601 mailimap_single_body_fld_param*param;
602 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
603 param = (mailimap_single_body_fld_param*)cur->data;
604 }
605}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 90f3004..f809edb 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,39 +1,52 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10struct mailimap_body_type_basic;
11struct mailimap_body_type_mpart;
12struct mailimap_body_fields;
10struct mailimap_msg_att; 13struct mailimap_msg_att;
11class RecMail; 14class RecMail;
12class RecBody; 15class RecBody;
16class RecPart;
13 17
14class IMAPwrapper : public QObject 18class IMAPwrapper : public QObject
15{ 19{
16 Q_OBJECT 20 Q_OBJECT
17 21
18public: 22public:
19 IMAPwrapper( IMAPaccount *a ); 23 IMAPwrapper( IMAPaccount *a );
20 virtual ~IMAPwrapper(); 24 virtual ~IMAPwrapper();
21 QList<IMAPFolder>* listFolders(); 25 QList<IMAPFolder>* listFolders();
22 void listMessages(const QString & mailbox,QList<RecMail>&target ); 26 void listMessages(const QString & mailbox,QList<RecMail>&target );
23 RecBody fetchBody(const RecMail&mail); 27 RecBody fetchBody(const RecMail&mail);
24 static void imap_progress( size_t current, size_t maximum ); 28 static void imap_progress( size_t current, size_t maximum );
25 29
26protected: 30protected:
27 RecMail*parse_list_result(mailimap_msg_att*); 31 RecMail*parse_list_result(mailimap_msg_att*);
28 void login(); 32 void login();
29 void logout(); 33 void logout();
34
30 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
31 void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body); 36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion);
37
38 void fillPlainBody(const RecMail&mail,RecBody&target_body);
39 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
40 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
41 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
42
43 /* just helpers */
44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
32 static QStringList address_list_to_stringlist(clist*list); 45 static QStringList address_list_to_stringlist(clist*list);
33 46
34private: 47private:
35 IMAPaccount *account; 48 IMAPaccount *account;
36 mailimap *m_imap; 49 mailimap *m_imap;
37}; 50};
38 51
39#endif 52#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index e6e9fc9..27f1410 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,487 +1,605 @@
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 logout();
27 const char *server, *user, *pass; 26 const char *server, *user, *pass;
28 uint16_t port; 27 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 28 int err = MAILIMAP_NO_ERROR;
30 29
30 /* we are connected this moment */
31 /* TODO: setup a timer holding the line or if connection closed - delete the value */
32 if (m_imap) {
33 return;
34 }
31 server = account->getServer().latin1(); 35 server = account->getServer().latin1();
32 port = account->getPort().toUInt(); 36 port = account->getPort().toUInt();
33 user = account->getUser().latin1(); 37 user = account->getUser().latin1();
34 pass = account->getPassword().latin1(); 38 pass = account->getPassword().latin1();
35 39
36 m_imap = mailimap_new( 20, &imap_progress ); 40 m_imap = mailimap_new( 20, &imap_progress );
37 /* connect */ 41 /* connect */
38 // err = mailimap_socket_connect( m_imap, (char*)server, port ); 42 if (account->getSSL()) {
39 if (account->getSSL()) {
40 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 43 err = mailimap_ssl_connect( m_imap, (char*)server, port );
41 } else { 44 } else {
42 err = mailimap_socket_connect( m_imap, (char*)server, port ); 45 err = mailimap_socket_connect( m_imap, (char*)server, port );
43 } 46 }
44 47
45 if ( err != MAILIMAP_NO_ERROR && 48 if ( err != MAILIMAP_NO_ERROR &&
46 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 49 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 50 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
48 qDebug("error connecting server: %s",m_imap->imap_response); 51 qDebug("error connecting server: %s",m_imap->imap_response);
49 mailimap_free( m_imap ); 52 mailimap_free( m_imap );
50 m_imap = 0; 53 m_imap = 0;
51 return; 54 return;
52 } 55 }
53 56
54 /* login */ 57 /* login */
55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 58 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
56 if ( err != MAILIMAP_NO_ERROR ) { 59 if ( err != MAILIMAP_NO_ERROR ) {
57 qDebug("error logging in imap: %s",m_imap->imap_response); 60 qDebug("error logging in imap: %s",m_imap->imap_response);
58 err = mailimap_close( m_imap ); 61 err = mailimap_close( m_imap );
59 mailimap_free( m_imap ); 62 mailimap_free( m_imap );
60 m_imap = 0; 63 m_imap = 0;
61 } 64 }
62} 65}
63 66
64void IMAPwrapper::logout() 67void IMAPwrapper::logout()
65{ 68{
66 int err = MAILIMAP_NO_ERROR; 69 int err = MAILIMAP_NO_ERROR;
67 if (!m_imap) return; 70 if (!m_imap) return;
68 err = mailimap_logout( m_imap ); 71 err = mailimap_logout( m_imap );
69 err = mailimap_close( m_imap ); 72 err = mailimap_close( m_imap );
70 mailimap_free( m_imap ); 73 mailimap_free( m_imap );
71 m_imap = 0; 74 m_imap = 0;
72} 75}
73 76
74void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 77void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
75{ 78{
76 const char *mb; 79 const char *mb;
77 int err = MAILIMAP_NO_ERROR; 80 int err = MAILIMAP_NO_ERROR;
78 clist *result; 81 clist *result;
79 clistcell *current; 82 clistcell *current;
80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 83// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
81 mailimap_fetch_type *fetchType; 84 mailimap_fetch_type *fetchType;
82 mailimap_set *set; 85 mailimap_set *set;
83 86
84 mb = mailbox.latin1(); 87 mb = mailbox.latin1();
85 login(); 88 login();
86 if (!m_imap) { 89 if (!m_imap) {
87 return; 90 return;
88 } 91 }
89 /* select mailbox READONLY for operations */ 92 /* select mailbox READONLY for operations */
90 err = mailimap_examine( m_imap, (char*)mb); 93 err = mailimap_examine( m_imap, (char*)mb);
91 if ( err != MAILIMAP_NO_ERROR ) { 94 if ( err != MAILIMAP_NO_ERROR ) {
92 qDebug("error selecting mailbox: %s",m_imap->imap_response); 95 qDebug("error selecting mailbox: %s",m_imap->imap_response);
93 logout();
94 return; 96 return;
95 } 97 }
96 98
97 int last = m_imap->imap_selection_info->sel_exists; 99 int last = m_imap->imap_selection_info->sel_exists;
98 100
99 if (last == 0) { 101 if (last == 0) {
100 qDebug("mailbox has no mails"); 102 qDebug("mailbox has no mails");
101 logout();
102 return; 103 return;
103 } 104 }
104 105
105 result = clist_new(); 106 result = clist_new();
106 /* the range has to start at 1!!! not with 0!!!! */ 107 /* the range has to start at 1!!! not with 0!!!! */
107 set = mailimap_set_new_interval( 1, last ); 108 set = mailimap_set_new_interval( 1, last );
108 fetchAtt = mailimap_fetch_att_new_envelope();
109 fetchAttFlags = mailimap_fetch_att_new_flags();
110 fetchAttDate = mailimap_fetch_att_new_internaldate();
111
112 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
113 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
116 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 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());
117 114
118 err = mailimap_fetch( m_imap, set, fetchType, &result ); 115 err = mailimap_fetch( m_imap, set, fetchType, &result );
119 mailimap_set_free( set ); 116 mailimap_set_free( set );
120 /* cleans up the fetch_att's too! */
121 mailimap_fetch_type_free( fetchType ); 117 mailimap_fetch_type_free( fetchType );
122 118
123 QString date,subject,from; 119 QString date,subject,from;
124 120
125 if ( err == MAILIMAP_NO_ERROR ) { 121 if ( err == MAILIMAP_NO_ERROR ) {
126 current = clist_begin(result); 122
127 mailimap_msg_att * msg_att; 123 mailimap_msg_att * msg_att;
128 int i = 0; 124 int i = 0;
129 while ( current != 0 ) { 125 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
130 ++i; 126 ++i;
131 msg_att = (mailimap_msg_att*)current->data; 127 msg_att = (mailimap_msg_att*)current->data;
132 RecMail*m = parse_list_result(msg_att); 128 RecMail*m = parse_list_result(msg_att);
133 if (m) { 129 if (m) {
134 m->setNumber(i); 130 m->setNumber(i);
135 m->setMbox(mailbox); 131 m->setMbox(mailbox);
136 target.append(m); 132 target.append(m);
137 } 133 }
138 current = current->next;
139 } 134 }
140 } else { 135 } else {
141 qDebug("Error fetching headers: %s",m_imap->imap_response); 136 qDebug("Error fetching headers: %s",m_imap->imap_response);
142 } 137 }
143 logout(); 138 mailimap_fetch_list_free(result);
144 clist_free(result);
145} 139}
146 140
147QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
148{ 142{
149 const char *path, *mask; 143 const char *path, *mask;
150 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
151 clist *result; 145 clist *result;
152 clistcell *current; 146 clistcell *current;
153 147
154 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
155 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
156 login(); 150 login();
157 if (!m_imap) { 151 if (!m_imap) {
158 return folders; 152 return folders;
159 } 153 }
160 154
161/* 155/*
162 * 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.
163 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
164 * 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.
165 */ 159 */
166 QString temp; 160 QString temp;
167 mask = "INBOX" ; 161 mask = "INBOX" ;
168 result = clist_new(); 162 result = clist_new();
169 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
171 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
172 current = result->first; 166 current = result->first;
173 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
174 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
175 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
176 // instead of using strdup! 170 // instead of using strdup!
177 temp = list->mb_name; 171 temp = list->mb_name;
178 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
179 current = current->next; 173 current = current->next;
180 } 174 }
181 } else { 175 } else {
182 qDebug("error fetching folders: %s",m_imap->imap_response); 176 qDebug("error fetching folders: %s",m_imap->imap_response);
183 } 177 }
184 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
185 179
186/* 180/*
187 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
188 */ 182 */
189 mask = "*" ; 183 mask = "*" ;
190 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
191 if (!path) path = ""; 185 if (!path) path = "";
192 result = clist_new(); 186 result = clist_new();
193 qDebug(path); 187 qDebug(path);
194 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
195 if ( err == MAILIMAP_NO_ERROR ) { 189 if ( err == MAILIMAP_NO_ERROR ) {
196 current = result->first; 190 current = result->first;
197 for ( int i = result->count; i > 0; i-- ) { 191 for ( int i = result->count; i > 0; i-- ) {
198 list = (mailimap_mailbox_list *) current->data; 192 list = (mailimap_mailbox_list *) current->data;
199 // it is better use the deep copy mechanism of qt itself 193 // it is better use the deep copy mechanism of qt itself
200 // instead of using strdup! 194 // instead of using strdup!
201 temp = list->mb_name; 195 temp = list->mb_name;
202 current = current->next; 196 current = current->next;
203 if (temp.lower()=="inbox") 197 if (temp.lower()=="inbox")
204 continue; 198 continue;
205 folders->append(new IMAPFolder(temp)); 199 folders->append(new IMAPFolder(temp));
206 200
207 } 201 }
208 } else { 202 } else {
209 qDebug("error fetching folders %s",m_imap->imap_response); 203 qDebug("error fetching folders %s",m_imap->imap_response);
210 } 204 }
211 mailimap_list_result_free( result ); 205 mailimap_list_result_free( result );
212 return folders; 206 return folders;
213} 207}
214 208
215RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
216{ 210{
217 RecMail * m = 0; 211 RecMail * m = 0;
218 mailimap_msg_att_item *item=0; 212 mailimap_msg_att_item *item=0;
219 clistcell *current,*c,*cf; 213 clistcell *current,*c,*cf;
220 mailimap_msg_att_dynamic*flist; 214 mailimap_msg_att_dynamic*flist;
221 mailimap_flag_fetch*cflag; 215 mailimap_flag_fetch*cflag;
216 int size;
222 QBitArray mFlags(7); 217 QBitArray mFlags(7);
223 QStringList addresslist; 218 QStringList addresslist;
224 219
225 if (!m_att) { 220 if (!m_att) {
226 return m; 221 return m;
227 } 222 }
228 223 m = new RecMail();
229 c = clist_begin(m_att->att_list); 224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
230 while ( c ) {
231 current = c; 225 current = c;
232 c = c->next; 226 size = 0;
233 item = (mailimap_msg_att_item*)current->data; 227 item = (mailimap_msg_att_item*)current->data;
234 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
235 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
236 if (!flist->att_list) { 230 if (!flist->att_list) {
237 continue; 231 continue;
238 } 232 }
239 cf = flist->att_list->first; 233 cf = flist->att_list->first;
240 while (cf) { 234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
241 cflag = (mailimap_flag_fetch*)cf->data; 235 cflag = (mailimap_flag_fetch*)cf->data;
242 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) {
243 switch (cflag->fl_flag->fl_type) { 237 switch (cflag->fl_flag->fl_type) {
244 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
245 mFlags.setBit(FLAG_ANSWERED); 239 mFlags.setBit(FLAG_ANSWERED);
246 break; 240 break;
247 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
248 mFlags.setBit(FLAG_FLAGGED); 242 mFlags.setBit(FLAG_FLAGGED);
249 break; 243 break;
250 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
251 mFlags.setBit(FLAG_DELETED); 245 mFlags.setBit(FLAG_DELETED);
252 break; 246 break;
253 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
254 mFlags.setBit(FLAG_SEEN); 248 mFlags.setBit(FLAG_SEEN);
255 break; 249 break;
256 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
257 mFlags.setBit(FLAG_DRAFT); 251 mFlags.setBit(FLAG_DRAFT);
258 break; 252 break;
259 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
260 break; 254 break;
261 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
262 break; 256 break;
263 default: 257 default:
264 break; 258 break;
265 } 259 }
266 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
267 mFlags.setBit(FLAG_RECENT); 261 mFlags.setBit(FLAG_RECENT);
268 } 262 }
269 cf = cf->next;
270 } 263 }
271 continue; 264 continue;
272 } 265 }
273 if ( item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
274 qDebug( "header: \n%s", item->att_data.att_static->att_data.att_rfc822_header );
275 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 267 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
277 m = new RecMail();
278 m->setDate(head->env_date); 268 m->setDate(head->env_date);
279 m->setSubject(head->env_subject); 269 m->setSubject(head->env_subject);
280 if (head->env_from!=NULL) { 270 if (head->env_from!=NULL) {
281 addresslist = address_list_to_stringlist(head->env_from->frm_list); 271 addresslist = address_list_to_stringlist(head->env_from->frm_list);
282 if (addresslist.count()) { 272 if (addresslist.count()) {
283 m->setFrom(addresslist.first()); 273 m->setFrom(addresslist.first());
284 } 274 }
285 } 275 }
286 if (head->env_to!=NULL) { 276 if (head->env_to!=NULL) {
287 addresslist = address_list_to_stringlist(head->env_to->to_list); 277 addresslist = address_list_to_stringlist(head->env_to->to_list);
288 m->setTo(addresslist); 278 m->setTo(addresslist);
289 } 279 }
290 if (head->env_cc!=NULL) { 280 if (head->env_cc!=NULL) {
291 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 281 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
292 m->setCC(addresslist); 282 m->setCC(addresslist);
293 } 283 }
294 if (head->env_bcc!=NULL) { 284 if (head->env_bcc!=NULL) {
295 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
296 m->setBcc(addresslist); 286 m->setBcc(addresslist);
297 } 287 }
298 if (head->env_reply_to!=NULL) { 288 if (head->env_reply_to!=NULL) {
299 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
300 if (addresslist.count()) { 290 if (addresslist.count()) {
301 m->setReplyto(addresslist.first()); 291 m->setReplyto(addresslist.first());
302 } 292 }
303 } 293 }
304 m->setMsgid(QString(head->env_message_id)); 294 m->setMsgid(QString(head->env_message_id));
305 } 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) {
306 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;
307 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));
308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 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);
309 qDebug(da.toString()); 299 qDebug(da.toString());
310 } else { 300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
311 qDebug("Another type"); 301 size = item->att_data.att_static->att_data.att_rfc822_size;
312 } 302 }
313 } 303 }
314 /* msg is already deleted */ 304 /* msg is already deleted */
315 if (mFlags.testBit(FLAG_DELETED) && m) { 305 if (mFlags.testBit(FLAG_DELETED) && m) {
316 delete m; 306 delete m;
317 m = 0; 307 m = 0;
318 } 308 }
319 if (m) { 309 if (m) {
320 m->setFlags(mFlags); 310 m->setFlags(mFlags);
311 m->setMsgsize(size);
321 } 312 }
322 return m; 313 return m;
323} 314}
324 315
325RecBody IMAPwrapper::fetchBody(const RecMail&mail) 316RecBody IMAPwrapper::fetchBody(const RecMail&mail)
326{ 317{
327 RecBody body; 318 RecBody body;
328 const char *mb; 319 const char *mb;
329 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
330 clist *result; 321 clist *result;
331 clistcell *current; 322 clistcell *current;
332 mailimap_fetch_att *fetchAtt; 323 mailimap_fetch_att *fetchAtt;
333 mailimap_fetch_type *fetchType; 324 mailimap_fetch_type *fetchType;
334 mailimap_set *set; 325 mailimap_set *set;
335 mailimap_body*body_desc; 326 mailimap_body*body_desc;
336 327
337 mb = mail.getMbox().latin1(); 328 mb = mail.getMbox().latin1();
338 329
339 login(); 330 login();
340 if (!m_imap) { 331 if (!m_imap) {
341 return body; 332 return body;
342 } 333 }
343 /* select mailbox READONLY for operations */ 334 /* select mailbox READONLY for operations */
344 err = mailimap_examine( m_imap, (char*)mb); 335 err = mailimap_examine( m_imap, (char*)mb);
345 if ( err != MAILIMAP_NO_ERROR ) { 336 if ( err != MAILIMAP_NO_ERROR ) {
346 qDebug("error selecting mailbox: %s",m_imap->imap_response); 337 qDebug("error selecting mailbox: %s",m_imap->imap_response);
347 logout();
348 return body; 338 return body;
349 } 339 }
340
350 result = clist_new(); 341 result = clist_new();
351 /* the range has to start at 1!!! not with 0!!!! */ 342 /* the range has to start at 1!!! not with 0!!!! */
352 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
353 fetchAtt = mailimap_fetch_att_new_body(); 344 fetchAtt = mailimap_fetch_att_new_bodystructure();
354 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
355 err = mailimap_fetch( m_imap, set, fetchType, &result ); 346 err = mailimap_fetch( m_imap, set, fetchType, &result );
356 mailimap_set_free( set ); 347 mailimap_set_free( set );
357 mailimap_fetch_type_free( fetchType ); 348 mailimap_fetch_type_free( fetchType );
358 349
359 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
360 mailimap_msg_att * msg_att; 351 mailimap_msg_att * msg_att;
361 msg_att = (mailimap_msg_att*)current->data; 352 msg_att = (mailimap_msg_att*)current->data;
362 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;
363 body_desc = item->att_data.att_static->att_data.att_body; 354 body_desc = item->att_data.att_static->att_data.att_body;
364 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
365 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
366 } else { 357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
358 qDebug("Mulitpart mail");
359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body,0);
367 } 360 }
368
369 } else { 361 } else {
370 qDebug("error fetching body: %s",m_imap->imap_response); 362 qDebug("error fetching body: %s",m_imap->imap_response);
371 } 363 }
372 364 mailimap_fetch_list_free(result);
373 clist_free(result);
374 logout();
375 return body; 365 return body;
376} 366}
377 367
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
370 routines 'cause we can not simply fetch the whole body. */
378void 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)
379{ 372{
380 if (!mailDescription) { 373 if (!mailDescription) {
381 return; 374 return;
382 } 375 }
376 QString sub;
383 switch (mailDescription->bd_type) { 377 switch (mailDescription->bd_type) {
378 case MAILIMAP_BODY_TYPE_1PART_MSG:
379 target_body.setType("text");
380 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
381 target_body.setSubtype(sub.lower());
382 fillPlainBody(mail,target_body);
383 break;
384 case MAILIMAP_BODY_TYPE_1PART_TEXT: 384 case MAILIMAP_BODY_TYPE_1PART_TEXT:
385 fillPlainBody(mail,target_body,mailDescription->bd_data.bd_type_text); 385 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
386 target_body.setType("text");
387 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
388 target_body.setSubtype(sub.lower());
389 fillPlainBody(mail,target_body);
386 break; 390 break;
387 default: 391 default:
388 break; 392 break;
389 } 393 }
390 return; 394 return;
391} 395}
392 396
393void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * bd) 397void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body)
394{ 398{
395 const char *mb; 399 const char *mb;
396 QString body=""; 400 QString body="";
397 int err = MAILIMAP_NO_ERROR; 401 int err = MAILIMAP_NO_ERROR;
398 clist *result; 402 clist *result;
399 clistcell *current,*cur; 403 clistcell *current,*cur;
400 mailimap_fetch_att *fetchAtt; 404 mailimap_fetch_att *fetchAtt;
401 mailimap_fetch_type *fetchType; 405 mailimap_fetch_type *fetchType;
402 mailimap_set *set; 406 mailimap_set *set;
403 407
404 mb = mail.getMbox().latin1(); 408 mb = mail.getMbox().latin1();
405 409
406 if (!m_imap) { 410 if (!m_imap) {
407 return; 411 return;
408 } 412 }
409 413
410 result = clist_new(); 414 result = clist_new();
411 set = set = mailimap_set_new_single(mail.getNumber()); 415 set = set = mailimap_set_new_single(mail.getNumber());
412 mailimap_section * section = mailimap_section_new_text(); 416 mailimap_section * section = mailimap_section_new_text();
413 fetchAtt = mailimap_fetch_att_new_body_peek_section(section); 417 fetchAtt = mailimap_fetch_att_new_body_peek_section(section);
414 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 418 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
415 err = mailimap_fetch( m_imap, set, fetchType, &result ); 419 err = mailimap_fetch( m_imap, set, fetchType, &result );
416 mailimap_set_free( set ); 420 mailimap_set_free( set );
417 mailimap_fetch_type_free( fetchType ); 421 mailimap_fetch_type_free( fetchType );
418 422
419 423
420 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 424 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
421 mailimap_msg_att * msg_att; 425 mailimap_msg_att * msg_att;
422 msg_att = (mailimap_msg_att*)current->data; 426 msg_att = (mailimap_msg_att*)current->data;
423 mailimap_msg_att_item*msg_att_item; 427 mailimap_msg_att_item*msg_att_item;
424 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 428 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
425 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 429 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
426 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 430 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
427 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 431 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
428 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 432 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
429 int length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
430 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 433 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
431 body = QString(text); 434 if (text) {
432 free(text); 435 body = QString(text);
436 free(text);
437 } else {
438 body = "";
439 }
433 } 440 }
434 } 441 }
435 } 442 }
436 443
437 } else { 444 } else {
438 qDebug("error fetching text: %s",m_imap->imap_response); 445 qDebug("error fetching text: %s",m_imap->imap_response);
439 } 446 }
440 //clist_free(result);
441 mailimap_fetch_list_free(result); 447 mailimap_fetch_list_free(result);
442 target_body.setBodytext(body); 448 target_body.setBodytext(body);
443 return; 449 return;
444} 450}
445 451
446QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 452QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
447{ 453{
448 QStringList l; 454 QStringList l;
449 QString from; 455 QString from;
450 bool named_from; 456 bool named_from;
451 clistcell *current = NULL; 457 clistcell *current = NULL;
452 mailimap_address * current_address=NULL; 458 mailimap_address * current_address=NULL;
453 if (!list) { 459 if (!list) {
454 return l; 460 return l;
455 } 461 }
456 current = clist_begin(list);
457 unsigned int count = 0; 462 unsigned int count = 0;
458 while (current!= NULL) { 463 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
459 from = ""; 464 from = "";
460 named_from = false; 465 named_from = false;
461 current_address=(mailimap_address*)current->data; 466 current_address=(mailimap_address*)current->data;
462 current = current->next;
463 if (current_address->ad_personal_name){ 467 if (current_address->ad_personal_name){
464 from+=QString(current_address->ad_personal_name); 468 from+=QString(current_address->ad_personal_name);
465 from+=" "; 469 from+=" ";
466 named_from = true; 470 named_from = true;
467 } 471 }
468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 472 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
469 from+="<"; 473 from+="<";
470 } 474 }
471 if (current_address->ad_mailbox_name) { 475 if (current_address->ad_mailbox_name) {
472 from+=QString(current_address->ad_mailbox_name); 476 from+=QString(current_address->ad_mailbox_name);
473 from+="@"; 477 from+="@";
474 } 478 }
475 if (current_address->ad_host_name) { 479 if (current_address->ad_host_name) {
476 from+=QString(current_address->ad_host_name); 480 from+=QString(current_address->ad_host_name);
477 } 481 }
478 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 482 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
479 from+=">"; 483 from+=">";
480 } 484 }
481 l.append(QString(from)); 485 l.append(QString(from));
482 if (++count > 99) { 486 if (++count > 99) {
483 break; 487 break;
484 } 488 }
485 } 489 }
486 return l; 490 return l;
487} 491}
492
493void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion)
494{
495 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
496 if (!mailDescription||current_recursion==2) {
497 return;
498 }
499 qDebug("Mediatype: %s",mailDescription->bd_media_subtype);
500 clistcell*current;
501 mailimap_body*current_body;
502 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
503 current_body = (mailimap_body*)current->data;
504 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
505 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1);
506 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
507 RecPart currentPart;
508 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
509 target_body.addPart(currentPart);
510 }
511 }
512 if (current_recursion==0) {
513
514 }
515}
516
517void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
518{
519 if (!Description) {
520 return;
521 }
522 switch (Description->bd_type) {
523 case MAILIMAP_BODY_TYPE_1PART_TEXT:
524 target_part.setType("text");
525 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
526 break;
527 case MAILIMAP_BODY_TYPE_1PART_BASIC:
528 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
529 break;
530 default:
531 break;
532 }
533}
534
535void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
536{
537 if (!which) {
538 return;
539 }
540 QString sub;
541 sub = which->bd_media_text;
542 target_part.setSubtype(sub.lower());
543 target_part.setLines(which->bd_lines);
544 fillBodyFields(target_part,which->bd_fields);
545}
546
547void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
548{
549 if (!which) {
550 return;
551 }
552 QString type,sub;
553 switch (which->bd_media_basic->med_type) {
554 case MAILIMAP_MEDIA_BASIC_APPLICATION:
555 type = "application";
556 break;
557 case MAILIMAP_MEDIA_BASIC_AUDIO:
558 type = "audio";
559 break;
560 case MAILIMAP_MEDIA_BASIC_IMAGE:
561 type = "image";
562 break;
563 case MAILIMAP_MEDIA_BASIC_MESSAGE:
564 type = "message";
565 break;
566 case MAILIMAP_MEDIA_BASIC_VIDEO:
567 type = "video";
568 break;
569 case MAILIMAP_MEDIA_BASIC_OTHER:
570 default:
571 if (which->bd_media_basic->med_basic_type) {
572 type = which->bd_media_basic->med_basic_type;
573 } else {
574 type = "";
575 }
576 break;
577 }
578 if (which->bd_media_basic->med_subtype) {
579 sub = which->bd_media_basic->med_subtype;
580 } else {
581 sub = "";
582 }
583 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
584 target_part.setType(type.lower());
585 target_part.setSubtype(sub.lower());
586 fillBodyFields(target_part,which->bd_fields);
587}
588
589void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
590{
591 if (!which) return;
592 if (which->bd_id) {
593 qDebug("Part ID = %s",which->bd_id);
594 target_part.setIdentifier(which->bd_id);
595 } else {
596 qDebug("ID empty");
597 target_part.setIdentifier("");
598 }
599
600 clistcell*cur;
601 mailimap_single_body_fld_param*param;
602 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
603 param = (mailimap_single_body_fld_param*)cur->data;
604 }
605}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 90f3004..f809edb 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,39 +1,52 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10struct mailimap_body_type_basic;
11struct mailimap_body_type_mpart;
12struct mailimap_body_fields;
10struct mailimap_msg_att; 13struct mailimap_msg_att;
11class RecMail; 14class RecMail;
12class RecBody; 15class RecBody;
16class RecPart;
13 17
14class IMAPwrapper : public QObject 18class IMAPwrapper : public QObject
15{ 19{
16 Q_OBJECT 20 Q_OBJECT
17 21
18public: 22public:
19 IMAPwrapper( IMAPaccount *a ); 23 IMAPwrapper( IMAPaccount *a );
20 virtual ~IMAPwrapper(); 24 virtual ~IMAPwrapper();
21 QList<IMAPFolder>* listFolders(); 25 QList<IMAPFolder>* listFolders();
22 void listMessages(const QString & mailbox,QList<RecMail>&target ); 26 void listMessages(const QString & mailbox,QList<RecMail>&target );
23 RecBody fetchBody(const RecMail&mail); 27 RecBody fetchBody(const RecMail&mail);
24 static void imap_progress( size_t current, size_t maximum ); 28 static void imap_progress( size_t current, size_t maximum );
25 29
26protected: 30protected:
27 RecMail*parse_list_result(mailimap_msg_att*); 31 RecMail*parse_list_result(mailimap_msg_att*);
28 void login(); 32 void login();
29 void logout(); 33 void logout();
34
30 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
31 void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body); 36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion);
37
38 void fillPlainBody(const RecMail&mail,RecBody&target_body);
39 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
40 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
41 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
42
43 /* just helpers */
44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
32 static QStringList address_list_to_stringlist(clist*list); 45 static QStringList address_list_to_stringlist(clist*list);
33 46
34private: 47private:
35 IMAPaccount *account; 48 IMAPaccount *account;
36 mailimap *m_imap; 49 mailimap *m_imap;
37}; 50};
38 51
39#endif 52#endif
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index f9e5794..0e3174d 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,158 +1,189 @@
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_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_number = old.msg_number; 25 msg_number = old.msg_number;
25 from = old.from; 26 from = old.from;
26 msg_flags = old.msg_flags; 27 msg_flags = old.msg_flags;
27 to = old.to; 28 to = old.to;
28 cc = old.cc; 29 cc = old.cc;
29 bcc = old.bcc; 30 bcc = old.bcc;
30} 31}
31 32
32void RecMail::init() 33void RecMail::init()
33{ 34{
34 to.clear(); 35 to.clear();
35 cc.clear(); 36 cc.clear();
36 bcc.clear(); 37 bcc.clear();
37} 38}
38 39
39void RecMail::setTo(const QStringList&list) 40void RecMail::setTo(const QStringList&list)
40{ 41{
41 to = list; 42 to = list;
42} 43}
43 44
44const QStringList&RecMail::To()const 45const QStringList&RecMail::To()const
45{ 46{
46 return to; 47 return to;
47} 48}
48 49
49void RecMail::setCC(const QStringList&list) 50void RecMail::setCC(const QStringList&list)
50{ 51{
51 cc = list; 52 cc = list;
52} 53}
53 54
54const QStringList&RecMail::CC()const 55const QStringList&RecMail::CC()const
55{ 56{
56 return cc; 57 return cc;
57} 58}
58 59
59void RecMail::setBcc(const QStringList&list) 60void RecMail::setBcc(const QStringList&list)
60{ 61{
61 bcc = list; 62 bcc = list;
62} 63}
63 64
64const QStringList& RecMail::Bcc()const 65const QStringList& RecMail::Bcc()const
65{ 66{
66 return bcc; 67 return bcc;
67} 68}
68 69
69RecPart::RecPart() 70RecPart::RecPart()
70 : m_type(""),m_subtype(""),m_identifier(""),m_encoding("") 71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0)
71{ 72{
72} 73}
73 74
74RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding) 75RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding,unsigned int lines)
75 : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding) 76 : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding),m_lines(lines)
76{ 77{
77} 78}
78 79
79RecPart::~RecPart() 80RecPart::~RecPart()
80{ 81{
81} 82}
82 83
84void RecPart::setLines(unsigned int lines)
85{
86 m_lines = lines;
87}
88
89const unsigned int RecPart::Lines()const
90{
91 return m_lines;
92}
93
83const QString& RecPart::Type()const 94const QString& RecPart::Type()const
84{ 95{
85 return m_type; 96 return m_type;
86} 97}
87 98
88void RecPart::setType(const QString&type) 99void RecPart::setType(const QString&type)
89{ 100{
90 m_type = type; 101 m_type = type;
91} 102}
92 103
93const QString& RecPart::Subtype()const 104const QString& RecPart::Subtype()const
94{ 105{
95 return m_subtype; 106 return m_subtype;
96} 107}
97 108
98void RecPart::setSubtype(const QString&subtype) 109void RecPart::setSubtype(const QString&subtype)
99{ 110{
100 m_subtype = subtype; 111 m_subtype = subtype;
101} 112}
102 113
103const QString& RecPart::Identifier()const 114const QString& RecPart::Identifier()const
104{ 115{
105 return m_identifier; 116 return m_identifier;
106} 117}
107 118
108void RecPart::setIdentifier(const QString&identifier) 119void RecPart::setIdentifier(const QString&identifier)
109{ 120{
110 m_identifier = identifier; 121 m_identifier = identifier;
111} 122}
112 123
113const QString& RecPart::Encoding()const 124const QString& RecPart::Encoding()const
114{ 125{
115 return m_encoding; 126 return m_encoding;
116} 127}
117 128
118void RecPart::setEncoding(const QString&encoding) 129void RecPart::setEncoding(const QString&encoding)
119{ 130{
120 m_encoding = encoding; 131 m_encoding = encoding;
121} 132}
122 133
123RecBody::RecBody() 134RecBody::RecBody()
124 : m_BodyText(""),m_PartsList() 135 : m_BodyText(""),m_PartsList()
125{ 136{
126 m_PartsList.setAutoDelete(true); 137 m_PartsList.setAutoDelete(true);
127} 138}
128 139
129RecBody::~RecBody() 140RecBody::~RecBody()
130{ 141{
131} 142}
132 143
133void RecBody::setBodytext(const QString&bodyText) 144void RecBody::setBodytext(const QString&bodyText)
134{ 145{
135 m_BodyText = bodyText; 146 m_BodyText = bodyText;
136} 147}
137 148
138const QString& RecBody::Bodytext()const 149const QString& RecBody::Bodytext()const
139{ 150{
140 return m_BodyText; 151 return m_BodyText;
141} 152}
142 153
143void RecBody::setParts(const QList<RecPart>&parts) 154void RecBody::setParts(const QList<RecPart>&parts)
144{ 155{
145 m_PartsList = parts; 156 m_PartsList = parts;
146 m_PartsList.setAutoDelete(true); 157 m_PartsList.setAutoDelete(true);
147} 158}
148 159
149const QList<RecPart>& RecBody::Parts()const 160const QList<RecPart>& RecBody::Parts()const
150{ 161{
151 return m_PartsList; 162 return m_PartsList;
152} 163}
153 164
154void RecBody::addPart(const RecPart& part) 165void RecBody::addPart(const RecPart& part)
155{ 166{
156 RecPart*p = new RecPart(part); 167 RecPart*p = new RecPart(part);
157 m_PartsList.append(p); 168 m_PartsList.append(p);
158} 169}
170
171void RecBody::setType(const QString&type)
172{
173 m_type = type;
174}
175
176const QString& RecBody::Type()const
177{
178 return m_type;
179}
180
181void RecBody::setSubtype(const QString&type)
182{
183 m_subtype = type;
184}
185
186const QString& RecBody::Subtype()const
187{
188 return m_subtype;
189}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 6d6b080..900f10a 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -1,105 +1,115 @@
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 15
16/* a class to describe mails in a mailbox */ 16/* a class to describe mails in a mailbox */
17/* Attention! 17/* Attention!
18 From programmers point of view it would make sense to 18 From programmers point of view it would make sense to
19 store the mail body into this class, too. 19 store the mail body into this class, too.
20 But: not from the point of view of the device. 20 But: not from the point of view of the device.
21 Mailbodies can be real large. So we request them when 21 Mailbodies can be real large. So we request them when
22 needed from the mail-wrapper class direct from the server itself 22 needed from the mail-wrapper class direct from the server itself
23 (imap) or from a file-based cache (pop3?) 23 (imap) or from a file-based cache (pop3?)
24 So there is no interface "const QString&body()" but you should 24 So there is no interface "const QString&body()" but you should
25 make a request to the mailwrapper with this class as parameter to 25 make a request to the mailwrapper with this class as parameter to
26 get the body. Same words for the attachments. 26 get the body. Same words for the attachments.
27*/ 27*/
28class RecMail 28class RecMail
29{ 29{
30public: 30public:
31 RecMail(); 31 RecMail();
32 RecMail(const RecMail&old); 32 RecMail(const RecMail&old);
33 virtual ~RecMail(){} 33 virtual ~RecMail(){}
34 34
35 const int getNumber()const{return msg_number;} 35 const int getNumber()const{return msg_number;}
36 void setNumber(int number){msg_number=number;} 36 void setNumber(int number){msg_number=number;}
37 const QString&getDate()const{ return date; } 37 const QString&getDate()const{ return date; }
38 void setDate( const QString&a ) { date = a; } 38 void setDate( const QString&a ) { date = a; }
39 const QString&getFrom()const{ return from; } 39 const QString&getFrom()const{ return from; }
40 void setFrom( const QString&a ) { from = a; } 40 void setFrom( const QString&a ) { from = a; }
41 const QString&getSubject()const { return subject; } 41 const QString&getSubject()const { return subject; }
42 void setSubject( const QString&s ) { subject = s; } 42 void setSubject( const QString&s ) { subject = s; }
43 const QString&getMbox()const{return mbox;} 43 const QString&getMbox()const{return mbox;}
44 void setMbox(const QString&box){mbox = box;} 44 void setMbox(const QString&box){mbox = box;}
45 void setMsgid(const QString&id){msg_id=id;} 45 void setMsgid(const QString&id){msg_id=id;}
46 const QString&Msgid()const{return msg_id;} 46 const QString&Msgid()const{return msg_id;}
47 void setReplyto(const QString&reply){replyto=reply;} 47 void setReplyto(const QString&reply){replyto=reply;}
48 const QString&Replyto()const{return replyto;} 48 const QString&Replyto()const{return replyto;}
49 void setMsgsize(int size){msg_size = size;}
50 const int Msgsize()const{return msg_size;}
49 51
50 52
51 void setTo(const QStringList&list); 53 void setTo(const QStringList&list);
52 const QStringList&To()const; 54 const QStringList&To()const;
53 void setCC(const QStringList&list); 55 void setCC(const QStringList&list);
54 const QStringList&CC()const; 56 const QStringList&CC()const;
55 void setBcc(const QStringList&list); 57 void setBcc(const QStringList&list);
56 const QStringList&Bcc()const; 58 const QStringList&Bcc()const;
57 const QBitArray&getFlags()const{return msg_flags;} 59 const QBitArray&getFlags()const{return msg_flags;}
58 void setFlags(const QBitArray&flags){msg_flags = flags;} 60 void setFlags(const QBitArray&flags){msg_flags = flags;}
59 61
60protected: 62protected:
61 QString subject,date,from,mbox,msg_id,replyto; 63 QString subject,date,from,mbox,msg_id,replyto;
62 int msg_number; 64 int msg_number,msg_size;
63 QBitArray msg_flags; 65 QBitArray msg_flags;
64 QStringList to,cc,bcc; 66 QStringList to,cc,bcc;
65 void init(); 67 void init();
66 void copy_old(const RecMail&old); 68 void copy_old(const RecMail&old);
67}; 69};
68 70
69class RecPart 71class RecPart
70{ 72{
71protected: 73protected:
72 QString m_type,m_subtype,m_identifier,m_encoding; 74 QString m_type,m_subtype,m_identifier,m_encoding;
75 unsigned int m_lines;
73public: 76public:
74 RecPart(); 77 RecPart();
75 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); 78 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64",unsigned int lines=0);
76 virtual ~RecPart(); 79 virtual ~RecPart();
77 80
78 const QString&Type()const; 81 const QString&Type()const;
79 void setType(const QString&type); 82 void setType(const QString&type);
80 const QString&Subtype()const; 83 const QString&Subtype()const;
81 void setSubtype(const QString&subtype); 84 void setSubtype(const QString&subtype);
82 const QString&Identifier()const; 85 const QString&Identifier()const;
83 void setIdentifier(const QString&identifier); 86 void setIdentifier(const QString&identifier);
84 const QString&Encoding()const; 87 const QString&Encoding()const;
85 void setEncoding(const QString&encoding); 88 void setEncoding(const QString&encoding);
89 void setLines(unsigned int lines);
90 const unsigned int Lines()const;
86}; 91};
87 92
88class RecBody 93class RecBody
89{ 94{
90protected: 95protected:
91 QString m_BodyText; 96 QString m_BodyText,m_type,m_subtype;
92 QList<RecPart> m_PartsList; 97 QList<RecPart> m_PartsList;
93 98
94public: 99public:
95 RecBody(); 100 RecBody();
96 virtual ~RecBody(); 101 virtual ~RecBody();
97 void setBodytext(const QString&); 102 void setBodytext(const QString&);
98 const QString& Bodytext()const; 103 const QString& Bodytext()const;
104 void setType(const QString&);
105 const QString&Type()const;
106 void setSubtype(const QString&);
107 const QString&Subtype()const;
108
99 109
100 void setParts(const QList<RecPart>&parts); 110 void setParts(const QList<RecPart>&parts);
101 const QList<RecPart>& Parts()const; 111 const QList<RecPart>& Parts()const;
102 void addPart(const RecPart&part); 112 void addPart(const RecPart&part);
103}; 113};
104 114
105#endif 115#endif
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
index f9e5794..0e3174d 100644
--- a/noncore/net/mail/mailtypes.cpp
+++ b/noncore/net/mail/mailtypes.cpp
@@ -1,158 +1,189 @@
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_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_number = old.msg_number; 25 msg_number = old.msg_number;
25 from = old.from; 26 from = old.from;
26 msg_flags = old.msg_flags; 27 msg_flags = old.msg_flags;
27 to = old.to; 28 to = old.to;
28 cc = old.cc; 29 cc = old.cc;
29 bcc = old.bcc; 30 bcc = old.bcc;
30} 31}
31 32
32void RecMail::init() 33void RecMail::init()
33{ 34{
34 to.clear(); 35 to.clear();
35 cc.clear(); 36 cc.clear();
36 bcc.clear(); 37 bcc.clear();
37} 38}
38 39
39void RecMail::setTo(const QStringList&list) 40void RecMail::setTo(const QStringList&list)
40{ 41{
41 to = list; 42 to = list;
42} 43}
43 44
44const QStringList&RecMail::To()const 45const QStringList&RecMail::To()const
45{ 46{
46 return to; 47 return to;
47} 48}
48 49
49void RecMail::setCC(const QStringList&list) 50void RecMail::setCC(const QStringList&list)
50{ 51{
51 cc = list; 52 cc = list;
52} 53}
53 54
54const QStringList&RecMail::CC()const 55const QStringList&RecMail::CC()const
55{ 56{
56 return cc; 57 return cc;
57} 58}
58 59
59void RecMail::setBcc(const QStringList&list) 60void RecMail::setBcc(const QStringList&list)
60{ 61{
61 bcc = list; 62 bcc = list;
62} 63}
63 64
64const QStringList& RecMail::Bcc()const 65const QStringList& RecMail::Bcc()const
65{ 66{
66 return bcc; 67 return bcc;
67} 68}
68 69
69RecPart::RecPart() 70RecPart::RecPart()
70 : m_type(""),m_subtype(""),m_identifier(""),m_encoding("") 71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0)
71{ 72{
72} 73}
73 74
74RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding) 75RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding,unsigned int lines)
75 : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding) 76 : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding),m_lines(lines)
76{ 77{
77} 78}
78 79
79RecPart::~RecPart() 80RecPart::~RecPart()
80{ 81{
81} 82}
82 83
84void RecPart::setLines(unsigned int lines)
85{
86 m_lines = lines;
87}
88
89const unsigned int RecPart::Lines()const
90{
91 return m_lines;
92}
93
83const QString& RecPart::Type()const 94const QString& RecPart::Type()const
84{ 95{
85 return m_type; 96 return m_type;
86} 97}
87 98
88void RecPart::setType(const QString&type) 99void RecPart::setType(const QString&type)
89{ 100{
90 m_type = type; 101 m_type = type;
91} 102}
92 103
93const QString& RecPart::Subtype()const 104const QString& RecPart::Subtype()const
94{ 105{
95 return m_subtype; 106 return m_subtype;
96} 107}
97 108
98void RecPart::setSubtype(const QString&subtype) 109void RecPart::setSubtype(const QString&subtype)
99{ 110{
100 m_subtype = subtype; 111 m_subtype = subtype;
101} 112}
102 113
103const QString& RecPart::Identifier()const 114const QString& RecPart::Identifier()const
104{ 115{
105 return m_identifier; 116 return m_identifier;
106} 117}
107 118
108void RecPart::setIdentifier(const QString&identifier) 119void RecPart::setIdentifier(const QString&identifier)
109{ 120{
110 m_identifier = identifier; 121 m_identifier = identifier;
111} 122}
112 123
113const QString& RecPart::Encoding()const 124const QString& RecPart::Encoding()const
114{ 125{
115 return m_encoding; 126 return m_encoding;
116} 127}
117 128
118void RecPart::setEncoding(const QString&encoding) 129void RecPart::setEncoding(const QString&encoding)
119{ 130{
120 m_encoding = encoding; 131 m_encoding = encoding;
121} 132}
122 133
123RecBody::RecBody() 134RecBody::RecBody()
124 : m_BodyText(""),m_PartsList() 135 : m_BodyText(""),m_PartsList()
125{ 136{
126 m_PartsList.setAutoDelete(true); 137 m_PartsList.setAutoDelete(true);
127} 138}
128 139
129RecBody::~RecBody() 140RecBody::~RecBody()
130{ 141{
131} 142}
132 143
133void RecBody::setBodytext(const QString&bodyText) 144void RecBody::setBodytext(const QString&bodyText)
134{ 145{
135 m_BodyText = bodyText; 146 m_BodyText = bodyText;
136} 147}
137 148
138const QString& RecBody::Bodytext()const 149const QString& RecBody::Bodytext()const
139{ 150{
140 return m_BodyText; 151 return m_BodyText;
141} 152}
142 153
143void RecBody::setParts(const QList<RecPart>&parts) 154void RecBody::setParts(const QList<RecPart>&parts)
144{ 155{
145 m_PartsList = parts; 156 m_PartsList = parts;
146 m_PartsList.setAutoDelete(true); 157 m_PartsList.setAutoDelete(true);
147} 158}
148 159
149const QList<RecPart>& RecBody::Parts()const 160const QList<RecPart>& RecBody::Parts()const
150{ 161{
151 return m_PartsList; 162 return m_PartsList;
152} 163}
153 164
154void RecBody::addPart(const RecPart& part) 165void RecBody::addPart(const RecPart& part)
155{ 166{
156 RecPart*p = new RecPart(part); 167 RecPart*p = new RecPart(part);
157 m_PartsList.append(p); 168 m_PartsList.append(p);
158} 169}
170
171void RecBody::setType(const QString&type)
172{
173 m_type = type;
174}
175
176const QString& RecBody::Type()const
177{
178 return m_type;
179}
180
181void RecBody::setSubtype(const QString&type)
182{
183 m_subtype = type;
184}
185
186const QString& RecBody::Subtype()const
187{
188 return m_subtype;
189}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index 6d6b080..900f10a 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -1,105 +1,115 @@
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 15
16/* a class to describe mails in a mailbox */ 16/* a class to describe mails in a mailbox */
17/* Attention! 17/* Attention!
18 From programmers point of view it would make sense to 18 From programmers point of view it would make sense to
19 store the mail body into this class, too. 19 store the mail body into this class, too.
20 But: not from the point of view of the device. 20 But: not from the point of view of the device.
21 Mailbodies can be real large. So we request them when 21 Mailbodies can be real large. So we request them when
22 needed from the mail-wrapper class direct from the server itself 22 needed from the mail-wrapper class direct from the server itself
23 (imap) or from a file-based cache (pop3?) 23 (imap) or from a file-based cache (pop3?)
24 So there is no interface "const QString&body()" but you should 24 So there is no interface "const QString&body()" but you should
25 make a request to the mailwrapper with this class as parameter to 25 make a request to the mailwrapper with this class as parameter to
26 get the body. Same words for the attachments. 26 get the body. Same words for the attachments.
27*/ 27*/
28class RecMail 28class RecMail
29{ 29{
30public: 30public:
31 RecMail(); 31 RecMail();
32 RecMail(const RecMail&old); 32 RecMail(const RecMail&old);
33 virtual ~RecMail(){} 33 virtual ~RecMail(){}
34 34
35 const int getNumber()const{return msg_number;} 35 const int getNumber()const{return msg_number;}
36 void setNumber(int number){msg_number=number;} 36 void setNumber(int number){msg_number=number;}
37 const QString&getDate()const{ return date; } 37 const QString&getDate()const{ return date; }
38 void setDate( const QString&a ) { date = a; } 38 void setDate( const QString&a ) { date = a; }
39 const QString&getFrom()const{ return from; } 39 const QString&getFrom()const{ return from; }
40 void setFrom( const QString&a ) { from = a; } 40 void setFrom( const QString&a ) { from = a; }
41 const QString&getSubject()const { return subject; } 41 const QString&getSubject()const { return subject; }
42 void setSubject( const QString&s ) { subject = s; } 42 void setSubject( const QString&s ) { subject = s; }
43 const QString&getMbox()const{return mbox;} 43 const QString&getMbox()const{return mbox;}
44 void setMbox(const QString&box){mbox = box;} 44 void setMbox(const QString&box){mbox = box;}
45 void setMsgid(const QString&id){msg_id=id;} 45 void setMsgid(const QString&id){msg_id=id;}
46 const QString&Msgid()const{return msg_id;} 46 const QString&Msgid()const{return msg_id;}
47 void setReplyto(const QString&reply){replyto=reply;} 47 void setReplyto(const QString&reply){replyto=reply;}
48 const QString&Replyto()const{return replyto;} 48 const QString&Replyto()const{return replyto;}
49 void setMsgsize(int size){msg_size = size;}
50 const int Msgsize()const{return msg_size;}
49 51
50 52
51 void setTo(const QStringList&list); 53 void setTo(const QStringList&list);
52 const QStringList&To()const; 54 const QStringList&To()const;
53 void setCC(const QStringList&list); 55 void setCC(const QStringList&list);
54 const QStringList&CC()const; 56 const QStringList&CC()const;
55 void setBcc(const QStringList&list); 57 void setBcc(const QStringList&list);
56 const QStringList&Bcc()const; 58 const QStringList&Bcc()const;
57 const QBitArray&getFlags()const{return msg_flags;} 59 const QBitArray&getFlags()const{return msg_flags;}
58 void setFlags(const QBitArray&flags){msg_flags = flags;} 60 void setFlags(const QBitArray&flags){msg_flags = flags;}
59 61
60protected: 62protected:
61 QString subject,date,from,mbox,msg_id,replyto; 63 QString subject,date,from,mbox,msg_id,replyto;
62 int msg_number; 64 int msg_number,msg_size;
63 QBitArray msg_flags; 65 QBitArray msg_flags;
64 QStringList to,cc,bcc; 66 QStringList to,cc,bcc;
65 void init(); 67 void init();
66 void copy_old(const RecMail&old); 68 void copy_old(const RecMail&old);
67}; 69};
68 70
69class RecPart 71class RecPart
70{ 72{
71protected: 73protected:
72 QString m_type,m_subtype,m_identifier,m_encoding; 74 QString m_type,m_subtype,m_identifier,m_encoding;
75 unsigned int m_lines;
73public: 76public:
74 RecPart(); 77 RecPart();
75 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); 78 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64",unsigned int lines=0);
76 virtual ~RecPart(); 79 virtual ~RecPart();
77 80
78 const QString&Type()const; 81 const QString&Type()const;
79 void setType(const QString&type); 82 void setType(const QString&type);
80 const QString&Subtype()const; 83 const QString&Subtype()const;
81 void setSubtype(const QString&subtype); 84 void setSubtype(const QString&subtype);
82 const QString&Identifier()const; 85 const QString&Identifier()const;
83 void setIdentifier(const QString&identifier); 86 void setIdentifier(const QString&identifier);
84 const QString&Encoding()const; 87 const QString&Encoding()const;
85 void setEncoding(const QString&encoding); 88 void setEncoding(const QString&encoding);
89 void setLines(unsigned int lines);
90 const unsigned int Lines()const;
86}; 91};
87 92
88class RecBody 93class RecBody
89{ 94{
90protected: 95protected:
91 QString m_BodyText; 96 QString m_BodyText,m_type,m_subtype;
92 QList<RecPart> m_PartsList; 97 QList<RecPart> m_PartsList;
93 98
94public: 99public:
95 RecBody(); 100 RecBody();
96 virtual ~RecBody(); 101 virtual ~RecBody();
97 void setBodytext(const QString&); 102 void setBodytext(const QString&);
98 const QString& Bodytext()const; 103 const QString& Bodytext()const;
104 void setType(const QString&);
105 const QString&Type()const;
106 void setSubtype(const QString&);
107 const QString&Subtype()const;
108
99 109
100 void setParts(const QList<RecPart>&parts); 110 void setParts(const QList<RecPart>&parts);
101 const QList<RecPart>& Parts()const; 111 const QList<RecPart>& Parts()const;
102 void addPart(const RecPart&part); 112 void addPart(const RecPart&part);
103}; 113};
104 114
105#endif 115#endif