summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-14 19:36:09 (UTC)
committer alwin <alwin>2003-12-14 19:36:09 (UTC)
commitaa2c19611a347a3945d403e20bcef01977d68b6a (patch) (unidiff)
tree669bf39c587f9ee22e17fe2c61ed0fec78f356d3
parent353e1da81b235d7798763bce76428fb473108fb6 (diff)
downloadopie-aa2c19611a347a3945d403e20bcef01977d68b6a.zip
opie-aa2c19611a347a3945d403e20bcef01977d68b6a.tar.gz
opie-aa2c19611a347a3945d403e20bcef01977d68b6a.tar.bz2
if a mailbox-prefix is set than it will not displayed in folderview
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp12
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h4
-rw-r--r--noncore/net/mail/mailwrapper.cpp12
-rw-r--r--noncore/net/mail/mailwrapper.h4
6 files changed, 32 insertions, 8 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index b253b49..0ce2c6c 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,591 +1,593 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 152 folders->setAutoDelete( false );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 169 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 173 // instead of using strdup!
174 temp = list->mb_name; 174 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
176 current = current->next; 176 current = current->next;
177 } 177 }
178 } else { 178 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 180 }
181 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
182 182
183/* 183/*
184 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
185 */ 185 */
186 mask = "*" ; 186 mask = "*" ;
187 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
188 if (!path) path = ""; 188 if (!path) path = "";
189 result = clist_new(); 189 result = clist_new();
190 qDebug(path); 190 qDebug(path);
191 bool selectable = true; 191 bool selectable = true;
192 mailimap_mbx_list_flags*bflags; 192 mailimap_mbx_list_flags*bflags;
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 194 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 195 current = result->first;
196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
197 list = (mailimap_mailbox_list *) current->data; 197 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 198 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 199 // instead of using strdup!
200 temp = list->mb_name; 200 temp = list->mb_name;
201 if (temp.lower()=="inbox") 201 if (temp.lower()=="inbox")
202 continue; 202 continue;
203 if (temp.lower()==account->getPrefix().lower())
204 continue;
203 if ( (bflags = list->mb_flag) ) { 205 if ( (bflags = list->mb_flag) ) {
204 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
205 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
206 } 208 }
207 folders->append(new IMAPFolder(temp,selectable)); 209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix()));
208 } 210 }
209 } else { 211 } else {
210 qDebug("error fetching folders %s",m_imap->imap_response); 212 qDebug("error fetching folders %s",m_imap->imap_response);
211 } 213 }
212 mailimap_list_result_free( result ); 214 mailimap_list_result_free( result );
213 return folders; 215 return folders;
214} 216}
215 217
216RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
217{ 219{
218 RecMail * m = 0; 220 RecMail * m = 0;
219 mailimap_msg_att_item *item=0; 221 mailimap_msg_att_item *item=0;
220 clistcell *current,*c,*cf; 222 clistcell *current,*c,*cf;
221 mailimap_msg_att_dynamic*flist; 223 mailimap_msg_att_dynamic*flist;
222 mailimap_flag_fetch*cflag; 224 mailimap_flag_fetch*cflag;
223 int size; 225 int size;
224 QBitArray mFlags(7); 226 QBitArray mFlags(7);
225 QStringList addresslist; 227 QStringList addresslist;
226 228
227 if (!m_att) { 229 if (!m_att) {
228 return m; 230 return m;
229 } 231 }
230 m = new RecMail(); 232 m = new RecMail();
231 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
232 current = c; 234 current = c;
233 size = 0; 235 size = 0;
234 item = (mailimap_msg_att_item*)current->data; 236 item = (mailimap_msg_att_item*)current->data;
235 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
236 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
237 if (!flist->att_list) { 239 if (!flist->att_list) {
238 continue; 240 continue;
239 } 241 }
240 cf = flist->att_list->first; 242 cf = flist->att_list->first;
241 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
242 cflag = (mailimap_flag_fetch*)cf->data; 244 cflag = (mailimap_flag_fetch*)cf->data;
243 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
244 switch (cflag->fl_flag->fl_type) { 246 switch (cflag->fl_flag->fl_type) {
245 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
246 mFlags.setBit(FLAG_ANSWERED); 248 mFlags.setBit(FLAG_ANSWERED);
247 break; 249 break;
248 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
249 mFlags.setBit(FLAG_FLAGGED); 251 mFlags.setBit(FLAG_FLAGGED);
250 break; 252 break;
251 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
252 mFlags.setBit(FLAG_DELETED); 254 mFlags.setBit(FLAG_DELETED);
253 break; 255 break;
254 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
255 mFlags.setBit(FLAG_SEEN); 257 mFlags.setBit(FLAG_SEEN);
256 break; 258 break;
257 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
258 mFlags.setBit(FLAG_DRAFT); 260 mFlags.setBit(FLAG_DRAFT);
259 break; 261 break;
260 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
261 break; 263 break;
262 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
263 break; 265 break;
264 default: 266 default:
265 break; 267 break;
266 } 268 }
267 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
268 mFlags.setBit(FLAG_RECENT); 270 mFlags.setBit(FLAG_RECENT);
269 } 271 }
270 } 272 }
271 continue; 273 continue;
272 } 274 }
273 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
274 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
275 m->setDate(head->env_date); 277 m->setDate(head->env_date);
276 m->setSubject(head->env_subject); 278 m->setSubject(head->env_subject);
277 if (head->env_from!=NULL) { 279 if (head->env_from!=NULL) {
278 addresslist = address_list_to_stringlist(head->env_from->frm_list); 280 addresslist = address_list_to_stringlist(head->env_from->frm_list);
279 if (addresslist.count()) { 281 if (addresslist.count()) {
280 m->setFrom(addresslist.first()); 282 m->setFrom(addresslist.first());
281 } 283 }
282 } 284 }
283 if (head->env_to!=NULL) { 285 if (head->env_to!=NULL) {
284 addresslist = address_list_to_stringlist(head->env_to->to_list); 286 addresslist = address_list_to_stringlist(head->env_to->to_list);
285 m->setTo(addresslist); 287 m->setTo(addresslist);
286 } 288 }
287 if (head->env_cc!=NULL) { 289 if (head->env_cc!=NULL) {
288 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 290 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
289 m->setCC(addresslist); 291 m->setCC(addresslist);
290 } 292 }
291 if (head->env_bcc!=NULL) { 293 if (head->env_bcc!=NULL) {
292 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
293 m->setBcc(addresslist); 295 m->setBcc(addresslist);
294 } 296 }
295 if (head->env_reply_to!=NULL) { 297 if (head->env_reply_to!=NULL) {
296 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
297 if (addresslist.count()) { 299 if (addresslist.count()) {
298 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
299 } 301 }
300 } 302 }
301 m->setMsgid(QString(head->env_message_id)); 303 m->setMsgid(QString(head->env_message_id));
302 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
303 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
304#if 0 306#if 0
305 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
306 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
307 qDebug(da.toString()); 309 qDebug(da.toString());
308#endif 310#endif
309 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
310 size = item->att_data.att_static->att_data.att_rfc822_size; 312 size = item->att_data.att_static->att_data.att_rfc822_size;
311 } 313 }
312 } 314 }
313 /* msg is already deleted */ 315 /* msg is already deleted */
314 if (mFlags.testBit(FLAG_DELETED) && m) { 316 if (mFlags.testBit(FLAG_DELETED) && m) {
315 delete m; 317 delete m;
316 m = 0; 318 m = 0;
317 } 319 }
318 if (m) { 320 if (m) {
319 m->setFlags(mFlags); 321 m->setFlags(mFlags);
320 m->setMsgsize(size); 322 m->setMsgsize(size);
321 } 323 }
322 return m; 324 return m;
323} 325}
324 326
325RecBody IMAPwrapper::fetchBody(const RecMail&mail) 327RecBody IMAPwrapper::fetchBody(const RecMail&mail)
326{ 328{
327 RecBody body; 329 RecBody body;
328 const char *mb; 330 const char *mb;
329 int err = MAILIMAP_NO_ERROR; 331 int err = MAILIMAP_NO_ERROR;
330 clist *result; 332 clist *result;
331 clistcell *current; 333 clistcell *current;
332 mailimap_fetch_att *fetchAtt; 334 mailimap_fetch_att *fetchAtt;
333 mailimap_fetch_type *fetchType; 335 mailimap_fetch_type *fetchType;
334 mailimap_set *set; 336 mailimap_set *set;
335 mailimap_body*body_desc; 337 mailimap_body*body_desc;
336 338
337 mb = mail.getMbox().latin1(); 339 mb = mail.getMbox().latin1();
338 340
339 login(); 341 login();
340 if (!m_imap) { 342 if (!m_imap) {
341 return body; 343 return body;
342 } 344 }
343 345
344 err = mailimap_select( m_imap, (char*)mb); 346 err = mailimap_select( m_imap, (char*)mb);
345 if ( err != MAILIMAP_NO_ERROR ) { 347 if ( err != MAILIMAP_NO_ERROR ) {
346 qDebug("error selecting mailbox: %s",m_imap->imap_response); 348 qDebug("error selecting mailbox: %s",m_imap->imap_response);
347 return body; 349 return body;
348 } 350 }
349 351
350 result = clist_new(); 352 result = clist_new();
351 /* the range has to start at 1!!! not with 0!!!! */ 353 /* the range has to start at 1!!! not with 0!!!! */
352 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
353 fetchAtt = mailimap_fetch_att_new_bodystructure(); 355 fetchAtt = mailimap_fetch_att_new_bodystructure();
354 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
355 err = mailimap_fetch( m_imap, set, fetchType, &result ); 357 err = mailimap_fetch( m_imap, set, fetchType, &result );
356 mailimap_set_free( set ); 358 mailimap_set_free( set );
357 mailimap_fetch_type_free( fetchType ); 359 mailimap_fetch_type_free( fetchType );
358 360
359 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
360 mailimap_msg_att * msg_att; 362 mailimap_msg_att * msg_att;
361 msg_att = (mailimap_msg_att*)current->data; 363 msg_att = (mailimap_msg_att*)current->data;
362 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
363 body_desc = item->att_data.att_static->att_data.att_body; 365 body_desc = item->att_data.att_static->att_data.att_body;
364 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 366 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
365 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 367 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
366 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 368 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
367 qDebug("Mulitpart mail"); 369 qDebug("Mulitpart mail");
368 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 370 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
369 } 371 }
370 } else { 372 } else {
371 qDebug("error fetching body: %s",m_imap->imap_response); 373 qDebug("error fetching body: %s",m_imap->imap_response);
372 } 374 }
373 mailimap_fetch_list_free(result); 375 mailimap_fetch_list_free(result);
374 return body; 376 return body;
375} 377}
376 378
377/* this routine is just called when the mail has only ONE part. 379/* this routine is just called when the mail has only ONE part.
378 for filling the parts of a multi-part-message there are other 380 for filling the parts of a multi-part-message there are other
379 routines 'cause we can not simply fetch the whole body. */ 381 routines 'cause we can not simply fetch the whole body. */
380void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
381{ 383{
382 if (!mailDescription) { 384 if (!mailDescription) {
383 return; 385 return;
384 } 386 }
385 QString sub,body_text; 387 QString sub,body_text;
386 RecPart singlePart; 388 RecPart singlePart;
387 QValueList<int> path; 389 QValueList<int> path;
388 fillSinglePart(singlePart,mailDescription); 390 fillSinglePart(singlePart,mailDescription);
389 switch (mailDescription->bd_type) { 391 switch (mailDescription->bd_type) {
390 case MAILIMAP_BODY_TYPE_1PART_MSG: 392 case MAILIMAP_BODY_TYPE_1PART_MSG:
391 path.append(1); 393 path.append(1);
392 body_text = fetchPart(mail,path,true); 394 body_text = fetchPart(mail,path,true);
393 target_body.setBodytext(body_text); 395 target_body.setBodytext(body_text);
394 target_body.setDescription(singlePart); 396 target_body.setDescription(singlePart);
395 break; 397 break;
396 case MAILIMAP_BODY_TYPE_1PART_TEXT: 398 case MAILIMAP_BODY_TYPE_1PART_TEXT:
397 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 399 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
398 path.append(1); 400 path.append(1);
399 body_text = fetchPart(mail,path,true); 401 body_text = fetchPart(mail,path,true);
400 target_body.setBodytext(body_text); 402 target_body.setBodytext(body_text);
401 target_body.setDescription(singlePart); 403 target_body.setDescription(singlePart);
402 break; 404 break;
403 case MAILIMAP_BODY_TYPE_1PART_BASIC: 405 case MAILIMAP_BODY_TYPE_1PART_BASIC:
404 qDebug("Single attachment"); 406 qDebug("Single attachment");
405 target_body.setBodytext(""); 407 target_body.setBodytext("");
406 target_body.addPart(singlePart); 408 target_body.addPart(singlePart);
407 break; 409 break;
408 default: 410 default:
409 break; 411 break;
410 } 412 }
411 413
412 return; 414 return;
413} 415}
414 416
415QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 417QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
416{ 418{
417 QStringList l; 419 QStringList l;
418 QString from; 420 QString from;
419 bool named_from; 421 bool named_from;
420 clistcell *current = NULL; 422 clistcell *current = NULL;
421 mailimap_address * current_address=NULL; 423 mailimap_address * current_address=NULL;
422 if (!list) { 424 if (!list) {
423 return l; 425 return l;
424 } 426 }
425 unsigned int count = 0; 427 unsigned int count = 0;
426 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 428 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
427 from = ""; 429 from = "";
428 named_from = false; 430 named_from = false;
429 current_address=(mailimap_address*)current->data; 431 current_address=(mailimap_address*)current->data;
430 if (current_address->ad_personal_name){ 432 if (current_address->ad_personal_name){
431 from+=QString(current_address->ad_personal_name); 433 from+=QString(current_address->ad_personal_name);
432 from+=" "; 434 from+=" ";
433 named_from = true; 435 named_from = true;
434 } 436 }
435 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 437 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
436 from+="<"; 438 from+="<";
437 } 439 }
438 if (current_address->ad_mailbox_name) { 440 if (current_address->ad_mailbox_name) {
439 from+=QString(current_address->ad_mailbox_name); 441 from+=QString(current_address->ad_mailbox_name);
440 from+="@"; 442 from+="@";
441 } 443 }
442 if (current_address->ad_host_name) { 444 if (current_address->ad_host_name) {
443 from+=QString(current_address->ad_host_name); 445 from+=QString(current_address->ad_host_name);
444 } 446 }
445 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 447 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
446 from+=">"; 448 from+=">";
447 } 449 }
448 l.append(QString(from)); 450 l.append(QString(from));
449 if (++count > 99) { 451 if (++count > 99) {
450 break; 452 break;
451 } 453 }
452 } 454 }
453 return l; 455 return l;
454} 456}
455 457
456QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 458QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
457{ 459{
458 QString body(""); 460 QString body("");
459 const char*mb; 461 const char*mb;
460 int err; 462 int err;
461 mailimap_fetch_type *fetchType; 463 mailimap_fetch_type *fetchType;
462 mailimap_set *set; 464 mailimap_set *set;
463 clistcell*current,*cur; 465 clistcell*current,*cur;
464 466
465 login(); 467 login();
466 if (!m_imap) { 468 if (!m_imap) {
467 return body; 469 return body;
468 } 470 }
469 if (!internal_call) { 471 if (!internal_call) {
470 mb = mail.getMbox().latin1(); 472 mb = mail.getMbox().latin1();
471 err = mailimap_select( m_imap, (char*)mb); 473 err = mailimap_select( m_imap, (char*)mb);
472 if ( err != MAILIMAP_NO_ERROR ) { 474 if ( err != MAILIMAP_NO_ERROR ) {
473 qDebug("error selecting mailbox: %s",m_imap->imap_response); 475 qDebug("error selecting mailbox: %s",m_imap->imap_response);
474 return body; 476 return body;
475 } 477 }
476 } 478 }
477 set = mailimap_set_new_single(mail.getNumber()); 479 set = mailimap_set_new_single(mail.getNumber());
478 clist*id_list=clist_new(); 480 clist*id_list=clist_new();
479 for (unsigned j=0; j < path.count();++j) { 481 for (unsigned j=0; j < path.count();++j) {
480 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 482 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
481 *p_id = path[j]; 483 *p_id = path[j];
482 clist_append(id_list,p_id); 484 clist_append(id_list,p_id);
483 } 485 }
484 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 486 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
485 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 487 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
486 mailimap_section * section = mailimap_section_new(section_spec); 488 mailimap_section * section = mailimap_section_new(section_spec);
487 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 489 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
488 490
489 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 491 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
490 492
491 clist*result = clist_new(); 493 clist*result = clist_new();
492 494
493 err = mailimap_fetch( m_imap, set, fetchType, &result ); 495 err = mailimap_fetch( m_imap, set, fetchType, &result );
494 mailimap_set_free( set ); 496 mailimap_set_free( set );
495 mailimap_fetch_type_free( fetchType ); 497 mailimap_fetch_type_free( fetchType );
496 498
497 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 499 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
498 mailimap_msg_att * msg_att; 500 mailimap_msg_att * msg_att;
499 msg_att = (mailimap_msg_att*)current->data; 501 msg_att = (mailimap_msg_att*)current->data;
500 mailimap_msg_att_item*msg_att_item; 502 mailimap_msg_att_item*msg_att_item;
501 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 503 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
502 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 504 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
503 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 505 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
504 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 506 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
505 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 507 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
506 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 508 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
507 if (text) { 509 if (text) {
508 body = QString(text); 510 body = QString(text);
509 free(text); 511 free(text);
510 } else { 512 } else {
511 body = ""; 513 body = "";
512 } 514 }
513 } 515 }
514 } 516 }
515 } 517 }
516 518
517 } else { 519 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response); 520 qDebug("error fetching text: %s",m_imap->imap_response);
519 } 521 }
520 mailimap_fetch_list_free(result); 522 mailimap_fetch_list_free(result);
521 return body; 523 return body;
522} 524}
523 525
524void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 526void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
525{ 527{
526 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 528 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
527 if (!mailDescription||current_recursion==10) { 529 if (!mailDescription||current_recursion==10) {
528 return; 530 return;
529 } 531 }
530 clistcell*current; 532 clistcell*current;
531 mailimap_body*current_body; 533 mailimap_body*current_body;
532 unsigned int count = 0; 534 unsigned int count = 0;
533 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 535 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
534 /* the point in the message */ 536 /* the point in the message */
535 ++count; 537 ++count;
536 current_body = (mailimap_body*)current->data; 538 current_body = (mailimap_body*)current->data;
537 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 539 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
538 QValueList<int>clist = recList; 540 QValueList<int>clist = recList;
539 clist.append(count); 541 clist.append(count);
540 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 542 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
541 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 543 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
542 RecPart currentPart; 544 RecPart currentPart;
543 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 545 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
544 QValueList<int>clist = recList; 546 QValueList<int>clist = recList;
545 clist.append(count); 547 clist.append(count);
546 /* important: Check for is NULL 'cause a body can be empty! */ 548 /* important: Check for is NULL 'cause a body can be empty! */
547 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 549 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
548 QString body_text = fetchPart(mail,clist,true); 550 QString body_text = fetchPart(mail,clist,true);
549 target_body.setDescription(currentPart); 551 target_body.setDescription(currentPart);
550 target_body.setBodytext(body_text); 552 target_body.setBodytext(body_text);
551 } else { 553 } else {
552 QString id(""); 554 QString id("");
553 for (unsigned int j = 0; j < clist.count();++j) { 555 for (unsigned int j = 0; j < clist.count();++j) {
554 id+=(j>0?" ":""); 556 id+=(j>0?" ":"");
555 id+=QString("%1").arg(clist[j]); 557 id+=QString("%1").arg(clist[j]);
556 } 558 }
557 qDebug("ID= %s",id.latin1()); 559 qDebug("ID= %s",id.latin1());
558 currentPart.setIdentifier(id); 560 currentPart.setIdentifier(id);
559 currentPart.setPositionlist(clist); 561 currentPart.setPositionlist(clist);
560 target_body.addPart(currentPart); 562 target_body.addPart(currentPart);
561 } 563 }
562 } 564 }
563 } 565 }
564} 566}
565 567
566void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 568void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
567{ 569{
568 if (!Description) { 570 if (!Description) {
569 return; 571 return;
570 } 572 }
571 switch (Description->bd_type) { 573 switch (Description->bd_type) {
572 case MAILIMAP_BODY_TYPE_1PART_TEXT: 574 case MAILIMAP_BODY_TYPE_1PART_TEXT:
573 target_part.setType("text"); 575 target_part.setType("text");
574 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 576 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
575 break; 577 break;
576 case MAILIMAP_BODY_TYPE_1PART_BASIC: 578 case MAILIMAP_BODY_TYPE_1PART_BASIC:
577 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 579 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
578 break; 580 break;
579 case MAILIMAP_BODY_TYPE_1PART_MSG: 581 case MAILIMAP_BODY_TYPE_1PART_MSG:
580 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 582 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
581 break; 583 break;
582 default: 584 default:
583 break; 585 break;
584 } 586 }
585} 587}
586 588
587void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 589void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
588{ 590{
589 if (!which) { 591 if (!which) {
590 return; 592 return;
591 } 593 }
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index b253b49..0ce2c6c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,591 +1,593 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
7 7
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 9 : AbstractMail()
10{ 10{
11 account = a; 11 account = a;
12 m_imap = 0; 12 m_imap = 0;
13} 13}
14 14
15IMAPwrapper::~IMAPwrapper() 15IMAPwrapper::~IMAPwrapper()
16{ 16{
17 logout(); 17 logout();
18} 18}
19 19
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 20void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 21{
22 qDebug( "IMAP: %i of %i", current, maximum ); 22 qDebug( "IMAP: %i of %i", current, maximum );
23} 23}
24 24
25void IMAPwrapper::login() 25void IMAPwrapper::login()
26{ 26{
27 const char *server, *user, *pass; 27 const char *server, *user, *pass;
28 uint16_t port; 28 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
30 30
31 /* we are connected this moment */ 31 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 32 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 33 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 34 mailstream_flush(m_imap->imap_stream);
35 return; 35 return;
36 } 36 }
37 server = account->getServer().latin1(); 37 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 38 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 39 user = account->getUser().latin1();
40 pass = account->getPassword().latin1(); 40 pass = account->getPassword().latin1();
41 41
42 m_imap = mailimap_new( 20, &imap_progress ); 42 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 43 /* connect */
44 if (account->getSSL()) { 44 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 45 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 46 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 47 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 48 }
49 49
50 if ( err != MAILIMAP_NO_ERROR && 50 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 51 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 53 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 54 mailimap_free( m_imap );
55 m_imap = 0; 55 m_imap = 0;
56 return; 56 return;
57 } 57 }
58 58
59 /* login */ 59 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 61 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 62 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
65 m_imap = 0; 65 m_imap = 0;
66 } 66 }
67} 67}
68 68
69void IMAPwrapper::logout() 69void IMAPwrapper::logout()
70{ 70{
71 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 72 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 73 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 74 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 75 mailimap_free( m_imap );
76 m_imap = 0; 76 m_imap = 0;
77} 77}
78 78
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 80{
81 const char *mb; 81 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 82 int err = MAILIMAP_NO_ERROR;
83 clist *result; 83 clist *result;
84 clistcell *current; 84 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 86 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 87 mailimap_set *set;
88 88
89 mb = mailbox.latin1(); 89 mb = mailbox.latin1();
90 login(); 90 login();
91 if (!m_imap) { 91 if (!m_imap) {
92 return; 92 return;
93 } 93 }
94 /* select mailbox READONLY for operations */ 94 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 95 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 96 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 97 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 98 return;
99 } 99 }
100 100
101 int last = m_imap->imap_selection_info->sel_exists; 101 int last = m_imap->imap_selection_info->sel_exists;
102 102
103 if (last == 0) { 103 if (last == 0) {
104 qDebug("mailbox has no mails"); 104 qDebug("mailbox has no mails");
105 return; 105 return;
106 } 106 }
107 107
108 result = clist_new(); 108 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 109 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 110 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 116
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 117 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 118 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 119 mailimap_fetch_type_free( fetchType );
120 120
121 QString date,subject,from; 121 QString date,subject,from;
122 122
123 if ( err == MAILIMAP_NO_ERROR ) { 123 if ( err == MAILIMAP_NO_ERROR ) {
124 124
125 mailimap_msg_att * msg_att; 125 mailimap_msg_att * msg_att;
126 int i = 0; 126 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 127 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 128 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 129 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 130 RecMail*m = parse_list_result(msg_att);
131 if (m) { 131 if (m) {
132 m->setNumber(i); 132 m->setNumber(i);
133 m->setMbox(mailbox); 133 m->setMbox(mailbox);
134 m->setWrapper(this); 134 m->setWrapper(this);
135 target.append(m); 135 target.append(m);
136 } 136 }
137 } 137 }
138 } else { 138 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 139 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 140 }
141 mailimap_fetch_list_free(result); 141 mailimap_fetch_list_free(result);
142} 142}
143 143
144QList<Folder>* IMAPwrapper::listFolders() 144QList<Folder>* IMAPwrapper::listFolders()
145{ 145{
146 const char *path, *mask; 146 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 147 int err = MAILIMAP_NO_ERROR;
148 clist *result; 148 clist *result;
149 clistcell *current; 149 clistcell *current;
150 150
151 QList<Folder> * folders = new QList<Folder>(); 151 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 152 folders->setAutoDelete( false );
153 login(); 153 login();
154 if (!m_imap) { 154 if (!m_imap) {
155 return folders; 155 return folders;
156 } 156 }
157 157
158/* 158/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 159 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 160 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 161 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 162 */
163 QString temp; 163 QString temp;
164 mask = "INBOX" ; 164 mask = "INBOX" ;
165 result = clist_new(); 165 result = clist_new();
166 mailimap_mailbox_list *list; 166 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 if ( err == MAILIMAP_NO_ERROR ) { 168 if ( err == MAILIMAP_NO_ERROR ) {
169 current = result->first; 169 current = result->first;
170 for ( int i = result->count; i > 0; i-- ) { 170 for ( int i = result->count; i > 0; i-- ) {
171 list = (mailimap_mailbox_list *) current->data; 171 list = (mailimap_mailbox_list *) current->data;
172 // it is better use the deep copy mechanism of qt itself 172 // it is better use the deep copy mechanism of qt itself
173 // instead of using strdup! 173 // instead of using strdup!
174 temp = list->mb_name; 174 temp = list->mb_name;
175 folders->append( new IMAPFolder(temp)); 175 folders->append( new IMAPFolder(temp));
176 current = current->next; 176 current = current->next;
177 } 177 }
178 } else { 178 } else {
179 qDebug("error fetching folders: %s",m_imap->imap_response); 179 qDebug("error fetching folders: %s",m_imap->imap_response);
180 } 180 }
181 mailimap_list_result_free( result ); 181 mailimap_list_result_free( result );
182 182
183/* 183/*
184 * second stage - get the other then inbox folders 184 * second stage - get the other then inbox folders
185 */ 185 */
186 mask = "*" ; 186 mask = "*" ;
187 path = account->getPrefix().latin1(); 187 path = account->getPrefix().latin1();
188 if (!path) path = ""; 188 if (!path) path = "";
189 result = clist_new(); 189 result = clist_new();
190 qDebug(path); 190 qDebug(path);
191 bool selectable = true; 191 bool selectable = true;
192 mailimap_mbx_list_flags*bflags; 192 mailimap_mbx_list_flags*bflags;
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 194 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 195 current = result->first;
196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 196 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
197 list = (mailimap_mailbox_list *) current->data; 197 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 198 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 199 // instead of using strdup!
200 temp = list->mb_name; 200 temp = list->mb_name;
201 if (temp.lower()=="inbox") 201 if (temp.lower()=="inbox")
202 continue; 202 continue;
203 if (temp.lower()==account->getPrefix().lower())
204 continue;
203 if ( (bflags = list->mb_flag) ) { 205 if ( (bflags = list->mb_flag) ) {
204 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 206 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
205 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 207 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
206 } 208 }
207 folders->append(new IMAPFolder(temp,selectable)); 209 folders->append(new IMAPFolder(temp,selectable,account->getPrefix()));
208 } 210 }
209 } else { 211 } else {
210 qDebug("error fetching folders %s",m_imap->imap_response); 212 qDebug("error fetching folders %s",m_imap->imap_response);
211 } 213 }
212 mailimap_list_result_free( result ); 214 mailimap_list_result_free( result );
213 return folders; 215 return folders;
214} 216}
215 217
216RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 218RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
217{ 219{
218 RecMail * m = 0; 220 RecMail * m = 0;
219 mailimap_msg_att_item *item=0; 221 mailimap_msg_att_item *item=0;
220 clistcell *current,*c,*cf; 222 clistcell *current,*c,*cf;
221 mailimap_msg_att_dynamic*flist; 223 mailimap_msg_att_dynamic*flist;
222 mailimap_flag_fetch*cflag; 224 mailimap_flag_fetch*cflag;
223 int size; 225 int size;
224 QBitArray mFlags(7); 226 QBitArray mFlags(7);
225 QStringList addresslist; 227 QStringList addresslist;
226 228
227 if (!m_att) { 229 if (!m_att) {
228 return m; 230 return m;
229 } 231 }
230 m = new RecMail(); 232 m = new RecMail();
231 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 233 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
232 current = c; 234 current = c;
233 size = 0; 235 size = 0;
234 item = (mailimap_msg_att_item*)current->data; 236 item = (mailimap_msg_att_item*)current->data;
235 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 237 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
236 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 238 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
237 if (!flist->att_list) { 239 if (!flist->att_list) {
238 continue; 240 continue;
239 } 241 }
240 cf = flist->att_list->first; 242 cf = flist->att_list->first;
241 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 243 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
242 cflag = (mailimap_flag_fetch*)cf->data; 244 cflag = (mailimap_flag_fetch*)cf->data;
243 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 245 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
244 switch (cflag->fl_flag->fl_type) { 246 switch (cflag->fl_flag->fl_type) {
245 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 247 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
246 mFlags.setBit(FLAG_ANSWERED); 248 mFlags.setBit(FLAG_ANSWERED);
247 break; 249 break;
248 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 250 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
249 mFlags.setBit(FLAG_FLAGGED); 251 mFlags.setBit(FLAG_FLAGGED);
250 break; 252 break;
251 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 253 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
252 mFlags.setBit(FLAG_DELETED); 254 mFlags.setBit(FLAG_DELETED);
253 break; 255 break;
254 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 256 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
255 mFlags.setBit(FLAG_SEEN); 257 mFlags.setBit(FLAG_SEEN);
256 break; 258 break;
257 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 259 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
258 mFlags.setBit(FLAG_DRAFT); 260 mFlags.setBit(FLAG_DRAFT);
259 break; 261 break;
260 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 262 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
261 break; 263 break;
262 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 264 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
263 break; 265 break;
264 default: 266 default:
265 break; 267 break;
266 } 268 }
267 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 269 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
268 mFlags.setBit(FLAG_RECENT); 270 mFlags.setBit(FLAG_RECENT);
269 } 271 }
270 } 272 }
271 continue; 273 continue;
272 } 274 }
273 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
274 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
275 m->setDate(head->env_date); 277 m->setDate(head->env_date);
276 m->setSubject(head->env_subject); 278 m->setSubject(head->env_subject);
277 if (head->env_from!=NULL) { 279 if (head->env_from!=NULL) {
278 addresslist = address_list_to_stringlist(head->env_from->frm_list); 280 addresslist = address_list_to_stringlist(head->env_from->frm_list);
279 if (addresslist.count()) { 281 if (addresslist.count()) {
280 m->setFrom(addresslist.first()); 282 m->setFrom(addresslist.first());
281 } 283 }
282 } 284 }
283 if (head->env_to!=NULL) { 285 if (head->env_to!=NULL) {
284 addresslist = address_list_to_stringlist(head->env_to->to_list); 286 addresslist = address_list_to_stringlist(head->env_to->to_list);
285 m->setTo(addresslist); 287 m->setTo(addresslist);
286 } 288 }
287 if (head->env_cc!=NULL) { 289 if (head->env_cc!=NULL) {
288 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 290 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
289 m->setCC(addresslist); 291 m->setCC(addresslist);
290 } 292 }
291 if (head->env_bcc!=NULL) { 293 if (head->env_bcc!=NULL) {
292 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
293 m->setBcc(addresslist); 295 m->setBcc(addresslist);
294 } 296 }
295 if (head->env_reply_to!=NULL) { 297 if (head->env_reply_to!=NULL) {
296 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
297 if (addresslist.count()) { 299 if (addresslist.count()) {
298 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
299 } 301 }
300 } 302 }
301 m->setMsgid(QString(head->env_message_id)); 303 m->setMsgid(QString(head->env_message_id));
302 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
303 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
304#if 0 306#if 0
305 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
306 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
307 qDebug(da.toString()); 309 qDebug(da.toString());
308#endif 310#endif
309 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
310 size = item->att_data.att_static->att_data.att_rfc822_size; 312 size = item->att_data.att_static->att_data.att_rfc822_size;
311 } 313 }
312 } 314 }
313 /* msg is already deleted */ 315 /* msg is already deleted */
314 if (mFlags.testBit(FLAG_DELETED) && m) { 316 if (mFlags.testBit(FLAG_DELETED) && m) {
315 delete m; 317 delete m;
316 m = 0; 318 m = 0;
317 } 319 }
318 if (m) { 320 if (m) {
319 m->setFlags(mFlags); 321 m->setFlags(mFlags);
320 m->setMsgsize(size); 322 m->setMsgsize(size);
321 } 323 }
322 return m; 324 return m;
323} 325}
324 326
325RecBody IMAPwrapper::fetchBody(const RecMail&mail) 327RecBody IMAPwrapper::fetchBody(const RecMail&mail)
326{ 328{
327 RecBody body; 329 RecBody body;
328 const char *mb; 330 const char *mb;
329 int err = MAILIMAP_NO_ERROR; 331 int err = MAILIMAP_NO_ERROR;
330 clist *result; 332 clist *result;
331 clistcell *current; 333 clistcell *current;
332 mailimap_fetch_att *fetchAtt; 334 mailimap_fetch_att *fetchAtt;
333 mailimap_fetch_type *fetchType; 335 mailimap_fetch_type *fetchType;
334 mailimap_set *set; 336 mailimap_set *set;
335 mailimap_body*body_desc; 337 mailimap_body*body_desc;
336 338
337 mb = mail.getMbox().latin1(); 339 mb = mail.getMbox().latin1();
338 340
339 login(); 341 login();
340 if (!m_imap) { 342 if (!m_imap) {
341 return body; 343 return body;
342 } 344 }
343 345
344 err = mailimap_select( m_imap, (char*)mb); 346 err = mailimap_select( m_imap, (char*)mb);
345 if ( err != MAILIMAP_NO_ERROR ) { 347 if ( err != MAILIMAP_NO_ERROR ) {
346 qDebug("error selecting mailbox: %s",m_imap->imap_response); 348 qDebug("error selecting mailbox: %s",m_imap->imap_response);
347 return body; 349 return body;
348 } 350 }
349 351
350 result = clist_new(); 352 result = clist_new();
351 /* the range has to start at 1!!! not with 0!!!! */ 353 /* the range has to start at 1!!! not with 0!!!! */
352 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
353 fetchAtt = mailimap_fetch_att_new_bodystructure(); 355 fetchAtt = mailimap_fetch_att_new_bodystructure();
354 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
355 err = mailimap_fetch( m_imap, set, fetchType, &result ); 357 err = mailimap_fetch( m_imap, set, fetchType, &result );
356 mailimap_set_free( set ); 358 mailimap_set_free( set );
357 mailimap_fetch_type_free( fetchType ); 359 mailimap_fetch_type_free( fetchType );
358 360
359 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
360 mailimap_msg_att * msg_att; 362 mailimap_msg_att * msg_att;
361 msg_att = (mailimap_msg_att*)current->data; 363 msg_att = (mailimap_msg_att*)current->data;
362 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
363 body_desc = item->att_data.att_static->att_data.att_body; 365 body_desc = item->att_data.att_static->att_data.att_body;
364 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 366 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
365 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 367 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
366 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 368 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
367 qDebug("Mulitpart mail"); 369 qDebug("Mulitpart mail");
368 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 370 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
369 } 371 }
370 } else { 372 } else {
371 qDebug("error fetching body: %s",m_imap->imap_response); 373 qDebug("error fetching body: %s",m_imap->imap_response);
372 } 374 }
373 mailimap_fetch_list_free(result); 375 mailimap_fetch_list_free(result);
374 return body; 376 return body;
375} 377}
376 378
377/* this routine is just called when the mail has only ONE part. 379/* this routine is just called when the mail has only ONE part.
378 for filling the parts of a multi-part-message there are other 380 for filling the parts of a multi-part-message there are other
379 routines 'cause we can not simply fetch the whole body. */ 381 routines 'cause we can not simply fetch the whole body. */
380void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
381{ 383{
382 if (!mailDescription) { 384 if (!mailDescription) {
383 return; 385 return;
384 } 386 }
385 QString sub,body_text; 387 QString sub,body_text;
386 RecPart singlePart; 388 RecPart singlePart;
387 QValueList<int> path; 389 QValueList<int> path;
388 fillSinglePart(singlePart,mailDescription); 390 fillSinglePart(singlePart,mailDescription);
389 switch (mailDescription->bd_type) { 391 switch (mailDescription->bd_type) {
390 case MAILIMAP_BODY_TYPE_1PART_MSG: 392 case MAILIMAP_BODY_TYPE_1PART_MSG:
391 path.append(1); 393 path.append(1);
392 body_text = fetchPart(mail,path,true); 394 body_text = fetchPart(mail,path,true);
393 target_body.setBodytext(body_text); 395 target_body.setBodytext(body_text);
394 target_body.setDescription(singlePart); 396 target_body.setDescription(singlePart);
395 break; 397 break;
396 case MAILIMAP_BODY_TYPE_1PART_TEXT: 398 case MAILIMAP_BODY_TYPE_1PART_TEXT:
397 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 399 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
398 path.append(1); 400 path.append(1);
399 body_text = fetchPart(mail,path,true); 401 body_text = fetchPart(mail,path,true);
400 target_body.setBodytext(body_text); 402 target_body.setBodytext(body_text);
401 target_body.setDescription(singlePart); 403 target_body.setDescription(singlePart);
402 break; 404 break;
403 case MAILIMAP_BODY_TYPE_1PART_BASIC: 405 case MAILIMAP_BODY_TYPE_1PART_BASIC:
404 qDebug("Single attachment"); 406 qDebug("Single attachment");
405 target_body.setBodytext(""); 407 target_body.setBodytext("");
406 target_body.addPart(singlePart); 408 target_body.addPart(singlePart);
407 break; 409 break;
408 default: 410 default:
409 break; 411 break;
410 } 412 }
411 413
412 return; 414 return;
413} 415}
414 416
415QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 417QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
416{ 418{
417 QStringList l; 419 QStringList l;
418 QString from; 420 QString from;
419 bool named_from; 421 bool named_from;
420 clistcell *current = NULL; 422 clistcell *current = NULL;
421 mailimap_address * current_address=NULL; 423 mailimap_address * current_address=NULL;
422 if (!list) { 424 if (!list) {
423 return l; 425 return l;
424 } 426 }
425 unsigned int count = 0; 427 unsigned int count = 0;
426 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 428 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
427 from = ""; 429 from = "";
428 named_from = false; 430 named_from = false;
429 current_address=(mailimap_address*)current->data; 431 current_address=(mailimap_address*)current->data;
430 if (current_address->ad_personal_name){ 432 if (current_address->ad_personal_name){
431 from+=QString(current_address->ad_personal_name); 433 from+=QString(current_address->ad_personal_name);
432 from+=" "; 434 from+=" ";
433 named_from = true; 435 named_from = true;
434 } 436 }
435 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 437 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
436 from+="<"; 438 from+="<";
437 } 439 }
438 if (current_address->ad_mailbox_name) { 440 if (current_address->ad_mailbox_name) {
439 from+=QString(current_address->ad_mailbox_name); 441 from+=QString(current_address->ad_mailbox_name);
440 from+="@"; 442 from+="@";
441 } 443 }
442 if (current_address->ad_host_name) { 444 if (current_address->ad_host_name) {
443 from+=QString(current_address->ad_host_name); 445 from+=QString(current_address->ad_host_name);
444 } 446 }
445 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 447 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
446 from+=">"; 448 from+=">";
447 } 449 }
448 l.append(QString(from)); 450 l.append(QString(from));
449 if (++count > 99) { 451 if (++count > 99) {
450 break; 452 break;
451 } 453 }
452 } 454 }
453 return l; 455 return l;
454} 456}
455 457
456QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 458QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
457{ 459{
458 QString body(""); 460 QString body("");
459 const char*mb; 461 const char*mb;
460 int err; 462 int err;
461 mailimap_fetch_type *fetchType; 463 mailimap_fetch_type *fetchType;
462 mailimap_set *set; 464 mailimap_set *set;
463 clistcell*current,*cur; 465 clistcell*current,*cur;
464 466
465 login(); 467 login();
466 if (!m_imap) { 468 if (!m_imap) {
467 return body; 469 return body;
468 } 470 }
469 if (!internal_call) { 471 if (!internal_call) {
470 mb = mail.getMbox().latin1(); 472 mb = mail.getMbox().latin1();
471 err = mailimap_select( m_imap, (char*)mb); 473 err = mailimap_select( m_imap, (char*)mb);
472 if ( err != MAILIMAP_NO_ERROR ) { 474 if ( err != MAILIMAP_NO_ERROR ) {
473 qDebug("error selecting mailbox: %s",m_imap->imap_response); 475 qDebug("error selecting mailbox: %s",m_imap->imap_response);
474 return body; 476 return body;
475 } 477 }
476 } 478 }
477 set = mailimap_set_new_single(mail.getNumber()); 479 set = mailimap_set_new_single(mail.getNumber());
478 clist*id_list=clist_new(); 480 clist*id_list=clist_new();
479 for (unsigned j=0; j < path.count();++j) { 481 for (unsigned j=0; j < path.count();++j) {
480 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 482 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
481 *p_id = path[j]; 483 *p_id = path[j];
482 clist_append(id_list,p_id); 484 clist_append(id_list,p_id);
483 } 485 }
484 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 486 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
485 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 487 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
486 mailimap_section * section = mailimap_section_new(section_spec); 488 mailimap_section * section = mailimap_section_new(section_spec);
487 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 489 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
488 490
489 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 491 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
490 492
491 clist*result = clist_new(); 493 clist*result = clist_new();
492 494
493 err = mailimap_fetch( m_imap, set, fetchType, &result ); 495 err = mailimap_fetch( m_imap, set, fetchType, &result );
494 mailimap_set_free( set ); 496 mailimap_set_free( set );
495 mailimap_fetch_type_free( fetchType ); 497 mailimap_fetch_type_free( fetchType );
496 498
497 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 499 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
498 mailimap_msg_att * msg_att; 500 mailimap_msg_att * msg_att;
499 msg_att = (mailimap_msg_att*)current->data; 501 msg_att = (mailimap_msg_att*)current->data;
500 mailimap_msg_att_item*msg_att_item; 502 mailimap_msg_att_item*msg_att_item;
501 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 503 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
502 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 504 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
503 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 505 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
504 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 506 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
505 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 507 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
506 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 508 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
507 if (text) { 509 if (text) {
508 body = QString(text); 510 body = QString(text);
509 free(text); 511 free(text);
510 } else { 512 } else {
511 body = ""; 513 body = "";
512 } 514 }
513 } 515 }
514 } 516 }
515 } 517 }
516 518
517 } else { 519 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response); 520 qDebug("error fetching text: %s",m_imap->imap_response);
519 } 521 }
520 mailimap_fetch_list_free(result); 522 mailimap_fetch_list_free(result);
521 return body; 523 return body;
522} 524}
523 525
524void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 526void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
525{ 527{
526 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 528 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
527 if (!mailDescription||current_recursion==10) { 529 if (!mailDescription||current_recursion==10) {
528 return; 530 return;
529 } 531 }
530 clistcell*current; 532 clistcell*current;
531 mailimap_body*current_body; 533 mailimap_body*current_body;
532 unsigned int count = 0; 534 unsigned int count = 0;
533 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 535 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
534 /* the point in the message */ 536 /* the point in the message */
535 ++count; 537 ++count;
536 current_body = (mailimap_body*)current->data; 538 current_body = (mailimap_body*)current->data;
537 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 539 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
538 QValueList<int>clist = recList; 540 QValueList<int>clist = recList;
539 clist.append(count); 541 clist.append(count);
540 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 542 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
541 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 543 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
542 RecPart currentPart; 544 RecPart currentPart;
543 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 545 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
544 QValueList<int>clist = recList; 546 QValueList<int>clist = recList;
545 clist.append(count); 547 clist.append(count);
546 /* important: Check for is NULL 'cause a body can be empty! */ 548 /* important: Check for is NULL 'cause a body can be empty! */
547 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 549 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
548 QString body_text = fetchPart(mail,clist,true); 550 QString body_text = fetchPart(mail,clist,true);
549 target_body.setDescription(currentPart); 551 target_body.setDescription(currentPart);
550 target_body.setBodytext(body_text); 552 target_body.setBodytext(body_text);
551 } else { 553 } else {
552 QString id(""); 554 QString id("");
553 for (unsigned int j = 0; j < clist.count();++j) { 555 for (unsigned int j = 0; j < clist.count();++j) {
554 id+=(j>0?" ":""); 556 id+=(j>0?" ":"");
555 id+=QString("%1").arg(clist[j]); 557 id+=QString("%1").arg(clist[j]);
556 } 558 }
557 qDebug("ID= %s",id.latin1()); 559 qDebug("ID= %s",id.latin1());
558 currentPart.setIdentifier(id); 560 currentPart.setIdentifier(id);
559 currentPart.setPositionlist(clist); 561 currentPart.setPositionlist(clist);
560 target_body.addPart(currentPart); 562 target_body.addPart(currentPart);
561 } 563 }
562 } 564 }
563 } 565 }
564} 566}
565 567
566void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 568void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
567{ 569{
568 if (!Description) { 570 if (!Description) {
569 return; 571 return;
570 } 572 }
571 switch (Description->bd_type) { 573 switch (Description->bd_type) {
572 case MAILIMAP_BODY_TYPE_1PART_TEXT: 574 case MAILIMAP_BODY_TYPE_1PART_TEXT:
573 target_part.setType("text"); 575 target_part.setType("text");
574 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 576 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
575 break; 577 break;
576 case MAILIMAP_BODY_TYPE_1PART_BASIC: 578 case MAILIMAP_BODY_TYPE_1PART_BASIC:
577 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 579 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
578 break; 580 break;
579 case MAILIMAP_BODY_TYPE_1PART_MSG: 581 case MAILIMAP_BODY_TYPE_1PART_MSG:
580 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 582 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
581 break; 583 break;
582 default: 584 default:
583 break; 585 break;
584 } 586 }
585} 587}
586 588
587void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 589void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
588{ 590{
589 if (!which) { 591 if (!which) {
590 return; 592 return;
591 } 593 }
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 3ffc274..96602c2 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -1,424 +1,434 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8 8
9#include "mailwrapper.h" 9#include "mailwrapper.h"
10#include "logindialog.h" 10#include "logindialog.h"
11//#include "mail.h" 11//#include "mail.h"
12#include "defines.h" 12#include "defines.h"
13 13
14Attachment::Attachment( DocLnk lnk ) 14Attachment::Attachment( DocLnk lnk )
15{ 15{
16 doc = lnk; 16 doc = lnk;
17 size = QFileInfo( doc.file() ).size(); 17 size = QFileInfo( doc.file() ).size();
18} 18}
19 19
20Folder::Folder(const QString&tmp_name ) 20Folder::Folder(const QString&tmp_name )
21{ 21{
22 name = tmp_name; 22 name = tmp_name;
23 nameDisplay = name; 23 nameDisplay = name;
24 24
25 for ( int pos = nameDisplay.find( '&' ); pos != -1; 25 for ( int pos = nameDisplay.find( '&' ); pos != -1;
26 pos = nameDisplay.find( '&' ) ) { 26 pos = nameDisplay.find( '&' ) ) {
27 int end = nameDisplay.find( '-' ); 27 int end = nameDisplay.find( '-' );
28 if ( end == -1 || end <= pos ) break; 28 if ( end == -1 || end <= pos ) break;
29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); 29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
30 // TODO: do real base64 decoding here ! 30 // TODO: do real base64 decoding here !
31 if ( str64.compare( "APw" ) == 0 ) { 31 if ( str64.compare( "APw" ) == 0 ) {
32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); 32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
33 } else if ( str64.compare( "APY" ) == 0 ) { 33 } else if ( str64.compare( "APY" ) == 0 ) {
34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); 34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
35 } 35 }
36 } 36 }
37
38 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
39} 38}
40 39
40
41IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix )
42 : Folder( name ),m_MaySelect(select)
43{
44 if (prefix.length()>0) {
45 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
46 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
47 }
48 }
49}
50
41MailWrapper::MailWrapper( Settings *s ) 51MailWrapper::MailWrapper( Settings *s )
42 : QObject() 52 : QObject()
43{ 53{
44 settings = s; 54 settings = s;
45} 55}
46 56
47QString MailWrapper::mailsmtpError( int errnum ) 57QString MailWrapper::mailsmtpError( int errnum )
48{ 58{
49 switch ( errnum ) { 59 switch ( errnum ) {
50 case MAILSMTP_NO_ERROR: 60 case MAILSMTP_NO_ERROR:
51 return tr( "No error" ); 61 return tr( "No error" );
52 case MAILSMTP_ERROR_UNEXPECTED_CODE: 62 case MAILSMTP_ERROR_UNEXPECTED_CODE:
53 return tr( "Unexpected error code" ); 63 return tr( "Unexpected error code" );
54 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 64 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
55 return tr( "Service not available" ); 65 return tr( "Service not available" );
56 case MAILSMTP_ERROR_STREAM: 66 case MAILSMTP_ERROR_STREAM:
57 return tr( "Stream error" ); 67 return tr( "Stream error" );
58 case MAILSMTP_ERROR_HOSTNAME: 68 case MAILSMTP_ERROR_HOSTNAME:
59 return tr( "gethostname() failed" ); 69 return tr( "gethostname() failed" );
60 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 70 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
61 return tr( "Not implemented" ); 71 return tr( "Not implemented" );
62 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 72 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
63 return tr( "Error, action not taken" ); 73 return tr( "Error, action not taken" );
64 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 74 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
65 return tr( "Data exceeds storage allocation" ); 75 return tr( "Data exceeds storage allocation" );
66 case MAILSMTP_ERROR_IN_PROCESSING: 76 case MAILSMTP_ERROR_IN_PROCESSING:
67 return tr( "Error in processing" ); 77 return tr( "Error in processing" );
68 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 78 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
69 // return tr( "Insufficient system storage" ); 79 // return tr( "Insufficient system storage" );
70 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 80 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
71 return tr( "Mailbox unavailable" ); 81 return tr( "Mailbox unavailable" );
72 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 82 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
73 return tr( "Mailbox name not allowed" ); 83 return tr( "Mailbox name not allowed" );
74 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 84 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
75 return tr( "Bad command sequence" ); 85 return tr( "Bad command sequence" );
76 case MAILSMTP_ERROR_USER_NOT_LOCAL: 86 case MAILSMTP_ERROR_USER_NOT_LOCAL:
77 return tr( "User not local" ); 87 return tr( "User not local" );
78 case MAILSMTP_ERROR_TRANSACTION_FAILED: 88 case MAILSMTP_ERROR_TRANSACTION_FAILED:
79 return tr( "Transaction failed" ); 89 return tr( "Transaction failed" );
80 case MAILSMTP_ERROR_MEMORY: 90 case MAILSMTP_ERROR_MEMORY:
81 return tr( "Memory error" ); 91 return tr( "Memory error" );
82 case MAILSMTP_ERROR_CONNECTION_REFUSED: 92 case MAILSMTP_ERROR_CONNECTION_REFUSED:
83 return tr( "Connection refused" ); 93 return tr( "Connection refused" );
84 default: 94 default:
85 return tr( "Unknown error code" ); 95 return tr( "Unknown error code" );
86 } 96 }
87} 97}
88 98
89mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) 99mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
90{ 100{
91 return mailimf_mailbox_new( strdup( name.latin1() ), 101 return mailimf_mailbox_new( strdup( name.latin1() ),
92 strdup( mail.latin1() ) ); 102 strdup( mail.latin1() ) );
93} 103}
94 104
95mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) 105mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
96{ 106{
97 mailimf_address_list *addresses; 107 mailimf_address_list *addresses;
98 108
99 if ( addr.isEmpty() ) return NULL; 109 if ( addr.isEmpty() ) return NULL;
100 110
101 addresses = mailimf_address_list_new_empty(); 111 addresses = mailimf_address_list_new_empty();
102 112
103 QStringList list = QStringList::split( ',', addr ); 113 QStringList list = QStringList::split( ',', addr );
104 QStringList::Iterator it; 114 QStringList::Iterator it;
105 for ( it = list.begin(); it != list.end(); it++ ) { 115 for ( it = list.begin(); it != list.end(); it++ ) {
106 char *str = strdup( (*it).latin1() ); 116 char *str = strdup( (*it).latin1() );
107 int err = mailimf_address_list_add_parse( addresses, str ); 117 int err = mailimf_address_list_add_parse( addresses, str );
108 if ( err != MAILIMF_NO_ERROR ) { 118 if ( err != MAILIMF_NO_ERROR ) {
109 qDebug( "Error parsing" ); 119 qDebug( "Error parsing" );
110 qDebug( *it ); 120 qDebug( *it );
111 free( str ); 121 free( str );
112 } else { 122 } else {
113 qDebug( "Parse success! :)" ); 123 qDebug( "Parse success! :)" );
114 } 124 }
115 } 125 }
116 126
117 return addresses; 127 return addresses;
118} 128}
119 129
120mailimf_fields *MailWrapper::createImfFields( Mail *mail ) 130mailimf_fields *MailWrapper::createImfFields( Mail *mail )
121{ 131{
122 mailimf_fields *fields; 132 mailimf_fields *fields;
123 mailimf_field *xmailer; 133 mailimf_field *xmailer;
124 mailimf_mailbox *sender, *fromBox; 134 mailimf_mailbox *sender, *fromBox;
125 mailimf_mailbox_list *from; 135 mailimf_mailbox_list *from;
126 mailimf_address_list *to, *cc, *bcc, *reply; 136 mailimf_address_list *to, *cc, *bcc, *reply;
127 char *subject = strdup( mail->getSubject().latin1() ); 137 char *subject = strdup( mail->getSubject().latin1() );
128 int err; 138 int err;
129 139
130 sender = newMailbox( mail->getName(), mail->getMail() ); 140 sender = newMailbox( mail->getName(), mail->getMail() );
131 if ( sender == NULL ) goto err_free; 141 if ( sender == NULL ) goto err_free;
132 142
133 fromBox = newMailbox( mail->getName(), mail->getMail() ); 143 fromBox = newMailbox( mail->getName(), mail->getMail() );
134 if ( fromBox == NULL ) goto err_free_sender; 144 if ( fromBox == NULL ) goto err_free_sender;
135 145
136 from = mailimf_mailbox_list_new_empty(); 146 from = mailimf_mailbox_list_new_empty();
137 if ( from == NULL ) goto err_free_fromBox; 147 if ( from == NULL ) goto err_free_fromBox;
138 148
139 err = mailimf_mailbox_list_add( from, fromBox ); 149 err = mailimf_mailbox_list_add( from, fromBox );
140 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 150 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
141 151
142 to = parseAddresses( mail->getTo() ); 152 to = parseAddresses( mail->getTo() );
143 if ( to == NULL ) goto err_free_from; 153 if ( to == NULL ) goto err_free_from;
144 154
145 cc = parseAddresses( mail->getCC() ); 155 cc = parseAddresses( mail->getCC() );
146 bcc = parseAddresses( mail->getBCC() ); 156 bcc = parseAddresses( mail->getBCC() );
147 reply = parseAddresses( mail->getReply() ); 157 reply = parseAddresses( mail->getReply() );
148 158
149 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 159 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
150 NULL, NULL, subject ); 160 NULL, NULL, subject );
151 if ( fields == NULL ) goto err_free_reply; 161 if ( fields == NULL ) goto err_free_reply;
152 162
153 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 163 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
154 strdup( USER_AGENT ) ); 164 strdup( USER_AGENT ) );
155 if ( xmailer == NULL ) goto err_free_fields; 165 if ( xmailer == NULL ) goto err_free_fields;
156 166
157 err = mailimf_fields_add( fields, xmailer ); 167 err = mailimf_fields_add( fields, xmailer );
158 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 168 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
159 169
160 return fields; // Success :) 170 return fields; // Success :)
161 171
162err_free_xmailer: 172err_free_xmailer:
163 mailimf_field_free( xmailer ); 173 mailimf_field_free( xmailer );
164err_free_fields: 174err_free_fields:
165 mailimf_fields_free( fields ); 175 mailimf_fields_free( fields );
166err_free_reply: 176err_free_reply:
167 mailimf_address_list_free( reply ); 177 mailimf_address_list_free( reply );
168 mailimf_address_list_free( bcc ); 178 mailimf_address_list_free( bcc );
169 mailimf_address_list_free( cc ); 179 mailimf_address_list_free( cc );
170 mailimf_address_list_free( to ); 180 mailimf_address_list_free( to );
171err_free_from: 181err_free_from:
172 mailimf_mailbox_list_free( from ); 182 mailimf_mailbox_list_free( from );
173err_free_fromBox: 183err_free_fromBox:
174 mailimf_mailbox_free( fromBox ); 184 mailimf_mailbox_free( fromBox );
175err_free_sender: 185err_free_sender:
176 mailimf_mailbox_free( sender ); 186 mailimf_mailbox_free( sender );
177err_free: 187err_free:
178 free( subject ); 188 free( subject );
179 qDebug( "createImfFields - error" ); 189 qDebug( "createImfFields - error" );
180 190
181 return NULL; // Error :( 191 return NULL; // Error :(
182} 192}
183 193
184mailmime *MailWrapper::buildTxtPart( QString str ) 194mailmime *MailWrapper::buildTxtPart( QString str )
185{ 195{
186 mailmime *txtPart; 196 mailmime *txtPart;
187 mailmime_fields *fields; 197 mailmime_fields *fields;
188 mailmime_content *content; 198 mailmime_content *content;
189 mailmime_parameter *param; 199 mailmime_parameter *param;
190 char *txt = strdup( str.latin1() ); 200 char *txt = strdup( str.latin1() );
191 int err; 201 int err;
192 202
193 param = mailmime_parameter_new( strdup( "charset" ), 203 param = mailmime_parameter_new( strdup( "charset" ),
194 strdup( "iso-8859-1" ) ); 204 strdup( "iso-8859-1" ) );
195 if ( param == NULL ) goto err_free; 205 if ( param == NULL ) goto err_free;
196 206
197 content = mailmime_content_new_with_str( "text/plain" ); 207 content = mailmime_content_new_with_str( "text/plain" );
198 if ( content == NULL ) goto err_free_param; 208 if ( content == NULL ) goto err_free_param;
199 209
200 err = clist_append( content->ct_parameters, param ); 210 err = clist_append( content->ct_parameters, param );
201 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 211 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
202 212
203 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 213 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
204 if ( fields == NULL ) goto err_free_content; 214 if ( fields == NULL ) goto err_free_content;
205 215
206 txtPart = mailmime_new_empty( content, fields ); 216 txtPart = mailmime_new_empty( content, fields );
207 if ( txtPart == NULL ) goto err_free_fields; 217 if ( txtPart == NULL ) goto err_free_fields;
208 218
209 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 219 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
210 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 220 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
211 221
212 return txtPart; // Success :) 222 return txtPart; // Success :)
213 223
214err_free_txtPart: 224err_free_txtPart:
215 mailmime_free( txtPart ); 225 mailmime_free( txtPart );
216err_free_fields: 226err_free_fields:
217 mailmime_fields_free( fields ); 227 mailmime_fields_free( fields );
218err_free_content: 228err_free_content:
219 mailmime_content_free( content ); 229 mailmime_content_free( content );
220err_free_param: 230err_free_param:
221 mailmime_parameter_free( param ); 231 mailmime_parameter_free( param );
222err_free: 232err_free:
223 free( txt ); 233 free( txt );
224 qDebug( "buildTxtPart - error" ); 234 qDebug( "buildTxtPart - error" );
225 235
226 return NULL; // Error :( 236 return NULL; // Error :(
227} 237}
228 238
229mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) 239mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
230{ 240{
231 mailmime * filePart; 241 mailmime * filePart;
232 mailmime_fields * fields; 242 mailmime_fields * fields;
233 mailmime_content * content; 243 mailmime_content * content;
234 mailmime_parameter * param = NULL; 244 mailmime_parameter * param = NULL;
235 int err; 245 int err;
236 246
237 int pos = filename.findRev( '/' ); 247 int pos = filename.findRev( '/' );
238 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 248 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
239 char *name = strdup( tmp.latin1() ); // just filename 249 char *name = strdup( tmp.latin1() ); // just filename
240 char *file = strdup( filename.latin1() ); // full name with path 250 char *file = strdup( filename.latin1() ); // full name with path
241 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 251 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
242 252
243 fields = mailmime_fields_new_filename( 253 fields = mailmime_fields_new_filename(
244 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, 254 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name,
245 MAILMIME_MECHANISM_BASE64 ); 255 MAILMIME_MECHANISM_BASE64 );
246 if ( fields == NULL ) goto err_free; 256 if ( fields == NULL ) goto err_free;
247 257
248 content = mailmime_content_new_with_str( mime ); 258 content = mailmime_content_new_with_str( mime );
249 if ( content == NULL ) goto err_free_fields; 259 if ( content == NULL ) goto err_free_fields;
250 260
251 if ( mimetype.compare( "text/plain" ) == 0 ) { 261 if ( mimetype.compare( "text/plain" ) == 0 ) {
252 param = mailmime_parameter_new( strdup( "charset" ), 262 param = mailmime_parameter_new( strdup( "charset" ),
253 strdup( "iso-8859-1" ) ); 263 strdup( "iso-8859-1" ) );
254 if ( param == NULL ) goto err_free_content; 264 if ( param == NULL ) goto err_free_content;
255 265
256 err = clist_append( content->ct_parameters, param ); 266 err = clist_append( content->ct_parameters, param );
257 if ( err != MAILIMF_NO_ERROR ) goto err_free_param; 267 if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
258 } 268 }
259 269
260 filePart = mailmime_new_empty( content, fields ); 270 filePart = mailmime_new_empty( content, fields );
261 if ( filePart == NULL ) goto err_free_param; 271 if ( filePart == NULL ) goto err_free_param;
262 272
263 err = mailmime_set_body_file( filePart, file ); 273 err = mailmime_set_body_file( filePart, file );
264 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 274 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
265 275
266 return filePart; // Success :) 276 return filePart; // Success :)
267 277
268err_free_filePart: 278err_free_filePart:
269 mailmime_free( filePart ); 279 mailmime_free( filePart );
270err_free_param: 280err_free_param:
271 if ( param != NULL ) mailmime_parameter_free( param ); 281 if ( param != NULL ) mailmime_parameter_free( param );
272err_free_content: 282err_free_content:
273 mailmime_content_free( content ); 283 mailmime_content_free( content );
274err_free_fields: 284err_free_fields:
275 mailmime_fields_free( fields ); 285 mailmime_fields_free( fields );
276err_free: 286err_free:
277 free( name ); 287 free( name );
278 free( mime ); 288 free( mime );
279 free( file ); 289 free( file );
280 qDebug( "buildFilePart - error" ); 290 qDebug( "buildFilePart - error" );
281 291
282 return NULL; // Error :( 292 return NULL; // Error :(
283} 293}
284 294
285void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) 295void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
286{ 296{
287 Attachment *it; 297 Attachment *it;
288 for ( it = files.first(); it; it = files.next() ) { 298 for ( it = files.first(); it; it = files.next() ) {
289 qDebug( "Adding file" ); 299 qDebug( "Adding file" );
290 mailmime *filePart; 300 mailmime *filePart;
291 int err; 301 int err;
292 302
293 filePart = buildFilePart( it->getFileName(), it->getMimeType() ); 303 filePart = buildFilePart( it->getFileName(), it->getMimeType() );
294 if ( filePart == NULL ) goto err_free; 304 if ( filePart == NULL ) goto err_free;
295 305
296 err = mailmime_smart_add_part( message, filePart ); 306 err = mailmime_smart_add_part( message, filePart );
297 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 307 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
298 308
299 continue; // Success :) 309 continue; // Success :)
300 310
301 err_free_filePart: 311 err_free_filePart:
302 mailmime_free( filePart ); 312 mailmime_free( filePart );
303 err_free: 313 err_free:
304 qDebug( "addFileParts: error adding file:" ); 314 qDebug( "addFileParts: error adding file:" );
305 qDebug( it->getFileName() ); 315 qDebug( it->getFileName() );
306 } 316 }
307} 317}
308 318
309mailmime *MailWrapper::createMimeMail( Mail *mail ) 319mailmime *MailWrapper::createMimeMail( Mail *mail )
310{ 320{
311 mailmime *message, *txtPart; 321 mailmime *message, *txtPart;
312 mailimf_fields *fields; 322 mailimf_fields *fields;
313 int err; 323 int err;
314 324
315 fields = createImfFields( mail ); 325 fields = createImfFields( mail );
316 if ( fields == NULL ) goto err_free; 326 if ( fields == NULL ) goto err_free;
317 327
318 message = mailmime_new_message_data( NULL ); 328 message = mailmime_new_message_data( NULL );
319 if ( message == NULL ) goto err_free_fields; 329 if ( message == NULL ) goto err_free_fields;
320 330
321 mailmime_set_imf_fields( message, fields ); 331 mailmime_set_imf_fields( message, fields );
322 332
323 txtPart = buildTxtPart( mail->getMessage() ); 333 txtPart = buildTxtPart( mail->getMessage() );
324 if ( txtPart == NULL ) goto err_free_message; 334 if ( txtPart == NULL ) goto err_free_message;
325 335
326 err = mailmime_smart_add_part( message, txtPart ); 336 err = mailmime_smart_add_part( message, txtPart );
327 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 337 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
328 338
329 addFileParts( message, mail->getAttachments() ); 339 addFileParts( message, mail->getAttachments() );
330 340
331 return message; // Success :) 341 return message; // Success :)
332 342
333err_free_txtPart: 343err_free_txtPart:
334 mailmime_free( txtPart ); 344 mailmime_free( txtPart );
335err_free_message: 345err_free_message:
336 mailmime_free( message ); 346 mailmime_free( message );
337err_free_fields: 347err_free_fields:
338 mailimf_fields_free( fields ); 348 mailimf_fields_free( fields );
339err_free: 349err_free:
340 qDebug( "createMimeMail: error" ); 350 qDebug( "createMimeMail: error" );
341 351
342 return NULL; // Error :( 352 return NULL; // Error :(
343} 353}
344 354
345mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) 355mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
346{ 356{
347 mailimf_field *field; 357 mailimf_field *field;
348 clistiter *it; 358 clistiter *it;
349 359
350 it = clist_begin( fields->fld_list ); 360 it = clist_begin( fields->fld_list );
351 while ( it ) { 361 while ( it ) {
352 field = (mailimf_field *) it->data; 362 field = (mailimf_field *) it->data;
353 if ( field->fld_type == type ) { 363 if ( field->fld_type == type ) {
354 return field; 364 return field;
355 } 365 }
356 it = it->next; 366 it = it->next;
357 } 367 }
358 368
359 return NULL; 369 return NULL;
360} 370}
361 371
362static void addRcpts( clist *list, mailimf_address_list *addr_list ) 372static void addRcpts( clist *list, mailimf_address_list *addr_list )
363{ 373{
364 clistiter *it, *it2; 374 clistiter *it, *it2;
365 375
366 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 376 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
367 mailimf_address *addr; 377 mailimf_address *addr;
368 addr = (mailimf_address *) it->data; 378 addr = (mailimf_address *) it->data;
369 379
370 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 380 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
371 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 381 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
372 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 382 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
373 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 383 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
374 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 384 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
375 mailimf_mailbox *mbox; 385 mailimf_mailbox *mbox;
376 mbox = (mailimf_mailbox *) it2->data; 386 mbox = (mailimf_mailbox *) it2->data;
377 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 387 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
378 } 388 }
379 } 389 }
380 } 390 }
381} 391}
382 392
383clist *MailWrapper::createRcptList( mailimf_fields *fields ) 393clist *MailWrapper::createRcptList( mailimf_fields *fields )
384{ 394{
385 clist *rcptList; 395 clist *rcptList;
386 mailimf_field *field; 396 mailimf_field *field;
387 397
388 rcptList = esmtp_address_list_new(); 398 rcptList = esmtp_address_list_new();
389 399
390 field = getField( fields, MAILIMF_FIELD_TO ); 400 field = getField( fields, MAILIMF_FIELD_TO );
391 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 401 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
392 && field->fld_data.fld_to->to_addr_list ) { 402 && field->fld_data.fld_to->to_addr_list ) {
393 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 403 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
394 } 404 }
395 405
396 field = getField( fields, MAILIMF_FIELD_CC ); 406 field = getField( fields, MAILIMF_FIELD_CC );
397 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 407 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
398 && field->fld_data.fld_cc->cc_addr_list ) { 408 && field->fld_data.fld_cc->cc_addr_list ) {
399 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 409 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
400 } 410 }
401 411
402 field = getField( fields, MAILIMF_FIELD_BCC ); 412 field = getField( fields, MAILIMF_FIELD_BCC );
403 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 413 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
404 && field->fld_data.fld_bcc->bcc_addr_list ) { 414 && field->fld_data.fld_bcc->bcc_addr_list ) {
405 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 415 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
406 } 416 }
407 417
408 return rcptList; 418 return rcptList;
409} 419}
410 420
411char *MailWrapper::getFrom( mailmime *mail ) 421char *MailWrapper::getFrom( mailmime *mail )
412{ 422{
413 char *from = NULL; 423 char *from = NULL;
414 424
415 mailimf_field *ffrom; 425 mailimf_field *ffrom;
416 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 426 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
417 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 427 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
418 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 428 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
419 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 429 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
420 clistiter *it; 430 clistiter *it;
421 for ( it = clist_begin( cl ); it; it = it->next ) { 431 for ( it = clist_begin( cl ); it; it = it->next ) {
422 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 432 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
423 from = strdup( mb->mb_addr_spec ); 433 from = strdup( mb->mb_addr_spec );
424 } 434 }
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 34fd5c5..6994dd8 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,123 +1,123 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34class Mail 34class Mail
35{ 35{
36public: 36public:
37 Mail(); 37 Mail();
38 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
39 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
40 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
41 * speed will be a little bit better? 41 * speed will be a little bit better?
42 */ 42 */
43 virtual ~Mail(){} 43 virtual ~Mail(){}
44 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
45 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
46 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
47 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
48 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
49 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
50 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
51 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
52 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
53 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
54 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
55 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
56 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
57 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
58 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
59 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
60 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
61 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
62 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
63 63
64private: 64private:
65 QList<Attachment> attList; 65 QList<Attachment> attList;
66 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
67}; 67};
68 68
69class Folder : public QObject 69class Folder : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73public: 73public:
74 Folder( const QString&init_name ); 74 Folder( const QString&init_name );
75 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
76 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
77 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
78 78
79private: 79protected:
80 QString nameDisplay, name; 80 QString nameDisplay, name;
81 81
82}; 82};
83 83
84class IMAPFolder : public Folder 84class IMAPFolder : public Folder
85{ 85{
86 public: 86 public:
87 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} 87 IMAPFolder(const QString&name,bool select=true,const QString&prefix="" );
88 virtual bool may_select()const{return m_MaySelect;} 88 virtual bool may_select()const{return m_MaySelect;}
89 private: 89 private:
90 bool m_MaySelect; 90 bool m_MaySelect;
91}; 91};
92 92
93class MailWrapper : public QObject 93class MailWrapper : public QObject
94{ 94{
95 Q_OBJECT 95 Q_OBJECT
96 96
97public: 97public:
98 MailWrapper( Settings *s ); 98 MailWrapper( Settings *s );
99 void sendMail( Mail mail ); 99 void sendMail( Mail mail );
100 100
101private: 101private:
102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
103 mailimf_address_list *parseAddresses(const QString&addr ); 103 mailimf_address_list *parseAddresses(const QString&addr );
104 mailimf_fields *createImfFields( Mail *mail ); 104 mailimf_fields *createImfFields( Mail *mail );
105 mailmime *buildTxtPart( QString str ); 105 mailmime *buildTxtPart( QString str );
106 mailmime *buildFilePart( QString filename, QString mimetype ); 106 mailmime *buildFilePart( QString filename, QString mimetype );
107 void addFileParts( mailmime *message, QList<Attachment> files ); 107 void addFileParts( mailmime *message, QList<Attachment> files );
108 mailmime *createMimeMail( Mail *mail ); 108 mailmime *createMimeMail( Mail *mail );
109 void smtpSend( mailmime *mail ); 109 void smtpSend( mailmime *mail );
110 mailimf_field *getField( mailimf_fields *fields, int type ); 110 mailimf_field *getField( mailimf_fields *fields, int type );
111 clist *createRcptList( mailimf_fields *fields ); 111 clist *createRcptList( mailimf_fields *fields );
112 char *getFrom( mailmime *mail ); 112 char *getFrom( mailmime *mail );
113 SMTPaccount *getAccount( QString from ); 113 SMTPaccount *getAccount( QString from );
114 void writeToFile( QString file, mailmime *mail ); 114 void writeToFile( QString file, mailmime *mail );
115 void readFromFile( QString file, char **data, size_t *size ); 115 void readFromFile( QString file, char **data, size_t *size );
116 static QString mailsmtpError( int err ); 116 static QString mailsmtpError( int err );
117 static QString getTmpFile(); 117 static QString getTmpFile();
118 118
119 Settings *settings; 119 Settings *settings;
120 120
121}; 121};
122 122
123#endif 123#endif
diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp
index 3ffc274..96602c2 100644
--- a/noncore/net/mail/mailwrapper.cpp
+++ b/noncore/net/mail/mailwrapper.cpp
@@ -1,424 +1,434 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8 8
9#include "mailwrapper.h" 9#include "mailwrapper.h"
10#include "logindialog.h" 10#include "logindialog.h"
11//#include "mail.h" 11//#include "mail.h"
12#include "defines.h" 12#include "defines.h"
13 13
14Attachment::Attachment( DocLnk lnk ) 14Attachment::Attachment( DocLnk lnk )
15{ 15{
16 doc = lnk; 16 doc = lnk;
17 size = QFileInfo( doc.file() ).size(); 17 size = QFileInfo( doc.file() ).size();
18} 18}
19 19
20Folder::Folder(const QString&tmp_name ) 20Folder::Folder(const QString&tmp_name )
21{ 21{
22 name = tmp_name; 22 name = tmp_name;
23 nameDisplay = name; 23 nameDisplay = name;
24 24
25 for ( int pos = nameDisplay.find( '&' ); pos != -1; 25 for ( int pos = nameDisplay.find( '&' ); pos != -1;
26 pos = nameDisplay.find( '&' ) ) { 26 pos = nameDisplay.find( '&' ) ) {
27 int end = nameDisplay.find( '-' ); 27 int end = nameDisplay.find( '-' );
28 if ( end == -1 || end <= pos ) break; 28 if ( end == -1 || end <= pos ) break;
29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 ); 29 QString str64 = nameDisplay.mid( pos + 1, end - pos - 1 );
30 // TODO: do real base64 decoding here ! 30 // TODO: do real base64 decoding here !
31 if ( str64.compare( "APw" ) == 0 ) { 31 if ( str64.compare( "APw" ) == 0 ) {
32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" ); 32 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "ue" );
33 } else if ( str64.compare( "APY" ) == 0 ) { 33 } else if ( str64.compare( "APY" ) == 0 ) {
34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" ); 34 nameDisplay = nameDisplay.replace( pos, end - pos + 1, "oe" );
35 } 35 }
36 } 36 }
37
38 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 37 qDebug( "folder " + name + " - displayed as " + nameDisplay );
39} 38}
40 39
40
41IMAPFolder::IMAPFolder(const QString&name,bool select,const QString&prefix )
42 : Folder( name ),m_MaySelect(select)
43{
44 if (prefix.length()>0) {
45 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
46 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
47 }
48 }
49}
50
41MailWrapper::MailWrapper( Settings *s ) 51MailWrapper::MailWrapper( Settings *s )
42 : QObject() 52 : QObject()
43{ 53{
44 settings = s; 54 settings = s;
45} 55}
46 56
47QString MailWrapper::mailsmtpError( int errnum ) 57QString MailWrapper::mailsmtpError( int errnum )
48{ 58{
49 switch ( errnum ) { 59 switch ( errnum ) {
50 case MAILSMTP_NO_ERROR: 60 case MAILSMTP_NO_ERROR:
51 return tr( "No error" ); 61 return tr( "No error" );
52 case MAILSMTP_ERROR_UNEXPECTED_CODE: 62 case MAILSMTP_ERROR_UNEXPECTED_CODE:
53 return tr( "Unexpected error code" ); 63 return tr( "Unexpected error code" );
54 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 64 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
55 return tr( "Service not available" ); 65 return tr( "Service not available" );
56 case MAILSMTP_ERROR_STREAM: 66 case MAILSMTP_ERROR_STREAM:
57 return tr( "Stream error" ); 67 return tr( "Stream error" );
58 case MAILSMTP_ERROR_HOSTNAME: 68 case MAILSMTP_ERROR_HOSTNAME:
59 return tr( "gethostname() failed" ); 69 return tr( "gethostname() failed" );
60 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 70 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
61 return tr( "Not implemented" ); 71 return tr( "Not implemented" );
62 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 72 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
63 return tr( "Error, action not taken" ); 73 return tr( "Error, action not taken" );
64 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 74 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
65 return tr( "Data exceeds storage allocation" ); 75 return tr( "Data exceeds storage allocation" );
66 case MAILSMTP_ERROR_IN_PROCESSING: 76 case MAILSMTP_ERROR_IN_PROCESSING:
67 return tr( "Error in processing" ); 77 return tr( "Error in processing" );
68 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 78 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
69 // return tr( "Insufficient system storage" ); 79 // return tr( "Insufficient system storage" );
70 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 80 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
71 return tr( "Mailbox unavailable" ); 81 return tr( "Mailbox unavailable" );
72 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 82 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
73 return tr( "Mailbox name not allowed" ); 83 return tr( "Mailbox name not allowed" );
74 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 84 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
75 return tr( "Bad command sequence" ); 85 return tr( "Bad command sequence" );
76 case MAILSMTP_ERROR_USER_NOT_LOCAL: 86 case MAILSMTP_ERROR_USER_NOT_LOCAL:
77 return tr( "User not local" ); 87 return tr( "User not local" );
78 case MAILSMTP_ERROR_TRANSACTION_FAILED: 88 case MAILSMTP_ERROR_TRANSACTION_FAILED:
79 return tr( "Transaction failed" ); 89 return tr( "Transaction failed" );
80 case MAILSMTP_ERROR_MEMORY: 90 case MAILSMTP_ERROR_MEMORY:
81 return tr( "Memory error" ); 91 return tr( "Memory error" );
82 case MAILSMTP_ERROR_CONNECTION_REFUSED: 92 case MAILSMTP_ERROR_CONNECTION_REFUSED:
83 return tr( "Connection refused" ); 93 return tr( "Connection refused" );
84 default: 94 default:
85 return tr( "Unknown error code" ); 95 return tr( "Unknown error code" );
86 } 96 }
87} 97}
88 98
89mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail ) 99mailimf_mailbox *MailWrapper::newMailbox(const QString&name, const QString&mail )
90{ 100{
91 return mailimf_mailbox_new( strdup( name.latin1() ), 101 return mailimf_mailbox_new( strdup( name.latin1() ),
92 strdup( mail.latin1() ) ); 102 strdup( mail.latin1() ) );
93} 103}
94 104
95mailimf_address_list *MailWrapper::parseAddresses(const QString&addr ) 105mailimf_address_list *MailWrapper::parseAddresses(const QString&addr )
96{ 106{
97 mailimf_address_list *addresses; 107 mailimf_address_list *addresses;
98 108
99 if ( addr.isEmpty() ) return NULL; 109 if ( addr.isEmpty() ) return NULL;
100 110
101 addresses = mailimf_address_list_new_empty(); 111 addresses = mailimf_address_list_new_empty();
102 112
103 QStringList list = QStringList::split( ',', addr ); 113 QStringList list = QStringList::split( ',', addr );
104 QStringList::Iterator it; 114 QStringList::Iterator it;
105 for ( it = list.begin(); it != list.end(); it++ ) { 115 for ( it = list.begin(); it != list.end(); it++ ) {
106 char *str = strdup( (*it).latin1() ); 116 char *str = strdup( (*it).latin1() );
107 int err = mailimf_address_list_add_parse( addresses, str ); 117 int err = mailimf_address_list_add_parse( addresses, str );
108 if ( err != MAILIMF_NO_ERROR ) { 118 if ( err != MAILIMF_NO_ERROR ) {
109 qDebug( "Error parsing" ); 119 qDebug( "Error parsing" );
110 qDebug( *it ); 120 qDebug( *it );
111 free( str ); 121 free( str );
112 } else { 122 } else {
113 qDebug( "Parse success! :)" ); 123 qDebug( "Parse success! :)" );
114 } 124 }
115 } 125 }
116 126
117 return addresses; 127 return addresses;
118} 128}
119 129
120mailimf_fields *MailWrapper::createImfFields( Mail *mail ) 130mailimf_fields *MailWrapper::createImfFields( Mail *mail )
121{ 131{
122 mailimf_fields *fields; 132 mailimf_fields *fields;
123 mailimf_field *xmailer; 133 mailimf_field *xmailer;
124 mailimf_mailbox *sender, *fromBox; 134 mailimf_mailbox *sender, *fromBox;
125 mailimf_mailbox_list *from; 135 mailimf_mailbox_list *from;
126 mailimf_address_list *to, *cc, *bcc, *reply; 136 mailimf_address_list *to, *cc, *bcc, *reply;
127 char *subject = strdup( mail->getSubject().latin1() ); 137 char *subject = strdup( mail->getSubject().latin1() );
128 int err; 138 int err;
129 139
130 sender = newMailbox( mail->getName(), mail->getMail() ); 140 sender = newMailbox( mail->getName(), mail->getMail() );
131 if ( sender == NULL ) goto err_free; 141 if ( sender == NULL ) goto err_free;
132 142
133 fromBox = newMailbox( mail->getName(), mail->getMail() ); 143 fromBox = newMailbox( mail->getName(), mail->getMail() );
134 if ( fromBox == NULL ) goto err_free_sender; 144 if ( fromBox == NULL ) goto err_free_sender;
135 145
136 from = mailimf_mailbox_list_new_empty(); 146 from = mailimf_mailbox_list_new_empty();
137 if ( from == NULL ) goto err_free_fromBox; 147 if ( from == NULL ) goto err_free_fromBox;
138 148
139 err = mailimf_mailbox_list_add( from, fromBox ); 149 err = mailimf_mailbox_list_add( from, fromBox );
140 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 150 if ( err != MAILIMF_NO_ERROR ) goto err_free_from;
141 151
142 to = parseAddresses( mail->getTo() ); 152 to = parseAddresses( mail->getTo() );
143 if ( to == NULL ) goto err_free_from; 153 if ( to == NULL ) goto err_free_from;
144 154
145 cc = parseAddresses( mail->getCC() ); 155 cc = parseAddresses( mail->getCC() );
146 bcc = parseAddresses( mail->getBCC() ); 156 bcc = parseAddresses( mail->getBCC() );
147 reply = parseAddresses( mail->getReply() ); 157 reply = parseAddresses( mail->getReply() );
148 158
149 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 159 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
150 NULL, NULL, subject ); 160 NULL, NULL, subject );
151 if ( fields == NULL ) goto err_free_reply; 161 if ( fields == NULL ) goto err_free_reply;
152 162
153 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 163 xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
154 strdup( USER_AGENT ) ); 164 strdup( USER_AGENT ) );
155 if ( xmailer == NULL ) goto err_free_fields; 165 if ( xmailer == NULL ) goto err_free_fields;
156 166
157 err = mailimf_fields_add( fields, xmailer ); 167 err = mailimf_fields_add( fields, xmailer );
158 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 168 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer;
159 169
160 return fields; // Success :) 170 return fields; // Success :)
161 171
162err_free_xmailer: 172err_free_xmailer:
163 mailimf_field_free( xmailer ); 173 mailimf_field_free( xmailer );
164err_free_fields: 174err_free_fields:
165 mailimf_fields_free( fields ); 175 mailimf_fields_free( fields );
166err_free_reply: 176err_free_reply:
167 mailimf_address_list_free( reply ); 177 mailimf_address_list_free( reply );
168 mailimf_address_list_free( bcc ); 178 mailimf_address_list_free( bcc );
169 mailimf_address_list_free( cc ); 179 mailimf_address_list_free( cc );
170 mailimf_address_list_free( to ); 180 mailimf_address_list_free( to );
171err_free_from: 181err_free_from:
172 mailimf_mailbox_list_free( from ); 182 mailimf_mailbox_list_free( from );
173err_free_fromBox: 183err_free_fromBox:
174 mailimf_mailbox_free( fromBox ); 184 mailimf_mailbox_free( fromBox );
175err_free_sender: 185err_free_sender:
176 mailimf_mailbox_free( sender ); 186 mailimf_mailbox_free( sender );
177err_free: 187err_free:
178 free( subject ); 188 free( subject );
179 qDebug( "createImfFields - error" ); 189 qDebug( "createImfFields - error" );
180 190
181 return NULL; // Error :( 191 return NULL; // Error :(
182} 192}
183 193
184mailmime *MailWrapper::buildTxtPart( QString str ) 194mailmime *MailWrapper::buildTxtPart( QString str )
185{ 195{
186 mailmime *txtPart; 196 mailmime *txtPart;
187 mailmime_fields *fields; 197 mailmime_fields *fields;
188 mailmime_content *content; 198 mailmime_content *content;
189 mailmime_parameter *param; 199 mailmime_parameter *param;
190 char *txt = strdup( str.latin1() ); 200 char *txt = strdup( str.latin1() );
191 int err; 201 int err;
192 202
193 param = mailmime_parameter_new( strdup( "charset" ), 203 param = mailmime_parameter_new( strdup( "charset" ),
194 strdup( "iso-8859-1" ) ); 204 strdup( "iso-8859-1" ) );
195 if ( param == NULL ) goto err_free; 205 if ( param == NULL ) goto err_free;
196 206
197 content = mailmime_content_new_with_str( "text/plain" ); 207 content = mailmime_content_new_with_str( "text/plain" );
198 if ( content == NULL ) goto err_free_param; 208 if ( content == NULL ) goto err_free_param;
199 209
200 err = clist_append( content->ct_parameters, param ); 210 err = clist_append( content->ct_parameters, param );
201 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 211 if ( err != MAILIMF_NO_ERROR ) goto err_free_content;
202 212
203 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 213 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT );
204 if ( fields == NULL ) goto err_free_content; 214 if ( fields == NULL ) goto err_free_content;
205 215
206 txtPart = mailmime_new_empty( content, fields ); 216 txtPart = mailmime_new_empty( content, fields );
207 if ( txtPart == NULL ) goto err_free_fields; 217 if ( txtPart == NULL ) goto err_free_fields;
208 218
209 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 219 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) );
210 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 220 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
211 221
212 return txtPart; // Success :) 222 return txtPart; // Success :)
213 223
214err_free_txtPart: 224err_free_txtPart:
215 mailmime_free( txtPart ); 225 mailmime_free( txtPart );
216err_free_fields: 226err_free_fields:
217 mailmime_fields_free( fields ); 227 mailmime_fields_free( fields );
218err_free_content: 228err_free_content:
219 mailmime_content_free( content ); 229 mailmime_content_free( content );
220err_free_param: 230err_free_param:
221 mailmime_parameter_free( param ); 231 mailmime_parameter_free( param );
222err_free: 232err_free:
223 free( txt ); 233 free( txt );
224 qDebug( "buildTxtPart - error" ); 234 qDebug( "buildTxtPart - error" );
225 235
226 return NULL; // Error :( 236 return NULL; // Error :(
227} 237}
228 238
229mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) 239mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype )
230{ 240{
231 mailmime * filePart; 241 mailmime * filePart;
232 mailmime_fields * fields; 242 mailmime_fields * fields;
233 mailmime_content * content; 243 mailmime_content * content;
234 mailmime_parameter * param = NULL; 244 mailmime_parameter * param = NULL;
235 int err; 245 int err;
236 246
237 int pos = filename.findRev( '/' ); 247 int pos = filename.findRev( '/' );
238 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 248 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
239 char *name = strdup( tmp.latin1() ); // just filename 249 char *name = strdup( tmp.latin1() ); // just filename
240 char *file = strdup( filename.latin1() ); // full name with path 250 char *file = strdup( filename.latin1() ); // full name with path
241 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 251 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain
242 252
243 fields = mailmime_fields_new_filename( 253 fields = mailmime_fields_new_filename(
244 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, 254 MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name,
245 MAILMIME_MECHANISM_BASE64 ); 255 MAILMIME_MECHANISM_BASE64 );
246 if ( fields == NULL ) goto err_free; 256 if ( fields == NULL ) goto err_free;
247 257
248 content = mailmime_content_new_with_str( mime ); 258 content = mailmime_content_new_with_str( mime );
249 if ( content == NULL ) goto err_free_fields; 259 if ( content == NULL ) goto err_free_fields;
250 260
251 if ( mimetype.compare( "text/plain" ) == 0 ) { 261 if ( mimetype.compare( "text/plain" ) == 0 ) {
252 param = mailmime_parameter_new( strdup( "charset" ), 262 param = mailmime_parameter_new( strdup( "charset" ),
253 strdup( "iso-8859-1" ) ); 263 strdup( "iso-8859-1" ) );
254 if ( param == NULL ) goto err_free_content; 264 if ( param == NULL ) goto err_free_content;
255 265
256 err = clist_append( content->ct_parameters, param ); 266 err = clist_append( content->ct_parameters, param );
257 if ( err != MAILIMF_NO_ERROR ) goto err_free_param; 267 if ( err != MAILIMF_NO_ERROR ) goto err_free_param;
258 } 268 }
259 269
260 filePart = mailmime_new_empty( content, fields ); 270 filePart = mailmime_new_empty( content, fields );
261 if ( filePart == NULL ) goto err_free_param; 271 if ( filePart == NULL ) goto err_free_param;
262 272
263 err = mailmime_set_body_file( filePart, file ); 273 err = mailmime_set_body_file( filePart, file );
264 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 274 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
265 275
266 return filePart; // Success :) 276 return filePart; // Success :)
267 277
268err_free_filePart: 278err_free_filePart:
269 mailmime_free( filePart ); 279 mailmime_free( filePart );
270err_free_param: 280err_free_param:
271 if ( param != NULL ) mailmime_parameter_free( param ); 281 if ( param != NULL ) mailmime_parameter_free( param );
272err_free_content: 282err_free_content:
273 mailmime_content_free( content ); 283 mailmime_content_free( content );
274err_free_fields: 284err_free_fields:
275 mailmime_fields_free( fields ); 285 mailmime_fields_free( fields );
276err_free: 286err_free:
277 free( name ); 287 free( name );
278 free( mime ); 288 free( mime );
279 free( file ); 289 free( file );
280 qDebug( "buildFilePart - error" ); 290 qDebug( "buildFilePart - error" );
281 291
282 return NULL; // Error :( 292 return NULL; // Error :(
283} 293}
284 294
285void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) 295void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files )
286{ 296{
287 Attachment *it; 297 Attachment *it;
288 for ( it = files.first(); it; it = files.next() ) { 298 for ( it = files.first(); it; it = files.next() ) {
289 qDebug( "Adding file" ); 299 qDebug( "Adding file" );
290 mailmime *filePart; 300 mailmime *filePart;
291 int err; 301 int err;
292 302
293 filePart = buildFilePart( it->getFileName(), it->getMimeType() ); 303 filePart = buildFilePart( it->getFileName(), it->getMimeType() );
294 if ( filePart == NULL ) goto err_free; 304 if ( filePart == NULL ) goto err_free;
295 305
296 err = mailmime_smart_add_part( message, filePart ); 306 err = mailmime_smart_add_part( message, filePart );
297 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; 307 if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart;
298 308
299 continue; // Success :) 309 continue; // Success :)
300 310
301 err_free_filePart: 311 err_free_filePart:
302 mailmime_free( filePart ); 312 mailmime_free( filePart );
303 err_free: 313 err_free:
304 qDebug( "addFileParts: error adding file:" ); 314 qDebug( "addFileParts: error adding file:" );
305 qDebug( it->getFileName() ); 315 qDebug( it->getFileName() );
306 } 316 }
307} 317}
308 318
309mailmime *MailWrapper::createMimeMail( Mail *mail ) 319mailmime *MailWrapper::createMimeMail( Mail *mail )
310{ 320{
311 mailmime *message, *txtPart; 321 mailmime *message, *txtPart;
312 mailimf_fields *fields; 322 mailimf_fields *fields;
313 int err; 323 int err;
314 324
315 fields = createImfFields( mail ); 325 fields = createImfFields( mail );
316 if ( fields == NULL ) goto err_free; 326 if ( fields == NULL ) goto err_free;
317 327
318 message = mailmime_new_message_data( NULL ); 328 message = mailmime_new_message_data( NULL );
319 if ( message == NULL ) goto err_free_fields; 329 if ( message == NULL ) goto err_free_fields;
320 330
321 mailmime_set_imf_fields( message, fields ); 331 mailmime_set_imf_fields( message, fields );
322 332
323 txtPart = buildTxtPart( mail->getMessage() ); 333 txtPart = buildTxtPart( mail->getMessage() );
324 if ( txtPart == NULL ) goto err_free_message; 334 if ( txtPart == NULL ) goto err_free_message;
325 335
326 err = mailmime_smart_add_part( message, txtPart ); 336 err = mailmime_smart_add_part( message, txtPart );
327 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 337 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
328 338
329 addFileParts( message, mail->getAttachments() ); 339 addFileParts( message, mail->getAttachments() );
330 340
331 return message; // Success :) 341 return message; // Success :)
332 342
333err_free_txtPart: 343err_free_txtPart:
334 mailmime_free( txtPart ); 344 mailmime_free( txtPart );
335err_free_message: 345err_free_message:
336 mailmime_free( message ); 346 mailmime_free( message );
337err_free_fields: 347err_free_fields:
338 mailimf_fields_free( fields ); 348 mailimf_fields_free( fields );
339err_free: 349err_free:
340 qDebug( "createMimeMail: error" ); 350 qDebug( "createMimeMail: error" );
341 351
342 return NULL; // Error :( 352 return NULL; // Error :(
343} 353}
344 354
345mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) 355mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type )
346{ 356{
347 mailimf_field *field; 357 mailimf_field *field;
348 clistiter *it; 358 clistiter *it;
349 359
350 it = clist_begin( fields->fld_list ); 360 it = clist_begin( fields->fld_list );
351 while ( it ) { 361 while ( it ) {
352 field = (mailimf_field *) it->data; 362 field = (mailimf_field *) it->data;
353 if ( field->fld_type == type ) { 363 if ( field->fld_type == type ) {
354 return field; 364 return field;
355 } 365 }
356 it = it->next; 366 it = it->next;
357 } 367 }
358 368
359 return NULL; 369 return NULL;
360} 370}
361 371
362static void addRcpts( clist *list, mailimf_address_list *addr_list ) 372static void addRcpts( clist *list, mailimf_address_list *addr_list )
363{ 373{
364 clistiter *it, *it2; 374 clistiter *it, *it2;
365 375
366 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 376 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
367 mailimf_address *addr; 377 mailimf_address *addr;
368 addr = (mailimf_address *) it->data; 378 addr = (mailimf_address *) it->data;
369 379
370 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 380 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
371 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 381 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
372 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 382 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
373 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 383 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
374 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 384 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
375 mailimf_mailbox *mbox; 385 mailimf_mailbox *mbox;
376 mbox = (mailimf_mailbox *) it2->data; 386 mbox = (mailimf_mailbox *) it2->data;
377 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 387 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
378 } 388 }
379 } 389 }
380 } 390 }
381} 391}
382 392
383clist *MailWrapper::createRcptList( mailimf_fields *fields ) 393clist *MailWrapper::createRcptList( mailimf_fields *fields )
384{ 394{
385 clist *rcptList; 395 clist *rcptList;
386 mailimf_field *field; 396 mailimf_field *field;
387 397
388 rcptList = esmtp_address_list_new(); 398 rcptList = esmtp_address_list_new();
389 399
390 field = getField( fields, MAILIMF_FIELD_TO ); 400 field = getField( fields, MAILIMF_FIELD_TO );
391 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 401 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
392 && field->fld_data.fld_to->to_addr_list ) { 402 && field->fld_data.fld_to->to_addr_list ) {
393 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 403 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
394 } 404 }
395 405
396 field = getField( fields, MAILIMF_FIELD_CC ); 406 field = getField( fields, MAILIMF_FIELD_CC );
397 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 407 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
398 && field->fld_data.fld_cc->cc_addr_list ) { 408 && field->fld_data.fld_cc->cc_addr_list ) {
399 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 409 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
400 } 410 }
401 411
402 field = getField( fields, MAILIMF_FIELD_BCC ); 412 field = getField( fields, MAILIMF_FIELD_BCC );
403 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 413 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
404 && field->fld_data.fld_bcc->bcc_addr_list ) { 414 && field->fld_data.fld_bcc->bcc_addr_list ) {
405 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 415 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
406 } 416 }
407 417
408 return rcptList; 418 return rcptList;
409} 419}
410 420
411char *MailWrapper::getFrom( mailmime *mail ) 421char *MailWrapper::getFrom( mailmime *mail )
412{ 422{
413 char *from = NULL; 423 char *from = NULL;
414 424
415 mailimf_field *ffrom; 425 mailimf_field *ffrom;
416 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 426 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
417 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 427 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
418 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 428 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
419 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 429 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
420 clistiter *it; 430 clistiter *it;
421 for ( it = clist_begin( cl ); it; it = it->next ) { 431 for ( it = clist_begin( cl ); it; it = it->next ) {
422 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 432 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
423 from = strdup( mb->mb_addr_spec ); 433 from = strdup( mb->mb_addr_spec );
424 } 434 }
diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h
index 34fd5c5..6994dd8 100644
--- a/noncore/net/mail/mailwrapper.h
+++ b/noncore/net/mail/mailwrapper.h
@@ -1,123 +1,123 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
7#include <libetpan/mailimf.h> 7#include <libetpan/mailimf.h>
8#include <libetpan/mailsmtp.h> 8#include <libetpan/mailsmtp.h>
9#include <libetpan/mailstorage.h> 9#include <libetpan/mailstorage.h>
10#include <libetpan/maildriver.h> 10#include <libetpan/maildriver.h>
11#include <qbitarray.h> 11#include <qbitarray.h>
12#include <qdatetime.h> 12#include <qdatetime.h>
13 13
14#include "settings.h" 14#include "settings.h"
15 15
16class Attachment 16class Attachment
17{ 17{
18public: 18public:
19 Attachment( DocLnk lnk ); 19 Attachment( DocLnk lnk );
20 virtual ~Attachment(){} 20 virtual ~Attachment(){}
21 const QString getFileName()const{ return doc.file(); } 21 const QString getFileName()const{ return doc.file(); }
22 const QString getName()const{ return doc.name(); } 22 const QString getName()const{ return doc.name(); }
23 const QString getMimeType()const{ return doc.type(); } 23 const QString getMimeType()const{ return doc.type(); }
24 const QPixmap getPixmap()const{ return doc.pixmap(); } 24 const QPixmap getPixmap()const{ return doc.pixmap(); }
25 const int getSize()const { return size; } 25 const int getSize()const { return size; }
26 DocLnk getDocLnk() { return doc; } 26 DocLnk getDocLnk() { return doc; }
27 27
28protected: 28protected:
29 DocLnk doc; 29 DocLnk doc;
30 int size; 30 int size;
31 31
32}; 32};
33 33
34class Mail 34class Mail
35{ 35{
36public: 36public:
37 Mail(); 37 Mail();
38 /* Possible that this destructor must not be declared virtual 38 /* Possible that this destructor must not be declared virtual
39 * 'cause it seems that it will never have some child classes. 39 * 'cause it seems that it will never have some child classes.
40 * in this case this object will not get a virtual table -> memory and 40 * in this case this object will not get a virtual table -> memory and
41 * speed will be a little bit better? 41 * speed will be a little bit better?
42 */ 42 */
43 virtual ~Mail(){} 43 virtual ~Mail(){}
44 void addAttachment( Attachment *att ) { attList.append( att ); } 44 void addAttachment( Attachment *att ) { attList.append( att ); }
45 const QList<Attachment>& getAttachments()const { return attList; } 45 const QList<Attachment>& getAttachments()const { return attList; }
46 void removeAttachment( Attachment *att ) { attList.remove( att ); } 46 void removeAttachment( Attachment *att ) { attList.remove( att ); }
47 const QString&getName()const { return name; } 47 const QString&getName()const { return name; }
48 void setName( QString s ) { name = s; } 48 void setName( QString s ) { name = s; }
49 const QString&getMail()const{ return mail; } 49 const QString&getMail()const{ return mail; }
50 void setMail( const QString&s ) { mail = s; } 50 void setMail( const QString&s ) { mail = s; }
51 const QString&getTo()const{ return to; } 51 const QString&getTo()const{ return to; }
52 void setTo( const QString&s ) { to = s; } 52 void setTo( const QString&s ) { to = s; }
53 const QString&getCC()const{ return cc; } 53 const QString&getCC()const{ return cc; }
54 void setCC( const QString&s ) { cc = s; } 54 void setCC( const QString&s ) { cc = s; }
55 const QString&getBCC()const { return bcc; } 55 const QString&getBCC()const { return bcc; }
56 void setBCC( const QString&s ) { bcc = s; } 56 void setBCC( const QString&s ) { bcc = s; }
57 const QString&getMessage()const { return message; } 57 const QString&getMessage()const { return message; }
58 void setMessage( const QString&s ) { message = s; } 58 void setMessage( const QString&s ) { message = s; }
59 const QString&getSubject()const { return subject; } 59 const QString&getSubject()const { return subject; }
60 void setSubject( const QString&s ) { subject = s; } 60 void setSubject( const QString&s ) { subject = s; }
61 const QString&getReply()const{ return reply; } 61 const QString&getReply()const{ return reply; }
62 void setReply( const QString&a ) { reply = a; } 62 void setReply( const QString&a ) { reply = a; }
63 63
64private: 64private:
65 QList<Attachment> attList; 65 QList<Attachment> attList;
66 QString name, mail, to, cc, bcc, reply, subject, message; 66 QString name, mail, to, cc, bcc, reply, subject, message;
67}; 67};
68 68
69class Folder : public QObject 69class Folder : public QObject
70{ 70{
71 Q_OBJECT 71 Q_OBJECT
72 72
73public: 73public:
74 Folder( const QString&init_name ); 74 Folder( const QString&init_name );
75 const QString&getDisplayName()const { return nameDisplay; } 75 const QString&getDisplayName()const { return nameDisplay; }
76 const QString&getName()const { return name; } 76 const QString&getName()const { return name; }
77 virtual bool may_select()const{return true;}; 77 virtual bool may_select()const{return true;};
78 78
79private: 79protected:
80 QString nameDisplay, name; 80 QString nameDisplay, name;
81 81
82}; 82};
83 83
84class IMAPFolder : public Folder 84class IMAPFolder : public Folder
85{ 85{
86 public: 86 public:
87 IMAPFolder( QString name,bool select=true ) : Folder( name ),m_MaySelect(select) {} 87 IMAPFolder(const QString&name,bool select=true,const QString&prefix="" );
88 virtual bool may_select()const{return m_MaySelect;} 88 virtual bool may_select()const{return m_MaySelect;}
89 private: 89 private:
90 bool m_MaySelect; 90 bool m_MaySelect;
91}; 91};
92 92
93class MailWrapper : public QObject 93class MailWrapper : public QObject
94{ 94{
95 Q_OBJECT 95 Q_OBJECT
96 96
97public: 97public:
98 MailWrapper( Settings *s ); 98 MailWrapper( Settings *s );
99 void sendMail( Mail mail ); 99 void sendMail( Mail mail );
100 100
101private: 101private:
102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 102 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
103 mailimf_address_list *parseAddresses(const QString&addr ); 103 mailimf_address_list *parseAddresses(const QString&addr );
104 mailimf_fields *createImfFields( Mail *mail ); 104 mailimf_fields *createImfFields( Mail *mail );
105 mailmime *buildTxtPart( QString str ); 105 mailmime *buildTxtPart( QString str );
106 mailmime *buildFilePart( QString filename, QString mimetype ); 106 mailmime *buildFilePart( QString filename, QString mimetype );
107 void addFileParts( mailmime *message, QList<Attachment> files ); 107 void addFileParts( mailmime *message, QList<Attachment> files );
108 mailmime *createMimeMail( Mail *mail ); 108 mailmime *createMimeMail( Mail *mail );
109 void smtpSend( mailmime *mail ); 109 void smtpSend( mailmime *mail );
110 mailimf_field *getField( mailimf_fields *fields, int type ); 110 mailimf_field *getField( mailimf_fields *fields, int type );
111 clist *createRcptList( mailimf_fields *fields ); 111 clist *createRcptList( mailimf_fields *fields );
112 char *getFrom( mailmime *mail ); 112 char *getFrom( mailmime *mail );
113 SMTPaccount *getAccount( QString from ); 113 SMTPaccount *getAccount( QString from );
114 void writeToFile( QString file, mailmime *mail ); 114 void writeToFile( QString file, mailmime *mail );
115 void readFromFile( QString file, char **data, size_t *size ); 115 void readFromFile( QString file, char **data, size_t *size );
116 static QString mailsmtpError( int err ); 116 static QString mailsmtpError( int err );
117 static QString getTmpFile(); 117 static QString getTmpFile();
118 118
119 Settings *settings; 119 Settings *settings;
120 120
121}; 121};
122 122
123#endif 123#endif