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