-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 11bf3b8..48e476b 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,695 +1,696 @@ | |||
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 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | { | 9 | { |
10 | account = a; | 10 | account = a; |
11 | m_imap = 0; | 11 | m_imap = 0; |
12 | } | 12 | } |
13 | 13 | ||
14 | IMAPwrapper::~IMAPwrapper() | 14 | IMAPwrapper::~IMAPwrapper() |
15 | { | 15 | { |
16 | logout(); | 16 | logout(); |
17 | } | 17 | } |
18 | 18 | ||
19 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 19 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
20 | { | 20 | { |
21 | qDebug( "IMAP: %i of %i", current, maximum ); | 21 | qDebug( "IMAP: %i of %i", current, maximum ); |
22 | } | 22 | } |
23 | 23 | ||
24 | void IMAPwrapper::login() | 24 | void IMAPwrapper::login() |
25 | { | 25 | { |
26 | const char *server, *user, *pass; | 26 | const char *server, *user, *pass; |
27 | uint16_t port; | 27 | uint16_t port; |
28 | int err = MAILIMAP_NO_ERROR; | 28 | int err = MAILIMAP_NO_ERROR; |
29 | 29 | ||
30 | /* we are connected this moment */ | 30 | /* we are connected this moment */ |
31 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 31 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
32 | if (m_imap) { | 32 | if (m_imap) { |
33 | mailstream_flush(m_imap->imap_stream); | ||
33 | return; | 34 | return; |
34 | } | 35 | } |
35 | server = account->getServer().latin1(); | 36 | server = account->getServer().latin1(); |
36 | port = account->getPort().toUInt(); | 37 | port = account->getPort().toUInt(); |
37 | user = account->getUser().latin1(); | 38 | user = account->getUser().latin1(); |
38 | pass = account->getPassword().latin1(); | 39 | pass = account->getPassword().latin1(); |
39 | 40 | ||
40 | m_imap = mailimap_new( 20, &imap_progress ); | 41 | m_imap = mailimap_new( 20, &imap_progress ); |
41 | /* connect */ | 42 | /* connect */ |
42 | if (account->getSSL()) { | 43 | if (account->getSSL()) { |
43 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 44 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
44 | } else { | 45 | } else { |
45 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 46 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
46 | } | 47 | } |
47 | 48 | ||
48 | if ( err != MAILIMAP_NO_ERROR && | 49 | if ( err != MAILIMAP_NO_ERROR && |
49 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 50 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
50 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 51 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
51 | qDebug("error connecting server: %s",m_imap->imap_response); | 52 | qDebug("error connecting server: %s",m_imap->imap_response); |
52 | mailimap_free( m_imap ); | 53 | mailimap_free( m_imap ); |
53 | m_imap = 0; | 54 | m_imap = 0; |
54 | return; | 55 | return; |
55 | } | 56 | } |
56 | 57 | ||
57 | /* login */ | 58 | /* login */ |
58 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 59 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
59 | if ( err != MAILIMAP_NO_ERROR ) { | 60 | if ( err != MAILIMAP_NO_ERROR ) { |
60 | qDebug("error logging in imap: %s",m_imap->imap_response); | 61 | qDebug("error logging in imap: %s",m_imap->imap_response); |
61 | err = mailimap_close( m_imap ); | 62 | err = mailimap_close( m_imap ); |
62 | mailimap_free( m_imap ); | 63 | mailimap_free( m_imap ); |
63 | m_imap = 0; | 64 | m_imap = 0; |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
67 | void IMAPwrapper::logout() | 68 | void IMAPwrapper::logout() |
68 | { | 69 | { |
69 | int err = MAILIMAP_NO_ERROR; | 70 | int err = MAILIMAP_NO_ERROR; |
70 | if (!m_imap) return; | 71 | if (!m_imap) return; |
71 | err = mailimap_logout( m_imap ); | 72 | err = mailimap_logout( m_imap ); |
72 | err = mailimap_close( m_imap ); | 73 | err = mailimap_close( m_imap ); |
73 | mailimap_free( m_imap ); | 74 | mailimap_free( m_imap ); |
74 | m_imap = 0; | 75 | m_imap = 0; |
75 | } | 76 | } |
76 | 77 | ||
77 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 78 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
78 | { | 79 | { |
79 | const char *mb; | 80 | const char *mb; |
80 | int err = MAILIMAP_NO_ERROR; | 81 | int err = MAILIMAP_NO_ERROR; |
81 | clist *result; | 82 | clist *result; |
82 | clistcell *current; | 83 | clistcell *current; |
83 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 84 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
84 | mailimap_fetch_type *fetchType; | 85 | mailimap_fetch_type *fetchType; |
85 | mailimap_set *set; | 86 | mailimap_set *set; |
86 | 87 | ||
87 | mb = mailbox.latin1(); | 88 | mb = mailbox.latin1(); |
88 | login(); | 89 | login(); |
89 | if (!m_imap) { | 90 | if (!m_imap) { |
90 | return; | 91 | return; |
91 | } | 92 | } |
92 | /* select mailbox READONLY for operations */ | 93 | /* select mailbox READONLY for operations */ |
93 | err = mailimap_examine( m_imap, (char*)mb); | 94 | err = mailimap_examine( m_imap, (char*)mb); |
94 | if ( err != MAILIMAP_NO_ERROR ) { | 95 | if ( err != MAILIMAP_NO_ERROR ) { |
95 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 96 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
96 | return; | 97 | return; |
97 | } | 98 | } |
98 | 99 | ||
99 | int last = m_imap->imap_selection_info->sel_exists; | 100 | int last = m_imap->imap_selection_info->sel_exists; |
100 | 101 | ||
101 | if (last == 0) { | 102 | if (last == 0) { |
102 | qDebug("mailbox has no mails"); | 103 | qDebug("mailbox has no mails"); |
103 | return; | 104 | return; |
104 | } | 105 | } |
105 | 106 | ||
106 | result = clist_new(); | 107 | result = clist_new(); |
107 | /* the range has to start at 1!!! not with 0!!!! */ | 108 | /* the range has to start at 1!!! not with 0!!!! */ |
108 | set = mailimap_set_new_interval( 1, last ); | 109 | set = mailimap_set_new_interval( 1, last ); |
109 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 110 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
110 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 111 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
111 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
114 | 115 | ||
115 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 116 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
116 | mailimap_set_free( set ); | 117 | mailimap_set_free( set ); |
117 | mailimap_fetch_type_free( fetchType ); | 118 | mailimap_fetch_type_free( fetchType ); |
118 | 119 | ||
119 | QString date,subject,from; | 120 | QString date,subject,from; |
120 | 121 | ||
121 | if ( err == MAILIMAP_NO_ERROR ) { | 122 | if ( err == MAILIMAP_NO_ERROR ) { |
122 | 123 | ||
123 | mailimap_msg_att * msg_att; | 124 | mailimap_msg_att * msg_att; |
124 | int i = 0; | 125 | int i = 0; |
125 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 126 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
126 | ++i; | 127 | ++i; |
127 | msg_att = (mailimap_msg_att*)current->data; | 128 | msg_att = (mailimap_msg_att*)current->data; |
128 | RecMail*m = parse_list_result(msg_att); | 129 | RecMail*m = parse_list_result(msg_att); |
129 | if (m) { | 130 | if (m) { |
130 | m->setNumber(i); | 131 | m->setNumber(i); |
131 | m->setMbox(mailbox); | 132 | m->setMbox(mailbox); |
132 | target.append(m); | 133 | target.append(m); |
133 | } | 134 | } |
134 | } | 135 | } |
135 | } else { | 136 | } else { |
136 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 137 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
137 | } | 138 | } |
138 | mailimap_fetch_list_free(result); | 139 | mailimap_fetch_list_free(result); |
139 | } | 140 | } |
140 | 141 | ||
141 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 142 | QList<IMAPFolder>* IMAPwrapper::listFolders() |
142 | { | 143 | { |
143 | const char *path, *mask; | 144 | const char *path, *mask; |
144 | int err = MAILIMAP_NO_ERROR; | 145 | int err = MAILIMAP_NO_ERROR; |
145 | clist *result; | 146 | clist *result; |
146 | clistcell *current; | 147 | clistcell *current; |
147 | 148 | ||
148 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | 149 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); |
149 | folders->setAutoDelete( true ); | 150 | folders->setAutoDelete( true ); |
150 | login(); | 151 | login(); |
151 | if (!m_imap) { | 152 | if (!m_imap) { |
152 | return folders; | 153 | return folders; |
153 | } | 154 | } |
154 | 155 | ||
155 | /* | 156 | /* |
156 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 157 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
157 | * We must not forget to filter them out in next loop! | 158 | * We must not forget to filter them out in next loop! |
158 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 159 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
159 | */ | 160 | */ |
160 | QString temp; | 161 | QString temp; |
161 | mask = "INBOX" ; | 162 | mask = "INBOX" ; |
162 | result = clist_new(); | 163 | result = clist_new(); |
163 | mailimap_mailbox_list *list; | 164 | mailimap_mailbox_list *list; |
164 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 165 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
165 | if ( err == MAILIMAP_NO_ERROR ) { | 166 | if ( err == MAILIMAP_NO_ERROR ) { |
166 | current = result->first; | 167 | current = result->first; |
167 | for ( int i = result->count; i > 0; i-- ) { | 168 | for ( int i = result->count; i > 0; i-- ) { |
168 | list = (mailimap_mailbox_list *) current->data; | 169 | list = (mailimap_mailbox_list *) current->data; |
169 | // it is better use the deep copy mechanism of qt itself | 170 | // it is better use the deep copy mechanism of qt itself |
170 | // instead of using strdup! | 171 | // instead of using strdup! |
171 | temp = list->mb_name; | 172 | temp = list->mb_name; |
172 | folders->append( new IMAPFolder(temp)); | 173 | folders->append( new IMAPFolder(temp)); |
173 | current = current->next; | 174 | current = current->next; |
174 | } | 175 | } |
175 | } else { | 176 | } else { |
176 | qDebug("error fetching folders: %s",m_imap->imap_response); | 177 | qDebug("error fetching folders: %s",m_imap->imap_response); |
177 | } | 178 | } |
178 | mailimap_list_result_free( result ); | 179 | mailimap_list_result_free( result ); |
179 | 180 | ||
180 | /* | 181 | /* |
181 | * second stage - get the other then inbox folders | 182 | * second stage - get the other then inbox folders |
182 | */ | 183 | */ |
183 | mask = "*" ; | 184 | mask = "*" ; |
184 | path = account->getPrefix().latin1(); | 185 | path = account->getPrefix().latin1(); |
185 | if (!path) path = ""; | 186 | if (!path) path = ""; |
186 | result = clist_new(); | 187 | result = clist_new(); |
187 | qDebug(path); | 188 | qDebug(path); |
188 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 189 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
189 | if ( err == MAILIMAP_NO_ERROR ) { | 190 | if ( err == MAILIMAP_NO_ERROR ) { |
190 | current = result->first; | 191 | current = result->first; |
191 | for ( int i = result->count; i > 0; i-- ) { | 192 | for ( int i = result->count; i > 0; i-- ) { |
192 | list = (mailimap_mailbox_list *) current->data; | 193 | list = (mailimap_mailbox_list *) current->data; |
193 | // it is better use the deep copy mechanism of qt itself | 194 | // it is better use the deep copy mechanism of qt itself |
194 | // instead of using strdup! | 195 | // instead of using strdup! |
195 | temp = list->mb_name; | 196 | temp = list->mb_name; |
196 | current = current->next; | 197 | current = current->next; |
197 | if (temp.lower()=="inbox") | 198 | if (temp.lower()=="inbox") |
198 | continue; | 199 | continue; |
199 | folders->append(new IMAPFolder(temp)); | 200 | folders->append(new IMAPFolder(temp)); |
200 | 201 | ||
201 | } | 202 | } |
202 | } else { | 203 | } else { |
203 | qDebug("error fetching folders %s",m_imap->imap_response); | 204 | qDebug("error fetching folders %s",m_imap->imap_response); |
204 | } | 205 | } |
205 | mailimap_list_result_free( result ); | 206 | mailimap_list_result_free( result ); |
206 | return folders; | 207 | return folders; |
207 | } | 208 | } |
208 | 209 | ||
209 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 210 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
210 | { | 211 | { |
211 | RecMail * m = 0; | 212 | RecMail * m = 0; |
212 | mailimap_msg_att_item *item=0; | 213 | mailimap_msg_att_item *item=0; |
213 | clistcell *current,*c,*cf; | 214 | clistcell *current,*c,*cf; |
214 | mailimap_msg_att_dynamic*flist; | 215 | mailimap_msg_att_dynamic*flist; |
215 | mailimap_flag_fetch*cflag; | 216 | mailimap_flag_fetch*cflag; |
216 | int size; | 217 | int size; |
217 | QBitArray mFlags(7); | 218 | QBitArray mFlags(7); |
218 | QStringList addresslist; | 219 | QStringList addresslist; |
219 | 220 | ||
220 | if (!m_att) { | 221 | if (!m_att) { |
221 | return m; | 222 | return m; |
222 | } | 223 | } |
223 | m = new RecMail(); | 224 | m = new RecMail(); |
224 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 225 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
225 | current = c; | 226 | current = c; |
226 | size = 0; | 227 | size = 0; |
227 | item = (mailimap_msg_att_item*)current->data; | 228 | item = (mailimap_msg_att_item*)current->data; |
228 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 229 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
229 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 230 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
230 | if (!flist->att_list) { | 231 | if (!flist->att_list) { |
231 | continue; | 232 | continue; |
232 | } | 233 | } |
233 | cf = flist->att_list->first; | 234 | cf = flist->att_list->first; |
234 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 235 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
235 | cflag = (mailimap_flag_fetch*)cf->data; | 236 | cflag = (mailimap_flag_fetch*)cf->data; |
236 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 237 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
237 | switch (cflag->fl_flag->fl_type) { | 238 | switch (cflag->fl_flag->fl_type) { |
238 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 239 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
239 | mFlags.setBit(FLAG_ANSWERED); | 240 | mFlags.setBit(FLAG_ANSWERED); |
240 | break; | 241 | break; |
241 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 242 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
242 | mFlags.setBit(FLAG_FLAGGED); | 243 | mFlags.setBit(FLAG_FLAGGED); |
243 | break; | 244 | break; |
244 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 245 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
245 | mFlags.setBit(FLAG_DELETED); | 246 | mFlags.setBit(FLAG_DELETED); |
246 | break; | 247 | break; |
247 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 248 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
248 | mFlags.setBit(FLAG_SEEN); | 249 | mFlags.setBit(FLAG_SEEN); |
249 | break; | 250 | break; |
250 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 251 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
251 | mFlags.setBit(FLAG_DRAFT); | 252 | mFlags.setBit(FLAG_DRAFT); |
252 | break; | 253 | break; |
253 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 254 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
254 | break; | 255 | break; |
255 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 256 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
256 | break; | 257 | break; |
257 | default: | 258 | default: |
258 | break; | 259 | break; |
259 | } | 260 | } |
260 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 261 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
261 | mFlags.setBit(FLAG_RECENT); | 262 | mFlags.setBit(FLAG_RECENT); |
262 | } | 263 | } |
263 | } | 264 | } |
264 | continue; | 265 | continue; |
265 | } | 266 | } |
266 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 267 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
267 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 268 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
268 | m->setDate(head->env_date); | 269 | m->setDate(head->env_date); |
269 | m->setSubject(head->env_subject); | 270 | m->setSubject(head->env_subject); |
270 | if (head->env_from!=NULL) { | 271 | if (head->env_from!=NULL) { |
271 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 272 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
272 | if (addresslist.count()) { | 273 | if (addresslist.count()) { |
273 | m->setFrom(addresslist.first()); | 274 | m->setFrom(addresslist.first()); |
274 | } | 275 | } |
275 | } | 276 | } |
276 | if (head->env_to!=NULL) { | 277 | if (head->env_to!=NULL) { |
277 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 278 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
278 | m->setTo(addresslist); | 279 | m->setTo(addresslist); |
279 | } | 280 | } |
280 | if (head->env_cc!=NULL) { | 281 | if (head->env_cc!=NULL) { |
281 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 282 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
282 | m->setCC(addresslist); | 283 | m->setCC(addresslist); |
283 | } | 284 | } |
284 | if (head->env_bcc!=NULL) { | 285 | if (head->env_bcc!=NULL) { |
285 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 286 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
286 | m->setBcc(addresslist); | 287 | m->setBcc(addresslist); |
287 | } | 288 | } |
288 | if (head->env_reply_to!=NULL) { | 289 | if (head->env_reply_to!=NULL) { |
289 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 290 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
290 | if (addresslist.count()) { | 291 | if (addresslist.count()) { |
291 | m->setReplyto(addresslist.first()); | 292 | m->setReplyto(addresslist.first()); |
292 | } | 293 | } |
293 | } | 294 | } |
294 | m->setMsgid(QString(head->env_message_id)); | 295 | m->setMsgid(QString(head->env_message_id)); |
295 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 296 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
296 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 297 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
297 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 298 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
298 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 299 | 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); |
299 | qDebug(da.toString()); | 300 | qDebug(da.toString()); |
300 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 301 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
301 | size = item->att_data.att_static->att_data.att_rfc822_size; | 302 | size = item->att_data.att_static->att_data.att_rfc822_size; |
302 | } | 303 | } |
303 | } | 304 | } |
304 | /* msg is already deleted */ | 305 | /* msg is already deleted */ |
305 | if (mFlags.testBit(FLAG_DELETED) && m) { | 306 | if (mFlags.testBit(FLAG_DELETED) && m) { |
306 | delete m; | 307 | delete m; |
307 | m = 0; | 308 | m = 0; |
308 | } | 309 | } |
309 | if (m) { | 310 | if (m) { |
310 | m->setFlags(mFlags); | 311 | m->setFlags(mFlags); |
311 | m->setMsgsize(size); | 312 | m->setMsgsize(size); |
312 | } | 313 | } |
313 | return m; | 314 | return m; |
314 | } | 315 | } |
315 | 316 | ||
316 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 317 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
317 | { | 318 | { |
318 | RecBody body; | 319 | RecBody body; |
319 | const char *mb; | 320 | const char *mb; |
320 | int err = MAILIMAP_NO_ERROR; | 321 | int err = MAILIMAP_NO_ERROR; |
321 | clist *result; | 322 | clist *result; |
322 | clistcell *current; | 323 | clistcell *current; |
323 | mailimap_fetch_att *fetchAtt; | 324 | mailimap_fetch_att *fetchAtt; |
324 | mailimap_fetch_type *fetchType; | 325 | mailimap_fetch_type *fetchType; |
325 | mailimap_set *set; | 326 | mailimap_set *set; |
326 | mailimap_body*body_desc; | 327 | mailimap_body*body_desc; |
327 | 328 | ||
328 | mb = mail.getMbox().latin1(); | 329 | mb = mail.getMbox().latin1(); |
329 | 330 | ||
330 | login(); | 331 | login(); |
331 | if (!m_imap) { | 332 | if (!m_imap) { |
332 | return body; | 333 | return body; |
333 | } | 334 | } |
334 | 335 | ||
335 | err = mailimap_select( m_imap, (char*)mb); | 336 | err = mailimap_select( m_imap, (char*)mb); |
336 | if ( err != MAILIMAP_NO_ERROR ) { | 337 | if ( err != MAILIMAP_NO_ERROR ) { |
337 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 338 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
338 | return body; | 339 | return body; |
339 | } | 340 | } |
340 | 341 | ||
341 | result = clist_new(); | 342 | result = clist_new(); |
342 | /* the range has to start at 1!!! not with 0!!!! */ | 343 | /* the range has to start at 1!!! not with 0!!!! */ |
343 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 344 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
344 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 345 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
345 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 346 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
346 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 347 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
347 | mailimap_set_free( set ); | 348 | mailimap_set_free( set ); |
348 | mailimap_fetch_type_free( fetchType ); | 349 | mailimap_fetch_type_free( fetchType ); |
349 | 350 | ||
350 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 351 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
351 | mailimap_msg_att * msg_att; | 352 | mailimap_msg_att * msg_att; |
352 | msg_att = (mailimap_msg_att*)current->data; | 353 | msg_att = (mailimap_msg_att*)current->data; |
353 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 354 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
354 | body_desc = item->att_data.att_static->att_data.att_body; | 355 | body_desc = item->att_data.att_static->att_data.att_body; |
355 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 356 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
356 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 357 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
357 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 358 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
358 | qDebug("Mulitpart mail"); | 359 | qDebug("Mulitpart mail"); |
359 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 360 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
360 | } | 361 | } |
361 | } else { | 362 | } else { |
362 | qDebug("error fetching body: %s",m_imap->imap_response); | 363 | qDebug("error fetching body: %s",m_imap->imap_response); |
363 | } | 364 | } |
364 | mailimap_fetch_list_free(result); | 365 | mailimap_fetch_list_free(result); |
365 | return body; | 366 | return body; |
366 | } | 367 | } |
367 | 368 | ||
368 | /* this routine is just called when the mail has only ONE part. | 369 | /* this routine is just called when the mail has only ONE part. |
369 | for filling the parts of a multi-part-message there are other | 370 | for filling the parts of a multi-part-message there are other |
370 | routines 'cause we can not simply fetch the whole body. */ | 371 | routines 'cause we can not simply fetch the whole body. */ |
371 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 372 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
372 | { | 373 | { |
373 | if (!mailDescription) { | 374 | if (!mailDescription) { |
374 | return; | 375 | return; |
375 | } | 376 | } |
376 | QString sub,body_text; | 377 | QString sub,body_text; |
377 | RecPart singlePart; | 378 | RecPart singlePart; |
378 | QValueList<int> path; | 379 | QValueList<int> path; |
379 | fillSinglePart(singlePart,mailDescription); | 380 | fillSinglePart(singlePart,mailDescription); |
380 | switch (mailDescription->bd_type) { | 381 | switch (mailDescription->bd_type) { |
381 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 382 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
382 | path.append(1); | 383 | path.append(1); |
383 | body_text = fetchPart(mail,path,true); | 384 | body_text = fetchPart(mail,path,true); |
384 | target_body.setBodytext(body_text); | 385 | target_body.setBodytext(body_text); |
385 | target_body.setDescription(singlePart); | 386 | target_body.setDescription(singlePart); |
386 | break; | 387 | break; |
387 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 388 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
388 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 389 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
389 | path.append(1); | 390 | path.append(1); |
390 | body_text = fetchPart(mail,path,true); | 391 | body_text = fetchPart(mail,path,true); |
391 | target_body.setBodytext(body_text); | 392 | target_body.setBodytext(body_text); |
392 | target_body.setDescription(singlePart); | 393 | target_body.setDescription(singlePart); |
393 | break; | 394 | break; |
394 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 395 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
395 | qDebug("Single attachment"); | 396 | qDebug("Single attachment"); |
396 | target_body.setBodytext(""); | 397 | target_body.setBodytext(""); |
397 | target_body.addPart(singlePart); | 398 | target_body.addPart(singlePart); |
398 | break; | 399 | break; |
399 | default: | 400 | default: |
400 | break; | 401 | break; |
401 | } | 402 | } |
402 | 403 | ||
403 | return; | 404 | return; |
404 | } | 405 | } |
405 | 406 | ||
406 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 407 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
407 | { | 408 | { |
408 | QStringList l; | 409 | QStringList l; |
409 | QString from; | 410 | QString from; |
410 | bool named_from; | 411 | bool named_from; |
411 | clistcell *current = NULL; | 412 | clistcell *current = NULL; |
412 | mailimap_address * current_address=NULL; | 413 | mailimap_address * current_address=NULL; |
413 | if (!list) { | 414 | if (!list) { |
414 | return l; | 415 | return l; |
415 | } | 416 | } |
416 | unsigned int count = 0; | 417 | unsigned int count = 0; |
417 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 418 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
418 | from = ""; | 419 | from = ""; |
419 | named_from = false; | 420 | named_from = false; |
420 | current_address=(mailimap_address*)current->data; | 421 | current_address=(mailimap_address*)current->data; |
421 | if (current_address->ad_personal_name){ | 422 | if (current_address->ad_personal_name){ |
422 | from+=QString(current_address->ad_personal_name); | 423 | from+=QString(current_address->ad_personal_name); |
423 | from+=" "; | 424 | from+=" "; |
424 | named_from = true; | 425 | named_from = true; |
425 | } | 426 | } |
426 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 427 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
427 | from+="<"; | 428 | from+="<"; |
428 | } | 429 | } |
429 | if (current_address->ad_mailbox_name) { | 430 | if (current_address->ad_mailbox_name) { |
430 | from+=QString(current_address->ad_mailbox_name); | 431 | from+=QString(current_address->ad_mailbox_name); |
431 | from+="@"; | 432 | from+="@"; |
432 | } | 433 | } |
433 | if (current_address->ad_host_name) { | 434 | if (current_address->ad_host_name) { |
434 | from+=QString(current_address->ad_host_name); | 435 | from+=QString(current_address->ad_host_name); |
435 | } | 436 | } |
436 | 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)) { |
437 | from+=">"; | 438 | from+=">"; |
438 | } | 439 | } |
439 | l.append(QString(from)); | 440 | l.append(QString(from)); |
440 | if (++count > 99) { | 441 | if (++count > 99) { |
441 | break; | 442 | break; |
442 | } | 443 | } |
443 | } | 444 | } |
444 | return l; | 445 | return l; |
445 | } | 446 | } |
446 | 447 | ||
447 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 448 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
448 | { | 449 | { |
449 | QString body(""); | 450 | QString body(""); |
450 | const char*mb; | 451 | const char*mb; |
451 | int err; | 452 | int err; |
452 | mailimap_fetch_type *fetchType; | 453 | mailimap_fetch_type *fetchType; |
453 | mailimap_set *set; | 454 | mailimap_set *set; |
454 | clistcell*current,*cur; | 455 | clistcell*current,*cur; |
455 | 456 | ||
456 | login(); | 457 | login(); |
457 | if (!m_imap) { | 458 | if (!m_imap) { |
458 | return body; | 459 | return body; |
459 | } | 460 | } |
460 | if (!internal_call) { | 461 | if (!internal_call) { |
461 | mb = mail.getMbox().latin1(); | 462 | mb = mail.getMbox().latin1(); |
462 | err = mailimap_select( m_imap, (char*)mb); | 463 | err = mailimap_select( m_imap, (char*)mb); |
463 | if ( err != MAILIMAP_NO_ERROR ) { | 464 | if ( err != MAILIMAP_NO_ERROR ) { |
464 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 465 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
465 | return body; | 466 | return body; |
466 | } | 467 | } |
467 | } | 468 | } |
468 | set = mailimap_set_new_single(mail.getNumber()); | 469 | set = mailimap_set_new_single(mail.getNumber()); |
469 | clist*id_list=clist_new(); | 470 | clist*id_list=clist_new(); |
470 | for (unsigned j=0; j < path.count();++j) { | 471 | for (unsigned j=0; j < path.count();++j) { |
471 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 472 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
472 | *p_id = path[j]; | 473 | *p_id = path[j]; |
473 | clist_append(id_list,p_id); | 474 | clist_append(id_list,p_id); |
474 | } | 475 | } |
475 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 476 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
476 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 477 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
477 | mailimap_section * section = mailimap_section_new(section_spec); | 478 | mailimap_section * section = mailimap_section_new(section_spec); |
478 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 479 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
479 | 480 | ||
480 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 481 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
481 | 482 | ||
482 | clist*result = clist_new(); | 483 | clist*result = clist_new(); |
483 | 484 | ||
484 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 485 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
485 | mailimap_set_free( set ); | 486 | mailimap_set_free( set ); |
486 | mailimap_fetch_type_free( fetchType ); | 487 | mailimap_fetch_type_free( fetchType ); |
487 | 488 | ||
488 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 489 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
489 | mailimap_msg_att * msg_att; | 490 | mailimap_msg_att * msg_att; |
490 | msg_att = (mailimap_msg_att*)current->data; | 491 | msg_att = (mailimap_msg_att*)current->data; |
491 | mailimap_msg_att_item*msg_att_item; | 492 | mailimap_msg_att_item*msg_att_item; |
492 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 493 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
493 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 494 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
494 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 495 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
495 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 496 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
496 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 497 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
497 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 498 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
498 | if (text) { | 499 | if (text) { |
499 | body = QString(text); | 500 | body = QString(text); |
500 | free(text); | 501 | free(text); |
501 | } else { | 502 | } else { |
502 | body = ""; | 503 | body = ""; |
503 | } | 504 | } |
504 | } | 505 | } |
505 | } | 506 | } |
506 | } | 507 | } |
507 | 508 | ||
508 | } else { | 509 | } else { |
509 | qDebug("error fetching text: %s",m_imap->imap_response); | 510 | qDebug("error fetching text: %s",m_imap->imap_response); |
510 | } | 511 | } |
511 | mailimap_fetch_list_free(result); | 512 | mailimap_fetch_list_free(result); |
512 | return body; | 513 | return body; |
513 | } | 514 | } |
514 | 515 | ||
515 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 516 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
516 | { | 517 | { |
517 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 518 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
518 | if (!mailDescription||current_recursion==10) { | 519 | if (!mailDescription||current_recursion==10) { |
519 | return; | 520 | return; |
520 | } | 521 | } |
521 | clistcell*current; | 522 | clistcell*current; |
522 | mailimap_body*current_body; | 523 | mailimap_body*current_body; |
523 | unsigned int count = 0; | 524 | unsigned int count = 0; |
524 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 525 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
525 | /* the point in the message */ | 526 | /* the point in the message */ |
526 | ++count; | 527 | ++count; |
527 | current_body = (mailimap_body*)current->data; | 528 | current_body = (mailimap_body*)current->data; |
528 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 529 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
529 | QValueList<int>clist = recList; | 530 | QValueList<int>clist = recList; |
530 | clist.append(count); | 531 | clist.append(count); |
531 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 532 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
532 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 533 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
533 | RecPart currentPart; | 534 | RecPart currentPart; |
534 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 535 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
535 | QValueList<int>clist = recList; | 536 | QValueList<int>clist = recList; |
536 | clist.append(count); | 537 | clist.append(count); |
537 | /* important: Check for is NULL 'cause a body can be empty! */ | 538 | /* important: Check for is NULL 'cause a body can be empty! */ |
538 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 539 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
539 | QString body_text = fetchPart(mail,clist,true); | 540 | QString body_text = fetchPart(mail,clist,true); |
540 | target_body.setDescription(currentPart); | 541 | target_body.setDescription(currentPart); |
541 | target_body.setBodytext(body_text); | 542 | target_body.setBodytext(body_text); |
542 | } else { | 543 | } else { |
543 | QString id(""); | 544 | QString id(""); |
544 | for (unsigned int j = 0; j < clist.count();++j) { | 545 | for (unsigned int j = 0; j < clist.count();++j) { |
545 | id+=(j>0?" ":""); | 546 | id+=(j>0?" ":""); |
546 | id+=QString("%1").arg(clist[j]); | 547 | id+=QString("%1").arg(clist[j]); |
547 | } | 548 | } |
548 | qDebug("ID= %s",id.latin1()); | 549 | qDebug("ID= %s",id.latin1()); |
549 | currentPart.setIdentifier(id); | 550 | currentPart.setIdentifier(id); |
550 | currentPart.setPositionlist(clist); | 551 | currentPart.setPositionlist(clist); |
551 | target_body.addPart(currentPart); | 552 | target_body.addPart(currentPart); |
552 | } | 553 | } |
553 | } | 554 | } |
554 | } | 555 | } |
555 | } | 556 | } |
556 | 557 | ||
557 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 558 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
558 | { | 559 | { |
559 | if (!Description) { | 560 | if (!Description) { |
560 | return; | 561 | return; |
561 | } | 562 | } |
562 | switch (Description->bd_type) { | 563 | switch (Description->bd_type) { |
563 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 564 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
564 | target_part.setType("text"); | 565 | target_part.setType("text"); |
565 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 566 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
566 | break; | 567 | break; |
567 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 568 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
568 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 569 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
569 | break; | 570 | break; |
570 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 571 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
571 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 572 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
572 | break; | 573 | break; |
573 | default: | 574 | default: |
574 | break; | 575 | break; |
575 | } | 576 | } |
576 | } | 577 | } |
577 | 578 | ||
578 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 579 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
579 | { | 580 | { |
580 | if (!which) { | 581 | if (!which) { |
581 | return; | 582 | return; |
582 | } | 583 | } |
583 | QString sub; | 584 | QString sub; |
584 | sub = which->bd_media_text; | 585 | sub = which->bd_media_text; |
585 | target_part.setSubtype(sub.lower()); | 586 | target_part.setSubtype(sub.lower()); |
586 | target_part.setLines(which->bd_lines); | 587 | target_part.setLines(which->bd_lines); |
587 | fillBodyFields(target_part,which->bd_fields); | 588 | fillBodyFields(target_part,which->bd_fields); |
588 | } | 589 | } |
589 | 590 | ||
590 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 591 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
591 | { | 592 | { |
592 | if (!which) { | 593 | if (!which) { |
593 | return; | 594 | return; |
594 | } | 595 | } |
595 | // QString sub; | 596 | // QString sub; |
596 | // sub = which->bd_media_text; | 597 | // sub = which->bd_media_text; |
597 | // target_part.setSubtype(sub.lower()); | 598 | // target_part.setSubtype(sub.lower()); |
598 | qDebug("Message part"); | 599 | qDebug("Message part"); |
599 | /* we set this type to text/plain */ | 600 | /* we set this type to text/plain */ |
600 | target_part.setType("text"); | 601 | target_part.setType("text"); |
601 | target_part.setSubtype("plain"); | 602 | target_part.setSubtype("plain"); |
602 | target_part.setLines(which->bd_lines); | 603 | target_part.setLines(which->bd_lines); |
603 | fillBodyFields(target_part,which->bd_fields); | 604 | fillBodyFields(target_part,which->bd_fields); |
604 | } | 605 | } |
605 | 606 | ||
606 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 607 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
607 | { | 608 | { |
608 | if (!which) { | 609 | if (!which) { |
609 | return; | 610 | return; |
610 | } | 611 | } |
611 | QString type,sub; | 612 | QString type,sub; |
612 | switch (which->bd_media_basic->med_type) { | 613 | switch (which->bd_media_basic->med_type) { |
613 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 614 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
614 | type = "application"; | 615 | type = "application"; |
615 | break; | 616 | break; |
616 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 617 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
617 | type = "audio"; | 618 | type = "audio"; |
618 | break; | 619 | break; |
619 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 620 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
620 | type = "image"; | 621 | type = "image"; |
621 | break; | 622 | break; |
622 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 623 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
623 | type = "message"; | 624 | type = "message"; |
624 | break; | 625 | break; |
625 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 626 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
626 | type = "video"; | 627 | type = "video"; |
627 | break; | 628 | break; |
628 | case MAILIMAP_MEDIA_BASIC_OTHER: | 629 | case MAILIMAP_MEDIA_BASIC_OTHER: |
629 | default: | 630 | default: |
630 | if (which->bd_media_basic->med_basic_type) { | 631 | if (which->bd_media_basic->med_basic_type) { |
631 | type = which->bd_media_basic->med_basic_type; | 632 | type = which->bd_media_basic->med_basic_type; |
632 | } else { | 633 | } else { |
633 | type = ""; | 634 | type = ""; |
634 | } | 635 | } |
635 | break; | 636 | break; |
636 | } | 637 | } |
637 | if (which->bd_media_basic->med_subtype) { | 638 | if (which->bd_media_basic->med_subtype) { |
638 | sub = which->bd_media_basic->med_subtype; | 639 | sub = which->bd_media_basic->med_subtype; |
639 | } else { | 640 | } else { |
640 | sub = ""; | 641 | sub = ""; |
641 | } | 642 | } |
642 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 643 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
643 | target_part.setType(type.lower()); | 644 | target_part.setType(type.lower()); |
644 | target_part.setSubtype(sub.lower()); | 645 | target_part.setSubtype(sub.lower()); |
645 | fillBodyFields(target_part,which->bd_fields); | 646 | fillBodyFields(target_part,which->bd_fields); |
646 | } | 647 | } |
647 | 648 | ||
648 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 649 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
649 | { | 650 | { |
650 | if (!which) return; | 651 | if (!which) return; |
651 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 652 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
652 | clistcell*cur; | 653 | clistcell*cur; |
653 | mailimap_single_body_fld_param*param=0; | 654 | mailimap_single_body_fld_param*param=0; |
654 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 655 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
655 | param = (mailimap_single_body_fld_param*)cur->data; | 656 | param = (mailimap_single_body_fld_param*)cur->data; |
656 | if (param) { | 657 | if (param) { |
657 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 658 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
658 | } | 659 | } |
659 | } | 660 | } |
660 | } | 661 | } |
661 | mailimap_body_fld_enc*enc = which->bd_encoding; | 662 | mailimap_body_fld_enc*enc = which->bd_encoding; |
662 | QString encoding(""); | 663 | QString encoding(""); |
663 | switch (enc->enc_type) { | 664 | switch (enc->enc_type) { |
664 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 665 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
665 | encoding = "7bit"; | 666 | encoding = "7bit"; |
666 | break; | 667 | break; |
667 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 668 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
668 | encoding = "8bit"; | 669 | encoding = "8bit"; |
669 | break; | 670 | break; |
670 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 671 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
671 | encoding="binary"; | 672 | encoding="binary"; |
672 | break; | 673 | break; |
673 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 674 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
674 | encoding="base64"; | 675 | encoding="base64"; |
675 | break; | 676 | break; |
676 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 677 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
677 | encoding="quoted-printable"; | 678 | encoding="quoted-printable"; |
678 | break; | 679 | break; |
679 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 680 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
680 | default: | 681 | default: |
681 | if (enc->enc_value) { | 682 | if (enc->enc_value) { |
682 | char*t=enc->enc_value; | 683 | char*t=enc->enc_value; |
683 | encoding=QString(enc->enc_value); | 684 | encoding=QString(enc->enc_value); |
684 | enc->enc_value=0L; | 685 | enc->enc_value=0L; |
685 | free(t); | 686 | free(t); |
686 | } | 687 | } |
687 | } | 688 | } |
688 | target_part.setEncoding(encoding); | 689 | target_part.setEncoding(encoding); |
689 | target_part.setSize(which->bd_size); | 690 | target_part.setSize(which->bd_size); |
690 | } | 691 | } |
691 | 692 | ||
692 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | 693 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) |
693 | { | 694 | { |
694 | return fetchPart(mail,part.Positionlist(),false); | 695 | return fetchPart(mail,part.Positionlist(),false); |
695 | } | 696 | } |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 11bf3b8..48e476b 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,695 +1,696 @@ | |||
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 | ||
8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 8 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
9 | { | 9 | { |
10 | account = a; | 10 | account = a; |
11 | m_imap = 0; | 11 | m_imap = 0; |
12 | } | 12 | } |
13 | 13 | ||
14 | IMAPwrapper::~IMAPwrapper() | 14 | IMAPwrapper::~IMAPwrapper() |
15 | { | 15 | { |
16 | logout(); | 16 | logout(); |
17 | } | 17 | } |
18 | 18 | ||
19 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 19 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
20 | { | 20 | { |
21 | qDebug( "IMAP: %i of %i", current, maximum ); | 21 | qDebug( "IMAP: %i of %i", current, maximum ); |
22 | } | 22 | } |
23 | 23 | ||
24 | void IMAPwrapper::login() | 24 | void IMAPwrapper::login() |
25 | { | 25 | { |
26 | const char *server, *user, *pass; | 26 | const char *server, *user, *pass; |
27 | uint16_t port; | 27 | uint16_t port; |
28 | int err = MAILIMAP_NO_ERROR; | 28 | int err = MAILIMAP_NO_ERROR; |
29 | 29 | ||
30 | /* we are connected this moment */ | 30 | /* we are connected this moment */ |
31 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 31 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
32 | if (m_imap) { | 32 | if (m_imap) { |
33 | mailstream_flush(m_imap->imap_stream); | ||
33 | return; | 34 | return; |
34 | } | 35 | } |
35 | server = account->getServer().latin1(); | 36 | server = account->getServer().latin1(); |
36 | port = account->getPort().toUInt(); | 37 | port = account->getPort().toUInt(); |
37 | user = account->getUser().latin1(); | 38 | user = account->getUser().latin1(); |
38 | pass = account->getPassword().latin1(); | 39 | pass = account->getPassword().latin1(); |
39 | 40 | ||
40 | m_imap = mailimap_new( 20, &imap_progress ); | 41 | m_imap = mailimap_new( 20, &imap_progress ); |
41 | /* connect */ | 42 | /* connect */ |
42 | if (account->getSSL()) { | 43 | if (account->getSSL()) { |
43 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 44 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
44 | } else { | 45 | } else { |
45 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 46 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
46 | } | 47 | } |
47 | 48 | ||
48 | if ( err != MAILIMAP_NO_ERROR && | 49 | if ( err != MAILIMAP_NO_ERROR && |
49 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 50 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
50 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 51 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
51 | qDebug("error connecting server: %s",m_imap->imap_response); | 52 | qDebug("error connecting server: %s",m_imap->imap_response); |
52 | mailimap_free( m_imap ); | 53 | mailimap_free( m_imap ); |
53 | m_imap = 0; | 54 | m_imap = 0; |
54 | return; | 55 | return; |
55 | } | 56 | } |
56 | 57 | ||
57 | /* login */ | 58 | /* login */ |
58 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 59 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
59 | if ( err != MAILIMAP_NO_ERROR ) { | 60 | if ( err != MAILIMAP_NO_ERROR ) { |
60 | qDebug("error logging in imap: %s",m_imap->imap_response); | 61 | qDebug("error logging in imap: %s",m_imap->imap_response); |
61 | err = mailimap_close( m_imap ); | 62 | err = mailimap_close( m_imap ); |
62 | mailimap_free( m_imap ); | 63 | mailimap_free( m_imap ); |
63 | m_imap = 0; | 64 | m_imap = 0; |
64 | } | 65 | } |
65 | } | 66 | } |
66 | 67 | ||
67 | void IMAPwrapper::logout() | 68 | void IMAPwrapper::logout() |
68 | { | 69 | { |
69 | int err = MAILIMAP_NO_ERROR; | 70 | int err = MAILIMAP_NO_ERROR; |
70 | if (!m_imap) return; | 71 | if (!m_imap) return; |
71 | err = mailimap_logout( m_imap ); | 72 | err = mailimap_logout( m_imap ); |
72 | err = mailimap_close( m_imap ); | 73 | err = mailimap_close( m_imap ); |
73 | mailimap_free( m_imap ); | 74 | mailimap_free( m_imap ); |
74 | m_imap = 0; | 75 | m_imap = 0; |
75 | } | 76 | } |
76 | 77 | ||
77 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 78 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
78 | { | 79 | { |
79 | const char *mb; | 80 | const char *mb; |
80 | int err = MAILIMAP_NO_ERROR; | 81 | int err = MAILIMAP_NO_ERROR; |
81 | clist *result; | 82 | clist *result; |
82 | clistcell *current; | 83 | clistcell *current; |
83 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 84 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
84 | mailimap_fetch_type *fetchType; | 85 | mailimap_fetch_type *fetchType; |
85 | mailimap_set *set; | 86 | mailimap_set *set; |
86 | 87 | ||
87 | mb = mailbox.latin1(); | 88 | mb = mailbox.latin1(); |
88 | login(); | 89 | login(); |
89 | if (!m_imap) { | 90 | if (!m_imap) { |
90 | return; | 91 | return; |
91 | } | 92 | } |
92 | /* select mailbox READONLY for operations */ | 93 | /* select mailbox READONLY for operations */ |
93 | err = mailimap_examine( m_imap, (char*)mb); | 94 | err = mailimap_examine( m_imap, (char*)mb); |
94 | if ( err != MAILIMAP_NO_ERROR ) { | 95 | if ( err != MAILIMAP_NO_ERROR ) { |
95 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 96 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
96 | return; | 97 | return; |
97 | } | 98 | } |
98 | 99 | ||
99 | int last = m_imap->imap_selection_info->sel_exists; | 100 | int last = m_imap->imap_selection_info->sel_exists; |
100 | 101 | ||
101 | if (last == 0) { | 102 | if (last == 0) { |
102 | qDebug("mailbox has no mails"); | 103 | qDebug("mailbox has no mails"); |
103 | return; | 104 | return; |
104 | } | 105 | } |
105 | 106 | ||
106 | result = clist_new(); | 107 | result = clist_new(); |
107 | /* the range has to start at 1!!! not with 0!!!! */ | 108 | /* the range has to start at 1!!! not with 0!!!! */ |
108 | set = mailimap_set_new_interval( 1, last ); | 109 | set = mailimap_set_new_interval( 1, last ); |
109 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 110 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
110 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 111 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
111 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
114 | 115 | ||
115 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 116 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
116 | mailimap_set_free( set ); | 117 | mailimap_set_free( set ); |
117 | mailimap_fetch_type_free( fetchType ); | 118 | mailimap_fetch_type_free( fetchType ); |
118 | 119 | ||
119 | QString date,subject,from; | 120 | QString date,subject,from; |
120 | 121 | ||
121 | if ( err == MAILIMAP_NO_ERROR ) { | 122 | if ( err == MAILIMAP_NO_ERROR ) { |
122 | 123 | ||
123 | mailimap_msg_att * msg_att; | 124 | mailimap_msg_att * msg_att; |
124 | int i = 0; | 125 | int i = 0; |
125 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 126 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
126 | ++i; | 127 | ++i; |
127 | msg_att = (mailimap_msg_att*)current->data; | 128 | msg_att = (mailimap_msg_att*)current->data; |
128 | RecMail*m = parse_list_result(msg_att); | 129 | RecMail*m = parse_list_result(msg_att); |
129 | if (m) { | 130 | if (m) { |
130 | m->setNumber(i); | 131 | m->setNumber(i); |
131 | m->setMbox(mailbox); | 132 | m->setMbox(mailbox); |
132 | target.append(m); | 133 | target.append(m); |
133 | } | 134 | } |
134 | } | 135 | } |
135 | } else { | 136 | } else { |
136 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 137 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
137 | } | 138 | } |
138 | mailimap_fetch_list_free(result); | 139 | mailimap_fetch_list_free(result); |
139 | } | 140 | } |
140 | 141 | ||
141 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 142 | QList<IMAPFolder>* IMAPwrapper::listFolders() |
142 | { | 143 | { |
143 | const char *path, *mask; | 144 | const char *path, *mask; |
144 | int err = MAILIMAP_NO_ERROR; | 145 | int err = MAILIMAP_NO_ERROR; |
145 | clist *result; | 146 | clist *result; |
146 | clistcell *current; | 147 | clistcell *current; |
147 | 148 | ||
148 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); | 149 | QList<IMAPFolder> * folders = new QList<IMAPFolder>(); |
149 | folders->setAutoDelete( true ); | 150 | folders->setAutoDelete( true ); |
150 | login(); | 151 | login(); |
151 | if (!m_imap) { | 152 | if (!m_imap) { |
152 | return folders; | 153 | return folders; |
153 | } | 154 | } |
154 | 155 | ||
155 | /* | 156 | /* |
156 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 157 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
157 | * We must not forget to filter them out in next loop! | 158 | * We must not forget to filter them out in next loop! |
158 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 159 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
159 | */ | 160 | */ |
160 | QString temp; | 161 | QString temp; |
161 | mask = "INBOX" ; | 162 | mask = "INBOX" ; |
162 | result = clist_new(); | 163 | result = clist_new(); |
163 | mailimap_mailbox_list *list; | 164 | mailimap_mailbox_list *list; |
164 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 165 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
165 | if ( err == MAILIMAP_NO_ERROR ) { | 166 | if ( err == MAILIMAP_NO_ERROR ) { |
166 | current = result->first; | 167 | current = result->first; |
167 | for ( int i = result->count; i > 0; i-- ) { | 168 | for ( int i = result->count; i > 0; i-- ) { |
168 | list = (mailimap_mailbox_list *) current->data; | 169 | list = (mailimap_mailbox_list *) current->data; |
169 | // it is better use the deep copy mechanism of qt itself | 170 | // it is better use the deep copy mechanism of qt itself |
170 | // instead of using strdup! | 171 | // instead of using strdup! |
171 | temp = list->mb_name; | 172 | temp = list->mb_name; |
172 | folders->append( new IMAPFolder(temp)); | 173 | folders->append( new IMAPFolder(temp)); |
173 | current = current->next; | 174 | current = current->next; |
174 | } | 175 | } |
175 | } else { | 176 | } else { |
176 | qDebug("error fetching folders: %s",m_imap->imap_response); | 177 | qDebug("error fetching folders: %s",m_imap->imap_response); |
177 | } | 178 | } |
178 | mailimap_list_result_free( result ); | 179 | mailimap_list_result_free( result ); |
179 | 180 | ||
180 | /* | 181 | /* |
181 | * second stage - get the other then inbox folders | 182 | * second stage - get the other then inbox folders |
182 | */ | 183 | */ |
183 | mask = "*" ; | 184 | mask = "*" ; |
184 | path = account->getPrefix().latin1(); | 185 | path = account->getPrefix().latin1(); |
185 | if (!path) path = ""; | 186 | if (!path) path = ""; |
186 | result = clist_new(); | 187 | result = clist_new(); |
187 | qDebug(path); | 188 | qDebug(path); |
188 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 189 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
189 | if ( err == MAILIMAP_NO_ERROR ) { | 190 | if ( err == MAILIMAP_NO_ERROR ) { |
190 | current = result->first; | 191 | current = result->first; |
191 | for ( int i = result->count; i > 0; i-- ) { | 192 | for ( int i = result->count; i > 0; i-- ) { |
192 | list = (mailimap_mailbox_list *) current->data; | 193 | list = (mailimap_mailbox_list *) current->data; |
193 | // it is better use the deep copy mechanism of qt itself | 194 | // it is better use the deep copy mechanism of qt itself |
194 | // instead of using strdup! | 195 | // instead of using strdup! |
195 | temp = list->mb_name; | 196 | temp = list->mb_name; |
196 | current = current->next; | 197 | current = current->next; |
197 | if (temp.lower()=="inbox") | 198 | if (temp.lower()=="inbox") |
198 | continue; | 199 | continue; |
199 | folders->append(new IMAPFolder(temp)); | 200 | folders->append(new IMAPFolder(temp)); |
200 | 201 | ||
201 | } | 202 | } |
202 | } else { | 203 | } else { |
203 | qDebug("error fetching folders %s",m_imap->imap_response); | 204 | qDebug("error fetching folders %s",m_imap->imap_response); |
204 | } | 205 | } |
205 | mailimap_list_result_free( result ); | 206 | mailimap_list_result_free( result ); |
206 | return folders; | 207 | return folders; |
207 | } | 208 | } |
208 | 209 | ||
209 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 210 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
210 | { | 211 | { |
211 | RecMail * m = 0; | 212 | RecMail * m = 0; |
212 | mailimap_msg_att_item *item=0; | 213 | mailimap_msg_att_item *item=0; |
213 | clistcell *current,*c,*cf; | 214 | clistcell *current,*c,*cf; |
214 | mailimap_msg_att_dynamic*flist; | 215 | mailimap_msg_att_dynamic*flist; |
215 | mailimap_flag_fetch*cflag; | 216 | mailimap_flag_fetch*cflag; |
216 | int size; | 217 | int size; |
217 | QBitArray mFlags(7); | 218 | QBitArray mFlags(7); |
218 | QStringList addresslist; | 219 | QStringList addresslist; |
219 | 220 | ||
220 | if (!m_att) { | 221 | if (!m_att) { |
221 | return m; | 222 | return m; |
222 | } | 223 | } |
223 | m = new RecMail(); | 224 | m = new RecMail(); |
224 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 225 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
225 | current = c; | 226 | current = c; |
226 | size = 0; | 227 | size = 0; |
227 | item = (mailimap_msg_att_item*)current->data; | 228 | item = (mailimap_msg_att_item*)current->data; |
228 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 229 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
229 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 230 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
230 | if (!flist->att_list) { | 231 | if (!flist->att_list) { |
231 | continue; | 232 | continue; |
232 | } | 233 | } |
233 | cf = flist->att_list->first; | 234 | cf = flist->att_list->first; |
234 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 235 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
235 | cflag = (mailimap_flag_fetch*)cf->data; | 236 | cflag = (mailimap_flag_fetch*)cf->data; |
236 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 237 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
237 | switch (cflag->fl_flag->fl_type) { | 238 | switch (cflag->fl_flag->fl_type) { |
238 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 239 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
239 | mFlags.setBit(FLAG_ANSWERED); | 240 | mFlags.setBit(FLAG_ANSWERED); |
240 | break; | 241 | break; |
241 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 242 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
242 | mFlags.setBit(FLAG_FLAGGED); | 243 | mFlags.setBit(FLAG_FLAGGED); |
243 | break; | 244 | break; |
244 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 245 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
245 | mFlags.setBit(FLAG_DELETED); | 246 | mFlags.setBit(FLAG_DELETED); |
246 | break; | 247 | break; |
247 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 248 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
248 | mFlags.setBit(FLAG_SEEN); | 249 | mFlags.setBit(FLAG_SEEN); |
249 | break; | 250 | break; |
250 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 251 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
251 | mFlags.setBit(FLAG_DRAFT); | 252 | mFlags.setBit(FLAG_DRAFT); |
252 | break; | 253 | break; |
253 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 254 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
254 | break; | 255 | break; |
255 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 256 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
256 | break; | 257 | break; |
257 | default: | 258 | default: |
258 | break; | 259 | break; |
259 | } | 260 | } |
260 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 261 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
261 | mFlags.setBit(FLAG_RECENT); | 262 | mFlags.setBit(FLAG_RECENT); |
262 | } | 263 | } |
263 | } | 264 | } |
264 | continue; | 265 | continue; |
265 | } | 266 | } |
266 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 267 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
267 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 268 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
268 | m->setDate(head->env_date); | 269 | m->setDate(head->env_date); |
269 | m->setSubject(head->env_subject); | 270 | m->setSubject(head->env_subject); |
270 | if (head->env_from!=NULL) { | 271 | if (head->env_from!=NULL) { |
271 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 272 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
272 | if (addresslist.count()) { | 273 | if (addresslist.count()) { |
273 | m->setFrom(addresslist.first()); | 274 | m->setFrom(addresslist.first()); |
274 | } | 275 | } |
275 | } | 276 | } |
276 | if (head->env_to!=NULL) { | 277 | if (head->env_to!=NULL) { |
277 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 278 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
278 | m->setTo(addresslist); | 279 | m->setTo(addresslist); |
279 | } | 280 | } |
280 | if (head->env_cc!=NULL) { | 281 | if (head->env_cc!=NULL) { |
281 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 282 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
282 | m->setCC(addresslist); | 283 | m->setCC(addresslist); |
283 | } | 284 | } |
284 | if (head->env_bcc!=NULL) { | 285 | if (head->env_bcc!=NULL) { |
285 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 286 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
286 | m->setBcc(addresslist); | 287 | m->setBcc(addresslist); |
287 | } | 288 | } |
288 | if (head->env_reply_to!=NULL) { | 289 | if (head->env_reply_to!=NULL) { |
289 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 290 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
290 | if (addresslist.count()) { | 291 | if (addresslist.count()) { |
291 | m->setReplyto(addresslist.first()); | 292 | m->setReplyto(addresslist.first()); |
292 | } | 293 | } |
293 | } | 294 | } |
294 | m->setMsgid(QString(head->env_message_id)); | 295 | m->setMsgid(QString(head->env_message_id)); |
295 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 296 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
296 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 297 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
297 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 298 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
298 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 299 | 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); |
299 | qDebug(da.toString()); | 300 | qDebug(da.toString()); |
300 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 301 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
301 | size = item->att_data.att_static->att_data.att_rfc822_size; | 302 | size = item->att_data.att_static->att_data.att_rfc822_size; |
302 | } | 303 | } |
303 | } | 304 | } |
304 | /* msg is already deleted */ | 305 | /* msg is already deleted */ |
305 | if (mFlags.testBit(FLAG_DELETED) && m) { | 306 | if (mFlags.testBit(FLAG_DELETED) && m) { |
306 | delete m; | 307 | delete m; |
307 | m = 0; | 308 | m = 0; |
308 | } | 309 | } |
309 | if (m) { | 310 | if (m) { |
310 | m->setFlags(mFlags); | 311 | m->setFlags(mFlags); |
311 | m->setMsgsize(size); | 312 | m->setMsgsize(size); |
312 | } | 313 | } |
313 | return m; | 314 | return m; |
314 | } | 315 | } |
315 | 316 | ||
316 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 317 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
317 | { | 318 | { |
318 | RecBody body; | 319 | RecBody body; |
319 | const char *mb; | 320 | const char *mb; |
320 | int err = MAILIMAP_NO_ERROR; | 321 | int err = MAILIMAP_NO_ERROR; |
321 | clist *result; | 322 | clist *result; |
322 | clistcell *current; | 323 | clistcell *current; |
323 | mailimap_fetch_att *fetchAtt; | 324 | mailimap_fetch_att *fetchAtt; |
324 | mailimap_fetch_type *fetchType; | 325 | mailimap_fetch_type *fetchType; |
325 | mailimap_set *set; | 326 | mailimap_set *set; |
326 | mailimap_body*body_desc; | 327 | mailimap_body*body_desc; |
327 | 328 | ||
328 | mb = mail.getMbox().latin1(); | 329 | mb = mail.getMbox().latin1(); |
329 | 330 | ||
330 | login(); | 331 | login(); |
331 | if (!m_imap) { | 332 | if (!m_imap) { |
332 | return body; | 333 | return body; |
333 | } | 334 | } |
334 | 335 | ||
335 | err = mailimap_select( m_imap, (char*)mb); | 336 | err = mailimap_select( m_imap, (char*)mb); |
336 | if ( err != MAILIMAP_NO_ERROR ) { | 337 | if ( err != MAILIMAP_NO_ERROR ) { |
337 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 338 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
338 | return body; | 339 | return body; |
339 | } | 340 | } |
340 | 341 | ||
341 | result = clist_new(); | 342 | result = clist_new(); |
342 | /* the range has to start at 1!!! not with 0!!!! */ | 343 | /* the range has to start at 1!!! not with 0!!!! */ |
343 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 344 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
344 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 345 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
345 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 346 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
346 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 347 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
347 | mailimap_set_free( set ); | 348 | mailimap_set_free( set ); |
348 | mailimap_fetch_type_free( fetchType ); | 349 | mailimap_fetch_type_free( fetchType ); |
349 | 350 | ||
350 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 351 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
351 | mailimap_msg_att * msg_att; | 352 | mailimap_msg_att * msg_att; |
352 | msg_att = (mailimap_msg_att*)current->data; | 353 | msg_att = (mailimap_msg_att*)current->data; |
353 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 354 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
354 | body_desc = item->att_data.att_static->att_data.att_body; | 355 | body_desc = item->att_data.att_static->att_data.att_body; |
355 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 356 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
356 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 357 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
357 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 358 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
358 | qDebug("Mulitpart mail"); | 359 | qDebug("Mulitpart mail"); |
359 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 360 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
360 | } | 361 | } |
361 | } else { | 362 | } else { |
362 | qDebug("error fetching body: %s",m_imap->imap_response); | 363 | qDebug("error fetching body: %s",m_imap->imap_response); |
363 | } | 364 | } |
364 | mailimap_fetch_list_free(result); | 365 | mailimap_fetch_list_free(result); |
365 | return body; | 366 | return body; |
366 | } | 367 | } |
367 | 368 | ||
368 | /* this routine is just called when the mail has only ONE part. | 369 | /* this routine is just called when the mail has only ONE part. |
369 | for filling the parts of a multi-part-message there are other | 370 | for filling the parts of a multi-part-message there are other |
370 | routines 'cause we can not simply fetch the whole body. */ | 371 | routines 'cause we can not simply fetch the whole body. */ |
371 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 372 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
372 | { | 373 | { |
373 | if (!mailDescription) { | 374 | if (!mailDescription) { |
374 | return; | 375 | return; |
375 | } | 376 | } |
376 | QString sub,body_text; | 377 | QString sub,body_text; |
377 | RecPart singlePart; | 378 | RecPart singlePart; |
378 | QValueList<int> path; | 379 | QValueList<int> path; |
379 | fillSinglePart(singlePart,mailDescription); | 380 | fillSinglePart(singlePart,mailDescription); |
380 | switch (mailDescription->bd_type) { | 381 | switch (mailDescription->bd_type) { |
381 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 382 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
382 | path.append(1); | 383 | path.append(1); |
383 | body_text = fetchPart(mail,path,true); | 384 | body_text = fetchPart(mail,path,true); |
384 | target_body.setBodytext(body_text); | 385 | target_body.setBodytext(body_text); |
385 | target_body.setDescription(singlePart); | 386 | target_body.setDescription(singlePart); |
386 | break; | 387 | break; |
387 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 388 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
388 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 389 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
389 | path.append(1); | 390 | path.append(1); |
390 | body_text = fetchPart(mail,path,true); | 391 | body_text = fetchPart(mail,path,true); |
391 | target_body.setBodytext(body_text); | 392 | target_body.setBodytext(body_text); |
392 | target_body.setDescription(singlePart); | 393 | target_body.setDescription(singlePart); |
393 | break; | 394 | break; |
394 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 395 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
395 | qDebug("Single attachment"); | 396 | qDebug("Single attachment"); |
396 | target_body.setBodytext(""); | 397 | target_body.setBodytext(""); |
397 | target_body.addPart(singlePart); | 398 | target_body.addPart(singlePart); |
398 | break; | 399 | break; |
399 | default: | 400 | default: |
400 | break; | 401 | break; |
401 | } | 402 | } |
402 | 403 | ||
403 | return; | 404 | return; |
404 | } | 405 | } |
405 | 406 | ||
406 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 407 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
407 | { | 408 | { |
408 | QStringList l; | 409 | QStringList l; |
409 | QString from; | 410 | QString from; |
410 | bool named_from; | 411 | bool named_from; |
411 | clistcell *current = NULL; | 412 | clistcell *current = NULL; |
412 | mailimap_address * current_address=NULL; | 413 | mailimap_address * current_address=NULL; |
413 | if (!list) { | 414 | if (!list) { |
414 | return l; | 415 | return l; |
415 | } | 416 | } |
416 | unsigned int count = 0; | 417 | unsigned int count = 0; |
417 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 418 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
418 | from = ""; | 419 | from = ""; |
419 | named_from = false; | 420 | named_from = false; |
420 | current_address=(mailimap_address*)current->data; | 421 | current_address=(mailimap_address*)current->data; |
421 | if (current_address->ad_personal_name){ | 422 | if (current_address->ad_personal_name){ |
422 | from+=QString(current_address->ad_personal_name); | 423 | from+=QString(current_address->ad_personal_name); |
423 | from+=" "; | 424 | from+=" "; |
424 | named_from = true; | 425 | named_from = true; |
425 | } | 426 | } |
426 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 427 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
427 | from+="<"; | 428 | from+="<"; |
428 | } | 429 | } |
429 | if (current_address->ad_mailbox_name) { | 430 | if (current_address->ad_mailbox_name) { |
430 | from+=QString(current_address->ad_mailbox_name); | 431 | from+=QString(current_address->ad_mailbox_name); |
431 | from+="@"; | 432 | from+="@"; |
432 | } | 433 | } |
433 | if (current_address->ad_host_name) { | 434 | if (current_address->ad_host_name) { |
434 | from+=QString(current_address->ad_host_name); | 435 | from+=QString(current_address->ad_host_name); |
435 | } | 436 | } |
436 | 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)) { |
437 | from+=">"; | 438 | from+=">"; |
438 | } | 439 | } |
439 | l.append(QString(from)); | 440 | l.append(QString(from)); |
440 | if (++count > 99) { | 441 | if (++count > 99) { |
441 | break; | 442 | break; |
442 | } | 443 | } |
443 | } | 444 | } |
444 | return l; | 445 | return l; |
445 | } | 446 | } |
446 | 447 | ||
447 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 448 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
448 | { | 449 | { |
449 | QString body(""); | 450 | QString body(""); |
450 | const char*mb; | 451 | const char*mb; |
451 | int err; | 452 | int err; |
452 | mailimap_fetch_type *fetchType; | 453 | mailimap_fetch_type *fetchType; |
453 | mailimap_set *set; | 454 | mailimap_set *set; |
454 | clistcell*current,*cur; | 455 | clistcell*current,*cur; |
455 | 456 | ||
456 | login(); | 457 | login(); |
457 | if (!m_imap) { | 458 | if (!m_imap) { |
458 | return body; | 459 | return body; |
459 | } | 460 | } |
460 | if (!internal_call) { | 461 | if (!internal_call) { |
461 | mb = mail.getMbox().latin1(); | 462 | mb = mail.getMbox().latin1(); |
462 | err = mailimap_select( m_imap, (char*)mb); | 463 | err = mailimap_select( m_imap, (char*)mb); |
463 | if ( err != MAILIMAP_NO_ERROR ) { | 464 | if ( err != MAILIMAP_NO_ERROR ) { |
464 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 465 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
465 | return body; | 466 | return body; |
466 | } | 467 | } |
467 | } | 468 | } |
468 | set = mailimap_set_new_single(mail.getNumber()); | 469 | set = mailimap_set_new_single(mail.getNumber()); |
469 | clist*id_list=clist_new(); | 470 | clist*id_list=clist_new(); |
470 | for (unsigned j=0; j < path.count();++j) { | 471 | for (unsigned j=0; j < path.count();++j) { |
471 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 472 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
472 | *p_id = path[j]; | 473 | *p_id = path[j]; |
473 | clist_append(id_list,p_id); | 474 | clist_append(id_list,p_id); |
474 | } | 475 | } |
475 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 476 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
476 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 477 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
477 | mailimap_section * section = mailimap_section_new(section_spec); | 478 | mailimap_section * section = mailimap_section_new(section_spec); |
478 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 479 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
479 | 480 | ||
480 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 481 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
481 | 482 | ||
482 | clist*result = clist_new(); | 483 | clist*result = clist_new(); |
483 | 484 | ||
484 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 485 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
485 | mailimap_set_free( set ); | 486 | mailimap_set_free( set ); |
486 | mailimap_fetch_type_free( fetchType ); | 487 | mailimap_fetch_type_free( fetchType ); |
487 | 488 | ||
488 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 489 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
489 | mailimap_msg_att * msg_att; | 490 | mailimap_msg_att * msg_att; |
490 | msg_att = (mailimap_msg_att*)current->data; | 491 | msg_att = (mailimap_msg_att*)current->data; |
491 | mailimap_msg_att_item*msg_att_item; | 492 | mailimap_msg_att_item*msg_att_item; |
492 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 493 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
493 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 494 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
494 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 495 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
495 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 496 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
496 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 497 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
497 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 498 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
498 | if (text) { | 499 | if (text) { |
499 | body = QString(text); | 500 | body = QString(text); |
500 | free(text); | 501 | free(text); |
501 | } else { | 502 | } else { |
502 | body = ""; | 503 | body = ""; |
503 | } | 504 | } |
504 | } | 505 | } |
505 | } | 506 | } |
506 | } | 507 | } |
507 | 508 | ||
508 | } else { | 509 | } else { |
509 | qDebug("error fetching text: %s",m_imap->imap_response); | 510 | qDebug("error fetching text: %s",m_imap->imap_response); |
510 | } | 511 | } |
511 | mailimap_fetch_list_free(result); | 512 | mailimap_fetch_list_free(result); |
512 | return body; | 513 | return body; |
513 | } | 514 | } |
514 | 515 | ||
515 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 516 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
516 | { | 517 | { |
517 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 518 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
518 | if (!mailDescription||current_recursion==10) { | 519 | if (!mailDescription||current_recursion==10) { |
519 | return; | 520 | return; |
520 | } | 521 | } |
521 | clistcell*current; | 522 | clistcell*current; |
522 | mailimap_body*current_body; | 523 | mailimap_body*current_body; |
523 | unsigned int count = 0; | 524 | unsigned int count = 0; |
524 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 525 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
525 | /* the point in the message */ | 526 | /* the point in the message */ |
526 | ++count; | 527 | ++count; |
527 | current_body = (mailimap_body*)current->data; | 528 | current_body = (mailimap_body*)current->data; |
528 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 529 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
529 | QValueList<int>clist = recList; | 530 | QValueList<int>clist = recList; |
530 | clist.append(count); | 531 | clist.append(count); |
531 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); | 532 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); |
532 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 533 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
533 | RecPart currentPart; | 534 | RecPart currentPart; |
534 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 535 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
535 | QValueList<int>clist = recList; | 536 | QValueList<int>clist = recList; |
536 | clist.append(count); | 537 | clist.append(count); |
537 | /* important: Check for is NULL 'cause a body can be empty! */ | 538 | /* important: Check for is NULL 'cause a body can be empty! */ |
538 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 539 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
539 | QString body_text = fetchPart(mail,clist,true); | 540 | QString body_text = fetchPart(mail,clist,true); |
540 | target_body.setDescription(currentPart); | 541 | target_body.setDescription(currentPart); |
541 | target_body.setBodytext(body_text); | 542 | target_body.setBodytext(body_text); |
542 | } else { | 543 | } else { |
543 | QString id(""); | 544 | QString id(""); |
544 | for (unsigned int j = 0; j < clist.count();++j) { | 545 | for (unsigned int j = 0; j < clist.count();++j) { |
545 | id+=(j>0?" ":""); | 546 | id+=(j>0?" ":""); |
546 | id+=QString("%1").arg(clist[j]); | 547 | id+=QString("%1").arg(clist[j]); |
547 | } | 548 | } |
548 | qDebug("ID= %s",id.latin1()); | 549 | qDebug("ID= %s",id.latin1()); |
549 | currentPart.setIdentifier(id); | 550 | currentPart.setIdentifier(id); |
550 | currentPart.setPositionlist(clist); | 551 | currentPart.setPositionlist(clist); |
551 | target_body.addPart(currentPart); | 552 | target_body.addPart(currentPart); |
552 | } | 553 | } |
553 | } | 554 | } |
554 | } | 555 | } |
555 | } | 556 | } |
556 | 557 | ||
557 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 558 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
558 | { | 559 | { |
559 | if (!Description) { | 560 | if (!Description) { |
560 | return; | 561 | return; |
561 | } | 562 | } |
562 | switch (Description->bd_type) { | 563 | switch (Description->bd_type) { |
563 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 564 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
564 | target_part.setType("text"); | 565 | target_part.setType("text"); |
565 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 566 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
566 | break; | 567 | break; |
567 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 568 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
568 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 569 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
569 | break; | 570 | break; |
570 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 571 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
571 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 572 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
572 | break; | 573 | break; |
573 | default: | 574 | default: |
574 | break; | 575 | break; |
575 | } | 576 | } |
576 | } | 577 | } |
577 | 578 | ||
578 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 579 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
579 | { | 580 | { |
580 | if (!which) { | 581 | if (!which) { |
581 | return; | 582 | return; |
582 | } | 583 | } |
583 | QString sub; | 584 | QString sub; |
584 | sub = which->bd_media_text; | 585 | sub = which->bd_media_text; |
585 | target_part.setSubtype(sub.lower()); | 586 | target_part.setSubtype(sub.lower()); |
586 | target_part.setLines(which->bd_lines); | 587 | target_part.setLines(which->bd_lines); |
587 | fillBodyFields(target_part,which->bd_fields); | 588 | fillBodyFields(target_part,which->bd_fields); |
588 | } | 589 | } |
589 | 590 | ||
590 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 591 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
591 | { | 592 | { |
592 | if (!which) { | 593 | if (!which) { |
593 | return; | 594 | return; |
594 | } | 595 | } |
595 | // QString sub; | 596 | // QString sub; |
596 | // sub = which->bd_media_text; | 597 | // sub = which->bd_media_text; |
597 | // target_part.setSubtype(sub.lower()); | 598 | // target_part.setSubtype(sub.lower()); |
598 | qDebug("Message part"); | 599 | qDebug("Message part"); |
599 | /* we set this type to text/plain */ | 600 | /* we set this type to text/plain */ |
600 | target_part.setType("text"); | 601 | target_part.setType("text"); |
601 | target_part.setSubtype("plain"); | 602 | target_part.setSubtype("plain"); |
602 | target_part.setLines(which->bd_lines); | 603 | target_part.setLines(which->bd_lines); |
603 | fillBodyFields(target_part,which->bd_fields); | 604 | fillBodyFields(target_part,which->bd_fields); |
604 | } | 605 | } |
605 | 606 | ||
606 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 607 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
607 | { | 608 | { |
608 | if (!which) { | 609 | if (!which) { |
609 | return; | 610 | return; |
610 | } | 611 | } |
611 | QString type,sub; | 612 | QString type,sub; |
612 | switch (which->bd_media_basic->med_type) { | 613 | switch (which->bd_media_basic->med_type) { |
613 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 614 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
614 | type = "application"; | 615 | type = "application"; |
615 | break; | 616 | break; |
616 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 617 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
617 | type = "audio"; | 618 | type = "audio"; |
618 | break; | 619 | break; |
619 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 620 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
620 | type = "image"; | 621 | type = "image"; |
621 | break; | 622 | break; |
622 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 623 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
623 | type = "message"; | 624 | type = "message"; |
624 | break; | 625 | break; |
625 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 626 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
626 | type = "video"; | 627 | type = "video"; |
627 | break; | 628 | break; |
628 | case MAILIMAP_MEDIA_BASIC_OTHER: | 629 | case MAILIMAP_MEDIA_BASIC_OTHER: |
629 | default: | 630 | default: |
630 | if (which->bd_media_basic->med_basic_type) { | 631 | if (which->bd_media_basic->med_basic_type) { |
631 | type = which->bd_media_basic->med_basic_type; | 632 | type = which->bd_media_basic->med_basic_type; |
632 | } else { | 633 | } else { |
633 | type = ""; | 634 | type = ""; |
634 | } | 635 | } |
635 | break; | 636 | break; |
636 | } | 637 | } |
637 | if (which->bd_media_basic->med_subtype) { | 638 | if (which->bd_media_basic->med_subtype) { |
638 | sub = which->bd_media_basic->med_subtype; | 639 | sub = which->bd_media_basic->med_subtype; |
639 | } else { | 640 | } else { |
640 | sub = ""; | 641 | sub = ""; |
641 | } | 642 | } |
642 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 643 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
643 | target_part.setType(type.lower()); | 644 | target_part.setType(type.lower()); |
644 | target_part.setSubtype(sub.lower()); | 645 | target_part.setSubtype(sub.lower()); |
645 | fillBodyFields(target_part,which->bd_fields); | 646 | fillBodyFields(target_part,which->bd_fields); |
646 | } | 647 | } |
647 | 648 | ||
648 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 649 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
649 | { | 650 | { |
650 | if (!which) return; | 651 | if (!which) return; |
651 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 652 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
652 | clistcell*cur; | 653 | clistcell*cur; |
653 | mailimap_single_body_fld_param*param=0; | 654 | mailimap_single_body_fld_param*param=0; |
654 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 655 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
655 | param = (mailimap_single_body_fld_param*)cur->data; | 656 | param = (mailimap_single_body_fld_param*)cur->data; |
656 | if (param) { | 657 | if (param) { |
657 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 658 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
658 | } | 659 | } |
659 | } | 660 | } |
660 | } | 661 | } |
661 | mailimap_body_fld_enc*enc = which->bd_encoding; | 662 | mailimap_body_fld_enc*enc = which->bd_encoding; |
662 | QString encoding(""); | 663 | QString encoding(""); |
663 | switch (enc->enc_type) { | 664 | switch (enc->enc_type) { |
664 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 665 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
665 | encoding = "7bit"; | 666 | encoding = "7bit"; |
666 | break; | 667 | break; |
667 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 668 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
668 | encoding = "8bit"; | 669 | encoding = "8bit"; |
669 | break; | 670 | break; |
670 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 671 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
671 | encoding="binary"; | 672 | encoding="binary"; |
672 | break; | 673 | break; |
673 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 674 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
674 | encoding="base64"; | 675 | encoding="base64"; |
675 | break; | 676 | break; |
676 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 677 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
677 | encoding="quoted-printable"; | 678 | encoding="quoted-printable"; |
678 | break; | 679 | break; |
679 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 680 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
680 | default: | 681 | default: |
681 | if (enc->enc_value) { | 682 | if (enc->enc_value) { |
682 | char*t=enc->enc_value; | 683 | char*t=enc->enc_value; |
683 | encoding=QString(enc->enc_value); | 684 | encoding=QString(enc->enc_value); |
684 | enc->enc_value=0L; | 685 | enc->enc_value=0L; |
685 | free(t); | 686 | free(t); |
686 | } | 687 | } |
687 | } | 688 | } |
688 | target_part.setEncoding(encoding); | 689 | target_part.setEncoding(encoding); |
689 | target_part.setSize(which->bd_size); | 690 | target_part.setSize(which->bd_size); |
690 | } | 691 | } |
691 | 692 | ||
692 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | 693 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) |
693 | { | 694 | { |
694 | return fetchPart(mail,part.Positionlist(),false); | 695 | return fetchPart(mail,part.Positionlist(),false); |
695 | } | 696 | } |