-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 1c22c26..098dbdc 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -64,223 +64,223 @@ void IMAPwrapper::login() | |||
64 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 64 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
65 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 65 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
66 | login.show(); | 66 | login.show(); |
67 | if ( QDialog::Accepted == login.exec() ) { | 67 | if ( QDialog::Accepted == login.exec() ) { |
68 | // ok | 68 | // ok |
69 | user = login.getUser().latin1(); | 69 | user = login.getUser().latin1(); |
70 | pass = login.getPassword().latin1(); | 70 | pass = login.getPassword().latin1(); |
71 | } else { | 71 | } else { |
72 | // cancel | 72 | // cancel |
73 | qDebug( "IMAP: Login canceled" ); | 73 | qDebug( "IMAP: Login canceled" ); |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | } else { | 76 | } else { |
77 | user = account->getUser().latin1(); | 77 | user = account->getUser().latin1(); |
78 | pass = account->getPassword().latin1(); | 78 | pass = account->getPassword().latin1(); |
79 | } | 79 | } |
80 | 80 | ||
81 | m_imap = mailimap_new( 20, &imap_progress ); | 81 | m_imap = mailimap_new( 20, &imap_progress ); |
82 | 82 | ||
83 | 83 | ||
84 | 84 | ||
85 | /* connect */ | 85 | /* connect */ |
86 | 86 | ||
87 | bool ssl = false; | 87 | bool ssl = false; |
88 | 88 | ||
89 | if ( account->ConnectionType() == 2 ) { | 89 | if ( account->ConnectionType() == 2 ) { |
90 | ssl = true; | 90 | ssl = true; |
91 | } | 91 | } |
92 | 92 | ||
93 | if ( ssl ) { | 93 | if ( ssl ) { |
94 | qDebug( "using ssl" ); | 94 | qDebug( "using ssl" ); |
95 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 95 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
96 | } else { | 96 | } else { |
97 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 97 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
98 | } | 98 | } |
99 | 99 | ||
100 | if ( err != MAILIMAP_NO_ERROR && | 100 | if ( err != MAILIMAP_NO_ERROR && |
101 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 101 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
102 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 102 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
103 | QString failure = ""; | 103 | QString failure = ""; |
104 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 104 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
105 | failure="Connection refused"; | 105 | failure="Connection refused"; |
106 | } else { | 106 | } else { |
107 | failure="Unknown failure"; | 107 | failure="Unknown failure"; |
108 | } | 108 | } |
109 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 109 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
110 | mailimap_free( m_imap ); | 110 | mailimap_free( m_imap ); |
111 | m_imap = 0; | 111 | m_imap = 0; |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | 114 | ||
115 | /* login */ | 115 | /* login */ |
116 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 116 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
117 | if ( err != MAILIMAP_NO_ERROR ) { | 117 | if ( err != MAILIMAP_NO_ERROR ) { |
118 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 118 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
119 | err = mailimap_close( m_imap ); | 119 | err = mailimap_close( m_imap ); |
120 | mailimap_free( m_imap ); | 120 | mailimap_free( m_imap ); |
121 | m_imap = 0; | 121 | m_imap = 0; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | void IMAPwrapper::logout() | 125 | void IMAPwrapper::logout() |
126 | { | 126 | { |
127 | int err = MAILIMAP_NO_ERROR; | 127 | int err = MAILIMAP_NO_ERROR; |
128 | if (!m_imap) return; | 128 | if (!m_imap) return; |
129 | err = mailimap_logout( m_imap ); | 129 | err = mailimap_logout( m_imap ); |
130 | err = mailimap_close( m_imap ); | 130 | err = mailimap_close( m_imap ); |
131 | mailimap_free( m_imap ); | 131 | mailimap_free( m_imap ); |
132 | m_imap = 0; | 132 | m_imap = 0; |
133 | m_Lastmbox = ""; | 133 | m_Lastmbox = ""; |
134 | } | 134 | } |
135 | 135 | ||
136 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 136 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
137 | { | 137 | { |
138 | int err = MAILIMAP_NO_ERROR; | 138 | int err = MAILIMAP_NO_ERROR; |
139 | clist *result = 0; | 139 | clist *result = 0; |
140 | clistcell *current; | 140 | clistcell *current; |
141 | mailimap_fetch_type *fetchType = 0; | 141 | mailimap_fetch_type *fetchType = 0; |
142 | mailimap_set *set = 0; | 142 | mailimap_set *set = 0; |
143 | 143 | ||
144 | login(); | 144 | login(); |
145 | if (!m_imap) { | 145 | if (!m_imap) { |
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | /* select mailbox READONLY for operations */ | 148 | /* select mailbox READONLY for operations */ |
149 | err = selectMbox(mailbox); | 149 | err = selectMbox(mailbox); |
150 | if ( err != MAILIMAP_NO_ERROR ) { | 150 | if ( err != MAILIMAP_NO_ERROR ) { |
151 | return; | 151 | return; |
152 | } | 152 | } |
153 | 153 | ||
154 | int last = m_imap->imap_selection_info->sel_exists; | 154 | int last = m_imap->imap_selection_info->sel_exists; |
155 | 155 | ||
156 | if (last == 0) { | 156 | if (last == 0) { |
157 | Global::statusMessage(tr("Mailbox has no mails")); | 157 | Global::statusMessage(tr("Mailbox has no mails")); |
158 | return; | 158 | return; |
159 | } else { | 159 | } else { |
160 | Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); | ||
161 | } | 160 | } |
162 | 161 | ||
163 | /* the range has to start at 1!!! not with 0!!!! */ | 162 | /* the range has to start at 1!!! not with 0!!!! */ |
164 | set = mailimap_set_new_interval( 1, last ); | 163 | set = mailimap_set_new_interval( 1, last ); |
165 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 164 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
166 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 165 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
167 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 166 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
168 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 167 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
169 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 168 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
170 | 169 | ||
171 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 170 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
172 | mailimap_set_free( set ); | 171 | mailimap_set_free( set ); |
173 | mailimap_fetch_type_free( fetchType ); | 172 | mailimap_fetch_type_free( fetchType ); |
174 | 173 | ||
175 | QString date,subject,from; | 174 | QString date,subject,from; |
176 | 175 | ||
177 | if ( err == MAILIMAP_NO_ERROR ) { | 176 | if ( err == MAILIMAP_NO_ERROR ) { |
178 | mailimap_msg_att * msg_att; | 177 | mailimap_msg_att * msg_att; |
179 | int i = 0; | 178 | int i = 0; |
180 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 179 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
181 | ++i; | 180 | ++i; |
182 | msg_att = (mailimap_msg_att*)current->data; | 181 | msg_att = (mailimap_msg_att*)current->data; |
183 | RecMail*m = parse_list_result(msg_att); | 182 | RecMail*m = parse_list_result(msg_att); |
184 | if (m) { | 183 | if (m) { |
185 | m->setNumber(i); | 184 | m->setNumber(i); |
186 | m->setMbox(mailbox); | 185 | m->setMbox(mailbox); |
187 | m->setWrapper(this); | 186 | m->setWrapper(this); |
188 | target.append(m); | 187 | target.append(m); |
189 | } | 188 | } |
190 | } | 189 | } |
190 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | ||
191 | } else { | 191 | } else { |
192 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 192 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
193 | } | 193 | } |
194 | if (result) mailimap_fetch_list_free(result); | 194 | if (result) mailimap_fetch_list_free(result); |
195 | } | 195 | } |
196 | 196 | ||
197 | QList<Folder>* IMAPwrapper::listFolders() | 197 | QList<Folder>* IMAPwrapper::listFolders() |
198 | { | 198 | { |
199 | const char *path, *mask; | 199 | const char *path, *mask; |
200 | int err = MAILIMAP_NO_ERROR; | 200 | int err = MAILIMAP_NO_ERROR; |
201 | clist *result = 0; | 201 | clist *result = 0; |
202 | clistcell *current = 0; | 202 | clistcell *current = 0; |
203 | clistcell*cur_flag = 0; | 203 | clistcell*cur_flag = 0; |
204 | mailimap_mbx_list_flags*bflags = 0; | 204 | mailimap_mbx_list_flags*bflags = 0; |
205 | 205 | ||
206 | QList<Folder> * folders = new QList<Folder>(); | 206 | QList<Folder> * folders = new QList<Folder>(); |
207 | folders->setAutoDelete( false ); | 207 | folders->setAutoDelete( false ); |
208 | login(); | 208 | login(); |
209 | if (!m_imap) { | 209 | if (!m_imap) { |
210 | return folders; | 210 | return folders; |
211 | } | 211 | } |
212 | 212 | ||
213 | /* | 213 | /* |
214 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 214 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
215 | * We must not forget to filter them out in next loop! | 215 | * We must not forget to filter them out in next loop! |
216 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 216 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
217 | */ | 217 | */ |
218 | QString temp; | 218 | QString temp; |
219 | mask = "INBOX" ; | 219 | mask = "INBOX" ; |
220 | mailimap_mailbox_list *list; | 220 | mailimap_mailbox_list *list; |
221 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 221 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
222 | QString del; | 222 | QString del; |
223 | bool selectable = true; | 223 | bool selectable = true; |
224 | bool no_inferiors = false; | 224 | bool no_inferiors = false; |
225 | if ( err == MAILIMAP_NO_ERROR ) { | 225 | if ( err == MAILIMAP_NO_ERROR ) { |
226 | current = result->first; | 226 | current = result->first; |
227 | for ( int i = result->count; i > 0; i-- ) { | 227 | for ( int i = result->count; i > 0; i-- ) { |
228 | list = (mailimap_mailbox_list *) current->data; | 228 | list = (mailimap_mailbox_list *) current->data; |
229 | // it is better use the deep copy mechanism of qt itself | 229 | // it is better use the deep copy mechanism of qt itself |
230 | // instead of using strdup! | 230 | // instead of using strdup! |
231 | temp = list->mb_name; | 231 | temp = list->mb_name; |
232 | del = list->mb_delimiter; | 232 | del = list->mb_delimiter; |
233 | current = current->next; | 233 | current = current->next; |
234 | if ( (bflags = list->mb_flag) ) { | 234 | if ( (bflags = list->mb_flag) ) { |
235 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 235 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
236 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 236 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
237 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 237 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
238 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 238 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
239 | no_inferiors = true; | 239 | no_inferiors = true; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | } | 242 | } |
243 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 243 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
244 | } | 244 | } |
245 | } else { | 245 | } else { |
246 | qDebug("error fetching folders: %s",m_imap->imap_response); | 246 | qDebug("error fetching folders: %s",m_imap->imap_response); |
247 | } | 247 | } |
248 | mailimap_list_result_free( result ); | 248 | mailimap_list_result_free( result ); |
249 | 249 | ||
250 | /* | 250 | /* |
251 | * second stage - get the other then inbox folders | 251 | * second stage - get the other then inbox folders |
252 | */ | 252 | */ |
253 | mask = "*" ; | 253 | mask = "*" ; |
254 | path = account->getPrefix().latin1(); | 254 | path = account->getPrefix().latin1(); |
255 | if (!path) path = ""; | 255 | if (!path) path = ""; |
256 | qDebug(path); | 256 | qDebug(path); |
257 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 257 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
258 | if ( err == MAILIMAP_NO_ERROR ) { | 258 | if ( err == MAILIMAP_NO_ERROR ) { |
259 | current = result->first; | 259 | current = result->first; |
260 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 260 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
261 | no_inferiors = false; | 261 | no_inferiors = false; |
262 | list = (mailimap_mailbox_list *) current->data; | 262 | list = (mailimap_mailbox_list *) current->data; |
263 | // it is better use the deep copy mechanism of qt itself | 263 | // it is better use the deep copy mechanism of qt itself |
264 | // instead of using strdup! | 264 | // instead of using strdup! |
265 | temp = list->mb_name; | 265 | temp = list->mb_name; |
266 | if (temp.lower()=="inbox") | 266 | if (temp.lower()=="inbox") |
267 | continue; | 267 | continue; |
268 | if (temp.lower()==account->getPrefix().lower()) | 268 | if (temp.lower()==account->getPrefix().lower()) |
269 | continue; | 269 | continue; |
270 | if ( (bflags = list->mb_flag) ) { | 270 | if ( (bflags = list->mb_flag) ) { |
271 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 271 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
272 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 272 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
273 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 273 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
274 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 274 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
275 | no_inferiors = true; | 275 | no_inferiors = true; |
276 | } | 276 | } |
277 | } | 277 | } |
278 | } | 278 | } |
279 | del = list->mb_delimiter; | 279 | del = list->mb_delimiter; |
280 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 280 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
281 | } | 281 | } |
282 | } else { | 282 | } else { |
283 | qDebug("error fetching folders %s",m_imap->imap_response); | 283 | qDebug("error fetching folders %s",m_imap->imap_response); |
284 | } | 284 | } |
285 | if (result) mailimap_list_result_free( result ); | 285 | if (result) mailimap_list_result_free( result ); |
286 | return folders; | 286 | return folders; |