author | alwin <alwin> | 2003-12-25 20:10:26 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-25 20:10:26 (UTC) |
commit | bde1302aed8a0e2506684eaae7c2d2d823de42c6 (patch) (unidiff) | |
tree | 24b16fc0f0c969df001615a00ac08a8bd4acd2df | |
parent | 67d7f0b0fc79377fba216e556785f6c630c437ad (diff) | |
download | opie-bde1302aed8a0e2506684eaae7c2d2d823de42c6.zip opie-bde1302aed8a0e2506684eaae7c2d2d823de42c6.tar.gz opie-bde1302aed8a0e2506684eaae7c2d2d823de42c6.tar.bz2 |
try to resolve timeouts via NOOP statement in login
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 9 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 9 |
2 files changed, 14 insertions, 4 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 89ec7ab..ab20249 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -1,421 +1,426 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | err = mailimap_noop(m_imap); |
37 | return; | 37 | if (err!=MAILIMAP_NO_ERROR) { |
38 | logout(); | ||
39 | } else { | ||
40 | mailstream_flush(m_imap->imap_stream); | ||
41 | return; | ||
42 | } | ||
38 | } | 43 | } |
39 | server = account->getServer().latin1(); | 44 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 45 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 46 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 47 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 48 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 49 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 50 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 51 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 52 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 53 | } else { |
49 | // cancel | 54 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 55 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 56 | return; |
52 | } | 57 | } |
53 | } else { | 58 | } else { |
54 | user = account->getUser().latin1(); | 59 | user = account->getUser().latin1(); |
55 | pass = account->getPassword().latin1(); | 60 | pass = account->getPassword().latin1(); |
56 | } | 61 | } |
57 | 62 | ||
58 | m_imap = mailimap_new( 20, &imap_progress ); | 63 | m_imap = mailimap_new( 20, &imap_progress ); |
59 | /* connect */ | 64 | /* connect */ |
60 | if (account->getSSL()) { | 65 | if (account->getSSL()) { |
61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 66 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
62 | } else { | 67 | } else { |
63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 68 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
64 | } | 69 | } |
65 | 70 | ||
66 | if ( err != MAILIMAP_NO_ERROR && | 71 | if ( err != MAILIMAP_NO_ERROR && |
67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 72 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 73 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
69 | qDebug("error connecting server: %s",m_imap->imap_response); | 74 | qDebug("error connecting server: %s",m_imap->imap_response); |
70 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
71 | m_imap = 0; | 76 | m_imap = 0; |
72 | return; | 77 | return; |
73 | } | 78 | } |
74 | 79 | ||
75 | /* login */ | 80 | /* login */ |
76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 81 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
77 | if ( err != MAILIMAP_NO_ERROR ) { | 82 | if ( err != MAILIMAP_NO_ERROR ) { |
78 | qDebug("error logging in imap: %s",m_imap->imap_response); | 83 | qDebug("error logging in imap: %s",m_imap->imap_response); |
79 | err = mailimap_close( m_imap ); | 84 | err = mailimap_close( m_imap ); |
80 | mailimap_free( m_imap ); | 85 | mailimap_free( m_imap ); |
81 | m_imap = 0; | 86 | m_imap = 0; |
82 | } | 87 | } |
83 | } | 88 | } |
84 | 89 | ||
85 | void IMAPwrapper::logout() | 90 | void IMAPwrapper::logout() |
86 | { | 91 | { |
87 | int err = MAILIMAP_NO_ERROR; | 92 | int err = MAILIMAP_NO_ERROR; |
88 | if (!m_imap) return; | 93 | if (!m_imap) return; |
89 | err = mailimap_logout( m_imap ); | 94 | err = mailimap_logout( m_imap ); |
90 | err = mailimap_close( m_imap ); | 95 | err = mailimap_close( m_imap ); |
91 | mailimap_free( m_imap ); | 96 | mailimap_free( m_imap ); |
92 | m_imap = 0; | 97 | m_imap = 0; |
93 | } | 98 | } |
94 | 99 | ||
95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 100 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
96 | { | 101 | { |
97 | const char *mb = 0; | 102 | const char *mb = 0; |
98 | int err = MAILIMAP_NO_ERROR; | 103 | int err = MAILIMAP_NO_ERROR; |
99 | clist *result = 0; | 104 | clist *result = 0; |
100 | clistcell *current; | 105 | clistcell *current; |
101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 106 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
102 | mailimap_fetch_type *fetchType = 0; | 107 | mailimap_fetch_type *fetchType = 0; |
103 | mailimap_set *set = 0; | 108 | mailimap_set *set = 0; |
104 | 109 | ||
105 | mb = mailbox.latin1(); | 110 | mb = mailbox.latin1(); |
106 | login(); | 111 | login(); |
107 | if (!m_imap) { | 112 | if (!m_imap) { |
108 | return; | 113 | return; |
109 | } | 114 | } |
110 | /* select mailbox READONLY for operations */ | 115 | /* select mailbox READONLY for operations */ |
111 | err = mailimap_examine( m_imap, (char*)mb); | 116 | err = mailimap_examine( m_imap, (char*)mb); |
112 | if ( err != MAILIMAP_NO_ERROR ) { | 117 | if ( err != MAILIMAP_NO_ERROR ) { |
113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 118 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
114 | return; | 119 | return; |
115 | } | 120 | } |
116 | 121 | ||
117 | int last = m_imap->imap_selection_info->sel_exists; | 122 | int last = m_imap->imap_selection_info->sel_exists; |
118 | 123 | ||
119 | if (last == 0) { | 124 | if (last == 0) { |
120 | qDebug("mailbox has no mails"); | 125 | qDebug("mailbox has no mails"); |
121 | return; | 126 | return; |
122 | } | 127 | } |
123 | 128 | ||
124 | /* the range has to start at 1!!! not with 0!!!! */ | 129 | /* the range has to start at 1!!! not with 0!!!! */ |
125 | set = mailimap_set_new_interval( 1, last ); | 130 | set = mailimap_set_new_interval( 1, last ); |
126 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 131 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
127 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 132 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 133 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 134 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 135 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
131 | 136 | ||
132 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 137 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
133 | mailimap_set_free( set ); | 138 | mailimap_set_free( set ); |
134 | mailimap_fetch_type_free( fetchType ); | 139 | mailimap_fetch_type_free( fetchType ); |
135 | 140 | ||
136 | QString date,subject,from; | 141 | QString date,subject,from; |
137 | 142 | ||
138 | if ( err == MAILIMAP_NO_ERROR ) { | 143 | if ( err == MAILIMAP_NO_ERROR ) { |
139 | mailimap_msg_att * msg_att; | 144 | mailimap_msg_att * msg_att; |
140 | int i = 0; | 145 | int i = 0; |
141 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 146 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
142 | ++i; | 147 | ++i; |
143 | msg_att = (mailimap_msg_att*)current->data; | 148 | msg_att = (mailimap_msg_att*)current->data; |
144 | RecMail*m = parse_list_result(msg_att); | 149 | RecMail*m = parse_list_result(msg_att); |
145 | if (m) { | 150 | if (m) { |
146 | m->setNumber(i); | 151 | m->setNumber(i); |
147 | m->setMbox(mailbox); | 152 | m->setMbox(mailbox); |
148 | m->setWrapper(this); | 153 | m->setWrapper(this); |
149 | target.append(m); | 154 | target.append(m); |
150 | } | 155 | } |
151 | } | 156 | } |
152 | } else { | 157 | } else { |
153 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 158 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
154 | } | 159 | } |
155 | if (result) mailimap_fetch_list_free(result); | 160 | if (result) mailimap_fetch_list_free(result); |
156 | } | 161 | } |
157 | 162 | ||
158 | QList<Folder>* IMAPwrapper::listFolders() | 163 | QList<Folder>* IMAPwrapper::listFolders() |
159 | { | 164 | { |
160 | const char *path, *mask; | 165 | const char *path, *mask; |
161 | int err = MAILIMAP_NO_ERROR; | 166 | int err = MAILIMAP_NO_ERROR; |
162 | clist *result = 0; | 167 | clist *result = 0; |
163 | clistcell *current = 0; | 168 | clistcell *current = 0; |
164 | 169 | ||
165 | QList<Folder> * folders = new QList<Folder>(); | 170 | QList<Folder> * folders = new QList<Folder>(); |
166 | folders->setAutoDelete( false ); | 171 | folders->setAutoDelete( false ); |
167 | login(); | 172 | login(); |
168 | if (!m_imap) { | 173 | if (!m_imap) { |
169 | return folders; | 174 | return folders; |
170 | } | 175 | } |
171 | 176 | ||
172 | /* | 177 | /* |
173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 178 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
174 | * We must not forget to filter them out in next loop! | 179 | * We must not forget to filter them out in next loop! |
175 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 180 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
176 | */ | 181 | */ |
177 | QString temp; | 182 | QString temp; |
178 | mask = "INBOX" ; | 183 | mask = "INBOX" ; |
179 | mailimap_mailbox_list *list; | 184 | mailimap_mailbox_list *list; |
180 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 185 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
181 | QString del; | 186 | QString del; |
182 | if ( err == MAILIMAP_NO_ERROR ) { | 187 | if ( err == MAILIMAP_NO_ERROR ) { |
183 | current = result->first; | 188 | current = result->first; |
184 | for ( int i = result->count; i > 0; i-- ) { | 189 | for ( int i = result->count; i > 0; i-- ) { |
185 | list = (mailimap_mailbox_list *) current->data; | 190 | list = (mailimap_mailbox_list *) current->data; |
186 | // it is better use the deep copy mechanism of qt itself | 191 | // it is better use the deep copy mechanism of qt itself |
187 | // instead of using strdup! | 192 | // instead of using strdup! |
188 | temp = list->mb_name; | 193 | temp = list->mb_name; |
189 | del = list->mb_delimiter; | 194 | del = list->mb_delimiter; |
190 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 195 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
191 | current = current->next; | 196 | current = current->next; |
192 | } | 197 | } |
193 | } else { | 198 | } else { |
194 | qDebug("error fetching folders: %s",m_imap->imap_response); | 199 | qDebug("error fetching folders: %s",m_imap->imap_response); |
195 | } | 200 | } |
196 | mailimap_list_result_free( result ); | 201 | mailimap_list_result_free( result ); |
197 | 202 | ||
198 | /* | 203 | /* |
199 | * second stage - get the other then inbox folders | 204 | * second stage - get the other then inbox folders |
200 | */ | 205 | */ |
201 | mask = "*" ; | 206 | mask = "*" ; |
202 | path = account->getPrefix().latin1(); | 207 | path = account->getPrefix().latin1(); |
203 | if (!path) path = ""; | 208 | if (!path) path = ""; |
204 | qDebug(path); | 209 | qDebug(path); |
205 | bool selectable = true; | 210 | bool selectable = true; |
206 | mailimap_mbx_list_flags*bflags; | 211 | mailimap_mbx_list_flags*bflags; |
207 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 212 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
208 | if ( err == MAILIMAP_NO_ERROR ) { | 213 | if ( err == MAILIMAP_NO_ERROR ) { |
209 | current = result->first; | 214 | current = result->first; |
210 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 215 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
211 | list = (mailimap_mailbox_list *) current->data; | 216 | list = (mailimap_mailbox_list *) current->data; |
212 | // it is better use the deep copy mechanism of qt itself | 217 | // it is better use the deep copy mechanism of qt itself |
213 | // instead of using strdup! | 218 | // instead of using strdup! |
214 | temp = list->mb_name; | 219 | temp = list->mb_name; |
215 | if (temp.lower()=="inbox") | 220 | if (temp.lower()=="inbox") |
216 | continue; | 221 | continue; |
217 | if (temp.lower()==account->getPrefix().lower()) | 222 | if (temp.lower()==account->getPrefix().lower()) |
218 | continue; | 223 | continue; |
219 | if ( (bflags = list->mb_flag) ) { | 224 | if ( (bflags = list->mb_flag) ) { |
220 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 225 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
221 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 226 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
222 | } | 227 | } |
223 | del = list->mb_delimiter; | 228 | del = list->mb_delimiter; |
224 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 229 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
225 | } | 230 | } |
226 | } else { | 231 | } else { |
227 | qDebug("error fetching folders %s",m_imap->imap_response); | 232 | qDebug("error fetching folders %s",m_imap->imap_response); |
228 | } | 233 | } |
229 | if (result) mailimap_list_result_free( result ); | 234 | if (result) mailimap_list_result_free( result ); |
230 | return folders; | 235 | return folders; |
231 | } | 236 | } |
232 | 237 | ||
233 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 238 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
234 | { | 239 | { |
235 | RecMail * m = 0; | 240 | RecMail * m = 0; |
236 | mailimap_msg_att_item *item=0; | 241 | mailimap_msg_att_item *item=0; |
237 | clistcell *current,*c,*cf; | 242 | clistcell *current,*c,*cf; |
238 | mailimap_msg_att_dynamic*flist; | 243 | mailimap_msg_att_dynamic*flist; |
239 | mailimap_flag_fetch*cflag; | 244 | mailimap_flag_fetch*cflag; |
240 | int size; | 245 | int size; |
241 | QBitArray mFlags(7); | 246 | QBitArray mFlags(7); |
242 | QStringList addresslist; | 247 | QStringList addresslist; |
243 | 248 | ||
244 | if (!m_att) { | 249 | if (!m_att) { |
245 | return m; | 250 | return m; |
246 | } | 251 | } |
247 | m = new RecMail(); | 252 | m = new RecMail(); |
248 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 253 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
249 | current = c; | 254 | current = c; |
250 | size = 0; | 255 | size = 0; |
251 | item = (mailimap_msg_att_item*)current->data; | 256 | item = (mailimap_msg_att_item*)current->data; |
252 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 257 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
253 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 258 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
254 | if (!flist->att_list) { | 259 | if (!flist->att_list) { |
255 | continue; | 260 | continue; |
256 | } | 261 | } |
257 | cf = flist->att_list->first; | 262 | cf = flist->att_list->first; |
258 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 263 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
259 | cflag = (mailimap_flag_fetch*)cf->data; | 264 | cflag = (mailimap_flag_fetch*)cf->data; |
260 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 265 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
261 | switch (cflag->fl_flag->fl_type) { | 266 | switch (cflag->fl_flag->fl_type) { |
262 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 267 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
263 | mFlags.setBit(FLAG_ANSWERED); | 268 | mFlags.setBit(FLAG_ANSWERED); |
264 | break; | 269 | break; |
265 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 270 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
266 | mFlags.setBit(FLAG_FLAGGED); | 271 | mFlags.setBit(FLAG_FLAGGED); |
267 | break; | 272 | break; |
268 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 273 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
269 | mFlags.setBit(FLAG_DELETED); | 274 | mFlags.setBit(FLAG_DELETED); |
270 | break; | 275 | break; |
271 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 276 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
272 | mFlags.setBit(FLAG_SEEN); | 277 | mFlags.setBit(FLAG_SEEN); |
273 | break; | 278 | break; |
274 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 279 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
275 | mFlags.setBit(FLAG_DRAFT); | 280 | mFlags.setBit(FLAG_DRAFT); |
276 | break; | 281 | break; |
277 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 282 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
278 | break; | 283 | break; |
279 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 284 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
280 | break; | 285 | break; |
281 | default: | 286 | default: |
282 | break; | 287 | break; |
283 | } | 288 | } |
284 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 289 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
285 | mFlags.setBit(FLAG_RECENT); | 290 | mFlags.setBit(FLAG_RECENT); |
286 | } | 291 | } |
287 | } | 292 | } |
288 | continue; | 293 | continue; |
289 | } | 294 | } |
290 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 295 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
291 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 296 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
292 | m->setDate(head->env_date); | 297 | m->setDate(head->env_date); |
293 | m->setSubject(convert_String((const char*)head->env_subject)); | 298 | m->setSubject(convert_String((const char*)head->env_subject)); |
294 | //m->setSubject(head->env_subject); | 299 | //m->setSubject(head->env_subject); |
295 | if (head->env_from!=NULL) { | 300 | if (head->env_from!=NULL) { |
296 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 301 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
297 | if (addresslist.count()) { | 302 | if (addresslist.count()) { |
298 | m->setFrom(addresslist.first()); | 303 | m->setFrom(addresslist.first()); |
299 | } | 304 | } |
300 | } | 305 | } |
301 | if (head->env_to!=NULL) { | 306 | if (head->env_to!=NULL) { |
302 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 307 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
303 | m->setTo(addresslist); | 308 | m->setTo(addresslist); |
304 | } | 309 | } |
305 | if (head->env_cc!=NULL) { | 310 | if (head->env_cc!=NULL) { |
306 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 311 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
307 | m->setCC(addresslist); | 312 | m->setCC(addresslist); |
308 | } | 313 | } |
309 | if (head->env_bcc!=NULL) { | 314 | if (head->env_bcc!=NULL) { |
310 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 315 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
311 | m->setBcc(addresslist); | 316 | m->setBcc(addresslist); |
312 | } | 317 | } |
313 | if (head->env_reply_to!=NULL) { | 318 | if (head->env_reply_to!=NULL) { |
314 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 319 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
315 | if (addresslist.count()) { | 320 | if (addresslist.count()) { |
316 | m->setReplyto(addresslist.first()); | 321 | m->setReplyto(addresslist.first()); |
317 | } | 322 | } |
318 | } | 323 | } |
319 | m->setMsgid(QString(head->env_message_id)); | 324 | m->setMsgid(QString(head->env_message_id)); |
320 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 325 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
321 | #if 0 | 326 | #if 0 |
322 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 327 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
323 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 328 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
324 | 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); | 329 | 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); |
325 | qDebug(da.toString()); | 330 | qDebug(da.toString()); |
326 | #endif | 331 | #endif |
327 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 332 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
328 | size = item->att_data.att_static->att_data.att_rfc822_size; | 333 | size = item->att_data.att_static->att_data.att_rfc822_size; |
329 | } | 334 | } |
330 | } | 335 | } |
331 | /* msg is already deleted */ | 336 | /* msg is already deleted */ |
332 | if (mFlags.testBit(FLAG_DELETED) && m) { | 337 | if (mFlags.testBit(FLAG_DELETED) && m) { |
333 | delete m; | 338 | delete m; |
334 | m = 0; | 339 | m = 0; |
335 | } | 340 | } |
336 | if (m) { | 341 | if (m) { |
337 | m->setFlags(mFlags); | 342 | m->setFlags(mFlags); |
338 | m->setMsgsize(size); | 343 | m->setMsgsize(size); |
339 | } | 344 | } |
340 | return m; | 345 | return m; |
341 | } | 346 | } |
342 | 347 | ||
343 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 348 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
344 | { | 349 | { |
345 | RecBody body; | 350 | RecBody body; |
346 | const char *mb; | 351 | const char *mb; |
347 | int err = MAILIMAP_NO_ERROR; | 352 | int err = MAILIMAP_NO_ERROR; |
348 | clist *result = 0; | 353 | clist *result = 0; |
349 | clistcell *current; | 354 | clistcell *current; |
350 | mailimap_fetch_att *fetchAtt = 0; | 355 | mailimap_fetch_att *fetchAtt = 0; |
351 | mailimap_fetch_type *fetchType = 0; | 356 | mailimap_fetch_type *fetchType = 0; |
352 | mailimap_set *set = 0; | 357 | mailimap_set *set = 0; |
353 | mailimap_body*body_desc = 0; | 358 | mailimap_body*body_desc = 0; |
354 | 359 | ||
355 | mb = mail.getMbox().latin1(); | 360 | mb = mail.getMbox().latin1(); |
356 | 361 | ||
357 | login(); | 362 | login(); |
358 | if (!m_imap) { | 363 | if (!m_imap) { |
359 | return body; | 364 | return body; |
360 | } | 365 | } |
361 | 366 | ||
362 | err = mailimap_select( m_imap, (char*)mb); | 367 | err = mailimap_select( m_imap, (char*)mb); |
363 | if ( err != MAILIMAP_NO_ERROR ) { | 368 | if ( err != MAILIMAP_NO_ERROR ) { |
364 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 369 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
365 | return body; | 370 | return body; |
366 | } | 371 | } |
367 | 372 | ||
368 | /* the range has to start at 1!!! not with 0!!!! */ | 373 | /* the range has to start at 1!!! not with 0!!!! */ |
369 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 374 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
370 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 375 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
371 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 376 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
372 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 377 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
373 | mailimap_set_free( set ); | 378 | mailimap_set_free( set ); |
374 | mailimap_fetch_type_free( fetchType ); | 379 | mailimap_fetch_type_free( fetchType ); |
375 | 380 | ||
376 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 381 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
377 | mailimap_msg_att * msg_att; | 382 | mailimap_msg_att * msg_att; |
378 | msg_att = (mailimap_msg_att*)current->data; | 383 | msg_att = (mailimap_msg_att*)current->data; |
379 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 384 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
380 | body_desc = item->att_data.att_static->att_data.att_body; | 385 | body_desc = item->att_data.att_static->att_data.att_body; |
381 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 386 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
382 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 387 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
383 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 388 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
384 | qDebug("Mulitpart mail"); | 389 | qDebug("Mulitpart mail"); |
385 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 390 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
386 | } | 391 | } |
387 | } else { | 392 | } else { |
388 | qDebug("error fetching body: %s",m_imap->imap_response); | 393 | qDebug("error fetching body: %s",m_imap->imap_response); |
389 | } | 394 | } |
390 | if (result) mailimap_fetch_list_free(result); | 395 | if (result) mailimap_fetch_list_free(result); |
391 | return body; | 396 | return body; |
392 | } | 397 | } |
393 | 398 | ||
394 | /* this routine is just called when the mail has only ONE part. | 399 | /* this routine is just called when the mail has only ONE part. |
395 | for filling the parts of a multi-part-message there are other | 400 | for filling the parts of a multi-part-message there are other |
396 | routines 'cause we can not simply fetch the whole body. */ | 401 | routines 'cause we can not simply fetch the whole body. */ |
397 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 402 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
398 | { | 403 | { |
399 | if (!mailDescription) { | 404 | if (!mailDescription) { |
400 | return; | 405 | return; |
401 | } | 406 | } |
402 | QString sub,body_text; | 407 | QString sub,body_text; |
403 | RecPart singlePart; | 408 | RecPart singlePart; |
404 | QValueList<int> path; | 409 | QValueList<int> path; |
405 | fillSinglePart(singlePart,mailDescription); | 410 | fillSinglePart(singlePart,mailDescription); |
406 | switch (mailDescription->bd_type) { | 411 | switch (mailDescription->bd_type) { |
407 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 412 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
408 | path.append(1); | 413 | path.append(1); |
409 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 414 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
410 | target_body.setBodytext(body_text); | 415 | target_body.setBodytext(body_text); |
411 | target_body.setDescription(singlePart); | 416 | target_body.setDescription(singlePart); |
412 | break; | 417 | break; |
413 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 418 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
414 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 419 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
415 | path.append(1); | 420 | path.append(1); |
416 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 421 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
417 | target_body.setBodytext(body_text); | 422 | target_body.setBodytext(body_text); |
418 | target_body.setDescription(singlePart); | 423 | target_body.setDescription(singlePart); |
419 | break; | 424 | break; |
420 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 425 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
421 | qDebug("Single attachment"); | 426 | qDebug("Single attachment"); |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 89ec7ab..ab20249 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,421 +1,426 @@ | |||
1 | 1 | ||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | 5 | ||
6 | #include "imapwrapper.h" | 6 | #include "imapwrapper.h" |
7 | #include "mailtypes.h" | 7 | #include "mailtypes.h" |
8 | #include "logindialog.h" | 8 | #include "logindialog.h" |
9 | 9 | ||
10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 10 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
11 | : AbstractMail() | 11 | : AbstractMail() |
12 | { | 12 | { |
13 | account = a; | 13 | account = a; |
14 | m_imap = 0; | 14 | m_imap = 0; |
15 | } | 15 | } |
16 | 16 | ||
17 | IMAPwrapper::~IMAPwrapper() | 17 | IMAPwrapper::~IMAPwrapper() |
18 | { | 18 | { |
19 | logout(); | 19 | logout(); |
20 | } | 20 | } |
21 | 21 | ||
22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 22 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
23 | { | 23 | { |
24 | qDebug( "IMAP: %i of %i", current, maximum ); | 24 | qDebug( "IMAP: %i of %i", current, maximum ); |
25 | } | 25 | } |
26 | 26 | ||
27 | void IMAPwrapper::login() | 27 | void IMAPwrapper::login() |
28 | { | 28 | { |
29 | const char *server, *user, *pass; | 29 | const char *server, *user, *pass; |
30 | uint16_t port; | 30 | uint16_t port; |
31 | int err = MAILIMAP_NO_ERROR; | 31 | int err = MAILIMAP_NO_ERROR; |
32 | 32 | ||
33 | /* we are connected this moment */ | 33 | /* we are connected this moment */ |
34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 34 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
35 | if (m_imap) { | 35 | if (m_imap) { |
36 | mailstream_flush(m_imap->imap_stream); | 36 | err = mailimap_noop(m_imap); |
37 | return; | 37 | if (err!=MAILIMAP_NO_ERROR) { |
38 | logout(); | ||
39 | } else { | ||
40 | mailstream_flush(m_imap->imap_stream); | ||
41 | return; | ||
42 | } | ||
38 | } | 43 | } |
39 | server = account->getServer().latin1(); | 44 | server = account->getServer().latin1(); |
40 | port = account->getPort().toUInt(); | 45 | port = account->getPort().toUInt(); |
41 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 46 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
42 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 47 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
43 | login.show(); | 48 | login.show(); |
44 | if ( QDialog::Accepted == login.exec() ) { | 49 | if ( QDialog::Accepted == login.exec() ) { |
45 | // ok | 50 | // ok |
46 | user = strdup( login.getUser().latin1() ); | 51 | user = strdup( login.getUser().latin1() ); |
47 | pass = strdup( login.getPassword().latin1() ); | 52 | pass = strdup( login.getPassword().latin1() ); |
48 | } else { | 53 | } else { |
49 | // cancel | 54 | // cancel |
50 | qDebug( "IMAP: Login canceled" ); | 55 | qDebug( "IMAP: Login canceled" ); |
51 | return; | 56 | return; |
52 | } | 57 | } |
53 | } else { | 58 | } else { |
54 | user = account->getUser().latin1(); | 59 | user = account->getUser().latin1(); |
55 | pass = account->getPassword().latin1(); | 60 | pass = account->getPassword().latin1(); |
56 | } | 61 | } |
57 | 62 | ||
58 | m_imap = mailimap_new( 20, &imap_progress ); | 63 | m_imap = mailimap_new( 20, &imap_progress ); |
59 | /* connect */ | 64 | /* connect */ |
60 | if (account->getSSL()) { | 65 | if (account->getSSL()) { |
61 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 66 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
62 | } else { | 67 | } else { |
63 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 68 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
64 | } | 69 | } |
65 | 70 | ||
66 | if ( err != MAILIMAP_NO_ERROR && | 71 | if ( err != MAILIMAP_NO_ERROR && |
67 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 72 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
68 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 73 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
69 | qDebug("error connecting server: %s",m_imap->imap_response); | 74 | qDebug("error connecting server: %s",m_imap->imap_response); |
70 | mailimap_free( m_imap ); | 75 | mailimap_free( m_imap ); |
71 | m_imap = 0; | 76 | m_imap = 0; |
72 | return; | 77 | return; |
73 | } | 78 | } |
74 | 79 | ||
75 | /* login */ | 80 | /* login */ |
76 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 81 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
77 | if ( err != MAILIMAP_NO_ERROR ) { | 82 | if ( err != MAILIMAP_NO_ERROR ) { |
78 | qDebug("error logging in imap: %s",m_imap->imap_response); | 83 | qDebug("error logging in imap: %s",m_imap->imap_response); |
79 | err = mailimap_close( m_imap ); | 84 | err = mailimap_close( m_imap ); |
80 | mailimap_free( m_imap ); | 85 | mailimap_free( m_imap ); |
81 | m_imap = 0; | 86 | m_imap = 0; |
82 | } | 87 | } |
83 | } | 88 | } |
84 | 89 | ||
85 | void IMAPwrapper::logout() | 90 | void IMAPwrapper::logout() |
86 | { | 91 | { |
87 | int err = MAILIMAP_NO_ERROR; | 92 | int err = MAILIMAP_NO_ERROR; |
88 | if (!m_imap) return; | 93 | if (!m_imap) return; |
89 | err = mailimap_logout( m_imap ); | 94 | err = mailimap_logout( m_imap ); |
90 | err = mailimap_close( m_imap ); | 95 | err = mailimap_close( m_imap ); |
91 | mailimap_free( m_imap ); | 96 | mailimap_free( m_imap ); |
92 | m_imap = 0; | 97 | m_imap = 0; |
93 | } | 98 | } |
94 | 99 | ||
95 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 100 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
96 | { | 101 | { |
97 | const char *mb = 0; | 102 | const char *mb = 0; |
98 | int err = MAILIMAP_NO_ERROR; | 103 | int err = MAILIMAP_NO_ERROR; |
99 | clist *result = 0; | 104 | clist *result = 0; |
100 | clistcell *current; | 105 | clistcell *current; |
101 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; | 106 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
102 | mailimap_fetch_type *fetchType = 0; | 107 | mailimap_fetch_type *fetchType = 0; |
103 | mailimap_set *set = 0; | 108 | mailimap_set *set = 0; |
104 | 109 | ||
105 | mb = mailbox.latin1(); | 110 | mb = mailbox.latin1(); |
106 | login(); | 111 | login(); |
107 | if (!m_imap) { | 112 | if (!m_imap) { |
108 | return; | 113 | return; |
109 | } | 114 | } |
110 | /* select mailbox READONLY for operations */ | 115 | /* select mailbox READONLY for operations */ |
111 | err = mailimap_examine( m_imap, (char*)mb); | 116 | err = mailimap_examine( m_imap, (char*)mb); |
112 | if ( err != MAILIMAP_NO_ERROR ) { | 117 | if ( err != MAILIMAP_NO_ERROR ) { |
113 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 118 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
114 | return; | 119 | return; |
115 | } | 120 | } |
116 | 121 | ||
117 | int last = m_imap->imap_selection_info->sel_exists; | 122 | int last = m_imap->imap_selection_info->sel_exists; |
118 | 123 | ||
119 | if (last == 0) { | 124 | if (last == 0) { |
120 | qDebug("mailbox has no mails"); | 125 | qDebug("mailbox has no mails"); |
121 | return; | 126 | return; |
122 | } | 127 | } |
123 | 128 | ||
124 | /* the range has to start at 1!!! not with 0!!!! */ | 129 | /* the range has to start at 1!!! not with 0!!!! */ |
125 | set = mailimap_set_new_interval( 1, last ); | 130 | set = mailimap_set_new_interval( 1, last ); |
126 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 131 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
127 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 132 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
128 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 133 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
129 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 134 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
130 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 135 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
131 | 136 | ||
132 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 137 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
133 | mailimap_set_free( set ); | 138 | mailimap_set_free( set ); |
134 | mailimap_fetch_type_free( fetchType ); | 139 | mailimap_fetch_type_free( fetchType ); |
135 | 140 | ||
136 | QString date,subject,from; | 141 | QString date,subject,from; |
137 | 142 | ||
138 | if ( err == MAILIMAP_NO_ERROR ) { | 143 | if ( err == MAILIMAP_NO_ERROR ) { |
139 | mailimap_msg_att * msg_att; | 144 | mailimap_msg_att * msg_att; |
140 | int i = 0; | 145 | int i = 0; |
141 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 146 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
142 | ++i; | 147 | ++i; |
143 | msg_att = (mailimap_msg_att*)current->data; | 148 | msg_att = (mailimap_msg_att*)current->data; |
144 | RecMail*m = parse_list_result(msg_att); | 149 | RecMail*m = parse_list_result(msg_att); |
145 | if (m) { | 150 | if (m) { |
146 | m->setNumber(i); | 151 | m->setNumber(i); |
147 | m->setMbox(mailbox); | 152 | m->setMbox(mailbox); |
148 | m->setWrapper(this); | 153 | m->setWrapper(this); |
149 | target.append(m); | 154 | target.append(m); |
150 | } | 155 | } |
151 | } | 156 | } |
152 | } else { | 157 | } else { |
153 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 158 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
154 | } | 159 | } |
155 | if (result) mailimap_fetch_list_free(result); | 160 | if (result) mailimap_fetch_list_free(result); |
156 | } | 161 | } |
157 | 162 | ||
158 | QList<Folder>* IMAPwrapper::listFolders() | 163 | QList<Folder>* IMAPwrapper::listFolders() |
159 | { | 164 | { |
160 | const char *path, *mask; | 165 | const char *path, *mask; |
161 | int err = MAILIMAP_NO_ERROR; | 166 | int err = MAILIMAP_NO_ERROR; |
162 | clist *result = 0; | 167 | clist *result = 0; |
163 | clistcell *current = 0; | 168 | clistcell *current = 0; |
164 | 169 | ||
165 | QList<Folder> * folders = new QList<Folder>(); | 170 | QList<Folder> * folders = new QList<Folder>(); |
166 | folders->setAutoDelete( false ); | 171 | folders->setAutoDelete( false ); |
167 | login(); | 172 | login(); |
168 | if (!m_imap) { | 173 | if (!m_imap) { |
169 | return folders; | 174 | return folders; |
170 | } | 175 | } |
171 | 176 | ||
172 | /* | 177 | /* |
173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 178 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
174 | * We must not forget to filter them out in next loop! | 179 | * We must not forget to filter them out in next loop! |
175 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 180 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
176 | */ | 181 | */ |
177 | QString temp; | 182 | QString temp; |
178 | mask = "INBOX" ; | 183 | mask = "INBOX" ; |
179 | mailimap_mailbox_list *list; | 184 | mailimap_mailbox_list *list; |
180 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 185 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
181 | QString del; | 186 | QString del; |
182 | if ( err == MAILIMAP_NO_ERROR ) { | 187 | if ( err == MAILIMAP_NO_ERROR ) { |
183 | current = result->first; | 188 | current = result->first; |
184 | for ( int i = result->count; i > 0; i-- ) { | 189 | for ( int i = result->count; i > 0; i-- ) { |
185 | list = (mailimap_mailbox_list *) current->data; | 190 | list = (mailimap_mailbox_list *) current->data; |
186 | // it is better use the deep copy mechanism of qt itself | 191 | // it is better use the deep copy mechanism of qt itself |
187 | // instead of using strdup! | 192 | // instead of using strdup! |
188 | temp = list->mb_name; | 193 | temp = list->mb_name; |
189 | del = list->mb_delimiter; | 194 | del = list->mb_delimiter; |
190 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 195 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
191 | current = current->next; | 196 | current = current->next; |
192 | } | 197 | } |
193 | } else { | 198 | } else { |
194 | qDebug("error fetching folders: %s",m_imap->imap_response); | 199 | qDebug("error fetching folders: %s",m_imap->imap_response); |
195 | } | 200 | } |
196 | mailimap_list_result_free( result ); | 201 | mailimap_list_result_free( result ); |
197 | 202 | ||
198 | /* | 203 | /* |
199 | * second stage - get the other then inbox folders | 204 | * second stage - get the other then inbox folders |
200 | */ | 205 | */ |
201 | mask = "*" ; | 206 | mask = "*" ; |
202 | path = account->getPrefix().latin1(); | 207 | path = account->getPrefix().latin1(); |
203 | if (!path) path = ""; | 208 | if (!path) path = ""; |
204 | qDebug(path); | 209 | qDebug(path); |
205 | bool selectable = true; | 210 | bool selectable = true; |
206 | mailimap_mbx_list_flags*bflags; | 211 | mailimap_mbx_list_flags*bflags; |
207 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 212 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
208 | if ( err == MAILIMAP_NO_ERROR ) { | 213 | if ( err == MAILIMAP_NO_ERROR ) { |
209 | current = result->first; | 214 | current = result->first; |
210 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 215 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
211 | list = (mailimap_mailbox_list *) current->data; | 216 | list = (mailimap_mailbox_list *) current->data; |
212 | // it is better use the deep copy mechanism of qt itself | 217 | // it is better use the deep copy mechanism of qt itself |
213 | // instead of using strdup! | 218 | // instead of using strdup! |
214 | temp = list->mb_name; | 219 | temp = list->mb_name; |
215 | if (temp.lower()=="inbox") | 220 | if (temp.lower()=="inbox") |
216 | continue; | 221 | continue; |
217 | if (temp.lower()==account->getPrefix().lower()) | 222 | if (temp.lower()==account->getPrefix().lower()) |
218 | continue; | 223 | continue; |
219 | if ( (bflags = list->mb_flag) ) { | 224 | if ( (bflags = list->mb_flag) ) { |
220 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 225 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
221 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 226 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
222 | } | 227 | } |
223 | del = list->mb_delimiter; | 228 | del = list->mb_delimiter; |
224 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 229 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
225 | } | 230 | } |
226 | } else { | 231 | } else { |
227 | qDebug("error fetching folders %s",m_imap->imap_response); | 232 | qDebug("error fetching folders %s",m_imap->imap_response); |
228 | } | 233 | } |
229 | if (result) mailimap_list_result_free( result ); | 234 | if (result) mailimap_list_result_free( result ); |
230 | return folders; | 235 | return folders; |
231 | } | 236 | } |
232 | 237 | ||
233 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 238 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
234 | { | 239 | { |
235 | RecMail * m = 0; | 240 | RecMail * m = 0; |
236 | mailimap_msg_att_item *item=0; | 241 | mailimap_msg_att_item *item=0; |
237 | clistcell *current,*c,*cf; | 242 | clistcell *current,*c,*cf; |
238 | mailimap_msg_att_dynamic*flist; | 243 | mailimap_msg_att_dynamic*flist; |
239 | mailimap_flag_fetch*cflag; | 244 | mailimap_flag_fetch*cflag; |
240 | int size; | 245 | int size; |
241 | QBitArray mFlags(7); | 246 | QBitArray mFlags(7); |
242 | QStringList addresslist; | 247 | QStringList addresslist; |
243 | 248 | ||
244 | if (!m_att) { | 249 | if (!m_att) { |
245 | return m; | 250 | return m; |
246 | } | 251 | } |
247 | m = new RecMail(); | 252 | m = new RecMail(); |
248 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 253 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
249 | current = c; | 254 | current = c; |
250 | size = 0; | 255 | size = 0; |
251 | item = (mailimap_msg_att_item*)current->data; | 256 | item = (mailimap_msg_att_item*)current->data; |
252 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 257 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
253 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 258 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
254 | if (!flist->att_list) { | 259 | if (!flist->att_list) { |
255 | continue; | 260 | continue; |
256 | } | 261 | } |
257 | cf = flist->att_list->first; | 262 | cf = flist->att_list->first; |
258 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 263 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
259 | cflag = (mailimap_flag_fetch*)cf->data; | 264 | cflag = (mailimap_flag_fetch*)cf->data; |
260 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 265 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
261 | switch (cflag->fl_flag->fl_type) { | 266 | switch (cflag->fl_flag->fl_type) { |
262 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 267 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
263 | mFlags.setBit(FLAG_ANSWERED); | 268 | mFlags.setBit(FLAG_ANSWERED); |
264 | break; | 269 | break; |
265 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 270 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
266 | mFlags.setBit(FLAG_FLAGGED); | 271 | mFlags.setBit(FLAG_FLAGGED); |
267 | break; | 272 | break; |
268 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 273 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
269 | mFlags.setBit(FLAG_DELETED); | 274 | mFlags.setBit(FLAG_DELETED); |
270 | break; | 275 | break; |
271 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 276 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
272 | mFlags.setBit(FLAG_SEEN); | 277 | mFlags.setBit(FLAG_SEEN); |
273 | break; | 278 | break; |
274 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 279 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
275 | mFlags.setBit(FLAG_DRAFT); | 280 | mFlags.setBit(FLAG_DRAFT); |
276 | break; | 281 | break; |
277 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 282 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
278 | break; | 283 | break; |
279 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 284 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
280 | break; | 285 | break; |
281 | default: | 286 | default: |
282 | break; | 287 | break; |
283 | } | 288 | } |
284 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 289 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
285 | mFlags.setBit(FLAG_RECENT); | 290 | mFlags.setBit(FLAG_RECENT); |
286 | } | 291 | } |
287 | } | 292 | } |
288 | continue; | 293 | continue; |
289 | } | 294 | } |
290 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 295 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
291 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 296 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
292 | m->setDate(head->env_date); | 297 | m->setDate(head->env_date); |
293 | m->setSubject(convert_String((const char*)head->env_subject)); | 298 | m->setSubject(convert_String((const char*)head->env_subject)); |
294 | //m->setSubject(head->env_subject); | 299 | //m->setSubject(head->env_subject); |
295 | if (head->env_from!=NULL) { | 300 | if (head->env_from!=NULL) { |
296 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 301 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
297 | if (addresslist.count()) { | 302 | if (addresslist.count()) { |
298 | m->setFrom(addresslist.first()); | 303 | m->setFrom(addresslist.first()); |
299 | } | 304 | } |
300 | } | 305 | } |
301 | if (head->env_to!=NULL) { | 306 | if (head->env_to!=NULL) { |
302 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 307 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
303 | m->setTo(addresslist); | 308 | m->setTo(addresslist); |
304 | } | 309 | } |
305 | if (head->env_cc!=NULL) { | 310 | if (head->env_cc!=NULL) { |
306 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 311 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
307 | m->setCC(addresslist); | 312 | m->setCC(addresslist); |
308 | } | 313 | } |
309 | if (head->env_bcc!=NULL) { | 314 | if (head->env_bcc!=NULL) { |
310 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 315 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
311 | m->setBcc(addresslist); | 316 | m->setBcc(addresslist); |
312 | } | 317 | } |
313 | if (head->env_reply_to!=NULL) { | 318 | if (head->env_reply_to!=NULL) { |
314 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 319 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
315 | if (addresslist.count()) { | 320 | if (addresslist.count()) { |
316 | m->setReplyto(addresslist.first()); | 321 | m->setReplyto(addresslist.first()); |
317 | } | 322 | } |
318 | } | 323 | } |
319 | m->setMsgid(QString(head->env_message_id)); | 324 | m->setMsgid(QString(head->env_message_id)); |
320 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 325 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
321 | #if 0 | 326 | #if 0 |
322 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 327 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
323 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 328 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
324 | 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); | 329 | 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); |
325 | qDebug(da.toString()); | 330 | qDebug(da.toString()); |
326 | #endif | 331 | #endif |
327 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 332 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
328 | size = item->att_data.att_static->att_data.att_rfc822_size; | 333 | size = item->att_data.att_static->att_data.att_rfc822_size; |
329 | } | 334 | } |
330 | } | 335 | } |
331 | /* msg is already deleted */ | 336 | /* msg is already deleted */ |
332 | if (mFlags.testBit(FLAG_DELETED) && m) { | 337 | if (mFlags.testBit(FLAG_DELETED) && m) { |
333 | delete m; | 338 | delete m; |
334 | m = 0; | 339 | m = 0; |
335 | } | 340 | } |
336 | if (m) { | 341 | if (m) { |
337 | m->setFlags(mFlags); | 342 | m->setFlags(mFlags); |
338 | m->setMsgsize(size); | 343 | m->setMsgsize(size); |
339 | } | 344 | } |
340 | return m; | 345 | return m; |
341 | } | 346 | } |
342 | 347 | ||
343 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 348 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
344 | { | 349 | { |
345 | RecBody body; | 350 | RecBody body; |
346 | const char *mb; | 351 | const char *mb; |
347 | int err = MAILIMAP_NO_ERROR; | 352 | int err = MAILIMAP_NO_ERROR; |
348 | clist *result = 0; | 353 | clist *result = 0; |
349 | clistcell *current; | 354 | clistcell *current; |
350 | mailimap_fetch_att *fetchAtt = 0; | 355 | mailimap_fetch_att *fetchAtt = 0; |
351 | mailimap_fetch_type *fetchType = 0; | 356 | mailimap_fetch_type *fetchType = 0; |
352 | mailimap_set *set = 0; | 357 | mailimap_set *set = 0; |
353 | mailimap_body*body_desc = 0; | 358 | mailimap_body*body_desc = 0; |
354 | 359 | ||
355 | mb = mail.getMbox().latin1(); | 360 | mb = mail.getMbox().latin1(); |
356 | 361 | ||
357 | login(); | 362 | login(); |
358 | if (!m_imap) { | 363 | if (!m_imap) { |
359 | return body; | 364 | return body; |
360 | } | 365 | } |
361 | 366 | ||
362 | err = mailimap_select( m_imap, (char*)mb); | 367 | err = mailimap_select( m_imap, (char*)mb); |
363 | if ( err != MAILIMAP_NO_ERROR ) { | 368 | if ( err != MAILIMAP_NO_ERROR ) { |
364 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 369 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
365 | return body; | 370 | return body; |
366 | } | 371 | } |
367 | 372 | ||
368 | /* the range has to start at 1!!! not with 0!!!! */ | 373 | /* the range has to start at 1!!! not with 0!!!! */ |
369 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 374 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
370 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 375 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
371 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 376 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
372 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 377 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
373 | mailimap_set_free( set ); | 378 | mailimap_set_free( set ); |
374 | mailimap_fetch_type_free( fetchType ); | 379 | mailimap_fetch_type_free( fetchType ); |
375 | 380 | ||
376 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 381 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
377 | mailimap_msg_att * msg_att; | 382 | mailimap_msg_att * msg_att; |
378 | msg_att = (mailimap_msg_att*)current->data; | 383 | msg_att = (mailimap_msg_att*)current->data; |
379 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 384 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
380 | body_desc = item->att_data.att_static->att_data.att_body; | 385 | body_desc = item->att_data.att_static->att_data.att_body; |
381 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 386 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
382 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 387 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
383 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 388 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
384 | qDebug("Mulitpart mail"); | 389 | qDebug("Mulitpart mail"); |
385 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 390 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
386 | } | 391 | } |
387 | } else { | 392 | } else { |
388 | qDebug("error fetching body: %s",m_imap->imap_response); | 393 | qDebug("error fetching body: %s",m_imap->imap_response); |
389 | } | 394 | } |
390 | if (result) mailimap_fetch_list_free(result); | 395 | if (result) mailimap_fetch_list_free(result); |
391 | return body; | 396 | return body; |
392 | } | 397 | } |
393 | 398 | ||
394 | /* this routine is just called when the mail has only ONE part. | 399 | /* this routine is just called when the mail has only ONE part. |
395 | for filling the parts of a multi-part-message there are other | 400 | for filling the parts of a multi-part-message there are other |
396 | routines 'cause we can not simply fetch the whole body. */ | 401 | routines 'cause we can not simply fetch the whole body. */ |
397 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 402 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
398 | { | 403 | { |
399 | if (!mailDescription) { | 404 | if (!mailDescription) { |
400 | return; | 405 | return; |
401 | } | 406 | } |
402 | QString sub,body_text; | 407 | QString sub,body_text; |
403 | RecPart singlePart; | 408 | RecPart singlePart; |
404 | QValueList<int> path; | 409 | QValueList<int> path; |
405 | fillSinglePart(singlePart,mailDescription); | 410 | fillSinglePart(singlePart,mailDescription); |
406 | switch (mailDescription->bd_type) { | 411 | switch (mailDescription->bd_type) { |
407 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 412 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
408 | path.append(1); | 413 | path.append(1); |
409 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 414 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
410 | target_body.setBodytext(body_text); | 415 | target_body.setBodytext(body_text); |
411 | target_body.setDescription(singlePart); | 416 | target_body.setDescription(singlePart); |
412 | break; | 417 | break; |
413 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 418 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
414 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 419 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
415 | path.append(1); | 420 | path.append(1); |
416 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | 421 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
417 | target_body.setBodytext(body_text); | 422 | target_body.setBodytext(body_text); |
418 | target_body.setDescription(singlePart); | 423 | target_body.setDescription(singlePart); |
419 | break; | 424 | break; |
420 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 425 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
421 | qDebug("Single attachment"); | 426 | qDebug("Single attachment"); |