Diffstat (limited to 'noncore/net/mail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 9b7c0e0..fe75a15 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -10,93 +10,93 @@ | |||
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
13 | : AbstractMail() | 13 | : AbstractMail() |
14 | { | 14 | { |
15 | account = a; | 15 | account = a; |
16 | m_imap = 0; | 16 | m_imap = 0; |
17 | m_Lastmbox = ""; | 17 | m_Lastmbox = ""; |
18 | } | 18 | } |
19 | 19 | ||
20 | IMAPwrapper::~IMAPwrapper() | 20 | IMAPwrapper::~IMAPwrapper() |
21 | { | 21 | { |
22 | logout(); | 22 | logout(); |
23 | } | 23 | } |
24 | 24 | ||
25 | /* to avoid to often select statements in loops etc. | 25 | /* to avoid to often select statements in loops etc. |
26 | we trust that we are logged in and connection is established!*/ | 26 | we trust that we are logged in and connection is established!*/ |
27 | int IMAPwrapper::selectMbox(const QString&mbox) | 27 | int IMAPwrapper::selectMbox(const QString&mbox) |
28 | { | 28 | { |
29 | if (mbox == m_Lastmbox) { | 29 | if (mbox == m_Lastmbox) { |
30 | return MAILIMAP_NO_ERROR; | 30 | return MAILIMAP_NO_ERROR; |
31 | } | 31 | } |
32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
33 | if ( err != MAILIMAP_NO_ERROR ) { | 33 | if ( err != MAILIMAP_NO_ERROR ) { |
34 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; | 34 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; |
35 | m_Lastmbox = ""; | 35 | m_Lastmbox = ""; |
36 | return err; | 36 | return err; |
37 | } | 37 | } |
38 | m_Lastmbox = mbox; | 38 | m_Lastmbox = mbox; |
39 | return err; | 39 | return err; |
40 | } | 40 | } |
41 | 41 | ||
42 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 42 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
43 | { | 43 | { |
44 | qApp->processEvents(); | 44 | qApp->processEvents(); |
45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; | 45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; |
46 | } | 46 | } |
47 | 47 | ||
48 | bool IMAPwrapper::start_tls(bool force_tls) | 48 | bool IMAPwrapper::start_tls(bool force_tls) |
49 | { | 49 | { |
50 | int err; | 50 | int err; |
51 | bool try_tls; | 51 | bool try_tls; |
52 | mailimap_capability_data * cap_data = 0; | 52 | mailimap_capability_data * cap_data = 0; |
53 | 53 | ||
54 | err = mailimap_capability(m_imap,&cap_data); | 54 | err = mailimap_capability(m_imap,&cap_data); |
55 | if (err != MAILIMAP_NO_ERROR) { | 55 | if (err != MAILIMAP_NO_ERROR) { |
56 | Global::statusMessage("error getting capabilities!"); | 56 | Global::statusMessage("error getting capabilities!"); |
57 | odebug << "error getting capabilities!" << oendl; | 57 | odebug << "error getting capabilities!" << oendl; |
58 | return false; | 58 | return false; |
59 | } | 59 | } |
60 | clistiter * cur; | 60 | clistiter * cur; |
61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
62 | struct mailimap_capability * cap; | 62 | struct mailimap_capability * cap; |
63 | cap = (struct mailimap_capability *)clist_content(cur); | 63 | cap = (struct mailimap_capability *)clist_content(cur); |
64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
66 | try_tls = true; | 66 | try_tls = true; |
67 | break; | 67 | break; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | if (cap_data) { | 71 | if (cap_data) { |
72 | mailimap_capability_data_free(cap_data); | 72 | mailimap_capability_data_free(cap_data); |
73 | } | 73 | } |
74 | if (try_tls) { | 74 | if (try_tls) { |
75 | err = mailimap_starttls(m_imap); | 75 | err = mailimap_starttls(m_imap); |
76 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 76 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
77 | Global::statusMessage(tr("Server has no TLS support!")); | 77 | Global::statusMessage(tr("Server has no TLS support!")); |
78 | odebug << "Server has no TLS support!" << oendl; | 78 | odebug << "Server has no TLS support!" << oendl; |
79 | try_tls = false; | 79 | try_tls = false; |
80 | } else { | 80 | } else { |
81 | mailstream_low * low; | 81 | mailstream_low * low; |
82 | mailstream_low * new_low; | 82 | mailstream_low * new_low; |
83 | low = mailstream_get_low(m_imap->imap_stream); | 83 | low = mailstream_get_low(m_imap->imap_stream); |
84 | if (!low) { | 84 | if (!low) { |
85 | try_tls = false; | 85 | try_tls = false; |
86 | } else { | 86 | } else { |
87 | int fd = mailstream_low_get_fd(low); | 87 | int fd = mailstream_low_get_fd(low); |
88 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 88 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
89 | mailstream_low_free(low); | 89 | mailstream_low_free(low); |
90 | mailstream_set_low(m_imap->imap_stream, new_low); | 90 | mailstream_set_low(m_imap->imap_stream, new_low); |
91 | } else { | 91 | } else { |
92 | try_tls = false; | 92 | try_tls = false; |
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
97 | return try_tls; | 97 | return try_tls; |
98 | } | 98 | } |
99 | 99 | ||
100 | void IMAPwrapper::login() | 100 | void IMAPwrapper::login() |
101 | { | 101 | { |
102 | const char *server, *user, *pass; | 102 | const char *server, *user, *pass; |
@@ -105,100 +105,100 @@ void IMAPwrapper::login() | |||
105 | 105 | ||
106 | if (account->getOffline()) return; | 106 | if (account->getOffline()) return; |
107 | /* we are connected this moment */ | 107 | /* we are connected this moment */ |
108 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 108 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
109 | if (m_imap) { | 109 | if (m_imap) { |
110 | err = mailimap_noop(m_imap); | 110 | err = mailimap_noop(m_imap); |
111 | if (err!=MAILIMAP_NO_ERROR) { | 111 | if (err!=MAILIMAP_NO_ERROR) { |
112 | logout(); | 112 | logout(); |
113 | } else { | 113 | } else { |
114 | mailstream_flush(m_imap->imap_stream); | 114 | mailstream_flush(m_imap->imap_stream); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | server = account->getServer().latin1(); | 118 | server = account->getServer().latin1(); |
119 | port = account->getPort().toUInt(); | 119 | port = account->getPort().toUInt(); |
120 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 120 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
121 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 121 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
122 | login.show(); | 122 | login.show(); |
123 | if ( QDialog::Accepted == login.exec() ) { | 123 | if ( QDialog::Accepted == login.exec() ) { |
124 | // ok | 124 | // ok |
125 | user = login.getUser().latin1(); | 125 | user = login.getUser().latin1(); |
126 | pass = login.getPassword().latin1(); | 126 | pass = login.getPassword().latin1(); |
127 | } else { | 127 | } else { |
128 | // cancel | 128 | // cancel |
129 | odebug << "IMAP: Login canceled" << oendl; | 129 | odebug << "IMAP: Login canceled" << oendl; |
130 | return; | 130 | return; |
131 | } | 131 | } |
132 | } else { | 132 | } else { |
133 | user = account->getUser().latin1(); | 133 | user = account->getUser().latin1(); |
134 | pass = account->getPassword().latin1(); | 134 | pass = account->getPassword().latin1(); |
135 | } | 135 | } |
136 | 136 | ||
137 | m_imap = mailimap_new( 20, &imap_progress ); | 137 | m_imap = mailimap_new( 20, &imap_progress ); |
138 | 138 | ||
139 | /* connect */ | 139 | /* connect */ |
140 | bool ssl = false; | 140 | bool ssl = false; |
141 | bool try_tls = false; | 141 | bool try_tls = false; |
142 | bool force_tls = false; | 142 | bool force_tls = false; |
143 | 143 | ||
144 | if ( account->ConnectionType() == 2 ) { | 144 | if ( account->ConnectionType() == 2 ) { |
145 | ssl = true; | 145 | ssl = true; |
146 | } | 146 | } |
147 | if (account->ConnectionType()==1) { | 147 | if (account->ConnectionType()==1) { |
148 | force_tls = true; | 148 | force_tls = true; |
149 | } | 149 | } |
150 | 150 | ||
151 | if ( ssl ) { | 151 | if ( ssl ) { |
152 | odebug << "using ssl" << oendl; | 152 | odebug << "using ssl" << oendl; |
153 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 153 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
154 | } else { | 154 | } else { |
155 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 155 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
156 | } | 156 | } |
157 | 157 | ||
158 | if ( err != MAILIMAP_NO_ERROR && | 158 | if ( err != MAILIMAP_NO_ERROR && |
159 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 159 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
160 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 160 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
161 | QString failure = ""; | 161 | QString failure = ""; |
162 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 162 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
163 | failure="Connection refused"; | 163 | failure="Connection refused"; |
164 | } else { | 164 | } else { |
165 | failure="Unknown failure"; | 165 | failure="Unknown failure"; |
166 | } | 166 | } |
167 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 167 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
168 | mailimap_free( m_imap ); | 168 | mailimap_free( m_imap ); |
169 | m_imap = 0; | 169 | m_imap = 0; |
170 | return; | 170 | return; |
171 | } | 171 | } |
172 | 172 | ||
173 | if (!ssl) { | 173 | if (!ssl) { |
174 | try_tls = start_tls(force_tls); | 174 | try_tls = start_tls(force_tls); |
175 | } | 175 | } |
176 | 176 | ||
177 | bool ok = true; | 177 | bool ok = true; |
178 | if (force_tls && !try_tls) { | 178 | if (force_tls && !try_tls) { |
179 | Global::statusMessage(tr("Server has no TLS support!")); | 179 | Global::statusMessage(tr("Server has no TLS support!")); |
180 | odebug << "Server has no TLS support!" << oendl; | 180 | odebug << "Server has no TLS support!" << oendl; |
181 | ok = false; | 181 | ok = false; |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | /* login */ | 185 | /* login */ |
186 | 186 | ||
187 | if (ok) { | 187 | if (ok) { |
188 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 188 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
189 | if ( err != MAILIMAP_NO_ERROR ) { | 189 | if ( err != MAILIMAP_NO_ERROR ) { |
190 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 190 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
191 | ok = false; | 191 | ok = false; |
192 | } | 192 | } |
193 | } | 193 | } |
194 | if (!ok) { | 194 | if (!ok) { |
195 | err = mailimap_close( m_imap ); | 195 | err = mailimap_close( m_imap ); |
196 | mailimap_free( m_imap ); | 196 | mailimap_free( m_imap ); |
197 | m_imap = 0; | 197 | m_imap = 0; |
198 | } | 198 | } |
199 | } | 199 | } |
200 | 200 | ||
201 | void IMAPwrapper::logout() | 201 | void IMAPwrapper::logout() |
202 | { | 202 | { |
203 | int err = MAILIMAP_NO_ERROR; | 203 | int err = MAILIMAP_NO_ERROR; |
204 | if (!m_imap) return; | 204 | if (!m_imap) return; |
@@ -216,54 +216,58 @@ void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSma | |||
216 | clistcell *current; | 216 | clistcell *current; |
217 | mailimap_fetch_type *fetchType = 0; | 217 | mailimap_fetch_type *fetchType = 0; |
218 | mailimap_set *set = 0; | 218 | mailimap_set *set = 0; |
219 | 219 | ||
220 | login(); | 220 | login(); |
221 | if (!m_imap) { | 221 | if (!m_imap) { |
222 | return; | 222 | return; |
223 | } | 223 | } |
224 | /* select mailbox READONLY for operations */ | 224 | /* select mailbox READONLY for operations */ |
225 | err = selectMbox(mailbox); | 225 | err = selectMbox(mailbox); |
226 | if ( err != MAILIMAP_NO_ERROR ) { | 226 | if ( err != MAILIMAP_NO_ERROR ) { |
227 | return; | 227 | return; |
228 | } | 228 | } |
229 | 229 | ||
230 | int last = m_imap->imap_selection_info->sel_exists; | 230 | int last = m_imap->imap_selection_info->sel_exists; |
231 | 231 | ||
232 | if (last == 0) { | 232 | if (last == 0) { |
233 | Global::statusMessage(tr("Mailbox has no mails")); | 233 | Global::statusMessage(tr("Mailbox has no mails")); |
234 | return; | 234 | return; |
235 | } else { | 235 | } else { |
236 | } | 236 | } |
237 | 237 | ||
238 | /* the range has to start at 1!!! not with 0!!!! */ | 238 | /* the range has to start at 1!!! not with 0!!!! */ |
239 | set = mailimap_set_new_interval( 1, last ); | 239 | set = mailimap_set_new_interval( 1, last ); |
240 | |||
241 | |||
242 | fetchType = mailimap_fetch_type_new_all(); | ||
243 | /* | ||
240 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 244 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
241 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 245 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
242 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 246 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
243 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 247 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
244 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 248 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
245 | 249 | */ | |
246 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 250 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
247 | mailimap_set_free( set ); | 251 | mailimap_set_free( set ); |
248 | mailimap_fetch_type_free( fetchType ); | 252 | mailimap_fetch_type_free( fetchType ); |
249 | 253 | ||
250 | QString date,subject,from; | 254 | QString date,subject,from; |
251 | 255 | ||
252 | if ( err == MAILIMAP_NO_ERROR ) { | 256 | if ( err == MAILIMAP_NO_ERROR ) { |
253 | mailimap_msg_att * msg_att; | 257 | mailimap_msg_att * msg_att; |
254 | int i = 0; | 258 | int i = 0; |
255 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 259 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
256 | ++i; | 260 | ++i; |
257 | msg_att = (mailimap_msg_att*)current->data; | 261 | msg_att = (mailimap_msg_att*)current->data; |
258 | RecMail*m = parse_list_result(msg_att); | 262 | RecMail*m = parse_list_result(msg_att); |
259 | if (m) { | 263 | if (m) { |
260 | m->setNumber(i); | 264 | m->setNumber(i); |
261 | m->setMbox(mailbox); | 265 | m->setMbox(mailbox); |
262 | m->setWrapper(this); | 266 | m->setWrapper(this); |
263 | target.append(m); | 267 | target.append(m); |
264 | } | 268 | } |
265 | } | 269 | } |
266 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 270 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
267 | } else { | 271 | } else { |
268 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 272 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
269 | } | 273 | } |
@@ -297,109 +301,109 @@ QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | |||
297 | QString del; | 301 | QString del; |
298 | bool selectable = true; | 302 | bool selectable = true; |
299 | bool no_inferiors = false; | 303 | bool no_inferiors = false; |
300 | if ( err == MAILIMAP_NO_ERROR ) { | 304 | if ( err == MAILIMAP_NO_ERROR ) { |
301 | current = result->first; | 305 | current = result->first; |
302 | for ( int i = result->count; i > 0; i-- ) { | 306 | for ( int i = result->count; i > 0; i-- ) { |
303 | list = (mailimap_mailbox_list *) current->data; | 307 | list = (mailimap_mailbox_list *) current->data; |
304 | // it is better use the deep copy mechanism of qt itself | 308 | // it is better use the deep copy mechanism of qt itself |
305 | // instead of using strdup! | 309 | // instead of using strdup! |
306 | temp = list->mb_name; | 310 | temp = list->mb_name; |
307 | del = list->mb_delimiter; | 311 | del = list->mb_delimiter; |
308 | current = current->next; | 312 | current = current->next; |
309 | if ( (bflags = list->mb_flag) ) { | 313 | if ( (bflags = list->mb_flag) ) { |
310 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 314 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
311 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 315 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
312 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 316 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
313 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 317 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
314 | no_inferiors = true; | 318 | no_inferiors = true; |
315 | } | 319 | } |
316 | } | 320 | } |
317 | } | 321 | } |
318 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 322 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
319 | } | 323 | } |
320 | } else { | 324 | } else { |
321 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; | 325 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; |
322 | } | 326 | } |
323 | mailimap_list_result_free( result ); | 327 | mailimap_list_result_free( result ); |
324 | 328 | ||
325 | /* | 329 | /* |
326 | * second stage - get the other then inbox folders | 330 | * second stage - get the other then inbox folders |
327 | */ | 331 | */ |
328 | mask = "*" ; | 332 | mask = "*" ; |
329 | path = account->getPrefix().latin1(); | 333 | path = account->getPrefix().latin1(); |
330 | if (!path) path = ""; | 334 | if (!path) path = ""; |
331 | odebug << path << oendl; | 335 | odebug << path << oendl; |
332 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 336 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
333 | if ( err == MAILIMAP_NO_ERROR ) { | 337 | if ( err == MAILIMAP_NO_ERROR ) { |
334 | current = result->first; | 338 | current = result->first; |
335 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 339 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
336 | no_inferiors = false; | 340 | no_inferiors = false; |
337 | list = (mailimap_mailbox_list *) current->data; | 341 | list = (mailimap_mailbox_list *) current->data; |
338 | // it is better use the deep copy mechanism of qt itself | 342 | // it is better use the deep copy mechanism of qt itself |
339 | // instead of using strdup! | 343 | // instead of using strdup! |
340 | temp = list->mb_name; | 344 | temp = list->mb_name; |
341 | if (temp.lower()=="inbox") | 345 | if (temp.lower()=="inbox") |
342 | continue; | 346 | continue; |
343 | if (temp.lower()==account->getPrefix().lower()) | 347 | if (temp.lower()==account->getPrefix().lower()) |
344 | continue; | 348 | continue; |
345 | if ( (bflags = list->mb_flag) ) { | 349 | if ( (bflags = list->mb_flag) ) { |
346 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 350 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
347 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 351 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
348 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 352 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
349 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 353 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
350 | no_inferiors = true; | 354 | no_inferiors = true; |
351 | } | 355 | } |
352 | } | 356 | } |
353 | } | 357 | } |
354 | del = list->mb_delimiter; | 358 | del = list->mb_delimiter; |
355 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 359 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
356 | } | 360 | } |
357 | } else { | 361 | } else { |
358 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; | 362 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; |
359 | } | 363 | } |
360 | if (result) mailimap_list_result_free( result ); | 364 | if (result) mailimap_list_result_free( result ); |
361 | return folders; | 365 | return folders; |
362 | } | 366 | } |
363 | 367 | ||
364 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 368 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
365 | { | 369 | { |
366 | RecMail * m = 0; | 370 | RecMail * m = 0; |
367 | mailimap_msg_att_item *item=0; | 371 | mailimap_msg_att_item *item=0; |
368 | clistcell *current,*c,*cf; | 372 | clistcell *current,*c,*cf; |
369 | mailimap_msg_att_dynamic*flist; | 373 | mailimap_msg_att_dynamic*flist; |
370 | mailimap_flag_fetch*cflag; | 374 | mailimap_flag_fetch*cflag; |
371 | int size; | 375 | int size; |
372 | QBitArray mFlags(7); | 376 | QBitArray mFlags(7); |
373 | QStringList addresslist; | 377 | QStringList addresslist; |
374 | 378 | ||
375 | if (!m_att) { | 379 | if (!m_att) { |
376 | return m; | 380 | return m; |
377 | } | 381 | } |
382 | size = 0; | ||
378 | m = new RecMail(); | 383 | m = new RecMail(); |
379 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 384 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
380 | current = c; | 385 | current = c; |
381 | size = 0; | ||
382 | item = (mailimap_msg_att_item*)current->data; | 386 | item = (mailimap_msg_att_item*)current->data; |
383 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 387 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
384 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 388 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
385 | if (!flist->att_list) { | 389 | if (!flist->att_list) { |
386 | continue; | 390 | continue; |
387 | } | 391 | } |
388 | cf = flist->att_list->first; | 392 | cf = flist->att_list->first; |
389 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 393 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
390 | cflag = (mailimap_flag_fetch*)cf->data; | 394 | cflag = (mailimap_flag_fetch*)cf->data; |
391 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 395 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
392 | switch (cflag->fl_flag->fl_type) { | 396 | switch (cflag->fl_flag->fl_type) { |
393 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 397 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
394 | mFlags.setBit(FLAG_ANSWERED); | 398 | mFlags.setBit(FLAG_ANSWERED); |
395 | break; | 399 | break; |
396 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 400 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
397 | mFlags.setBit(FLAG_FLAGGED); | 401 | mFlags.setBit(FLAG_FLAGGED); |
398 | break; | 402 | break; |
399 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 403 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
400 | mFlags.setBit(FLAG_DELETED); | 404 | mFlags.setBit(FLAG_DELETED); |
401 | break; | 405 | break; |
402 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 406 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
403 | mFlags.setBit(FLAG_SEEN); | 407 | mFlags.setBit(FLAG_SEEN); |
404 | break; | 408 | break; |
405 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 409 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
@@ -444,109 +448,115 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
444 | /* reply to address, eg. email. */ | 448 | /* reply to address, eg. email. */ |
445 | if (head->env_reply_to!=NULL) { | 449 | if (head->env_reply_to!=NULL) { |
446 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 450 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
447 | if (addresslist.count()) { | 451 | if (addresslist.count()) { |
448 | m->setReplyto(addresslist.first()); | 452 | m->setReplyto(addresslist.first()); |
449 | } | 453 | } |
450 | } | 454 | } |
451 | if (head->env_in_reply_to!=NULL) { | 455 | if (head->env_in_reply_to!=NULL) { |
452 | QString h(head->env_in_reply_to); | 456 | QString h(head->env_in_reply_to); |
453 | while (h.length()>0 && h[0]=='<') { | 457 | while (h.length()>0 && h[0]=='<') { |
454 | h.remove(0,1); | 458 | h.remove(0,1); |
455 | } | 459 | } |
456 | while (h.length()>0 && h[h.length()-1]=='>') { | 460 | while (h.length()>0 && h[h.length()-1]=='>') { |
457 | h.remove(h.length()-1,1); | 461 | h.remove(h.length()-1,1); |
458 | } | 462 | } |
459 | if (h.length()>0) { | 463 | if (h.length()>0) { |
460 | m->setInreply(QStringList(h)); | 464 | m->setInreply(QStringList(h)); |
461 | } | 465 | } |
462 | } | 466 | } |
463 | if (head->env_message_id) { | 467 | if (head->env_message_id) { |
464 | m->setMsgid(QString(head->env_message_id)); | 468 | m->setMsgid(QString(head->env_message_id)); |
465 | } | 469 | } |
466 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 470 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
467 | #if 0 | 471 | #if 0 |
468 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 472 | mailimap_date_time*date = item->att_data.att_static->att_data.att_internal_date; |
473 | if (date->dt_sec>60 || date->dt_sec<0) date->dt_sec=0; | ||
474 | //QDateTime da(QDate(d->dt_year,date->dt_month,date->dt_day),QTime(date->dt_hour,date->dt_min,date->dt_sec)); | ||
475 | QString timestring = TimeString::numberDateString(QDate(date->dt_year,date->dt_month,date->dt_day))+" "; | ||
476 | timestring+=TimeString::timeString(QTime(date->dt_hour,date->dt_min,date->dt_sec))+" "; | ||
477 | timestring.sprintf(timestring+" %+05i",date->dt_zone); | ||
478 | m->setDate(timestring); | ||
469 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 479 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
470 | odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; | 480 | odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; |
471 | odebug << da.toString() << oendl; | 481 | odebug << da.toString() << oendl; |
472 | #endif | 482 | #endif |
473 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 483 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
474 | size = item->att_data.att_static->att_data.att_rfc822_size; | 484 | //size = item->att_data.att_static->att_data.att_rfc822_size; |
485 | m->setMsgsize(item->att_data.att_static->att_data.att_rfc822_size); | ||
475 | } | 486 | } |
476 | } | 487 | } |
477 | /* msg is already deleted */ | 488 | /* msg is already deleted */ |
478 | if (mFlags.testBit(FLAG_DELETED) && m) { | 489 | if (mFlags.testBit(FLAG_DELETED) && m) { |
479 | delete m; | 490 | delete m; |
480 | m = 0; | 491 | m = 0; |
481 | } | 492 | } |
482 | if (m) { | 493 | if (m) { |
483 | m->setFlags(mFlags); | 494 | m->setFlags(mFlags); |
484 | m->setMsgsize(size); | ||
485 | } | 495 | } |
486 | return m; | 496 | return m; |
487 | } | 497 | } |
488 | 498 | ||
489 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 499 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
490 | { | 500 | { |
491 | RecBodyP body = new RecBody(); | 501 | RecBodyP body = new RecBody(); |
492 | const char *mb; | 502 | const char *mb; |
493 | int err = MAILIMAP_NO_ERROR; | 503 | int err = MAILIMAP_NO_ERROR; |
494 | clist *result = 0; | 504 | clist *result = 0; |
495 | clistcell *current; | 505 | clistcell *current; |
496 | mailimap_fetch_att *fetchAtt = 0; | 506 | mailimap_fetch_att *fetchAtt = 0; |
497 | mailimap_fetch_type *fetchType = 0; | 507 | mailimap_fetch_type *fetchType = 0; |
498 | mailimap_set *set = 0; | 508 | mailimap_set *set = 0; |
499 | mailimap_body*body_desc = 0; | 509 | mailimap_body*body_desc = 0; |
500 | 510 | ||
501 | mb = mail->getMbox().latin1(); | 511 | mb = mail->getMbox().latin1(); |
502 | 512 | ||
503 | login(); | 513 | login(); |
504 | if (!m_imap) { | 514 | if (!m_imap) { |
505 | return body; | 515 | return body; |
506 | } | 516 | } |
507 | err = selectMbox(mail->getMbox()); | 517 | err = selectMbox(mail->getMbox()); |
508 | if ( err != MAILIMAP_NO_ERROR ) { | 518 | if ( err != MAILIMAP_NO_ERROR ) { |
509 | return body; | 519 | return body; |
510 | } | 520 | } |
511 | 521 | ||
512 | /* the range has to start at 1!!! not with 0!!!! */ | 522 | /* the range has to start at 1!!! not with 0!!!! */ |
513 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 523 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
514 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 524 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
515 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 525 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
516 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 526 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
517 | mailimap_set_free( set ); | 527 | mailimap_set_free( set ); |
518 | mailimap_fetch_type_free( fetchType ); | 528 | mailimap_fetch_type_free( fetchType ); |
519 | 529 | ||
520 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 530 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
521 | mailimap_msg_att * msg_att; | 531 | mailimap_msg_att * msg_att; |
522 | msg_att = (mailimap_msg_att*)current->data; | 532 | msg_att = (mailimap_msg_att*)current->data; |
523 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 533 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
524 | QValueList<int> path; | 534 | QValueList<int> path; |
525 | body_desc = item->att_data.att_static->att_data.att_body; | 535 | body_desc = item->att_data.att_static->att_data.att_body; |
526 | traverseBody(mail,body_desc,body,0,path); | 536 | traverseBody(mail,body_desc,body,0,path); |
527 | } else { | 537 | } else { |
528 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; | 538 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; |
529 | } | 539 | } |
530 | if (result) mailimap_fetch_list_free(result); | 540 | if (result) mailimap_fetch_list_free(result); |
531 | return body; | 541 | return body; |
532 | } | 542 | } |
533 | 543 | ||
534 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 544 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
535 | { | 545 | { |
536 | QStringList l; | 546 | QStringList l; |
537 | QString from; | 547 | QString from; |
538 | bool named_from; | 548 | bool named_from; |
539 | clistcell *current = NULL; | 549 | clistcell *current = NULL; |
540 | mailimap_address * current_address=NULL; | 550 | mailimap_address * current_address=NULL; |
541 | if (!list) { | 551 | if (!list) { |
542 | return l; | 552 | return l; |
543 | } | 553 | } |
544 | unsigned int count = 0; | 554 | unsigned int count = 0; |
545 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 555 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
546 | from = ""; | 556 | from = ""; |
547 | named_from = false; | 557 | named_from = false; |
548 | current_address=(mailimap_address*)current->data; | 558 | current_address=(mailimap_address*)current->data; |
549 | if (current_address->ad_personal_name){ | 559 | if (current_address->ad_personal_name){ |
550 | from+=convert_String((const char*)current_address->ad_personal_name); | 560 | from+=convert_String((const char*)current_address->ad_personal_name); |
551 | from+=" "; | 561 | from+=" "; |
552 | named_from = true; | 562 | named_from = true; |
@@ -616,173 +626,173 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int | |||
616 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 626 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
617 | 627 | ||
618 | clist*result = 0; | 628 | clist*result = 0; |
619 | 629 | ||
620 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 630 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
621 | mailimap_set_free( set ); | 631 | mailimap_set_free( set ); |
622 | mailimap_fetch_type_free( fetchType ); | 632 | mailimap_fetch_type_free( fetchType ); |
623 | 633 | ||
624 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 634 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
625 | mailimap_msg_att * msg_att; | 635 | mailimap_msg_att * msg_att; |
626 | msg_att = (mailimap_msg_att*)current->data; | 636 | msg_att = (mailimap_msg_att*)current->data; |
627 | mailimap_msg_att_item*msg_att_item; | 637 | mailimap_msg_att_item*msg_att_item; |
628 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 638 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
629 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 639 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
630 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 640 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
631 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 641 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
632 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 642 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
633 | /* detach - we take over the content */ | 643 | /* detach - we take over the content */ |
634 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 644 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
635 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 645 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
636 | } | 646 | } |
637 | } | 647 | } |
638 | } | 648 | } |
639 | } else { | 649 | } else { |
640 | odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 650 | odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
641 | } | 651 | } |
642 | if (result) mailimap_fetch_list_free(result); | 652 | if (result) mailimap_fetch_list_free(result); |
643 | return res; | 653 | return res; |
644 | } | 654 | } |
645 | 655 | ||
646 | /* current_recursion is for recursive calls. | 656 | /* current_recursion is for recursive calls. |
647 | current_count means the position inside the internal loop! */ | 657 | current_count means the position inside the internal loop! */ |
648 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 658 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
649 | int current_recursion,QValueList<int>recList,int current_count) | 659 | int current_recursion,QValueList<int>recList,int current_count) |
650 | { | 660 | { |
651 | if (!body || current_recursion>=10) { | 661 | if (!body || current_recursion>=10) { |
652 | return; | 662 | return; |
653 | } | 663 | } |
654 | switch (body->bd_type) { | 664 | switch (body->bd_type) { |
655 | case MAILIMAP_BODY_1PART: | 665 | case MAILIMAP_BODY_1PART: |
656 | { | 666 | { |
657 | QValueList<int>countlist = recList; | 667 | QValueList<int>countlist = recList; |
658 | countlist.append(current_count); | 668 | countlist.append(current_count); |
659 | RecPartP currentPart = new RecPart(); | 669 | RecPartP currentPart = new RecPart(); |
660 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 670 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
661 | QString id(""); | 671 | QString id(""); |
662 | currentPart->setPositionlist(countlist); | 672 | currentPart->setPositionlist(countlist); |
663 | for (unsigned int j = 0; j < countlist.count();++j) { | 673 | for (unsigned int j = 0; j < countlist.count();++j) { |
664 | id+=(j>0?" ":""); | 674 | id+=(j>0?" ":""); |
665 | id+=QString("%1").arg(countlist[j]); | 675 | id+=QString("%1").arg(countlist[j]); |
666 | } | 676 | } |
667 | odebug << "ID = " << id.latin1() << "" << oendl; | 677 | odebug << "ID = " << id.latin1() << "" << oendl; |
668 | currentPart->setIdentifier(id); | 678 | currentPart->setIdentifier(id); |
669 | fillSinglePart(currentPart,part1); | 679 | fillSinglePart(currentPart,part1); |
670 | /* important: Check for is NULL 'cause a body can be empty! | 680 | /* important: Check for is NULL 'cause a body can be empty! |
671 | And we put it only into the mail if it is the FIRST part */ | 681 | And we put it only into the mail if it is the FIRST part */ |
672 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 682 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
673 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 683 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
674 | target_body->setDescription(currentPart); | 684 | target_body->setDescription(currentPart); |
675 | target_body->setBodytext(body_text); | 685 | target_body->setBodytext(body_text); |
676 | if (countlist.count()>1) { | 686 | if (countlist.count()>1) { |
677 | target_body->addPart(currentPart); | 687 | target_body->addPart(currentPart); |
678 | } | 688 | } |
679 | } else { | 689 | } else { |
680 | target_body->addPart(currentPart); | 690 | target_body->addPart(currentPart); |
681 | } | 691 | } |
682 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 692 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
683 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 693 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
684 | } | 694 | } |
685 | } | 695 | } |
686 | break; | 696 | break; |
687 | case MAILIMAP_BODY_MPART: | 697 | case MAILIMAP_BODY_MPART: |
688 | { | 698 | { |
689 | QValueList<int>countlist = recList; | 699 | QValueList<int>countlist = recList; |
690 | clistcell*current=0; | 700 | clistcell*current=0; |
691 | mailimap_body*current_body=0; | 701 | mailimap_body*current_body=0; |
692 | unsigned int ccount = 1; | 702 | unsigned int ccount = 1; |
693 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 703 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
694 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 704 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
695 | current_body = (mailimap_body*)current->data; | 705 | current_body = (mailimap_body*)current->data; |
696 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 706 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
697 | RecPartP targetPart = new RecPart(); | 707 | RecPartP targetPart = new RecPart(); |
698 | targetPart->setType("multipart"); | 708 | targetPart->setType("multipart"); |
699 | fillMultiPart(targetPart,mailDescription); | 709 | fillMultiPart(targetPart,mailDescription); |
700 | countlist.append(current_count); | 710 | countlist.append(current_count); |
701 | targetPart->setPositionlist(countlist); | 711 | targetPart->setPositionlist(countlist); |
702 | target_body->addPart(targetPart); | 712 | target_body->addPart(targetPart); |
703 | QString id(""); | 713 | QString id(""); |
704 | for (unsigned int j = 0; j < countlist.count();++j) { | 714 | for (unsigned int j = 0; j < countlist.count();++j) { |
705 | id+=(j>0?" ":""); | 715 | id+=(j>0?" ":""); |
706 | id+=QString("%1").arg(countlist[j]); | 716 | id+=QString("%1").arg(countlist[j]); |
707 | } | 717 | } |
708 | odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 718 | odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
709 | } | 719 | } |
710 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 720 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
711 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 721 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
712 | countlist = recList; | 722 | countlist = recList; |
713 | } | 723 | } |
714 | ++ccount; | 724 | ++ccount; |
715 | } | 725 | } |
716 | } | 726 | } |
717 | break; | 727 | break; |
718 | default: | 728 | default: |
719 | break; | 729 | break; |
720 | } | 730 | } |
721 | } | 731 | } |
722 | 732 | ||
723 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | 733 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) |
724 | { | 734 | { |
725 | if (!Description) { | 735 | if (!Description) { |
726 | return; | 736 | return; |
727 | } | 737 | } |
728 | switch (Description->bd_type) { | 738 | switch (Description->bd_type) { |
729 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 739 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
730 | target_part->setType("text"); | 740 | target_part->setType("text"); |
731 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 741 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
732 | break; | 742 | break; |
733 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 743 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
734 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 744 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
735 | break; | 745 | break; |
736 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 746 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
737 | target_part->setType("message"); | 747 | target_part->setType("message"); |
738 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 748 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
739 | break; | 749 | break; |
740 | default: | 750 | default: |
741 | break; | 751 | break; |
742 | } | 752 | } |
743 | } | 753 | } |
744 | 754 | ||
745 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | 755 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) |
746 | { | 756 | { |
747 | if (!which) { | 757 | if (!which) { |
748 | return; | 758 | return; |
749 | } | 759 | } |
750 | QString sub; | 760 | QString sub; |
751 | sub = which->bd_media_text; | 761 | sub = which->bd_media_text; |
752 | odebug << "Type= text/" << which->bd_media_text << "" << oendl; | 762 | odebug << "Type= text/" << which->bd_media_text << "" << oendl; |
753 | target_part->setSubtype(sub.lower()); | 763 | target_part->setSubtype(sub.lower()); |
754 | target_part->setLines(which->bd_lines); | 764 | target_part->setLines(which->bd_lines); |
755 | fillBodyFields(target_part,which->bd_fields); | 765 | fillBodyFields(target_part,which->bd_fields); |
756 | } | 766 | } |
757 | 767 | ||
758 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | 768 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) |
759 | { | 769 | { |
760 | if (!which) { | 770 | if (!which) { |
761 | return; | 771 | return; |
762 | } | 772 | } |
763 | target_part->setSubtype("rfc822"); | 773 | target_part->setSubtype("rfc822"); |
764 | odebug << "Message part" << oendl; | 774 | odebug << "Message part" << oendl; |
765 | /* we set this type to text/plain */ | 775 | /* we set this type to text/plain */ |
766 | target_part->setLines(which->bd_lines); | 776 | target_part->setLines(which->bd_lines); |
767 | fillBodyFields(target_part,which->bd_fields); | 777 | fillBodyFields(target_part,which->bd_fields); |
768 | } | 778 | } |
769 | 779 | ||
770 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | 780 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) |
771 | { | 781 | { |
772 | if (!which) return; | 782 | if (!which) return; |
773 | QString sub = which->bd_media_subtype; | 783 | QString sub = which->bd_media_subtype; |
774 | target_part->setSubtype(sub.lower()); | 784 | target_part->setSubtype(sub.lower()); |
775 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 785 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
776 | clistcell*cur = 0; | 786 | clistcell*cur = 0; |
777 | mailimap_single_body_fld_param*param=0; | 787 | mailimap_single_body_fld_param*param=0; |
778 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 788 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
779 | param = (mailimap_single_body_fld_param*)cur->data; | 789 | param = (mailimap_single_body_fld_param*)cur->data; |
780 | if (param) { | 790 | if (param) { |
781 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 791 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
782 | } | 792 | } |
783 | } | 793 | } |
784 | } | 794 | } |
785 | } | 795 | } |
786 | 796 | ||
787 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | 797 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) |
788 | { | 798 | { |
@@ -799,49 +809,49 @@ void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_ba | |||
799 | break; | 809 | break; |
800 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 810 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
801 | type = "image"; | 811 | type = "image"; |
802 | break; | 812 | break; |
803 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 813 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
804 | type = "message"; | 814 | type = "message"; |
805 | break; | 815 | break; |
806 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 816 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
807 | type = "video"; | 817 | type = "video"; |
808 | break; | 818 | break; |
809 | case MAILIMAP_MEDIA_BASIC_OTHER: | 819 | case MAILIMAP_MEDIA_BASIC_OTHER: |
810 | default: | 820 | default: |
811 | if (which->bd_media_basic->med_basic_type) { | 821 | if (which->bd_media_basic->med_basic_type) { |
812 | type = which->bd_media_basic->med_basic_type; | 822 | type = which->bd_media_basic->med_basic_type; |
813 | } else { | 823 | } else { |
814 | type = ""; | 824 | type = ""; |
815 | } | 825 | } |
816 | break; | 826 | break; |
817 | } | 827 | } |
818 | if (which->bd_media_basic->med_subtype) { | 828 | if (which->bd_media_basic->med_subtype) { |
819 | sub = which->bd_media_basic->med_subtype; | 829 | sub = which->bd_media_basic->med_subtype; |
820 | } else { | 830 | } else { |
821 | sub = ""; | 831 | sub = ""; |
822 | } | 832 | } |
823 | odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; | 833 | odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; |
824 | target_part->setType(type.lower()); | 834 | target_part->setType(type.lower()); |
825 | target_part->setSubtype(sub.lower()); | 835 | target_part->setSubtype(sub.lower()); |
826 | fillBodyFields(target_part,which->bd_fields); | 836 | fillBodyFields(target_part,which->bd_fields); |
827 | } | 837 | } |
828 | 838 | ||
829 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) | 839 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) |
830 | { | 840 | { |
831 | if (!which) return; | 841 | if (!which) return; |
832 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 842 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
833 | clistcell*cur; | 843 | clistcell*cur; |
834 | mailimap_single_body_fld_param*param=0; | 844 | mailimap_single_body_fld_param*param=0; |
835 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 845 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
836 | param = (mailimap_single_body_fld_param*)cur->data; | 846 | param = (mailimap_single_body_fld_param*)cur->data; |
837 | if (param) { | 847 | if (param) { |
838 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 848 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
839 | } | 849 | } |
840 | } | 850 | } |
841 | } | 851 | } |
842 | mailimap_body_fld_enc*enc = which->bd_encoding; | 852 | mailimap_body_fld_enc*enc = which->bd_encoding; |
843 | QString encoding(""); | 853 | QString encoding(""); |
844 | switch (enc->enc_type) { | 854 | switch (enc->enc_type) { |
845 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 855 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
846 | encoding = "7bit"; | 856 | encoding = "7bit"; |
847 | break; | 857 | break; |
@@ -875,84 +885,84 @@ void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which | |||
875 | 885 | ||
876 | void IMAPwrapper::deleteMail(const RecMailP&mail) | 886 | void IMAPwrapper::deleteMail(const RecMailP&mail) |
877 | { | 887 | { |
878 | mailimap_flag_list*flist; | 888 | mailimap_flag_list*flist; |
879 | mailimap_set *set; | 889 | mailimap_set *set; |
880 | mailimap_store_att_flags * store_flags; | 890 | mailimap_store_att_flags * store_flags; |
881 | int err; | 891 | int err; |
882 | login(); | 892 | login(); |
883 | if (!m_imap) { | 893 | if (!m_imap) { |
884 | return; | 894 | return; |
885 | } | 895 | } |
886 | err = selectMbox(mail->getMbox()); | 896 | err = selectMbox(mail->getMbox()); |
887 | if ( err != MAILIMAP_NO_ERROR ) { | 897 | if ( err != MAILIMAP_NO_ERROR ) { |
888 | return; | 898 | return; |
889 | } | 899 | } |
890 | flist = mailimap_flag_list_new_empty(); | 900 | flist = mailimap_flag_list_new_empty(); |
891 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 901 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
892 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 902 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
893 | set = mailimap_set_new_single(mail->getNumber()); | 903 | set = mailimap_set_new_single(mail->getNumber()); |
894 | err = mailimap_store(m_imap,set,store_flags); | 904 | err = mailimap_store(m_imap,set,store_flags); |
895 | mailimap_set_free( set ); | 905 | mailimap_set_free( set ); |
896 | mailimap_store_att_flags_free(store_flags); | 906 | mailimap_store_att_flags_free(store_flags); |
897 | 907 | ||
898 | if (err != MAILIMAP_NO_ERROR) { | 908 | if (err != MAILIMAP_NO_ERROR) { |
899 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 909 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
900 | return; | 910 | return; |
901 | } | 911 | } |
902 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 912 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
903 | /* should we realy do that at this moment? */ | 913 | /* should we realy do that at this moment? */ |
904 | err = mailimap_expunge(m_imap); | 914 | err = mailimap_expunge(m_imap); |
905 | if (err != MAILIMAP_NO_ERROR) { | 915 | if (err != MAILIMAP_NO_ERROR) { |
906 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 916 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
907 | } | 917 | } |
908 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 918 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; |
909 | } | 919 | } |
910 | 920 | ||
911 | void IMAPwrapper::answeredMail(const RecMailP&mail) | 921 | void IMAPwrapper::answeredMail(const RecMailP&mail) |
912 | { | 922 | { |
913 | mailimap_flag_list*flist; | 923 | mailimap_flag_list*flist; |
914 | mailimap_set *set; | 924 | mailimap_set *set; |
915 | mailimap_store_att_flags * store_flags; | 925 | mailimap_store_att_flags * store_flags; |
916 | int err; | 926 | int err; |
917 | login(); | 927 | login(); |
918 | if (!m_imap) { | 928 | if (!m_imap) { |
919 | return; | 929 | return; |
920 | } | 930 | } |
921 | err = selectMbox(mail->getMbox()); | 931 | err = selectMbox(mail->getMbox()); |
922 | if ( err != MAILIMAP_NO_ERROR ) { | 932 | if ( err != MAILIMAP_NO_ERROR ) { |
923 | return; | 933 | return; |
924 | } | 934 | } |
925 | flist = mailimap_flag_list_new_empty(); | 935 | flist = mailimap_flag_list_new_empty(); |
926 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 936 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
927 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 937 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
928 | set = mailimap_set_new_single(mail->getNumber()); | 938 | set = mailimap_set_new_single(mail->getNumber()); |
929 | err = mailimap_store(m_imap,set,store_flags); | 939 | err = mailimap_store(m_imap,set,store_flags); |
930 | mailimap_set_free( set ); | 940 | mailimap_set_free( set ); |
931 | mailimap_store_att_flags_free(store_flags); | 941 | mailimap_store_att_flags_free(store_flags); |
932 | 942 | ||
933 | if (err != MAILIMAP_NO_ERROR) { | 943 | if (err != MAILIMAP_NO_ERROR) { |
934 | odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | 944 | odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; |
935 | return; | 945 | return; |
936 | } | 946 | } |
937 | } | 947 | } |
938 | 948 | ||
939 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 949 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
940 | { | 950 | { |
941 | QString body(""); | 951 | QString body(""); |
942 | encodedString*res = fetchRawPart(mail,path,internal_call); | 952 | encodedString*res = fetchRawPart(mail,path,internal_call); |
943 | encodedString*r = decode_String(res,enc); | 953 | encodedString*r = decode_String(res,enc); |
944 | delete res; | 954 | delete res; |
945 | if (r) { | 955 | if (r) { |
946 | if (r->Length()>0) { | 956 | if (r->Length()>0) { |
947 | body = r->Content(); | 957 | body = r->Content(); |
948 | } | 958 | } |
949 | delete r; | 959 | delete r; |
950 | } | 960 | } |
951 | return body; | 961 | return body; |
952 | } | 962 | } |
953 | 963 | ||
954 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 964 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
955 | { | 965 | { |
956 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); | 966 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); |
957 | } | 967 | } |
958 | 968 | ||
@@ -978,81 +988,81 @@ int IMAPwrapper::deleteAllMail(const FolderP&folder) | |||
978 | mailimap_flag_list*flist; | 988 | mailimap_flag_list*flist; |
979 | mailimap_set *set; | 989 | mailimap_set *set; |
980 | mailimap_store_att_flags * store_flags; | 990 | mailimap_store_att_flags * store_flags; |
981 | int err = selectMbox(folder->getName()); | 991 | int err = selectMbox(folder->getName()); |
982 | if ( err != MAILIMAP_NO_ERROR ) { | 992 | if ( err != MAILIMAP_NO_ERROR ) { |
983 | return 0; | 993 | return 0; |
984 | } | 994 | } |
985 | 995 | ||
986 | int last = m_imap->imap_selection_info->sel_exists; | 996 | int last = m_imap->imap_selection_info->sel_exists; |
987 | if (last == 0) { | 997 | if (last == 0) { |
988 | Global::statusMessage(tr("Mailbox has no mails!")); | 998 | Global::statusMessage(tr("Mailbox has no mails!")); |
989 | return 0; | 999 | return 0; |
990 | } | 1000 | } |
991 | flist = mailimap_flag_list_new_empty(); | 1001 | flist = mailimap_flag_list_new_empty(); |
992 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1002 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
993 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1003 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
994 | set = mailimap_set_new_interval( 1, last ); | 1004 | set = mailimap_set_new_interval( 1, last ); |
995 | err = mailimap_store(m_imap,set,store_flags); | 1005 | err = mailimap_store(m_imap,set,store_flags); |
996 | mailimap_set_free( set ); | 1006 | mailimap_set_free( set ); |
997 | mailimap_store_att_flags_free(store_flags); | 1007 | mailimap_store_att_flags_free(store_flags); |
998 | if (err != MAILIMAP_NO_ERROR) { | 1008 | if (err != MAILIMAP_NO_ERROR) { |
999 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 1009 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
1000 | return 0; | 1010 | return 0; |
1001 | } | 1011 | } |
1002 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1012 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1003 | /* should we realy do that at this moment? */ | 1013 | /* should we realy do that at this moment? */ |
1004 | err = mailimap_expunge(m_imap); | 1014 | err = mailimap_expunge(m_imap); |
1005 | if (err != MAILIMAP_NO_ERROR) { | 1015 | if (err != MAILIMAP_NO_ERROR) { |
1006 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 1016 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
1007 | return 0; | 1017 | return 0; |
1008 | } | 1018 | } |
1009 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 1019 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; |
1010 | return 1; | 1020 | return 1; |
1011 | } | 1021 | } |
1012 | 1022 | ||
1013 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) | 1023 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) |
1014 | { | 1024 | { |
1015 | if (folder.length()==0) return 0; | 1025 | if (folder.length()==0) return 0; |
1016 | login(); | 1026 | login(); |
1017 | if (!m_imap) {return 0;} | 1027 | if (!m_imap) {return 0;} |
1018 | QString pre = account->getPrefix(); | 1028 | QString pre = account->getPrefix(); |
1019 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | 1029 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { |
1020 | pre+=delemiter; | 1030 | pre+=delemiter; |
1021 | } | 1031 | } |
1022 | if (parentfolder) { | 1032 | if (parentfolder) { |
1023 | pre += parentfolder->getDisplayName()+delemiter; | 1033 | pre += parentfolder->getDisplayName()+delemiter; |
1024 | } | 1034 | } |
1025 | pre+=folder; | 1035 | pre+=folder; |
1026 | if (getsubfolder) { | 1036 | if (getsubfolder) { |
1027 | if (delemiter.length()>0) { | 1037 | if (delemiter.length()>0) { |
1028 | pre+=delemiter; | 1038 | pre+=delemiter; |
1029 | } else { | 1039 | } else { |
1030 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | 1040 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); |
1031 | return 0; | 1041 | return 0; |
1032 | } | 1042 | } |
1033 | } | 1043 | } |
1034 | odebug << "Creating " << pre.latin1() << "" << oendl; | 1044 | odebug << "Creating " << pre.latin1() << "" << oendl; |
1035 | int res = mailimap_create(m_imap,pre.latin1()); | 1045 | int res = mailimap_create(m_imap,pre.latin1()); |
1036 | if (res != MAILIMAP_NO_ERROR) { | 1046 | if (res != MAILIMAP_NO_ERROR) { |
1037 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 1047 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
1038 | return 0; | 1048 | return 0; |
1039 | } | 1049 | } |
1040 | return 1; | 1050 | return 1; |
1041 | } | 1051 | } |
1042 | 1052 | ||
1043 | int IMAPwrapper::deleteMbox(const FolderP&folder) | 1053 | int IMAPwrapper::deleteMbox(const FolderP&folder) |
1044 | { | 1054 | { |
1045 | if (!folder) return 0; | 1055 | if (!folder) return 0; |
1046 | login(); | 1056 | login(); |
1047 | if (!m_imap) {return 0;} | 1057 | if (!m_imap) {return 0;} |
1048 | int res = mailimap_delete(m_imap,folder->getName()); | 1058 | int res = mailimap_delete(m_imap,folder->getName()); |
1049 | if (res != MAILIMAP_NO_ERROR) { | 1059 | if (res != MAILIMAP_NO_ERROR) { |
1050 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 1060 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
1051 | return 0; | 1061 | return 0; |
1052 | } | 1062 | } |
1053 | return 1; | 1063 | return 1; |
1054 | } | 1064 | } |
1055 | 1065 | ||
1056 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 1066 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
1057 | { | 1067 | { |
1058 | mailimap_status_att_list * att_list =0; | 1068 | mailimap_status_att_list * att_list =0; |
@@ -1069,120 +1079,120 @@ void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | |||
1069 | att_list = mailimap_status_att_list_new_empty(); | 1079 | att_list = mailimap_status_att_list_new_empty(); |
1070 | if (!att_list) return; | 1080 | if (!att_list) return; |
1071 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); | 1081 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); |
1072 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); | 1082 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); |
1073 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | 1083 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); |
1074 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | 1084 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); |
1075 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | 1085 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { |
1076 | for (cur = clist_begin(status->st_info_list); | 1086 | for (cur = clist_begin(status->st_info_list); |
1077 | cur != NULL ; cur = clist_next(cur)) { | 1087 | cur != NULL ; cur = clist_next(cur)) { |
1078 | mailimap_status_info * status_info; | 1088 | mailimap_status_info * status_info; |
1079 | status_info = (mailimap_status_info *)clist_content(cur); | 1089 | status_info = (mailimap_status_info *)clist_content(cur); |
1080 | switch (status_info->st_att) { | 1090 | switch (status_info->st_att) { |
1081 | case MAILIMAP_STATUS_ATT_MESSAGES: | 1091 | case MAILIMAP_STATUS_ATT_MESSAGES: |
1082 | target_stat.message_count = status_info->st_value; | 1092 | target_stat.message_count = status_info->st_value; |
1083 | break; | 1093 | break; |
1084 | case MAILIMAP_STATUS_ATT_RECENT: | 1094 | case MAILIMAP_STATUS_ATT_RECENT: |
1085 | target_stat.message_recent = status_info->st_value; | 1095 | target_stat.message_recent = status_info->st_value; |
1086 | break; | 1096 | break; |
1087 | case MAILIMAP_STATUS_ATT_UNSEEN: | 1097 | case MAILIMAP_STATUS_ATT_UNSEEN: |
1088 | target_stat.message_unseen = status_info->st_value; | 1098 | target_stat.message_unseen = status_info->st_value; |
1089 | break; | 1099 | break; |
1090 | } | 1100 | } |
1091 | } | 1101 | } |
1092 | } else { | 1102 | } else { |
1093 | odebug << "Error retrieving status" << oendl; | 1103 | odebug << "Error retrieving status" << oendl; |
1094 | } | 1104 | } |
1095 | if (status) mailimap_mailbox_data_status_free(status); | 1105 | if (status) mailimap_mailbox_data_status_free(status); |
1096 | if (att_list) mailimap_status_att_list_free(att_list); | 1106 | if (att_list) mailimap_status_att_list_free(att_list); |
1097 | } | 1107 | } |
1098 | 1108 | ||
1099 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 1109 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
1100 | { | 1110 | { |
1101 | login(); | 1111 | login(); |
1102 | if (!m_imap) return; | 1112 | if (!m_imap) return; |
1103 | if (!msg) return; | 1113 | if (!msg) return; |
1104 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1114 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1105 | if (r != MAILIMAP_NO_ERROR) { | 1115 | if (r != MAILIMAP_NO_ERROR) { |
1106 | Global::statusMessage("Error storing mail!"); | 1116 | Global::statusMessage("Error storing mail!"); |
1107 | } | 1117 | } |
1108 | } | 1118 | } |
1109 | 1119 | ||
1110 | MAILLIB::ATYPE IMAPwrapper::getType()const | 1120 | MAILLIB::ATYPE IMAPwrapper::getType()const |
1111 | { | 1121 | { |
1112 | return account->getType(); | 1122 | return account->getType(); |
1113 | } | 1123 | } |
1114 | 1124 | ||
1115 | const QString&IMAPwrapper::getName()const | 1125 | const QString&IMAPwrapper::getName()const |
1116 | { | 1126 | { |
1117 | odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | 1127 | odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; |
1118 | return account->getAccountName(); | 1128 | return account->getAccountName(); |
1119 | } | 1129 | } |
1120 | 1130 | ||
1121 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1131 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1122 | { | 1132 | { |
1123 | // dummy | 1133 | // dummy |
1124 | QValueList<int> path; | 1134 | QValueList<int> path; |
1125 | return fetchRawPart(mail,path,false); | 1135 | return fetchRawPart(mail,path,false); |
1126 | } | 1136 | } |
1127 | 1137 | ||
1128 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1138 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1129 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1139 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1130 | { | 1140 | { |
1131 | if (targetWrapper != this) { | 1141 | if (targetWrapper != this) { |
1132 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); | 1142 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); |
1133 | odebug << "Using generic" << oendl; | 1143 | odebug << "Using generic" << oendl; |
1134 | return; | 1144 | return; |
1135 | } | 1145 | } |
1136 | mailimap_set *set = 0; | 1146 | mailimap_set *set = 0; |
1137 | login(); | 1147 | login(); |
1138 | if (!m_imap) { | 1148 | if (!m_imap) { |
1139 | return; | 1149 | return; |
1140 | } | 1150 | } |
1141 | int err = selectMbox(fromFolder->getName()); | 1151 | int err = selectMbox(fromFolder->getName()); |
1142 | if ( err != MAILIMAP_NO_ERROR ) { | 1152 | if ( err != MAILIMAP_NO_ERROR ) { |
1143 | return; | 1153 | return; |
1144 | } | 1154 | } |
1145 | int last = m_imap->imap_selection_info->sel_exists; | 1155 | int last = m_imap->imap_selection_info->sel_exists; |
1146 | set = mailimap_set_new_interval( 1, last ); | 1156 | set = mailimap_set_new_interval( 1, last ); |
1147 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1157 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1148 | mailimap_set_free( set ); | 1158 | mailimap_set_free( set ); |
1149 | if ( err != MAILIMAP_NO_ERROR ) { | 1159 | if ( err != MAILIMAP_NO_ERROR ) { |
1150 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); | 1160 | QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); |
1151 | Global::statusMessage(error_msg); | 1161 | Global::statusMessage(error_msg); |
1152 | odebug << error_msg << oendl; | 1162 | odebug << error_msg << oendl; |
1153 | return; | 1163 | return; |
1154 | } | 1164 | } |
1155 | if (moveit) { | 1165 | if (moveit) { |
1156 | deleteAllMail(fromFolder); | 1166 | deleteAllMail(fromFolder); |
1157 | } | 1167 | } |
1158 | } | 1168 | } |
1159 | 1169 | ||
1160 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1170 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1161 | { | 1171 | { |
1162 | if (targetWrapper != this) { | 1172 | if (targetWrapper != this) { |
1163 | odebug << "Using generic" << oendl; | 1173 | odebug << "Using generic" << oendl; |
1164 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1174 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1165 | return; | 1175 | return; |
1166 | } | 1176 | } |
1167 | mailimap_set *set = 0; | 1177 | mailimap_set *set = 0; |
1168 | login(); | 1178 | login(); |
1169 | if (!m_imap) { | 1179 | if (!m_imap) { |
1170 | return; | 1180 | return; |
1171 | } | 1181 | } |
1172 | int err = selectMbox(mail->getMbox()); | 1182 | int err = selectMbox(mail->getMbox()); |
1173 | if ( err != MAILIMAP_NO_ERROR ) { | 1183 | if ( err != MAILIMAP_NO_ERROR ) { |
1174 | return; | 1184 | return; |
1175 | } | 1185 | } |
1176 | set = mailimap_set_new_single(mail->getNumber()); | 1186 | set = mailimap_set_new_single(mail->getNumber()); |
1177 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1187 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1178 | mailimap_set_free( set ); | 1188 | mailimap_set_free( set ); |
1179 | if ( err != MAILIMAP_NO_ERROR ) { | 1189 | if ( err != MAILIMAP_NO_ERROR ) { |
1180 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); | 1190 | QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); |
1181 | Global::statusMessage(error_msg); | 1191 | Global::statusMessage(error_msg); |
1182 | odebug << error_msg << oendl; | 1192 | odebug << error_msg << oendl; |
1183 | return; | 1193 | return; |
1184 | } | 1194 | } |
1185 | if (moveit) { | 1195 | if (moveit) { |
1186 | deleteMail(mail); | 1196 | deleteMail(mail); |
1187 | } | 1197 | } |
1188 | } | 1198 | } |