summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-13 21:03:45 (UTC)
committer alwin <alwin>2003-12-13 21:03:45 (UTC)
commitc0e86973b0cd2d01163ccf60340c8d295aa645f4 (patch) (unidiff)
tree4ccb0f7b8071711bf7ebc5320ea5c2f6974d6fb4
parent85444223acfafd9d7955032b2cbdad3279ba27ad (diff)
downloadopie-c0e86973b0cd2d01163ccf60340c8d295aa645f4.zip
opie-c0e86973b0cd2d01163ccf60340c8d295aa645f4.tar.gz
opie-c0e86973b0cd2d01163ccf60340c8d295aa645f4.tar.bz2
the RecMail class get on creation a mailwrapper assigened
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp1
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp1
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp17
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h7
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp1
-rw-r--r--noncore/net/mail/mailtypes.cpp17
-rw-r--r--noncore/net/mail/mailtypes.h7
-rw-r--r--noncore/net/mail/pop3wrapper.cpp1
8 files changed, 50 insertions, 2 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index e5eb335..3222c7e 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,645 +1,646 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this);
134 target.append(m); 135 target.append(m);
135 } 136 }
136 } 137 }
137 } else { 138 } else {
138 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
139 } 140 }
140 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
141} 142}
142 143
143QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
144{ 145{
145 const char *path, *mask; 146 const char *path, *mask;
146 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
147 clist *result; 148 clist *result;
148 clistcell *current; 149 clistcell *current;
149 150
150 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
151 folders->setAutoDelete( true ); 152 folders->setAutoDelete( true );
152 login(); 153 login();
153 if (!m_imap) { 154 if (!m_imap) {
154 return folders; 155 return folders;
155 } 156 }
156 157
157/* 158/*
158 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
159 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
160 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
161 */ 162 */
162 QString temp; 163 QString temp;
163 mask = "INBOX" ; 164 mask = "INBOX" ;
164 result = clist_new(); 165 result = clist_new();
165 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
166 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
167 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
168 current = result->first; 169 current = result->first;
169 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
170 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
171 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
172 // instead of using strdup! 173 // instead of using strdup!
173 temp = list->mb_name; 174 temp = list->mb_name;
174 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
175 current = current->next; 176 current = current->next;
176 } 177 }
177 } else { 178 } else {
178 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
179 } 180 }
180 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
181 182
182/* 183/*
183 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
184 */ 185 */
185 mask = "*" ; 186 mask = "*" ;
186 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
187 if (!path) path = ""; 188 if (!path) path = "";
188 result = clist_new(); 189 result = clist_new();
189 qDebug(path); 190 qDebug(path);
190 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
191 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
192 current = result->first; 193 current = result->first;
193 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
194 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
195 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
196 // instead of using strdup! 197 // instead of using strdup!
197 temp = list->mb_name; 198 temp = list->mb_name;
198 current = current->next; 199 current = current->next;
199 if (temp.lower()=="inbox") 200 if (temp.lower()=="inbox")
200 continue; 201 continue;
201 folders->append(new IMAPFolder(temp)); 202 folders->append(new IMAPFolder(temp));
202 203
203 } 204 }
204 } else { 205 } else {
205 qDebug("error fetching folders %s",m_imap->imap_response); 206 qDebug("error fetching folders %s",m_imap->imap_response);
206 } 207 }
207 mailimap_list_result_free( result ); 208 mailimap_list_result_free( result );
208 return folders; 209 return folders;
209} 210}
210 211
211RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 212RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
212{ 213{
213 RecMail * m = 0; 214 RecMail * m = 0;
214 mailimap_msg_att_item *item=0; 215 mailimap_msg_att_item *item=0;
215 clistcell *current,*c,*cf; 216 clistcell *current,*c,*cf;
216 mailimap_msg_att_dynamic*flist; 217 mailimap_msg_att_dynamic*flist;
217 mailimap_flag_fetch*cflag; 218 mailimap_flag_fetch*cflag;
218 int size; 219 int size;
219 QBitArray mFlags(7); 220 QBitArray mFlags(7);
220 QStringList addresslist; 221 QStringList addresslist;
221 222
222 if (!m_att) { 223 if (!m_att) {
223 return m; 224 return m;
224 } 225 }
225 m = new RecMail(); 226 m = new RecMail();
226 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 227 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
227 current = c; 228 current = c;
228 size = 0; 229 size = 0;
229 item = (mailimap_msg_att_item*)current->data; 230 item = (mailimap_msg_att_item*)current->data;
230 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 231 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
231 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 232 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
232 if (!flist->att_list) { 233 if (!flist->att_list) {
233 continue; 234 continue;
234 } 235 }
235 cf = flist->att_list->first; 236 cf = flist->att_list->first;
236 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 237 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
237 cflag = (mailimap_flag_fetch*)cf->data; 238 cflag = (mailimap_flag_fetch*)cf->data;
238 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 239 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
239 switch (cflag->fl_flag->fl_type) { 240 switch (cflag->fl_flag->fl_type) {
240 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
241 mFlags.setBit(FLAG_ANSWERED); 242 mFlags.setBit(FLAG_ANSWERED);
242 break; 243 break;
243 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
244 mFlags.setBit(FLAG_FLAGGED); 245 mFlags.setBit(FLAG_FLAGGED);
245 break; 246 break;
246 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
247 mFlags.setBit(FLAG_DELETED); 248 mFlags.setBit(FLAG_DELETED);
248 break; 249 break;
249 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
250 mFlags.setBit(FLAG_SEEN); 251 mFlags.setBit(FLAG_SEEN);
251 break; 252 break;
252 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
253 mFlags.setBit(FLAG_DRAFT); 254 mFlags.setBit(FLAG_DRAFT);
254 break; 255 break;
255 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
256 break; 257 break;
257 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
258 break; 259 break;
259 default: 260 default:
260 break; 261 break;
261 } 262 }
262 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 263 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
263 mFlags.setBit(FLAG_RECENT); 264 mFlags.setBit(FLAG_RECENT);
264 } 265 }
265 } 266 }
266 continue; 267 continue;
267 } 268 }
268 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 269 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
269 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 270 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
270 m->setDate(head->env_date); 271 m->setDate(head->env_date);
271 m->setSubject(head->env_subject); 272 m->setSubject(head->env_subject);
272 if (head->env_from!=NULL) { 273 if (head->env_from!=NULL) {
273 addresslist = address_list_to_stringlist(head->env_from->frm_list); 274 addresslist = address_list_to_stringlist(head->env_from->frm_list);
274 if (addresslist.count()) { 275 if (addresslist.count()) {
275 m->setFrom(addresslist.first()); 276 m->setFrom(addresslist.first());
276 } 277 }
277 } 278 }
278 if (head->env_to!=NULL) { 279 if (head->env_to!=NULL) {
279 addresslist = address_list_to_stringlist(head->env_to->to_list); 280 addresslist = address_list_to_stringlist(head->env_to->to_list);
280 m->setTo(addresslist); 281 m->setTo(addresslist);
281 } 282 }
282 if (head->env_cc!=NULL) { 283 if (head->env_cc!=NULL) {
283 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 284 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
284 m->setCC(addresslist); 285 m->setCC(addresslist);
285 } 286 }
286 if (head->env_bcc!=NULL) { 287 if (head->env_bcc!=NULL) {
287 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 288 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
288 m->setBcc(addresslist); 289 m->setBcc(addresslist);
289 } 290 }
290 if (head->env_reply_to!=NULL) { 291 if (head->env_reply_to!=NULL) {
291 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 292 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
292 if (addresslist.count()) { 293 if (addresslist.count()) {
293 m->setReplyto(addresslist.first()); 294 m->setReplyto(addresslist.first());
294 } 295 }
295 } 296 }
296 m->setMsgid(QString(head->env_message_id)); 297 m->setMsgid(QString(head->env_message_id));
297 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 298 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
298 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 299 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
299 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 300 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
300 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); 301 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);
301 qDebug(da.toString()); 302 qDebug(da.toString());
302 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 303 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
303 size = item->att_data.att_static->att_data.att_rfc822_size; 304 size = item->att_data.att_static->att_data.att_rfc822_size;
304 } 305 }
305 } 306 }
306 /* msg is already deleted */ 307 /* msg is already deleted */
307 if (mFlags.testBit(FLAG_DELETED) && m) { 308 if (mFlags.testBit(FLAG_DELETED) && m) {
308 delete m; 309 delete m;
309 m = 0; 310 m = 0;
310 } 311 }
311 if (m) { 312 if (m) {
312 m->setFlags(mFlags); 313 m->setFlags(mFlags);
313 m->setMsgsize(size); 314 m->setMsgsize(size);
314 } 315 }
315 return m; 316 return m;
316} 317}
317 318
318RecBody IMAPwrapper::fetchBody(const RecMail&mail) 319RecBody IMAPwrapper::fetchBody(const RecMail&mail)
319{ 320{
320 RecBody body; 321 RecBody body;
321 const char *mb; 322 const char *mb;
322 int err = MAILIMAP_NO_ERROR; 323 int err = MAILIMAP_NO_ERROR;
323 clist *result; 324 clist *result;
324 clistcell *current; 325 clistcell *current;
325 mailimap_fetch_att *fetchAtt; 326 mailimap_fetch_att *fetchAtt;
326 mailimap_fetch_type *fetchType; 327 mailimap_fetch_type *fetchType;
327 mailimap_set *set; 328 mailimap_set *set;
328 mailimap_body*body_desc; 329 mailimap_body*body_desc;
329 330
330 mb = mail.getMbox().latin1(); 331 mb = mail.getMbox().latin1();
331 332
332 login(); 333 login();
333 if (!m_imap) { 334 if (!m_imap) {
334 return body; 335 return body;
335 } 336 }
336 337
337 err = mailimap_select( m_imap, (char*)mb); 338 err = mailimap_select( m_imap, (char*)mb);
338 if ( err != MAILIMAP_NO_ERROR ) { 339 if ( err != MAILIMAP_NO_ERROR ) {
339 qDebug("error selecting mailbox: %s",m_imap->imap_response); 340 qDebug("error selecting mailbox: %s",m_imap->imap_response);
340 return body; 341 return body;
341 } 342 }
342 343
343 result = clist_new(); 344 result = clist_new();
344 /* the range has to start at 1!!! not with 0!!!! */ 345 /* the range has to start at 1!!! not with 0!!!! */
345 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 346 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
346 fetchAtt = mailimap_fetch_att_new_bodystructure(); 347 fetchAtt = mailimap_fetch_att_new_bodystructure();
347 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 348 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
348 err = mailimap_fetch( m_imap, set, fetchType, &result ); 349 err = mailimap_fetch( m_imap, set, fetchType, &result );
349 mailimap_set_free( set ); 350 mailimap_set_free( set );
350 mailimap_fetch_type_free( fetchType ); 351 mailimap_fetch_type_free( fetchType );
351 352
352 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 353 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
353 mailimap_msg_att * msg_att; 354 mailimap_msg_att * msg_att;
354 msg_att = (mailimap_msg_att*)current->data; 355 msg_att = (mailimap_msg_att*)current->data;
355 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 356 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
356 body_desc = item->att_data.att_static->att_data.att_body; 357 body_desc = item->att_data.att_static->att_data.att_body;
357 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 358 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
358 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 359 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
359 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 360 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
360 qDebug("Mulitpart mail"); 361 qDebug("Mulitpart mail");
361 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 362 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
362 } 363 }
363 } else { 364 } else {
364 qDebug("error fetching body: %s",m_imap->imap_response); 365 qDebug("error fetching body: %s",m_imap->imap_response);
365 } 366 }
366 mailimap_fetch_list_free(result); 367 mailimap_fetch_list_free(result);
367 return body; 368 return body;
368} 369}
369 370
370/* this routine is just called when the mail has only ONE part. 371/* this routine is just called when the mail has only ONE part.
371 for filling the parts of a multi-part-message there are other 372 for filling the parts of a multi-part-message there are other
372 routines 'cause we can not simply fetch the whole body. */ 373 routines 'cause we can not simply fetch the whole body. */
373void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 374void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
374{ 375{
375 if (!mailDescription) { 376 if (!mailDescription) {
376 return; 377 return;
377 } 378 }
378 QString sub,body_text; 379 QString sub,body_text;
379 RecPart singlePart; 380 RecPart singlePart;
380 QValueList<int> path; 381 QValueList<int> path;
381 fillSinglePart(singlePart,mailDescription); 382 fillSinglePart(singlePart,mailDescription);
382 switch (mailDescription->bd_type) { 383 switch (mailDescription->bd_type) {
383 case MAILIMAP_BODY_TYPE_1PART_MSG: 384 case MAILIMAP_BODY_TYPE_1PART_MSG:
384 path.append(1); 385 path.append(1);
385 body_text = fetchPart(mail,path,true); 386 body_text = fetchPart(mail,path,true);
386 target_body.setBodytext(body_text); 387 target_body.setBodytext(body_text);
387 target_body.setDescription(singlePart); 388 target_body.setDescription(singlePart);
388 break; 389 break;
389 case MAILIMAP_BODY_TYPE_1PART_TEXT: 390 case MAILIMAP_BODY_TYPE_1PART_TEXT:
390 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 391 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
391 path.append(1); 392 path.append(1);
392 body_text = fetchPart(mail,path,true); 393 body_text = fetchPart(mail,path,true);
393 target_body.setBodytext(body_text); 394 target_body.setBodytext(body_text);
394 target_body.setDescription(singlePart); 395 target_body.setDescription(singlePart);
395 break; 396 break;
396 case MAILIMAP_BODY_TYPE_1PART_BASIC: 397 case MAILIMAP_BODY_TYPE_1PART_BASIC:
397 qDebug("Single attachment"); 398 qDebug("Single attachment");
398 target_body.setBodytext(""); 399 target_body.setBodytext("");
399 target_body.addPart(singlePart); 400 target_body.addPart(singlePart);
400 break; 401 break;
401 default: 402 default:
402 break; 403 break;
403 } 404 }
404 405
405 return; 406 return;
406} 407}
407 408
408QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 409QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
409{ 410{
410 QStringList l; 411 QStringList l;
411 QString from; 412 QString from;
412 bool named_from; 413 bool named_from;
413 clistcell *current = NULL; 414 clistcell *current = NULL;
414 mailimap_address * current_address=NULL; 415 mailimap_address * current_address=NULL;
415 if (!list) { 416 if (!list) {
416 return l; 417 return l;
417 } 418 }
418 unsigned int count = 0; 419 unsigned int count = 0;
419 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 420 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
420 from = ""; 421 from = "";
421 named_from = false; 422 named_from = false;
422 current_address=(mailimap_address*)current->data; 423 current_address=(mailimap_address*)current->data;
423 if (current_address->ad_personal_name){ 424 if (current_address->ad_personal_name){
424 from+=QString(current_address->ad_personal_name); 425 from+=QString(current_address->ad_personal_name);
425 from+=" "; 426 from+=" ";
426 named_from = true; 427 named_from = true;
427 } 428 }
428 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 429 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
429 from+="<"; 430 from+="<";
430 } 431 }
431 if (current_address->ad_mailbox_name) { 432 if (current_address->ad_mailbox_name) {
432 from+=QString(current_address->ad_mailbox_name); 433 from+=QString(current_address->ad_mailbox_name);
433 from+="@"; 434 from+="@";
434 } 435 }
435 if (current_address->ad_host_name) { 436 if (current_address->ad_host_name) {
436 from+=QString(current_address->ad_host_name); 437 from+=QString(current_address->ad_host_name);
437 } 438 }
438 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 439 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
439 from+=">"; 440 from+=">";
440 } 441 }
441 l.append(QString(from)); 442 l.append(QString(from));
442 if (++count > 99) { 443 if (++count > 99) {
443 break; 444 break;
444 } 445 }
445 } 446 }
446 return l; 447 return l;
447} 448}
448 449
449QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
450{ 451{
451 QString body(""); 452 QString body("");
452 const char*mb; 453 const char*mb;
453 int err; 454 int err;
454 mailimap_fetch_type *fetchType; 455 mailimap_fetch_type *fetchType;
455 mailimap_set *set; 456 mailimap_set *set;
456 clistcell*current,*cur; 457 clistcell*current,*cur;
457 458
458 login(); 459 login();
459 if (!m_imap) { 460 if (!m_imap) {
460 return body; 461 return body;
461 } 462 }
462 if (!internal_call) { 463 if (!internal_call) {
463 mb = mail.getMbox().latin1(); 464 mb = mail.getMbox().latin1();
464 err = mailimap_select( m_imap, (char*)mb); 465 err = mailimap_select( m_imap, (char*)mb);
465 if ( err != MAILIMAP_NO_ERROR ) { 466 if ( err != MAILIMAP_NO_ERROR ) {
466 qDebug("error selecting mailbox: %s",m_imap->imap_response); 467 qDebug("error selecting mailbox: %s",m_imap->imap_response);
467 return body; 468 return body;
468 } 469 }
469 } 470 }
470 set = mailimap_set_new_single(mail.getNumber()); 471 set = mailimap_set_new_single(mail.getNumber());
471 clist*id_list=clist_new(); 472 clist*id_list=clist_new();
472 for (unsigned j=0; j < path.count();++j) { 473 for (unsigned j=0; j < path.count();++j) {
473 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
474 *p_id = path[j]; 475 *p_id = path[j];
475 clist_append(id_list,p_id); 476 clist_append(id_list,p_id);
476 } 477 }
477 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 478 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
478 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
479 mailimap_section * section = mailimap_section_new(section_spec); 480 mailimap_section * section = mailimap_section_new(section_spec);
480 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
481 482
482 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
483 484
484 clist*result = clist_new(); 485 clist*result = clist_new();
485 486
486 err = mailimap_fetch( m_imap, set, fetchType, &result ); 487 err = mailimap_fetch( m_imap, set, fetchType, &result );
487 mailimap_set_free( set ); 488 mailimap_set_free( set );
488 mailimap_fetch_type_free( fetchType ); 489 mailimap_fetch_type_free( fetchType );
489 490
490 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
491 mailimap_msg_att * msg_att; 492 mailimap_msg_att * msg_att;
492 msg_att = (mailimap_msg_att*)current->data; 493 msg_att = (mailimap_msg_att*)current->data;
493 mailimap_msg_att_item*msg_att_item; 494 mailimap_msg_att_item*msg_att_item;
494 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 495 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
495 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 496 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
496 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 497 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
497 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 498 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
498 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 499 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
499 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 500 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
500 if (text) { 501 if (text) {
501 body = QString(text); 502 body = QString(text);
502 free(text); 503 free(text);
503 } else { 504 } else {
504 body = ""; 505 body = "";
505 } 506 }
506 } 507 }
507 } 508 }
508 } 509 }
509 510
510 } else { 511 } else {
511 qDebug("error fetching text: %s",m_imap->imap_response); 512 qDebug("error fetching text: %s",m_imap->imap_response);
512 } 513 }
513 mailimap_fetch_list_free(result); 514 mailimap_fetch_list_free(result);
514 return body; 515 return body;
515} 516}
516 517
517void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 518void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
518{ 519{
519 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 520 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
520 if (!mailDescription||current_recursion==10) { 521 if (!mailDescription||current_recursion==10) {
521 return; 522 return;
522 } 523 }
523 clistcell*current; 524 clistcell*current;
524 mailimap_body*current_body; 525 mailimap_body*current_body;
525 unsigned int count = 0; 526 unsigned int count = 0;
526 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 527 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
527 /* the point in the message */ 528 /* the point in the message */
528 ++count; 529 ++count;
529 current_body = (mailimap_body*)current->data; 530 current_body = (mailimap_body*)current->data;
530 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 531 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
531 QValueList<int>clist = recList; 532 QValueList<int>clist = recList;
532 clist.append(count); 533 clist.append(count);
533 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
534 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
535 RecPart currentPart; 536 RecPart currentPart;
536 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
537 QValueList<int>clist = recList; 538 QValueList<int>clist = recList;
538 clist.append(count); 539 clist.append(count);
539 /* important: Check for is NULL 'cause a body can be empty! */ 540 /* important: Check for is NULL 'cause a body can be empty! */
540 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
541 QString body_text = fetchPart(mail,clist,true); 542 QString body_text = fetchPart(mail,clist,true);
542 target_body.setDescription(currentPart); 543 target_body.setDescription(currentPart);
543 target_body.setBodytext(body_text); 544 target_body.setBodytext(body_text);
544 } else { 545 } else {
545 QString id(""); 546 QString id("");
546 for (unsigned int j = 0; j < clist.count();++j) { 547 for (unsigned int j = 0; j < clist.count();++j) {
547 id+=(j>0?" ":""); 548 id+=(j>0?" ":"");
548 id+=QString("%1").arg(clist[j]); 549 id+=QString("%1").arg(clist[j]);
549 } 550 }
550 qDebug("ID= %s",id.latin1()); 551 qDebug("ID= %s",id.latin1());
551 currentPart.setIdentifier(id); 552 currentPart.setIdentifier(id);
552 currentPart.setPositionlist(clist); 553 currentPart.setPositionlist(clist);
553 target_body.addPart(currentPart); 554 target_body.addPart(currentPart);
554 } 555 }
555 } 556 }
556 } 557 }
557} 558}
558 559
559void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
560{ 561{
561 if (!Description) { 562 if (!Description) {
562 return; 563 return;
563 } 564 }
564 switch (Description->bd_type) { 565 switch (Description->bd_type) {
565 case MAILIMAP_BODY_TYPE_1PART_TEXT: 566 case MAILIMAP_BODY_TYPE_1PART_TEXT:
566 target_part.setType("text"); 567 target_part.setType("text");
567 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
568 break; 569 break;
569 case MAILIMAP_BODY_TYPE_1PART_BASIC: 570 case MAILIMAP_BODY_TYPE_1PART_BASIC:
570 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
571 break; 572 break;
572 case MAILIMAP_BODY_TYPE_1PART_MSG: 573 case MAILIMAP_BODY_TYPE_1PART_MSG:
573 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
574 break; 575 break;
575 default: 576 default:
576 break; 577 break;
577 } 578 }
578} 579}
579 580
580void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
581{ 582{
582 if (!which) { 583 if (!which) {
583 return; 584 return;
584 } 585 }
585 QString sub; 586 QString sub;
586 sub = which->bd_media_text; 587 sub = which->bd_media_text;
587 target_part.setSubtype(sub.lower()); 588 target_part.setSubtype(sub.lower());
588 target_part.setLines(which->bd_lines); 589 target_part.setLines(which->bd_lines);
589 fillBodyFields(target_part,which->bd_fields); 590 fillBodyFields(target_part,which->bd_fields);
590} 591}
591 592
592void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
593{ 594{
594 if (!which) { 595 if (!which) {
595 return; 596 return;
596 } 597 }
597// QString sub; 598// QString sub;
598// sub = which->bd_media_text; 599// sub = which->bd_media_text;
599// target_part.setSubtype(sub.lower()); 600// target_part.setSubtype(sub.lower());
600 qDebug("Message part"); 601 qDebug("Message part");
601 /* we set this type to text/plain */ 602 /* we set this type to text/plain */
602 target_part.setType("text"); 603 target_part.setType("text");
603 target_part.setSubtype("plain"); 604 target_part.setSubtype("plain");
604 target_part.setLines(which->bd_lines); 605 target_part.setLines(which->bd_lines);
605 fillBodyFields(target_part,which->bd_fields); 606 fillBodyFields(target_part,which->bd_fields);
606} 607}
607 608
608void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
609{ 610{
610 if (!which) { 611 if (!which) {
611 return; 612 return;
612 } 613 }
613 QString type,sub; 614 QString type,sub;
614 switch (which->bd_media_basic->med_type) { 615 switch (which->bd_media_basic->med_type) {
615 case MAILIMAP_MEDIA_BASIC_APPLICATION: 616 case MAILIMAP_MEDIA_BASIC_APPLICATION:
616 type = "application"; 617 type = "application";
617 break; 618 break;
618 case MAILIMAP_MEDIA_BASIC_AUDIO: 619 case MAILIMAP_MEDIA_BASIC_AUDIO:
619 type = "audio"; 620 type = "audio";
620 break; 621 break;
621 case MAILIMAP_MEDIA_BASIC_IMAGE: 622 case MAILIMAP_MEDIA_BASIC_IMAGE:
622 type = "image"; 623 type = "image";
623 break; 624 break;
624 case MAILIMAP_MEDIA_BASIC_MESSAGE: 625 case MAILIMAP_MEDIA_BASIC_MESSAGE:
625 type = "message"; 626 type = "message";
626 break; 627 break;
627 case MAILIMAP_MEDIA_BASIC_VIDEO: 628 case MAILIMAP_MEDIA_BASIC_VIDEO:
628 type = "video"; 629 type = "video";
629 break; 630 break;
630 case MAILIMAP_MEDIA_BASIC_OTHER: 631 case MAILIMAP_MEDIA_BASIC_OTHER:
631 default: 632 default:
632 if (which->bd_media_basic->med_basic_type) { 633 if (which->bd_media_basic->med_basic_type) {
633 type = which->bd_media_basic->med_basic_type; 634 type = which->bd_media_basic->med_basic_type;
634 } else { 635 } else {
635 type = ""; 636 type = "";
636 } 637 }
637 break; 638 break;
638 } 639 }
639 if (which->bd_media_basic->med_subtype) { 640 if (which->bd_media_basic->med_subtype) {
640 sub = which->bd_media_basic->med_subtype; 641 sub = which->bd_media_basic->med_subtype;
641 } else { 642 } else {
642 sub = ""; 643 sub = "";
643 } 644 }
644 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 645 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
645 target_part.setType(type.lower()); 646 target_part.setType(type.lower());
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index e5eb335..3222c7e 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,645 +1,646 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this);
134 target.append(m); 135 target.append(m);
135 } 136 }
136 } 137 }
137 } else { 138 } else {
138 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
139 } 140 }
140 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
141} 142}
142 143
143QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
144{ 145{
145 const char *path, *mask; 146 const char *path, *mask;
146 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
147 clist *result; 148 clist *result;
148 clistcell *current; 149 clistcell *current;
149 150
150 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
151 folders->setAutoDelete( true ); 152 folders->setAutoDelete( true );
152 login(); 153 login();
153 if (!m_imap) { 154 if (!m_imap) {
154 return folders; 155 return folders;
155 } 156 }
156 157
157/* 158/*
158 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
159 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
160 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
161 */ 162 */
162 QString temp; 163 QString temp;
163 mask = "INBOX" ; 164 mask = "INBOX" ;
164 result = clist_new(); 165 result = clist_new();
165 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
166 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
167 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
168 current = result->first; 169 current = result->first;
169 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
170 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
171 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
172 // instead of using strdup! 173 // instead of using strdup!
173 temp = list->mb_name; 174 temp = list->mb_name;
174 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
175 current = current->next; 176 current = current->next;
176 } 177 }
177 } else { 178 } else {
178 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
179 } 180 }
180 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
181 182
182/* 183/*
183 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
184 */ 185 */
185 mask = "*" ; 186 mask = "*" ;
186 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
187 if (!path) path = ""; 188 if (!path) path = "";
188 result = clist_new(); 189 result = clist_new();
189 qDebug(path); 190 qDebug(path);
190 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 191 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
191 if ( err == MAILIMAP_NO_ERROR ) { 192 if ( err == MAILIMAP_NO_ERROR ) {
192 current = result->first; 193 current = result->first;
193 for ( int i = result->count; i > 0; i-- ) { 194 for ( int i = result->count; i > 0; i-- ) {
194 list = (mailimap_mailbox_list *) current->data; 195 list = (mailimap_mailbox_list *) current->data;
195 // it is better use the deep copy mechanism of qt itself 196 // it is better use the deep copy mechanism of qt itself
196 // instead of using strdup! 197 // instead of using strdup!
197 temp = list->mb_name; 198 temp = list->mb_name;
198 current = current->next; 199 current = current->next;
199 if (temp.lower()=="inbox") 200 if (temp.lower()=="inbox")
200 continue; 201 continue;
201 folders->append(new IMAPFolder(temp)); 202 folders->append(new IMAPFolder(temp));
202 203
203 } 204 }
204 } else { 205 } else {
205 qDebug("error fetching folders %s",m_imap->imap_response); 206 qDebug("error fetching folders %s",m_imap->imap_response);
206 } 207 }
207 mailimap_list_result_free( result ); 208 mailimap_list_result_free( result );
208 return folders; 209 return folders;
209} 210}
210 211
211RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 212RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
212{ 213{
213 RecMail * m = 0; 214 RecMail * m = 0;
214 mailimap_msg_att_item *item=0; 215 mailimap_msg_att_item *item=0;
215 clistcell *current,*c,*cf; 216 clistcell *current,*c,*cf;
216 mailimap_msg_att_dynamic*flist; 217 mailimap_msg_att_dynamic*flist;
217 mailimap_flag_fetch*cflag; 218 mailimap_flag_fetch*cflag;
218 int size; 219 int size;
219 QBitArray mFlags(7); 220 QBitArray mFlags(7);
220 QStringList addresslist; 221 QStringList addresslist;
221 222
222 if (!m_att) { 223 if (!m_att) {
223 return m; 224 return m;
224 } 225 }
225 m = new RecMail(); 226 m = new RecMail();
226 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 227 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
227 current = c; 228 current = c;
228 size = 0; 229 size = 0;
229 item = (mailimap_msg_att_item*)current->data; 230 item = (mailimap_msg_att_item*)current->data;
230 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 231 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
231 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 232 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
232 if (!flist->att_list) { 233 if (!flist->att_list) {
233 continue; 234 continue;
234 } 235 }
235 cf = flist->att_list->first; 236 cf = flist->att_list->first;
236 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 237 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
237 cflag = (mailimap_flag_fetch*)cf->data; 238 cflag = (mailimap_flag_fetch*)cf->data;
238 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 239 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
239 switch (cflag->fl_flag->fl_type) { 240 switch (cflag->fl_flag->fl_type) {
240 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
241 mFlags.setBit(FLAG_ANSWERED); 242 mFlags.setBit(FLAG_ANSWERED);
242 break; 243 break;
243 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
244 mFlags.setBit(FLAG_FLAGGED); 245 mFlags.setBit(FLAG_FLAGGED);
245 break; 246 break;
246 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
247 mFlags.setBit(FLAG_DELETED); 248 mFlags.setBit(FLAG_DELETED);
248 break; 249 break;
249 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
250 mFlags.setBit(FLAG_SEEN); 251 mFlags.setBit(FLAG_SEEN);
251 break; 252 break;
252 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
253 mFlags.setBit(FLAG_DRAFT); 254 mFlags.setBit(FLAG_DRAFT);
254 break; 255 break;
255 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
256 break; 257 break;
257 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
258 break; 259 break;
259 default: 260 default:
260 break; 261 break;
261 } 262 }
262 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 263 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
263 mFlags.setBit(FLAG_RECENT); 264 mFlags.setBit(FLAG_RECENT);
264 } 265 }
265 } 266 }
266 continue; 267 continue;
267 } 268 }
268 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 269 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
269 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 270 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
270 m->setDate(head->env_date); 271 m->setDate(head->env_date);
271 m->setSubject(head->env_subject); 272 m->setSubject(head->env_subject);
272 if (head->env_from!=NULL) { 273 if (head->env_from!=NULL) {
273 addresslist = address_list_to_stringlist(head->env_from->frm_list); 274 addresslist = address_list_to_stringlist(head->env_from->frm_list);
274 if (addresslist.count()) { 275 if (addresslist.count()) {
275 m->setFrom(addresslist.first()); 276 m->setFrom(addresslist.first());
276 } 277 }
277 } 278 }
278 if (head->env_to!=NULL) { 279 if (head->env_to!=NULL) {
279 addresslist = address_list_to_stringlist(head->env_to->to_list); 280 addresslist = address_list_to_stringlist(head->env_to->to_list);
280 m->setTo(addresslist); 281 m->setTo(addresslist);
281 } 282 }
282 if (head->env_cc!=NULL) { 283 if (head->env_cc!=NULL) {
283 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 284 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
284 m->setCC(addresslist); 285 m->setCC(addresslist);
285 } 286 }
286 if (head->env_bcc!=NULL) { 287 if (head->env_bcc!=NULL) {
287 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 288 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
288 m->setBcc(addresslist); 289 m->setBcc(addresslist);
289 } 290 }
290 if (head->env_reply_to!=NULL) { 291 if (head->env_reply_to!=NULL) {
291 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 292 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
292 if (addresslist.count()) { 293 if (addresslist.count()) {
293 m->setReplyto(addresslist.first()); 294 m->setReplyto(addresslist.first());
294 } 295 }
295 } 296 }
296 m->setMsgid(QString(head->env_message_id)); 297 m->setMsgid(QString(head->env_message_id));
297 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 298 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
298 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 299 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
299 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 300 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
300 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); 301 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);
301 qDebug(da.toString()); 302 qDebug(da.toString());
302 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 303 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
303 size = item->att_data.att_static->att_data.att_rfc822_size; 304 size = item->att_data.att_static->att_data.att_rfc822_size;
304 } 305 }
305 } 306 }
306 /* msg is already deleted */ 307 /* msg is already deleted */
307 if (mFlags.testBit(FLAG_DELETED) && m) { 308 if (mFlags.testBit(FLAG_DELETED) && m) {
308 delete m; 309 delete m;
309 m = 0; 310 m = 0;
310 } 311 }
311 if (m) { 312 if (m) {
312 m->setFlags(mFlags); 313 m->setFlags(mFlags);
313 m->setMsgsize(size); 314 m->setMsgsize(size);
314 } 315 }
315 return m; 316 return m;
316} 317}
317 318
318RecBody IMAPwrapper::fetchBody(const RecMail&mail) 319RecBody IMAPwrapper::fetchBody(const RecMail&mail)
319{ 320{
320 RecBody body; 321 RecBody body;
321 const char *mb; 322 const char *mb;
322 int err = MAILIMAP_NO_ERROR; 323 int err = MAILIMAP_NO_ERROR;
323 clist *result; 324 clist *result;
324 clistcell *current; 325 clistcell *current;
325 mailimap_fetch_att *fetchAtt; 326 mailimap_fetch_att *fetchAtt;
326 mailimap_fetch_type *fetchType; 327 mailimap_fetch_type *fetchType;
327 mailimap_set *set; 328 mailimap_set *set;
328 mailimap_body*body_desc; 329 mailimap_body*body_desc;
329 330
330 mb = mail.getMbox().latin1(); 331 mb = mail.getMbox().latin1();
331 332
332 login(); 333 login();
333 if (!m_imap) { 334 if (!m_imap) {
334 return body; 335 return body;
335 } 336 }
336 337
337 err = mailimap_select( m_imap, (char*)mb); 338 err = mailimap_select( m_imap, (char*)mb);
338 if ( err != MAILIMAP_NO_ERROR ) { 339 if ( err != MAILIMAP_NO_ERROR ) {
339 qDebug("error selecting mailbox: %s",m_imap->imap_response); 340 qDebug("error selecting mailbox: %s",m_imap->imap_response);
340 return body; 341 return body;
341 } 342 }
342 343
343 result = clist_new(); 344 result = clist_new();
344 /* the range has to start at 1!!! not with 0!!!! */ 345 /* the range has to start at 1!!! not with 0!!!! */
345 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 346 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
346 fetchAtt = mailimap_fetch_att_new_bodystructure(); 347 fetchAtt = mailimap_fetch_att_new_bodystructure();
347 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 348 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
348 err = mailimap_fetch( m_imap, set, fetchType, &result ); 349 err = mailimap_fetch( m_imap, set, fetchType, &result );
349 mailimap_set_free( set ); 350 mailimap_set_free( set );
350 mailimap_fetch_type_free( fetchType ); 351 mailimap_fetch_type_free( fetchType );
351 352
352 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 353 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
353 mailimap_msg_att * msg_att; 354 mailimap_msg_att * msg_att;
354 msg_att = (mailimap_msg_att*)current->data; 355 msg_att = (mailimap_msg_att*)current->data;
355 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 356 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
356 body_desc = item->att_data.att_static->att_data.att_body; 357 body_desc = item->att_data.att_static->att_data.att_body;
357 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 358 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
358 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 359 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
359 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 360 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
360 qDebug("Mulitpart mail"); 361 qDebug("Mulitpart mail");
361 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 362 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
362 } 363 }
363 } else { 364 } else {
364 qDebug("error fetching body: %s",m_imap->imap_response); 365 qDebug("error fetching body: %s",m_imap->imap_response);
365 } 366 }
366 mailimap_fetch_list_free(result); 367 mailimap_fetch_list_free(result);
367 return body; 368 return body;
368} 369}
369 370
370/* this routine is just called when the mail has only ONE part. 371/* this routine is just called when the mail has only ONE part.
371 for filling the parts of a multi-part-message there are other 372 for filling the parts of a multi-part-message there are other
372 routines 'cause we can not simply fetch the whole body. */ 373 routines 'cause we can not simply fetch the whole body. */
373void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 374void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
374{ 375{
375 if (!mailDescription) { 376 if (!mailDescription) {
376 return; 377 return;
377 } 378 }
378 QString sub,body_text; 379 QString sub,body_text;
379 RecPart singlePart; 380 RecPart singlePart;
380 QValueList<int> path; 381 QValueList<int> path;
381 fillSinglePart(singlePart,mailDescription); 382 fillSinglePart(singlePart,mailDescription);
382 switch (mailDescription->bd_type) { 383 switch (mailDescription->bd_type) {
383 case MAILIMAP_BODY_TYPE_1PART_MSG: 384 case MAILIMAP_BODY_TYPE_1PART_MSG:
384 path.append(1); 385 path.append(1);
385 body_text = fetchPart(mail,path,true); 386 body_text = fetchPart(mail,path,true);
386 target_body.setBodytext(body_text); 387 target_body.setBodytext(body_text);
387 target_body.setDescription(singlePart); 388 target_body.setDescription(singlePart);
388 break; 389 break;
389 case MAILIMAP_BODY_TYPE_1PART_TEXT: 390 case MAILIMAP_BODY_TYPE_1PART_TEXT:
390 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 391 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
391 path.append(1); 392 path.append(1);
392 body_text = fetchPart(mail,path,true); 393 body_text = fetchPart(mail,path,true);
393 target_body.setBodytext(body_text); 394 target_body.setBodytext(body_text);
394 target_body.setDescription(singlePart); 395 target_body.setDescription(singlePart);
395 break; 396 break;
396 case MAILIMAP_BODY_TYPE_1PART_BASIC: 397 case MAILIMAP_BODY_TYPE_1PART_BASIC:
397 qDebug("Single attachment"); 398 qDebug("Single attachment");
398 target_body.setBodytext(""); 399 target_body.setBodytext("");
399 target_body.addPart(singlePart); 400 target_body.addPart(singlePart);
400 break; 401 break;
401 default: 402 default:
402 break; 403 break;
403 } 404 }
404 405
405 return; 406 return;
406} 407}
407 408
408QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 409QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
409{ 410{
410 QStringList l; 411 QStringList l;
411 QString from; 412 QString from;
412 bool named_from; 413 bool named_from;
413 clistcell *current = NULL; 414 clistcell *current = NULL;
414 mailimap_address * current_address=NULL; 415 mailimap_address * current_address=NULL;
415 if (!list) { 416 if (!list) {
416 return l; 417 return l;
417 } 418 }
418 unsigned int count = 0; 419 unsigned int count = 0;
419 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 420 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
420 from = ""; 421 from = "";
421 named_from = false; 422 named_from = false;
422 current_address=(mailimap_address*)current->data; 423 current_address=(mailimap_address*)current->data;
423 if (current_address->ad_personal_name){ 424 if (current_address->ad_personal_name){
424 from+=QString(current_address->ad_personal_name); 425 from+=QString(current_address->ad_personal_name);
425 from+=" "; 426 from+=" ";
426 named_from = true; 427 named_from = true;
427 } 428 }
428 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 429 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
429 from+="<"; 430 from+="<";
430 } 431 }
431 if (current_address->ad_mailbox_name) { 432 if (current_address->ad_mailbox_name) {
432 from+=QString(current_address->ad_mailbox_name); 433 from+=QString(current_address->ad_mailbox_name);
433 from+="@"; 434 from+="@";
434 } 435 }
435 if (current_address->ad_host_name) { 436 if (current_address->ad_host_name) {
436 from+=QString(current_address->ad_host_name); 437 from+=QString(current_address->ad_host_name);
437 } 438 }
438 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 439 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
439 from+=">"; 440 from+=">";
440 } 441 }
441 l.append(QString(from)); 442 l.append(QString(from));
442 if (++count > 99) { 443 if (++count > 99) {
443 break; 444 break;
444 } 445 }
445 } 446 }
446 return l; 447 return l;
447} 448}
448 449
449QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
450{ 451{
451 QString body(""); 452 QString body("");
452 const char*mb; 453 const char*mb;
453 int err; 454 int err;
454 mailimap_fetch_type *fetchType; 455 mailimap_fetch_type *fetchType;
455 mailimap_set *set; 456 mailimap_set *set;
456 clistcell*current,*cur; 457 clistcell*current,*cur;
457 458
458 login(); 459 login();
459 if (!m_imap) { 460 if (!m_imap) {
460 return body; 461 return body;
461 } 462 }
462 if (!internal_call) { 463 if (!internal_call) {
463 mb = mail.getMbox().latin1(); 464 mb = mail.getMbox().latin1();
464 err = mailimap_select( m_imap, (char*)mb); 465 err = mailimap_select( m_imap, (char*)mb);
465 if ( err != MAILIMAP_NO_ERROR ) { 466 if ( err != MAILIMAP_NO_ERROR ) {
466 qDebug("error selecting mailbox: %s",m_imap->imap_response); 467 qDebug("error selecting mailbox: %s",m_imap->imap_response);
467 return body; 468 return body;
468 } 469 }
469 } 470 }
470 set = mailimap_set_new_single(mail.getNumber()); 471 set = mailimap_set_new_single(mail.getNumber());
471 clist*id_list=clist_new(); 472 clist*id_list=clist_new();
472 for (unsigned j=0; j < path.count();++j) { 473 for (unsigned j=0; j < path.count();++j) {
473 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
474 *p_id = path[j]; 475 *p_id = path[j];
475 clist_append(id_list,p_id); 476 clist_append(id_list,p_id);
476 } 477 }
477 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 478 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
478 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
479 mailimap_section * section = mailimap_section_new(section_spec); 480 mailimap_section * section = mailimap_section_new(section_spec);
480 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
481 482
482 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
483 484
484 clist*result = clist_new(); 485 clist*result = clist_new();
485 486
486 err = mailimap_fetch( m_imap, set, fetchType, &result ); 487 err = mailimap_fetch( m_imap, set, fetchType, &result );
487 mailimap_set_free( set ); 488 mailimap_set_free( set );
488 mailimap_fetch_type_free( fetchType ); 489 mailimap_fetch_type_free( fetchType );
489 490
490 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
491 mailimap_msg_att * msg_att; 492 mailimap_msg_att * msg_att;
492 msg_att = (mailimap_msg_att*)current->data; 493 msg_att = (mailimap_msg_att*)current->data;
493 mailimap_msg_att_item*msg_att_item; 494 mailimap_msg_att_item*msg_att_item;
494 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 495 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
495 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 496 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
496 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 497 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
497 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 498 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
498 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 499 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
499 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 500 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
500 if (text) { 501 if (text) {
501 body = QString(text); 502 body = QString(text);
502 free(text); 503 free(text);
503 } else { 504 } else {
504 body = ""; 505 body = "";
505 } 506 }
506 } 507 }
507 } 508 }
508 } 509 }
509 510
510 } else { 511 } else {
511 qDebug("error fetching text: %s",m_imap->imap_response); 512 qDebug("error fetching text: %s",m_imap->imap_response);
512 } 513 }
513 mailimap_fetch_list_free(result); 514 mailimap_fetch_list_free(result);
514 return body; 515 return body;
515} 516}
516 517
517void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 518void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
518{ 519{
519 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 520 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
520 if (!mailDescription||current_recursion==10) { 521 if (!mailDescription||current_recursion==10) {
521 return; 522 return;
522 } 523 }
523 clistcell*current; 524 clistcell*current;
524 mailimap_body*current_body; 525 mailimap_body*current_body;
525 unsigned int count = 0; 526 unsigned int count = 0;
526 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 527 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
527 /* the point in the message */ 528 /* the point in the message */
528 ++count; 529 ++count;
529 current_body = (mailimap_body*)current->data; 530 current_body = (mailimap_body*)current->data;
530 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 531 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
531 QValueList<int>clist = recList; 532 QValueList<int>clist = recList;
532 clist.append(count); 533 clist.append(count);
533 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
534 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
535 RecPart currentPart; 536 RecPart currentPart;
536 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
537 QValueList<int>clist = recList; 538 QValueList<int>clist = recList;
538 clist.append(count); 539 clist.append(count);
539 /* important: Check for is NULL 'cause a body can be empty! */ 540 /* important: Check for is NULL 'cause a body can be empty! */
540 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
541 QString body_text = fetchPart(mail,clist,true); 542 QString body_text = fetchPart(mail,clist,true);
542 target_body.setDescription(currentPart); 543 target_body.setDescription(currentPart);
543 target_body.setBodytext(body_text); 544 target_body.setBodytext(body_text);
544 } else { 545 } else {
545 QString id(""); 546 QString id("");
546 for (unsigned int j = 0; j < clist.count();++j) { 547 for (unsigned int j = 0; j < clist.count();++j) {
547 id+=(j>0?" ":""); 548 id+=(j>0?" ":"");
548 id+=QString("%1").arg(clist[j]); 549 id+=QString("%1").arg(clist[j]);
549 } 550 }
550 qDebug("ID= %s",id.latin1()); 551 qDebug("ID= %s",id.latin1());
551 currentPart.setIdentifier(id); 552 currentPart.setIdentifier(id);
552 currentPart.setPositionlist(clist); 553 currentPart.setPositionlist(clist);
553 target_body.addPart(currentPart); 554 target_body.addPart(currentPart);
554 } 555 }
555 } 556 }
556 } 557 }
557} 558}
558 559
559void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
560{ 561{
561 if (!Description) { 562 if (!Description) {
562 return; 563 return;
563 } 564 }
564 switch (Description->bd_type) { 565 switch (Description->bd_type) {
565 case MAILIMAP_BODY_TYPE_1PART_TEXT: 566 case MAILIMAP_BODY_TYPE_1PART_TEXT:
566 target_part.setType("text"); 567 target_part.setType("text");
567 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
568 break; 569 break;
569 case MAILIMAP_BODY_TYPE_1PART_BASIC: 570 case MAILIMAP_BODY_TYPE_1PART_BASIC:
570 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
571 break; 572 break;
572 case MAILIMAP_BODY_TYPE_1PART_MSG: 573 case MAILIMAP_BODY_TYPE_1PART_MSG:
573 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
574 break; 575 break;
575 default: 576 default:
576 break; 577 break;
577 } 578 }
578} 579}
579 580
580void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
581{ 582{
582 if (!which) { 583 if (!which) {
583 return; 584 return;
584 } 585 }
585 QString sub; 586 QString sub;
586 sub = which->bd_media_text; 587 sub = which->bd_media_text;
587 target_part.setSubtype(sub.lower()); 588 target_part.setSubtype(sub.lower());
588 target_part.setLines(which->bd_lines); 589 target_part.setLines(which->bd_lines);
589 fillBodyFields(target_part,which->bd_fields); 590 fillBodyFields(target_part,which->bd_fields);
590} 591}
591 592
592void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
593{ 594{
594 if (!which) { 595 if (!which) {
595 return; 596 return;
596 } 597 }
597// QString sub; 598// QString sub;
598// sub = which->bd_media_text; 599// sub = which->bd_media_text;
599// target_part.setSubtype(sub.lower()); 600// target_part.setSubtype(sub.lower());
600 qDebug("Message part"); 601 qDebug("Message part");
601 /* we set this type to text/plain */ 602 /* we set this type to text/plain */
602 target_part.setType("text"); 603 target_part.setType("text");
603 target_part.setSubtype("plain"); 604 target_part.setSubtype("plain");
604 target_part.setLines(which->bd_lines); 605 target_part.setLines(which->bd_lines);
605 fillBodyFields(target_part,which->bd_fields); 606 fillBodyFields(target_part,which->bd_fields);
606} 607}
607 608
608void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
609{ 610{
610 if (!which) { 611 if (!which) {
611 return; 612 return;
612 } 613 }
613 QString type,sub; 614 QString type,sub;
614 switch (which->bd_media_basic->med_type) { 615 switch (which->bd_media_basic->med_type) {
615 case MAILIMAP_MEDIA_BASIC_APPLICATION: 616 case MAILIMAP_MEDIA_BASIC_APPLICATION:
616 type = "application"; 617 type = "application";
617 break; 618 break;
618 case MAILIMAP_MEDIA_BASIC_AUDIO: 619 case MAILIMAP_MEDIA_BASIC_AUDIO:
619 type = "audio"; 620 type = "audio";
620 break; 621 break;
621 case MAILIMAP_MEDIA_BASIC_IMAGE: 622 case MAILIMAP_MEDIA_BASIC_IMAGE:
622 type = "image"; 623 type = "image";
623 break; 624 break;
624 case MAILIMAP_MEDIA_BASIC_MESSAGE: 625 case MAILIMAP_MEDIA_BASIC_MESSAGE:
625 type = "message"; 626 type = "message";
626 break; 627 break;
627 case MAILIMAP_MEDIA_BASIC_VIDEO: 628 case MAILIMAP_MEDIA_BASIC_VIDEO:
628 type = "video"; 629 type = "video";
629 break; 630 break;
630 case MAILIMAP_MEDIA_BASIC_OTHER: 631 case MAILIMAP_MEDIA_BASIC_OTHER:
631 default: 632 default:
632 if (which->bd_media_basic->med_basic_type) { 633 if (which->bd_media_basic->med_basic_type) {
633 type = which->bd_media_basic->med_basic_type; 634 type = which->bd_media_basic->med_basic_type;
634 } else { 635 } else {
635 type = ""; 636 type = "";
636 } 637 }
637 break; 638 break;
638 } 639 }
639 if (which->bd_media_basic->med_subtype) { 640 if (which->bd_media_basic->med_subtype) {
640 sub = which->bd_media_basic->med_subtype; 641 sub = which->bd_media_basic->med_subtype;
641 } else { 642 } else {
642 sub = ""; 643 sub = "";
643 } 644 }
644 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 645 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
645 target_part.setType(type.lower()); 646 target_part.setType(type.lower());
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 5cd45ed..94f5d6f 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,220 +1,237 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
15 qDebug("Copy constructor RecMail"); 15 qDebug("Copy constructor RecMail");
16} 16}
17 17
18RecMail::~RecMail()
19{
20 wrapper = 0;
21}
22
18void RecMail::copy_old(const RecMail&old) 23void RecMail::copy_old(const RecMail&old)
19{ 24{
20 subject = old.subject; 25 subject = old.subject;
21 date = old.date; 26 date = old.date;
22 mbox = old.mbox; 27 mbox = old.mbox;
23 msg_id = old.msg_id; 28 msg_id = old.msg_id;
24 msg_size = old.msg_size; 29 msg_size = old.msg_size;
25 msg_number = old.msg_number; 30 msg_number = old.msg_number;
26 from = old.from; 31 from = old.from;
27 msg_flags = old.msg_flags; 32 msg_flags = old.msg_flags;
28 to = old.to; 33 to = old.to;
29 cc = old.cc; 34 cc = old.cc;
30 bcc = old.bcc; 35 bcc = old.bcc;
36 wrapper = old.wrapper;
31} 37}
32 38
33void RecMail::init() 39void RecMail::init()
34{ 40{
35 to.clear(); 41 to.clear();
36 cc.clear(); 42 cc.clear();
37 bcc.clear(); 43 bcc.clear();
44 wrapper = 0;
45}
46
47void RecMail::setWrapper(AbstractMail*awrapper)
48{
49 wrapper = awrapper;
50}
51
52AbstractMail* RecMail::Wrapper()
53{
54 return wrapper;
38} 55}
39 56
40void RecMail::setTo(const QStringList&list) 57void RecMail::setTo(const QStringList&list)
41{ 58{
42 to = list; 59 to = list;
43} 60}
44 61
45const QStringList&RecMail::To()const 62const QStringList&RecMail::To()const
46{ 63{
47 return to; 64 return to;
48} 65}
49 66
50void RecMail::setCC(const QStringList&list) 67void RecMail::setCC(const QStringList&list)
51{ 68{
52 cc = list; 69 cc = list;
53} 70}
54 71
55const QStringList&RecMail::CC()const 72const QStringList&RecMail::CC()const
56{ 73{
57 return cc; 74 return cc;
58} 75}
59 76
60void RecMail::setBcc(const QStringList&list) 77void RecMail::setBcc(const QStringList&list)
61{ 78{
62 bcc = list; 79 bcc = list;
63} 80}
64 81
65const QStringList& RecMail::Bcc()const 82const QStringList& RecMail::Bcc()const
66{ 83{
67 return bcc; 84 return bcc;
68} 85}
69 86
70RecPart::RecPart() 87RecPart::RecPart()
71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0) 88 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0)
72{ 89{
73 m_Parameters.clear(); 90 m_Parameters.clear();
74 m_poslist.clear(); 91 m_poslist.clear();
75} 92}
76 93
77RecPart::~RecPart() 94RecPart::~RecPart()
78{ 95{
79} 96}
80 97
81void RecPart::setSize(unsigned int size) 98void RecPart::setSize(unsigned int size)
82{ 99{
83 m_size = size; 100 m_size = size;
84} 101}
85 102
86const unsigned int RecPart::Size()const 103const unsigned int RecPart::Size()const
87{ 104{
88 return m_size; 105 return m_size;
89} 106}
90 107
91void RecPart::setLines(unsigned int lines) 108void RecPart::setLines(unsigned int lines)
92{ 109{
93 m_lines = lines; 110 m_lines = lines;
94} 111}
95 112
96const unsigned int RecPart::Lines()const 113const unsigned int RecPart::Lines()const
97{ 114{
98 return m_lines; 115 return m_lines;
99} 116}
100 117
101const QString& RecPart::Type()const 118const QString& RecPart::Type()const
102{ 119{
103 return m_type; 120 return m_type;
104} 121}
105 122
106void RecPart::setType(const QString&type) 123void RecPart::setType(const QString&type)
107{ 124{
108 m_type = type; 125 m_type = type;
109} 126}
110 127
111const QString& RecPart::Subtype()const 128const QString& RecPart::Subtype()const
112{ 129{
113 return m_subtype; 130 return m_subtype;
114} 131}
115 132
116void RecPart::setSubtype(const QString&subtype) 133void RecPart::setSubtype(const QString&subtype)
117{ 134{
118 m_subtype = subtype; 135 m_subtype = subtype;
119} 136}
120 137
121const QString& RecPart::Identifier()const 138const QString& RecPart::Identifier()const
122{ 139{
123 return m_identifier; 140 return m_identifier;
124} 141}
125 142
126void RecPart::setIdentifier(const QString&identifier) 143void RecPart::setIdentifier(const QString&identifier)
127{ 144{
128 m_identifier = identifier; 145 m_identifier = identifier;
129} 146}
130 147
131const QString& RecPart::Encoding()const 148const QString& RecPart::Encoding()const
132{ 149{
133 return m_encoding; 150 return m_encoding;
134} 151}
135 152
136void RecPart::setEncoding(const QString&encoding) 153void RecPart::setEncoding(const QString&encoding)
137{ 154{
138 m_encoding = encoding; 155 m_encoding = encoding;
139} 156}
140 157
141void RecPart::setParameters(const part_plist_t&list) 158void RecPart::setParameters(const part_plist_t&list)
142{ 159{
143 m_Parameters = list; 160 m_Parameters = list;
144} 161}
145 162
146const part_plist_t& RecPart::Parameters()const 163const part_plist_t& RecPart::Parameters()const
147{ 164{
148 return m_Parameters; 165 return m_Parameters;
149} 166}
150 167
151void RecPart::addParameter(const QString&key,const QString&value) 168void RecPart::addParameter(const QString&key,const QString&value)
152{ 169{
153 m_Parameters[key]=value; 170 m_Parameters[key]=value;
154} 171}
155 172
156const QString RecPart::searchParamter(const QString&key)const 173const QString RecPart::searchParamter(const QString&key)const
157{ 174{
158 QString value(""); 175 QString value("");
159 part_plist_t::ConstIterator it = m_Parameters.find(key); 176 part_plist_t::ConstIterator it = m_Parameters.find(key);
160 if (it != m_Parameters.end()) { 177 if (it != m_Parameters.end()) {
161 value = it.data(); 178 value = it.data();
162 } 179 }
163 return value; 180 return value;
164} 181}
165 182
166void RecPart::setPositionlist(const QValueList<int>&poslist) 183void RecPart::setPositionlist(const QValueList<int>&poslist)
167{ 184{
168 m_poslist = poslist; 185 m_poslist = poslist;
169} 186}
170 187
171const QValueList<int>& RecPart::Positionlist()const 188const QValueList<int>& RecPart::Positionlist()const
172{ 189{
173 return m_poslist; 190 return m_poslist;
174} 191}
175 192
176RecBody::RecBody() 193RecBody::RecBody()
177 : m_BodyText(),m_PartsList(),m_description() 194 : m_BodyText(),m_PartsList(),m_description()
178{ 195{
179 m_PartsList.clear(); 196 m_PartsList.clear();
180} 197}
181 198
182RecBody::~RecBody() 199RecBody::~RecBody()
183{ 200{
184} 201}
185 202
186void RecBody::setBodytext(const QString&bodyText) 203void RecBody::setBodytext(const QString&bodyText)
187{ 204{
188 m_BodyText = bodyText; 205 m_BodyText = bodyText;
189} 206}
190 207
191const QString& RecBody::Bodytext()const 208const QString& RecBody::Bodytext()const
192{ 209{
193 return m_BodyText; 210 return m_BodyText;
194} 211}
195 212
196void RecBody::setParts(const QValueList<RecPart>&parts) 213void RecBody::setParts(const QValueList<RecPart>&parts)
197{ 214{
198 m_PartsList.clear(); 215 m_PartsList.clear();
199 m_PartsList = parts; 216 m_PartsList = parts;
200} 217}
201 218
202const QValueList<RecPart>& RecBody::Parts()const 219const QValueList<RecPart>& RecBody::Parts()const
203{ 220{
204 return m_PartsList; 221 return m_PartsList;
205} 222}
206 223
207void RecBody::addPart(const RecPart& part) 224void RecBody::addPart(const RecPart& part)
208{ 225{
209 m_PartsList.append(part); 226 m_PartsList.append(part);
210} 227}
211 228
212void RecBody::setDescription(const RecPart&des) 229void RecBody::setDescription(const RecPart&des)
213{ 230{
214 m_description = des; 231 m_description = des;
215} 232}
216 233
217const RecPart& RecBody::Description()const 234const RecPart& RecBody::Description()const
218{ 235{
219 return m_description; 236 return m_description;
220} 237}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 24518cf..9ef762d 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -1,131 +1,136 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <qlist.h> 11#include <qlist.h>
12#include <qbitarray.h> 12#include <qbitarray.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15#include <qmap.h> 15#include <qmap.h>
16#include <qvaluelist.h> 16#include <qvaluelist.h>
17 17
18class AbstractMail;
18/* a class to describe mails in a mailbox */ 19/* a class to describe mails in a mailbox */
19/* Attention! 20/* Attention!
20 From programmers point of view it would make sense to 21 From programmers point of view it would make sense to
21 store the mail body into this class, too. 22 store the mail body into this class, too.
22 But: not from the point of view of the device. 23 But: not from the point of view of the device.
23 Mailbodies can be real large. So we request them when 24 Mailbodies can be real large. So we request them when
24 needed from the mail-wrapper class direct from the server itself 25 needed from the mail-wrapper class direct from the server itself
25 (imap) or from a file-based cache (pop3?) 26 (imap) or from a file-based cache (pop3?)
26 So there is no interface "const QString&body()" but you should 27 So there is no interface "const QString&body()" but you should
27 make a request to the mailwrapper with this class as parameter to 28 make a request to the mailwrapper with this class as parameter to
28 get the body. Same words for the attachments. 29 get the body. Same words for the attachments.
29*/ 30*/
30class RecMail 31class RecMail
31{ 32{
32public: 33public:
33 RecMail(); 34 RecMail();
34 RecMail(const RecMail&old); 35 RecMail(const RecMail&old);
35 virtual ~RecMail(){} 36 virtual ~RecMail();
36 37
37 const int getNumber()const{return msg_number;} 38 const int getNumber()const{return msg_number;}
38 void setNumber(int number){msg_number=number;} 39 void setNumber(int number){msg_number=number;}
39 const QString&getDate()const{ return date; } 40 const QString&getDate()const{ return date; }
40 void setDate( const QString&a ) { date = a; } 41 void setDate( const QString&a ) { date = a; }
41 const QString&getFrom()const{ return from; } 42 const QString&getFrom()const{ return from; }
42 void setFrom( const QString&a ) { from = a; } 43 void setFrom( const QString&a ) { from = a; }
43 const QString&getSubject()const { return subject; } 44 const QString&getSubject()const { return subject; }
44 void setSubject( const QString&s ) { subject = s; } 45 void setSubject( const QString&s ) { subject = s; }
45 const QString&getMbox()const{return mbox;} 46 const QString&getMbox()const{return mbox;}
46 void setMbox(const QString&box){mbox = box;} 47 void setMbox(const QString&box){mbox = box;}
47 void setMsgid(const QString&id){msg_id=id;} 48 void setMsgid(const QString&id){msg_id=id;}
48 const QString&Msgid()const{return msg_id;} 49 const QString&Msgid()const{return msg_id;}
49 void setReplyto(const QString&reply){replyto=reply;} 50 void setReplyto(const QString&reply){replyto=reply;}
50 const QString&Replyto()const{return replyto;} 51 const QString&Replyto()const{return replyto;}
51 void setMsgsize(int size){msg_size = size;} 52 void setMsgsize(int size){msg_size = size;}
52 const int Msgsize()const{return msg_size;} 53 const int Msgsize()const{return msg_size;}
53 54
54 55
55 void setTo(const QStringList&list); 56 void setTo(const QStringList&list);
56 const QStringList&To()const; 57 const QStringList&To()const;
57 void setCC(const QStringList&list); 58 void setCC(const QStringList&list);
58 const QStringList&CC()const; 59 const QStringList&CC()const;
59 void setBcc(const QStringList&list); 60 void setBcc(const QStringList&list);
60 const QStringList&Bcc()const; 61 const QStringList&Bcc()const;
61 const QBitArray&getFlags()const{return msg_flags;} 62 const QBitArray&getFlags()const{return msg_flags;}
62 void setFlags(const QBitArray&flags){msg_flags = flags;} 63 void setFlags(const QBitArray&flags){msg_flags = flags;}
64
65 void setWrapper(AbstractMail*wrapper);
66 AbstractMail* Wrapper();
63 67
64protected: 68protected:
65 QString subject,date,from,mbox,msg_id,replyto; 69 QString subject,date,from,mbox,msg_id,replyto;
66 int msg_number,msg_size; 70 int msg_number,msg_size;
67 QBitArray msg_flags; 71 QBitArray msg_flags;
68 QStringList to,cc,bcc; 72 QStringList to,cc,bcc;
73 AbstractMail*wrapper;
69 void init(); 74 void init();
70 void copy_old(const RecMail&old); 75 void copy_old(const RecMail&old);
71}; 76};
72 77
73typedef QMap<QString,QString> part_plist_t; 78typedef QMap<QString,QString> part_plist_t;
74 79
75class RecPart 80class RecPart
76{ 81{
77protected: 82protected:
78 QString m_type,m_subtype,m_identifier,m_encoding; 83 QString m_type,m_subtype,m_identifier,m_encoding;
79 unsigned int m_lines,m_size; 84 unsigned int m_lines,m_size;
80 part_plist_t m_Parameters; 85 part_plist_t m_Parameters;
81 /* describes the position in the mail */ 86 /* describes the position in the mail */
82 QValueList<int> m_poslist; 87 QValueList<int> m_poslist;
83 88
84public: 89public:
85 RecPart(); 90 RecPart();
86 virtual ~RecPart(); 91 virtual ~RecPart();
87 92
88 const QString&Type()const; 93 const QString&Type()const;
89 void setType(const QString&type); 94 void setType(const QString&type);
90 const QString&Subtype()const; 95 const QString&Subtype()const;
91 void setSubtype(const QString&subtype); 96 void setSubtype(const QString&subtype);
92 const QString&Identifier()const; 97 const QString&Identifier()const;
93 void setIdentifier(const QString&identifier); 98 void setIdentifier(const QString&identifier);
94 const QString&Encoding()const; 99 const QString&Encoding()const;
95 void setEncoding(const QString&encoding); 100 void setEncoding(const QString&encoding);
96 void setLines(unsigned int lines); 101 void setLines(unsigned int lines);
97 const unsigned int Lines()const; 102 const unsigned int Lines()const;
98 void setSize(unsigned int size); 103 void setSize(unsigned int size);
99 const unsigned int Size()const; 104 const unsigned int Size()const;
100 105
101 106
102 void setParameters(const part_plist_t&list); 107 void setParameters(const part_plist_t&list);
103 const part_plist_t&Parameters()const; 108 const part_plist_t&Parameters()const;
104 void addParameter(const QString&key,const QString&value); 109 void addParameter(const QString&key,const QString&value);
105 const QString searchParamter(const QString&key)const; 110 const QString searchParamter(const QString&key)const;
106 void setPositionlist(const QValueList<int>&poslist); 111 void setPositionlist(const QValueList<int>&poslist);
107 const QValueList<int>& Positionlist()const; 112 const QValueList<int>& Positionlist()const;
108}; 113};
109 114
110class RecBody 115class RecBody
111{ 116{
112protected: 117protected:
113 QString m_BodyText; 118 QString m_BodyText;
114 QValueList<RecPart> m_PartsList; 119 QValueList<RecPart> m_PartsList;
115 RecPart m_description; 120 RecPart m_description;
116 121
117public: 122public:
118 RecBody(); 123 RecBody();
119 virtual ~RecBody(); 124 virtual ~RecBody();
120 void setBodytext(const QString&); 125 void setBodytext(const QString&);
121 const QString& Bodytext()const; 126 const QString& Bodytext()const;
122 127
123 void setDescription(const RecPart&des); 128 void setDescription(const RecPart&des);
124 const RecPart& Description()const; 129 const RecPart& Description()const;
125 130
126 void setParts(const QValueList<RecPart>&parts); 131 void setParts(const QValueList<RecPart>&parts);
127 const QValueList<RecPart>& Parts()const; 132 const QValueList<RecPart>& Parts()const;
128 void addPart(const RecPart&part); 133 void addPart(const RecPart&part);
129}; 134};
130 135
131#endif 136#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 49c3b7a..903ef4d 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,289 +1,290 @@
1 1
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5 5
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL; 9 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 22RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{ 23{
24 int err = MAILPOP3_NO_ERROR; 24 int err = MAILPOP3_NO_ERROR;
25 char *message; 25 char *message;
26 size_t length; 26 size_t length;
27 27
28 login(); 28 login();
29 if ( !m_pop3 ) return RecBody(); 29 if ( !m_pop3 ) return RecBody();
30 30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) { 32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 mail->setWrapper(this);
84 target.append( mail ); 85 target.append( mail );
85 } 86 }
86 87
87 logout(); 88 logout();
88} 89}
89 90
90RecMail *POP3wrapper::parseHeader( const char *header ) 91RecMail *POP3wrapper::parseHeader( const char *header )
91{ 92{
92 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
93 size_t curTok; 94 size_t curTok;
94 RecMail *mail = new RecMail(); 95 RecMail *mail = new RecMail();
95 mailimf_fields *fields; 96 mailimf_fields *fields;
96 97
97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
99 mailimf_field *field = (mailimf_field *) current->data; 100 mailimf_field *field = (mailimf_field *) current->data;
100 switch ( field->fld_type ) { 101 switch ( field->fld_type ) {
101 case MAILIMF_FIELD_FROM: 102 case MAILIMF_FIELD_FROM:
102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
103 break; 104 break;
104 case MAILIMF_FIELD_TO: 105 case MAILIMF_FIELD_TO:
105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
106 break; 107 break;
107 case MAILIMF_FIELD_CC: 108 case MAILIMF_FIELD_CC:
108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
109 break; 110 break;
110 case MAILIMF_FIELD_BCC: 111 case MAILIMF_FIELD_BCC:
111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
112 break; 113 break;
113 case MAILIMF_FIELD_SUBJECT: 114 case MAILIMF_FIELD_SUBJECT:
114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
115 break; 116 break;
116 case MAILIMF_FIELD_ORIG_DATE: 117 case MAILIMF_FIELD_ORIG_DATE:
117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
118 break; 119 break;
119 default: 120 default:
120 break; 121 break;
121 } 122 }
122 } 123 }
123 124
124 return mail; 125 return mail;
125} 126}
126 127
127QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 128QString POP3wrapper::parseDateTime( mailimf_date_time *date )
128{ 129{
129 char tmp[23]; 130 char tmp[23];
130 131
131 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
132 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
133 134
134 return QString( tmp ); 135 return QString( tmp );
135} 136}
136 137
137QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 138QString POP3wrapper::parseAddressList( mailimf_address_list *list )
138{ 139{
139 QString result( "" ); 140 QString result( "" );
140 141
141 bool first = true; 142 bool first = true;
142 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
143 mailimf_address *addr = (mailimf_address *) current->data; 144 mailimf_address *addr = (mailimf_address *) current->data;
144 145
145 if ( !first ) { 146 if ( !first ) {
146 result.append( "," ); 147 result.append( "," );
147 } else { 148 } else {
148 first = false; 149 first = false;
149 } 150 }
150 151
151 switch ( addr->ad_type ) { 152 switch ( addr->ad_type ) {
152 case MAILIMF_ADDRESS_MAILBOX: 153 case MAILIMF_ADDRESS_MAILBOX:
153 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
154 break; 155 break;
155 case MAILIMF_ADDRESS_GROUP: 156 case MAILIMF_ADDRESS_GROUP:
156 result.append( parseGroup( addr->ad_data.ad_group ) ); 157 result.append( parseGroup( addr->ad_data.ad_group ) );
157 break; 158 break;
158 default: 159 default:
159 qDebug( "POP3: unkown mailimf address type" ); 160 qDebug( "POP3: unkown mailimf address type" );
160 break; 161 break;
161 } 162 }
162 } 163 }
163 164
164 return result; 165 return result;
165} 166}
166 167
167QString POP3wrapper::parseGroup( mailimf_group *group ) 168QString POP3wrapper::parseGroup( mailimf_group *group )
168{ 169{
169 QString result( "" ); 170 QString result( "" );
170 171
171 result.append( group->grp_display_name ); 172 result.append( group->grp_display_name );
172 result.append( ": " ); 173 result.append( ": " );
173 174
174 if ( group->grp_mb_list != NULL ) { 175 if ( group->grp_mb_list != NULL ) {
175 result.append( parseMailboxList( group->grp_mb_list ) ); 176 result.append( parseMailboxList( group->grp_mb_list ) );
176 } 177 }
177 178
178 result.append( ";" ); 179 result.append( ";" );
179 180
180 return result; 181 return result;
181} 182}
182 183
183QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 184QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
184{ 185{
185 QString result( "" ); 186 QString result( "" );
186 187
187 if ( box->mb_display_name == NULL ) { 188 if ( box->mb_display_name == NULL ) {
188 result.append( box->mb_addr_spec ); 189 result.append( box->mb_addr_spec );
189 } else { 190 } else {
190 result.append( box->mb_display_name ); 191 result.append( box->mb_display_name );
191 result.append( " <" ); 192 result.append( " <" );
192 result.append( box->mb_addr_spec ); 193 result.append( box->mb_addr_spec );
193 result.append( ">" ); 194 result.append( ">" );
194 } 195 }
195 196
196 return result; 197 return result;
197} 198}
198 199
199QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
200{ 201{
201 QString result( "" ); 202 QString result( "" );
202 203
203 bool first = true; 204 bool first = true;
204 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
205 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 206 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
206 207
207 if ( !first ) { 208 if ( !first ) {
208 result.append( "," ); 209 result.append( "," );
209 } else { 210 } else {
210 first = false; 211 first = false;
211 } 212 }
212 213
213 result.append( parseMailbox( box ) ); 214 result.append( parseMailbox( box ) );
214 } 215 }
215 216
216 return result; 217 return result;
217} 218}
218 219
219void POP3wrapper::login() 220void POP3wrapper::login()
220{ 221{
221 if ( m_pop3 != NULL ) logout(); 222 if ( m_pop3 != NULL ) logout();
222 223
223 const char *server, *user, *pass; 224 const char *server, *user, *pass;
224 uint16_t port; 225 uint16_t port;
225 int err = MAILPOP3_NO_ERROR; 226 int err = MAILPOP3_NO_ERROR;
226 227
227 server = account->getServer().latin1(); 228 server = account->getServer().latin1();
228 port = account->getPort().toUInt(); 229 port = account->getPort().toUInt();
229 user = account->getUser().latin1(); 230 user = account->getUser().latin1();
230 pass = account->getPassword().latin1(); 231 pass = account->getPassword().latin1();
231 232
232 m_pop3 = mailpop3_new( 200, &pop3_progress ); 233 m_pop3 = mailpop3_new( 200, &pop3_progress );
233 234
234 // connect 235 // connect
235 if (account->getSSL()) { 236 if (account->getSSL()) {
236 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
237 } else { 238 } else {
238 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 239 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
239 } 240 }
240 241
241 if ( err != MAILPOP3_NO_ERROR ) { 242 if ( err != MAILPOP3_NO_ERROR ) {
242 qDebug( "pop3: error connecting to %s\n reason: %s", server, 243 qDebug( "pop3: error connecting to %s\n reason: %s", server,
243 m_pop3->pop3_response ); 244 m_pop3->pop3_response );
244 mailpop3_free( m_pop3 ); 245 mailpop3_free( m_pop3 );
245 m_pop3 = NULL; 246 m_pop3 = NULL;
246 return; 247 return;
247 } 248 }
248 qDebug( "POP3: connected!" ); 249 qDebug( "POP3: connected!" );
249 250
250 // login 251 // login
251 // TODO: decide if apop or plain login should be used 252 // TODO: decide if apop or plain login should be used
252 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
253 if ( err != MAILPOP3_NO_ERROR ) { 254 if ( err != MAILPOP3_NO_ERROR ) {
254 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
255 logout(); 256 logout();
256 return; 257 return;
257 } 258 }
258 259
259 qDebug( "POP3: logged in!" ); 260 qDebug( "POP3: logged in!" );
260} 261}
261 262
262void POP3wrapper::logout() 263void POP3wrapper::logout()
263{ 264{
264 int err = MAILPOP3_NO_ERROR; 265 int err = MAILPOP3_NO_ERROR;
265 if ( m_pop3 == NULL ) return; 266 if ( m_pop3 == NULL ) return;
266 err = mailpop3_quit( m_pop3 ); 267 err = mailpop3_quit( m_pop3 );
267 mailpop3_free( m_pop3 ); 268 mailpop3_free( m_pop3 );
268 m_pop3 = NULL; 269 m_pop3 = NULL;
269} 270}
270 271
271 272
272QList<Folder>* POP3wrapper::listFolders() 273QList<Folder>* POP3wrapper::listFolders()
273{ 274{
274 QList<Folder> * folders = new QList<Folder>(); 275 QList<Folder> * folders = new QList<Folder>();
275 folders->setAutoDelete( true ); 276 folders->setAutoDelete( true );
276 Folder*inb=new Folder("INBOX"); 277 Folder*inb=new Folder("INBOX");
277 folders->append(inb); 278 folders->append(inb);
278 return folders; 279 return folders;
279} 280}
280 281
281QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool) 282QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool)
282{ 283{
283 return ""; 284 return "";
284} 285}
285 286
286QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 287QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
287{ 288{
288 return ""; 289 return "";
289} 290}
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
index 5cd45ed..94f5d6f 100644
--- a/noncore/net/mail/mailtypes.cpp
+++ b/noncore/net/mail/mailtypes.cpp
@@ -1,220 +1,237 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
15 qDebug("Copy constructor RecMail"); 15 qDebug("Copy constructor RecMail");
16} 16}
17 17
18RecMail::~RecMail()
19{
20 wrapper = 0;
21}
22
18void RecMail::copy_old(const RecMail&old) 23void RecMail::copy_old(const RecMail&old)
19{ 24{
20 subject = old.subject; 25 subject = old.subject;
21 date = old.date; 26 date = old.date;
22 mbox = old.mbox; 27 mbox = old.mbox;
23 msg_id = old.msg_id; 28 msg_id = old.msg_id;
24 msg_size = old.msg_size; 29 msg_size = old.msg_size;
25 msg_number = old.msg_number; 30 msg_number = old.msg_number;
26 from = old.from; 31 from = old.from;
27 msg_flags = old.msg_flags; 32 msg_flags = old.msg_flags;
28 to = old.to; 33 to = old.to;
29 cc = old.cc; 34 cc = old.cc;
30 bcc = old.bcc; 35 bcc = old.bcc;
36 wrapper = old.wrapper;
31} 37}
32 38
33void RecMail::init() 39void RecMail::init()
34{ 40{
35 to.clear(); 41 to.clear();
36 cc.clear(); 42 cc.clear();
37 bcc.clear(); 43 bcc.clear();
44 wrapper = 0;
45}
46
47void RecMail::setWrapper(AbstractMail*awrapper)
48{
49 wrapper = awrapper;
50}
51
52AbstractMail* RecMail::Wrapper()
53{
54 return wrapper;
38} 55}
39 56
40void RecMail::setTo(const QStringList&list) 57void RecMail::setTo(const QStringList&list)
41{ 58{
42 to = list; 59 to = list;
43} 60}
44 61
45const QStringList&RecMail::To()const 62const QStringList&RecMail::To()const
46{ 63{
47 return to; 64 return to;
48} 65}
49 66
50void RecMail::setCC(const QStringList&list) 67void RecMail::setCC(const QStringList&list)
51{ 68{
52 cc = list; 69 cc = list;
53} 70}
54 71
55const QStringList&RecMail::CC()const 72const QStringList&RecMail::CC()const
56{ 73{
57 return cc; 74 return cc;
58} 75}
59 76
60void RecMail::setBcc(const QStringList&list) 77void RecMail::setBcc(const QStringList&list)
61{ 78{
62 bcc = list; 79 bcc = list;
63} 80}
64 81
65const QStringList& RecMail::Bcc()const 82const QStringList& RecMail::Bcc()const
66{ 83{
67 return bcc; 84 return bcc;
68} 85}
69 86
70RecPart::RecPart() 87RecPart::RecPart()
71 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0) 88 : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0),m_size(0)
72{ 89{
73 m_Parameters.clear(); 90 m_Parameters.clear();
74 m_poslist.clear(); 91 m_poslist.clear();
75} 92}
76 93
77RecPart::~RecPart() 94RecPart::~RecPart()
78{ 95{
79} 96}
80 97
81void RecPart::setSize(unsigned int size) 98void RecPart::setSize(unsigned int size)
82{ 99{
83 m_size = size; 100 m_size = size;
84} 101}
85 102
86const unsigned int RecPart::Size()const 103const unsigned int RecPart::Size()const
87{ 104{
88 return m_size; 105 return m_size;
89} 106}
90 107
91void RecPart::setLines(unsigned int lines) 108void RecPart::setLines(unsigned int lines)
92{ 109{
93 m_lines = lines; 110 m_lines = lines;
94} 111}
95 112
96const unsigned int RecPart::Lines()const 113const unsigned int RecPart::Lines()const
97{ 114{
98 return m_lines; 115 return m_lines;
99} 116}
100 117
101const QString& RecPart::Type()const 118const QString& RecPart::Type()const
102{ 119{
103 return m_type; 120 return m_type;
104} 121}
105 122
106void RecPart::setType(const QString&type) 123void RecPart::setType(const QString&type)
107{ 124{
108 m_type = type; 125 m_type = type;
109} 126}
110 127
111const QString& RecPart::Subtype()const 128const QString& RecPart::Subtype()const
112{ 129{
113 return m_subtype; 130 return m_subtype;
114} 131}
115 132
116void RecPart::setSubtype(const QString&subtype) 133void RecPart::setSubtype(const QString&subtype)
117{ 134{
118 m_subtype = subtype; 135 m_subtype = subtype;
119} 136}
120 137
121const QString& RecPart::Identifier()const 138const QString& RecPart::Identifier()const
122{ 139{
123 return m_identifier; 140 return m_identifier;
124} 141}
125 142
126void RecPart::setIdentifier(const QString&identifier) 143void RecPart::setIdentifier(const QString&identifier)
127{ 144{
128 m_identifier = identifier; 145 m_identifier = identifier;
129} 146}
130 147
131const QString& RecPart::Encoding()const 148const QString& RecPart::Encoding()const
132{ 149{
133 return m_encoding; 150 return m_encoding;
134} 151}
135 152
136void RecPart::setEncoding(const QString&encoding) 153void RecPart::setEncoding(const QString&encoding)
137{ 154{
138 m_encoding = encoding; 155 m_encoding = encoding;
139} 156}
140 157
141void RecPart::setParameters(const part_plist_t&list) 158void RecPart::setParameters(const part_plist_t&list)
142{ 159{
143 m_Parameters = list; 160 m_Parameters = list;
144} 161}
145 162
146const part_plist_t& RecPart::Parameters()const 163const part_plist_t& RecPart::Parameters()const
147{ 164{
148 return m_Parameters; 165 return m_Parameters;
149} 166}
150 167
151void RecPart::addParameter(const QString&key,const QString&value) 168void RecPart::addParameter(const QString&key,const QString&value)
152{ 169{
153 m_Parameters[key]=value; 170 m_Parameters[key]=value;
154} 171}
155 172
156const QString RecPart::searchParamter(const QString&key)const 173const QString RecPart::searchParamter(const QString&key)const
157{ 174{
158 QString value(""); 175 QString value("");
159 part_plist_t::ConstIterator it = m_Parameters.find(key); 176 part_plist_t::ConstIterator it = m_Parameters.find(key);
160 if (it != m_Parameters.end()) { 177 if (it != m_Parameters.end()) {
161 value = it.data(); 178 value = it.data();
162 } 179 }
163 return value; 180 return value;
164} 181}
165 182
166void RecPart::setPositionlist(const QValueList<int>&poslist) 183void RecPart::setPositionlist(const QValueList<int>&poslist)
167{ 184{
168 m_poslist = poslist; 185 m_poslist = poslist;
169} 186}
170 187
171const QValueList<int>& RecPart::Positionlist()const 188const QValueList<int>& RecPart::Positionlist()const
172{ 189{
173 return m_poslist; 190 return m_poslist;
174} 191}
175 192
176RecBody::RecBody() 193RecBody::RecBody()
177 : m_BodyText(),m_PartsList(),m_description() 194 : m_BodyText(),m_PartsList(),m_description()
178{ 195{
179 m_PartsList.clear(); 196 m_PartsList.clear();
180} 197}
181 198
182RecBody::~RecBody() 199RecBody::~RecBody()
183{ 200{
184} 201}
185 202
186void RecBody::setBodytext(const QString&bodyText) 203void RecBody::setBodytext(const QString&bodyText)
187{ 204{
188 m_BodyText = bodyText; 205 m_BodyText = bodyText;
189} 206}
190 207
191const QString& RecBody::Bodytext()const 208const QString& RecBody::Bodytext()const
192{ 209{
193 return m_BodyText; 210 return m_BodyText;
194} 211}
195 212
196void RecBody::setParts(const QValueList<RecPart>&parts) 213void RecBody::setParts(const QValueList<RecPart>&parts)
197{ 214{
198 m_PartsList.clear(); 215 m_PartsList.clear();
199 m_PartsList = parts; 216 m_PartsList = parts;
200} 217}
201 218
202const QValueList<RecPart>& RecBody::Parts()const 219const QValueList<RecPart>& RecBody::Parts()const
203{ 220{
204 return m_PartsList; 221 return m_PartsList;
205} 222}
206 223
207void RecBody::addPart(const RecPart& part) 224void RecBody::addPart(const RecPart& part)
208{ 225{
209 m_PartsList.append(part); 226 m_PartsList.append(part);
210} 227}
211 228
212void RecBody::setDescription(const RecPart&des) 229void RecBody::setDescription(const RecPart&des)
213{ 230{
214 m_description = des; 231 m_description = des;
215} 232}
216 233
217const RecPart& RecBody::Description()const 234const RecPart& RecBody::Description()const
218{ 235{
219 return m_description; 236 return m_description;
220} 237}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index 24518cf..9ef762d 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -1,131 +1,136 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <qlist.h> 11#include <qlist.h>
12#include <qbitarray.h> 12#include <qbitarray.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15#include <qmap.h> 15#include <qmap.h>
16#include <qvaluelist.h> 16#include <qvaluelist.h>
17 17
18class AbstractMail;
18/* a class to describe mails in a mailbox */ 19/* a class to describe mails in a mailbox */
19/* Attention! 20/* Attention!
20 From programmers point of view it would make sense to 21 From programmers point of view it would make sense to
21 store the mail body into this class, too. 22 store the mail body into this class, too.
22 But: not from the point of view of the device. 23 But: not from the point of view of the device.
23 Mailbodies can be real large. So we request them when 24 Mailbodies can be real large. So we request them when
24 needed from the mail-wrapper class direct from the server itself 25 needed from the mail-wrapper class direct from the server itself
25 (imap) or from a file-based cache (pop3?) 26 (imap) or from a file-based cache (pop3?)
26 So there is no interface "const QString&body()" but you should 27 So there is no interface "const QString&body()" but you should
27 make a request to the mailwrapper with this class as parameter to 28 make a request to the mailwrapper with this class as parameter to
28 get the body. Same words for the attachments. 29 get the body. Same words for the attachments.
29*/ 30*/
30class RecMail 31class RecMail
31{ 32{
32public: 33public:
33 RecMail(); 34 RecMail();
34 RecMail(const RecMail&old); 35 RecMail(const RecMail&old);
35 virtual ~RecMail(){} 36 virtual ~RecMail();
36 37
37 const int getNumber()const{return msg_number;} 38 const int getNumber()const{return msg_number;}
38 void setNumber(int number){msg_number=number;} 39 void setNumber(int number){msg_number=number;}
39 const QString&getDate()const{ return date; } 40 const QString&getDate()const{ return date; }
40 void setDate( const QString&a ) { date = a; } 41 void setDate( const QString&a ) { date = a; }
41 const QString&getFrom()const{ return from; } 42 const QString&getFrom()const{ return from; }
42 void setFrom( const QString&a ) { from = a; } 43 void setFrom( const QString&a ) { from = a; }
43 const QString&getSubject()const { return subject; } 44 const QString&getSubject()const { return subject; }
44 void setSubject( const QString&s ) { subject = s; } 45 void setSubject( const QString&s ) { subject = s; }
45 const QString&getMbox()const{return mbox;} 46 const QString&getMbox()const{return mbox;}
46 void setMbox(const QString&box){mbox = box;} 47 void setMbox(const QString&box){mbox = box;}
47 void setMsgid(const QString&id){msg_id=id;} 48 void setMsgid(const QString&id){msg_id=id;}
48 const QString&Msgid()const{return msg_id;} 49 const QString&Msgid()const{return msg_id;}
49 void setReplyto(const QString&reply){replyto=reply;} 50 void setReplyto(const QString&reply){replyto=reply;}
50 const QString&Replyto()const{return replyto;} 51 const QString&Replyto()const{return replyto;}
51 void setMsgsize(int size){msg_size = size;} 52 void setMsgsize(int size){msg_size = size;}
52 const int Msgsize()const{return msg_size;} 53 const int Msgsize()const{return msg_size;}
53 54
54 55
55 void setTo(const QStringList&list); 56 void setTo(const QStringList&list);
56 const QStringList&To()const; 57 const QStringList&To()const;
57 void setCC(const QStringList&list); 58 void setCC(const QStringList&list);
58 const QStringList&CC()const; 59 const QStringList&CC()const;
59 void setBcc(const QStringList&list); 60 void setBcc(const QStringList&list);
60 const QStringList&Bcc()const; 61 const QStringList&Bcc()const;
61 const QBitArray&getFlags()const{return msg_flags;} 62 const QBitArray&getFlags()const{return msg_flags;}
62 void setFlags(const QBitArray&flags){msg_flags = flags;} 63 void setFlags(const QBitArray&flags){msg_flags = flags;}
64
65 void setWrapper(AbstractMail*wrapper);
66 AbstractMail* Wrapper();
63 67
64protected: 68protected:
65 QString subject,date,from,mbox,msg_id,replyto; 69 QString subject,date,from,mbox,msg_id,replyto;
66 int msg_number,msg_size; 70 int msg_number,msg_size;
67 QBitArray msg_flags; 71 QBitArray msg_flags;
68 QStringList to,cc,bcc; 72 QStringList to,cc,bcc;
73 AbstractMail*wrapper;
69 void init(); 74 void init();
70 void copy_old(const RecMail&old); 75 void copy_old(const RecMail&old);
71}; 76};
72 77
73typedef QMap<QString,QString> part_plist_t; 78typedef QMap<QString,QString> part_plist_t;
74 79
75class RecPart 80class RecPart
76{ 81{
77protected: 82protected:
78 QString m_type,m_subtype,m_identifier,m_encoding; 83 QString m_type,m_subtype,m_identifier,m_encoding;
79 unsigned int m_lines,m_size; 84 unsigned int m_lines,m_size;
80 part_plist_t m_Parameters; 85 part_plist_t m_Parameters;
81 /* describes the position in the mail */ 86 /* describes the position in the mail */
82 QValueList<int> m_poslist; 87 QValueList<int> m_poslist;
83 88
84public: 89public:
85 RecPart(); 90 RecPart();
86 virtual ~RecPart(); 91 virtual ~RecPart();
87 92
88 const QString&Type()const; 93 const QString&Type()const;
89 void setType(const QString&type); 94 void setType(const QString&type);
90 const QString&Subtype()const; 95 const QString&Subtype()const;
91 void setSubtype(const QString&subtype); 96 void setSubtype(const QString&subtype);
92 const QString&Identifier()const; 97 const QString&Identifier()const;
93 void setIdentifier(const QString&identifier); 98 void setIdentifier(const QString&identifier);
94 const QString&Encoding()const; 99 const QString&Encoding()const;
95 void setEncoding(const QString&encoding); 100 void setEncoding(const QString&encoding);
96 void setLines(unsigned int lines); 101 void setLines(unsigned int lines);
97 const unsigned int Lines()const; 102 const unsigned int Lines()const;
98 void setSize(unsigned int size); 103 void setSize(unsigned int size);
99 const unsigned int Size()const; 104 const unsigned int Size()const;
100 105
101 106
102 void setParameters(const part_plist_t&list); 107 void setParameters(const part_plist_t&list);
103 const part_plist_t&Parameters()const; 108 const part_plist_t&Parameters()const;
104 void addParameter(const QString&key,const QString&value); 109 void addParameter(const QString&key,const QString&value);
105 const QString searchParamter(const QString&key)const; 110 const QString searchParamter(const QString&key)const;
106 void setPositionlist(const QValueList<int>&poslist); 111 void setPositionlist(const QValueList<int>&poslist);
107 const QValueList<int>& Positionlist()const; 112 const QValueList<int>& Positionlist()const;
108}; 113};
109 114
110class RecBody 115class RecBody
111{ 116{
112protected: 117protected:
113 QString m_BodyText; 118 QString m_BodyText;
114 QValueList<RecPart> m_PartsList; 119 QValueList<RecPart> m_PartsList;
115 RecPart m_description; 120 RecPart m_description;
116 121
117public: 122public:
118 RecBody(); 123 RecBody();
119 virtual ~RecBody(); 124 virtual ~RecBody();
120 void setBodytext(const QString&); 125 void setBodytext(const QString&);
121 const QString& Bodytext()const; 126 const QString& Bodytext()const;
122 127
123 void setDescription(const RecPart&des); 128 void setDescription(const RecPart&des);
124 const RecPart& Description()const; 129 const RecPart& Description()const;
125 130
126 void setParts(const QValueList<RecPart>&parts); 131 void setParts(const QValueList<RecPart>&parts);
127 const QValueList<RecPart>& Parts()const; 132 const QValueList<RecPart>& Parts()const;
128 void addPart(const RecPart&part); 133 void addPart(const RecPart&part);
129}; 134};
130 135
131#endif 136#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 49c3b7a..903ef4d 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,289 +1,290 @@
1 1
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5 5
6POP3wrapper::POP3wrapper( POP3account *a ) 6POP3wrapper::POP3wrapper( POP3account *a )
7{ 7{
8 account = a; 8 account = a;
9 m_pop3 = NULL; 9 m_pop3 = NULL;
10} 10}
11 11
12POP3wrapper::~POP3wrapper() 12POP3wrapper::~POP3wrapper()
13{ 13{
14 logout(); 14 logout();
15} 15}
16 16
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 17void POP3wrapper::pop3_progress( size_t current, size_t maximum )
18{ 18{
19 qDebug( "POP3: %i of %i", current, maximum ); 19 qDebug( "POP3: %i of %i", current, maximum );
20} 20}
21 21
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 22RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{ 23{
24 int err = MAILPOP3_NO_ERROR; 24 int err = MAILPOP3_NO_ERROR;
25 char *message; 25 char *message;
26 size_t length; 26 size_t length;
27 27
28 login(); 28 login();
29 if ( !m_pop3 ) return RecBody(); 29 if ( !m_pop3 ) return RecBody();
30 30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) { 32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 mail->setWrapper(this);
84 target.append( mail ); 85 target.append( mail );
85 } 86 }
86 87
87 logout(); 88 logout();
88} 89}
89 90
90RecMail *POP3wrapper::parseHeader( const char *header ) 91RecMail *POP3wrapper::parseHeader( const char *header )
91{ 92{
92 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
93 size_t curTok; 94 size_t curTok;
94 RecMail *mail = new RecMail(); 95 RecMail *mail = new RecMail();
95 mailimf_fields *fields; 96 mailimf_fields *fields;
96 97
97 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
98 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
99 mailimf_field *field = (mailimf_field *) current->data; 100 mailimf_field *field = (mailimf_field *) current->data;
100 switch ( field->fld_type ) { 101 switch ( field->fld_type ) {
101 case MAILIMF_FIELD_FROM: 102 case MAILIMF_FIELD_FROM:
102 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
103 break; 104 break;
104 case MAILIMF_FIELD_TO: 105 case MAILIMF_FIELD_TO:
105 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
106 break; 107 break;
107 case MAILIMF_FIELD_CC: 108 case MAILIMF_FIELD_CC:
108 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
109 break; 110 break;
110 case MAILIMF_FIELD_BCC: 111 case MAILIMF_FIELD_BCC:
111 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
112 break; 113 break;
113 case MAILIMF_FIELD_SUBJECT: 114 case MAILIMF_FIELD_SUBJECT:
114 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
115 break; 116 break;
116 case MAILIMF_FIELD_ORIG_DATE: 117 case MAILIMF_FIELD_ORIG_DATE:
117 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
118 break; 119 break;
119 default: 120 default:
120 break; 121 break;
121 } 122 }
122 } 123 }
123 124
124 return mail; 125 return mail;
125} 126}
126 127
127QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 128QString POP3wrapper::parseDateTime( mailimf_date_time *date )
128{ 129{
129 char tmp[23]; 130 char tmp[23];
130 131
131 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
132 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
133 134
134 return QString( tmp ); 135 return QString( tmp );
135} 136}
136 137
137QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 138QString POP3wrapper::parseAddressList( mailimf_address_list *list )
138{ 139{
139 QString result( "" ); 140 QString result( "" );
140 141
141 bool first = true; 142 bool first = true;
142 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
143 mailimf_address *addr = (mailimf_address *) current->data; 144 mailimf_address *addr = (mailimf_address *) current->data;
144 145
145 if ( !first ) { 146 if ( !first ) {
146 result.append( "," ); 147 result.append( "," );
147 } else { 148 } else {
148 first = false; 149 first = false;
149 } 150 }
150 151
151 switch ( addr->ad_type ) { 152 switch ( addr->ad_type ) {
152 case MAILIMF_ADDRESS_MAILBOX: 153 case MAILIMF_ADDRESS_MAILBOX:
153 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
154 break; 155 break;
155 case MAILIMF_ADDRESS_GROUP: 156 case MAILIMF_ADDRESS_GROUP:
156 result.append( parseGroup( addr->ad_data.ad_group ) ); 157 result.append( parseGroup( addr->ad_data.ad_group ) );
157 break; 158 break;
158 default: 159 default:
159 qDebug( "POP3: unkown mailimf address type" ); 160 qDebug( "POP3: unkown mailimf address type" );
160 break; 161 break;
161 } 162 }
162 } 163 }
163 164
164 return result; 165 return result;
165} 166}
166 167
167QString POP3wrapper::parseGroup( mailimf_group *group ) 168QString POP3wrapper::parseGroup( mailimf_group *group )
168{ 169{
169 QString result( "" ); 170 QString result( "" );
170 171
171 result.append( group->grp_display_name ); 172 result.append( group->grp_display_name );
172 result.append( ": " ); 173 result.append( ": " );
173 174
174 if ( group->grp_mb_list != NULL ) { 175 if ( group->grp_mb_list != NULL ) {
175 result.append( parseMailboxList( group->grp_mb_list ) ); 176 result.append( parseMailboxList( group->grp_mb_list ) );
176 } 177 }
177 178
178 result.append( ";" ); 179 result.append( ";" );
179 180
180 return result; 181 return result;
181} 182}
182 183
183QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 184QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
184{ 185{
185 QString result( "" ); 186 QString result( "" );
186 187
187 if ( box->mb_display_name == NULL ) { 188 if ( box->mb_display_name == NULL ) {
188 result.append( box->mb_addr_spec ); 189 result.append( box->mb_addr_spec );
189 } else { 190 } else {
190 result.append( box->mb_display_name ); 191 result.append( box->mb_display_name );
191 result.append( " <" ); 192 result.append( " <" );
192 result.append( box->mb_addr_spec ); 193 result.append( box->mb_addr_spec );
193 result.append( ">" ); 194 result.append( ">" );
194 } 195 }
195 196
196 return result; 197 return result;
197} 198}
198 199
199QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
200{ 201{
201 QString result( "" ); 202 QString result( "" );
202 203
203 bool first = true; 204 bool first = true;
204 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
205 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 206 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
206 207
207 if ( !first ) { 208 if ( !first ) {
208 result.append( "," ); 209 result.append( "," );
209 } else { 210 } else {
210 first = false; 211 first = false;
211 } 212 }
212 213
213 result.append( parseMailbox( box ) ); 214 result.append( parseMailbox( box ) );
214 } 215 }
215 216
216 return result; 217 return result;
217} 218}
218 219
219void POP3wrapper::login() 220void POP3wrapper::login()
220{ 221{
221 if ( m_pop3 != NULL ) logout(); 222 if ( m_pop3 != NULL ) logout();
222 223
223 const char *server, *user, *pass; 224 const char *server, *user, *pass;
224 uint16_t port; 225 uint16_t port;
225 int err = MAILPOP3_NO_ERROR; 226 int err = MAILPOP3_NO_ERROR;
226 227
227 server = account->getServer().latin1(); 228 server = account->getServer().latin1();
228 port = account->getPort().toUInt(); 229 port = account->getPort().toUInt();
229 user = account->getUser().latin1(); 230 user = account->getUser().latin1();
230 pass = account->getPassword().latin1(); 231 pass = account->getPassword().latin1();
231 232
232 m_pop3 = mailpop3_new( 200, &pop3_progress ); 233 m_pop3 = mailpop3_new( 200, &pop3_progress );
233 234
234 // connect 235 // connect
235 if (account->getSSL()) { 236 if (account->getSSL()) {
236 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
237 } else { 238 } else {
238 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 239 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
239 } 240 }
240 241
241 if ( err != MAILPOP3_NO_ERROR ) { 242 if ( err != MAILPOP3_NO_ERROR ) {
242 qDebug( "pop3: error connecting to %s\n reason: %s", server, 243 qDebug( "pop3: error connecting to %s\n reason: %s", server,
243 m_pop3->pop3_response ); 244 m_pop3->pop3_response );
244 mailpop3_free( m_pop3 ); 245 mailpop3_free( m_pop3 );
245 m_pop3 = NULL; 246 m_pop3 = NULL;
246 return; 247 return;
247 } 248 }
248 qDebug( "POP3: connected!" ); 249 qDebug( "POP3: connected!" );
249 250
250 // login 251 // login
251 // TODO: decide if apop or plain login should be used 252 // TODO: decide if apop or plain login should be used
252 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
253 if ( err != MAILPOP3_NO_ERROR ) { 254 if ( err != MAILPOP3_NO_ERROR ) {
254 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
255 logout(); 256 logout();
256 return; 257 return;
257 } 258 }
258 259
259 qDebug( "POP3: logged in!" ); 260 qDebug( "POP3: logged in!" );
260} 261}
261 262
262void POP3wrapper::logout() 263void POP3wrapper::logout()
263{ 264{
264 int err = MAILPOP3_NO_ERROR; 265 int err = MAILPOP3_NO_ERROR;
265 if ( m_pop3 == NULL ) return; 266 if ( m_pop3 == NULL ) return;
266 err = mailpop3_quit( m_pop3 ); 267 err = mailpop3_quit( m_pop3 );
267 mailpop3_free( m_pop3 ); 268 mailpop3_free( m_pop3 );
268 m_pop3 = NULL; 269 m_pop3 = NULL;
269} 270}
270 271
271 272
272QList<Folder>* POP3wrapper::listFolders() 273QList<Folder>* POP3wrapper::listFolders()
273{ 274{
274 QList<Folder> * folders = new QList<Folder>(); 275 QList<Folder> * folders = new QList<Folder>();
275 folders->setAutoDelete( true ); 276 folders->setAutoDelete( true );
276 Folder*inb=new Folder("INBOX"); 277 Folder*inb=new Folder("INBOX");
277 folders->append(inb); 278 folders->append(inb);
278 return folders; 279 return folders;
279} 280}
280 281
281QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool) 282QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool)
282{ 283{
283 return ""; 284 return "";
284} 285}
285 286
286QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 287QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
287{ 288{
288 return ""; 289 return "";
289} 290}