author | alwin <alwin> | 2004-10-27 00:20:35 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-10-27 00:20:35 (UTC) |
commit | e44d35ca3fd26ef7a3184b07516f6535d8844a83 (patch) (unidiff) | |
tree | 4c4ac98450106bb9b05ca76bf5f29e2b6d4fc58b | |
parent | ae5855babec6e46802be89ee408d26a2cbbb1981 (diff) | |
download | opie-e44d35ca3fd26ef7a3184b07516f6535d8844a83.zip opie-e44d35ca3fd26ef7a3184b07516f6535d8844a83.tar.gz opie-e44d35ca3fd26ef7a3184b07516f6535d8844a83.tar.bz2 |
fixed a bug within tls support
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 8e5212b..576804d 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,956 +1,958 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <libetpan/libetpan.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <qpe/global.h> | 3 | #include <qpe/global.h> |
4 | #include <opie2/oapplication.h> | 4 | #include <opie2/oapplication.h> |
5 | #include <opie2/odebug.h> | 5 | #include <opie2/odebug.h> |
6 | 6 | ||
7 | #include "imapwrapper.h" | 7 | #include "imapwrapper.h" |
8 | #include "mailtypes.h" | 8 | #include "mailtypes.h" |
9 | #include "logindialog.h" | 9 | #include "logindialog.h" |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) | 12 | IMAPwrapper::IMAPwrapper( IMAPaccount *a ) |
13 | : AbstractMail(),MailStatics() | 13 | : AbstractMail(),MailStatics() |
14 | { | 14 | { |
15 | account = a; | 15 | account = a; |
16 | m_imap = 0; | 16 | m_imap = 0; |
17 | m_Lastmbox = ""; | 17 | m_Lastmbox = ""; |
18 | } | 18 | } |
19 | 19 | ||
20 | IMAPwrapper::~IMAPwrapper() | 20 | IMAPwrapper::~IMAPwrapper() |
21 | { | 21 | { |
22 | logout(); | 22 | logout(); |
23 | } | 23 | } |
24 | 24 | ||
25 | /* to avoid to often select statements in loops etc. | 25 | /* to avoid to often select statements in loops etc. |
26 | we trust that we are logged in and connection is established!*/ | 26 | we trust that we are logged in and connection is established!*/ |
27 | int IMAPwrapper::selectMbox(const QString&mbox) | 27 | int IMAPwrapper::selectMbox(const QString&mbox) |
28 | { | 28 | { |
29 | if (mbox == m_Lastmbox) { | 29 | if (mbox == m_Lastmbox) { |
30 | return MAILIMAP_NO_ERROR; | 30 | return MAILIMAP_NO_ERROR; |
31 | } | 31 | } |
32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); | 32 | int err = mailimap_select( m_imap, (char*)mbox.latin1()); |
33 | if ( err != MAILIMAP_NO_ERROR ) { | 33 | if ( err != MAILIMAP_NO_ERROR ) { |
34 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; | 34 | odebug << "error selecting mailbox: " << m_imap->imap_response << "" << oendl; |
35 | m_Lastmbox = ""; | 35 | m_Lastmbox = ""; |
36 | return err; | 36 | return err; |
37 | } | 37 | } |
38 | m_Lastmbox = mbox; | 38 | m_Lastmbox = mbox; |
39 | return err; | 39 | return err; |
40 | } | 40 | } |
41 | 41 | ||
42 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | 42 | void IMAPwrapper::imap_progress( size_t current, size_t maximum ) |
43 | { | 43 | { |
44 | qApp->processEvents(); | 44 | qApp->processEvents(); |
45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; | 45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; |
46 | } | 46 | } |
47 | 47 | ||
48 | bool IMAPwrapper::start_tls(bool force_tls) | 48 | bool IMAPwrapper::start_tls(bool force_tls) |
49 | { | 49 | { |
50 | int err; | 50 | int err; |
51 | bool try_tls; | 51 | bool try_tls; |
52 | mailimap_capability_data * cap_data = 0; | 52 | mailimap_capability_data * cap_data = 0; |
53 | 53 | ||
54 | err = mailimap_capability(m_imap,&cap_data); | 54 | err = mailimap_capability(m_imap,&cap_data); |
55 | if (err != MAILIMAP_NO_ERROR) { | 55 | if (err != MAILIMAP_NO_ERROR) { |
56 | Global::statusMessage("error getting capabilities!"); | 56 | Global::statusMessage("error getting capabilities!"); |
57 | odebug << "error getting capabilities!" << oendl; | 57 | odebug << "error getting capabilities!" << oendl; |
58 | return false; | 58 | return false; |
59 | } | 59 | } |
60 | clistiter * cur; | 60 | clistiter * cur; |
61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
62 | struct mailimap_capability * cap; | 62 | struct mailimap_capability * cap; |
63 | cap = (struct mailimap_capability *)clist_content(cur); | 63 | cap = (struct mailimap_capability *)clist_content(cur); |
64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
66 | try_tls = true; | 66 | try_tls = true; |
67 | break; | 67 | break; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | if (cap_data) { | 71 | if (cap_data) { |
72 | mailimap_capability_data_free(cap_data); | 72 | mailimap_capability_data_free(cap_data); |
73 | } | 73 | } |
74 | if (try_tls) { | 74 | if (try_tls) { |
75 | err = mailimap_starttls(m_imap); | 75 | err = mailimap_starttls(m_imap); |
76 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 76 | if (err != MAILIMAP_NO_ERROR) { |
77 | Global::statusMessage(tr("Server has no TLS support!")); | 77 | if (force_tls) { |
78 | odebug << "Server has no TLS support!" << oendl; | 78 | Global::statusMessage(tr("Server has no TLS support!")); |
79 | odebug << "Server has no TLS support!" << oendl; | ||
80 | } | ||
79 | try_tls = false; | 81 | try_tls = false; |
80 | } else { | 82 | } else { |
81 | mailstream_low * low; | 83 | mailstream_low * low; |
82 | mailstream_low * new_low; | 84 | mailstream_low * new_low; |
83 | low = mailstream_get_low(m_imap->imap_stream); | 85 | low = mailstream_get_low(m_imap->imap_stream); |
84 | if (!low) { | 86 | if (!low) { |
85 | try_tls = false; | 87 | try_tls = false; |
86 | } else { | 88 | } else { |
87 | int fd = mailstream_low_get_fd(low); | 89 | int fd = mailstream_low_get_fd(low); |
88 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 90 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
89 | mailstream_low_free(low); | 91 | mailstream_low_free(low); |
90 | mailstream_set_low(m_imap->imap_stream, new_low); | 92 | mailstream_set_low(m_imap->imap_stream, new_low); |
91 | } else { | 93 | } else { |
92 | try_tls = false; | 94 | try_tls = false; |
93 | } | 95 | } |
94 | } | 96 | } |
95 | } | 97 | } |
96 | } | 98 | } |
97 | return try_tls; | 99 | return try_tls; |
98 | } | 100 | } |
99 | 101 | ||
100 | void IMAPwrapper::login() | 102 | void IMAPwrapper::login() |
101 | { | 103 | { |
102 | const char *server, *user, *pass; | 104 | const char *server, *user, *pass; |
103 | uint16_t port; | 105 | uint16_t port; |
104 | int err = MAILIMAP_NO_ERROR; | 106 | int err = MAILIMAP_NO_ERROR; |
105 | 107 | ||
106 | if (account->getOffline()) return; | 108 | if (account->getOffline()) return; |
107 | /* we are connected this moment */ | 109 | /* we are connected this moment */ |
108 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 110 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
109 | if (m_imap) { | 111 | if (m_imap) { |
110 | err = mailimap_noop(m_imap); | 112 | err = mailimap_noop(m_imap); |
111 | if (err!=MAILIMAP_NO_ERROR) { | 113 | if (err!=MAILIMAP_NO_ERROR) { |
112 | logout(); | 114 | logout(); |
113 | } else { | 115 | } else { |
114 | mailstream_flush(m_imap->imap_stream); | 116 | mailstream_flush(m_imap->imap_stream); |
115 | return; | 117 | return; |
116 | } | 118 | } |
117 | } | 119 | } |
118 | server = account->getServer().latin1(); | 120 | server = account->getServer().latin1(); |
119 | port = account->getPort().toUInt(); | 121 | port = account->getPort().toUInt(); |
120 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 122 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
121 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 123 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
122 | login.show(); | 124 | login.show(); |
123 | if ( QDialog::Accepted == login.exec() ) { | 125 | if ( QDialog::Accepted == login.exec() ) { |
124 | // ok | 126 | // ok |
125 | user = login.getUser().latin1(); | 127 | user = login.getUser().latin1(); |
126 | pass = login.getPassword().latin1(); | 128 | pass = login.getPassword().latin1(); |
127 | } else { | 129 | } else { |
128 | // cancel | 130 | // cancel |
129 | odebug << "IMAP: Login canceled" << oendl; | 131 | odebug << "IMAP: Login canceled" << oendl; |
130 | return; | 132 | return; |
131 | } | 133 | } |
132 | } else { | 134 | } else { |
133 | user = account->getUser().latin1(); | 135 | user = account->getUser().latin1(); |
134 | pass = account->getPassword().latin1(); | 136 | pass = account->getPassword().latin1(); |
135 | } | 137 | } |
136 | 138 | ||
137 | m_imap = mailimap_new( 20, &imap_progress ); | 139 | m_imap = mailimap_new( 20, &imap_progress ); |
138 | 140 | ||
139 | /* connect */ | 141 | /* connect */ |
140 | bool ssl = false; | 142 | bool ssl = false; |
141 | bool try_tls = false; | 143 | bool try_tls = false; |
142 | bool force_tls = false; | 144 | bool force_tls = false; |
143 | 145 | ||
144 | if ( account->ConnectionType() == 2 ) { | 146 | if ( account->ConnectionType() == 2 ) { |
145 | ssl = true; | 147 | ssl = true; |
146 | } | 148 | } |
147 | if (account->ConnectionType()==1) { | 149 | if (account->ConnectionType()==1) { |
148 | force_tls = true; | 150 | force_tls = true; |
149 | } | 151 | } |
150 | 152 | ||
151 | if ( ssl ) { | 153 | if ( ssl ) { |
152 | odebug << "using ssl" << oendl; | 154 | odebug << "using ssl" << oendl; |
153 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 155 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
154 | } else { | 156 | } else { |
155 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 157 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
156 | } | 158 | } |
157 | 159 | ||
158 | if ( err != MAILIMAP_NO_ERROR && | 160 | if ( err != MAILIMAP_NO_ERROR && |
159 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 161 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
160 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 162 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
161 | QString failure = ""; | 163 | QString failure = ""; |
162 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 164 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
163 | failure="Connection refused"; | 165 | failure="Connection refused"; |
164 | } else { | 166 | } else { |
165 | failure="Unknown failure"; | 167 | failure="Unknown failure"; |
166 | } | 168 | } |
167 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 169 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
168 | mailimap_free( m_imap ); | 170 | mailimap_free( m_imap ); |
169 | m_imap = 0; | 171 | m_imap = 0; |
170 | return; | 172 | return; |
171 | } | 173 | } |
172 | 174 | ||
173 | if (!ssl) { | 175 | if (!ssl) { |
174 | try_tls = start_tls(force_tls); | 176 | try_tls = start_tls(force_tls); |
175 | } | 177 | } |
176 | 178 | ||
177 | bool ok = true; | 179 | bool ok = true; |
178 | if (force_tls && !try_tls) { | 180 | if (force_tls && !try_tls) { |
179 | Global::statusMessage(tr("Server has no TLS support!")); | 181 | Global::statusMessage(tr("Server has no TLS support!")); |
180 | odebug << "Server has no TLS support!" << oendl; | 182 | odebug << "Server has no TLS support!" << oendl; |
181 | ok = false; | 183 | ok = false; |
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
185 | /* login */ | 187 | /* login */ |
186 | 188 | ||
187 | if (ok) { | 189 | if (ok) { |
188 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 190 | err = mailimap_login( m_imap, (char*)user, (char*)pass ); |
189 | if ( err != MAILIMAP_NO_ERROR ) { | 191 | if ( err != MAILIMAP_NO_ERROR ) { |
190 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 192 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
191 | ok = false; | 193 | ok = false; |
192 | } | 194 | } |
193 | } | 195 | } |
194 | if (!ok) { | 196 | if (!ok) { |
195 | err = mailimap_close( m_imap ); | 197 | err = mailimap_close( m_imap ); |
196 | mailimap_free( m_imap ); | 198 | mailimap_free( m_imap ); |
197 | m_imap = 0; | 199 | m_imap = 0; |
198 | } | 200 | } |
199 | } | 201 | } |
200 | 202 | ||
201 | void IMAPwrapper::logout() | 203 | void IMAPwrapper::logout() |
202 | { | 204 | { |
203 | int err = MAILIMAP_NO_ERROR; | 205 | int err = MAILIMAP_NO_ERROR; |
204 | if (!m_imap) return; | 206 | if (!m_imap) return; |
205 | err = mailimap_logout( m_imap ); | 207 | err = mailimap_logout( m_imap ); |
206 | err = mailimap_close( m_imap ); | 208 | err = mailimap_close( m_imap ); |
207 | mailimap_free( m_imap ); | 209 | mailimap_free( m_imap ); |
208 | m_imap = 0; | 210 | m_imap = 0; |
209 | m_Lastmbox = ""; | 211 | m_Lastmbox = ""; |
210 | } | 212 | } |
211 | 213 | ||
212 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 214 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) |
213 | { | 215 | { |
214 | int err = MAILIMAP_NO_ERROR; | 216 | int err = MAILIMAP_NO_ERROR; |
215 | clist *result = 0; | 217 | clist *result = 0; |
216 | clistcell *current; | 218 | clistcell *current; |
217 | mailimap_fetch_type *fetchType = 0; | 219 | mailimap_fetch_type *fetchType = 0; |
218 | mailimap_set *set = 0; | 220 | mailimap_set *set = 0; |
219 | 221 | ||
220 | login(); | 222 | login(); |
221 | if (!m_imap) { | 223 | if (!m_imap) { |
222 | return; | 224 | return; |
223 | } | 225 | } |
224 | /* select mailbox READONLY for operations */ | 226 | /* select mailbox READONLY for operations */ |
225 | err = selectMbox(mailbox); | 227 | err = selectMbox(mailbox); |
226 | if ( err != MAILIMAP_NO_ERROR ) { | 228 | if ( err != MAILIMAP_NO_ERROR ) { |
227 | return; | 229 | return; |
228 | } | 230 | } |
229 | 231 | ||
230 | int last = m_imap->imap_selection_info->sel_exists; | 232 | int last = m_imap->imap_selection_info->sel_exists; |
231 | 233 | ||
232 | if (last == 0) { | 234 | if (last == 0) { |
233 | Global::statusMessage(tr("Mailbox has no mails")); | 235 | Global::statusMessage(tr("Mailbox has no mails")); |
234 | return; | 236 | return; |
235 | } else { | 237 | } else { |
236 | } | 238 | } |
237 | 239 | ||
238 | /* the range has to start at 1!!! not with 0!!!! */ | 240 | /* the range has to start at 1!!! not with 0!!!! */ |
239 | set = mailimap_set_new_interval( 1, last ); | 241 | set = mailimap_set_new_interval( 1, last ); |
240 | 242 | ||
241 | 243 | ||
242 | fetchType = mailimap_fetch_type_new_all(); | 244 | fetchType = mailimap_fetch_type_new_all(); |
243 | /* | 245 | /* |
244 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 246 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
245 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 247 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
246 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 248 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
247 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 249 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
248 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 250 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
249 | */ | 251 | */ |
250 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 252 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
251 | mailimap_set_free( set ); | 253 | mailimap_set_free( set ); |
252 | mailimap_fetch_type_free( fetchType ); | 254 | mailimap_fetch_type_free( fetchType ); |
253 | 255 | ||
254 | QString date,subject,from; | 256 | QString date,subject,from; |
255 | 257 | ||
256 | if ( err == MAILIMAP_NO_ERROR ) { | 258 | if ( err == MAILIMAP_NO_ERROR ) { |
257 | mailimap_msg_att * msg_att; | 259 | mailimap_msg_att * msg_att; |
258 | int i = 0; | 260 | int i = 0; |
259 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 261 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
260 | ++i; | 262 | ++i; |
261 | msg_att = (mailimap_msg_att*)current->data; | 263 | msg_att = (mailimap_msg_att*)current->data; |
262 | RecMail*m = parse_list_result(msg_att); | 264 | RecMail*m = parse_list_result(msg_att); |
263 | if (m) { | 265 | if (m) { |
264 | m->setNumber(i); | 266 | m->setNumber(i); |
265 | m->setMbox(mailbox); | 267 | m->setMbox(mailbox); |
266 | m->setWrapper(this); | 268 | m->setWrapper(this); |
267 | target.append(m); | 269 | target.append(m); |
268 | } | 270 | } |
269 | } | 271 | } |
270 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 272 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
271 | } else { | 273 | } else { |
272 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 274 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
273 | } | 275 | } |
274 | if (result) mailimap_fetch_list_free(result); | 276 | if (result) mailimap_fetch_list_free(result); |
275 | } | 277 | } |
276 | 278 | ||
277 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 279 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
278 | { | 280 | { |
279 | const char *path, *mask; | 281 | const char *path, *mask; |
280 | int err = MAILIMAP_NO_ERROR; | 282 | int err = MAILIMAP_NO_ERROR; |
281 | clist *result = 0; | 283 | clist *result = 0; |
282 | clistcell *current = 0; | 284 | clistcell *current = 0; |
283 | clistcell*cur_flag = 0; | 285 | clistcell*cur_flag = 0; |
284 | mailimap_mbx_list_flags*bflags = 0; | 286 | mailimap_mbx_list_flags*bflags = 0; |
285 | 287 | ||
286 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 288 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
287 | login(); | 289 | login(); |
288 | if (!m_imap) { | 290 | if (!m_imap) { |
289 | return folders; | 291 | return folders; |
290 | } | 292 | } |
291 | 293 | ||
292 | /* | 294 | /* |
293 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 295 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
294 | * We must not forget to filter them out in next loop! | 296 | * We must not forget to filter them out in next loop! |
295 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 297 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
296 | */ | 298 | */ |
297 | QString temp; | 299 | QString temp; |
298 | mask = "INBOX" ; | 300 | mask = "INBOX" ; |
299 | mailimap_mailbox_list *list; | 301 | mailimap_mailbox_list *list; |
300 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 302 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
301 | QString del; | 303 | QString del; |
302 | bool selectable = true; | 304 | bool selectable = true; |
303 | bool no_inferiors = false; | 305 | bool no_inferiors = false; |
304 | if ( err == MAILIMAP_NO_ERROR ) { | 306 | if ( err == MAILIMAP_NO_ERROR ) { |
305 | current = result->first; | 307 | current = result->first; |
306 | for ( int i = result->count; i > 0; i-- ) { | 308 | for ( int i = result->count; i > 0; i-- ) { |
307 | list = (mailimap_mailbox_list *) current->data; | 309 | list = (mailimap_mailbox_list *) current->data; |
308 | // it is better use the deep copy mechanism of qt itself | 310 | // it is better use the deep copy mechanism of qt itself |
309 | // instead of using strdup! | 311 | // instead of using strdup! |
310 | temp = list->mb_name; | 312 | temp = list->mb_name; |
311 | del = list->mb_delimiter; | 313 | del = list->mb_delimiter; |
312 | current = current->next; | 314 | current = current->next; |
313 | if ( (bflags = list->mb_flag) ) { | 315 | if ( (bflags = list->mb_flag) ) { |
314 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 316 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
315 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 317 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
316 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 318 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
317 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 319 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
318 | no_inferiors = true; | 320 | no_inferiors = true; |
319 | } | 321 | } |
320 | } | 322 | } |
321 | } | 323 | } |
322 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 324 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
323 | } | 325 | } |
324 | } else { | 326 | } else { |
325 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; | 327 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; |
326 | } | 328 | } |
327 | mailimap_list_result_free( result ); | 329 | mailimap_list_result_free( result ); |
328 | 330 | ||
329 | /* | 331 | /* |
330 | * second stage - get the other then inbox folders | 332 | * second stage - get the other then inbox folders |
331 | */ | 333 | */ |
332 | mask = "*" ; | 334 | mask = "*" ; |
333 | path = account->getPrefix().latin1(); | 335 | path = account->getPrefix().latin1(); |
334 | if (!path) path = ""; | 336 | if (!path) path = ""; |
335 | odebug << path << oendl; | 337 | odebug << path << oendl; |
336 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 338 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
337 | if ( err == MAILIMAP_NO_ERROR ) { | 339 | if ( err == MAILIMAP_NO_ERROR ) { |
338 | current = result->first; | 340 | current = result->first; |
339 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 341 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
340 | no_inferiors = false; | 342 | no_inferiors = false; |
341 | list = (mailimap_mailbox_list *) current->data; | 343 | list = (mailimap_mailbox_list *) current->data; |
342 | // it is better use the deep copy mechanism of qt itself | 344 | // it is better use the deep copy mechanism of qt itself |
343 | // instead of using strdup! | 345 | // instead of using strdup! |
344 | temp = list->mb_name; | 346 | temp = list->mb_name; |
345 | if (temp.lower()=="inbox") | 347 | if (temp.lower()=="inbox") |
346 | continue; | 348 | continue; |
347 | if (temp.lower()==account->getPrefix().lower()) | 349 | if (temp.lower()==account->getPrefix().lower()) |
348 | continue; | 350 | continue; |
349 | if ( (bflags = list->mb_flag) ) { | 351 | if ( (bflags = list->mb_flag) ) { |
350 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 352 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
351 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 353 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
352 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 354 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
353 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 355 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
354 | no_inferiors = true; | 356 | no_inferiors = true; |
355 | } | 357 | } |
356 | } | 358 | } |
357 | } | 359 | } |
358 | del = list->mb_delimiter; | 360 | del = list->mb_delimiter; |
359 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 361 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
360 | } | 362 | } |
361 | } else { | 363 | } else { |
362 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; | 364 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; |
363 | } | 365 | } |
364 | if (result) mailimap_list_result_free( result ); | 366 | if (result) mailimap_list_result_free( result ); |
365 | return folders; | 367 | return folders; |
366 | } | 368 | } |
367 | 369 | ||
368 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 370 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
369 | { | 371 | { |
370 | RecMail * m = 0; | 372 | RecMail * m = 0; |
371 | mailimap_msg_att_item *item=0; | 373 | mailimap_msg_att_item *item=0; |
372 | clistcell *current,*c,*cf; | 374 | clistcell *current,*c,*cf; |
373 | mailimap_msg_att_dynamic*flist; | 375 | mailimap_msg_att_dynamic*flist; |
374 | mailimap_flag_fetch*cflag; | 376 | mailimap_flag_fetch*cflag; |
375 | int size,toffset; | 377 | int size,toffset; |
376 | QBitArray mFlags(7); | 378 | QBitArray mFlags(7); |
377 | QStringList addresslist; | 379 | QStringList addresslist; |
378 | 380 | ||
379 | if (!m_att) { | 381 | if (!m_att) { |
380 | return m; | 382 | return m; |
381 | } | 383 | } |
382 | size = 0; | 384 | size = 0; |
383 | m = new RecMail(); | 385 | m = new RecMail(); |
384 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 386 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
385 | current = c; | 387 | current = c; |
386 | item = (mailimap_msg_att_item*)current->data; | 388 | item = (mailimap_msg_att_item*)current->data; |
387 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 389 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
388 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 390 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
389 | if (!flist->att_list) { | 391 | if (!flist->att_list) { |
390 | continue; | 392 | continue; |
391 | } | 393 | } |
392 | cf = flist->att_list->first; | 394 | cf = flist->att_list->first; |
393 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 395 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
394 | cflag = (mailimap_flag_fetch*)cf->data; | 396 | cflag = (mailimap_flag_fetch*)cf->data; |
395 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 397 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
396 | switch (cflag->fl_flag->fl_type) { | 398 | switch (cflag->fl_flag->fl_type) { |
397 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 399 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
398 | mFlags.setBit(FLAG_ANSWERED); | 400 | mFlags.setBit(FLAG_ANSWERED); |
399 | break; | 401 | break; |
400 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 402 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
401 | mFlags.setBit(FLAG_FLAGGED); | 403 | mFlags.setBit(FLAG_FLAGGED); |
402 | break; | 404 | break; |
403 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 405 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
404 | mFlags.setBit(FLAG_DELETED); | 406 | mFlags.setBit(FLAG_DELETED); |
405 | break; | 407 | break; |
406 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 408 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
407 | mFlags.setBit(FLAG_SEEN); | 409 | mFlags.setBit(FLAG_SEEN); |
408 | break; | 410 | break; |
409 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 411 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
410 | mFlags.setBit(FLAG_DRAFT); | 412 | mFlags.setBit(FLAG_DRAFT); |
411 | break; | 413 | break; |
412 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 414 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
413 | break; | 415 | break; |
414 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 416 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
415 | break; | 417 | break; |
416 | default: | 418 | default: |
417 | break; | 419 | break; |
418 | } | 420 | } |
419 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 421 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
420 | mFlags.setBit(FLAG_RECENT); | 422 | mFlags.setBit(FLAG_RECENT); |
421 | } | 423 | } |
422 | } | 424 | } |
423 | continue; | 425 | continue; |
424 | } | 426 | } |
425 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 427 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
426 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 428 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
427 | QDateTime d = parseDateTime(head->env_date,toffset); | 429 | QDateTime d = parseDateTime(head->env_date,toffset); |
428 | m->setDate(d,toffset); | 430 | m->setDate(d,toffset); |
429 | m->setSubject(convert_String((const char*)head->env_subject)); | 431 | m->setSubject(convert_String((const char*)head->env_subject)); |
430 | if (head->env_from!=NULL) { | 432 | if (head->env_from!=NULL) { |
431 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 433 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
432 | if (addresslist.count()) { | 434 | if (addresslist.count()) { |
433 | m->setFrom(addresslist.first()); | 435 | m->setFrom(addresslist.first()); |
434 | } | 436 | } |
435 | } | 437 | } |
436 | if (head->env_to!=NULL) { | 438 | if (head->env_to!=NULL) { |
437 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 439 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
438 | m->setTo(addresslist); | 440 | m->setTo(addresslist); |
439 | } | 441 | } |
440 | if (head->env_cc!=NULL) { | 442 | if (head->env_cc!=NULL) { |
441 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 443 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
442 | m->setCC(addresslist); | 444 | m->setCC(addresslist); |
443 | } | 445 | } |
444 | if (head->env_bcc!=NULL) { | 446 | if (head->env_bcc!=NULL) { |
445 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 447 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
446 | m->setBcc(addresslist); | 448 | m->setBcc(addresslist); |
447 | } | 449 | } |
448 | /* reply to address, eg. email. */ | 450 | /* reply to address, eg. email. */ |
449 | if (head->env_reply_to!=NULL) { | 451 | if (head->env_reply_to!=NULL) { |
450 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 452 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
451 | if (addresslist.count()) { | 453 | if (addresslist.count()) { |
452 | m->setReplyto(addresslist.first()); | 454 | m->setReplyto(addresslist.first()); |
453 | } | 455 | } |
454 | } | 456 | } |
455 | if (head->env_in_reply_to!=NULL) { | 457 | if (head->env_in_reply_to!=NULL) { |
456 | QString h(head->env_in_reply_to); | 458 | QString h(head->env_in_reply_to); |
457 | while (h.length()>0 && h[0]=='<') { | 459 | while (h.length()>0 && h[0]=='<') { |
458 | h.remove(0,1); | 460 | h.remove(0,1); |
459 | } | 461 | } |
460 | while (h.length()>0 && h[h.length()-1]=='>') { | 462 | while (h.length()>0 && h[h.length()-1]=='>') { |
461 | h.remove(h.length()-1,1); | 463 | h.remove(h.length()-1,1); |
462 | } | 464 | } |
463 | if (h.length()>0) { | 465 | if (h.length()>0) { |
464 | m->setInreply(QStringList(h)); | 466 | m->setInreply(QStringList(h)); |
465 | } | 467 | } |
466 | } | 468 | } |
467 | if (head->env_message_id) { | 469 | if (head->env_message_id) { |
468 | m->setMsgid(QString(head->env_message_id)); | 470 | m->setMsgid(QString(head->env_message_id)); |
469 | } | 471 | } |
470 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 472 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
471 | // not used this moment | 473 | // not used this moment |
472 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 474 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
473 | //size = item->att_data.att_static->att_data.att_rfc822_size; | 475 | //size = item->att_data.att_static->att_data.att_rfc822_size; |
474 | m->setMsgsize(item->att_data.att_static->att_data.att_rfc822_size); | 476 | m->setMsgsize(item->att_data.att_static->att_data.att_rfc822_size); |
475 | } | 477 | } |
476 | } | 478 | } |
477 | /* msg is already deleted */ | 479 | /* msg is already deleted */ |
478 | if (mFlags.testBit(FLAG_DELETED) && m) { | 480 | if (mFlags.testBit(FLAG_DELETED) && m) { |
479 | delete m; | 481 | delete m; |
480 | m = 0; | 482 | m = 0; |
481 | } | 483 | } |
482 | if (m) { | 484 | if (m) { |
483 | m->setFlags(mFlags); | 485 | m->setFlags(mFlags); |
484 | } | 486 | } |
485 | return m; | 487 | return m; |
486 | } | 488 | } |
487 | 489 | ||
488 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 490 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
489 | { | 491 | { |
490 | RecBodyP body = new RecBody(); | 492 | RecBodyP body = new RecBody(); |
491 | const char *mb; | 493 | const char *mb; |
492 | int err = MAILIMAP_NO_ERROR; | 494 | int err = MAILIMAP_NO_ERROR; |
493 | clist *result = 0; | 495 | clist *result = 0; |
494 | clistcell *current; | 496 | clistcell *current; |
495 | mailimap_fetch_att *fetchAtt = 0; | 497 | mailimap_fetch_att *fetchAtt = 0; |
496 | mailimap_fetch_type *fetchType = 0; | 498 | mailimap_fetch_type *fetchType = 0; |
497 | mailimap_set *set = 0; | 499 | mailimap_set *set = 0; |
498 | mailimap_body*body_desc = 0; | 500 | mailimap_body*body_desc = 0; |
499 | 501 | ||
500 | mb = mail->getMbox().latin1(); | 502 | mb = mail->getMbox().latin1(); |
501 | 503 | ||
502 | login(); | 504 | login(); |
503 | if (!m_imap) { | 505 | if (!m_imap) { |
504 | return body; | 506 | return body; |
505 | } | 507 | } |
506 | err = selectMbox(mail->getMbox()); | 508 | err = selectMbox(mail->getMbox()); |
507 | if ( err != MAILIMAP_NO_ERROR ) { | 509 | if ( err != MAILIMAP_NO_ERROR ) { |
508 | return body; | 510 | return body; |
509 | } | 511 | } |
510 | 512 | ||
511 | /* the range has to start at 1!!! not with 0!!!! */ | 513 | /* the range has to start at 1!!! not with 0!!!! */ |
512 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 514 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
513 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 515 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
514 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 516 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
515 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 517 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
516 | mailimap_set_free( set ); | 518 | mailimap_set_free( set ); |
517 | mailimap_fetch_type_free( fetchType ); | 519 | mailimap_fetch_type_free( fetchType ); |
518 | 520 | ||
519 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 521 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
520 | mailimap_msg_att * msg_att; | 522 | mailimap_msg_att * msg_att; |
521 | msg_att = (mailimap_msg_att*)current->data; | 523 | msg_att = (mailimap_msg_att*)current->data; |
522 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 524 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
523 | QValueList<int> path; | 525 | QValueList<int> path; |
524 | body_desc = item->att_data.att_static->att_data.att_body; | 526 | body_desc = item->att_data.att_static->att_data.att_body; |
525 | traverseBody(mail,body_desc,body,0,path); | 527 | traverseBody(mail,body_desc,body,0,path); |
526 | } else { | 528 | } else { |
527 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; | 529 | odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; |
528 | } | 530 | } |
529 | if (result) mailimap_fetch_list_free(result); | 531 | if (result) mailimap_fetch_list_free(result); |
530 | return body; | 532 | return body; |
531 | } | 533 | } |
532 | 534 | ||
533 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 535 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
534 | { | 536 | { |
535 | QStringList l; | 537 | QStringList l; |
536 | QString from; | 538 | QString from; |
537 | bool named_from; | 539 | bool named_from; |
538 | clistcell *current = NULL; | 540 | clistcell *current = NULL; |
539 | mailimap_address * current_address=NULL; | 541 | mailimap_address * current_address=NULL; |
540 | if (!list) { | 542 | if (!list) { |
541 | return l; | 543 | return l; |
542 | } | 544 | } |
543 | unsigned int count = 0; | 545 | unsigned int count = 0; |
544 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 546 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
545 | from = ""; | 547 | from = ""; |
546 | named_from = false; | 548 | named_from = false; |
547 | current_address=(mailimap_address*)current->data; | 549 | current_address=(mailimap_address*)current->data; |
548 | if (current_address->ad_personal_name){ | 550 | if (current_address->ad_personal_name){ |
549 | from+=convert_String((const char*)current_address->ad_personal_name); | 551 | from+=convert_String((const char*)current_address->ad_personal_name); |
550 | from+=" "; | 552 | from+=" "; |
551 | named_from = true; | 553 | named_from = true; |
552 | } | 554 | } |
553 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 555 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
554 | from+="<"; | 556 | from+="<"; |
555 | } | 557 | } |
556 | if (current_address->ad_mailbox_name) { | 558 | if (current_address->ad_mailbox_name) { |
557 | from+=QString(current_address->ad_mailbox_name); | 559 | from+=QString(current_address->ad_mailbox_name); |
558 | from+="@"; | 560 | from+="@"; |
559 | } | 561 | } |
560 | if (current_address->ad_host_name) { | 562 | if (current_address->ad_host_name) { |
561 | from+=QString(current_address->ad_host_name); | 563 | from+=QString(current_address->ad_host_name); |
562 | } | 564 | } |
563 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 565 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
564 | from+=">"; | 566 | from+=">"; |
565 | } | 567 | } |
566 | l.append(QString(from)); | 568 | l.append(QString(from)); |
567 | if (++count > 99) { | 569 | if (++count > 99) { |
568 | break; | 570 | break; |
569 | } | 571 | } |
570 | } | 572 | } |
571 | return l; | 573 | return l; |
572 | } | 574 | } |
573 | 575 | ||
574 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 576 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
575 | { | 577 | { |
576 | encodedString*res=new encodedString; | 578 | encodedString*res=new encodedString; |
577 | int err; | 579 | int err; |
578 | mailimap_fetch_type *fetchType; | 580 | mailimap_fetch_type *fetchType; |
579 | mailimap_set *set; | 581 | mailimap_set *set; |
580 | clistcell*current,*cur; | 582 | clistcell*current,*cur; |
581 | mailimap_section_part * section_part = 0; | 583 | mailimap_section_part * section_part = 0; |
582 | mailimap_section_spec * section_spec = 0; | 584 | mailimap_section_spec * section_spec = 0; |
583 | mailimap_section * section = 0; | 585 | mailimap_section * section = 0; |
584 | mailimap_fetch_att * fetch_att = 0; | 586 | mailimap_fetch_att * fetch_att = 0; |
585 | 587 | ||
586 | login(); | 588 | login(); |
587 | if (!m_imap) { | 589 | if (!m_imap) { |
588 | return res; | 590 | return res; |
589 | } | 591 | } |
590 | if (!internal_call) { | 592 | if (!internal_call) { |
591 | err = selectMbox(mail->getMbox()); | 593 | err = selectMbox(mail->getMbox()); |
592 | if ( err != MAILIMAP_NO_ERROR ) { | 594 | if ( err != MAILIMAP_NO_ERROR ) { |
593 | return res; | 595 | return res; |
594 | } | 596 | } |
595 | } | 597 | } |
596 | set = mailimap_set_new_single(mail->getNumber()); | 598 | set = mailimap_set_new_single(mail->getNumber()); |
597 | 599 | ||
598 | clist*id_list = 0; | 600 | clist*id_list = 0; |
599 | 601 | ||
600 | /* if path == empty then its a request for the whole rfc822 mail and generates | 602 | /* if path == empty then its a request for the whole rfc822 mail and generates |
601 | a "fetch <id> (body[])" statement on imap server */ | 603 | a "fetch <id> (body[])" statement on imap server */ |
602 | if (path.count()>0 ) { | 604 | if (path.count()>0 ) { |
603 | id_list = clist_new(); | 605 | id_list = clist_new(); |
604 | for (unsigned j=0; j < path.count();++j) { | 606 | for (unsigned j=0; j < path.count();++j) { |
605 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 607 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
606 | *p_id = path[j]; | 608 | *p_id = path[j]; |
607 | clist_append(id_list,p_id); | 609 | clist_append(id_list,p_id); |
608 | } | 610 | } |
609 | section_part = mailimap_section_part_new(id_list); | 611 | section_part = mailimap_section_part_new(id_list); |
610 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 612 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
611 | } | 613 | } |
612 | 614 | ||
613 | section = mailimap_section_new(section_spec); | 615 | section = mailimap_section_new(section_spec); |
614 | fetch_att = mailimap_fetch_att_new_body_section(section); | 616 | fetch_att = mailimap_fetch_att_new_body_section(section); |
615 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 617 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
616 | 618 | ||
617 | clist*result = 0; | 619 | clist*result = 0; |
618 | 620 | ||
619 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 621 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
620 | mailimap_set_free( set ); | 622 | mailimap_set_free( set ); |
621 | mailimap_fetch_type_free( fetchType ); | 623 | mailimap_fetch_type_free( fetchType ); |
622 | 624 | ||
623 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 625 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
624 | mailimap_msg_att * msg_att; | 626 | mailimap_msg_att * msg_att; |
625 | msg_att = (mailimap_msg_att*)current->data; | 627 | msg_att = (mailimap_msg_att*)current->data; |
626 | mailimap_msg_att_item*msg_att_item; | 628 | mailimap_msg_att_item*msg_att_item; |
627 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 629 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
628 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 630 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
629 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 631 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
630 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 632 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
631 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 633 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
632 | /* detach - we take over the content */ | 634 | /* detach - we take over the content */ |
633 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 635 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
634 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 636 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
635 | } | 637 | } |
636 | } | 638 | } |
637 | } | 639 | } |
638 | } else { | 640 | } else { |
639 | odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 641 | odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
640 | } | 642 | } |
641 | if (result) mailimap_fetch_list_free(result); | 643 | if (result) mailimap_fetch_list_free(result); |
642 | return res; | 644 | return res; |
643 | } | 645 | } |
644 | 646 | ||
645 | /* current_recursion is for recursive calls. | 647 | /* current_recursion is for recursive calls. |
646 | current_count means the position inside the internal loop! */ | 648 | current_count means the position inside the internal loop! */ |
647 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 649 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
648 | int current_recursion,QValueList<int>recList,int current_count) | 650 | int current_recursion,QValueList<int>recList,int current_count) |
649 | { | 651 | { |
650 | if (!body || current_recursion>=10) { | 652 | if (!body || current_recursion>=10) { |
651 | return; | 653 | return; |
652 | } | 654 | } |
653 | switch (body->bd_type) { | 655 | switch (body->bd_type) { |
654 | case MAILIMAP_BODY_1PART: | 656 | case MAILIMAP_BODY_1PART: |
655 | { | 657 | { |
656 | QValueList<int>countlist = recList; | 658 | QValueList<int>countlist = recList; |
657 | countlist.append(current_count); | 659 | countlist.append(current_count); |
658 | RecPartP currentPart = new RecPart(); | 660 | RecPartP currentPart = new RecPart(); |
659 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 661 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
660 | QString id(""); | 662 | QString id(""); |
661 | currentPart->setPositionlist(countlist); | 663 | currentPart->setPositionlist(countlist); |
662 | for (unsigned int j = 0; j < countlist.count();++j) { | 664 | for (unsigned int j = 0; j < countlist.count();++j) { |
663 | id+=(j>0?" ":""); | 665 | id+=(j>0?" ":""); |
664 | id+=QString("%1").arg(countlist[j]); | 666 | id+=QString("%1").arg(countlist[j]); |
665 | } | 667 | } |
666 | odebug << "ID = " << id.latin1() << "" << oendl; | 668 | odebug << "ID = " << id.latin1() << "" << oendl; |
667 | currentPart->setIdentifier(id); | 669 | currentPart->setIdentifier(id); |
668 | fillSinglePart(currentPart,part1); | 670 | fillSinglePart(currentPart,part1); |
669 | /* important: Check for is NULL 'cause a body can be empty! | 671 | /* important: Check for is NULL 'cause a body can be empty! |
670 | And we put it only into the mail if it is the FIRST part */ | 672 | And we put it only into the mail if it is the FIRST part */ |
671 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 673 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
672 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 674 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
673 | target_body->setDescription(currentPart); | 675 | target_body->setDescription(currentPart); |
674 | target_body->setBodytext(body_text); | 676 | target_body->setBodytext(body_text); |
675 | if (countlist.count()>1) { | 677 | if (countlist.count()>1) { |
676 | target_body->addPart(currentPart); | 678 | target_body->addPart(currentPart); |
677 | } | 679 | } |
678 | } else { | 680 | } else { |
679 | target_body->addPart(currentPart); | 681 | target_body->addPart(currentPart); |
680 | } | 682 | } |
681 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 683 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
682 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 684 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
683 | } | 685 | } |
684 | } | 686 | } |
685 | break; | 687 | break; |
686 | case MAILIMAP_BODY_MPART: | 688 | case MAILIMAP_BODY_MPART: |
687 | { | 689 | { |
688 | QValueList<int>countlist = recList; | 690 | QValueList<int>countlist = recList; |
689 | clistcell*current=0; | 691 | clistcell*current=0; |
690 | mailimap_body*current_body=0; | 692 | mailimap_body*current_body=0; |
691 | unsigned int ccount = 1; | 693 | unsigned int ccount = 1; |
692 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 694 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
693 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 695 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
694 | current_body = (mailimap_body*)current->data; | 696 | current_body = (mailimap_body*)current->data; |
695 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 697 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
696 | RecPartP targetPart = new RecPart(); | 698 | RecPartP targetPart = new RecPart(); |
697 | targetPart->setType("multipart"); | 699 | targetPart->setType("multipart"); |
698 | fillMultiPart(targetPart,mailDescription); | 700 | fillMultiPart(targetPart,mailDescription); |
699 | countlist.append(current_count); | 701 | countlist.append(current_count); |
700 | targetPart->setPositionlist(countlist); | 702 | targetPart->setPositionlist(countlist); |
701 | target_body->addPart(targetPart); | 703 | target_body->addPart(targetPart); |
702 | QString id(""); | 704 | QString id(""); |
703 | for (unsigned int j = 0; j < countlist.count();++j) { | 705 | for (unsigned int j = 0; j < countlist.count();++j) { |
704 | id+=(j>0?" ":""); | 706 | id+=(j>0?" ":""); |
705 | id+=QString("%1").arg(countlist[j]); | 707 | id+=QString("%1").arg(countlist[j]); |
706 | } | 708 | } |
707 | odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 709 | odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
708 | } | 710 | } |
709 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 711 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
710 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 712 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
711 | countlist = recList; | 713 | countlist = recList; |
712 | } | 714 | } |
713 | ++ccount; | 715 | ++ccount; |
714 | } | 716 | } |
715 | } | 717 | } |
716 | break; | 718 | break; |
717 | default: | 719 | default: |
718 | break; | 720 | break; |
719 | } | 721 | } |
720 | } | 722 | } |
721 | 723 | ||
722 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) | 724 | void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) |
723 | { | 725 | { |
724 | if (!Description) { | 726 | if (!Description) { |
725 | return; | 727 | return; |
726 | } | 728 | } |
727 | switch (Description->bd_type) { | 729 | switch (Description->bd_type) { |
728 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 730 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
729 | target_part->setType("text"); | 731 | target_part->setType("text"); |
730 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 732 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
731 | break; | 733 | break; |
732 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 734 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
733 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 735 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
734 | break; | 736 | break; |
735 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 737 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
736 | target_part->setType("message"); | 738 | target_part->setType("message"); |
737 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 739 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
738 | break; | 740 | break; |
739 | default: | 741 | default: |
740 | break; | 742 | break; |
741 | } | 743 | } |
742 | } | 744 | } |
743 | 745 | ||
744 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) | 746 | void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) |
745 | { | 747 | { |
746 | if (!which) { | 748 | if (!which) { |
747 | return; | 749 | return; |
748 | } | 750 | } |
749 | QString sub; | 751 | QString sub; |
750 | sub = which->bd_media_text; | 752 | sub = which->bd_media_text; |
751 | odebug << "Type= text/" << which->bd_media_text << "" << oendl; | 753 | odebug << "Type= text/" << which->bd_media_text << "" << oendl; |
752 | target_part->setSubtype(sub.lower()); | 754 | target_part->setSubtype(sub.lower()); |
753 | target_part->setLines(which->bd_lines); | 755 | target_part->setLines(which->bd_lines); |
754 | fillBodyFields(target_part,which->bd_fields); | 756 | fillBodyFields(target_part,which->bd_fields); |
755 | } | 757 | } |
756 | 758 | ||
757 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) | 759 | void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) |
758 | { | 760 | { |
759 | if (!which) { | 761 | if (!which) { |
760 | return; | 762 | return; |
761 | } | 763 | } |
762 | target_part->setSubtype("rfc822"); | 764 | target_part->setSubtype("rfc822"); |
763 | odebug << "Message part" << oendl; | 765 | odebug << "Message part" << oendl; |
764 | /* we set this type to text/plain */ | 766 | /* we set this type to text/plain */ |
765 | target_part->setLines(which->bd_lines); | 767 | target_part->setLines(which->bd_lines); |
766 | fillBodyFields(target_part,which->bd_fields); | 768 | fillBodyFields(target_part,which->bd_fields); |
767 | } | 769 | } |
768 | 770 | ||
769 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) | 771 | void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) |
770 | { | 772 | { |
771 | if (!which) return; | 773 | if (!which) return; |
772 | QString sub = which->bd_media_subtype; | 774 | QString sub = which->bd_media_subtype; |
773 | target_part->setSubtype(sub.lower()); | 775 | target_part->setSubtype(sub.lower()); |
774 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 776 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
775 | clistcell*cur = 0; | 777 | clistcell*cur = 0; |
776 | mailimap_single_body_fld_param*param=0; | 778 | mailimap_single_body_fld_param*param=0; |
777 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 779 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
778 | param = (mailimap_single_body_fld_param*)cur->data; | 780 | param = (mailimap_single_body_fld_param*)cur->data; |
779 | if (param) { | 781 | if (param) { |
780 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 782 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
781 | } | 783 | } |
782 | } | 784 | } |
783 | } | 785 | } |
784 | } | 786 | } |
785 | 787 | ||
786 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) | 788 | void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) |
787 | { | 789 | { |
788 | if (!which) { | 790 | if (!which) { |
789 | return; | 791 | return; |
790 | } | 792 | } |
791 | QString type,sub; | 793 | QString type,sub; |
792 | switch (which->bd_media_basic->med_type) { | 794 | switch (which->bd_media_basic->med_type) { |
793 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 795 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
794 | type = "application"; | 796 | type = "application"; |
795 | break; | 797 | break; |
796 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 798 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
797 | type = "audio"; | 799 | type = "audio"; |
798 | break; | 800 | break; |
799 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 801 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
800 | type = "image"; | 802 | type = "image"; |
801 | break; | 803 | break; |
802 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 804 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
803 | type = "message"; | 805 | type = "message"; |
804 | break; | 806 | break; |
805 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 807 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
806 | type = "video"; | 808 | type = "video"; |
807 | break; | 809 | break; |
808 | case MAILIMAP_MEDIA_BASIC_OTHER: | 810 | case MAILIMAP_MEDIA_BASIC_OTHER: |
809 | default: | 811 | default: |
810 | if (which->bd_media_basic->med_basic_type) { | 812 | if (which->bd_media_basic->med_basic_type) { |
811 | type = which->bd_media_basic->med_basic_type; | 813 | type = which->bd_media_basic->med_basic_type; |
812 | } else { | 814 | } else { |
813 | type = ""; | 815 | type = ""; |
814 | } | 816 | } |
815 | break; | 817 | break; |
816 | } | 818 | } |
817 | if (which->bd_media_basic->med_subtype) { | 819 | if (which->bd_media_basic->med_subtype) { |
818 | sub = which->bd_media_basic->med_subtype; | 820 | sub = which->bd_media_basic->med_subtype; |
819 | } else { | 821 | } else { |
820 | sub = ""; | 822 | sub = ""; |
821 | } | 823 | } |
822 | odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; | 824 | odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; |
823 | target_part->setType(type.lower()); | 825 | target_part->setType(type.lower()); |
824 | target_part->setSubtype(sub.lower()); | 826 | target_part->setSubtype(sub.lower()); |
825 | fillBodyFields(target_part,which->bd_fields); | 827 | fillBodyFields(target_part,which->bd_fields); |
826 | } | 828 | } |
827 | 829 | ||
828 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) | 830 | void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) |
829 | { | 831 | { |
830 | if (!which) return; | 832 | if (!which) return; |
831 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 833 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
832 | clistcell*cur; | 834 | clistcell*cur; |
833 | mailimap_single_body_fld_param*param=0; | 835 | mailimap_single_body_fld_param*param=0; |
834 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 836 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
835 | param = (mailimap_single_body_fld_param*)cur->data; | 837 | param = (mailimap_single_body_fld_param*)cur->data; |
836 | if (param) { | 838 | if (param) { |
837 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 839 | target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
838 | } | 840 | } |
839 | } | 841 | } |
840 | } | 842 | } |
841 | mailimap_body_fld_enc*enc = which->bd_encoding; | 843 | mailimap_body_fld_enc*enc = which->bd_encoding; |
842 | QString encoding(""); | 844 | QString encoding(""); |
843 | switch (enc->enc_type) { | 845 | switch (enc->enc_type) { |
844 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 846 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
845 | encoding = "7bit"; | 847 | encoding = "7bit"; |
846 | break; | 848 | break; |
847 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 849 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
848 | encoding = "8bit"; | 850 | encoding = "8bit"; |
849 | break; | 851 | break; |
850 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 852 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
851 | encoding="binary"; | 853 | encoding="binary"; |
852 | break; | 854 | break; |
853 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 855 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
854 | encoding="base64"; | 856 | encoding="base64"; |
855 | break; | 857 | break; |
856 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 858 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
857 | encoding="quoted-printable"; | 859 | encoding="quoted-printable"; |
858 | break; | 860 | break; |
859 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 861 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
860 | default: | 862 | default: |
861 | if (enc->enc_value) { | 863 | if (enc->enc_value) { |
862 | char*t=enc->enc_value; | 864 | char*t=enc->enc_value; |
863 | encoding=QString(enc->enc_value); | 865 | encoding=QString(enc->enc_value); |
864 | enc->enc_value=0L; | 866 | enc->enc_value=0L; |
865 | free(t); | 867 | free(t); |
866 | } | 868 | } |
867 | } | 869 | } |
868 | if (which->bd_description) { | 870 | if (which->bd_description) { |
869 | target_part->setDescription(QString(which->bd_description)); | 871 | target_part->setDescription(QString(which->bd_description)); |
870 | } | 872 | } |
871 | target_part->setEncoding(encoding); | 873 | target_part->setEncoding(encoding); |
872 | target_part->setSize(which->bd_size); | 874 | target_part->setSize(which->bd_size); |
873 | } | 875 | } |
874 | 876 | ||
875 | void IMAPwrapper::deleteMail(const RecMailP&mail) | 877 | void IMAPwrapper::deleteMail(const RecMailP&mail) |
876 | { | 878 | { |
877 | mailimap_flag_list*flist; | 879 | mailimap_flag_list*flist; |
878 | mailimap_set *set; | 880 | mailimap_set *set; |
879 | mailimap_store_att_flags * store_flags; | 881 | mailimap_store_att_flags * store_flags; |
880 | int err; | 882 | int err; |
881 | login(); | 883 | login(); |
882 | if (!m_imap) { | 884 | if (!m_imap) { |
883 | return; | 885 | return; |
884 | } | 886 | } |
885 | err = selectMbox(mail->getMbox()); | 887 | err = selectMbox(mail->getMbox()); |
886 | if ( err != MAILIMAP_NO_ERROR ) { | 888 | if ( err != MAILIMAP_NO_ERROR ) { |
887 | return; | 889 | return; |
888 | } | 890 | } |
889 | flist = mailimap_flag_list_new_empty(); | 891 | flist = mailimap_flag_list_new_empty(); |
890 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 892 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
891 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 893 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
892 | set = mailimap_set_new_single(mail->getNumber()); | 894 | set = mailimap_set_new_single(mail->getNumber()); |
893 | err = mailimap_store(m_imap,set,store_flags); | 895 | err = mailimap_store(m_imap,set,store_flags); |
894 | mailimap_set_free( set ); | 896 | mailimap_set_free( set ); |
895 | mailimap_store_att_flags_free(store_flags); | 897 | mailimap_store_att_flags_free(store_flags); |
896 | 898 | ||
897 | if (err != MAILIMAP_NO_ERROR) { | 899 | if (err != MAILIMAP_NO_ERROR) { |
898 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 900 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
899 | return; | 901 | return; |
900 | } | 902 | } |
901 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; | 903 | odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; |
902 | /* should we realy do that at this moment? */ | 904 | /* should we realy do that at this moment? */ |
903 | err = mailimap_expunge(m_imap); | 905 | err = mailimap_expunge(m_imap); |
904 | if (err != MAILIMAP_NO_ERROR) { | 906 | if (err != MAILIMAP_NO_ERROR) { |
905 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; | 907 | odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; |
906 | } | 908 | } |
907 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; | 909 | odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; |
908 | } | 910 | } |
909 | 911 | ||
910 | void IMAPwrapper::answeredMail(const RecMailP&mail) | 912 | void IMAPwrapper::answeredMail(const RecMailP&mail) |
911 | { | 913 | { |
912 | mailimap_flag_list*flist; | 914 | mailimap_flag_list*flist; |
913 | mailimap_set *set; | 915 | mailimap_set *set; |
914 | mailimap_store_att_flags * store_flags; | 916 | mailimap_store_att_flags * store_flags; |
915 | int err; | 917 | int err; |
916 | login(); | 918 | login(); |
917 | if (!m_imap) { | 919 | if (!m_imap) { |
918 | return; | 920 | return; |
919 | } | 921 | } |
920 | err = selectMbox(mail->getMbox()); | 922 | err = selectMbox(mail->getMbox()); |
921 | if ( err != MAILIMAP_NO_ERROR ) { | 923 | if ( err != MAILIMAP_NO_ERROR ) { |
922 | return; | 924 | return; |
923 | } | 925 | } |
924 | flist = mailimap_flag_list_new_empty(); | 926 | flist = mailimap_flag_list_new_empty(); |
925 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 927 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
926 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 928 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
927 | set = mailimap_set_new_single(mail->getNumber()); | 929 | set = mailimap_set_new_single(mail->getNumber()); |
928 | err = mailimap_store(m_imap,set,store_flags); | 930 | err = mailimap_store(m_imap,set,store_flags); |
929 | mailimap_set_free( set ); | 931 | mailimap_set_free( set ); |
930 | mailimap_store_att_flags_free(store_flags); | 932 | mailimap_store_att_flags_free(store_flags); |
931 | 933 | ||
932 | if (err != MAILIMAP_NO_ERROR) { | 934 | if (err != MAILIMAP_NO_ERROR) { |
933 | odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; | 935 | odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; |
934 | return; | 936 | return; |
935 | } | 937 | } |
936 | } | 938 | } |
937 | 939 | ||
938 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 940 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
939 | { | 941 | { |
940 | QString body(""); | 942 | QString body(""); |
941 | encodedString*res = fetchRawPart(mail,path,internal_call); | 943 | encodedString*res = fetchRawPart(mail,path,internal_call); |
942 | encodedString*r = decode_String(res,enc); | 944 | encodedString*r = decode_String(res,enc); |
943 | delete res; | 945 | delete res; |
944 | if (r) { | 946 | if (r) { |
945 | if (r->Length()>0) { | 947 | if (r->Length()>0) { |
946 | body = r->Content(); | 948 | body = r->Content(); |
947 | } | 949 | } |
948 | delete r; | 950 | delete r; |
949 | } | 951 | } |
950 | return body; | 952 | return body; |
951 | } | 953 | } |
952 | 954 | ||
953 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | 955 | QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) |
954 | { | 956 | { |
955 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); | 957 | return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); |
956 | } | 958 | } |