author | alwin <alwin> | 2005-02-26 10:48:06 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-02-26 10:48:06 (UTC) |
commit | 2e32fb035b4e8ed29e5522ed081c75df1fd74f40 (patch) (unidiff) | |
tree | 6a82a6f6eedb24a18df5166baf64a9fafb472d33 | |
parent | f2f2b0bc7f8fbb0ecbfd7548b7a29618cc5a9139 (diff) | |
download | opie-2e32fb035b4e8ed29e5522ed081c75df1fd74f40.zip opie-2e32fb035b4e8ed29e5522ed081c75df1fd74f40.tar.gz opie-2e32fb035b4e8ed29e5522ed081c75df1fd74f40.tar.bz2 |
uninitialized value of local variable fixed
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 576804d..9e58303 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -1,435 +1,435 @@ | |||
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=false; |
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) { | 76 | if (err != MAILIMAP_NO_ERROR) { |
77 | if (force_tls) { | 77 | if (force_tls) { |
78 | Global::statusMessage(tr("Server has no TLS support!")); | 78 | Global::statusMessage(tr("Server has no TLS support!")); |
79 | odebug << "Server has no TLS support!" << oendl; | 79 | odebug << "Server has no TLS support!" << oendl; |
80 | } | 80 | } |
81 | try_tls = false; | 81 | try_tls = false; |
82 | } else { | 82 | } else { |
83 | mailstream_low * low; | 83 | mailstream_low * low; |
84 | mailstream_low * new_low; | 84 | mailstream_low * new_low; |
85 | low = mailstream_get_low(m_imap->imap_stream); | 85 | low = mailstream_get_low(m_imap->imap_stream); |
86 | if (!low) { | 86 | if (!low) { |
87 | try_tls = false; | 87 | try_tls = false; |
88 | } else { | 88 | } else { |
89 | int fd = mailstream_low_get_fd(low); | 89 | int fd = mailstream_low_get_fd(low); |
90 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 90 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
91 | mailstream_low_free(low); | 91 | mailstream_low_free(low); |
92 | mailstream_set_low(m_imap->imap_stream, new_low); | 92 | mailstream_set_low(m_imap->imap_stream, new_low); |
93 | } else { | 93 | } else { |
94 | try_tls = false; | 94 | try_tls = false; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
99 | return try_tls; | 99 | return try_tls; |
100 | } | 100 | } |
101 | 101 | ||
102 | void IMAPwrapper::login() | 102 | void IMAPwrapper::login() |
103 | { | 103 | { |
104 | const char *server, *user, *pass; | 104 | const char *server, *user, *pass; |
105 | uint16_t port; | 105 | uint16_t port; |
106 | int err = MAILIMAP_NO_ERROR; | 106 | int err = MAILIMAP_NO_ERROR; |
107 | 107 | ||
108 | if (account->getOffline()) return; | 108 | if (account->getOffline()) return; |
109 | /* we are connected this moment */ | 109 | /* we are connected this moment */ |
110 | /* 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 */ |
111 | if (m_imap) { | 111 | if (m_imap) { |
112 | err = mailimap_noop(m_imap); | 112 | err = mailimap_noop(m_imap); |
113 | if (err!=MAILIMAP_NO_ERROR) { | 113 | if (err!=MAILIMAP_NO_ERROR) { |
114 | logout(); | 114 | logout(); |
115 | } else { | 115 | } else { |
116 | mailstream_flush(m_imap->imap_stream); | 116 | mailstream_flush(m_imap->imap_stream); |
117 | return; | 117 | return; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | server = account->getServer().latin1(); | 120 | server = account->getServer().latin1(); |
121 | port = account->getPort().toUInt(); | 121 | port = account->getPort().toUInt(); |
122 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 122 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
123 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 123 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
124 | login.show(); | 124 | login.show(); |
125 | if ( QDialog::Accepted == login.exec() ) { | 125 | if ( QDialog::Accepted == login.exec() ) { |
126 | // ok | 126 | // ok |
127 | user = login.getUser().latin1(); | 127 | user = login.getUser().latin1(); |
128 | pass = login.getPassword().latin1(); | 128 | pass = login.getPassword().latin1(); |
129 | } else { | 129 | } else { |
130 | // cancel | 130 | // cancel |
131 | odebug << "IMAP: Login canceled" << oendl; | 131 | odebug << "IMAP: Login canceled" << oendl; |
132 | return; | 132 | return; |
133 | } | 133 | } |
134 | } else { | 134 | } else { |
135 | user = account->getUser().latin1(); | 135 | user = account->getUser().latin1(); |
136 | pass = account->getPassword().latin1(); | 136 | pass = account->getPassword().latin1(); |
137 | } | 137 | } |
138 | 138 | ||
139 | m_imap = mailimap_new( 20, &imap_progress ); | 139 | m_imap = mailimap_new( 20, &imap_progress ); |
140 | 140 | ||
141 | /* connect */ | 141 | /* connect */ |
142 | bool ssl = false; | 142 | bool ssl = false; |
143 | bool try_tls = false; | 143 | bool try_tls = false; |
144 | bool force_tls = false; | 144 | bool force_tls = false; |
145 | 145 | ||
146 | if ( account->ConnectionType() == 2 ) { | 146 | if ( account->ConnectionType() == 2 ) { |
147 | ssl = true; | 147 | ssl = true; |
148 | } | 148 | } |
149 | if (account->ConnectionType()==1) { | 149 | if (account->ConnectionType()==1) { |
150 | force_tls = true; | 150 | force_tls = true; |
151 | } | 151 | } |
152 | 152 | ||
153 | if ( ssl ) { | 153 | if ( ssl ) { |
154 | odebug << "using ssl" << oendl; | 154 | odebug << "using ssl" << oendl; |
155 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 155 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
156 | } else { | 156 | } else { |
157 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 157 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
158 | } | 158 | } |
159 | 159 | ||
160 | if ( err != MAILIMAP_NO_ERROR && | 160 | if ( err != MAILIMAP_NO_ERROR && |
161 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 161 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
162 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 162 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
163 | QString failure = ""; | 163 | QString failure = ""; |
164 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 164 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
165 | failure="Connection refused"; | 165 | failure="Connection refused"; |
166 | } else { | 166 | } else { |
167 | failure="Unknown failure"; | 167 | failure="Unknown failure"; |
168 | } | 168 | } |
169 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 169 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
170 | mailimap_free( m_imap ); | 170 | mailimap_free( m_imap ); |
171 | m_imap = 0; | 171 | m_imap = 0; |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | 174 | ||
175 | if (!ssl) { | 175 | if (!ssl) { |
176 | try_tls = start_tls(force_tls); | 176 | try_tls = start_tls(force_tls); |
177 | } | 177 | } |
178 | 178 | ||
179 | bool ok = true; | 179 | bool ok = true; |
180 | if (force_tls && !try_tls) { | 180 | if (force_tls && !try_tls) { |
181 | Global::statusMessage(tr("Server has no TLS support!")); | 181 | Global::statusMessage(tr("Server has no TLS support!")); |
182 | odebug << "Server has no TLS support!" << oendl; | 182 | odebug << "Server has no TLS support!" << oendl; |
183 | ok = false; | 183 | ok = false; |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | /* login */ | 187 | /* login */ |
188 | 188 | ||
189 | if (ok) { | 189 | if (ok) { |
190 | err = mailimap_login( m_imap, (char*)user, (char*)pass ); | 190 | err = mailimap_login( m_imap, (char*)user, (char*)pass ); |
191 | if ( err != MAILIMAP_NO_ERROR ) { | 191 | if ( err != MAILIMAP_NO_ERROR ) { |
192 | 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)); |
193 | ok = false; | 193 | ok = false; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | if (!ok) { | 196 | if (!ok) { |
197 | err = mailimap_close( m_imap ); | 197 | err = mailimap_close( m_imap ); |
198 | mailimap_free( m_imap ); | 198 | mailimap_free( m_imap ); |
199 | m_imap = 0; | 199 | m_imap = 0; |
200 | } | 200 | } |
201 | } | 201 | } |
202 | 202 | ||
203 | void IMAPwrapper::logout() | 203 | void IMAPwrapper::logout() |
204 | { | 204 | { |
205 | int err = MAILIMAP_NO_ERROR; | 205 | int err = MAILIMAP_NO_ERROR; |
206 | if (!m_imap) return; | 206 | if (!m_imap) return; |
207 | err = mailimap_logout( m_imap ); | 207 | err = mailimap_logout( m_imap ); |
208 | err = mailimap_close( m_imap ); | 208 | err = mailimap_close( m_imap ); |
209 | mailimap_free( m_imap ); | 209 | mailimap_free( m_imap ); |
210 | m_imap = 0; | 210 | m_imap = 0; |
211 | m_Lastmbox = ""; | 211 | m_Lastmbox = ""; |
212 | } | 212 | } |
213 | 213 | ||
214 | 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 ) |
215 | { | 215 | { |
216 | int err = MAILIMAP_NO_ERROR; | 216 | int err = MAILIMAP_NO_ERROR; |
217 | clist *result = 0; | 217 | clist *result = 0; |
218 | clistcell *current; | 218 | clistcell *current; |
219 | mailimap_fetch_type *fetchType = 0; | 219 | mailimap_fetch_type *fetchType = 0; |
220 | mailimap_set *set = 0; | 220 | mailimap_set *set = 0; |
221 | 221 | ||
222 | login(); | 222 | login(); |
223 | if (!m_imap) { | 223 | if (!m_imap) { |
224 | return; | 224 | return; |
225 | } | 225 | } |
226 | /* select mailbox READONLY for operations */ | 226 | /* select mailbox READONLY for operations */ |
227 | err = selectMbox(mailbox); | 227 | err = selectMbox(mailbox); |
228 | if ( err != MAILIMAP_NO_ERROR ) { | 228 | if ( err != MAILIMAP_NO_ERROR ) { |
229 | return; | 229 | return; |
230 | } | 230 | } |
231 | 231 | ||
232 | int last = m_imap->imap_selection_info->sel_exists; | 232 | int last = m_imap->imap_selection_info->sel_exists; |
233 | 233 | ||
234 | if (last == 0) { | 234 | if (last == 0) { |
235 | Global::statusMessage(tr("Mailbox has no mails")); | 235 | Global::statusMessage(tr("Mailbox has no mails")); |
236 | return; | 236 | return; |
237 | } else { | 237 | } else { |
238 | } | 238 | } |
239 | 239 | ||
240 | /* the range has to start at 1!!! not with 0!!!! */ | 240 | /* the range has to start at 1!!! not with 0!!!! */ |
241 | set = mailimap_set_new_interval( 1, last ); | 241 | set = mailimap_set_new_interval( 1, last ); |
242 | 242 | ||
243 | 243 | ||
244 | fetchType = mailimap_fetch_type_new_all(); | 244 | fetchType = mailimap_fetch_type_new_all(); |
245 | /* | 245 | /* |
246 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 246 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
247 | 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()); |
248 | 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()); |
249 | 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()); |
250 | 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()); |
251 | */ | 251 | */ |
252 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 252 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
253 | mailimap_set_free( set ); | 253 | mailimap_set_free( set ); |
254 | mailimap_fetch_type_free( fetchType ); | 254 | mailimap_fetch_type_free( fetchType ); |
255 | 255 | ||
256 | QString date,subject,from; | 256 | QString date,subject,from; |
257 | 257 | ||
258 | if ( err == MAILIMAP_NO_ERROR ) { | 258 | if ( err == MAILIMAP_NO_ERROR ) { |
259 | mailimap_msg_att * msg_att; | 259 | mailimap_msg_att * msg_att; |
260 | int i = 0; | 260 | int i = 0; |
261 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 261 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
262 | ++i; | 262 | ++i; |
263 | msg_att = (mailimap_msg_att*)current->data; | 263 | msg_att = (mailimap_msg_att*)current->data; |
264 | RecMail*m = parse_list_result(msg_att); | 264 | RecMail*m = parse_list_result(msg_att); |
265 | if (m) { | 265 | if (m) { |
266 | m->setNumber(i); | 266 | m->setNumber(i); |
267 | m->setMbox(mailbox); | 267 | m->setMbox(mailbox); |
268 | m->setWrapper(this); | 268 | m->setWrapper(this); |
269 | target.append(m); | 269 | target.append(m); |
270 | } | 270 | } |
271 | } | 271 | } |
272 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 272 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
273 | } else { | 273 | } else { |
274 | 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)); |
275 | } | 275 | } |
276 | if (result) mailimap_fetch_list_free(result); | 276 | if (result) mailimap_fetch_list_free(result); |
277 | } | 277 | } |
278 | 278 | ||
279 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 279 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
280 | { | 280 | { |
281 | const char *path, *mask; | 281 | const char *path, *mask; |
282 | int err = MAILIMAP_NO_ERROR; | 282 | int err = MAILIMAP_NO_ERROR; |
283 | clist *result = 0; | 283 | clist *result = 0; |
284 | clistcell *current = 0; | 284 | clistcell *current = 0; |
285 | clistcell*cur_flag = 0; | 285 | clistcell*cur_flag = 0; |
286 | mailimap_mbx_list_flags*bflags = 0; | 286 | mailimap_mbx_list_flags*bflags = 0; |
287 | 287 | ||
288 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 288 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
289 | login(); | 289 | login(); |
290 | if (!m_imap) { | 290 | if (!m_imap) { |
291 | return folders; | 291 | return folders; |
292 | } | 292 | } |
293 | 293 | ||
294 | /* | 294 | /* |
295 | * 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. |
296 | * We must not forget to filter them out in next loop! | 296 | * We must not forget to filter them out in next loop! |
297 | * 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. |
298 | */ | 298 | */ |
299 | QString temp; | 299 | QString temp; |
300 | mask = "INBOX" ; | 300 | mask = "INBOX" ; |
301 | mailimap_mailbox_list *list; | 301 | mailimap_mailbox_list *list; |
302 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 302 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
303 | QString del; | 303 | QString del; |
304 | bool selectable = true; | 304 | bool selectable = true; |
305 | bool no_inferiors = false; | 305 | bool no_inferiors = false; |
306 | if ( err == MAILIMAP_NO_ERROR ) { | 306 | if ( err == MAILIMAP_NO_ERROR ) { |
307 | current = result->first; | 307 | current = result->first; |
308 | for ( int i = result->count; i > 0; i-- ) { | 308 | for ( int i = result->count; i > 0; i-- ) { |
309 | list = (mailimap_mailbox_list *) current->data; | 309 | list = (mailimap_mailbox_list *) current->data; |
310 | // it is better use the deep copy mechanism of qt itself | 310 | // it is better use the deep copy mechanism of qt itself |
311 | // instead of using strdup! | 311 | // instead of using strdup! |
312 | temp = list->mb_name; | 312 | temp = list->mb_name; |
313 | del = list->mb_delimiter; | 313 | del = list->mb_delimiter; |
314 | current = current->next; | 314 | current = current->next; |
315 | if ( (bflags = list->mb_flag) ) { | 315 | if ( (bflags = list->mb_flag) ) { |
316 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 316 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
317 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 317 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
318 | 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)) { |
319 | 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) { |
320 | no_inferiors = true; | 320 | no_inferiors = true; |
321 | } | 321 | } |
322 | } | 322 | } |
323 | } | 323 | } |
324 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 324 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
325 | } | 325 | } |
326 | } else { | 326 | } else { |
327 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; | 327 | odebug << "error fetching folders: " << m_imap->imap_response << "" << oendl; |
328 | } | 328 | } |
329 | mailimap_list_result_free( result ); | 329 | mailimap_list_result_free( result ); |
330 | 330 | ||
331 | /* | 331 | /* |
332 | * second stage - get the other then inbox folders | 332 | * second stage - get the other then inbox folders |
333 | */ | 333 | */ |
334 | mask = "*" ; | 334 | mask = "*" ; |
335 | path = account->getPrefix().latin1(); | 335 | path = account->getPrefix().latin1(); |
336 | if (!path) path = ""; | 336 | if (!path) path = ""; |
337 | odebug << path << oendl; | 337 | odebug << path << oendl; |
338 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 338 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
339 | if ( err == MAILIMAP_NO_ERROR ) { | 339 | if ( err == MAILIMAP_NO_ERROR ) { |
340 | current = result->first; | 340 | current = result->first; |
341 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 341 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
342 | no_inferiors = false; | 342 | no_inferiors = false; |
343 | list = (mailimap_mailbox_list *) current->data; | 343 | list = (mailimap_mailbox_list *) current->data; |
344 | // it is better use the deep copy mechanism of qt itself | 344 | // it is better use the deep copy mechanism of qt itself |
345 | // instead of using strdup! | 345 | // instead of using strdup! |
346 | temp = list->mb_name; | 346 | temp = list->mb_name; |
347 | if (temp.lower()=="inbox") | 347 | if (temp.lower()=="inbox") |
348 | continue; | 348 | continue; |
349 | if (temp.lower()==account->getPrefix().lower()) | 349 | if (temp.lower()==account->getPrefix().lower()) |
350 | continue; | 350 | continue; |
351 | if ( (bflags = list->mb_flag) ) { | 351 | if ( (bflags = list->mb_flag) ) { |
352 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 352 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
353 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 353 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
354 | 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)) { |
355 | 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) { |
356 | no_inferiors = true; | 356 | no_inferiors = true; |
357 | } | 357 | } |
358 | } | 358 | } |
359 | } | 359 | } |
360 | del = list->mb_delimiter; | 360 | del = list->mb_delimiter; |
361 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 361 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
362 | } | 362 | } |
363 | } else { | 363 | } else { |
364 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; | 364 | odebug << "error fetching folders " << m_imap->imap_response << "" << oendl; |
365 | } | 365 | } |
366 | if (result) mailimap_list_result_free( result ); | 366 | if (result) mailimap_list_result_free( result ); |
367 | return folders; | 367 | return folders; |
368 | } | 368 | } |
369 | 369 | ||
370 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 370 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
371 | { | 371 | { |
372 | RecMail * m = 0; | 372 | RecMail * m = 0; |
373 | mailimap_msg_att_item *item=0; | 373 | mailimap_msg_att_item *item=0; |
374 | clistcell *current,*c,*cf; | 374 | clistcell *current,*c,*cf; |
375 | mailimap_msg_att_dynamic*flist; | 375 | mailimap_msg_att_dynamic*flist; |
376 | mailimap_flag_fetch*cflag; | 376 | mailimap_flag_fetch*cflag; |
377 | int size,toffset; | 377 | int size,toffset; |
378 | QBitArray mFlags(7); | 378 | QBitArray mFlags(7); |
379 | QStringList addresslist; | 379 | QStringList addresslist; |
380 | 380 | ||
381 | if (!m_att) { | 381 | if (!m_att) { |
382 | return m; | 382 | return m; |
383 | } | 383 | } |
384 | size = 0; | 384 | size = 0; |
385 | m = new RecMail(); | 385 | m = new RecMail(); |
386 | 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) ) { |
387 | current = c; | 387 | current = c; |
388 | item = (mailimap_msg_att_item*)current->data; | 388 | item = (mailimap_msg_att_item*)current->data; |
389 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 389 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
390 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 390 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
391 | if (!flist->att_list) { | 391 | if (!flist->att_list) { |
392 | continue; | 392 | continue; |
393 | } | 393 | } |
394 | cf = flist->att_list->first; | 394 | cf = flist->att_list->first; |
395 | 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)) { |
396 | cflag = (mailimap_flag_fetch*)cf->data; | 396 | cflag = (mailimap_flag_fetch*)cf->data; |
397 | 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) { |
398 | switch (cflag->fl_flag->fl_type) { | 398 | switch (cflag->fl_flag->fl_type) { |
399 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 399 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
400 | mFlags.setBit(FLAG_ANSWERED); | 400 | mFlags.setBit(FLAG_ANSWERED); |
401 | break; | 401 | break; |
402 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 402 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
403 | mFlags.setBit(FLAG_FLAGGED); | 403 | mFlags.setBit(FLAG_FLAGGED); |
404 | break; | 404 | break; |
405 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 405 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
406 | mFlags.setBit(FLAG_DELETED); | 406 | mFlags.setBit(FLAG_DELETED); |
407 | break; | 407 | break; |
408 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 408 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
409 | mFlags.setBit(FLAG_SEEN); | 409 | mFlags.setBit(FLAG_SEEN); |
410 | break; | 410 | break; |
411 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 411 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
412 | mFlags.setBit(FLAG_DRAFT); | 412 | mFlags.setBit(FLAG_DRAFT); |
413 | break; | 413 | break; |
414 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 414 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
415 | break; | 415 | break; |
416 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 416 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
417 | break; | 417 | break; |
418 | default: | 418 | default: |
419 | break; | 419 | break; |
420 | } | 420 | } |
421 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 421 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
422 | mFlags.setBit(FLAG_RECENT); | 422 | mFlags.setBit(FLAG_RECENT); |
423 | } | 423 | } |
424 | } | 424 | } |
425 | continue; | 425 | continue; |
426 | } | 426 | } |
427 | 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) { |
428 | 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; |
429 | QDateTime d = parseDateTime(head->env_date,toffset); | 429 | QDateTime d = parseDateTime(head->env_date,toffset); |
430 | m->setDate(d,toffset); | 430 | m->setDate(d,toffset); |
431 | m->setSubject(convert_String((const char*)head->env_subject)); | 431 | m->setSubject(convert_String((const char*)head->env_subject)); |
432 | if (head->env_from!=NULL) { | 432 | if (head->env_from!=NULL) { |
433 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 433 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
434 | if (addresslist.count()) { | 434 | if (addresslist.count()) { |
435 | m->setFrom(addresslist.first()); | 435 | m->setFrom(addresslist.first()); |