summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/ProgrammersDoc/ReceivingMails.diabin3086 -> 3158 bytes
-rw-r--r--noncore/net/mail/imapwrapper.cpp29
-rw-r--r--noncore/net/mail/imapwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp29
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h5
-rw-r--r--noncore/net/mail/mailtypes.h5
7 files changed, 42 insertions, 30 deletions
diff --git a/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia b/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia
index 08c6434..2e3033e 100644
--- a/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia
+++ b/noncore/net/mail/ProgrammersDoc/ReceivingMails.dia
Binary files differ
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 5ce140e..eae85a7 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,468 +1,471 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9{ 9{
10 account = a; 10 account = a;
11 m_imap = 0; 11 m_imap = 0;
12} 12}
13 13
14IMAPwrapper::~IMAPwrapper() 14IMAPwrapper::~IMAPwrapper()
15{ 15{
16 logout(); 16 logout();
17} 17}
18 18
19void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 19void IMAPwrapper::imap_progress( size_t current, size_t maximum )
20{ 20{
21 qDebug( "IMAP: %i of %i", current, maximum ); 21 qDebug( "IMAP: %i of %i", current, maximum );
22} 22}
23 23
24void IMAPwrapper::login() 24void IMAPwrapper::login()
25{ 25{
26 logout(); 26 logout();
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 server = account->getServer().latin1(); 31 server = account->getServer().latin1();
32 port = account->getPort().toUInt(); 32 port = account->getPort().toUInt();
33 user = account->getUser().latin1(); 33 user = account->getUser().latin1();
34 pass = account->getPassword().latin1(); 34 pass = account->getPassword().latin1();
35 35
36 m_imap = mailimap_new( 20, &imap_progress ); 36 m_imap = mailimap_new( 20, &imap_progress );
37 /* connect */ 37 /* connect */
38 err = mailimap_socket_connect( m_imap, (char*)server, port ); 38 err = mailimap_socket_connect( m_imap, (char*)server, port );
39 if ( err != MAILIMAP_NO_ERROR && 39 if ( err != MAILIMAP_NO_ERROR &&
40 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 40 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
42 qDebug("error connecting server: %s",m_imap->response); 42 qDebug("error connecting server: %s",m_imap->response);
43 mailimap_free( m_imap ); 43 mailimap_free( m_imap );
44 m_imap = 0; 44 m_imap = 0;
45 return; 45 return;
46 } 46 }
47 47
48 /* login */ 48 /* login */
49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
50 if ( err != MAILIMAP_NO_ERROR ) { 50 if ( err != MAILIMAP_NO_ERROR ) {
51 qDebug("error logging in imap: %s",m_imap->response); 51 qDebug("error logging in imap: %s",m_imap->response);
52 err = mailimap_close( m_imap ); 52 err = mailimap_close( m_imap );
53 mailimap_free( m_imap ); 53 mailimap_free( m_imap );
54 m_imap = 0; 54 m_imap = 0;
55 } 55 }
56} 56}
57 57
58void IMAPwrapper::logout() 58void IMAPwrapper::logout()
59{ 59{
60 int err = MAILIMAP_NO_ERROR; 60 int err = MAILIMAP_NO_ERROR;
61 if (!m_imap) return; 61 if (!m_imap) return;
62 err = mailimap_logout( m_imap ); 62 err = mailimap_logout( m_imap );
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
68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
69{ 69{
70 const char *mb; 70 const char *mb;
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 clist *result; 72 clist *result;
73 clistcell *current; 73 clistcell *current;
74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
75 mailimap_fetch_type *fetchType; 75 mailimap_fetch_type *fetchType;
76 mailimap_set *set; 76 mailimap_set *set;
77 77
78 mb = mailbox.latin1(); 78 mb = mailbox.latin1();
79 login(); 79 login();
80 if (!m_imap) { 80 if (!m_imap) {
81 return; 81 return;
82 } 82 }
83 /* select mailbox READONLY for operations */ 83 /* select mailbox READONLY for operations */
84 err = mailimap_examine( m_imap, (char*)mb); 84 err = mailimap_examine( m_imap, (char*)mb);
85 if ( err != MAILIMAP_NO_ERROR ) { 85 if ( err != MAILIMAP_NO_ERROR ) {
86 qDebug("error selecting mailbox: %s",m_imap->response); 86 qDebug("error selecting mailbox: %s",m_imap->response);
87 logout(); 87 logout();
88 return; 88 return;
89 } 89 }
90 90
91 int last = m_imap->selection_info->exists; 91 int last = m_imap->selection_info->exists;
92 92
93 if (last == 0) { 93 if (last == 0) {
94 qDebug("mailbox has no mails"); 94 qDebug("mailbox has no mails");
95 logout(); 95 logout();
96 return; 96 return;
97 } 97 }
98 98
99 result = clist_new(); 99 result = clist_new();
100 /* the range has to start at 1!!! not with 0!!!! */ 100 /* the range has to start at 1!!! not with 0!!!! */
101 set = mailimap_set_new_interval( 1, last ); 101 set = mailimap_set_new_interval( 1, last );
102 fetchAtt = mailimap_fetch_att_new_envelope(); 102 fetchAtt = mailimap_fetch_att_new_envelope();
103 fetchAttFlags = mailimap_fetch_att_new_flags(); 103 fetchAttFlags = mailimap_fetch_att_new_flags();
104 fetchAttDate = mailimap_fetch_att_new_internaldate(); 104 fetchAttDate = mailimap_fetch_att_new_internaldate();
105 105
106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
111 111
112 err = mailimap_fetch( m_imap, set, fetchType, &result ); 112 err = mailimap_fetch( m_imap, set, fetchType, &result );
113 mailimap_set_free( set ); 113 mailimap_set_free( set );
114 /* cleans up the fetch_att's too! */ 114 /* cleans up the fetch_att's too! */
115 mailimap_fetch_type_free( fetchType ); 115 mailimap_fetch_type_free( fetchType );
116 116
117 QString date,subject,from; 117 QString date,subject,from;
118 118
119 if ( err == MAILIMAP_NO_ERROR ) { 119 if ( err == MAILIMAP_NO_ERROR ) {
120 current = clist_begin(result); 120 current = clist_begin(result);
121 mailimap_msg_att * msg_att; 121 mailimap_msg_att * msg_att;
122 int i = 0; 122 int i = 0;
123 while ( current != 0 ) { 123 while ( current != 0 ) {
124 ++i; 124 ++i;
125 msg_att = (mailimap_msg_att*)current->data; 125 msg_att = (mailimap_msg_att*)current->data;
126 RecMail*m = parse_list_result(msg_att); 126 RecMail*m = parse_list_result(msg_att);
127 if (m) { 127 if (m) {
128 m->setNumber(i); 128 m->setNumber(i);
129 m->setMbox(mailbox); 129 m->setMbox(mailbox);
130 target.append(m); 130 target.append(m);
131 } 131 }
132 current = current->next; 132 current = current->next;
133 } 133 }
134 } else { 134 } else {
135 qDebug("Error fetching headers: %s",m_imap->response); 135 qDebug("Error fetching headers: %s",m_imap->response);
136 } 136 }
137 logout(); 137 logout();
138 clist_free(result); 138 clist_free(result);
139} 139}
140 140
141QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 142{
143 const char *path, *mask; 143 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
145 clist *result; 145 clist *result;
146 clistcell *current; 146 clistcell *current;
147 147
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
150 login(); 150 login();
151 if (!m_imap) { 151 if (!m_imap) {
152 return folders; 152 return folders;
153 } 153 }
154 154
155/* 155/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
157 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
158 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 159 */
160 QString temp; 160 QString temp;
161 mask = "INBOX" ; 161 mask = "INBOX" ;
162 result = clist_new(); 162 result = clist_new();
163 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 166 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 170 // instead of using strdup!
171 temp = list->mb; 171 temp = list->mb;
172 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
173 current = current->next; 173 current = current->next;
174 } 174 }
175 } else { 175 } else {
176 qDebug("error fetching folders: %s",m_imap->response); 176 qDebug("error fetching folders: %s",m_imap->response);
177 } 177 }
178 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
179 179
180/* 180/*
181 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
182 */ 182 */
183 mask = "*" ; 183 mask = "*" ;
184 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
185 result = clist_new(); 185 result = clist_new();
186 qDebug(path); 186 qDebug(path);
187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
188 if ( err == MAILIMAP_NO_ERROR ) { 188 if ( err == MAILIMAP_NO_ERROR ) {
189 current = result->first; 189 current = result->first;
190 for ( int i = result->count; i > 0; i-- ) { 190 for ( int i = result->count; i > 0; i-- ) {
191 list = (mailimap_mailbox_list *) current->data; 191 list = (mailimap_mailbox_list *) current->data;
192 // it is better use the deep copy mechanism of qt itself 192 // it is better use the deep copy mechanism of qt itself
193 // instead of using strdup! 193 // instead of using strdup!
194 temp = list->mb; 194 temp = list->mb;
195 current = current->next; 195 current = current->next;
196 if (temp.lower()=="inbox") 196 if (temp.lower()=="inbox")
197 continue; 197 continue;
198 folders->append(new IMAPFolder(temp)); 198 folders->append(new IMAPFolder(temp));
199 199
200 } 200 }
201 } else { 201 } else {
202 qDebug("error fetching folders %s",m_imap->response); 202 qDebug("error fetching folders %s",m_imap->response);
203 } 203 }
204 mailimap_list_result_free( result ); 204 mailimap_list_result_free( result );
205 return folders; 205 return folders;
206} 206}
207 207
208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
209{ 209{
210 RecMail * m = 0; 210 RecMail * m = 0;
211 mailimap_msg_att_item *item=0; 211 mailimap_msg_att_item *item=0;
212 bool named_from = false; 212 clistcell *current,*c,*cf;
213 QString from,date,subject;
214 date = from = subject = "";
215 clistcell *current,*c,*cf, *current_from = NULL;
216 mailimap_address * current_address = NULL;
217 mailimap_msg_att_dynamic*flist; 213 mailimap_msg_att_dynamic*flist;
218 mailimap_flag_fetch*cflag; 214 mailimap_flag_fetch*cflag;
219 QBitArray mFlags(7); 215 QBitArray mFlags(7);
220 QStringList addresslist; 216 QStringList addresslist;
221 217
222 if (!m_att) { 218 if (!m_att) {
223 return m; 219 return m;
224 } 220 }
225 221
226 c = clist_begin(m_att->list); 222 c = clist_begin(m_att->list);
227 while ( c ) { 223 while ( c ) {
228 current = c; 224 current = c;
229 c = c->next; 225 c = c->next;
230 item = (mailimap_msg_att_item*)current->data; 226 item = (mailimap_msg_att_item*)current->data;
231 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 227 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
232 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 228 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
233 if (!flist->list) { 229 if (!flist->list) {
234 continue; 230 continue;
235 } 231 }
236 cf = flist->list->first; 232 cf = flist->list->first;
237 while (cf) { 233 while (cf) {
238 cflag = (mailimap_flag_fetch*)cf->data; 234 cflag = (mailimap_flag_fetch*)cf->data;
239 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 235 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
240 switch (cflag->flag->type) { 236 switch (cflag->flag->type) {
241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 237 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
242 mFlags.setBit(FLAG_ANSWERED); 238 mFlags.setBit(FLAG_ANSWERED);
243 break; 239 break;
244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 240 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
245 mFlags.setBit(FLAG_FLAGGED); 241 mFlags.setBit(FLAG_FLAGGED);
246 break; 242 break;
247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 243 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
248 mFlags.setBit(FLAG_DELETED); 244 mFlags.setBit(FLAG_DELETED);
249 break; 245 break;
250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 246 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
251 mFlags.setBit(FLAG_SEEN); 247 mFlags.setBit(FLAG_SEEN);
252 break; 248 break;
253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 249 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
254 mFlags.setBit(FLAG_DRAFT); 250 mFlags.setBit(FLAG_DRAFT);
255 break; 251 break;
256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 252 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
257 break; 253 break;
258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 254 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
259 break; 255 break;
260 default: 256 default:
261 break; 257 break;
262 } 258 }
263 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 259 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
264 mFlags.setBit(FLAG_RECENT); 260 mFlags.setBit(FLAG_RECENT);
265 } 261 }
266 cf = cf->next; 262 cf = cf->next;
267 } 263 }
268 continue; 264 continue;
269 } 265 }
270 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 266 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
271 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 267 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
272 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 268 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
273 mailimap_envelope * head = item->msg_att_static->env; 269 mailimap_envelope * head = item->msg_att_static->env;
274 date = head->date;
275 subject = head->subject;
276 m = new RecMail(); 270 m = new RecMail();
271 m->setDate(head->date);
272 m->setSubject(head->subject);
277 if (head->from!=NULL) { 273 if (head->from!=NULL) {
278 addresslist = address_list_to_stringlist(head->from->list); 274 addresslist = address_list_to_stringlist(head->from->list);
279 if (addresslist.count()) { 275 if (addresslist.count()) {
280 from = addresslist.first(); 276 m->setFrom(addresslist.first());
281 } 277 }
282 } 278 }
283 if (head->to!=NULL) { 279 if (head->to!=NULL) {
284 addresslist = address_list_to_stringlist(head->to->list); 280 addresslist = address_list_to_stringlist(head->to->list);
285 m->setTo(addresslist); 281 m->setTo(addresslist);
286 } 282 }
287 if (head->cc!=NULL) { 283 if (head->cc!=NULL) {
288 addresslist = address_list_to_stringlist(head->cc->list); 284 addresslist = address_list_to_stringlist(head->cc->list);
289 m->setCC(addresslist); 285 m->setCC(addresslist);
290 } 286 }
291 if (head->bcc!=NULL) { 287 if (head->bcc!=NULL) {
292 addresslist = address_list_to_stringlist(head->bcc->list); 288 addresslist = address_list_to_stringlist(head->bcc->list);
293 m->setBcc(addresslist); 289 m->setBcc(addresslist);
294 } 290 }
295 m->setSubject(subject); 291 if (head->reply_to!=NULL) {
296 m->setFrom(from); 292 addresslist = address_list_to_stringlist(head->bcc->list);
297 m->setDate(date); 293 if (addresslist.count()) {
294 m->setReplyto(addresslist.first());
295 }
296 }
298 m->setMsgid(QString(head->message_id)); 297 m->setMsgid(QString(head->message_id));
299 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", 298 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s",
300 from.latin1(), 299 m->getFrom().latin1(),
301 subject.latin1(),date.latin1(),m->Msgid().latin1()); 300 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1());
302 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 301 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
303 mailimap_date_time*d = item->msg_att_static->internal_date; 302 mailimap_date_time*d = item->msg_att_static->internal_date;
304 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 303 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
305 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); 304 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
306 qDebug(da.toString()); 305 qDebug(da.toString());
307 } else { 306 } else {
308 qDebug("Another type"); 307 qDebug("Another type");
309 } 308 }
310 } 309 }
311 /* msg is already deleted */ 310 /* msg is already deleted */
312 if (mFlags.testBit(FLAG_DELETED) && m) { 311 if (mFlags.testBit(FLAG_DELETED) && m) {
313 delete m; 312 delete m;
314 m = 0; 313 m = 0;
315 } 314 }
316 if (m) { 315 if (m) {
317 m->setFlags(mFlags); 316 m->setFlags(mFlags);
318 } 317 }
319 return m; 318 return m;
320} 319}
321 320
322RecBody IMAPwrapper::fetchBody(const RecMail&mail) 321RecBody IMAPwrapper::fetchBody(const RecMail&mail)
323{ 322{
324 RecBody body; 323 RecBody body;
325 const char *mb; 324 const char *mb;
326 int err = MAILIMAP_NO_ERROR; 325 int err = MAILIMAP_NO_ERROR;
327 clist *result; 326 clist *result;
328 clistcell *current; 327 clistcell *current;
329 mailimap_fetch_att *fetchAtt; 328 mailimap_fetch_att *fetchAtt;
330 mailimap_fetch_type *fetchType; 329 mailimap_fetch_type *fetchType;
331 mailimap_set *set; 330 mailimap_set *set;
332 mailimap_body*body_desc; 331 mailimap_body*body_desc;
333 332
334 mb = mail.getMbox().latin1(); 333 mb = mail.getMbox().latin1();
335 334
336 login(); 335 login();
337 if (!m_imap) { 336 if (!m_imap) {
338 return body; 337 return body;
339 } 338 }
340 /* select mailbox READONLY for operations */ 339 /* select mailbox READONLY for operations */
341 err = mailimap_examine( m_imap, (char*)mb); 340 err = mailimap_examine( m_imap, (char*)mb);
342 if ( err != MAILIMAP_NO_ERROR ) { 341 if ( err != MAILIMAP_NO_ERROR ) {
343 qDebug("error selecting mailbox: %s",m_imap->response); 342 qDebug("error selecting mailbox: %s",m_imap->response);
344 logout(); 343 logout();
345 return body; 344 return body;
346 } 345 }
347 result = clist_new(); 346 result = clist_new();
348 /* the range has to start at 1!!! not with 0!!!! */ 347 /* the range has to start at 1!!! not with 0!!!! */
349 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 348 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
350 fetchAtt = mailimap_fetch_att_new_body(); 349 fetchAtt = mailimap_fetch_att_new_body();
351 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 350 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
352 err = mailimap_fetch( m_imap, set, fetchType, &result ); 351 err = mailimap_fetch( m_imap, set, fetchType, &result );
353 mailimap_set_free( set ); 352 mailimap_set_free( set );
354 mailimap_fetch_type_free( fetchType ); 353 mailimap_fetch_type_free( fetchType );
355 354
356 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 355 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
357 mailimap_msg_att * msg_att; 356 mailimap_msg_att * msg_att;
358 msg_att = (mailimap_msg_att*)current->data; 357 msg_att = (mailimap_msg_att*)current->data;
359 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 358 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
360 body_desc = item->msg_att_static->body; 359 body_desc = item->msg_att_static->body;
361 if (body_desc->type==MAILIMAP_BODY_1PART) { 360 if (body_desc->type==MAILIMAP_BODY_1PART) {
362 searchBodyText(mail,body_desc->body_1part,body); 361 searchBodyText(mail,body_desc->body_1part,body);
363 } else { 362 } else {
364 } 363 }
365 364
366 } else { 365 } else {
367 qDebug("error fetching body: %s",m_imap->response); 366 qDebug("error fetching body: %s",m_imap->response);
368 } 367 }
369 368
370 clist_free(result); 369 clist_free(result);
371 logout(); 370 logout();
372 return body; 371 return body;
373} 372}
374 373
375void 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)
376{ 375{
377 if (!mailDescription) { 376 if (!mailDescription) {
378 return; 377 return;
379 } 378 }
380 switch (mailDescription->type) { 379 switch (mailDescription->type) {
381 case MAILIMAP_BODY_TYPE_1PART_TEXT: 380 case MAILIMAP_BODY_TYPE_1PART_TEXT:
382 fillPlainBody(mail,target_body,mailDescription->body_type_text); 381 fillPlainBody(mail,target_body,mailDescription->body_type_text);
383 break; 382 break;
384 default: 383 default:
385 break; 384 break;
386 } 385 }
387 return; 386 return;
388} 387}
389 388
390void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) 389void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body)
391{ 390{
392 const char *mb; 391 const char *mb;
393 QString body=""; 392 QString body="";
394 int err = MAILIMAP_NO_ERROR; 393 int err = MAILIMAP_NO_ERROR;
395 clist *result; 394 clist *result;
396 clistcell *current; 395 clistcell *current;
397 mailimap_fetch_att *fetchAtt; 396 mailimap_fetch_att *fetchAtt;
398 mailimap_fetch_type *fetchType; 397 mailimap_fetch_type *fetchType;
399 mailimap_set *set; 398 mailimap_set *set;
400 399
401 mb = mail.getMbox().latin1(); 400 mb = mail.getMbox().latin1();
402 401
403 if (!m_imap) { 402 if (!m_imap) {
404 return; 403 return;
405 } 404 }
406 405
407 result = clist_new(); 406 result = clist_new();
408 /* the range has to start at 1!!! not with 0!!!! */ 407 /* the range has to start at 1!!! not with 0!!!! */
409 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 408 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
410 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 409 fetchAtt = mailimap_fetch_att_new_rfc822_text();
411 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 410 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
412 err = mailimap_fetch( m_imap, set, fetchType, &result ); 411 err = mailimap_fetch( m_imap, set, fetchType, &result );
413 mailimap_set_free( set ); 412 mailimap_set_free( set );
414 mailimap_fetch_type_free( fetchType ); 413 mailimap_fetch_type_free( fetchType );
415 414
416 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 415 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
417 mailimap_msg_att * msg_att; 416 mailimap_msg_att * msg_att;
418 msg_att = (mailimap_msg_att*)current->data; 417 msg_att = (mailimap_msg_att*)current->data;
419 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 418 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
420 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 419 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
421 body = item->msg_att_static->rfc822_text; 420 body = item->msg_att_static->rfc822_text;
422 } 421 }
423 } else { 422 } else {
424 qDebug("error fetching text: %s",m_imap->response); 423 qDebug("error fetching text: %s",m_imap->response);
425 } 424 }
426 clist_free(result); 425 clist_free(result);
427 target_body.setBodytext(body); 426 target_body.setBodytext(body);
428 return; 427 return;
429} 428}
430 429
431QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 430QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
432{ 431{
433 QStringList l; 432 QStringList l;
434 QString from; 433 QString from;
435 bool named_from; 434 bool named_from;
436 clistcell *current = NULL; 435 clistcell *current = NULL;
437 mailimap_address * current_address=NULL; 436 mailimap_address * current_address=NULL;
438 if (!list) { 437 if (!list) {
439 return l; 438 return l;
440 } 439 }
441 current = clist_begin(list); 440 current = clist_begin(list);
441 unsigned int count = 0;
442 while (current!= NULL) { 442 while (current!= NULL) {
443 from = ""; 443 from = "";
444 named_from = false; 444 named_from = false;
445 current_address=(mailimap_address*)current->data; 445 current_address=(mailimap_address*)current->data;
446 current = current->next; 446 current = current->next;
447 if (current_address->personal_name){ 447 if (current_address->personal_name){
448 from+=QString(current_address->personal_name); 448 from+=QString(current_address->personal_name);
449 from+=" "; 449 from+=" ";
450 named_from = true; 450 named_from = true;
451 } 451 }
452 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 452 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
453 from+="<"; 453 from+="<";
454 } 454 }
455 if (current_address->mailbox_name) { 455 if (current_address->mailbox_name) {
456 from+=QString(current_address->mailbox_name); 456 from+=QString(current_address->mailbox_name);
457 from+="@"; 457 from+="@";
458 } 458 }
459 if (current_address->host_name) { 459 if (current_address->host_name) {
460 from+=QString(current_address->host_name); 460 from+=QString(current_address->host_name);
461 } 461 }
462 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 462 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
463 from+=">"; 463 from+=">";
464 } 464 }
465 l.append(QString(from)); 465 l.append(QString(from));
466 if (++count > 99) {
467 break;
468 }
466 } 469 }
467 return l; 470 return l;
468} 471}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 6565896..faab43c 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,38 +1,38 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10class RecMail; 10class RecMail;
11class RecBody; 11class RecBody;
12 12
13class IMAPwrapper : public QObject 13class IMAPwrapper : public QObject
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 IMAPwrapper( IMAPaccount *a ); 18 IMAPwrapper( IMAPaccount *a );
19 virtual ~IMAPwrapper(); 19 virtual ~IMAPwrapper();
20 QList<IMAPFolder>* listFolders(); 20 QList<IMAPFolder>* listFolders();
21 void listMessages(const QString & mailbox,QList<RecMail>&target ); 21 void listMessages(const QString & mailbox,QList<RecMail>&target );
22 RecBody fetchBody(const RecMail&mail); 22 RecBody fetchBody(const RecMail&mail);
23 static void imap_progress( size_t current, size_t maximum ); 23 static void imap_progress( size_t current, size_t maximum );
24 24
25protected: 25protected:
26 RecMail*parse_list_result(mailimap_msg_att*); 26 RecMail*parse_list_result(mailimap_msg_att*);
27 void login(); 27 void login();
28 void logout(); 28 void logout();
29 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 29 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
30 void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body); 30 void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body);
31 QStringList address_list_to_stringlist(clist*list); 31 static QStringList address_list_to_stringlist(clist*list);
32 32
33private: 33private:
34 IMAPaccount *account; 34 IMAPaccount *account;
35 mailimap *m_imap; 35 mailimap *m_imap;
36}; 36};
37 37
38#endif 38#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 5ce140e..eae85a7 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,468 +1,471 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9{ 9{
10 account = a; 10 account = a;
11 m_imap = 0; 11 m_imap = 0;
12} 12}
13 13
14IMAPwrapper::~IMAPwrapper() 14IMAPwrapper::~IMAPwrapper()
15{ 15{
16 logout(); 16 logout();
17} 17}
18 18
19void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 19void IMAPwrapper::imap_progress( size_t current, size_t maximum )
20{ 20{
21 qDebug( "IMAP: %i of %i", current, maximum ); 21 qDebug( "IMAP: %i of %i", current, maximum );
22} 22}
23 23
24void IMAPwrapper::login() 24void IMAPwrapper::login()
25{ 25{
26 logout(); 26 logout();
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 server = account->getServer().latin1(); 31 server = account->getServer().latin1();
32 port = account->getPort().toUInt(); 32 port = account->getPort().toUInt();
33 user = account->getUser().latin1(); 33 user = account->getUser().latin1();
34 pass = account->getPassword().latin1(); 34 pass = account->getPassword().latin1();
35 35
36 m_imap = mailimap_new( 20, &imap_progress ); 36 m_imap = mailimap_new( 20, &imap_progress );
37 /* connect */ 37 /* connect */
38 err = mailimap_socket_connect( m_imap, (char*)server, port ); 38 err = mailimap_socket_connect( m_imap, (char*)server, port );
39 if ( err != MAILIMAP_NO_ERROR && 39 if ( err != MAILIMAP_NO_ERROR &&
40 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 40 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
42 qDebug("error connecting server: %s",m_imap->response); 42 qDebug("error connecting server: %s",m_imap->response);
43 mailimap_free( m_imap ); 43 mailimap_free( m_imap );
44 m_imap = 0; 44 m_imap = 0;
45 return; 45 return;
46 } 46 }
47 47
48 /* login */ 48 /* login */
49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
50 if ( err != MAILIMAP_NO_ERROR ) { 50 if ( err != MAILIMAP_NO_ERROR ) {
51 qDebug("error logging in imap: %s",m_imap->response); 51 qDebug("error logging in imap: %s",m_imap->response);
52 err = mailimap_close( m_imap ); 52 err = mailimap_close( m_imap );
53 mailimap_free( m_imap ); 53 mailimap_free( m_imap );
54 m_imap = 0; 54 m_imap = 0;
55 } 55 }
56} 56}
57 57
58void IMAPwrapper::logout() 58void IMAPwrapper::logout()
59{ 59{
60 int err = MAILIMAP_NO_ERROR; 60 int err = MAILIMAP_NO_ERROR;
61 if (!m_imap) return; 61 if (!m_imap) return;
62 err = mailimap_logout( m_imap ); 62 err = mailimap_logout( m_imap );
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
68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
69{ 69{
70 const char *mb; 70 const char *mb;
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 clist *result; 72 clist *result;
73 clistcell *current; 73 clistcell *current;
74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
75 mailimap_fetch_type *fetchType; 75 mailimap_fetch_type *fetchType;
76 mailimap_set *set; 76 mailimap_set *set;
77 77
78 mb = mailbox.latin1(); 78 mb = mailbox.latin1();
79 login(); 79 login();
80 if (!m_imap) { 80 if (!m_imap) {
81 return; 81 return;
82 } 82 }
83 /* select mailbox READONLY for operations */ 83 /* select mailbox READONLY for operations */
84 err = mailimap_examine( m_imap, (char*)mb); 84 err = mailimap_examine( m_imap, (char*)mb);
85 if ( err != MAILIMAP_NO_ERROR ) { 85 if ( err != MAILIMAP_NO_ERROR ) {
86 qDebug("error selecting mailbox: %s",m_imap->response); 86 qDebug("error selecting mailbox: %s",m_imap->response);
87 logout(); 87 logout();
88 return; 88 return;
89 } 89 }
90 90
91 int last = m_imap->selection_info->exists; 91 int last = m_imap->selection_info->exists;
92 92
93 if (last == 0) { 93 if (last == 0) {
94 qDebug("mailbox has no mails"); 94 qDebug("mailbox has no mails");
95 logout(); 95 logout();
96 return; 96 return;
97 } 97 }
98 98
99 result = clist_new(); 99 result = clist_new();
100 /* the range has to start at 1!!! not with 0!!!! */ 100 /* the range has to start at 1!!! not with 0!!!! */
101 set = mailimap_set_new_interval( 1, last ); 101 set = mailimap_set_new_interval( 1, last );
102 fetchAtt = mailimap_fetch_att_new_envelope(); 102 fetchAtt = mailimap_fetch_att_new_envelope();
103 fetchAttFlags = mailimap_fetch_att_new_flags(); 103 fetchAttFlags = mailimap_fetch_att_new_flags();
104 fetchAttDate = mailimap_fetch_att_new_internaldate(); 104 fetchAttDate = mailimap_fetch_att_new_internaldate();
105 105
106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
111 111
112 err = mailimap_fetch( m_imap, set, fetchType, &result ); 112 err = mailimap_fetch( m_imap, set, fetchType, &result );
113 mailimap_set_free( set ); 113 mailimap_set_free( set );
114 /* cleans up the fetch_att's too! */ 114 /* cleans up the fetch_att's too! */
115 mailimap_fetch_type_free( fetchType ); 115 mailimap_fetch_type_free( fetchType );
116 116
117 QString date,subject,from; 117 QString date,subject,from;
118 118
119 if ( err == MAILIMAP_NO_ERROR ) { 119 if ( err == MAILIMAP_NO_ERROR ) {
120 current = clist_begin(result); 120 current = clist_begin(result);
121 mailimap_msg_att * msg_att; 121 mailimap_msg_att * msg_att;
122 int i = 0; 122 int i = 0;
123 while ( current != 0 ) { 123 while ( current != 0 ) {
124 ++i; 124 ++i;
125 msg_att = (mailimap_msg_att*)current->data; 125 msg_att = (mailimap_msg_att*)current->data;
126 RecMail*m = parse_list_result(msg_att); 126 RecMail*m = parse_list_result(msg_att);
127 if (m) { 127 if (m) {
128 m->setNumber(i); 128 m->setNumber(i);
129 m->setMbox(mailbox); 129 m->setMbox(mailbox);
130 target.append(m); 130 target.append(m);
131 } 131 }
132 current = current->next; 132 current = current->next;
133 } 133 }
134 } else { 134 } else {
135 qDebug("Error fetching headers: %s",m_imap->response); 135 qDebug("Error fetching headers: %s",m_imap->response);
136 } 136 }
137 logout(); 137 logout();
138 clist_free(result); 138 clist_free(result);
139} 139}
140 140
141QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 142{
143 const char *path, *mask; 143 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
145 clist *result; 145 clist *result;
146 clistcell *current; 146 clistcell *current;
147 147
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
150 login(); 150 login();
151 if (!m_imap) { 151 if (!m_imap) {
152 return folders; 152 return folders;
153 } 153 }
154 154
155/* 155/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
157 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
158 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 159 */
160 QString temp; 160 QString temp;
161 mask = "INBOX" ; 161 mask = "INBOX" ;
162 result = clist_new(); 162 result = clist_new();
163 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 166 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 170 // instead of using strdup!
171 temp = list->mb; 171 temp = list->mb;
172 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
173 current = current->next; 173 current = current->next;
174 } 174 }
175 } else { 175 } else {
176 qDebug("error fetching folders: %s",m_imap->response); 176 qDebug("error fetching folders: %s",m_imap->response);
177 } 177 }
178 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
179 179
180/* 180/*
181 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
182 */ 182 */
183 mask = "*" ; 183 mask = "*" ;
184 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
185 result = clist_new(); 185 result = clist_new();
186 qDebug(path); 186 qDebug(path);
187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
188 if ( err == MAILIMAP_NO_ERROR ) { 188 if ( err == MAILIMAP_NO_ERROR ) {
189 current = result->first; 189 current = result->first;
190 for ( int i = result->count; i > 0; i-- ) { 190 for ( int i = result->count; i > 0; i-- ) {
191 list = (mailimap_mailbox_list *) current->data; 191 list = (mailimap_mailbox_list *) current->data;
192 // it is better use the deep copy mechanism of qt itself 192 // it is better use the deep copy mechanism of qt itself
193 // instead of using strdup! 193 // instead of using strdup!
194 temp = list->mb; 194 temp = list->mb;
195 current = current->next; 195 current = current->next;
196 if (temp.lower()=="inbox") 196 if (temp.lower()=="inbox")
197 continue; 197 continue;
198 folders->append(new IMAPFolder(temp)); 198 folders->append(new IMAPFolder(temp));
199 199
200 } 200 }
201 } else { 201 } else {
202 qDebug("error fetching folders %s",m_imap->response); 202 qDebug("error fetching folders %s",m_imap->response);
203 } 203 }
204 mailimap_list_result_free( result ); 204 mailimap_list_result_free( result );
205 return folders; 205 return folders;
206} 206}
207 207
208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
209{ 209{
210 RecMail * m = 0; 210 RecMail * m = 0;
211 mailimap_msg_att_item *item=0; 211 mailimap_msg_att_item *item=0;
212 bool named_from = false; 212 clistcell *current,*c,*cf;
213 QString from,date,subject;
214 date = from = subject = "";
215 clistcell *current,*c,*cf, *current_from = NULL;
216 mailimap_address * current_address = NULL;
217 mailimap_msg_att_dynamic*flist; 213 mailimap_msg_att_dynamic*flist;
218 mailimap_flag_fetch*cflag; 214 mailimap_flag_fetch*cflag;
219 QBitArray mFlags(7); 215 QBitArray mFlags(7);
220 QStringList addresslist; 216 QStringList addresslist;
221 217
222 if (!m_att) { 218 if (!m_att) {
223 return m; 219 return m;
224 } 220 }
225 221
226 c = clist_begin(m_att->list); 222 c = clist_begin(m_att->list);
227 while ( c ) { 223 while ( c ) {
228 current = c; 224 current = c;
229 c = c->next; 225 c = c->next;
230 item = (mailimap_msg_att_item*)current->data; 226 item = (mailimap_msg_att_item*)current->data;
231 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 227 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
232 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 228 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
233 if (!flist->list) { 229 if (!flist->list) {
234 continue; 230 continue;
235 } 231 }
236 cf = flist->list->first; 232 cf = flist->list->first;
237 while (cf) { 233 while (cf) {
238 cflag = (mailimap_flag_fetch*)cf->data; 234 cflag = (mailimap_flag_fetch*)cf->data;
239 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 235 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
240 switch (cflag->flag->type) { 236 switch (cflag->flag->type) {
241 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 237 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
242 mFlags.setBit(FLAG_ANSWERED); 238 mFlags.setBit(FLAG_ANSWERED);
243 break; 239 break;
244 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 240 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
245 mFlags.setBit(FLAG_FLAGGED); 241 mFlags.setBit(FLAG_FLAGGED);
246 break; 242 break;
247 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 243 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
248 mFlags.setBit(FLAG_DELETED); 244 mFlags.setBit(FLAG_DELETED);
249 break; 245 break;
250 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 246 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
251 mFlags.setBit(FLAG_SEEN); 247 mFlags.setBit(FLAG_SEEN);
252 break; 248 break;
253 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 249 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
254 mFlags.setBit(FLAG_DRAFT); 250 mFlags.setBit(FLAG_DRAFT);
255 break; 251 break;
256 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 252 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
257 break; 253 break;
258 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 254 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
259 break; 255 break;
260 default: 256 default:
261 break; 257 break;
262 } 258 }
263 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 259 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
264 mFlags.setBit(FLAG_RECENT); 260 mFlags.setBit(FLAG_RECENT);
265 } 261 }
266 cf = cf->next; 262 cf = cf->next;
267 } 263 }
268 continue; 264 continue;
269 } 265 }
270 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 266 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
271 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 267 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
272 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 268 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
273 mailimap_envelope * head = item->msg_att_static->env; 269 mailimap_envelope * head = item->msg_att_static->env;
274 date = head->date;
275 subject = head->subject;
276 m = new RecMail(); 270 m = new RecMail();
271 m->setDate(head->date);
272 m->setSubject(head->subject);
277 if (head->from!=NULL) { 273 if (head->from!=NULL) {
278 addresslist = address_list_to_stringlist(head->from->list); 274 addresslist = address_list_to_stringlist(head->from->list);
279 if (addresslist.count()) { 275 if (addresslist.count()) {
280 from = addresslist.first(); 276 m->setFrom(addresslist.first());
281 } 277 }
282 } 278 }
283 if (head->to!=NULL) { 279 if (head->to!=NULL) {
284 addresslist = address_list_to_stringlist(head->to->list); 280 addresslist = address_list_to_stringlist(head->to->list);
285 m->setTo(addresslist); 281 m->setTo(addresslist);
286 } 282 }
287 if (head->cc!=NULL) { 283 if (head->cc!=NULL) {
288 addresslist = address_list_to_stringlist(head->cc->list); 284 addresslist = address_list_to_stringlist(head->cc->list);
289 m->setCC(addresslist); 285 m->setCC(addresslist);
290 } 286 }
291 if (head->bcc!=NULL) { 287 if (head->bcc!=NULL) {
292 addresslist = address_list_to_stringlist(head->bcc->list); 288 addresslist = address_list_to_stringlist(head->bcc->list);
293 m->setBcc(addresslist); 289 m->setBcc(addresslist);
294 } 290 }
295 m->setSubject(subject); 291 if (head->reply_to!=NULL) {
296 m->setFrom(from); 292 addresslist = address_list_to_stringlist(head->bcc->list);
297 m->setDate(date); 293 if (addresslist.count()) {
294 m->setReplyto(addresslist.first());
295 }
296 }
298 m->setMsgid(QString(head->message_id)); 297 m->setMsgid(QString(head->message_id));
299 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", 298 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s",
300 from.latin1(), 299 m->getFrom().latin1(),
301 subject.latin1(),date.latin1(),m->Msgid().latin1()); 300 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1());
302 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 301 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
303 mailimap_date_time*d = item->msg_att_static->internal_date; 302 mailimap_date_time*d = item->msg_att_static->internal_date;
304 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 303 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
305 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); 304 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
306 qDebug(da.toString()); 305 qDebug(da.toString());
307 } else { 306 } else {
308 qDebug("Another type"); 307 qDebug("Another type");
309 } 308 }
310 } 309 }
311 /* msg is already deleted */ 310 /* msg is already deleted */
312 if (mFlags.testBit(FLAG_DELETED) && m) { 311 if (mFlags.testBit(FLAG_DELETED) && m) {
313 delete m; 312 delete m;
314 m = 0; 313 m = 0;
315 } 314 }
316 if (m) { 315 if (m) {
317 m->setFlags(mFlags); 316 m->setFlags(mFlags);
318 } 317 }
319 return m; 318 return m;
320} 319}
321 320
322RecBody IMAPwrapper::fetchBody(const RecMail&mail) 321RecBody IMAPwrapper::fetchBody(const RecMail&mail)
323{ 322{
324 RecBody body; 323 RecBody body;
325 const char *mb; 324 const char *mb;
326 int err = MAILIMAP_NO_ERROR; 325 int err = MAILIMAP_NO_ERROR;
327 clist *result; 326 clist *result;
328 clistcell *current; 327 clistcell *current;
329 mailimap_fetch_att *fetchAtt; 328 mailimap_fetch_att *fetchAtt;
330 mailimap_fetch_type *fetchType; 329 mailimap_fetch_type *fetchType;
331 mailimap_set *set; 330 mailimap_set *set;
332 mailimap_body*body_desc; 331 mailimap_body*body_desc;
333 332
334 mb = mail.getMbox().latin1(); 333 mb = mail.getMbox().latin1();
335 334
336 login(); 335 login();
337 if (!m_imap) { 336 if (!m_imap) {
338 return body; 337 return body;
339 } 338 }
340 /* select mailbox READONLY for operations */ 339 /* select mailbox READONLY for operations */
341 err = mailimap_examine( m_imap, (char*)mb); 340 err = mailimap_examine( m_imap, (char*)mb);
342 if ( err != MAILIMAP_NO_ERROR ) { 341 if ( err != MAILIMAP_NO_ERROR ) {
343 qDebug("error selecting mailbox: %s",m_imap->response); 342 qDebug("error selecting mailbox: %s",m_imap->response);
344 logout(); 343 logout();
345 return body; 344 return body;
346 } 345 }
347 result = clist_new(); 346 result = clist_new();
348 /* the range has to start at 1!!! not with 0!!!! */ 347 /* the range has to start at 1!!! not with 0!!!! */
349 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 348 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
350 fetchAtt = mailimap_fetch_att_new_body(); 349 fetchAtt = mailimap_fetch_att_new_body();
351 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 350 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
352 err = mailimap_fetch( m_imap, set, fetchType, &result ); 351 err = mailimap_fetch( m_imap, set, fetchType, &result );
353 mailimap_set_free( set ); 352 mailimap_set_free( set );
354 mailimap_fetch_type_free( fetchType ); 353 mailimap_fetch_type_free( fetchType );
355 354
356 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 355 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
357 mailimap_msg_att * msg_att; 356 mailimap_msg_att * msg_att;
358 msg_att = (mailimap_msg_att*)current->data; 357 msg_att = (mailimap_msg_att*)current->data;
359 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 358 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
360 body_desc = item->msg_att_static->body; 359 body_desc = item->msg_att_static->body;
361 if (body_desc->type==MAILIMAP_BODY_1PART) { 360 if (body_desc->type==MAILIMAP_BODY_1PART) {
362 searchBodyText(mail,body_desc->body_1part,body); 361 searchBodyText(mail,body_desc->body_1part,body);
363 } else { 362 } else {
364 } 363 }
365 364
366 } else { 365 } else {
367 qDebug("error fetching body: %s",m_imap->response); 366 qDebug("error fetching body: %s",m_imap->response);
368 } 367 }
369 368
370 clist_free(result); 369 clist_free(result);
371 logout(); 370 logout();
372 return body; 371 return body;
373} 372}
374 373
375void 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)
376{ 375{
377 if (!mailDescription) { 376 if (!mailDescription) {
378 return; 377 return;
379 } 378 }
380 switch (mailDescription->type) { 379 switch (mailDescription->type) {
381 case MAILIMAP_BODY_TYPE_1PART_TEXT: 380 case MAILIMAP_BODY_TYPE_1PART_TEXT:
382 fillPlainBody(mail,target_body,mailDescription->body_type_text); 381 fillPlainBody(mail,target_body,mailDescription->body_type_text);
383 break; 382 break;
384 default: 383 default:
385 break; 384 break;
386 } 385 }
387 return; 386 return;
388} 387}
389 388
390void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) 389void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body)
391{ 390{
392 const char *mb; 391 const char *mb;
393 QString body=""; 392 QString body="";
394 int err = MAILIMAP_NO_ERROR; 393 int err = MAILIMAP_NO_ERROR;
395 clist *result; 394 clist *result;
396 clistcell *current; 395 clistcell *current;
397 mailimap_fetch_att *fetchAtt; 396 mailimap_fetch_att *fetchAtt;
398 mailimap_fetch_type *fetchType; 397 mailimap_fetch_type *fetchType;
399 mailimap_set *set; 398 mailimap_set *set;
400 399
401 mb = mail.getMbox().latin1(); 400 mb = mail.getMbox().latin1();
402 401
403 if (!m_imap) { 402 if (!m_imap) {
404 return; 403 return;
405 } 404 }
406 405
407 result = clist_new(); 406 result = clist_new();
408 /* the range has to start at 1!!! not with 0!!!! */ 407 /* the range has to start at 1!!! not with 0!!!! */
409 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 408 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
410 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 409 fetchAtt = mailimap_fetch_att_new_rfc822_text();
411 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 410 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
412 err = mailimap_fetch( m_imap, set, fetchType, &result ); 411 err = mailimap_fetch( m_imap, set, fetchType, &result );
413 mailimap_set_free( set ); 412 mailimap_set_free( set );
414 mailimap_fetch_type_free( fetchType ); 413 mailimap_fetch_type_free( fetchType );
415 414
416 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 415 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
417 mailimap_msg_att * msg_att; 416 mailimap_msg_att * msg_att;
418 msg_att = (mailimap_msg_att*)current->data; 417 msg_att = (mailimap_msg_att*)current->data;
419 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 418 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
420 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 419 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
421 body = item->msg_att_static->rfc822_text; 420 body = item->msg_att_static->rfc822_text;
422 } 421 }
423 } else { 422 } else {
424 qDebug("error fetching text: %s",m_imap->response); 423 qDebug("error fetching text: %s",m_imap->response);
425 } 424 }
426 clist_free(result); 425 clist_free(result);
427 target_body.setBodytext(body); 426 target_body.setBodytext(body);
428 return; 427 return;
429} 428}
430 429
431QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 430QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
432{ 431{
433 QStringList l; 432 QStringList l;
434 QString from; 433 QString from;
435 bool named_from; 434 bool named_from;
436 clistcell *current = NULL; 435 clistcell *current = NULL;
437 mailimap_address * current_address=NULL; 436 mailimap_address * current_address=NULL;
438 if (!list) { 437 if (!list) {
439 return l; 438 return l;
440 } 439 }
441 current = clist_begin(list); 440 current = clist_begin(list);
441 unsigned int count = 0;
442 while (current!= NULL) { 442 while (current!= NULL) {
443 from = ""; 443 from = "";
444 named_from = false; 444 named_from = false;
445 current_address=(mailimap_address*)current->data; 445 current_address=(mailimap_address*)current->data;
446 current = current->next; 446 current = current->next;
447 if (current_address->personal_name){ 447 if (current_address->personal_name){
448 from+=QString(current_address->personal_name); 448 from+=QString(current_address->personal_name);
449 from+=" "; 449 from+=" ";
450 named_from = true; 450 named_from = true;
451 } 451 }
452 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 452 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
453 from+="<"; 453 from+="<";
454 } 454 }
455 if (current_address->mailbox_name) { 455 if (current_address->mailbox_name) {
456 from+=QString(current_address->mailbox_name); 456 from+=QString(current_address->mailbox_name);
457 from+="@"; 457 from+="@";
458 } 458 }
459 if (current_address->host_name) { 459 if (current_address->host_name) {
460 from+=QString(current_address->host_name); 460 from+=QString(current_address->host_name);
461 } 461 }
462 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 462 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
463 from+=">"; 463 from+=">";
464 } 464 }
465 l.append(QString(from)); 465 l.append(QString(from));
466 if (++count > 99) {
467 break;
468 }
466 } 469 }
467 return l; 470 return l;
468} 471}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 6565896..faab43c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,38 +1,38 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10class RecMail; 10class RecMail;
11class RecBody; 11class RecBody;
12 12
13class IMAPwrapper : public QObject 13class IMAPwrapper : public QObject
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 IMAPwrapper( IMAPaccount *a ); 18 IMAPwrapper( IMAPaccount *a );
19 virtual ~IMAPwrapper(); 19 virtual ~IMAPwrapper();
20 QList<IMAPFolder>* listFolders(); 20 QList<IMAPFolder>* listFolders();
21 void listMessages(const QString & mailbox,QList<RecMail>&target ); 21 void listMessages(const QString & mailbox,QList<RecMail>&target );
22 RecBody fetchBody(const RecMail&mail); 22 RecBody fetchBody(const RecMail&mail);
23 static void imap_progress( size_t current, size_t maximum ); 23 static void imap_progress( size_t current, size_t maximum );
24 24
25protected: 25protected:
26 RecMail*parse_list_result(mailimap_msg_att*); 26 RecMail*parse_list_result(mailimap_msg_att*);
27 void login(); 27 void login();
28 void logout(); 28 void logout();
29 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 29 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
30 void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body); 30 void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body);
31 QStringList address_list_to_stringlist(clist*list); 31 static QStringList address_list_to_stringlist(clist*list);
32 32
33private: 33private:
34 IMAPaccount *account; 34 IMAPaccount *account;
35 mailimap *m_imap; 35 mailimap *m_imap;
36}; 36};
37 37
38#endif 38#endif
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index c8d533a..6d6b080 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -1,102 +1,105 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <qlist.h> 11#include <qlist.h>
12#include <qbitarray.h> 12#include <qbitarray.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15 15
16/* a class to describe mails in a mailbox */ 16/* a class to describe mails in a mailbox */
17/* Attention! 17/* Attention!
18 From programmers point of view it would make sense to 18 From programmers point of view it would make sense to
19 store the mail body into this class, too. 19 store the mail body into this class, too.
20 But: not from the point of view of the device. 20 But: not from the point of view of the device.
21 Mailbodies can be real large. So we request them when 21 Mailbodies can be real large. So we request them when
22 needed from the mail-wrapper class direct from the server itself 22 needed from the mail-wrapper class direct from the server itself
23 (imap) or from a file-based cache (pop3?) 23 (imap) or from a file-based cache (pop3?)
24 So there is no interface "const QString&body()" but you should 24 So there is no interface "const QString&body()" but you should
25 make a request to the mailwrapper with this class as parameter to 25 make a request to the mailwrapper with this class as parameter to
26 get the body. Same words for the attachments. 26 get the body. Same words for the attachments.
27*/ 27*/
28class RecMail 28class RecMail
29{ 29{
30public: 30public:
31 RecMail(); 31 RecMail();
32 RecMail(const RecMail&old); 32 RecMail(const RecMail&old);
33 virtual ~RecMail(){} 33 virtual ~RecMail(){}
34 34
35 const int getNumber()const{return msg_number;} 35 const int getNumber()const{return msg_number;}
36 void setNumber(int number){msg_number=number;} 36 void setNumber(int number){msg_number=number;}
37 const QString&getDate()const{ return date; } 37 const QString&getDate()const{ return date; }
38 void setDate( const QString&a ) { date = a; } 38 void setDate( const QString&a ) { date = a; }
39 const QString&getFrom()const{ return from; } 39 const QString&getFrom()const{ return from; }
40 void setFrom( const QString&a ) { from = a; } 40 void setFrom( const QString&a ) { from = a; }
41 const QString&getSubject()const { return subject; } 41 const QString&getSubject()const { return subject; }
42 void setSubject( const QString&s ) { subject = s; } 42 void setSubject( const QString&s ) { subject = s; }
43 const QString&getMbox()const{return mbox;} 43 const QString&getMbox()const{return mbox;}
44 void setMbox(const QString&box){mbox = box;} 44 void setMbox(const QString&box){mbox = box;}
45 void setMsgid(const QString&id){msg_id=id;} 45 void setMsgid(const QString&id){msg_id=id;}
46 const QString&Msgid()const{return msg_id;} 46 const QString&Msgid()const{return msg_id;}
47 void setReplyto(const QString&reply){replyto=reply;}
48 const QString&Replyto()const{return replyto;}
49
47 50
48 void setTo(const QStringList&list); 51 void setTo(const QStringList&list);
49 const QStringList&To()const; 52 const QStringList&To()const;
50 void setCC(const QStringList&list); 53 void setCC(const QStringList&list);
51 const QStringList&CC()const; 54 const QStringList&CC()const;
52 void setBcc(const QStringList&list); 55 void setBcc(const QStringList&list);
53 const QStringList&Bcc()const; 56 const QStringList&Bcc()const;
54 const QBitArray&getFlags()const{return msg_flags;} 57 const QBitArray&getFlags()const{return msg_flags;}
55 void setFlags(const QBitArray&flags){msg_flags = flags;} 58 void setFlags(const QBitArray&flags){msg_flags = flags;}
56 59
57protected: 60protected:
58 QString subject,date,from,mbox,msg_id; 61 QString subject,date,from,mbox,msg_id,replyto;
59 int msg_number; 62 int msg_number;
60 QBitArray msg_flags; 63 QBitArray msg_flags;
61 QStringList to,cc,bcc; 64 QStringList to,cc,bcc;
62 void init(); 65 void init();
63 void copy_old(const RecMail&old); 66 void copy_old(const RecMail&old);
64}; 67};
65 68
66class RecPart 69class RecPart
67{ 70{
68protected: 71protected:
69 QString m_type,m_subtype,m_identifier,m_encoding; 72 QString m_type,m_subtype,m_identifier,m_encoding;
70public: 73public:
71 RecPart(); 74 RecPart();
72 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); 75 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64");
73 virtual ~RecPart(); 76 virtual ~RecPart();
74 77
75 const QString&Type()const; 78 const QString&Type()const;
76 void setType(const QString&type); 79 void setType(const QString&type);
77 const QString&Subtype()const; 80 const QString&Subtype()const;
78 void setSubtype(const QString&subtype); 81 void setSubtype(const QString&subtype);
79 const QString&Identifier()const; 82 const QString&Identifier()const;
80 void setIdentifier(const QString&identifier); 83 void setIdentifier(const QString&identifier);
81 const QString&Encoding()const; 84 const QString&Encoding()const;
82 void setEncoding(const QString&encoding); 85 void setEncoding(const QString&encoding);
83}; 86};
84 87
85class RecBody 88class RecBody
86{ 89{
87protected: 90protected:
88 QString m_BodyText; 91 QString m_BodyText;
89 QList<RecPart> m_PartsList; 92 QList<RecPart> m_PartsList;
90 93
91public: 94public:
92 RecBody(); 95 RecBody();
93 virtual ~RecBody(); 96 virtual ~RecBody();
94 void setBodytext(const QString&); 97 void setBodytext(const QString&);
95 const QString& Bodytext()const; 98 const QString& Bodytext()const;
96 99
97 void setParts(const QList<RecPart>&parts); 100 void setParts(const QList<RecPart>&parts);
98 const QList<RecPart>& Parts()const; 101 const QList<RecPart>& Parts()const;
99 void addPart(const RecPart&part); 102 void addPart(const RecPart&part);
100}; 103};
101 104
102#endif 105#endif
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index c8d533a..6d6b080 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -1,102 +1,105 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <qlist.h> 11#include <qlist.h>
12#include <qbitarray.h> 12#include <qbitarray.h>
13#include <qstring.h> 13#include <qstring.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15 15
16/* a class to describe mails in a mailbox */ 16/* a class to describe mails in a mailbox */
17/* Attention! 17/* Attention!
18 From programmers point of view it would make sense to 18 From programmers point of view it would make sense to
19 store the mail body into this class, too. 19 store the mail body into this class, too.
20 But: not from the point of view of the device. 20 But: not from the point of view of the device.
21 Mailbodies can be real large. So we request them when 21 Mailbodies can be real large. So we request them when
22 needed from the mail-wrapper class direct from the server itself 22 needed from the mail-wrapper class direct from the server itself
23 (imap) or from a file-based cache (pop3?) 23 (imap) or from a file-based cache (pop3?)
24 So there is no interface "const QString&body()" but you should 24 So there is no interface "const QString&body()" but you should
25 make a request to the mailwrapper with this class as parameter to 25 make a request to the mailwrapper with this class as parameter to
26 get the body. Same words for the attachments. 26 get the body. Same words for the attachments.
27*/ 27*/
28class RecMail 28class RecMail
29{ 29{
30public: 30public:
31 RecMail(); 31 RecMail();
32 RecMail(const RecMail&old); 32 RecMail(const RecMail&old);
33 virtual ~RecMail(){} 33 virtual ~RecMail(){}
34 34
35 const int getNumber()const{return msg_number;} 35 const int getNumber()const{return msg_number;}
36 void setNumber(int number){msg_number=number;} 36 void setNumber(int number){msg_number=number;}
37 const QString&getDate()const{ return date; } 37 const QString&getDate()const{ return date; }
38 void setDate( const QString&a ) { date = a; } 38 void setDate( const QString&a ) { date = a; }
39 const QString&getFrom()const{ return from; } 39 const QString&getFrom()const{ return from; }
40 void setFrom( const QString&a ) { from = a; } 40 void setFrom( const QString&a ) { from = a; }
41 const QString&getSubject()const { return subject; } 41 const QString&getSubject()const { return subject; }
42 void setSubject( const QString&s ) { subject = s; } 42 void setSubject( const QString&s ) { subject = s; }
43 const QString&getMbox()const{return mbox;} 43 const QString&getMbox()const{return mbox;}
44 void setMbox(const QString&box){mbox = box;} 44 void setMbox(const QString&box){mbox = box;}
45 void setMsgid(const QString&id){msg_id=id;} 45 void setMsgid(const QString&id){msg_id=id;}
46 const QString&Msgid()const{return msg_id;} 46 const QString&Msgid()const{return msg_id;}
47 void setReplyto(const QString&reply){replyto=reply;}
48 const QString&Replyto()const{return replyto;}
49
47 50
48 void setTo(const QStringList&list); 51 void setTo(const QStringList&list);
49 const QStringList&To()const; 52 const QStringList&To()const;
50 void setCC(const QStringList&list); 53 void setCC(const QStringList&list);
51 const QStringList&CC()const; 54 const QStringList&CC()const;
52 void setBcc(const QStringList&list); 55 void setBcc(const QStringList&list);
53 const QStringList&Bcc()const; 56 const QStringList&Bcc()const;
54 const QBitArray&getFlags()const{return msg_flags;} 57 const QBitArray&getFlags()const{return msg_flags;}
55 void setFlags(const QBitArray&flags){msg_flags = flags;} 58 void setFlags(const QBitArray&flags){msg_flags = flags;}
56 59
57protected: 60protected:
58 QString subject,date,from,mbox,msg_id; 61 QString subject,date,from,mbox,msg_id,replyto;
59 int msg_number; 62 int msg_number;
60 QBitArray msg_flags; 63 QBitArray msg_flags;
61 QStringList to,cc,bcc; 64 QStringList to,cc,bcc;
62 void init(); 65 void init();
63 void copy_old(const RecMail&old); 66 void copy_old(const RecMail&old);
64}; 67};
65 68
66class RecPart 69class RecPart
67{ 70{
68protected: 71protected:
69 QString m_type,m_subtype,m_identifier,m_encoding; 72 QString m_type,m_subtype,m_identifier,m_encoding;
70public: 73public:
71 RecPart(); 74 RecPart();
72 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64"); 75 RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64");
73 virtual ~RecPart(); 76 virtual ~RecPart();
74 77
75 const QString&Type()const; 78 const QString&Type()const;
76 void setType(const QString&type); 79 void setType(const QString&type);
77 const QString&Subtype()const; 80 const QString&Subtype()const;
78 void setSubtype(const QString&subtype); 81 void setSubtype(const QString&subtype);
79 const QString&Identifier()const; 82 const QString&Identifier()const;
80 void setIdentifier(const QString&identifier); 83 void setIdentifier(const QString&identifier);
81 const QString&Encoding()const; 84 const QString&Encoding()const;
82 void setEncoding(const QString&encoding); 85 void setEncoding(const QString&encoding);
83}; 86};
84 87
85class RecBody 88class RecBody
86{ 89{
87protected: 90protected:
88 QString m_BodyText; 91 QString m_BodyText;
89 QList<RecPart> m_PartsList; 92 QList<RecPart> m_PartsList;
90 93
91public: 94public:
92 RecBody(); 95 RecBody();
93 virtual ~RecBody(); 96 virtual ~RecBody();
94 void setBodytext(const QString&); 97 void setBodytext(const QString&);
95 const QString& Bodytext()const; 98 const QString& Bodytext()const;
96 99
97 void setParts(const QList<RecPart>&parts); 100 void setParts(const QList<RecPart>&parts);
98 const QList<RecPart>& Parts()const; 101 const QList<RecPart>& Parts()const;
99 void addPart(const RecPart&part); 102 void addPart(const RecPart&part);
100}; 103};
101 104
102#endif 105#endif