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,805 +1,810 @@ | |||
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"); |
422 | target_body.setBodytext(""); | 427 | target_body.setBodytext(""); |
423 | target_body.addPart(singlePart); | 428 | target_body.addPart(singlePart); |
424 | break; | 429 | break; |
425 | default: | 430 | default: |
426 | break; | 431 | break; |
427 | } | 432 | } |
428 | 433 | ||
429 | return; | 434 | return; |
430 | } | 435 | } |
431 | 436 | ||
432 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 437 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
433 | { | 438 | { |
434 | QStringList l; | 439 | QStringList l; |
435 | QString from; | 440 | QString from; |
436 | bool named_from; | 441 | bool named_from; |
437 | clistcell *current = NULL; | 442 | clistcell *current = NULL; |
438 | mailimap_address * current_address=NULL; | 443 | mailimap_address * current_address=NULL; |
439 | if (!list) { | 444 | if (!list) { |
440 | return l; | 445 | return l; |
441 | } | 446 | } |
442 | unsigned int count = 0; | 447 | unsigned int count = 0; |
443 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 448 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
444 | from = ""; | 449 | from = ""; |
445 | named_from = false; | 450 | named_from = false; |
446 | current_address=(mailimap_address*)current->data; | 451 | current_address=(mailimap_address*)current->data; |
447 | if (current_address->ad_personal_name){ | 452 | if (current_address->ad_personal_name){ |
448 | from+=convert_String((const char*)current_address->ad_personal_name); | 453 | from+=convert_String((const char*)current_address->ad_personal_name); |
449 | //from+=QString(current_address->ad_personal_name); | 454 | //from+=QString(current_address->ad_personal_name); |
450 | from+=" "; | 455 | from+=" "; |
451 | named_from = true; | 456 | named_from = true; |
452 | } | 457 | } |
453 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 458 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
454 | from+="<"; | 459 | from+="<"; |
455 | } | 460 | } |
456 | if (current_address->ad_mailbox_name) { | 461 | if (current_address->ad_mailbox_name) { |
457 | from+=QString(current_address->ad_mailbox_name); | 462 | from+=QString(current_address->ad_mailbox_name); |
458 | from+="@"; | 463 | from+="@"; |
459 | } | 464 | } |
460 | if (current_address->ad_host_name) { | 465 | if (current_address->ad_host_name) { |
461 | from+=QString(current_address->ad_host_name); | 466 | from+=QString(current_address->ad_host_name); |
462 | } | 467 | } |
463 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 468 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
464 | from+=">"; | 469 | from+=">"; |
465 | } | 470 | } |
466 | l.append(QString(from)); | 471 | l.append(QString(from)); |
467 | if (++count > 99) { | 472 | if (++count > 99) { |
468 | break; | 473 | break; |
469 | } | 474 | } |
470 | } | 475 | } |
471 | return l; | 476 | return l; |
472 | } | 477 | } |
473 | 478 | ||
474 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 479 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
475 | { | 480 | { |
476 | encodedString*res=new encodedString; | 481 | encodedString*res=new encodedString; |
477 | const char*mb; | 482 | const char*mb; |
478 | int err; | 483 | int err; |
479 | mailimap_fetch_type *fetchType; | 484 | mailimap_fetch_type *fetchType; |
480 | mailimap_set *set; | 485 | mailimap_set *set; |
481 | clistcell*current,*cur; | 486 | clistcell*current,*cur; |
482 | 487 | ||
483 | login(); | 488 | login(); |
484 | if (!m_imap) { | 489 | if (!m_imap) { |
485 | return res; | 490 | return res; |
486 | } | 491 | } |
487 | if (!internal_call) { | 492 | if (!internal_call) { |
488 | mb = mail.getMbox().latin1(); | 493 | mb = mail.getMbox().latin1(); |
489 | err = mailimap_select( m_imap, (char*)mb); | 494 | err = mailimap_select( m_imap, (char*)mb); |
490 | if ( err != MAILIMAP_NO_ERROR ) { | 495 | if ( err != MAILIMAP_NO_ERROR ) { |
491 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 496 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
492 | return res; | 497 | return res; |
493 | } | 498 | } |
494 | } | 499 | } |
495 | set = mailimap_set_new_single(mail.getNumber()); | 500 | set = mailimap_set_new_single(mail.getNumber()); |
496 | clist*id_list=clist_new(); | 501 | clist*id_list=clist_new(); |
497 | for (unsigned j=0; j < path.count();++j) { | 502 | for (unsigned j=0; j < path.count();++j) { |
498 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 503 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
499 | *p_id = path[j]; | 504 | *p_id = path[j]; |
500 | clist_append(id_list,p_id); | 505 | clist_append(id_list,p_id); |
501 | } | 506 | } |
502 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 507 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
503 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 508 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
504 | mailimap_section * section = mailimap_section_new(section_spec); | 509 | mailimap_section * section = mailimap_section_new(section_spec); |
505 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 510 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
506 | 511 | ||
507 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 512 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
508 | 513 | ||
509 | clist*result = 0; | 514 | clist*result = 0; |
510 | 515 | ||
511 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
512 | mailimap_set_free( set ); | 517 | mailimap_set_free( set ); |
513 | mailimap_fetch_type_free( fetchType ); | 518 | mailimap_fetch_type_free( fetchType ); |
514 | 519 | ||
515 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
516 | mailimap_msg_att * msg_att; | 521 | mailimap_msg_att * msg_att; |
517 | msg_att = (mailimap_msg_att*)current->data; | 522 | msg_att = (mailimap_msg_att*)current->data; |
518 | mailimap_msg_att_item*msg_att_item; | 523 | mailimap_msg_att_item*msg_att_item; |
519 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 524 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
520 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 525 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
521 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 526 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
522 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 527 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
523 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 528 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
524 | /* detach - we take over the content */ | 529 | /* detach - we take over the content */ |
525 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 530 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
526 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 531 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
527 | } | 532 | } |
528 | } | 533 | } |
529 | } | 534 | } |
530 | } else { | 535 | } else { |
531 | qDebug("error fetching text: %s",m_imap->imap_response); | 536 | qDebug("error fetching text: %s",m_imap->imap_response); |
532 | } | 537 | } |
533 | if (result) mailimap_fetch_list_free(result); | 538 | if (result) mailimap_fetch_list_free(result); |
534 | return res; | 539 | return res; |
535 | } | 540 | } |
536 | 541 | ||
537 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 542 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
538 | { | 543 | { |
539 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 544 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
540 | if (!mailDescription||current_recursion==10) { | 545 | if (!mailDescription||current_recursion==10) { |
541 | return; | 546 | return; |
542 | } | 547 | } |
543 | clistcell*current; | 548 | clistcell*current; |
544 | mailimap_body*current_body; | 549 | mailimap_body*current_body; |
545 | unsigned int count = 0; | 550 | unsigned int count = 0; |
546 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 551 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
547 | /* the point in the message */ | 552 | /* the point in the message */ |
548 | ++count; | 553 | ++count; |
549 | current_body = (mailimap_body*)current->data; | 554 | current_body = (mailimap_body*)current->data; |
550 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 555 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
551 | QValueList<int>countlist = recList; | 556 | QValueList<int>countlist = recList; |
552 | countlist.append(count); | 557 | countlist.append(count); |
553 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); | 558 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); |
554 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 559 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
555 | RecPart currentPart; | 560 | RecPart currentPart; |
556 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 561 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
557 | QValueList<int>countlist = recList; | 562 | QValueList<int>countlist = recList; |
558 | countlist.append(count); | 563 | countlist.append(count); |
559 | /* important: Check for is NULL 'cause a body can be empty! */ | 564 | /* important: Check for is NULL 'cause a body can be empty! */ |
560 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 565 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
561 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 566 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
562 | target_body.setDescription(currentPart); | 567 | target_body.setDescription(currentPart); |
563 | target_body.setBodytext(body_text); | 568 | target_body.setBodytext(body_text); |
564 | } else { | 569 | } else { |
565 | QString id(""); | 570 | QString id(""); |
566 | for (unsigned int j = 0; j < countlist.count();++j) { | 571 | for (unsigned int j = 0; j < countlist.count();++j) { |
567 | id+=(j>0?" ":""); | 572 | id+=(j>0?" ":""); |
568 | id+=QString("%1").arg(countlist[j]); | 573 | id+=QString("%1").arg(countlist[j]); |
569 | } | 574 | } |
570 | qDebug("ID= %s",id.latin1()); | 575 | qDebug("ID= %s",id.latin1()); |
571 | currentPart.setIdentifier(id); | 576 | currentPart.setIdentifier(id); |
572 | currentPart.setPositionlist(countlist); | 577 | currentPart.setPositionlist(countlist); |
573 | target_body.addPart(currentPart); | 578 | target_body.addPart(currentPart); |
574 | } | 579 | } |
575 | } | 580 | } |
576 | } | 581 | } |
577 | } | 582 | } |
578 | 583 | ||
579 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 584 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
580 | { | 585 | { |
581 | if (!Description) { | 586 | if (!Description) { |
582 | return; | 587 | return; |
583 | } | 588 | } |
584 | switch (Description->bd_type) { | 589 | switch (Description->bd_type) { |
585 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 590 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
586 | target_part.setType("text"); | 591 | target_part.setType("text"); |
587 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 592 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
588 | break; | 593 | break; |
589 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 594 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
590 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 595 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
591 | break; | 596 | break; |
592 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 597 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
593 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 598 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
594 | break; | 599 | break; |
595 | default: | 600 | default: |
596 | break; | 601 | break; |
597 | } | 602 | } |
598 | } | 603 | } |
599 | 604 | ||
600 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 605 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
601 | { | 606 | { |
602 | if (!which) { | 607 | if (!which) { |
603 | return; | 608 | return; |
604 | } | 609 | } |
605 | QString sub; | 610 | QString sub; |
606 | sub = which->bd_media_text; | 611 | sub = which->bd_media_text; |
607 | target_part.setSubtype(sub.lower()); | 612 | target_part.setSubtype(sub.lower()); |
608 | target_part.setLines(which->bd_lines); | 613 | target_part.setLines(which->bd_lines); |
609 | fillBodyFields(target_part,which->bd_fields); | 614 | fillBodyFields(target_part,which->bd_fields); |
610 | } | 615 | } |
611 | 616 | ||
612 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 617 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
613 | { | 618 | { |
614 | if (!which) { | 619 | if (!which) { |
615 | return; | 620 | return; |
616 | } | 621 | } |
617 | // QString sub; | 622 | // QString sub; |
618 | // sub = which->bd_media_text; | 623 | // sub = which->bd_media_text; |
619 | // target_part.setSubtype(sub.lower()); | 624 | // target_part.setSubtype(sub.lower()); |
620 | qDebug("Message part"); | 625 | qDebug("Message part"); |
621 | /* we set this type to text/plain */ | 626 | /* we set this type to text/plain */ |
622 | target_part.setType("text"); | 627 | target_part.setType("text"); |
623 | target_part.setSubtype("plain"); | 628 | target_part.setSubtype("plain"); |
624 | target_part.setLines(which->bd_lines); | 629 | target_part.setLines(which->bd_lines); |
625 | fillBodyFields(target_part,which->bd_fields); | 630 | fillBodyFields(target_part,which->bd_fields); |
626 | } | 631 | } |
627 | 632 | ||
628 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 633 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
629 | { | 634 | { |
630 | if (!which) { | 635 | if (!which) { |
631 | return; | 636 | return; |
632 | } | 637 | } |
633 | QString type,sub; | 638 | QString type,sub; |
634 | switch (which->bd_media_basic->med_type) { | 639 | switch (which->bd_media_basic->med_type) { |
635 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 640 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
636 | type = "application"; | 641 | type = "application"; |
637 | break; | 642 | break; |
638 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 643 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
639 | type = "audio"; | 644 | type = "audio"; |
640 | break; | 645 | break; |
641 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 646 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
642 | type = "image"; | 647 | type = "image"; |
643 | break; | 648 | break; |
644 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 649 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
645 | type = "message"; | 650 | type = "message"; |
646 | break; | 651 | break; |
647 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 652 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
648 | type = "video"; | 653 | type = "video"; |
649 | break; | 654 | break; |
650 | case MAILIMAP_MEDIA_BASIC_OTHER: | 655 | case MAILIMAP_MEDIA_BASIC_OTHER: |
651 | default: | 656 | default: |
652 | if (which->bd_media_basic->med_basic_type) { | 657 | if (which->bd_media_basic->med_basic_type) { |
653 | type = which->bd_media_basic->med_basic_type; | 658 | type = which->bd_media_basic->med_basic_type; |
654 | } else { | 659 | } else { |
655 | type = ""; | 660 | type = ""; |
656 | } | 661 | } |
657 | break; | 662 | break; |
658 | } | 663 | } |
659 | if (which->bd_media_basic->med_subtype) { | 664 | if (which->bd_media_basic->med_subtype) { |
660 | sub = which->bd_media_basic->med_subtype; | 665 | sub = which->bd_media_basic->med_subtype; |
661 | } else { | 666 | } else { |
662 | sub = ""; | 667 | sub = ""; |
663 | } | 668 | } |
664 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 669 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
665 | target_part.setType(type.lower()); | 670 | target_part.setType(type.lower()); |
666 | target_part.setSubtype(sub.lower()); | 671 | target_part.setSubtype(sub.lower()); |
667 | fillBodyFields(target_part,which->bd_fields); | 672 | fillBodyFields(target_part,which->bd_fields); |
668 | } | 673 | } |
669 | 674 | ||
670 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 675 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
671 | { | 676 | { |
672 | if (!which) return; | 677 | if (!which) return; |
673 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 678 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
674 | clistcell*cur; | 679 | clistcell*cur; |
675 | mailimap_single_body_fld_param*param=0; | 680 | mailimap_single_body_fld_param*param=0; |
676 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 681 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
677 | param = (mailimap_single_body_fld_param*)cur->data; | 682 | param = (mailimap_single_body_fld_param*)cur->data; |
678 | if (param) { | 683 | if (param) { |
679 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 684 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
680 | } | 685 | } |
681 | } | 686 | } |
682 | } | 687 | } |
683 | mailimap_body_fld_enc*enc = which->bd_encoding; | 688 | mailimap_body_fld_enc*enc = which->bd_encoding; |
684 | QString encoding(""); | 689 | QString encoding(""); |
685 | switch (enc->enc_type) { | 690 | switch (enc->enc_type) { |
686 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 691 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
687 | encoding = "7bit"; | 692 | encoding = "7bit"; |
688 | break; | 693 | break; |
689 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 694 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
690 | encoding = "8bit"; | 695 | encoding = "8bit"; |
691 | break; | 696 | break; |
692 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 697 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
693 | encoding="binary"; | 698 | encoding="binary"; |
694 | break; | 699 | break; |
695 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 700 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
696 | encoding="base64"; | 701 | encoding="base64"; |
697 | break; | 702 | break; |
698 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 703 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
699 | encoding="quoted-printable"; | 704 | encoding="quoted-printable"; |
700 | break; | 705 | break; |
701 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 706 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
702 | default: | 707 | default: |
703 | if (enc->enc_value) { | 708 | if (enc->enc_value) { |
704 | char*t=enc->enc_value; | 709 | char*t=enc->enc_value; |
705 | encoding=QString(enc->enc_value); | 710 | encoding=QString(enc->enc_value); |
706 | enc->enc_value=0L; | 711 | enc->enc_value=0L; |
707 | free(t); | 712 | free(t); |
708 | } | 713 | } |
709 | } | 714 | } |
710 | if (which->bd_description) { | 715 | if (which->bd_description) { |
711 | target_part.setDescription(QString(which->bd_description)); | 716 | target_part.setDescription(QString(which->bd_description)); |
712 | } | 717 | } |
713 | target_part.setEncoding(encoding); | 718 | target_part.setEncoding(encoding); |
714 | target_part.setSize(which->bd_size); | 719 | target_part.setSize(which->bd_size); |
715 | } | 720 | } |
716 | 721 | ||
717 | void IMAPwrapper::deleteMail(const RecMail&mail) | 722 | void IMAPwrapper::deleteMail(const RecMail&mail) |
718 | { | 723 | { |
719 | mailimap_flag_list*flist; | 724 | mailimap_flag_list*flist; |
720 | mailimap_set *set; | 725 | mailimap_set *set; |
721 | mailimap_store_att_flags * store_flags; | 726 | mailimap_store_att_flags * store_flags; |
722 | int err; | 727 | int err; |
723 | login(); | 728 | login(); |
724 | if (!m_imap) { | 729 | if (!m_imap) { |
725 | return; | 730 | return; |
726 | } | 731 | } |
727 | const char *mb = mail.getMbox().latin1(); | 732 | const char *mb = mail.getMbox().latin1(); |
728 | err = mailimap_select( m_imap, (char*)mb); | 733 | err = mailimap_select( m_imap, (char*)mb); |
729 | if ( err != MAILIMAP_NO_ERROR ) { | 734 | if ( err != MAILIMAP_NO_ERROR ) { |
730 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 735 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
731 | return; | 736 | return; |
732 | } | 737 | } |
733 | flist = mailimap_flag_list_new_empty(); | 738 | flist = mailimap_flag_list_new_empty(); |
734 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 739 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
735 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 740 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
736 | set = mailimap_set_new_single(mail.getNumber()); | 741 | set = mailimap_set_new_single(mail.getNumber()); |
737 | err = mailimap_store(m_imap,set,store_flags); | 742 | err = mailimap_store(m_imap,set,store_flags); |
738 | mailimap_set_free( set ); | 743 | mailimap_set_free( set ); |
739 | mailimap_store_att_flags_free(store_flags); | 744 | mailimap_store_att_flags_free(store_flags); |
740 | 745 | ||
741 | if (err != MAILIMAP_NO_ERROR) { | 746 | if (err != MAILIMAP_NO_ERROR) { |
742 | qDebug("error deleting mail: %s",m_imap->imap_response); | 747 | qDebug("error deleting mail: %s",m_imap->imap_response); |
743 | return; | 748 | return; |
744 | } | 749 | } |
745 | qDebug("deleting mail: %s",m_imap->imap_response); | 750 | qDebug("deleting mail: %s",m_imap->imap_response); |
746 | /* should we realy do that at this moment? */ | 751 | /* should we realy do that at this moment? */ |
747 | err = mailimap_expunge(m_imap); | 752 | err = mailimap_expunge(m_imap); |
748 | if (err != MAILIMAP_NO_ERROR) { | 753 | if (err != MAILIMAP_NO_ERROR) { |
749 | qDebug("error deleting mail: %s",m_imap->imap_response); | 754 | qDebug("error deleting mail: %s",m_imap->imap_response); |
750 | } | 755 | } |
751 | qDebug("Delete successfull %s",m_imap->imap_response); | 756 | qDebug("Delete successfull %s",m_imap->imap_response); |
752 | } | 757 | } |
753 | 758 | ||
754 | void IMAPwrapper::answeredMail(const RecMail&mail) | 759 | void IMAPwrapper::answeredMail(const RecMail&mail) |
755 | { | 760 | { |
756 | mailimap_flag_list*flist; | 761 | mailimap_flag_list*flist; |
757 | mailimap_set *set; | 762 | mailimap_set *set; |
758 | mailimap_store_att_flags * store_flags; | 763 | mailimap_store_att_flags * store_flags; |
759 | int err; | 764 | int err; |
760 | login(); | 765 | login(); |
761 | if (!m_imap) { | 766 | if (!m_imap) { |
762 | return; | 767 | return; |
763 | } | 768 | } |
764 | const char *mb = mail.getMbox().latin1(); | 769 | const char *mb = mail.getMbox().latin1(); |
765 | err = mailimap_select( m_imap, (char*)mb); | 770 | err = mailimap_select( m_imap, (char*)mb); |
766 | if ( err != MAILIMAP_NO_ERROR ) { | 771 | if ( err != MAILIMAP_NO_ERROR ) { |
767 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 772 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
768 | return; | 773 | return; |
769 | } | 774 | } |
770 | flist = mailimap_flag_list_new_empty(); | 775 | flist = mailimap_flag_list_new_empty(); |
771 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 776 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
772 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 777 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
773 | set = mailimap_set_new_single(mail.getNumber()); | 778 | set = mailimap_set_new_single(mail.getNumber()); |
774 | err = mailimap_store(m_imap,set,store_flags); | 779 | err = mailimap_store(m_imap,set,store_flags); |
775 | mailimap_set_free( set ); | 780 | mailimap_set_free( set ); |
776 | mailimap_store_att_flags_free(store_flags); | 781 | mailimap_store_att_flags_free(store_flags); |
777 | 782 | ||
778 | if (err != MAILIMAP_NO_ERROR) { | 783 | if (err != MAILIMAP_NO_ERROR) { |
779 | qDebug("error marking mail: %s",m_imap->imap_response); | 784 | qDebug("error marking mail: %s",m_imap->imap_response); |
780 | return; | 785 | return; |
781 | } | 786 | } |
782 | } | 787 | } |
783 | 788 | ||
784 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 789 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
785 | { | 790 | { |
786 | QString body(""); | 791 | QString body(""); |
787 | encodedString*res = fetchRawPart(mail,path,internal_call); | 792 | encodedString*res = fetchRawPart(mail,path,internal_call); |
788 | encodedString*r = decode_String(res,enc); | 793 | encodedString*r = decode_String(res,enc); |
789 | delete res; | 794 | delete res; |
790 | if (r) { | 795 | if (r) { |
791 | if (r->Length()>0) { | 796 | if (r->Length()>0) { |
792 | body = r->Content(); | 797 | body = r->Content(); |
793 | } | 798 | } |
794 | delete r; | 799 | delete r; |
795 | } | 800 | } |
796 | return body; | 801 | return body; |
797 | } | 802 | } |
798 | 803 | ||
799 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 804 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
800 | { | 805 | { |
801 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 806 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
802 | } | 807 | } |
803 | 808 | ||
804 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 809 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
805 | { | 810 | { |
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,805 +1,810 @@ | |||
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"); |
422 | target_body.setBodytext(""); | 427 | target_body.setBodytext(""); |
423 | target_body.addPart(singlePart); | 428 | target_body.addPart(singlePart); |
424 | break; | 429 | break; |
425 | default: | 430 | default: |
426 | break; | 431 | break; |
427 | } | 432 | } |
428 | 433 | ||
429 | return; | 434 | return; |
430 | } | 435 | } |
431 | 436 | ||
432 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 437 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
433 | { | 438 | { |
434 | QStringList l; | 439 | QStringList l; |
435 | QString from; | 440 | QString from; |
436 | bool named_from; | 441 | bool named_from; |
437 | clistcell *current = NULL; | 442 | clistcell *current = NULL; |
438 | mailimap_address * current_address=NULL; | 443 | mailimap_address * current_address=NULL; |
439 | if (!list) { | 444 | if (!list) { |
440 | return l; | 445 | return l; |
441 | } | 446 | } |
442 | unsigned int count = 0; | 447 | unsigned int count = 0; |
443 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 448 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
444 | from = ""; | 449 | from = ""; |
445 | named_from = false; | 450 | named_from = false; |
446 | current_address=(mailimap_address*)current->data; | 451 | current_address=(mailimap_address*)current->data; |
447 | if (current_address->ad_personal_name){ | 452 | if (current_address->ad_personal_name){ |
448 | from+=convert_String((const char*)current_address->ad_personal_name); | 453 | from+=convert_String((const char*)current_address->ad_personal_name); |
449 | //from+=QString(current_address->ad_personal_name); | 454 | //from+=QString(current_address->ad_personal_name); |
450 | from+=" "; | 455 | from+=" "; |
451 | named_from = true; | 456 | named_from = true; |
452 | } | 457 | } |
453 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 458 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
454 | from+="<"; | 459 | from+="<"; |
455 | } | 460 | } |
456 | if (current_address->ad_mailbox_name) { | 461 | if (current_address->ad_mailbox_name) { |
457 | from+=QString(current_address->ad_mailbox_name); | 462 | from+=QString(current_address->ad_mailbox_name); |
458 | from+="@"; | 463 | from+="@"; |
459 | } | 464 | } |
460 | if (current_address->ad_host_name) { | 465 | if (current_address->ad_host_name) { |
461 | from+=QString(current_address->ad_host_name); | 466 | from+=QString(current_address->ad_host_name); |
462 | } | 467 | } |
463 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 468 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
464 | from+=">"; | 469 | from+=">"; |
465 | } | 470 | } |
466 | l.append(QString(from)); | 471 | l.append(QString(from)); |
467 | if (++count > 99) { | 472 | if (++count > 99) { |
468 | break; | 473 | break; |
469 | } | 474 | } |
470 | } | 475 | } |
471 | return l; | 476 | return l; |
472 | } | 477 | } |
473 | 478 | ||
474 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 479 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
475 | { | 480 | { |
476 | encodedString*res=new encodedString; | 481 | encodedString*res=new encodedString; |
477 | const char*mb; | 482 | const char*mb; |
478 | int err; | 483 | int err; |
479 | mailimap_fetch_type *fetchType; | 484 | mailimap_fetch_type *fetchType; |
480 | mailimap_set *set; | 485 | mailimap_set *set; |
481 | clistcell*current,*cur; | 486 | clistcell*current,*cur; |
482 | 487 | ||
483 | login(); | 488 | login(); |
484 | if (!m_imap) { | 489 | if (!m_imap) { |
485 | return res; | 490 | return res; |
486 | } | 491 | } |
487 | if (!internal_call) { | 492 | if (!internal_call) { |
488 | mb = mail.getMbox().latin1(); | 493 | mb = mail.getMbox().latin1(); |
489 | err = mailimap_select( m_imap, (char*)mb); | 494 | err = mailimap_select( m_imap, (char*)mb); |
490 | if ( err != MAILIMAP_NO_ERROR ) { | 495 | if ( err != MAILIMAP_NO_ERROR ) { |
491 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 496 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
492 | return res; | 497 | return res; |
493 | } | 498 | } |
494 | } | 499 | } |
495 | set = mailimap_set_new_single(mail.getNumber()); | 500 | set = mailimap_set_new_single(mail.getNumber()); |
496 | clist*id_list=clist_new(); | 501 | clist*id_list=clist_new(); |
497 | for (unsigned j=0; j < path.count();++j) { | 502 | for (unsigned j=0; j < path.count();++j) { |
498 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 503 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
499 | *p_id = path[j]; | 504 | *p_id = path[j]; |
500 | clist_append(id_list,p_id); | 505 | clist_append(id_list,p_id); |
501 | } | 506 | } |
502 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 507 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
503 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 508 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
504 | mailimap_section * section = mailimap_section_new(section_spec); | 509 | mailimap_section * section = mailimap_section_new(section_spec); |
505 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 510 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
506 | 511 | ||
507 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 512 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
508 | 513 | ||
509 | clist*result = 0; | 514 | clist*result = 0; |
510 | 515 | ||
511 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
512 | mailimap_set_free( set ); | 517 | mailimap_set_free( set ); |
513 | mailimap_fetch_type_free( fetchType ); | 518 | mailimap_fetch_type_free( fetchType ); |
514 | 519 | ||
515 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
516 | mailimap_msg_att * msg_att; | 521 | mailimap_msg_att * msg_att; |
517 | msg_att = (mailimap_msg_att*)current->data; | 522 | msg_att = (mailimap_msg_att*)current->data; |
518 | mailimap_msg_att_item*msg_att_item; | 523 | mailimap_msg_att_item*msg_att_item; |
519 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 524 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
520 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 525 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
521 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 526 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
522 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 527 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
523 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 528 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
524 | /* detach - we take over the content */ | 529 | /* detach - we take over the content */ |
525 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 530 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
526 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 531 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
527 | } | 532 | } |
528 | } | 533 | } |
529 | } | 534 | } |
530 | } else { | 535 | } else { |
531 | qDebug("error fetching text: %s",m_imap->imap_response); | 536 | qDebug("error fetching text: %s",m_imap->imap_response); |
532 | } | 537 | } |
533 | if (result) mailimap_fetch_list_free(result); | 538 | if (result) mailimap_fetch_list_free(result); |
534 | return res; | 539 | return res; |
535 | } | 540 | } |
536 | 541 | ||
537 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 542 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
538 | { | 543 | { |
539 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 544 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
540 | if (!mailDescription||current_recursion==10) { | 545 | if (!mailDescription||current_recursion==10) { |
541 | return; | 546 | return; |
542 | } | 547 | } |
543 | clistcell*current; | 548 | clistcell*current; |
544 | mailimap_body*current_body; | 549 | mailimap_body*current_body; |
545 | unsigned int count = 0; | 550 | unsigned int count = 0; |
546 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 551 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
547 | /* the point in the message */ | 552 | /* the point in the message */ |
548 | ++count; | 553 | ++count; |
549 | current_body = (mailimap_body*)current->data; | 554 | current_body = (mailimap_body*)current->data; |
550 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 555 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
551 | QValueList<int>countlist = recList; | 556 | QValueList<int>countlist = recList; |
552 | countlist.append(count); | 557 | countlist.append(count); |
553 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); | 558 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); |
554 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 559 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ |
555 | RecPart currentPart; | 560 | RecPart currentPart; |
556 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 561 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
557 | QValueList<int>countlist = recList; | 562 | QValueList<int>countlist = recList; |
558 | countlist.append(count); | 563 | countlist.append(count); |
559 | /* important: Check for is NULL 'cause a body can be empty! */ | 564 | /* important: Check for is NULL 'cause a body can be empty! */ |
560 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 565 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
561 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 566 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
562 | target_body.setDescription(currentPart); | 567 | target_body.setDescription(currentPart); |
563 | target_body.setBodytext(body_text); | 568 | target_body.setBodytext(body_text); |
564 | } else { | 569 | } else { |
565 | QString id(""); | 570 | QString id(""); |
566 | for (unsigned int j = 0; j < countlist.count();++j) { | 571 | for (unsigned int j = 0; j < countlist.count();++j) { |
567 | id+=(j>0?" ":""); | 572 | id+=(j>0?" ":""); |
568 | id+=QString("%1").arg(countlist[j]); | 573 | id+=QString("%1").arg(countlist[j]); |
569 | } | 574 | } |
570 | qDebug("ID= %s",id.latin1()); | 575 | qDebug("ID= %s",id.latin1()); |
571 | currentPart.setIdentifier(id); | 576 | currentPart.setIdentifier(id); |
572 | currentPart.setPositionlist(countlist); | 577 | currentPart.setPositionlist(countlist); |
573 | target_body.addPart(currentPart); | 578 | target_body.addPart(currentPart); |
574 | } | 579 | } |
575 | } | 580 | } |
576 | } | 581 | } |
577 | } | 582 | } |
578 | 583 | ||
579 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 584 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
580 | { | 585 | { |
581 | if (!Description) { | 586 | if (!Description) { |
582 | return; | 587 | return; |
583 | } | 588 | } |
584 | switch (Description->bd_type) { | 589 | switch (Description->bd_type) { |
585 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 590 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
586 | target_part.setType("text"); | 591 | target_part.setType("text"); |
587 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 592 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
588 | break; | 593 | break; |
589 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 594 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
590 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 595 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
591 | break; | 596 | break; |
592 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 597 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
593 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 598 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
594 | break; | 599 | break; |
595 | default: | 600 | default: |
596 | break; | 601 | break; |
597 | } | 602 | } |
598 | } | 603 | } |
599 | 604 | ||
600 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 605 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
601 | { | 606 | { |
602 | if (!which) { | 607 | if (!which) { |
603 | return; | 608 | return; |
604 | } | 609 | } |
605 | QString sub; | 610 | QString sub; |
606 | sub = which->bd_media_text; | 611 | sub = which->bd_media_text; |
607 | target_part.setSubtype(sub.lower()); | 612 | target_part.setSubtype(sub.lower()); |
608 | target_part.setLines(which->bd_lines); | 613 | target_part.setLines(which->bd_lines); |
609 | fillBodyFields(target_part,which->bd_fields); | 614 | fillBodyFields(target_part,which->bd_fields); |
610 | } | 615 | } |
611 | 616 | ||
612 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 617 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
613 | { | 618 | { |
614 | if (!which) { | 619 | if (!which) { |
615 | return; | 620 | return; |
616 | } | 621 | } |
617 | // QString sub; | 622 | // QString sub; |
618 | // sub = which->bd_media_text; | 623 | // sub = which->bd_media_text; |
619 | // target_part.setSubtype(sub.lower()); | 624 | // target_part.setSubtype(sub.lower()); |
620 | qDebug("Message part"); | 625 | qDebug("Message part"); |
621 | /* we set this type to text/plain */ | 626 | /* we set this type to text/plain */ |
622 | target_part.setType("text"); | 627 | target_part.setType("text"); |
623 | target_part.setSubtype("plain"); | 628 | target_part.setSubtype("plain"); |
624 | target_part.setLines(which->bd_lines); | 629 | target_part.setLines(which->bd_lines); |
625 | fillBodyFields(target_part,which->bd_fields); | 630 | fillBodyFields(target_part,which->bd_fields); |
626 | } | 631 | } |
627 | 632 | ||
628 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 633 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
629 | { | 634 | { |
630 | if (!which) { | 635 | if (!which) { |
631 | return; | 636 | return; |
632 | } | 637 | } |
633 | QString type,sub; | 638 | QString type,sub; |
634 | switch (which->bd_media_basic->med_type) { | 639 | switch (which->bd_media_basic->med_type) { |
635 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 640 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
636 | type = "application"; | 641 | type = "application"; |
637 | break; | 642 | break; |
638 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 643 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
639 | type = "audio"; | 644 | type = "audio"; |
640 | break; | 645 | break; |
641 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 646 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
642 | type = "image"; | 647 | type = "image"; |
643 | break; | 648 | break; |
644 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 649 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
645 | type = "message"; | 650 | type = "message"; |
646 | break; | 651 | break; |
647 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 652 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
648 | type = "video"; | 653 | type = "video"; |
649 | break; | 654 | break; |
650 | case MAILIMAP_MEDIA_BASIC_OTHER: | 655 | case MAILIMAP_MEDIA_BASIC_OTHER: |
651 | default: | 656 | default: |
652 | if (which->bd_media_basic->med_basic_type) { | 657 | if (which->bd_media_basic->med_basic_type) { |
653 | type = which->bd_media_basic->med_basic_type; | 658 | type = which->bd_media_basic->med_basic_type; |
654 | } else { | 659 | } else { |
655 | type = ""; | 660 | type = ""; |
656 | } | 661 | } |
657 | break; | 662 | break; |
658 | } | 663 | } |
659 | if (which->bd_media_basic->med_subtype) { | 664 | if (which->bd_media_basic->med_subtype) { |
660 | sub = which->bd_media_basic->med_subtype; | 665 | sub = which->bd_media_basic->med_subtype; |
661 | } else { | 666 | } else { |
662 | sub = ""; | 667 | sub = ""; |
663 | } | 668 | } |
664 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 669 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
665 | target_part.setType(type.lower()); | 670 | target_part.setType(type.lower()); |
666 | target_part.setSubtype(sub.lower()); | 671 | target_part.setSubtype(sub.lower()); |
667 | fillBodyFields(target_part,which->bd_fields); | 672 | fillBodyFields(target_part,which->bd_fields); |
668 | } | 673 | } |
669 | 674 | ||
670 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 675 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
671 | { | 676 | { |
672 | if (!which) return; | 677 | if (!which) return; |
673 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 678 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
674 | clistcell*cur; | 679 | clistcell*cur; |
675 | mailimap_single_body_fld_param*param=0; | 680 | mailimap_single_body_fld_param*param=0; |
676 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 681 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
677 | param = (mailimap_single_body_fld_param*)cur->data; | 682 | param = (mailimap_single_body_fld_param*)cur->data; |
678 | if (param) { | 683 | if (param) { |
679 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 684 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
680 | } | 685 | } |
681 | } | 686 | } |
682 | } | 687 | } |
683 | mailimap_body_fld_enc*enc = which->bd_encoding; | 688 | mailimap_body_fld_enc*enc = which->bd_encoding; |
684 | QString encoding(""); | 689 | QString encoding(""); |
685 | switch (enc->enc_type) { | 690 | switch (enc->enc_type) { |
686 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 691 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
687 | encoding = "7bit"; | 692 | encoding = "7bit"; |
688 | break; | 693 | break; |
689 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 694 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
690 | encoding = "8bit"; | 695 | encoding = "8bit"; |
691 | break; | 696 | break; |
692 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 697 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
693 | encoding="binary"; | 698 | encoding="binary"; |
694 | break; | 699 | break; |
695 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 700 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
696 | encoding="base64"; | 701 | encoding="base64"; |
697 | break; | 702 | break; |
698 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 703 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
699 | encoding="quoted-printable"; | 704 | encoding="quoted-printable"; |
700 | break; | 705 | break; |
701 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 706 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
702 | default: | 707 | default: |
703 | if (enc->enc_value) { | 708 | if (enc->enc_value) { |
704 | char*t=enc->enc_value; | 709 | char*t=enc->enc_value; |
705 | encoding=QString(enc->enc_value); | 710 | encoding=QString(enc->enc_value); |
706 | enc->enc_value=0L; | 711 | enc->enc_value=0L; |
707 | free(t); | 712 | free(t); |
708 | } | 713 | } |
709 | } | 714 | } |
710 | if (which->bd_description) { | 715 | if (which->bd_description) { |
711 | target_part.setDescription(QString(which->bd_description)); | 716 | target_part.setDescription(QString(which->bd_description)); |
712 | } | 717 | } |
713 | target_part.setEncoding(encoding); | 718 | target_part.setEncoding(encoding); |
714 | target_part.setSize(which->bd_size); | 719 | target_part.setSize(which->bd_size); |
715 | } | 720 | } |
716 | 721 | ||
717 | void IMAPwrapper::deleteMail(const RecMail&mail) | 722 | void IMAPwrapper::deleteMail(const RecMail&mail) |
718 | { | 723 | { |
719 | mailimap_flag_list*flist; | 724 | mailimap_flag_list*flist; |
720 | mailimap_set *set; | 725 | mailimap_set *set; |
721 | mailimap_store_att_flags * store_flags; | 726 | mailimap_store_att_flags * store_flags; |
722 | int err; | 727 | int err; |
723 | login(); | 728 | login(); |
724 | if (!m_imap) { | 729 | if (!m_imap) { |
725 | return; | 730 | return; |
726 | } | 731 | } |
727 | const char *mb = mail.getMbox().latin1(); | 732 | const char *mb = mail.getMbox().latin1(); |
728 | err = mailimap_select( m_imap, (char*)mb); | 733 | err = mailimap_select( m_imap, (char*)mb); |
729 | if ( err != MAILIMAP_NO_ERROR ) { | 734 | if ( err != MAILIMAP_NO_ERROR ) { |
730 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 735 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
731 | return; | 736 | return; |
732 | } | 737 | } |
733 | flist = mailimap_flag_list_new_empty(); | 738 | flist = mailimap_flag_list_new_empty(); |
734 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 739 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
735 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 740 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
736 | set = mailimap_set_new_single(mail.getNumber()); | 741 | set = mailimap_set_new_single(mail.getNumber()); |
737 | err = mailimap_store(m_imap,set,store_flags); | 742 | err = mailimap_store(m_imap,set,store_flags); |
738 | mailimap_set_free( set ); | 743 | mailimap_set_free( set ); |
739 | mailimap_store_att_flags_free(store_flags); | 744 | mailimap_store_att_flags_free(store_flags); |
740 | 745 | ||
741 | if (err != MAILIMAP_NO_ERROR) { | 746 | if (err != MAILIMAP_NO_ERROR) { |
742 | qDebug("error deleting mail: %s",m_imap->imap_response); | 747 | qDebug("error deleting mail: %s",m_imap->imap_response); |
743 | return; | 748 | return; |
744 | } | 749 | } |
745 | qDebug("deleting mail: %s",m_imap->imap_response); | 750 | qDebug("deleting mail: %s",m_imap->imap_response); |
746 | /* should we realy do that at this moment? */ | 751 | /* should we realy do that at this moment? */ |
747 | err = mailimap_expunge(m_imap); | 752 | err = mailimap_expunge(m_imap); |
748 | if (err != MAILIMAP_NO_ERROR) { | 753 | if (err != MAILIMAP_NO_ERROR) { |
749 | qDebug("error deleting mail: %s",m_imap->imap_response); | 754 | qDebug("error deleting mail: %s",m_imap->imap_response); |
750 | } | 755 | } |
751 | qDebug("Delete successfull %s",m_imap->imap_response); | 756 | qDebug("Delete successfull %s",m_imap->imap_response); |
752 | } | 757 | } |
753 | 758 | ||
754 | void IMAPwrapper::answeredMail(const RecMail&mail) | 759 | void IMAPwrapper::answeredMail(const RecMail&mail) |
755 | { | 760 | { |
756 | mailimap_flag_list*flist; | 761 | mailimap_flag_list*flist; |
757 | mailimap_set *set; | 762 | mailimap_set *set; |
758 | mailimap_store_att_flags * store_flags; | 763 | mailimap_store_att_flags * store_flags; |
759 | int err; | 764 | int err; |
760 | login(); | 765 | login(); |
761 | if (!m_imap) { | 766 | if (!m_imap) { |
762 | return; | 767 | return; |
763 | } | 768 | } |
764 | const char *mb = mail.getMbox().latin1(); | 769 | const char *mb = mail.getMbox().latin1(); |
765 | err = mailimap_select( m_imap, (char*)mb); | 770 | err = mailimap_select( m_imap, (char*)mb); |
766 | if ( err != MAILIMAP_NO_ERROR ) { | 771 | if ( err != MAILIMAP_NO_ERROR ) { |
767 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 772 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
768 | return; | 773 | return; |
769 | } | 774 | } |
770 | flist = mailimap_flag_list_new_empty(); | 775 | flist = mailimap_flag_list_new_empty(); |
771 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 776 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
772 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 777 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
773 | set = mailimap_set_new_single(mail.getNumber()); | 778 | set = mailimap_set_new_single(mail.getNumber()); |
774 | err = mailimap_store(m_imap,set,store_flags); | 779 | err = mailimap_store(m_imap,set,store_flags); |
775 | mailimap_set_free( set ); | 780 | mailimap_set_free( set ); |
776 | mailimap_store_att_flags_free(store_flags); | 781 | mailimap_store_att_flags_free(store_flags); |
777 | 782 | ||
778 | if (err != MAILIMAP_NO_ERROR) { | 783 | if (err != MAILIMAP_NO_ERROR) { |
779 | qDebug("error marking mail: %s",m_imap->imap_response); | 784 | qDebug("error marking mail: %s",m_imap->imap_response); |
780 | return; | 785 | return; |
781 | } | 786 | } |
782 | } | 787 | } |
783 | 788 | ||
784 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 789 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
785 | { | 790 | { |
786 | QString body(""); | 791 | QString body(""); |
787 | encodedString*res = fetchRawPart(mail,path,internal_call); | 792 | encodedString*res = fetchRawPart(mail,path,internal_call); |
788 | encodedString*r = decode_String(res,enc); | 793 | encodedString*r = decode_String(res,enc); |
789 | delete res; | 794 | delete res; |
790 | if (r) { | 795 | if (r) { |
791 | if (r->Length()>0) { | 796 | if (r->Length()>0) { |
792 | body = r->Content(); | 797 | body = r->Content(); |
793 | } | 798 | } |
794 | delete r; | 799 | delete r; |
795 | } | 800 | } |
796 | return body; | 801 | return body; |
797 | } | 802 | } |
798 | 803 | ||
799 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 804 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
800 | { | 805 | { |
801 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 806 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
802 | } | 807 | } |
803 | 808 | ||
804 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 809 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
805 | { | 810 | { |