author | zautrix <zautrix> | 2005-02-12 22:58:10 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-12 22:58:10 (UTC) |
commit | 00ec9899a4727a4c9100d320935dde7da4803801 (patch) (unidiff) | |
tree | 22c5100623497bc135d13e65a1da993ed5999d4b /kmicromail | |
parent | d45d293d045a8d0f68e09ff9414e2dd6d18dd651 (diff) | |
download | kdepimpi-00ec9899a4727a4c9100d320935dde7da4803801.zip kdepimpi-00ec9899a4727a4c9100d320935dde7da4803801.tar.gz kdepimpi-00ec9899a4727a4c9100d320935dde7da4803801.tar.bz2 |
imap login fix
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 17 | ||||
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.h | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 93fb7de..09e52b8 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,1365 +1,1372 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <libetpan/libetpan.h> | 3 | #include <libetpan/libetpan.h> |
4 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
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 | #include <qprogressbar.h> | 9 | #include <qprogressbar.h> |
10 | #include "genericwrapper.h" | 10 | #include "genericwrapper.h" |
11 | #include <kglobal.h> | 11 | #include <kglobal.h> |
12 | 12 | ||
13 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
14 | int IMAPwrapper::mMax = 0; | 14 | int IMAPwrapper::mMax = 0; |
15 | int IMAPwrapper::mCurrent = 0; | 15 | int IMAPwrapper::mCurrent = 0; |
16 | 16 | ||
17 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 17 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
18 | : AbstractMail() | 18 | : AbstractMail() |
19 | { | 19 | { |
20 | account = a; | 20 | account = a; |
21 | m_imap = 0; | 21 | m_imap = 0; |
22 | m_Lastmbox = ""; | 22 | m_Lastmbox = ""; |
23 | mCurrent = 0; | 23 | mCurrent = 0; |
24 | mMax = 0; | 24 | mMax = 0; |
25 | } | 25 | } |
26 | 26 | ||
27 | IMAPwrapper::~IMAPwrapper() | 27 | IMAPwrapper::~IMAPwrapper() |
28 | { | 28 | { |
29 | logout(); | 29 | logout(); |
30 | } | 30 | } |
31 | 31 | ||
32 | /* to avoid to often select statements in loops etc. | 32 | /* to avoid to often select statements in loops etc. |
33 | we trust that we are logged in and connection is established!*/ | 33 | we trust that we are logged in and connection is established!*/ |
34 | int IMAPwrapper::selectMbox(const QString&mbox) | 34 | int IMAPwrapper::selectMbox(const QString&mbox) |
35 | { | 35 | { |
36 | if (mbox == m_Lastmbox) { | 36 | if (mbox == m_Lastmbox) { |
37 | return MAILIMAP_NO_ERROR; | 37 | return MAILIMAP_NO_ERROR; |
38 | } | 38 | } |
39 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 39 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
40 | if ( err != MAILIMAP_NO_ERROR ) { | 40 | if ( err != MAILIMAP_NO_ERROR ) { |
41 | m_Lastmbox = ""; | 41 | m_Lastmbox = ""; |
42 | return err; | 42 | return err; |
43 | } | 43 | } |
44 | m_Lastmbox = mbox; | 44 | m_Lastmbox = mbox; |
45 | return err; | 45 | return err; |
46 | } | 46 | } |
47 | 47 | ||
48 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 48 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
49 | { | 49 | { |
50 | qApp->processEvents(); | 50 | qApp->processEvents(); |
51 | return; | 51 | return; |
52 | //qDebug("imap progress %d of %d ",current,maximum ); | 52 | //qDebug("imap progress %d of %d ",current,maximum ); |
53 | //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); | 53 | //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); |
54 | //qApp->processEvents() | 54 | //qApp->processEvents() |
55 | static unsigned int last = 0; | 55 | static unsigned int last = 0; |
56 | if ( last != current ) | 56 | if ( last != current ) |
57 | IMAPwrapper::progress(); | 57 | IMAPwrapper::progress(); |
58 | last = current; | 58 | last = current; |
59 | } | 59 | } |
60 | void IMAPwrapper::progress( QString m ) | 60 | void IMAPwrapper::progress( QString m ) |
61 | { | 61 | { |
62 | static QString mProgrMess; | 62 | static QString mProgrMess; |
63 | if ( m != QString::null ) { | 63 | if ( m != QString::null ) { |
64 | mProgrMess = m; | 64 | mProgrMess = m; |
65 | mCurrent = 1; | 65 | mCurrent = 1; |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | QString mess; | 68 | QString mess; |
69 | //qDebug("progress "); | 69 | //qDebug("progress "); |
70 | if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); | 70 | if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); |
71 | else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); | 71 | else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); |
72 | Global::statusMessage(mess); | 72 | Global::statusMessage(mess); |
73 | //qDebug("Progress %s %s", mess.latin1(), m.latin1()); | 73 | //qDebug("Progress %s %s", mess.latin1(), m.latin1()); |
74 | qApp->processEvents(); | 74 | qApp->processEvents(); |
75 | } | 75 | } |
76 | bool IMAPwrapper::start_tls(bool force_tls) | 76 | bool IMAPwrapper::start_tls(bool force_tls) |
77 | { | 77 | { |
78 | int err; | 78 | int err; |
79 | bool try_tls = force_tls; | 79 | bool try_tls = force_tls; |
80 | mailimap_capability_data * cap_data = 0; | 80 | mailimap_capability_data * cap_data = 0; |
81 | 81 | ||
82 | err = mailimap_capability(m_imap,&cap_data); | 82 | err = mailimap_capability(m_imap,&cap_data); |
83 | if (err != MAILIMAP_NO_ERROR) { | 83 | if (err != MAILIMAP_NO_ERROR) { |
84 | Global::statusMessage("error getting capabilities!"); | 84 | Global::statusMessage("error getting capabilities!"); |
85 | return false; | 85 | return false; |
86 | } | 86 | } |
87 | clistiter * cur; | 87 | clistiter * cur; |
88 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 88 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
89 | struct mailimap_capability * cap; | 89 | struct mailimap_capability * cap; |
90 | cap = (struct mailimap_capability *)clist_content(cur); | 90 | cap = (struct mailimap_capability *)clist_content(cur); |
91 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 91 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
92 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 92 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
93 | try_tls = true; | 93 | try_tls = true; |
94 | break; | 94 | break; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } | 97 | } |
98 | if (cap_data) { | 98 | if (cap_data) { |
99 | mailimap_capability_data_free(cap_data); | 99 | mailimap_capability_data_free(cap_data); |
100 | } | 100 | } |
101 | if (try_tls) { | 101 | if (try_tls) { |
102 | err = mailimap_starttls(m_imap); | 102 | err = mailimap_starttls(m_imap); |
103 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 103 | if (err != MAILIMAP_NO_ERROR && force_tls) { |
104 | Global::statusMessage(i18n("Server has no TLS support!")); | 104 | Global::statusMessage(i18n("Server has no TLS support!")); |
105 | try_tls = false; | 105 | try_tls = false; |
106 | } else { | 106 | } else { |
107 | mailstream_low * low; | 107 | mailstream_low * low; |
108 | mailstream_low * new_low; | 108 | mailstream_low * new_low; |
109 | low = mailstream_get_low(m_imap->imap_stream); | 109 | low = mailstream_get_low(m_imap->imap_stream); |
110 | if (!low) { | 110 | if (!low) { |
111 | try_tls = false; | 111 | try_tls = false; |
112 | } else { | 112 | } else { |
113 | int fd = mailstream_low_get_fd(low); | 113 | int fd = mailstream_low_get_fd(low); |
114 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 114 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
115 | mailstream_low_free(low); | 115 | mailstream_low_free(low); |
116 | mailstream_set_low(m_imap->imap_stream, new_low); | 116 | mailstream_set_low(m_imap->imap_stream, new_low); |
117 | } else { | 117 | } else { |
118 | try_tls = false; | 118 | try_tls = false; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
122 | } | 122 | } |
123 | return try_tls; | 123 | return try_tls; |
124 | } | 124 | } |
125 | 125 | ||
126 | void IMAPwrapper::login() | 126 | void IMAPwrapper::login(bool tryTLS) // = true) |
127 | { | 127 | { |
128 | QString server, user, pass; | 128 | QString server, user, pass; |
129 | uint16_t port; | 129 | uint16_t port; |
130 | int err = MAILIMAP_NO_ERROR; | 130 | int err = MAILIMAP_NO_ERROR; |
131 | 131 | ||
132 | if (account->getOffline()) return; | 132 | if (account->getOffline()) return; |
133 | /* we are connected this moment */ | 133 | /* we are connected this moment */ |
134 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 134 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
135 | if (m_imap) { | 135 | if (m_imap) { |
136 | err = mailimap_noop(m_imap); | 136 | err = mailimap_noop(m_imap); |
137 | if (err!=MAILIMAP_NO_ERROR) { | 137 | if (err!=MAILIMAP_NO_ERROR) { |
138 | logout(); | 138 | logout(); |
139 | } else { | 139 | } else { |
140 | mailstream_flush(m_imap->imap_stream); | 140 | mailstream_flush(m_imap->imap_stream); |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | server = account->getServer(); | 144 | server = account->getServer(); |
145 | port = account->getPort().toUInt(); | 145 | port = account->getPort().toUInt(); |
146 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 146 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
147 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 147 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
148 | login.show(); | 148 | login.show(); |
149 | if ( QDialog::Accepted == login.exec() ) { | 149 | if ( QDialog::Accepted == login.exec() ) { |
150 | // ok | 150 | // ok |
151 | user = login.getUser(); | 151 | user = login.getUser(); |
152 | pass = login.getPassword(); | 152 | pass = login.getPassword(); |
153 | } else { | 153 | } else { |
154 | // cancel | 154 | // cancel |
155 | return; | 155 | return; |
156 | } | 156 | } |
157 | } else { | 157 | } else { |
158 | user = account->getUser(); | 158 | user = account->getUser(); |
159 | pass = account->getPassword(); | 159 | pass = account->getPassword(); |
160 | } | 160 | } |
161 | 161 | ||
162 | m_imap = mailimap_new( 20, &imap_progress ); | 162 | m_imap = mailimap_new( 20, &imap_progress ); |
163 | 163 | ||
164 | /* connect */ | 164 | /* connect */ |
165 | bool ssl = false; | 165 | bool ssl = false; |
166 | bool try_tls = false; | 166 | bool try_tls = false; |
167 | bool force_tls = false; | 167 | bool force_tls = false; |
168 | 168 | ||
169 | if ( account->ConnectionType() == 2 ) { | 169 | if ( account->ConnectionType() == 2 ) { |
170 | ssl = true; | 170 | ssl = true; |
171 | } | 171 | } |
172 | if (account->ConnectionType()==1) { | 172 | if (account->ConnectionType()==1) { |
173 | force_tls = true; | 173 | force_tls = true; |
174 | } | 174 | } |
175 | 175 | ||
176 | if ( ssl ) { | 176 | if ( ssl ) { |
177 | qDebug("using ssl "); | 177 | qDebug("using ssl "); |
178 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); | 178 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
179 | qDebug("back "); | 179 | qDebug("back "); |
180 | } else { | 180 | } else { |
181 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); | 181 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
182 | } | 182 | } |
183 | 183 | ||
184 | if ( err != MAILIMAP_NO_ERROR && | 184 | if ( err != MAILIMAP_NO_ERROR && |
185 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 185 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
186 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 186 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
187 | QString failure = ""; | 187 | QString failure = ""; |
188 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 188 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
189 | failure="Connection refused"; | 189 | failure="Connection refused"; |
190 | } else { | 190 | } else { |
191 | failure="Unknown failure"; | 191 | failure="Unknown failure"; |
192 | } | 192 | } |
193 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); | 193 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); |
194 | mailimap_free( m_imap ); | 194 | mailimap_free( m_imap ); |
195 | m_imap = 0; | 195 | m_imap = 0; |
196 | return; | 196 | return; |
197 | } | 197 | } |
198 | 198 | if ( tryTLS ) { | |
199 | if (!ssl) { | 199 | if (!ssl) { |
200 | try_tls = start_tls(force_tls); | 200 | try_tls = start_tls(force_tls); |
201 | } | ||
201 | } | 202 | } |
202 | |||
203 | bool ok = true; | 203 | bool ok = true; |
204 | if (force_tls && !try_tls) { | 204 | if (force_tls && !try_tls) { |
205 | Global::statusMessage(i18n("Server has no TLS support!")); | 205 | Global::statusMessage(i18n("Server has no TLS support!")); |
206 | ok = false; | 206 | ok = false; |
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | /* login */ | 210 | /* login */ |
211 | 211 | ||
212 | if (ok) { | 212 | if (ok) { |
213 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); | 213 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
214 | if ( err != MAILIMAP_NO_ERROR ) { | 214 | if ( err != MAILIMAP_NO_ERROR ) { |
215 | if ( tryTLS && !force_tls && !try_tls ) { | ||
216 | err = mailimap_close( m_imap ); | ||
217 | mailimap_free( m_imap ); | ||
218 | m_imap = 0; | ||
219 | login( false ); | ||
220 | return; | ||
221 | } | ||
215 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); | 222 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); |
216 | ok = false; | 223 | ok = false; |
217 | } | 224 | } |
218 | } | 225 | } |
219 | if (!ok) { | 226 | if (!ok) { |
220 | err = mailimap_close( m_imap ); | 227 | err = mailimap_close( m_imap ); |
221 | mailimap_free( m_imap ); | 228 | mailimap_free( m_imap ); |
222 | m_imap = 0; | 229 | m_imap = 0; |
223 | } | 230 | } |
224 | } | 231 | } |
225 | 232 | ||
226 | void IMAPwrapper::logout() | 233 | void IMAPwrapper::logout() |
227 | { | 234 | { |
228 | int err = MAILIMAP_NO_ERROR; | 235 | int err = MAILIMAP_NO_ERROR; |
229 | if (!m_imap) return; | 236 | if (!m_imap) return; |
230 | err = mailimap_logout( m_imap ); | 237 | err = mailimap_logout( m_imap ); |
231 | err = mailimap_close( m_imap ); | 238 | err = mailimap_close( m_imap ); |
232 | mailimap_free( m_imap ); | 239 | mailimap_free( m_imap ); |
233 | m_imap = 0; | 240 | m_imap = 0; |
234 | m_Lastmbox = ""; | 241 | m_Lastmbox = ""; |
235 | } | 242 | } |
236 | 243 | ||
237 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 244 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
238 | { | 245 | { |
239 | 246 | ||
240 | int tryAgain = 1; | 247 | int tryAgain = 1; |
241 | while ( tryAgain >= 0 ) { | 248 | while ( tryAgain >= 0 ) { |
242 | int err = MAILIMAP_NO_ERROR; | 249 | int err = MAILIMAP_NO_ERROR; |
243 | clist *result = 0; | 250 | clist *result = 0; |
244 | clistcell *current; | 251 | clistcell *current; |
245 | mailimap_fetch_type *fetchType = 0; | 252 | mailimap_fetch_type *fetchType = 0; |
246 | mailimap_set *set = 0; | 253 | mailimap_set *set = 0; |
247 | 254 | ||
248 | login(); | 255 | login(); |
249 | if (!m_imap) { | 256 | if (!m_imap) { |
250 | return; | 257 | return; |
251 | } | 258 | } |
252 | /* select mailbox READONLY for operations */ | 259 | /* select mailbox READONLY for operations */ |
253 | err = selectMbox(mailbox); | 260 | err = selectMbox(mailbox); |
254 | if ( err != MAILIMAP_NO_ERROR ) { | 261 | if ( err != MAILIMAP_NO_ERROR ) { |
255 | return; | 262 | return; |
256 | } | 263 | } |
257 | 264 | ||
258 | int last = m_imap->imap_selection_info->sel_exists; | 265 | int last = m_imap->imap_selection_info->sel_exists; |
259 | 266 | ||
260 | if (last == 0) { | 267 | if (last == 0) { |
261 | Global::statusMessage(i18n("Mailbox has no mails")); | 268 | Global::statusMessage(i18n("Mailbox has no mails")); |
262 | return; | 269 | return; |
263 | } else { | 270 | } else { |
264 | } | 271 | } |
265 | progress( i18n("Fetch ")); | 272 | progress( i18n("Fetch ")); |
266 | mMax = last; | 273 | mMax = last; |
267 | //qDebug("last %d ", last); | 274 | //qDebug("last %d ", last); |
268 | Global::statusMessage(i18n("Fetching header list")); | 275 | Global::statusMessage(i18n("Fetching header list")); |
269 | qApp->processEvents(); | 276 | qApp->processEvents(); |
270 | /* the range has to start at 1!!! not with 0!!!! */ | 277 | /* the range has to start at 1!!! not with 0!!!! */ |
271 | //LR the access to web.de imap server is no working with value 1 | 278 | //LR the access to web.de imap server is no working with value 1 |
272 | //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); | 279 | //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); |
273 | set = mailimap_set_new_interval( tryAgain, last ); | 280 | set = mailimap_set_new_interval( tryAgain, last ); |
274 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 281 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
275 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 282 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
276 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 283 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
277 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 284 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
278 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 285 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
279 | 286 | ||
280 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 287 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
281 | mailimap_set_free( set ); | 288 | mailimap_set_free( set ); |
282 | mailimap_fetch_type_free( fetchType ); | 289 | mailimap_fetch_type_free( fetchType ); |
283 | 290 | ||
284 | QString date,subject,from; | 291 | QString date,subject,from; |
285 | 292 | ||
286 | if ( err == MAILIMAP_NO_ERROR ) { | 293 | if ( err == MAILIMAP_NO_ERROR ) { |
287 | tryAgain = -1; | 294 | tryAgain = -1; |
288 | mailimap_msg_att * msg_att; | 295 | mailimap_msg_att * msg_att; |
289 | int i = 0; | 296 | int i = 0; |
290 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 297 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
291 | ++i; | 298 | ++i; |
292 | //qDebug("iii %d ",i); | 299 | //qDebug("iii %d ",i); |
293 | msg_att = (mailimap_msg_att*)current->data; | 300 | msg_att = (mailimap_msg_att*)current->data; |
294 | RecMail*m = parse_list_result(msg_att); | 301 | RecMail*m = parse_list_result(msg_att); |
295 | if (m) { | 302 | if (m) { |
296 | if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { | 303 | if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { |
297 | m->setNumber(i); | 304 | m->setNumber(i); |
298 | m->setMbox(mailbox); | 305 | m->setMbox(mailbox); |
299 | m->setWrapper(this); | 306 | m->setWrapper(this); |
300 | target.append(m); | 307 | target.append(m); |
301 | } | 308 | } |
302 | } | 309 | } |
303 | } | 310 | } |
304 | Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); | 311 | Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); |
305 | } else { | 312 | } else { |
306 | --tryAgain; | 313 | --tryAgain; |
307 | --tryAgain;//disabled tryagain by adding this line | 314 | --tryAgain;//disabled tryagain by adding this line |
308 | if ( tryAgain < 0 ) | 315 | if ( tryAgain < 0 ) |
309 | Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); | 316 | Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); |
310 | else | 317 | else |
311 | qDebug("try again... "); | 318 | qDebug("try again... "); |
312 | } | 319 | } |
313 | 320 | ||
314 | if (result) mailimap_fetch_list_free(result); | 321 | if (result) mailimap_fetch_list_free(result); |
315 | } | 322 | } |
316 | } | 323 | } |
317 | 324 | ||
318 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 325 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
319 | { | 326 | { |
320 | const char *path, *mask; | 327 | const char *path, *mask; |
321 | int err = MAILIMAP_NO_ERROR; | 328 | int err = MAILIMAP_NO_ERROR; |
322 | clist *result = 0; | 329 | clist *result = 0; |
323 | clistcell *current = 0; | 330 | clistcell *current = 0; |
324 | clistcell*cur_flag = 0; | 331 | clistcell*cur_flag = 0; |
325 | mailimap_mbx_list_flags*bflags = 0; | 332 | mailimap_mbx_list_flags*bflags = 0; |
326 | 333 | ||
327 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 334 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
328 | login(); | 335 | login(); |
329 | if (!m_imap) { | 336 | if (!m_imap) { |
330 | return folders; | 337 | return folders; |
331 | } | 338 | } |
332 | 339 | ||
333 | /* | 340 | /* |
334 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 341 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
335 | * We must not forget to filter them out in next loop! | 342 | * We must not forget to filter them out in next loop! |
336 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 343 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
337 | */ | 344 | */ |
338 | Global::statusMessage(i18n("Fetching folder list")); | 345 | Global::statusMessage(i18n("Fetching folder list")); |
339 | qApp->processEvents(); | 346 | qApp->processEvents(); |
340 | QString temp; | 347 | QString temp; |
341 | mask = "INBOX" ; | 348 | mask = "INBOX" ; |
342 | mailimap_mailbox_list *list; | 349 | mailimap_mailbox_list *list; |
343 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 350 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
344 | QString del; | 351 | QString del; |
345 | bool selectable = true; | 352 | bool selectable = true; |
346 | bool no_inferiors = false; | 353 | bool no_inferiors = false; |
347 | if ( err == MAILIMAP_NO_ERROR ) { | 354 | if ( err == MAILIMAP_NO_ERROR ) { |
348 | current = result->first; | 355 | current = result->first; |
349 | for ( int i = result->count; i > 0; i-- ) { | 356 | for ( int i = result->count; i > 0; i-- ) { |
350 | list = (mailimap_mailbox_list *) current->data; | 357 | list = (mailimap_mailbox_list *) current->data; |
351 | // it is better use the deep copy mechanism of qt itself | 358 | // it is better use the deep copy mechanism of qt itself |
352 | // instead of using strdup! | 359 | // instead of using strdup! |
353 | temp = list->mb_name; | 360 | temp = list->mb_name; |
354 | del = list->mb_delimiter; | 361 | del = list->mb_delimiter; |
355 | current = current->next; | 362 | current = current->next; |
356 | if ( (bflags = list->mb_flag) ) { | 363 | if ( (bflags = list->mb_flag) ) { |
357 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 364 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
358 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 365 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
359 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 366 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
360 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 367 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
361 | no_inferiors = true; | 368 | no_inferiors = true; |
362 | } | 369 | } |
363 | } | 370 | } |
364 | } | 371 | } |
365 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 372 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
366 | } | 373 | } |
367 | } else { | 374 | } else { |
368 | qDebug("error fetching folders: "); | 375 | qDebug("error fetching folders: "); |
369 | 376 | ||
370 | } | 377 | } |
371 | mailimap_list_result_free( result ); | 378 | mailimap_list_result_free( result ); |
372 | 379 | ||
373 | /* | 380 | /* |
374 | * second stage - get the other then inbox folders | 381 | * second stage - get the other then inbox folders |
375 | */ | 382 | */ |
376 | mask = "*" ; | 383 | mask = "*" ; |
377 | path = account->getPrefix().latin1(); | 384 | path = account->getPrefix().latin1(); |
378 | if (!path) path = ""; | 385 | if (!path) path = ""; |
379 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 386 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
380 | if ( err == MAILIMAP_NO_ERROR ) { | 387 | if ( err == MAILIMAP_NO_ERROR ) { |
381 | current = result->first; | 388 | current = result->first; |
382 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 389 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
383 | no_inferiors = false; | 390 | no_inferiors = false; |
384 | list = (mailimap_mailbox_list *) current->data; | 391 | list = (mailimap_mailbox_list *) current->data; |
385 | // it is better use the deep copy mechanism of qt itself | 392 | // it is better use the deep copy mechanism of qt itself |
386 | // instead of using strdup! | 393 | // instead of using strdup! |
387 | temp = list->mb_name; | 394 | temp = list->mb_name; |
388 | if (temp.lower()=="inbox") | 395 | if (temp.lower()=="inbox") |
389 | continue; | 396 | continue; |
390 | if (temp.lower()==account->getPrefix().lower()) | 397 | if (temp.lower()==account->getPrefix().lower()) |
391 | continue; | 398 | continue; |
392 | if ( (bflags = list->mb_flag) ) { | 399 | if ( (bflags = list->mb_flag) ) { |
393 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 400 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
394 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 401 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
395 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 402 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
396 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 403 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
397 | no_inferiors = true; | 404 | no_inferiors = true; |
398 | } | 405 | } |
399 | } | 406 | } |
400 | } | 407 | } |
401 | del = list->mb_delimiter; | 408 | del = list->mb_delimiter; |
402 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 409 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
403 | } | 410 | } |
404 | } else { | 411 | } else { |
405 | qDebug("error fetching folders "); | 412 | qDebug("error fetching folders "); |
406 | 413 | ||
407 | } | 414 | } |
408 | if (result) mailimap_list_result_free( result ); | 415 | if (result) mailimap_list_result_free( result ); |
409 | return folders; | 416 | return folders; |
410 | } | 417 | } |
411 | 418 | ||
412 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 419 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
413 | { | 420 | { |
414 | RecMail * m = 0; | 421 | RecMail * m = 0; |
415 | mailimap_msg_att_item *item=0; | 422 | mailimap_msg_att_item *item=0; |
416 | clistcell *current,*c,*cf; | 423 | clistcell *current,*c,*cf; |
417 | mailimap_msg_att_dynamic*flist; | 424 | mailimap_msg_att_dynamic*flist; |
418 | mailimap_flag_fetch*cflag; | 425 | mailimap_flag_fetch*cflag; |
419 | int size = 0; | 426 | int size = 0; |
420 | QBitArray mFlags(7); | 427 | QBitArray mFlags(7); |
421 | QStringList addresslist; | 428 | QStringList addresslist; |
422 | 429 | ||
423 | if (!m_att) { | 430 | if (!m_att) { |
424 | return m; | 431 | return m; |
425 | } | 432 | } |
426 | m = new RecMail(); | 433 | m = new RecMail(); |
427 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 434 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
428 | current = c; | 435 | current = c; |
429 | size = 0; | 436 | size = 0; |
430 | item = (mailimap_msg_att_item*)current->data; | 437 | item = (mailimap_msg_att_item*)current->data; |
431 | if ( !item ) | 438 | if ( !item ) |
432 | continue; | 439 | continue; |
433 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 440 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
434 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 441 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
435 | if (!flist || !flist->att_list) { | 442 | if (!flist || !flist->att_list) { |
436 | continue; | 443 | continue; |
437 | } | 444 | } |
438 | cf = flist->att_list->first; | 445 | cf = flist->att_list->first; |
439 | if( cf ) { | 446 | if( cf ) { |
440 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 447 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
441 | cflag = (mailimap_flag_fetch*)cf->data; | 448 | cflag = (mailimap_flag_fetch*)cf->data; |
442 | if( ! cflag ) | 449 | if( ! cflag ) |
443 | qDebug("imap:NO cflag "); | 450 | qDebug("imap:NO cflag "); |
444 | else { | 451 | else { |
445 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 452 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
446 | switch (cflag->fl_flag->fl_type) { | 453 | switch (cflag->fl_flag->fl_type) { |
447 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 454 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
448 | mFlags.setBit(FLAG_ANSWERED); | 455 | mFlags.setBit(FLAG_ANSWERED); |
449 | break; | 456 | break; |
450 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 457 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
451 | mFlags.setBit(FLAG_FLAGGED); | 458 | mFlags.setBit(FLAG_FLAGGED); |
452 | break; | 459 | break; |
453 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 460 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
454 | mFlags.setBit(FLAG_DELETED); | 461 | mFlags.setBit(FLAG_DELETED); |
455 | break; | 462 | break; |
456 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 463 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
457 | mFlags.setBit(FLAG_SEEN); | 464 | mFlags.setBit(FLAG_SEEN); |
458 | break; | 465 | break; |
459 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 466 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
460 | mFlags.setBit(FLAG_DRAFT); | 467 | mFlags.setBit(FLAG_DRAFT); |
461 | break; | 468 | break; |
462 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 469 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
463 | break; | 470 | break; |
464 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 471 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
465 | break; | 472 | break; |
466 | default: | 473 | default: |
467 | break; | 474 | break; |
468 | } | 475 | } |
469 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 476 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
470 | mFlags.setBit(FLAG_RECENT); | 477 | mFlags.setBit(FLAG_RECENT); |
471 | } | 478 | } |
472 | } | 479 | } |
473 | } | 480 | } |
474 | } | 481 | } |
475 | //qDebug(" continue"); | 482 | //qDebug(" continue"); |
476 | continue; | 483 | continue; |
477 | } | 484 | } |
478 | if ( item->att_data.att_static == NULL ) | 485 | if ( item->att_data.att_static == NULL ) |
479 | continue; | 486 | continue; |
480 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 487 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
481 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 488 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
482 | if ( head == NULL ) | 489 | if ( head == NULL ) |
483 | continue; | 490 | continue; |
484 | if ( head->env_date != NULL ) { | 491 | if ( head->env_date != NULL ) { |
485 | m->setDate(head->env_date); | 492 | m->setDate(head->env_date); |
486 | //struct mailimf_date_time result; | 493 | //struct mailimf_date_time result; |
487 | struct mailimf_date_time* date;// = &result; | 494 | struct mailimf_date_time* date;// = &result; |
488 | struct mailimf_date_time **re = &date; | 495 | struct mailimf_date_time **re = &date; |
489 | size_t length = m->getDate().length(); | 496 | size_t length = m->getDate().length(); |
490 | size_t index = 0; | 497 | size_t index = 0; |
491 | if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { | 498 | if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { |
492 | //qDebug("parseDateTime "); | 499 | //qDebug("parseDateTime "); |
493 | QDateTime dt = Genericwrapper::parseDateTime( date ); | 500 | QDateTime dt = Genericwrapper::parseDateTime( date ); |
494 | QString ret; | 501 | QString ret; |
495 | if ( dt.date() == QDate::currentDate () ) | 502 | if ( dt.date() == QDate::currentDate () ) |
496 | ret = KGlobal::locale()->formatTime( dt.time(),true); | 503 | ret = KGlobal::locale()->formatTime( dt.time(),true); |
497 | else { | 504 | else { |
498 | ret = KGlobal::locale()->formatDateTime( dt,true,true); | 505 | ret = KGlobal::locale()->formatDateTime( dt,true,true); |
499 | } | 506 | } |
500 | m->setDate( ret ); | 507 | m->setDate( ret ); |
501 | char tmp[20]; | 508 | char tmp[20]; |
502 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", | 509 | snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", |
503 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); | 510 | dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); |
504 | //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); | 511 | //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); |
505 | m->setIsoDate( QString( tmp ) ); | 512 | m->setIsoDate( QString( tmp ) ); |
506 | mailimf_date_time_free ( date ); | 513 | mailimf_date_time_free ( date ); |
507 | } else { | 514 | } else { |
508 | m->setIsoDate(head->env_date); | 515 | m->setIsoDate(head->env_date); |
509 | } | 516 | } |
510 | } | 517 | } |
511 | if ( head->env_subject != NULL ) | 518 | if ( head->env_subject != NULL ) |
512 | m->setSubject(convert_String((const char*)head->env_subject)); | 519 | m->setSubject(convert_String((const char*)head->env_subject)); |
513 | //m->setSubject(head->env_subject); | 520 | //m->setSubject(head->env_subject); |
514 | if (head->env_from!=NULL) { | 521 | if (head->env_from!=NULL) { |
515 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 522 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
516 | if (addresslist.count()) { | 523 | if (addresslist.count()) { |
517 | m->setFrom(addresslist.first()); | 524 | m->setFrom(addresslist.first()); |
518 | } | 525 | } |
519 | } | 526 | } |
520 | if (head->env_to!=NULL) { | 527 | if (head->env_to!=NULL) { |
521 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 528 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
522 | m->setTo(addresslist); | 529 | m->setTo(addresslist); |
523 | } | 530 | } |
524 | if (head->env_cc!=NULL) { | 531 | if (head->env_cc!=NULL) { |
525 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 532 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
526 | m->setCC(addresslist); | 533 | m->setCC(addresslist); |
527 | } | 534 | } |
528 | if (head->env_bcc!=NULL) { | 535 | if (head->env_bcc!=NULL) { |
529 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 536 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
530 | m->setBcc(addresslist); | 537 | m->setBcc(addresslist); |
531 | } | 538 | } |
532 | /* reply to address, eg. email. */ | 539 | /* reply to address, eg. email. */ |
533 | if (head->env_reply_to!=NULL) { | 540 | if (head->env_reply_to!=NULL) { |
534 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 541 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
535 | if (addresslist.count()) { | 542 | if (addresslist.count()) { |
536 | m->setReplyto(addresslist.first()); | 543 | m->setReplyto(addresslist.first()); |
537 | } | 544 | } |
538 | } | 545 | } |
539 | if (head->env_in_reply_to!=NULL) { | 546 | if (head->env_in_reply_to!=NULL) { |
540 | QString h(head->env_in_reply_to); | 547 | QString h(head->env_in_reply_to); |
541 | while (h.length()>0 && h[0]=='<') { | 548 | while (h.length()>0 && h[0]=='<') { |
542 | h.remove(0,1); | 549 | h.remove(0,1); |
543 | } | 550 | } |
544 | while (h.length()>0 && h[h.length()-1]=='>') { | 551 | while (h.length()>0 && h[h.length()-1]=='>') { |
545 | h.remove(h.length()-1,1); | 552 | h.remove(h.length()-1,1); |
546 | } | 553 | } |
547 | if (h.length()>0) { | 554 | if (h.length()>0) { |
548 | m->setInreply(QStringList(h)); | 555 | m->setInreply(QStringList(h)); |
549 | } | 556 | } |
550 | } | 557 | } |
551 | if (head->env_message_id != NULL) { | 558 | if (head->env_message_id != NULL) { |
552 | m->setMsgid(QString(head->env_message_id)); | 559 | m->setMsgid(QString(head->env_message_id)); |
553 | } | 560 | } |
554 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 561 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
555 | #if 0 | 562 | #if 0 |
556 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 563 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
557 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 564 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
558 | qDebug("time %s ",da.toString().latin1() ); | 565 | qDebug("time %s ",da.toString().latin1() ); |
559 | #endif | 566 | #endif |
560 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 567 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
561 | size = item->att_data.att_static->att_data.att_rfc822_size; | 568 | size = item->att_data.att_static->att_data.att_rfc822_size; |
562 | } | 569 | } |
563 | } | 570 | } |
564 | /* msg is already deleted */ | 571 | /* msg is already deleted */ |
565 | if (mFlags.testBit(FLAG_DELETED) && m) { | 572 | if (mFlags.testBit(FLAG_DELETED) && m) { |
566 | delete m; | 573 | delete m; |
567 | m = 0; | 574 | m = 0; |
568 | } | 575 | } |
569 | if (m) { | 576 | if (m) { |
570 | m->setFlags(mFlags); | 577 | m->setFlags(mFlags); |
571 | m->setMsgsize(size); | 578 | m->setMsgsize(size); |
572 | } | 579 | } |
573 | return m; | 580 | return m; |
574 | } | 581 | } |
575 | 582 | ||
576 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 583 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
577 | { | 584 | { |
578 | RecBodyP body = new RecBody(); | 585 | RecBodyP body = new RecBody(); |
579 | const char *mb; | 586 | const char *mb; |
580 | int err = MAILIMAP_NO_ERROR; | 587 | int err = MAILIMAP_NO_ERROR; |
581 | clist *result = 0; | 588 | clist *result = 0; |
582 | clistcell *current; | 589 | clistcell *current; |
583 | mailimap_fetch_att *fetchAtt = 0; | 590 | mailimap_fetch_att *fetchAtt = 0; |
584 | mailimap_fetch_type *fetchType = 0; | 591 | mailimap_fetch_type *fetchType = 0; |
585 | mailimap_set *set = 0; | 592 | mailimap_set *set = 0; |
586 | mailimap_body*body_desc = 0; | 593 | mailimap_body*body_desc = 0; |
587 | 594 | ||
588 | mb = mail->getMbox().latin1(); | 595 | mb = mail->getMbox().latin1(); |
589 | 596 | ||
590 | login(); | 597 | login(); |
591 | if (!m_imap) { | 598 | if (!m_imap) { |
592 | return body; | 599 | return body; |
593 | } | 600 | } |
594 | err = selectMbox(mail->getMbox()); | 601 | err = selectMbox(mail->getMbox()); |
595 | if ( err != MAILIMAP_NO_ERROR ) { | 602 | if ( err != MAILIMAP_NO_ERROR ) { |
596 | return body; | 603 | return body; |
597 | } | 604 | } |
598 | 605 | ||
599 | /* the range has to start at 1!!! not with 0!!!! */ | 606 | /* the range has to start at 1!!! not with 0!!!! */ |
600 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 607 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
601 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 608 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
602 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 609 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
603 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 610 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
604 | mailimap_set_free( set ); | 611 | mailimap_set_free( set ); |
605 | mailimap_fetch_type_free( fetchType ); | 612 | mailimap_fetch_type_free( fetchType ); |
606 | 613 | ||
607 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 614 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
608 | mailimap_msg_att * msg_att; | 615 | mailimap_msg_att * msg_att; |
609 | msg_att = (mailimap_msg_att*)current->data; | 616 | msg_att = (mailimap_msg_att*)current->data; |
610 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 617 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
611 | QValueList<int> path; | 618 | QValueList<int> path; |
612 | body_desc = item->att_data.att_static->att_data.att_body; | 619 | body_desc = item->att_data.att_static->att_data.att_body; |
613 | traverseBody(mail,body_desc,body,0,path); | 620 | traverseBody(mail,body_desc,body,0,path); |
614 | } else { | 621 | } else { |
615 | qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response ); | 622 | qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response ); |
616 | } | 623 | } |
617 | if (result) mailimap_fetch_list_free(result); | 624 | if (result) mailimap_fetch_list_free(result); |
618 | return body; | 625 | return body; |
619 | } | 626 | } |
620 | 627 | ||
621 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 628 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
622 | { | 629 | { |
623 | QStringList l; | 630 | QStringList l; |
624 | QString from; | 631 | QString from; |
625 | bool named_from; | 632 | bool named_from; |
626 | clistcell *current = NULL; | 633 | clistcell *current = NULL; |
627 | mailimap_address * current_address=NULL; | 634 | mailimap_address * current_address=NULL; |
628 | if (!list) { | 635 | if (!list) { |
629 | return l; | 636 | return l; |
630 | } | 637 | } |
631 | unsigned int count = 0; | 638 | unsigned int count = 0; |
632 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 639 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
633 | from = ""; | 640 | from = ""; |
634 | named_from = false; | 641 | named_from = false; |
635 | current_address=(mailimap_address*)current->data; | 642 | current_address=(mailimap_address*)current->data; |
636 | if (current_address->ad_personal_name){ | 643 | if (current_address->ad_personal_name){ |
637 | from+=convert_String((const char*)current_address->ad_personal_name); | 644 | from+=convert_String((const char*)current_address->ad_personal_name); |
638 | from+=" "; | 645 | from+=" "; |
639 | named_from = true; | 646 | named_from = true; |
640 | } | 647 | } |
641 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 648 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
642 | from+="<"; | 649 | from+="<"; |
643 | } | 650 | } |
644 | if (current_address->ad_mailbox_name) { | 651 | if (current_address->ad_mailbox_name) { |
645 | from+=QString(current_address->ad_mailbox_name); | 652 | from+=QString(current_address->ad_mailbox_name); |
646 | from+="@"; | 653 | from+="@"; |
647 | } | 654 | } |
648 | if (current_address->ad_host_name) { | 655 | if (current_address->ad_host_name) { |
649 | from+=QString(current_address->ad_host_name); | 656 | from+=QString(current_address->ad_host_name); |
650 | } | 657 | } |
651 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 658 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
652 | from+=">"; | 659 | from+=">"; |
653 | } | 660 | } |
654 | l.append(QString(from)); | 661 | l.append(QString(from)); |
655 | if (++count > 99) { | 662 | if (++count > 99) { |
656 | break; | 663 | break; |
657 | } | 664 | } |
658 | } | 665 | } |
659 | return l; | 666 | return l; |
660 | } | 667 | } |
661 | 668 | ||
662 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 669 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
663 | { | 670 | { |
664 | encodedString*res=new encodedString; | 671 | encodedString*res=new encodedString; |
665 | int err; | 672 | int err; |
666 | mailimap_fetch_type *fetchType; | 673 | mailimap_fetch_type *fetchType; |
667 | mailimap_set *set; | 674 | mailimap_set *set; |
668 | clistcell*current,*cur; | 675 | clistcell*current,*cur; |
669 | mailimap_section_part * section_part = 0; | 676 | mailimap_section_part * section_part = 0; |
670 | mailimap_section_spec * section_spec = 0; | 677 | mailimap_section_spec * section_spec = 0; |
671 | mailimap_section * section = 0; | 678 | mailimap_section * section = 0; |
672 | mailimap_fetch_att * fetch_att = 0; | 679 | mailimap_fetch_att * fetch_att = 0; |
673 | 680 | ||
674 | login(); | 681 | login(); |
675 | if (!m_imap) { | 682 | if (!m_imap) { |
676 | return res; | 683 | return res; |
677 | } | 684 | } |
678 | if (!internal_call) { | 685 | if (!internal_call) { |
679 | err = selectMbox(mail->getMbox()); | 686 | err = selectMbox(mail->getMbox()); |
680 | if ( err != MAILIMAP_NO_ERROR ) { | 687 | if ( err != MAILIMAP_NO_ERROR ) { |
681 | return res; | 688 | return res; |
682 | } | 689 | } |
683 | } | 690 | } |
684 | set = mailimap_set_new_single(mail->getNumber()); | 691 | set = mailimap_set_new_single(mail->getNumber()); |
685 | 692 | ||
686 | clist*id_list = 0; | 693 | clist*id_list = 0; |
687 | 694 | ||
688 | /* if path == empty then its a request for the whole rfc822 mail and generates | 695 | /* if path == empty then its a request for the whole rfc822 mail and generates |
689 | a "fetch <id> (body[])" statement on imap server */ | 696 | a "fetch <id> (body[])" statement on imap server */ |
690 | if (path.count()>0 ) { | 697 | if (path.count()>0 ) { |
691 | id_list = clist_new(); | 698 | id_list = clist_new(); |
692 | for (unsigned j=0; j < path.count();++j) { | 699 | for (unsigned j=0; j < path.count();++j) { |
693 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 700 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
694 | *p_id = path[j]; | 701 | *p_id = path[j]; |
695 | clist_append(id_list,p_id); | 702 | clist_append(id_list,p_id); |
696 | } | 703 | } |
697 | section_part = mailimap_section_part_new(id_list); | 704 | section_part = mailimap_section_part_new(id_list); |
698 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 705 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
699 | } | 706 | } |
700 | 707 | ||
701 | section = mailimap_section_new(section_spec); | 708 | section = mailimap_section_new(section_spec); |
702 | fetch_att = mailimap_fetch_att_new_body_section(section); | 709 | fetch_att = mailimap_fetch_att_new_body_section(section); |
703 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 710 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
704 | 711 | ||
705 | clist*result = 0; | 712 | clist*result = 0; |
706 | 713 | ||
707 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 714 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
708 | mailimap_set_free( set ); | 715 | mailimap_set_free( set ); |
709 | mailimap_fetch_type_free( fetchType ); | 716 | mailimap_fetch_type_free( fetchType ); |
710 | 717 | ||
711 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 718 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
712 | mailimap_msg_att * msg_att; | 719 | mailimap_msg_att * msg_att; |
713 | msg_att = (mailimap_msg_att*)current->data; | 720 | msg_att = (mailimap_msg_att*)current->data; |
714 | mailimap_msg_att_item*msg_att_item; | 721 | mailimap_msg_att_item*msg_att_item; |
715 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 722 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
716 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 723 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
717 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 724 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
718 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 725 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
719 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 726 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
720 | /* detach - we take over the content */ | 727 | /* detach - we take over the content */ |
721 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 728 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
722 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 729 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
723 | } | 730 | } |
724 | } | 731 | } |
725 | } | 732 | } |
726 | } else { | 733 | } else { |
727 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 734 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
728 | } | 735 | } |
729 | if (result) mailimap_fetch_list_free(result); | 736 | if (result) mailimap_fetch_list_free(result); |
730 | return res; | 737 | return res; |
731 | } | 738 | } |
732 | 739 | ||
733 | /* current_recursion is for recursive calls. | 740 | /* current_recursion is for recursive calls. |
734 | current_count means the position inside the internal loop! */ | 741 | current_count means the position inside the internal loop! */ |
735 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 742 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
736 | int current_recursion,QValueList<int>recList,int current_count) | 743 | int current_recursion,QValueList<int>recList,int current_count) |
737 | { | 744 | { |
738 | if (!body || current_recursion>=10) { | 745 | if (!body || current_recursion>=10) { |
739 | return; | 746 | return; |
740 | } | 747 | } |
741 | switch (body->bd_type) { | 748 | switch (body->bd_type) { |
742 | case MAILIMAP_BODY_1PART: | 749 | case MAILIMAP_BODY_1PART: |
743 | { | 750 | { |
744 | QValueList<int>countlist = recList; | 751 | QValueList<int>countlist = recList; |
745 | countlist.append(current_count); | 752 | countlist.append(current_count); |
746 | RecPartP currentPart = new RecPart(); | 753 | RecPartP currentPart = new RecPart(); |
747 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 754 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
748 | QString id(""); | 755 | QString id(""); |
749 | currentPart->setPositionlist(countlist); | 756 | currentPart->setPositionlist(countlist); |
750 | for (unsigned int j = 0; j < countlist.count();++j) { | 757 | for (unsigned int j = 0; j < countlist.count();++j) { |
751 | id+=(j>0?" ":""); | 758 | id+=(j>0?" ":""); |
752 | id+=QString("%1").arg(countlist[j]); | 759 | id+=QString("%1").arg(countlist[j]); |
753 | } | 760 | } |
754 | //odebug << "ID = " << id.latin1() << "" << oendl; | 761 | //odebug << "ID = " << id.latin1() << "" << oendl; |
755 | currentPart->setIdentifier(id); | 762 | currentPart->setIdentifier(id); |
756 | fillSinglePart(currentPart,part1); | 763 | fillSinglePart(currentPart,part1); |
757 | /* important: Check for is NULL 'cause a body can be empty! | 764 | /* important: Check for is NULL 'cause a body can be empty! |
758 | And we put it only into the mail if it is the FIRST part */ | 765 | And we put it only into the mail if it is the FIRST part */ |
759 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 766 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
760 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 767 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
761 | 768 | ||
762 | size_t index = 0; | 769 | size_t index = 0; |
763 | char*res = 0; | 770 | char*res = 0; |
764 | int err = MAILIMF_NO_ERROR; | 771 | int err = MAILIMF_NO_ERROR; |
765 | 772 | ||
766 | QString charset = currentPart->searchParamter( "charset"); | 773 | QString charset = currentPart->searchParamter( "charset"); |
767 | qDebug("CHARSET %s ",charset.latin1() ); | 774 | qDebug("CHARSET %s ",charset.latin1() ); |
768 | if ( false ) { | 775 | if ( false ) { |
769 | //if ( !charset.isEmpty() ) { | 776 | //if ( !charset.isEmpty() ) { |
770 | target_body->setCharset( charset ); | 777 | target_body->setCharset( charset ); |
771 | //err = mailmime_encoded_phrase_parse("iso-8859-1", | 778 | //err = mailmime_encoded_phrase_parse("iso-8859-1", |
772 | // text, strlen(text),&index, "iso-8859-1",&res); | 779 | // text, strlen(text),&index, "iso-8859-1",&res); |
773 | err = mailmime_encoded_phrase_parse(charset.latin1(), | 780 | err = mailmime_encoded_phrase_parse(charset.latin1(), |
774 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); | 781 | body_text.latin1(), body_text.length(),&index, "utf-8",&res); |
775 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { | 782 | if (err == MAILIMF_NO_ERROR && res && strlen(res)) { |
776 | //qDebug("res %d %s ", index, res); | 783 | //qDebug("res %d %s ", index, res); |
777 | body_text = QString::fromUtf8(res); | 784 | body_text = QString::fromUtf8(res); |
778 | } | 785 | } |
779 | if (res) free(res); | 786 | if (res) free(res); |
780 | } | 787 | } |
781 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); | 788 | //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); |
782 | target_body->setDescription(currentPart); | 789 | target_body->setDescription(currentPart); |
783 | target_body->setBodytext(body_text); | 790 | target_body->setBodytext(body_text); |
784 | if (countlist.count()>1) { | 791 | if (countlist.count()>1) { |
785 | target_body->addPart(currentPart); | 792 | target_body->addPart(currentPart); |
786 | } | 793 | } |
787 | } else { | 794 | } else { |
788 | target_body->addPart(currentPart); | 795 | target_body->addPart(currentPart); |
789 | } | 796 | } |
790 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 797 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
791 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 798 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
792 | } | 799 | } |
793 | } | 800 | } |
794 | break; | 801 | break; |
795 | case MAILIMAP_BODY_MPART: | 802 | case MAILIMAP_BODY_MPART: |
796 | { | 803 | { |
797 | QValueList<int>countlist = recList; | 804 | QValueList<int>countlist = recList; |
798 | clistcell*current=0; | 805 | clistcell*current=0; |
799 | mailimap_body*current_body=0; | 806 | mailimap_body*current_body=0; |
800 | unsigned int ccount = 1; | 807 | unsigned int ccount = 1; |
801 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 808 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
802 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 809 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
803 | current_body = (mailimap_body*)current->data; | 810 | current_body = (mailimap_body*)current->data; |
804 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 811 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
805 | RecPartP targetPart = new RecPart(); | 812 | RecPartP targetPart = new RecPart(); |
806 | targetPart->setType("multipart"); | 813 | targetPart->setType("multipart"); |
807 | fillMultiPart(targetPart,mailDescription); | 814 | fillMultiPart(targetPart,mailDescription); |
808 | countlist.append(current_count); | 815 | countlist.append(current_count); |
809 | targetPart->setPositionlist(countlist); | 816 | targetPart->setPositionlist(countlist); |
810 | target_body->addPart(targetPart); | 817 | target_body->addPart(targetPart); |
811 | QString id(""); | 818 | QString id(""); |
812 | for (unsigned int j = 0; j < countlist.count();++j) { | 819 | for (unsigned int j = 0; j < countlist.count();++j) { |
813 | id+=(j>0?" ":""); | 820 | id+=(j>0?" ":""); |
814 | id+=QString("%1").arg(countlist[j]); | 821 | id+=QString("%1").arg(countlist[j]); |
815 | } | 822 | } |
816 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 823 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
817 | } | 824 | } |
818 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 825 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
819 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 826 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
820 | countlist = recList; | 827 | countlist = recList; |
821 | } | 828 | } |
822 | ++ccount; | 829 | ++ccount; |
823 | } | 830 | } |
824 | } | 831 | } |
825 | break; | 832 | break; |
826 | default: | 833 | default: |
827 | break; | 834 | break; |
828 | } | 835 | } |
829 | } | 836 | } |
830 | 837 | ||
831 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | 838 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) |
832 | { | 839 | { |
833 | if (!Description) { | 840 | if (!Description) { |
834 | return; | 841 | return; |
835 | } | 842 | } |
836 | switch (Description->bd_type) { | 843 | switch (Description->bd_type) { |
837 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 844 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
838 | target_part->setType("text"); | 845 | target_part->setType("text"); |
839 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 846 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
840 | break; | 847 | break; |
841 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 848 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
842 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 849 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
843 | break; | 850 | break; |
844 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 851 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
845 | target_part->setType("message"); | 852 | target_part->setType("message"); |
846 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 853 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
847 | break; | 854 | break; |
848 | default: | 855 | default: |
849 | break; | 856 | break; |
850 | } | 857 | } |
851 | } | 858 | } |
852 | 859 | ||
853 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | 860 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) |
854 | { | 861 | { |
855 | if (!which) { | 862 | if (!which) { |
856 | return; | 863 | return; |
857 | } | 864 | } |
858 | QString sub; | 865 | QString sub; |
859 | sub = which->bd_media_text; | 866 | sub = which->bd_media_text; |
860 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; | 867 | //odebug << "Type= text/" << which->bd_media_text << "" << oendl; |
861 | target_part->setSubtype(sub.lower()); | 868 | target_part->setSubtype(sub.lower()); |
862 | target_part->setLines(which->bd_lines); | 869 | target_part->setLines(which->bd_lines); |
863 | fillBodyFields(target_part,which->bd_fields); | 870 | fillBodyFields(target_part,which->bd_fields); |
864 | } | 871 | } |
865 | 872 | ||
866 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | 873 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) |
867 | { | 874 | { |
868 | if (!which) { | 875 | if (!which) { |
869 | return; | 876 | return; |
870 | } | 877 | } |
871 | target_part->setSubtype("rfc822"); | 878 | target_part->setSubtype("rfc822"); |
872 | //odebug << "Message part" << oendl; | 879 | //odebug << "Message part" << oendl; |
873 | /* we set this type to text/plain */ | 880 | /* we set this type to text/plain */ |
874 | target_part->setLines(which->bd_lines); | 881 | target_part->setLines(which->bd_lines); |
875 | fillBodyFields(target_part,which->bd_fields); | 882 | fillBodyFields(target_part,which->bd_fields); |
876 | } | 883 | } |
877 | 884 | ||
878 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | 885 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) |
879 | { | 886 | { |
880 | if (!which) return; | 887 | if (!which) return; |
881 | QString sub = which->bd_media_subtype; | 888 | QString sub = which->bd_media_subtype; |
882 | target_part->setSubtype(sub.lower()); | 889 | target_part->setSubtype(sub.lower()); |
883 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 890 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
884 | clistcell*cur = 0; | 891 | clistcell*cur = 0; |
885 | mailimap_single_body_fld_param*param=0; | 892 | mailimap_single_body_fld_param*param=0; |
886 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 893 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
887 | param = (mailimap_single_body_fld_param*)cur->data; | 894 | param = (mailimap_single_body_fld_param*)cur->data; |
888 | if (param) { | 895 | if (param) { |
889 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 896 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
890 | } | 897 | } |
891 | } | 898 | } |
892 | } | 899 | } |
893 | } | 900 | } |
894 | 901 | ||
895 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | 902 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) |
896 | { | 903 | { |
897 | if (!which) { | 904 | if (!which) { |
898 | return; | 905 | return; |
899 | } | 906 | } |
900 | QString type,sub; | 907 | QString type,sub; |
901 | switch (which->bd_media_basic->med_type) { | 908 | switch (which->bd_media_basic->med_type) { |
902 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 909 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
903 | type = "application"; | 910 | type = "application"; |
904 | break; | 911 | break; |
905 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 912 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
906 | type = "audio"; | 913 | type = "audio"; |
907 | break; | 914 | break; |
908 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 915 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
909 | type = "image"; | 916 | type = "image"; |
910 | break; | 917 | break; |
911 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 918 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
912 | type = "message"; | 919 | type = "message"; |
913 | break; | 920 | break; |
914 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 921 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
915 | type = "video"; | 922 | type = "video"; |
916 | break; | 923 | break; |
917 | case MAILIMAP_MEDIA_BASIC_OTHER: | 924 | case MAILIMAP_MEDIA_BASIC_OTHER: |
918 | default: | 925 | default: |
919 | if (which->bd_media_basic->med_basic_type) { | 926 | if (which->bd_media_basic->med_basic_type) { |
920 | type = which->bd_media_basic->med_basic_type; | 927 | type = which->bd_media_basic->med_basic_type; |
921 | } else { | 928 | } else { |
922 | type = ""; | 929 | type = ""; |
923 | } | 930 | } |
924 | break; | 931 | break; |
925 | } | 932 | } |
926 | if (which->bd_media_basic->med_subtype) { | 933 | if (which->bd_media_basic->med_subtype) { |
927 | sub = which->bd_media_basic->med_subtype; | 934 | sub = which->bd_media_basic->med_subtype; |
928 | } else { | 935 | } else { |
929 | sub = ""; | 936 | sub = ""; |
930 | } | 937 | } |
931 | // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; | 938 | // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; |
932 | target_part->setType(type.lower()); | 939 | target_part->setType(type.lower()); |
933 | target_part->setSubtype(sub.lower()); | 940 | target_part->setSubtype(sub.lower()); |
934 | fillBodyFields(target_part,which->bd_fields); | 941 | fillBodyFields(target_part,which->bd_fields); |
935 | } | 942 | } |
936 | 943 | ||
937 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) | 944 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) |
938 | { | 945 | { |
939 | if (!which) return; | 946 | if (!which) return; |
940 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 947 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
941 | clistcell*cur; | 948 | clistcell*cur; |
942 | mailimap_single_body_fld_param*param=0; | 949 | mailimap_single_body_fld_param*param=0; |
943 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 950 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
944 | param = (mailimap_single_body_fld_param*)cur->data; | 951 | param = (mailimap_single_body_fld_param*)cur->data; |
945 | if (param) { | 952 | if (param) { |
946 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 953 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
947 | } | 954 | } |
948 | } | 955 | } |
949 | } | 956 | } |
950 | mailimap_body_fld_enc*enc = which->bd_encoding; | 957 | mailimap_body_fld_enc*enc = which->bd_encoding; |
951 | QString encoding(""); | 958 | QString encoding(""); |
952 | switch (enc->enc_type) { | 959 | switch (enc->enc_type) { |
953 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 960 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
954 | encoding = "7bit"; | 961 | encoding = "7bit"; |
955 | break; | 962 | break; |
956 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 963 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
957 | encoding = "8bit"; | 964 | encoding = "8bit"; |
958 | break; | 965 | break; |
959 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 966 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
960 | encoding="binary"; | 967 | encoding="binary"; |
961 | break; | 968 | break; |
962 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 969 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
963 | encoding="base64"; | 970 | encoding="base64"; |
964 | break; | 971 | break; |
965 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 972 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
966 | encoding="quoted-printable"; | 973 | encoding="quoted-printable"; |
967 | break; | 974 | break; |
968 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 975 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
969 | default: | 976 | default: |
970 | if (enc->enc_value) { | 977 | if (enc->enc_value) { |
971 | char*t=enc->enc_value; | 978 | char*t=enc->enc_value; |
972 | encoding=QString(enc->enc_value); | 979 | encoding=QString(enc->enc_value); |
973 | enc->enc_value=0L; | 980 | enc->enc_value=0L; |
974 | free(t); | 981 | free(t); |
975 | } | 982 | } |
976 | } | 983 | } |
977 | if (which->bd_description) { | 984 | if (which->bd_description) { |
978 | target_part->setDescription(QString(which->bd_description)); | 985 | target_part->setDescription(QString(which->bd_description)); |
979 | } | 986 | } |
980 | target_part->setEncoding(encoding); | 987 | target_part->setEncoding(encoding); |
981 | target_part->setSize(which->bd_size); | 988 | target_part->setSize(which->bd_size); |
982 | } | 989 | } |
983 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) | 990 | void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) |
984 | { | 991 | { |
985 | //#if 0 | 992 | //#if 0 |
986 | mailimap_flag_list*flist; | 993 | mailimap_flag_list*flist; |
987 | mailimap_set *set; | 994 | mailimap_set *set; |
988 | mailimap_store_att_flags * store_flags; | 995 | mailimap_store_att_flags * store_flags; |
989 | int err; | 996 | int err; |
990 | login(); | 997 | login(); |
991 | //#endif | 998 | //#endif |
992 | if (!m_imap) { | 999 | if (!m_imap) { |
993 | return; | 1000 | return; |
994 | } | 1001 | } |
995 | int iii = 0; | 1002 | int iii = 0; |
996 | int count = target.count(); | 1003 | int count = target.count(); |
997 | // qDebug("imap remove count %d ", count); | 1004 | // qDebug("imap remove count %d ", count); |
998 | 1005 | ||
999 | 1006 | ||
1000 | mMax = count; | 1007 | mMax = count; |
1001 | progress( i18n("Delete")); | 1008 | progress( i18n("Delete")); |
1002 | 1009 | ||
1003 | QProgressBar wid ( count ); | 1010 | QProgressBar wid ( count ); |
1004 | wid.setCaption( i18n("Deleting ...")); | 1011 | wid.setCaption( i18n("Deleting ...")); |
1005 | wid.show(); | 1012 | wid.show(); |
1006 | while (iii < count ) { | 1013 | while (iii < count ) { |
1007 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); | 1014 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); |
1008 | wid.setProgress( iii ); | 1015 | wid.setProgress( iii ); |
1009 | wid.raise(); | 1016 | wid.raise(); |
1010 | qApp->processEvents(); | 1017 | qApp->processEvents(); |
1011 | RecMailP mail = (*target.at( iii )); | 1018 | RecMailP mail = (*target.at( iii )); |
1012 | //#if 0 | 1019 | //#if 0 |
1013 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); | 1020 | //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); |
1014 | err = selectMbox(mail->getMbox()); | 1021 | err = selectMbox(mail->getMbox()); |
1015 | if ( err != MAILIMAP_NO_ERROR ) { | 1022 | if ( err != MAILIMAP_NO_ERROR ) { |
1016 | return; | 1023 | return; |
1017 | } | 1024 | } |
1018 | flist = mailimap_flag_list_new_empty(); | 1025 | flist = mailimap_flag_list_new_empty(); |
1019 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1026 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
1020 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1027 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
1021 | set = mailimap_set_new_single(mail->getNumber()); | 1028 | set = mailimap_set_new_single(mail->getNumber()); |
1022 | err = mailimap_store(m_imap,set,store_flags); | 1029 | err = mailimap_store(m_imap,set,store_flags); |
1023 | mailimap_set_free( set ); | 1030 | mailimap_set_free( set ); |
1024 | mailimap_store_att_flags_free(store_flags); | 1031 | mailimap_store_att_flags_free(store_flags); |
1025 | 1032 | ||
1026 | if (err != MAILIMAP_NO_ERROR) { | 1033 | if (err != MAILIMAP_NO_ERROR) { |
1027 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 1034 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
1028 | return; | 1035 | return; |
1029 | } | 1036 | } |
1030 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1037 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1031 | /* should we realy do that at this moment? */ | 1038 | /* should we realy do that at this moment? */ |
1032 | 1039 | ||
1033 | // err = mailimap_expunge(m_imap); | 1040 | // err = mailimap_expunge(m_imap); |
1034 | //if (err != MAILIMAP_NO_ERROR) { | 1041 | //if (err != MAILIMAP_NO_ERROR) { |
1035 | // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); | 1042 | // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); |
1036 | // } | 1043 | // } |
1037 | //#endif | 1044 | //#endif |
1038 | //deleteMail( mail); | 1045 | //deleteMail( mail); |
1039 | ++iii; | 1046 | ++iii; |
1040 | } | 1047 | } |
1041 | //qDebug("Deleting imap mails... "); | 1048 | //qDebug("Deleting imap mails... "); |
1042 | err = mailimap_expunge(m_imap); | 1049 | err = mailimap_expunge(m_imap); |
1043 | if (err != MAILIMAP_NO_ERROR) { | 1050 | if (err != MAILIMAP_NO_ERROR) { |
1044 | Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); | 1051 | Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); |
1045 | } | 1052 | } |
1046 | } | 1053 | } |
1047 | void IMAPwrapper::deleteMail(const RecMailP&mail) | 1054 | void IMAPwrapper::deleteMail(const RecMailP&mail) |
1048 | { | 1055 | { |
1049 | mailimap_flag_list*flist; | 1056 | mailimap_flag_list*flist; |
1050 | mailimap_set *set; | 1057 | mailimap_set *set; |
1051 | mailimap_store_att_flags * store_flags; | 1058 | mailimap_store_att_flags * store_flags; |
1052 | int err; | 1059 | int err; |
1053 | login(); | 1060 | login(); |
1054 | if (!m_imap) { | 1061 | if (!m_imap) { |
1055 | return; | 1062 | return; |
1056 | } | 1063 | } |
1057 | err = selectMbox(mail->getMbox()); | 1064 | err = selectMbox(mail->getMbox()); |
1058 | if ( err != MAILIMAP_NO_ERROR ) { | 1065 | if ( err != MAILIMAP_NO_ERROR ) { |
1059 | return; | 1066 | return; |
1060 | } | 1067 | } |
1061 | flist = mailimap_flag_list_new_empty(); | 1068 | flist = mailimap_flag_list_new_empty(); |
1062 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1069 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
1063 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1070 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
1064 | set = mailimap_set_new_single(mail->getNumber()); | 1071 | set = mailimap_set_new_single(mail->getNumber()); |
1065 | err = mailimap_store(m_imap,set,store_flags); | 1072 | err = mailimap_store(m_imap,set,store_flags); |
1066 | mailimap_set_free( set ); | 1073 | mailimap_set_free( set ); |
1067 | mailimap_store_att_flags_free(store_flags); | 1074 | mailimap_store_att_flags_free(store_flags); |
1068 | 1075 | ||
1069 | if (err != MAILIMAP_NO_ERROR) { | 1076 | if (err != MAILIMAP_NO_ERROR) { |
1070 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 1077 | // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
1071 | return; | 1078 | return; |
1072 | } | 1079 | } |
1073 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1080 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1074 | /* should we realy do that at this moment? */ | 1081 | /* should we realy do that at this moment? */ |
1075 | 1082 | ||
1076 | err = mailimap_expunge(m_imap); | 1083 | err = mailimap_expunge(m_imap); |
1077 | if (err != MAILIMAP_NO_ERROR) { | 1084 | if (err != MAILIMAP_NO_ERROR) { |
1078 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); | 1085 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); |
1079 | } | 1086 | } |
1080 | //qDebug("IMAPwrapper::deleteMail 2"); | 1087 | //qDebug("IMAPwrapper::deleteMail 2"); |
1081 | 1088 | ||
1082 | } | 1089 | } |
1083 | 1090 | ||
1084 | void IMAPwrapper::answeredMail(const RecMailP&mail) | 1091 | void IMAPwrapper::answeredMail(const RecMailP&mail) |
1085 | { | 1092 | { |
1086 | mailimap_flag_list*flist; | 1093 | mailimap_flag_list*flist; |
1087 | mailimap_set *set; | 1094 | mailimap_set *set; |
1088 | mailimap_store_att_flags * store_flags; | 1095 | mailimap_store_att_flags * store_flags; |
1089 | int err; | 1096 | int err; |
1090 | login(); | 1097 | login(); |
1091 | if (!m_imap) { | 1098 | if (!m_imap) { |
1092 | return; | 1099 | return; |
1093 | } | 1100 | } |
1094 | err = selectMbox(mail->getMbox()); | 1101 | err = selectMbox(mail->getMbox()); |
1095 | if ( err != MAILIMAP_NO_ERROR ) { | 1102 | if ( err != MAILIMAP_NO_ERROR ) { |
1096 | return; | 1103 | return; |
1097 | } | 1104 | } |
1098 | flist = mailimap_flag_list_new_empty(); | 1105 | flist = mailimap_flag_list_new_empty(); |
1099 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 1106 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
1100 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 1107 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
1101 | set = mailimap_set_new_single(mail->getNumber()); | 1108 | set = mailimap_set_new_single(mail->getNumber()); |
1102 | err = mailimap_store(m_imap,set,store_flags); | 1109 | err = mailimap_store(m_imap,set,store_flags); |
1103 | mailimap_set_free( set ); | 1110 | mailimap_set_free( set ); |
1104 | mailimap_store_att_flags_free(store_flags); | 1111 | mailimap_store_att_flags_free(store_flags); |
1105 | 1112 | ||
1106 | if (err != MAILIMAP_NO_ERROR) { | 1113 | if (err != MAILIMAP_NO_ERROR) { |
1107 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | 1114 | // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; |
1108 | return; | 1115 | return; |
1109 | } | 1116 | } |
1110 | } | 1117 | } |
1111 | 1118 | ||
1112 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 1119 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
1113 | { | 1120 | { |
1114 | QString body(""); | 1121 | QString body(""); |
1115 | encodedString*res = fetchRawPart(mail,path,internal_call); | 1122 | encodedString*res = fetchRawPart(mail,path,internal_call); |
1116 | encodedString*r = decode_String(res,enc); | 1123 | encodedString*r = decode_String(res,enc); |
1117 | delete res; | 1124 | delete res; |
1118 | if (r) { | 1125 | if (r) { |
1119 | if (r->Length()>0) { | 1126 | if (r->Length()>0) { |
1120 | body = r->Content(); | 1127 | body = r->Content(); |
1121 | } | 1128 | } |
1122 | delete r; | 1129 | delete r; |
1123 | } | 1130 | } |
1124 | return body; | 1131 | return body; |
1125 | } | 1132 | } |
1126 | 1133 | ||
1127 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 1134 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
1128 | { | 1135 | { |
1129 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); | 1136 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); |
1130 | } | 1137 | } |
1131 | 1138 | ||
1132 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) | 1139 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) |
1133 | { | 1140 | { |
1134 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); | 1141 | encodedString*res = fetchRawPart(mail,part->Positionlist(),false); |
1135 | encodedString*r = decode_String(res,part->Encoding()); | 1142 | encodedString*r = decode_String(res,part->Encoding()); |
1136 | delete res; | 1143 | delete res; |
1137 | return r; | 1144 | return r; |
1138 | } | 1145 | } |
1139 | 1146 | ||
1140 | encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) | 1147 | encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) |
1141 | { | 1148 | { |
1142 | return fetchRawPart(mail,part->Positionlist(),false); | 1149 | return fetchRawPart(mail,part->Positionlist(),false); |
1143 | } | 1150 | } |
1144 | 1151 | ||
1145 | int IMAPwrapper::deleteAllMail(const FolderP&folder) | 1152 | int IMAPwrapper::deleteAllMail(const FolderP&folder) |
1146 | { | 1153 | { |
1147 | login(); | 1154 | login(); |
1148 | if (!m_imap) { | 1155 | if (!m_imap) { |
1149 | return 0; | 1156 | return 0; |
1150 | } | 1157 | } |
1151 | mailimap_flag_list*flist; | 1158 | mailimap_flag_list*flist; |
1152 | mailimap_set *set; | 1159 | mailimap_set *set; |
1153 | mailimap_store_att_flags * store_flags; | 1160 | mailimap_store_att_flags * store_flags; |
1154 | int err = selectMbox(folder->getName()); | 1161 | int err = selectMbox(folder->getName()); |
1155 | if ( err != MAILIMAP_NO_ERROR ) { | 1162 | if ( err != MAILIMAP_NO_ERROR ) { |
1156 | return 0; | 1163 | return 0; |
1157 | } | 1164 | } |
1158 | 1165 | ||
1159 | int last = m_imap->imap_selection_info->sel_exists; | 1166 | int last = m_imap->imap_selection_info->sel_exists; |
1160 | if (last == 0) { | 1167 | if (last == 0) { |
1161 | Global::statusMessage(i18n("Mailbox has no mails!")); | 1168 | Global::statusMessage(i18n("Mailbox has no mails!")); |
1162 | return 0; | 1169 | return 0; |
1163 | } | 1170 | } |
1164 | flist = mailimap_flag_list_new_empty(); | 1171 | flist = mailimap_flag_list_new_empty(); |
1165 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 1172 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
1166 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 1173 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
1167 | set = mailimap_set_new_interval( 1, last ); | 1174 | set = mailimap_set_new_interval( 1, last ); |
1168 | err = mailimap_store(m_imap,set,store_flags); | 1175 | err = mailimap_store(m_imap,set,store_flags); |
1169 | mailimap_set_free( set ); | 1176 | mailimap_set_free( set ); |
1170 | mailimap_store_att_flags_free(store_flags); | 1177 | mailimap_store_att_flags_free(store_flags); |
1171 | if (err != MAILIMAP_NO_ERROR) { | 1178 | if (err != MAILIMAP_NO_ERROR) { |
1172 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); | 1179 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); |
1173 | return 0; | 1180 | return 0; |
1174 | } | 1181 | } |
1175 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 1182 | // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
1176 | /* should we realy do that at this moment? */ | 1183 | /* should we realy do that at this moment? */ |
1177 | err = mailimap_expunge(m_imap); | 1184 | err = mailimap_expunge(m_imap); |
1178 | if (err != MAILIMAP_NO_ERROR) { | 1185 | if (err != MAILIMAP_NO_ERROR) { |
1179 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); | 1186 | Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); |
1180 | return 0; | 1187 | return 0; |
1181 | } | 1188 | } |
1182 | // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 1189 | // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; |
1183 | return 1; | 1190 | return 1; |
1184 | } | 1191 | } |
1185 | 1192 | ||
1186 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) | 1193 | int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) |
1187 | { | 1194 | { |
1188 | if (folder.length()==0) return 0; | 1195 | if (folder.length()==0) return 0; |
1189 | login(); | 1196 | login(); |
1190 | if (!m_imap) {return 0;} | 1197 | if (!m_imap) {return 0;} |
1191 | QString pre = account->getPrefix(); | 1198 | QString pre = account->getPrefix(); |
1192 | if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) { | 1199 | if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) { |
1193 | pre+=delemiter; | 1200 | pre+=delemiter; |
1194 | } | 1201 | } |
1195 | if (parentfolder) { | 1202 | if (parentfolder) { |
1196 | pre += parentfolder->getDisplayName()+delemiter; | 1203 | pre += parentfolder->getDisplayName()+delemiter; |
1197 | } | 1204 | } |
1198 | pre+=folder; | 1205 | pre+=folder; |
1199 | if (getsubfolder) { | 1206 | if (getsubfolder) { |
1200 | if (delemiter.length()>0) { | 1207 | if (delemiter.length()>0) { |
1201 | pre+=delemiter; | 1208 | pre+=delemiter; |
1202 | } else { | 1209 | } else { |
1203 | Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); | 1210 | Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); |
1204 | return 0; | 1211 | return 0; |
1205 | } | 1212 | } |
1206 | } | 1213 | } |
1207 | // odebug << "Creating " << pre.latin1() << "" << oendl; | 1214 | // odebug << "Creating " << pre.latin1() << "" << oendl; |
1208 | int res = mailimap_create(m_imap,pre.latin1()); | 1215 | int res = mailimap_create(m_imap,pre.latin1()); |
1209 | if (res != MAILIMAP_NO_ERROR) { | 1216 | if (res != MAILIMAP_NO_ERROR) { |
1210 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); | 1217 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); |
1211 | return 0; | 1218 | return 0; |
1212 | } | 1219 | } |
1213 | return 1; | 1220 | return 1; |
1214 | } | 1221 | } |
1215 | 1222 | ||
1216 | int IMAPwrapper::deleteMbox(const FolderP&folder) | 1223 | int IMAPwrapper::deleteMbox(const FolderP&folder) |
1217 | { | 1224 | { |
1218 | if (!folder) return 0; | 1225 | if (!folder) return 0; |
1219 | login(); | 1226 | login(); |
1220 | if (!m_imap) {return 0;} | 1227 | if (!m_imap) {return 0;} |
1221 | int res = mailimap_delete(m_imap,folder->getName()); | 1228 | int res = mailimap_delete(m_imap,folder->getName()); |
1222 | if (res != MAILIMAP_NO_ERROR) { | 1229 | if (res != MAILIMAP_NO_ERROR) { |
1223 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); | 1230 | Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); |
1224 | return 0; | 1231 | return 0; |
1225 | } | 1232 | } |
1226 | return 1; | 1233 | return 1; |
1227 | } | 1234 | } |
1228 | 1235 | ||
1229 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 1236 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
1230 | { | 1237 | { |
1231 | mailimap_status_att_list * att_list =0; | 1238 | mailimap_status_att_list * att_list =0; |
1232 | mailimap_mailbox_data_status * status=0; | 1239 | mailimap_mailbox_data_status * status=0; |
1233 | clistiter * cur = 0; | 1240 | clistiter * cur = 0; |
1234 | int r = 0; | 1241 | int r = 0; |
1235 | target_stat.message_count = 0; | 1242 | target_stat.message_count = 0; |
1236 | target_stat.message_unseen = 0; | 1243 | target_stat.message_unseen = 0; |
1237 | target_stat.message_recent = 0; | 1244 | target_stat.message_recent = 0; |
1238 | login(); | 1245 | login(); |
1239 | if (!m_imap) { | 1246 | if (!m_imap) { |
1240 | return; | 1247 | return; |
1241 | } | 1248 | } |
1242 | att_list = mailimap_status_att_list_new_empty(); | 1249 | att_list = mailimap_status_att_list_new_empty(); |
1243 | if (!att_list) return; | 1250 | if (!att_list) return; |
1244 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); | 1251 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); |
1245 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); | 1252 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); |
1246 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | 1253 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); |
1247 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | 1254 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); |
1248 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { | 1255 | if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { |
1249 | for (cur = clist_begin(status->st_info_list); | 1256 | for (cur = clist_begin(status->st_info_list); |
1250 | cur != NULL ; cur = clist_next(cur)) { | 1257 | cur != NULL ; cur = clist_next(cur)) { |
1251 | mailimap_status_info * status_info; | 1258 | mailimap_status_info * status_info; |
1252 | status_info = (mailimap_status_info *)clist_content(cur); | 1259 | status_info = (mailimap_status_info *)clist_content(cur); |
1253 | switch (status_info->st_att) { | 1260 | switch (status_info->st_att) { |
1254 | case MAILIMAP_STATUS_ATT_MESSAGES: | 1261 | case MAILIMAP_STATUS_ATT_MESSAGES: |
1255 | target_stat.message_count = status_info->st_value; | 1262 | target_stat.message_count = status_info->st_value; |
1256 | break; | 1263 | break; |
1257 | case MAILIMAP_STATUS_ATT_RECENT: | 1264 | case MAILIMAP_STATUS_ATT_RECENT: |
1258 | target_stat.message_recent = status_info->st_value; | 1265 | target_stat.message_recent = status_info->st_value; |
1259 | break; | 1266 | break; |
1260 | case MAILIMAP_STATUS_ATT_UNSEEN: | 1267 | case MAILIMAP_STATUS_ATT_UNSEEN: |
1261 | target_stat.message_unseen = status_info->st_value; | 1268 | target_stat.message_unseen = status_info->st_value; |
1262 | break; | 1269 | break; |
1263 | } | 1270 | } |
1264 | } | 1271 | } |
1265 | } else { | 1272 | } else { |
1266 | // odebug << "Error retrieving status" << oendl; | 1273 | // odebug << "Error retrieving status" << oendl; |
1267 | } | 1274 | } |
1268 | if (status) mailimap_mailbox_data_status_free(status); | 1275 | if (status) mailimap_mailbox_data_status_free(status); |
1269 | if (att_list) mailimap_status_att_list_free(att_list); | 1276 | if (att_list) mailimap_status_att_list_free(att_list); |
1270 | } | 1277 | } |
1271 | 1278 | ||
1272 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 1279 | void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
1273 | { | 1280 | { |
1274 | login(); | 1281 | login(); |
1275 | if (!m_imap) return; | 1282 | if (!m_imap) return; |
1276 | if (!msg) return; | 1283 | if (!msg) return; |
1277 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); | 1284 | int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); |
1278 | if (r != MAILIMAP_NO_ERROR) { | 1285 | if (r != MAILIMAP_NO_ERROR) { |
1279 | Global::statusMessage("Error storing mail!"); | 1286 | Global::statusMessage("Error storing mail!"); |
1280 | } | 1287 | } |
1281 | } | 1288 | } |
1282 | 1289 | ||
1283 | MAILLIB::ATYPE IMAPwrapper::getType()const | 1290 | MAILLIB::ATYPE IMAPwrapper::getType()const |
1284 | { | 1291 | { |
1285 | return account->getType(); | 1292 | return account->getType(); |
1286 | } | 1293 | } |
1287 | 1294 | ||
1288 | const QString&IMAPwrapper::getName()const | 1295 | const QString&IMAPwrapper::getName()const |
1289 | { | 1296 | { |
1290 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; | 1297 | // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; |
1291 | return account->getAccountName(); | 1298 | return account->getAccountName(); |
1292 | } | 1299 | } |
1293 | 1300 | ||
1294 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) | 1301 | encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) |
1295 | { | 1302 | { |
1296 | // dummy | 1303 | // dummy |
1297 | QValueList<int> path; | 1304 | QValueList<int> path; |
1298 | return fetchRawPart(mail,path,false); | 1305 | return fetchRawPart(mail,path,false); |
1299 | } | 1306 | } |
1300 | 1307 | ||
1301 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, | 1308 | void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, |
1302 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) | 1309 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) |
1303 | { | 1310 | { |
1304 | if (targetWrapper != this || maxSizeInKb > 0 ) { | 1311 | if (targetWrapper != this || maxSizeInKb > 0 ) { |
1305 | mMax = 0; | 1312 | mMax = 0; |
1306 | progress( i18n("Copy")); | 1313 | progress( i18n("Copy")); |
1307 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); | 1314 | AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); |
1308 | //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); | 1315 | //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); |
1309 | // odebug << "Using generic" << oendl; | 1316 | // odebug << "Using generic" << oendl; |
1310 | return; | 1317 | return; |
1311 | } | 1318 | } |
1312 | mailimap_set *set = 0; | 1319 | mailimap_set *set = 0; |
1313 | login(); | 1320 | login(); |
1314 | if (!m_imap) { | 1321 | if (!m_imap) { |
1315 | return; | 1322 | return; |
1316 | } | 1323 | } |
1317 | int err = selectMbox(fromFolder->getName()); | 1324 | int err = selectMbox(fromFolder->getName()); |
1318 | if ( err != MAILIMAP_NO_ERROR ) { | 1325 | if ( err != MAILIMAP_NO_ERROR ) { |
1319 | return; | 1326 | return; |
1320 | } | 1327 | } |
1321 | Global::statusMessage( i18n("Copying mails on server...") ); | 1328 | Global::statusMessage( i18n("Copying mails on server...") ); |
1322 | int last = m_imap->imap_selection_info->sel_exists; | 1329 | int last = m_imap->imap_selection_info->sel_exists; |
1323 | set = mailimap_set_new_interval( 1, last ); | 1330 | set = mailimap_set_new_interval( 1, last ); |
1324 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1331 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1325 | mailimap_set_free( set ); | 1332 | mailimap_set_free( set ); |
1326 | if ( err != MAILIMAP_NO_ERROR ) { | 1333 | if ( err != MAILIMAP_NO_ERROR ) { |
1327 | QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response); | 1334 | QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response); |
1328 | Global::statusMessage(error_msg); | 1335 | Global::statusMessage(error_msg); |
1329 | // odebug << error_msg << oendl; | 1336 | // odebug << error_msg << oendl; |
1330 | return; | 1337 | return; |
1331 | } | 1338 | } |
1332 | if (moveit) { | 1339 | if (moveit) { |
1333 | deleteAllMail(fromFolder); | 1340 | deleteAllMail(fromFolder); |
1334 | } | 1341 | } |
1335 | } | 1342 | } |
1336 | 1343 | ||
1337 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) | 1344 | void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) |
1338 | { | 1345 | { |
1339 | if (targetWrapper != this) { | 1346 | if (targetWrapper != this) { |
1340 | // odebug << "Using generic" << oendl; | 1347 | // odebug << "Using generic" << oendl; |
1341 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); | 1348 | AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); |
1342 | return; | 1349 | return; |
1343 | } | 1350 | } |
1344 | mailimap_set *set = 0; | 1351 | mailimap_set *set = 0; |
1345 | login(); | 1352 | login(); |
1346 | if (!m_imap) { | 1353 | if (!m_imap) { |
1347 | return; | 1354 | return; |
1348 | } | 1355 | } |
1349 | int err = selectMbox(mail->getMbox()); | 1356 | int err = selectMbox(mail->getMbox()); |
1350 | if ( err != MAILIMAP_NO_ERROR ) { | 1357 | if ( err != MAILIMAP_NO_ERROR ) { |
1351 | return; | 1358 | return; |
1352 | } | 1359 | } |
1353 | set = mailimap_set_new_single(mail->getNumber()); | 1360 | set = mailimap_set_new_single(mail->getNumber()); |
1354 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); | 1361 | err = mailimap_copy(m_imap,set,targetFolder.latin1()); |
1355 | mailimap_set_free( set ); | 1362 | mailimap_set_free( set ); |
1356 | if ( err != MAILIMAP_NO_ERROR ) { | 1363 | if ( err != MAILIMAP_NO_ERROR ) { |
1357 | QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response); | 1364 | QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response); |
1358 | Global::statusMessage(error_msg); | 1365 | Global::statusMessage(error_msg); |
1359 | // odebug << error_msg << oendl; | 1366 | // odebug << error_msg << oendl; |
1360 | return; | 1367 | return; |
1361 | } | 1368 | } |
1362 | if (moveit) { | 1369 | if (moveit) { |
1363 | deleteMail(mail); | 1370 | deleteMail(mail); |
1364 | } | 1371 | } |
1365 | } | 1372 | } |
diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h index 5535d8d..31c60a8 100644 --- a/kmicromail/libmailwrapper/imapwrapper.h +++ b/kmicromail/libmailwrapper/imapwrapper.h | |||
@@ -1,85 +1,85 @@ | |||
1 | // CHANGED 2004-09-31 Lutz Rogowski | 1 | // CHANGED 2004-09-31 Lutz Rogowski |
2 | #ifndef __IMAPWRAPPER | 2 | #ifndef __IMAPWRAPPER |
3 | #define __IMAPWRAPPER | 3 | #define __IMAPWRAPPER |
4 | 4 | ||
5 | #include <qlist.h> | 5 | #include <qlist.h> |
6 | #include "mailwrapper.h" | 6 | #include "mailwrapper.h" |
7 | #include "abstractmail.h" | 7 | #include "abstractmail.h" |
8 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
9 | 9 | ||
10 | struct mailimap; | 10 | struct mailimap; |
11 | struct mailimap_body; | 11 | struct mailimap_body; |
12 | struct mailimap_body_type_1part; | 12 | struct mailimap_body_type_1part; |
13 | struct mailimap_body_type_text; | 13 | struct mailimap_body_type_text; |
14 | struct mailimap_body_type_basic; | 14 | struct mailimap_body_type_basic; |
15 | struct mailimap_body_type_msg; | 15 | struct mailimap_body_type_msg; |
16 | struct mailimap_body_type_mpart; | 16 | struct mailimap_body_type_mpart; |
17 | struct mailimap_body_fields; | 17 | struct mailimap_body_fields; |
18 | struct mailimap_msg_att; | 18 | struct mailimap_msg_att; |
19 | class encodedString; | 19 | class encodedString; |
20 | 20 | ||
21 | class IMAPwrapper : public AbstractMail | 21 | class IMAPwrapper : public AbstractMail |
22 | { | 22 | { |
23 | Q_OBJECT | 23 | Q_OBJECT |
24 | public: | 24 | public: |
25 | IMAPwrapper( IMAPaccount *a ); | 25 | IMAPwrapper( IMAPaccount *a ); |
26 | virtual ~IMAPwrapper(); | 26 | virtual ~IMAPwrapper(); |
27 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); | 27 | virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); |
28 | virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0); | 28 | virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0); |
29 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | 29 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); |
30 | 30 | ||
31 | virtual void deleteMail(const RecMailP&mail); | 31 | virtual void deleteMail(const RecMailP&mail); |
32 | void deleteMailList(const QValueList<RecMailP>&target); | 32 | void deleteMailList(const QValueList<RecMailP>&target); |
33 | virtual void answeredMail(const RecMailP&mail); | 33 | virtual void answeredMail(const RecMailP&mail); |
34 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); | 34 | virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); |
35 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); | 35 | virtual void storeMessage(const char*msg,size_t length, const QString&folder); |
36 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, | 36 | virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, |
37 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0); | 37 | const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0); |
38 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); | 38 | virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); |
39 | 39 | ||
40 | virtual RecBodyP fetchBody(const RecMailP&mail); | 40 | virtual RecBodyP fetchBody(const RecMailP&mail); |
41 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); | 41 | virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); |
42 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); | 42 | virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); |
43 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); | 43 | virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); |
44 | virtual encodedString* fetchRawBody(const RecMailP&mail); | 44 | virtual encodedString* fetchRawBody(const RecMailP&mail); |
45 | 45 | ||
46 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, | 46 | virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, |
47 | const QString& delemiter="/",bool getsubfolder=false); | 47 | const QString& delemiter="/",bool getsubfolder=false); |
48 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); | 48 | virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); |
49 | 49 | ||
50 | static void imap_progress( size_t current, size_t maximum ); | 50 | static void imap_progress( size_t current, size_t maximum ); |
51 | 51 | ||
52 | virtual void logout(); | 52 | virtual void logout(); |
53 | virtual MAILLIB::ATYPE getType()const; | 53 | virtual MAILLIB::ATYPE getType()const; |
54 | virtual const QString&getName()const; | 54 | virtual const QString&getName()const; |
55 | virtual Account* getAccount() { return account; }; | 55 | virtual Account* getAccount() { return account; }; |
56 | 56 | ||
57 | protected: | 57 | protected: |
58 | RecMail*parse_list_result(mailimap_msg_att*); | 58 | RecMail*parse_list_result(mailimap_msg_att*); |
59 | void login(); | 59 | void login(bool tryTLS = true); |
60 | bool start_tls(bool force=true); | 60 | bool start_tls(bool force=true); |
61 | 61 | ||
62 | virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 62 | virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
63 | virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); | 63 | virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); |
64 | int selectMbox(const QString&mbox); | 64 | int selectMbox(const QString&mbox); |
65 | 65 | ||
66 | void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); | 66 | void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); |
67 | void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); | 67 | void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); |
68 | void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); | 68 | void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); |
69 | void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); | 69 | void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); |
70 | void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); | 70 | void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); |
71 | void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); | 71 | void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); |
72 | 72 | ||
73 | /* just helpers */ | 73 | /* just helpers */ |
74 | static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); | 74 | static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); |
75 | static QStringList address_list_to_stringlist(clist*list); | 75 | static QStringList address_list_to_stringlist(clist*list); |
76 | 76 | ||
77 | static void progress(QString mess = QString::null); | 77 | static void progress(QString mess = QString::null); |
78 | static int mCurrent; | 78 | static int mCurrent; |
79 | static int mMax; | 79 | static int mMax; |
80 | IMAPaccount *account; | 80 | IMAPaccount *account; |
81 | mailimap *m_imap; | 81 | mailimap *m_imap; |
82 | QString m_Lastmbox; | 82 | QString m_Lastmbox; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | #endif | 85 | #endif |