summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-12-10 02:02:53 (UTC)
committer harlekin <harlekin>2003-12-10 02:02:53 (UTC)
commit1f0b92e554b76852af210ceb277b3e9ecb09a43d (patch) (unidiff)
treea813761b2f0d1a2b8a9a1a996d6e37d511d24f0f
parenta908d0ffdb5cee72b7823fc411119b8e1e3faad8 (diff)
downloadopie-1f0b92e554b76852af210ceb277b3e9ecb09a43d.zip
opie-1f0b92e554b76852af210ceb277b3e9ecb09a43d.tar.gz
opie-1f0b92e554b76852af210ceb277b3e9ecb09a43d.tar.bz2
ssl for imap now working
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp60
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp60
-rw-r--r--noncore/net/mail/mainwindow.cpp2
3 files changed, 67 insertions, 55 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index eae85a7..dc02780 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,471 +1,477 @@
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 (account->getSSL()) {
40 err = mailimap_ssl_connect( m_imap, (char*)server, port );
41 } else {
42 err = mailimap_socket_connect( m_imap, (char*)server, port );
43 }
44
45 if ( err != MAILIMAP_NO_ERROR &&
40 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 46 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
42 qDebug("error connecting server: %s",m_imap->response); 48 qDebug("error connecting server: %s",m_imap->response);
43 mailimap_free( m_imap ); 49 mailimap_free( m_imap );
44 m_imap = 0; 50 m_imap = 0;
45 return; 51 return;
46 } 52 }
47 53
48 /* login */ 54 /* login */
49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
50 if ( err != MAILIMAP_NO_ERROR ) { 56 if ( err != MAILIMAP_NO_ERROR ) {
51 qDebug("error logging in imap: %s",m_imap->response); 57 qDebug("error logging in imap: %s",m_imap->response);
52 err = mailimap_close( m_imap ); 58 err = mailimap_close( m_imap );
53 mailimap_free( m_imap ); 59 mailimap_free( m_imap );
54 m_imap = 0; 60 m_imap = 0;
55 } 61 }
56} 62}
57 63
58void IMAPwrapper::logout() 64void IMAPwrapper::logout()
59{ 65{
60 int err = MAILIMAP_NO_ERROR; 66 int err = MAILIMAP_NO_ERROR;
61 if (!m_imap) return; 67 if (!m_imap) return;
62 err = mailimap_logout( m_imap ); 68 err = mailimap_logout( m_imap );
63 err = mailimap_close( m_imap ); 69 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 70 mailimap_free( m_imap );
65 m_imap = 0; 71 m_imap = 0;
66} 72}
67 73
68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 74void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
69{ 75{
70 const char *mb; 76 const char *mb;
71 int err = MAILIMAP_NO_ERROR; 77 int err = MAILIMAP_NO_ERROR;
72 clist *result; 78 clist *result;
73 clistcell *current; 79 clistcell *current;
74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
75 mailimap_fetch_type *fetchType; 81 mailimap_fetch_type *fetchType;
76 mailimap_set *set; 82 mailimap_set *set;
77 83
78 mb = mailbox.latin1(); 84 mb = mailbox.latin1();
79 login(); 85 login();
80 if (!m_imap) { 86 if (!m_imap) {
81 return; 87 return;
82 } 88 }
83 /* select mailbox READONLY for operations */ 89 /* select mailbox READONLY for operations */
84 err = mailimap_examine( m_imap, (char*)mb); 90 err = mailimap_examine( m_imap, (char*)mb);
85 if ( err != MAILIMAP_NO_ERROR ) { 91 if ( err != MAILIMAP_NO_ERROR ) {
86 qDebug("error selecting mailbox: %s",m_imap->response); 92 qDebug("error selecting mailbox: %s",m_imap->response);
87 logout(); 93 logout();
88 return; 94 return;
89 } 95 }
90 96
91 int last = m_imap->selection_info->exists; 97 int last = m_imap->selection_info->exists;
92 98
93 if (last == 0) { 99 if (last == 0) {
94 qDebug("mailbox has no mails"); 100 qDebug("mailbox has no mails");
95 logout(); 101 logout();
96 return; 102 return;
97 } 103 }
98 104
99 result = clist_new(); 105 result = clist_new();
100 /* the range has to start at 1!!! not with 0!!!! */ 106 /* the range has to start at 1!!! not with 0!!!! */
101 set = mailimap_set_new_interval( 1, last ); 107 set = mailimap_set_new_interval( 1, last );
102 fetchAtt = mailimap_fetch_att_new_envelope(); 108 fetchAtt = mailimap_fetch_att_new_envelope();
103 fetchAttFlags = mailimap_fetch_att_new_flags(); 109 fetchAttFlags = mailimap_fetch_att_new_flags();
104 fetchAttDate = mailimap_fetch_att_new_internaldate(); 110 fetchAttDate = mailimap_fetch_att_new_internaldate();
105 111
106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 112 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 113 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 116 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
111 117
112 err = mailimap_fetch( m_imap, set, fetchType, &result ); 118 err = mailimap_fetch( m_imap, set, fetchType, &result );
113 mailimap_set_free( set ); 119 mailimap_set_free( set );
114 /* cleans up the fetch_att's too! */ 120 /* cleans up the fetch_att's too! */
115 mailimap_fetch_type_free( fetchType ); 121 mailimap_fetch_type_free( fetchType );
116 122
117 QString date,subject,from; 123 QString date,subject,from;
118 124
119 if ( err == MAILIMAP_NO_ERROR ) { 125 if ( err == MAILIMAP_NO_ERROR ) {
120 current = clist_begin(result); 126 current = clist_begin(result);
121 mailimap_msg_att * msg_att; 127 mailimap_msg_att * msg_att;
122 int i = 0; 128 int i = 0;
123 while ( current != 0 ) { 129 while ( current != 0 ) {
124 ++i; 130 ++i;
125 msg_att = (mailimap_msg_att*)current->data; 131 msg_att = (mailimap_msg_att*)current->data;
126 RecMail*m = parse_list_result(msg_att); 132 RecMail*m = parse_list_result(msg_att);
127 if (m) { 133 if (m) {
128 m->setNumber(i); 134 m->setNumber(i);
129 m->setMbox(mailbox); 135 m->setMbox(mailbox);
130 target.append(m); 136 target.append(m);
131 } 137 }
132 current = current->next; 138 current = current->next;
133 } 139 }
134 } else { 140 } else {
135 qDebug("Error fetching headers: %s",m_imap->response); 141 qDebug("Error fetching headers: %s",m_imap->response);
136 } 142 }
137 logout(); 143 logout();
138 clist_free(result); 144 clist_free(result);
139} 145}
140 146
141QList<IMAPFolder>* IMAPwrapper::listFolders() 147QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 148{
143 const char *path, *mask; 149 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 150 int err = MAILIMAP_NO_ERROR;
145 clist *result; 151 clist *result;
146 clistcell *current; 152 clistcell *current;
147 153
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 154 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 155 folders->setAutoDelete( true );
150 login(); 156 login();
151 if (!m_imap) { 157 if (!m_imap) {
152 return folders; 158 return folders;
153 } 159 }
154 160
155/* 161/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 162 * 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! 163 * 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. 164 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 165 */
160 QString temp; 166 QString temp;
161 mask = "INBOX" ; 167 mask = "INBOX" ;
162 result = clist_new(); 168 result = clist_new();
163 mailimap_mailbox_list *list; 169 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 171 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 172 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 173 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 174 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 175 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 176 // instead of using strdup!
171 temp = list->mb; 177 temp = list->mb;
172 folders->append( new IMAPFolder(temp)); 178 folders->append( new IMAPFolder(temp));
173 current = current->next; 179 current = current->next;
174 } 180 }
175 } else { 181 } else {
176 qDebug("error fetching folders: %s",m_imap->response); 182 qDebug("error fetching folders: %s",m_imap->response);
177 } 183 }
178 mailimap_list_result_free( result ); 184 mailimap_list_result_free( result );
179 185
180/* 186/*
181 * second stage - get the other then inbox folders 187 * second stage - get the other then inbox folders
182 */ 188 */
183 mask = "*" ; 189 mask = "*" ;
184 path = account->getPrefix().latin1(); 190 path = account->getPrefix().latin1();
185 result = clist_new(); 191 result = clist_new();
186 qDebug(path); 192 qDebug(path);
187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
188 if ( err == MAILIMAP_NO_ERROR ) { 194 if ( err == MAILIMAP_NO_ERROR ) {
189 current = result->first; 195 current = result->first;
190 for ( int i = result->count; i > 0; i-- ) { 196 for ( int i = result->count; i > 0; i-- ) {
191 list = (mailimap_mailbox_list *) current->data; 197 list = (mailimap_mailbox_list *) current->data;
192 // it is better use the deep copy mechanism of qt itself 198 // it is better use the deep copy mechanism of qt itself
193 // instead of using strdup! 199 // instead of using strdup!
194 temp = list->mb; 200 temp = list->mb;
195 current = current->next; 201 current = current->next;
196 if (temp.lower()=="inbox") 202 if (temp.lower()=="inbox")
197 continue; 203 continue;
198 folders->append(new IMAPFolder(temp)); 204 folders->append(new IMAPFolder(temp));
199 205
200 } 206 }
201 } else { 207 } else {
202 qDebug("error fetching folders %s",m_imap->response); 208 qDebug("error fetching folders %s",m_imap->response);
203 } 209 }
204 mailimap_list_result_free( result ); 210 mailimap_list_result_free( result );
205 return folders; 211 return folders;
206} 212}
207 213
208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 214RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
209{ 215{
210 RecMail * m = 0; 216 RecMail * m = 0;
211 mailimap_msg_att_item *item=0; 217 mailimap_msg_att_item *item=0;
212 clistcell *current,*c,*cf; 218 clistcell *current,*c,*cf;
213 mailimap_msg_att_dynamic*flist; 219 mailimap_msg_att_dynamic*flist;
214 mailimap_flag_fetch*cflag; 220 mailimap_flag_fetch*cflag;
215 QBitArray mFlags(7); 221 QBitArray mFlags(7);
216 QStringList addresslist; 222 QStringList addresslist;
217 223
218 if (!m_att) { 224 if (!m_att) {
219 return m; 225 return m;
220 } 226 }
221 227
222 c = clist_begin(m_att->list); 228 c = clist_begin(m_att->list);
223 while ( c ) { 229 while ( c ) {
224 current = c; 230 current = c;
225 c = c->next; 231 c = c->next;
226 item = (mailimap_msg_att_item*)current->data; 232 item = (mailimap_msg_att_item*)current->data;
227 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
228 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
229 if (!flist->list) { 235 if (!flist->list) {
230 continue; 236 continue;
231 } 237 }
232 cf = flist->list->first; 238 cf = flist->list->first;
233 while (cf) { 239 while (cf) {
234 cflag = (mailimap_flag_fetch*)cf->data; 240 cflag = (mailimap_flag_fetch*)cf->data;
235 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
236 switch (cflag->flag->type) { 242 switch (cflag->flag->type) {
237 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
238 mFlags.setBit(FLAG_ANSWERED); 244 mFlags.setBit(FLAG_ANSWERED);
239 break; 245 break;
240 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
241 mFlags.setBit(FLAG_FLAGGED); 247 mFlags.setBit(FLAG_FLAGGED);
242 break; 248 break;
243 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
244 mFlags.setBit(FLAG_DELETED); 250 mFlags.setBit(FLAG_DELETED);
245 break; 251 break;
246 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
247 mFlags.setBit(FLAG_SEEN); 253 mFlags.setBit(FLAG_SEEN);
248 break; 254 break;
249 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
250 mFlags.setBit(FLAG_DRAFT); 256 mFlags.setBit(FLAG_DRAFT);
251 break; 257 break;
252 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
253 break; 259 break;
254 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
255 break; 261 break;
256 default: 262 default:
257 break; 263 break;
258 } 264 }
259 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
260 mFlags.setBit(FLAG_RECENT); 266 mFlags.setBit(FLAG_RECENT);
261 } 267 }
262 cf = cf->next; 268 cf = cf->next;
263 } 269 }
264 continue; 270 continue;
265 } 271 }
266 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
267 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
268 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
269 mailimap_envelope * head = item->msg_att_static->env; 275 mailimap_envelope * head = item->msg_att_static->env;
270 m = new RecMail(); 276 m = new RecMail();
271 m->setDate(head->date); 277 m->setDate(head->date);
272 m->setSubject(head->subject); 278 m->setSubject(head->subject);
273 if (head->from!=NULL) { 279 if (head->from!=NULL) {
274 addresslist = address_list_to_stringlist(head->from->list); 280 addresslist = address_list_to_stringlist(head->from->list);
275 if (addresslist.count()) { 281 if (addresslist.count()) {
276 m->setFrom(addresslist.first()); 282 m->setFrom(addresslist.first());
277 } 283 }
278 } 284 }
279 if (head->to!=NULL) { 285 if (head->to!=NULL) {
280 addresslist = address_list_to_stringlist(head->to->list); 286 addresslist = address_list_to_stringlist(head->to->list);
281 m->setTo(addresslist); 287 m->setTo(addresslist);
282 } 288 }
283 if (head->cc!=NULL) { 289 if (head->cc!=NULL) {
284 addresslist = address_list_to_stringlist(head->cc->list); 290 addresslist = address_list_to_stringlist(head->cc->list);
285 m->setCC(addresslist); 291 m->setCC(addresslist);
286 } 292 }
287 if (head->bcc!=NULL) { 293 if (head->bcc!=NULL) {
288 addresslist = address_list_to_stringlist(head->bcc->list); 294 addresslist = address_list_to_stringlist(head->bcc->list);
289 m->setBcc(addresslist); 295 m->setBcc(addresslist);
290 } 296 }
291 if (head->reply_to!=NULL) { 297 if (head->reply_to!=NULL) {
292 addresslist = address_list_to_stringlist(head->bcc->list); 298 addresslist = address_list_to_stringlist(head->bcc->list);
293 if (addresslist.count()) { 299 if (addresslist.count()) {
294 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
295 } 301 }
296 } 302 }
297 m->setMsgid(QString(head->message_id)); 303 m->setMsgid(QString(head->message_id));
298 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", 304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s",
299 m->getFrom().latin1(), 305 m->getFrom().latin1(),
300 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1()); 306 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1());
301 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 307 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
302 mailimap_date_time*d = item->msg_att_static->internal_date; 308 mailimap_date_time*d = item->msg_att_static->internal_date;
303 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 309 QDateTime da(QDate(d->year,d->month,d->day),QTime(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); 310 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
305 qDebug(da.toString()); 311 qDebug(da.toString());
306 } else { 312 } else {
307 qDebug("Another type"); 313 qDebug("Another type");
308 } 314 }
309 } 315 }
310 /* msg is already deleted */ 316 /* msg is already deleted */
311 if (mFlags.testBit(FLAG_DELETED) && m) { 317 if (mFlags.testBit(FLAG_DELETED) && m) {
312 delete m; 318 delete m;
313 m = 0; 319 m = 0;
314 } 320 }
315 if (m) { 321 if (m) {
316 m->setFlags(mFlags); 322 m->setFlags(mFlags);
317 } 323 }
318 return m; 324 return m;
319} 325}
320 326
321RecBody IMAPwrapper::fetchBody(const RecMail&mail) 327RecBody IMAPwrapper::fetchBody(const RecMail&mail)
322{ 328{
323 RecBody body; 329 RecBody body;
324 const char *mb; 330 const char *mb;
325 int err = MAILIMAP_NO_ERROR; 331 int err = MAILIMAP_NO_ERROR;
326 clist *result; 332 clist *result;
327 clistcell *current; 333 clistcell *current;
328 mailimap_fetch_att *fetchAtt; 334 mailimap_fetch_att *fetchAtt;
329 mailimap_fetch_type *fetchType; 335 mailimap_fetch_type *fetchType;
330 mailimap_set *set; 336 mailimap_set *set;
331 mailimap_body*body_desc; 337 mailimap_body*body_desc;
332 338
333 mb = mail.getMbox().latin1(); 339 mb = mail.getMbox().latin1();
334 340
335 login(); 341 login();
336 if (!m_imap) { 342 if (!m_imap) {
337 return body; 343 return body;
338 } 344 }
339 /* select mailbox READONLY for operations */ 345 /* select mailbox READONLY for operations */
340 err = mailimap_examine( m_imap, (char*)mb); 346 err = mailimap_examine( m_imap, (char*)mb);
341 if ( err != MAILIMAP_NO_ERROR ) { 347 if ( err != MAILIMAP_NO_ERROR ) {
342 qDebug("error selecting mailbox: %s",m_imap->response); 348 qDebug("error selecting mailbox: %s",m_imap->response);
343 logout(); 349 logout();
344 return body; 350 return body;
345 } 351 }
346 result = clist_new(); 352 result = clist_new();
347 /* the range has to start at 1!!! not with 0!!!! */ 353 /* the range has to start at 1!!! not with 0!!!! */
348 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
349 fetchAtt = mailimap_fetch_att_new_body(); 355 fetchAtt = mailimap_fetch_att_new_body();
350 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
351 err = mailimap_fetch( m_imap, set, fetchType, &result ); 357 err = mailimap_fetch( m_imap, set, fetchType, &result );
352 mailimap_set_free( set ); 358 mailimap_set_free( set );
353 mailimap_fetch_type_free( fetchType ); 359 mailimap_fetch_type_free( fetchType );
354 360
355 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
356 mailimap_msg_att * msg_att; 362 mailimap_msg_att * msg_att;
357 msg_att = (mailimap_msg_att*)current->data; 363 msg_att = (mailimap_msg_att*)current->data;
358 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
359 body_desc = item->msg_att_static->body; 365 body_desc = item->msg_att_static->body;
360 if (body_desc->type==MAILIMAP_BODY_1PART) { 366 if (body_desc->type==MAILIMAP_BODY_1PART) {
361 searchBodyText(mail,body_desc->body_1part,body); 367 searchBodyText(mail,body_desc->body_1part,body);
362 } else { 368 } else {
363 } 369 }
364 370
365 } else { 371 } else {
366 qDebug("error fetching body: %s",m_imap->response); 372 qDebug("error fetching body: %s",m_imap->response);
367 } 373 }
368 374
369 clist_free(result); 375 clist_free(result);
370 logout(); 376 logout();
371 return body; 377 return body;
372} 378}
373 379
374void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 380void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
375{ 381{
376 if (!mailDescription) { 382 if (!mailDescription) {
377 return; 383 return;
378 } 384 }
379 switch (mailDescription->type) { 385 switch (mailDescription->type) {
380 case MAILIMAP_BODY_TYPE_1PART_TEXT: 386 case MAILIMAP_BODY_TYPE_1PART_TEXT:
381 fillPlainBody(mail,target_body,mailDescription->body_type_text); 387 fillPlainBody(mail,target_body,mailDescription->body_type_text);
382 break; 388 break;
383 default: 389 default:
384 break; 390 break;
385 } 391 }
386 return; 392 return;
387} 393}
388 394
389void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) 395void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body)
390{ 396{
391 const char *mb; 397 const char *mb;
392 QString body=""; 398 QString body="";
393 int err = MAILIMAP_NO_ERROR; 399 int err = MAILIMAP_NO_ERROR;
394 clist *result; 400 clist *result;
395 clistcell *current; 401 clistcell *current;
396 mailimap_fetch_att *fetchAtt; 402 mailimap_fetch_att *fetchAtt;
397 mailimap_fetch_type *fetchType; 403 mailimap_fetch_type *fetchType;
398 mailimap_set *set; 404 mailimap_set *set;
399 405
400 mb = mail.getMbox().latin1(); 406 mb = mail.getMbox().latin1();
401 407
402 if (!m_imap) { 408 if (!m_imap) {
403 return; 409 return;
404 } 410 }
405 411
406 result = clist_new(); 412 result = clist_new();
407 /* the range has to start at 1!!! not with 0!!!! */ 413 /* the range has to start at 1!!! not with 0!!!! */
408 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 414 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
409 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 415 fetchAtt = mailimap_fetch_att_new_rfc822_text();
410 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 416 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
411 err = mailimap_fetch( m_imap, set, fetchType, &result ); 417 err = mailimap_fetch( m_imap, set, fetchType, &result );
412 mailimap_set_free( set ); 418 mailimap_set_free( set );
413 mailimap_fetch_type_free( fetchType ); 419 mailimap_fetch_type_free( fetchType );
414 420
415 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 421 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
416 mailimap_msg_att * msg_att; 422 mailimap_msg_att * msg_att;
417 msg_att = (mailimap_msg_att*)current->data; 423 msg_att = (mailimap_msg_att*)current->data;
418 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 424 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
419 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 425 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
420 body = item->msg_att_static->rfc822_text; 426 body = item->msg_att_static->rfc822_text;
421 } 427 }
422 } else { 428 } else {
423 qDebug("error fetching text: %s",m_imap->response); 429 qDebug("error fetching text: %s",m_imap->response);
424 } 430 }
425 clist_free(result); 431 clist_free(result);
426 target_body.setBodytext(body); 432 target_body.setBodytext(body);
427 return; 433 return;
428} 434}
429 435
430QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 436QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
431{ 437{
432 QStringList l; 438 QStringList l;
433 QString from; 439 QString from;
434 bool named_from; 440 bool named_from;
435 clistcell *current = NULL; 441 clistcell *current = NULL;
436 mailimap_address * current_address=NULL; 442 mailimap_address * current_address=NULL;
437 if (!list) { 443 if (!list) {
438 return l; 444 return l;
439 } 445 }
440 current = clist_begin(list); 446 current = clist_begin(list);
441 unsigned int count = 0; 447 unsigned int count = 0;
442 while (current!= NULL) { 448 while (current!= NULL) {
443 from = ""; 449 from = "";
444 named_from = false; 450 named_from = false;
445 current_address=(mailimap_address*)current->data; 451 current_address=(mailimap_address*)current->data;
446 current = current->next; 452 current = current->next;
447 if (current_address->personal_name){ 453 if (current_address->personal_name){
448 from+=QString(current_address->personal_name); 454 from+=QString(current_address->personal_name);
449 from+=" "; 455 from+=" ";
450 named_from = true; 456 named_from = true;
451 } 457 }
452 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 458 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
453 from+="<"; 459 from+="<";
454 } 460 }
455 if (current_address->mailbox_name) { 461 if (current_address->mailbox_name) {
456 from+=QString(current_address->mailbox_name); 462 from+=QString(current_address->mailbox_name);
457 from+="@"; 463 from+="@";
458 } 464 }
459 if (current_address->host_name) { 465 if (current_address->host_name) {
460 from+=QString(current_address->host_name); 466 from+=QString(current_address->host_name);
461 } 467 }
462 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 468 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
463 from+=">"; 469 from+=">";
464 } 470 }
465 l.append(QString(from)); 471 l.append(QString(from));
466 if (++count > 99) { 472 if (++count > 99) {
467 break; 473 break;
468 } 474 }
469 } 475 }
470 return l; 476 return l;
471} 477}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index eae85a7..dc02780 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,471 +1,477 @@
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 (account->getSSL()) {
40 err = mailimap_ssl_connect( m_imap, (char*)server, port );
41 } else {
42 err = mailimap_socket_connect( m_imap, (char*)server, port );
43 }
44
45 if ( err != MAILIMAP_NO_ERROR &&
40 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 46 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
41 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
42 qDebug("error connecting server: %s",m_imap->response); 48 qDebug("error connecting server: %s",m_imap->response);
43 mailimap_free( m_imap ); 49 mailimap_free( m_imap );
44 m_imap = 0; 50 m_imap = 0;
45 return; 51 return;
46 } 52 }
47 53
48 /* login */ 54 /* login */
49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
50 if ( err != MAILIMAP_NO_ERROR ) { 56 if ( err != MAILIMAP_NO_ERROR ) {
51 qDebug("error logging in imap: %s",m_imap->response); 57 qDebug("error logging in imap: %s",m_imap->response);
52 err = mailimap_close( m_imap ); 58 err = mailimap_close( m_imap );
53 mailimap_free( m_imap ); 59 mailimap_free( m_imap );
54 m_imap = 0; 60 m_imap = 0;
55 } 61 }
56} 62}
57 63
58void IMAPwrapper::logout() 64void IMAPwrapper::logout()
59{ 65{
60 int err = MAILIMAP_NO_ERROR; 66 int err = MAILIMAP_NO_ERROR;
61 if (!m_imap) return; 67 if (!m_imap) return;
62 err = mailimap_logout( m_imap ); 68 err = mailimap_logout( m_imap );
63 err = mailimap_close( m_imap ); 69 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 70 mailimap_free( m_imap );
65 m_imap = 0; 71 m_imap = 0;
66} 72}
67 73
68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 74void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
69{ 75{
70 const char *mb; 76 const char *mb;
71 int err = MAILIMAP_NO_ERROR; 77 int err = MAILIMAP_NO_ERROR;
72 clist *result; 78 clist *result;
73 clistcell *current; 79 clistcell *current;
74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
75 mailimap_fetch_type *fetchType; 81 mailimap_fetch_type *fetchType;
76 mailimap_set *set; 82 mailimap_set *set;
77 83
78 mb = mailbox.latin1(); 84 mb = mailbox.latin1();
79 login(); 85 login();
80 if (!m_imap) { 86 if (!m_imap) {
81 return; 87 return;
82 } 88 }
83 /* select mailbox READONLY for operations */ 89 /* select mailbox READONLY for operations */
84 err = mailimap_examine( m_imap, (char*)mb); 90 err = mailimap_examine( m_imap, (char*)mb);
85 if ( err != MAILIMAP_NO_ERROR ) { 91 if ( err != MAILIMAP_NO_ERROR ) {
86 qDebug("error selecting mailbox: %s",m_imap->response); 92 qDebug("error selecting mailbox: %s",m_imap->response);
87 logout(); 93 logout();
88 return; 94 return;
89 } 95 }
90 96
91 int last = m_imap->selection_info->exists; 97 int last = m_imap->selection_info->exists;
92 98
93 if (last == 0) { 99 if (last == 0) {
94 qDebug("mailbox has no mails"); 100 qDebug("mailbox has no mails");
95 logout(); 101 logout();
96 return; 102 return;
97 } 103 }
98 104
99 result = clist_new(); 105 result = clist_new();
100 /* the range has to start at 1!!! not with 0!!!! */ 106 /* the range has to start at 1!!! not with 0!!!! */
101 set = mailimap_set_new_interval( 1, last ); 107 set = mailimap_set_new_interval( 1, last );
102 fetchAtt = mailimap_fetch_att_new_envelope(); 108 fetchAtt = mailimap_fetch_att_new_envelope();
103 fetchAttFlags = mailimap_fetch_att_new_flags(); 109 fetchAttFlags = mailimap_fetch_att_new_flags();
104 fetchAttDate = mailimap_fetch_att_new_internaldate(); 110 fetchAttDate = mailimap_fetch_att_new_internaldate();
105 111
106 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 112 //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
107 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 113 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
108 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
109 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); 116 mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
111 117
112 err = mailimap_fetch( m_imap, set, fetchType, &result ); 118 err = mailimap_fetch( m_imap, set, fetchType, &result );
113 mailimap_set_free( set ); 119 mailimap_set_free( set );
114 /* cleans up the fetch_att's too! */ 120 /* cleans up the fetch_att's too! */
115 mailimap_fetch_type_free( fetchType ); 121 mailimap_fetch_type_free( fetchType );
116 122
117 QString date,subject,from; 123 QString date,subject,from;
118 124
119 if ( err == MAILIMAP_NO_ERROR ) { 125 if ( err == MAILIMAP_NO_ERROR ) {
120 current = clist_begin(result); 126 current = clist_begin(result);
121 mailimap_msg_att * msg_att; 127 mailimap_msg_att * msg_att;
122 int i = 0; 128 int i = 0;
123 while ( current != 0 ) { 129 while ( current != 0 ) {
124 ++i; 130 ++i;
125 msg_att = (mailimap_msg_att*)current->data; 131 msg_att = (mailimap_msg_att*)current->data;
126 RecMail*m = parse_list_result(msg_att); 132 RecMail*m = parse_list_result(msg_att);
127 if (m) { 133 if (m) {
128 m->setNumber(i); 134 m->setNumber(i);
129 m->setMbox(mailbox); 135 m->setMbox(mailbox);
130 target.append(m); 136 target.append(m);
131 } 137 }
132 current = current->next; 138 current = current->next;
133 } 139 }
134 } else { 140 } else {
135 qDebug("Error fetching headers: %s",m_imap->response); 141 qDebug("Error fetching headers: %s",m_imap->response);
136 } 142 }
137 logout(); 143 logout();
138 clist_free(result); 144 clist_free(result);
139} 145}
140 146
141QList<IMAPFolder>* IMAPwrapper::listFolders() 147QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 148{
143 const char *path, *mask; 149 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 150 int err = MAILIMAP_NO_ERROR;
145 clist *result; 151 clist *result;
146 clistcell *current; 152 clistcell *current;
147 153
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 154 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 155 folders->setAutoDelete( true );
150 login(); 156 login();
151 if (!m_imap) { 157 if (!m_imap) {
152 return folders; 158 return folders;
153 } 159 }
154 160
155/* 161/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 162 * 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! 163 * 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. 164 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 165 */
160 QString temp; 166 QString temp;
161 mask = "INBOX" ; 167 mask = "INBOX" ;
162 result = clist_new(); 168 result = clist_new();
163 mailimap_mailbox_list *list; 169 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 171 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 172 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 173 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 174 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 175 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 176 // instead of using strdup!
171 temp = list->mb; 177 temp = list->mb;
172 folders->append( new IMAPFolder(temp)); 178 folders->append( new IMAPFolder(temp));
173 current = current->next; 179 current = current->next;
174 } 180 }
175 } else { 181 } else {
176 qDebug("error fetching folders: %s",m_imap->response); 182 qDebug("error fetching folders: %s",m_imap->response);
177 } 183 }
178 mailimap_list_result_free( result ); 184 mailimap_list_result_free( result );
179 185
180/* 186/*
181 * second stage - get the other then inbox folders 187 * second stage - get the other then inbox folders
182 */ 188 */
183 mask = "*" ; 189 mask = "*" ;
184 path = account->getPrefix().latin1(); 190 path = account->getPrefix().latin1();
185 result = clist_new(); 191 result = clist_new();
186 qDebug(path); 192 qDebug(path);
187 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
188 if ( err == MAILIMAP_NO_ERROR ) { 194 if ( err == MAILIMAP_NO_ERROR ) {
189 current = result->first; 195 current = result->first;
190 for ( int i = result->count; i > 0; i-- ) { 196 for ( int i = result->count; i > 0; i-- ) {
191 list = (mailimap_mailbox_list *) current->data; 197 list = (mailimap_mailbox_list *) current->data;
192 // it is better use the deep copy mechanism of qt itself 198 // it is better use the deep copy mechanism of qt itself
193 // instead of using strdup! 199 // instead of using strdup!
194 temp = list->mb; 200 temp = list->mb;
195 current = current->next; 201 current = current->next;
196 if (temp.lower()=="inbox") 202 if (temp.lower()=="inbox")
197 continue; 203 continue;
198 folders->append(new IMAPFolder(temp)); 204 folders->append(new IMAPFolder(temp));
199 205
200 } 206 }
201 } else { 207 } else {
202 qDebug("error fetching folders %s",m_imap->response); 208 qDebug("error fetching folders %s",m_imap->response);
203 } 209 }
204 mailimap_list_result_free( result ); 210 mailimap_list_result_free( result );
205 return folders; 211 return folders;
206} 212}
207 213
208RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 214RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
209{ 215{
210 RecMail * m = 0; 216 RecMail * m = 0;
211 mailimap_msg_att_item *item=0; 217 mailimap_msg_att_item *item=0;
212 clistcell *current,*c,*cf; 218 clistcell *current,*c,*cf;
213 mailimap_msg_att_dynamic*flist; 219 mailimap_msg_att_dynamic*flist;
214 mailimap_flag_fetch*cflag; 220 mailimap_flag_fetch*cflag;
215 QBitArray mFlags(7); 221 QBitArray mFlags(7);
216 QStringList addresslist; 222 QStringList addresslist;
217 223
218 if (!m_att) { 224 if (!m_att) {
219 return m; 225 return m;
220 } 226 }
221 227
222 c = clist_begin(m_att->list); 228 c = clist_begin(m_att->list);
223 while ( c ) { 229 while ( c ) {
224 current = c; 230 current = c;
225 c = c->next; 231 c = c->next;
226 item = (mailimap_msg_att_item*)current->data; 232 item = (mailimap_msg_att_item*)current->data;
227 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
228 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn;
229 if (!flist->list) { 235 if (!flist->list) {
230 continue; 236 continue;
231 } 237 }
232 cf = flist->list->first; 238 cf = flist->list->first;
233 while (cf) { 239 while (cf) {
234 cflag = (mailimap_flag_fetch*)cf->data; 240 cflag = (mailimap_flag_fetch*)cf->data;
235 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) {
236 switch (cflag->flag->type) { 242 switch (cflag->flag->type) {
237 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
238 mFlags.setBit(FLAG_ANSWERED); 244 mFlags.setBit(FLAG_ANSWERED);
239 break; 245 break;
240 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
241 mFlags.setBit(FLAG_FLAGGED); 247 mFlags.setBit(FLAG_FLAGGED);
242 break; 248 break;
243 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
244 mFlags.setBit(FLAG_DELETED); 250 mFlags.setBit(FLAG_DELETED);
245 break; 251 break;
246 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
247 mFlags.setBit(FLAG_SEEN); 253 mFlags.setBit(FLAG_SEEN);
248 break; 254 break;
249 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
250 mFlags.setBit(FLAG_DRAFT); 256 mFlags.setBit(FLAG_DRAFT);
251 break; 257 break;
252 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
253 break; 259 break;
254 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
255 break; 261 break;
256 default: 262 default:
257 break; 263 break;
258 } 264 }
259 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) {
260 mFlags.setBit(FLAG_RECENT); 266 mFlags.setBit(FLAG_RECENT);
261 } 267 }
262 cf = cf->next; 268 cf = cf->next;
263 } 269 }
264 continue; 270 continue;
265 } 271 }
266 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
267 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header );
268 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) {
269 mailimap_envelope * head = item->msg_att_static->env; 275 mailimap_envelope * head = item->msg_att_static->env;
270 m = new RecMail(); 276 m = new RecMail();
271 m->setDate(head->date); 277 m->setDate(head->date);
272 m->setSubject(head->subject); 278 m->setSubject(head->subject);
273 if (head->from!=NULL) { 279 if (head->from!=NULL) {
274 addresslist = address_list_to_stringlist(head->from->list); 280 addresslist = address_list_to_stringlist(head->from->list);
275 if (addresslist.count()) { 281 if (addresslist.count()) {
276 m->setFrom(addresslist.first()); 282 m->setFrom(addresslist.first());
277 } 283 }
278 } 284 }
279 if (head->to!=NULL) { 285 if (head->to!=NULL) {
280 addresslist = address_list_to_stringlist(head->to->list); 286 addresslist = address_list_to_stringlist(head->to->list);
281 m->setTo(addresslist); 287 m->setTo(addresslist);
282 } 288 }
283 if (head->cc!=NULL) { 289 if (head->cc!=NULL) {
284 addresslist = address_list_to_stringlist(head->cc->list); 290 addresslist = address_list_to_stringlist(head->cc->list);
285 m->setCC(addresslist); 291 m->setCC(addresslist);
286 } 292 }
287 if (head->bcc!=NULL) { 293 if (head->bcc!=NULL) {
288 addresslist = address_list_to_stringlist(head->bcc->list); 294 addresslist = address_list_to_stringlist(head->bcc->list);
289 m->setBcc(addresslist); 295 m->setBcc(addresslist);
290 } 296 }
291 if (head->reply_to!=NULL) { 297 if (head->reply_to!=NULL) {
292 addresslist = address_list_to_stringlist(head->bcc->list); 298 addresslist = address_list_to_stringlist(head->bcc->list);
293 if (addresslist.count()) { 299 if (addresslist.count()) {
294 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
295 } 301 }
296 } 302 }
297 m->setMsgid(QString(head->message_id)); 303 m->setMsgid(QString(head->message_id));
298 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", 304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s",
299 m->getFrom().latin1(), 305 m->getFrom().latin1(),
300 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1()); 306 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1());
301 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 307 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
302 mailimap_date_time*d = item->msg_att_static->internal_date; 308 mailimap_date_time*d = item->msg_att_static->internal_date;
303 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 309 QDateTime da(QDate(d->year,d->month,d->day),QTime(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); 310 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
305 qDebug(da.toString()); 311 qDebug(da.toString());
306 } else { 312 } else {
307 qDebug("Another type"); 313 qDebug("Another type");
308 } 314 }
309 } 315 }
310 /* msg is already deleted */ 316 /* msg is already deleted */
311 if (mFlags.testBit(FLAG_DELETED) && m) { 317 if (mFlags.testBit(FLAG_DELETED) && m) {
312 delete m; 318 delete m;
313 m = 0; 319 m = 0;
314 } 320 }
315 if (m) { 321 if (m) {
316 m->setFlags(mFlags); 322 m->setFlags(mFlags);
317 } 323 }
318 return m; 324 return m;
319} 325}
320 326
321RecBody IMAPwrapper::fetchBody(const RecMail&mail) 327RecBody IMAPwrapper::fetchBody(const RecMail&mail)
322{ 328{
323 RecBody body; 329 RecBody body;
324 const char *mb; 330 const char *mb;
325 int err = MAILIMAP_NO_ERROR; 331 int err = MAILIMAP_NO_ERROR;
326 clist *result; 332 clist *result;
327 clistcell *current; 333 clistcell *current;
328 mailimap_fetch_att *fetchAtt; 334 mailimap_fetch_att *fetchAtt;
329 mailimap_fetch_type *fetchType; 335 mailimap_fetch_type *fetchType;
330 mailimap_set *set; 336 mailimap_set *set;
331 mailimap_body*body_desc; 337 mailimap_body*body_desc;
332 338
333 mb = mail.getMbox().latin1(); 339 mb = mail.getMbox().latin1();
334 340
335 login(); 341 login();
336 if (!m_imap) { 342 if (!m_imap) {
337 return body; 343 return body;
338 } 344 }
339 /* select mailbox READONLY for operations */ 345 /* select mailbox READONLY for operations */
340 err = mailimap_examine( m_imap, (char*)mb); 346 err = mailimap_examine( m_imap, (char*)mb);
341 if ( err != MAILIMAP_NO_ERROR ) { 347 if ( err != MAILIMAP_NO_ERROR ) {
342 qDebug("error selecting mailbox: %s",m_imap->response); 348 qDebug("error selecting mailbox: %s",m_imap->response);
343 logout(); 349 logout();
344 return body; 350 return body;
345 } 351 }
346 result = clist_new(); 352 result = clist_new();
347 /* the range has to start at 1!!! not with 0!!!! */ 353 /* the range has to start at 1!!! not with 0!!!! */
348 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
349 fetchAtt = mailimap_fetch_att_new_body(); 355 fetchAtt = mailimap_fetch_att_new_body();
350 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
351 err = mailimap_fetch( m_imap, set, fetchType, &result ); 357 err = mailimap_fetch( m_imap, set, fetchType, &result );
352 mailimap_set_free( set ); 358 mailimap_set_free( set );
353 mailimap_fetch_type_free( fetchType ); 359 mailimap_fetch_type_free( fetchType );
354 360
355 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
356 mailimap_msg_att * msg_att; 362 mailimap_msg_att * msg_att;
357 msg_att = (mailimap_msg_att*)current->data; 363 msg_att = (mailimap_msg_att*)current->data;
358 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
359 body_desc = item->msg_att_static->body; 365 body_desc = item->msg_att_static->body;
360 if (body_desc->type==MAILIMAP_BODY_1PART) { 366 if (body_desc->type==MAILIMAP_BODY_1PART) {
361 searchBodyText(mail,body_desc->body_1part,body); 367 searchBodyText(mail,body_desc->body_1part,body);
362 } else { 368 } else {
363 } 369 }
364 370
365 } else { 371 } else {
366 qDebug("error fetching body: %s",m_imap->response); 372 qDebug("error fetching body: %s",m_imap->response);
367 } 373 }
368 374
369 clist_free(result); 375 clist_free(result);
370 logout(); 376 logout();
371 return body; 377 return body;
372} 378}
373 379
374void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 380void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
375{ 381{
376 if (!mailDescription) { 382 if (!mailDescription) {
377 return; 383 return;
378 } 384 }
379 switch (mailDescription->type) { 385 switch (mailDescription->type) {
380 case MAILIMAP_BODY_TYPE_1PART_TEXT: 386 case MAILIMAP_BODY_TYPE_1PART_TEXT:
381 fillPlainBody(mail,target_body,mailDescription->body_type_text); 387 fillPlainBody(mail,target_body,mailDescription->body_type_text);
382 break; 388 break;
383 default: 389 default:
384 break; 390 break;
385 } 391 }
386 return; 392 return;
387} 393}
388 394
389void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) 395void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body)
390{ 396{
391 const char *mb; 397 const char *mb;
392 QString body=""; 398 QString body="";
393 int err = MAILIMAP_NO_ERROR; 399 int err = MAILIMAP_NO_ERROR;
394 clist *result; 400 clist *result;
395 clistcell *current; 401 clistcell *current;
396 mailimap_fetch_att *fetchAtt; 402 mailimap_fetch_att *fetchAtt;
397 mailimap_fetch_type *fetchType; 403 mailimap_fetch_type *fetchType;
398 mailimap_set *set; 404 mailimap_set *set;
399 405
400 mb = mail.getMbox().latin1(); 406 mb = mail.getMbox().latin1();
401 407
402 if (!m_imap) { 408 if (!m_imap) {
403 return; 409 return;
404 } 410 }
405 411
406 result = clist_new(); 412 result = clist_new();
407 /* the range has to start at 1!!! not with 0!!!! */ 413 /* the range has to start at 1!!! not with 0!!!! */
408 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 414 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
409 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 415 fetchAtt = mailimap_fetch_att_new_rfc822_text();
410 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 416 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
411 err = mailimap_fetch( m_imap, set, fetchType, &result ); 417 err = mailimap_fetch( m_imap, set, fetchType, &result );
412 mailimap_set_free( set ); 418 mailimap_set_free( set );
413 mailimap_fetch_type_free( fetchType ); 419 mailimap_fetch_type_free( fetchType );
414 420
415 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 421 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
416 mailimap_msg_att * msg_att; 422 mailimap_msg_att * msg_att;
417 msg_att = (mailimap_msg_att*)current->data; 423 msg_att = (mailimap_msg_att*)current->data;
418 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 424 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
419 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 425 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
420 body = item->msg_att_static->rfc822_text; 426 body = item->msg_att_static->rfc822_text;
421 } 427 }
422 } else { 428 } else {
423 qDebug("error fetching text: %s",m_imap->response); 429 qDebug("error fetching text: %s",m_imap->response);
424 } 430 }
425 clist_free(result); 431 clist_free(result);
426 target_body.setBodytext(body); 432 target_body.setBodytext(body);
427 return; 433 return;
428} 434}
429 435
430QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 436QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
431{ 437{
432 QStringList l; 438 QStringList l;
433 QString from; 439 QString from;
434 bool named_from; 440 bool named_from;
435 clistcell *current = NULL; 441 clistcell *current = NULL;
436 mailimap_address * current_address=NULL; 442 mailimap_address * current_address=NULL;
437 if (!list) { 443 if (!list) {
438 return l; 444 return l;
439 } 445 }
440 current = clist_begin(list); 446 current = clist_begin(list);
441 unsigned int count = 0; 447 unsigned int count = 0;
442 while (current!= NULL) { 448 while (current!= NULL) {
443 from = ""; 449 from = "";
444 named_from = false; 450 named_from = false;
445 current_address=(mailimap_address*)current->data; 451 current_address=(mailimap_address*)current->data;
446 current = current->next; 452 current = current->next;
447 if (current_address->personal_name){ 453 if (current_address->personal_name){
448 from+=QString(current_address->personal_name); 454 from+=QString(current_address->personal_name);
449 from+=" "; 455 from+=" ";
450 named_from = true; 456 named_from = true;
451 } 457 }
452 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 458 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
453 from+="<"; 459 from+="<";
454 } 460 }
455 if (current_address->mailbox_name) { 461 if (current_address->mailbox_name) {
456 from+=QString(current_address->mailbox_name); 462 from+=QString(current_address->mailbox_name);
457 from+="@"; 463 from+="@";
458 } 464 }
459 if (current_address->host_name) { 465 if (current_address->host_name) {
460 from+=QString(current_address->host_name); 466 from+=QString(current_address->host_name);
461 } 467 }
462 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 468 if (named_from && (current_address->mailbox_name || current_address->host_name)) {
463 from+=">"; 469 from+=">";
464 } 470 }
465 l.append(QString(from)); 471 l.append(QString(from));
466 if (++count > 99) { 472 if (++count > 99) {
467 break; 473 break;
468 } 474 }
469 } 475 }
470 return l; 476 return l;
471} 477}
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp
index 3edfff1..6d13a8b 100644
--- a/noncore/net/mail/mainwindow.cpp
+++ b/noncore/net/mail/mainwindow.cpp
@@ -1,185 +1,185 @@
1#include <qlabel.h> 1#include <qlabel.h>
2#include <qvbox.h> 2#include <qvbox.h>
3#include <qheader.h> 3#include <qheader.h>
4#include <qtimer.h> 4#include <qtimer.h>
5#include <qlayout.h> 5#include <qlayout.h>
6 6
7#include <qpe/qpeapplication.h> 7#include <qpe/qpeapplication.h>
8 8
9#include "defines.h" 9#include "defines.h"
10#include "mainwindow.h" 10#include "mainwindow.h"
11#include "viewmail.h" 11#include "viewmail.h"
12#include "mailtypes.h" 12#include "mailtypes.h"
13#include "mailistviewitem.h" 13#include "mailistviewitem.h"
14 14
15MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) 15MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags )
16 : QMainWindow( parent, name, flags ) 16 : QMainWindow( parent, name, flags )
17{ 17{
18 setCaption( tr( "Opie-Mail" ) ); 18 setCaption( tr( "Mail" ) );
19 setToolBarsMovable( false ); 19 setToolBarsMovable( false );
20 20
21 toolBar = new QToolBar( this ); 21 toolBar = new QToolBar( this );
22 menuBar = new QMenuBar( toolBar ); 22 menuBar = new QMenuBar( toolBar );
23 mailMenu = new QPopupMenu( menuBar ); 23 mailMenu = new QPopupMenu( menuBar );
24 menuBar->insertItem( tr( "Mail" ), mailMenu ); 24 menuBar->insertItem( tr( "Mail" ), mailMenu );
25 settingsMenu = new QPopupMenu( menuBar ); 25 settingsMenu = new QPopupMenu( menuBar );
26 menuBar->insertItem( tr( "Settings" ), settingsMenu ); 26 menuBar->insertItem( tr( "Settings" ), settingsMenu );
27 27
28 addToolBar( toolBar ); 28 addToolBar( toolBar );
29 toolBar->setHorizontalStretchable( true ); 29 toolBar->setHorizontalStretchable( true );
30 30
31 QLabel *spacer = new QLabel( toolBar ); 31 QLabel *spacer = new QLabel( toolBar );
32 spacer->setBackgroundMode( QWidget::PaletteButton ); 32 spacer->setBackgroundMode( QWidget::PaletteButton );
33 toolBar->setStretchableWidget( spacer ); 33 toolBar->setStretchableWidget( spacer );
34 34
35 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, 35 composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL,
36 0, 0, this ); 36 0, 0, this );
37 composeMail->addTo( toolBar ); 37 composeMail->addTo( toolBar );
38 composeMail->addTo( mailMenu ); 38 composeMail->addTo( mailMenu );
39 39
40 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, 40 sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED,
41 0, 0, this ); 41 0, 0, this );
42 sendQueued->addTo( toolBar ); 42 sendQueued->addTo( toolBar );
43 sendQueued->addTo( mailMenu ); 43 sendQueued->addTo( mailMenu );
44 44
45 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, 45 syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC,
46 0, 0, this ); 46 0, 0, this );
47 syncFolders->addTo( toolBar ); 47 syncFolders->addTo( toolBar );
48 syncFolders->addTo( mailMenu ); 48 syncFolders->addTo( mailMenu );
49 49
50 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, 50 showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS,
51 0, 0, this, 0, true ); 51 0, 0, this, 0, true );
52 showFolders->addTo( toolBar ); 52 showFolders->addTo( toolBar );
53 showFolders->addTo( mailMenu ); 53 showFolders->addTo( mailMenu );
54 connect(showFolders, SIGNAL( toggled( bool ) ), 54 connect(showFolders, SIGNAL( toggled( bool ) ),
55 SLOT( slotShowFolders( bool ) ) ); 55 SLOT( slotShowFolders( bool ) ) );
56 56
57 searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, 57 searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS,
58 0, 0, this ); 58 0, 0, this );
59 searchMails->addTo( toolBar ); 59 searchMails->addTo( toolBar );
60 searchMails->addTo( mailMenu ); 60 searchMails->addTo( mailMenu );
61 61
62 62
63 editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, 63 editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS,
64 0, 0, this ); 64 0, 0, this );
65 editSettings->addTo( settingsMenu ); 65 editSettings->addTo( settingsMenu );
66 66
67 editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, 67 editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS,
68 0, 0, this ); 68 0, 0, this );
69 editAccounts->addTo( settingsMenu ); 69 editAccounts->addTo( settingsMenu );
70 70
71 QWidget *view = new QWidget( this ); 71 QWidget *view = new QWidget( this );
72 setCentralWidget( view ); 72 setCentralWidget( view );
73 73
74 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); 74 layout = new QBoxLayout ( view, QBoxLayout::LeftToRight );
75 75
76 folderView = new AccountView( view ); 76 folderView = new AccountView( view );
77 folderView->header()->hide(); 77 folderView->header()->hide();
78 folderView->addColumn( tr( "Mailbox" ) ); 78 folderView->addColumn( tr( "Mailbox" ) );
79 folderView->hide(); 79 folderView->hide();
80 80
81 layout->addWidget( folderView ); 81 layout->addWidget( folderView );
82 82
83 mailView = new QListView( view ); 83 mailView = new QListView( view );
84 mailView->addColumn( tr( "Subject" ),QListView::Manual ); 84 mailView->addColumn( tr( "Subject" ),QListView::Manual );
85 mailView->addColumn( tr( "Sender" ),QListView::Manual ); 85 mailView->addColumn( tr( "Sender" ),QListView::Manual );
86 mailView->addColumn( tr( "Date" )); 86 mailView->addColumn( tr( "Date" ));
87 mailView->setAllColumnsShowFocus(true); 87 mailView->setAllColumnsShowFocus(true);
88 mailView->setSorting(-1); 88 mailView->setSorting(-1);
89 89
90 layout->addWidget( mailView ); 90 layout->addWidget( mailView );
91 layout->setStretchFactor( folderView, 1 ); 91 layout->setStretchFactor( folderView, 1 );
92 layout->setStretchFactor( mailView, 2 ); 92 layout->setStretchFactor( mailView, 2 );
93 93
94 slotAdjustLayout(); 94 slotAdjustLayout();
95 95
96 connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this, 96 connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this,
97 SLOT( displayMail( QListViewItem * ) ) ); 97 SLOT( displayMail( QListViewItem * ) ) );
98 98
99 connect(folderView,SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); 99 connect(folderView,SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*)));
100 100
101 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); 101 QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) );
102} 102}
103 103
104 104
105void MainWindow::slotAdjustLayout() { 105void MainWindow::slotAdjustLayout() {
106 106
107 QWidget *d = QApplication::desktop(); 107 QWidget *d = QApplication::desktop();
108 108
109 if ( d->width() < d->height() ) { 109 if ( d->width() < d->height() ) {
110 layout->setDirection( QBoxLayout::TopToBottom ); 110 layout->setDirection( QBoxLayout::TopToBottom );
111 } else { 111 } else {
112 layout->setDirection( QBoxLayout::LeftToRight ); 112 layout->setDirection( QBoxLayout::LeftToRight );
113 } 113 }
114 delete d; 114 delete d;
115} 115}
116 116
117void MainWindow::slotAdjustColumns() 117void MainWindow::slotAdjustColumns()
118{ 118{
119 bool hidden = folderView->isHidden(); 119 bool hidden = folderView->isHidden();
120 if ( hidden ) folderView->show(); 120 if ( hidden ) folderView->show();
121 folderView->setColumnWidth( 0, folderView->visibleWidth() ); 121 folderView->setColumnWidth( 0, folderView->visibleWidth() );
122 if ( hidden ) folderView->hide(); 122 if ( hidden ) folderView->hide();
123 123
124 mailView->setColumnWidth( 0, mailView->visibleWidth() - 130 ); 124 mailView->setColumnWidth( 0, mailView->visibleWidth() - 130 );
125 mailView->setColumnWidth( 1, 80 ); 125 mailView->setColumnWidth( 1, 80 );
126 mailView->setColumnWidth( 2, 50 ); 126 mailView->setColumnWidth( 2, 50 );
127} 127}
128 128
129void MainWindow::slotShowFolders( bool show ) 129void MainWindow::slotShowFolders( bool show )
130{ 130{
131 qDebug( "Show Folders" ); 131 qDebug( "Show Folders" );
132 if ( show && folderView->isHidden() ) { 132 if ( show && folderView->isHidden() ) {
133 qDebug( "-> showing" ); 133 qDebug( "-> showing" );
134 folderView->show(); 134 folderView->show();
135 } else if ( !show && !folderView->isHidden() ) { 135 } else if ( !show && !folderView->isHidden() ) {
136 qDebug( "-> hiding" ); 136 qDebug( "-> hiding" );
137 folderView->hide(); 137 folderView->hide();
138 } 138 }
139} 139}
140 140
141void MainWindow::refreshMailView(QList<RecMail>*list) 141void MainWindow::refreshMailView(QList<RecMail>*list)
142{ 142{
143 MailListViewItem*item = 0; 143 MailListViewItem*item = 0;
144 mailView->clear(); 144 mailView->clear();
145 for (unsigned int i = 0; i < list->count();++i) { 145 for (unsigned int i = 0; i < list->count();++i) {
146 item = new MailListViewItem(mailView,item); 146 item = new MailListViewItem(mailView,item);
147 item->storeData(*(list->at(i))); 147 item->storeData(*(list->at(i)));
148 item->showEntry(); 148 item->showEntry();
149 } 149 }
150} 150}
151void MainWindow::displayMail(QListViewItem*item) 151void MainWindow::displayMail(QListViewItem*item)
152{ 152{
153 if (!item) return; 153 if (!item) return;
154 qDebug("View mail"); 154 qDebug("View mail");
155 RecMail mail = ((MailListViewItem*)item)->data(); 155 RecMail mail = ((MailListViewItem*)item)->data();
156 RecBody body = folderView->fetchBody(mail); 156 RecBody body = folderView->fetchBody(mail);
157 157
158 ViewMail readMail( this ); 158 ViewMail readMail( this );
159 159
160 readMail.setMailInfo( mail.getFrom(), mail.To(), mail.getSubject(), mail.CC(), mail.Bcc(), mail.getDate(), body.Bodytext(), mail.Msgid() ); 160 readMail.setMailInfo( mail.getFrom(), mail.To(), mail.getSubject(), mail.CC(), mail.Bcc(), mail.getDate(), body.Bodytext(), mail.Msgid() );
161 readMail.showMaximized(); 161 readMail.showMaximized();
162 readMail.exec(); 162 readMail.exec();
163} 163}
164 164
165MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * after ) 165MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * after )
166 :QListViewItem(parent,after),mail_data() 166 :QListViewItem(parent,after),mail_data()
167{ 167{
168} 168}
169 169
170void MailListViewItem::showEntry() 170void MailListViewItem::showEntry()
171{ 171{
172 setText(0,mail_data.getSubject()); 172 setText(0,mail_data.getSubject());
173 setText(1,mail_data.getFrom()); 173 setText(1,mail_data.getFrom());
174 setText(2,mail_data.getDate()); 174 setText(2,mail_data.getDate());
175} 175}
176 176
177void MailListViewItem::storeData(const RecMail&data) 177void MailListViewItem::storeData(const RecMail&data)
178{ 178{
179 mail_data = data; 179 mail_data = data;
180} 180}
181 181
182const RecMail& MailListViewItem::data()const 182const RecMail& MailListViewItem::data()const
183{ 183{
184 return mail_data; 184 return mail_data;
185} 185}