summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/generic/pop3driver.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kmicromail/libetpan/generic/pop3driver.c b/kmicromail/libetpan/generic/pop3driver.c
index 475dfcc..a4a4893 100644
--- a/kmicromail/libetpan/generic/pop3driver.c
+++ b/kmicromail/libetpan/generic/pop3driver.c
@@ -59,333 +59,333 @@ static int pop3driver_login(mailsession * session,
59 59
60static int pop3driver_logout(mailsession * session); 60static int pop3driver_logout(mailsession * session);
61 61
62static int pop3driver_noop(mailsession * session); 62static int pop3driver_noop(mailsession * session);
63 63
64static int pop3driver_status_folder(mailsession * session, char * mb, 64static int pop3driver_status_folder(mailsession * session, char * mb,
65 uint32_t * result_messages, uint32_t * result_recent, 65 uint32_t * result_messages, uint32_t * result_recent,
66 uint32_t * result_unseen); 66 uint32_t * result_unseen);
67 67
68static int pop3driver_messages_number(mailsession * session, char * mb, 68static int pop3driver_messages_number(mailsession * session, char * mb,
69 uint32_t * result); 69 uint32_t * result);
70 70
71static int pop3driver_remove_message(mailsession * session, uint32_t num); 71static int pop3driver_remove_message(mailsession * session, uint32_t num);
72 72
73static int pop3driver_get_messages_list(mailsession * session, 73static int pop3driver_get_messages_list(mailsession * session,
74 struct mailmessage_list ** result); 74 struct mailmessage_list ** result);
75 75
76static int pop3driver_get_message(mailsession * session, 76static int pop3driver_get_message(mailsession * session,
77 uint32_t num, mailmessage ** result); 77 uint32_t num, mailmessage ** result);
78 78
79static mailsession_driver local_pop3_session_driver = { 79static mailsession_driver local_pop3_session_driver = {
80 .sess_name = "pop3", 80 .sess_name = "pop3",
81 81
82 .sess_initialize = pop3driver_initialize, 82 .sess_initialize = pop3driver_initialize,
83 .sess_uninitialize = pop3driver_uninitialize, 83 .sess_uninitialize = pop3driver_uninitialize,
84 84
85 .sess_parameters = pop3driver_parameters, 85 .sess_parameters = pop3driver_parameters,
86 86
87 .sess_connect_stream = pop3driver_connect_stream, 87 .sess_connect_stream = pop3driver_connect_stream,
88 .sess_connect_path = NULL, 88 .sess_connect_path = NULL,
89 .sess_starttls = pop3driver_starttls, 89 .sess_starttls = pop3driver_starttls,
90 .sess_login = pop3driver_login, 90 .sess_login = pop3driver_login,
91 .sess_logout = pop3driver_logout, 91 .sess_logout = pop3driver_logout,
92 .sess_noop = pop3driver_noop, 92 .sess_noop = pop3driver_noop,
93 93
94 .sess_build_folder_name = NULL, 94 .sess_build_folder_name = NULL,
95 .sess_create_folder = NULL, 95 .sess_create_folder = NULL,
96 .sess_delete_folder = NULL, 96 .sess_delete_folder = NULL,
97 .sess_rename_folder = NULL, 97 .sess_rename_folder = NULL,
98 .sess_check_folder = NULL, 98 .sess_check_folder = NULL,
99 .sess_examine_folder = NULL, 99 .sess_examine_folder = NULL,
100 .sess_select_folder = NULL, 100 .sess_select_folder = NULL,
101 .sess_expunge_folder = NULL, 101 .sess_expunge_folder = NULL,
102 .sess_status_folder = pop3driver_status_folder, 102 .sess_status_folder = pop3driver_status_folder,
103 .sess_messages_number = pop3driver_messages_number, 103 .sess_messages_number = pop3driver_messages_number,
104 .sess_recent_number = pop3driver_messages_number, 104 .sess_recent_number = pop3driver_messages_number,
105 .sess_unseen_number = pop3driver_messages_number, 105 .sess_unseen_number = pop3driver_messages_number,
106 .sess_list_folders = NULL, 106 .sess_list_folders = NULL,
107 .sess_lsub_folders = NULL, 107 .sess_lsub_folders = NULL,
108 .sess_subscribe_folder = NULL, 108 .sess_subscribe_folder = NULL,
109 .sess_unsubscribe_folder = NULL, 109 .sess_unsubscribe_folder = NULL,
110 110
111 .sess_append_message = NULL, 111 .sess_append_message = NULL,
112 .sess_append_message_flags = NULL, 112 .sess_append_message_flags = NULL,
113 .sess_copy_message = NULL, 113 .sess_copy_message = NULL,
114 .sess_move_message = NULL, 114 .sess_move_message = NULL,
115 115
116 .sess_get_messages_list = pop3driver_get_messages_list, 116 .sess_get_messages_list = pop3driver_get_messages_list,
117 .sess_get_envelopes_list = maildriver_generic_get_envelopes_list, 117 .sess_get_envelopes_list = maildriver_generic_get_envelopes_list,
118 .sess_remove_message = pop3driver_remove_message, 118 .sess_remove_message = pop3driver_remove_message,
119#if 0 119#if 0
120 .sess_search_messages = maildriver_generic_search_messages, 120 .sess_search_messages = maildriver_generic_search_messages,
121#endif 121#endif
122 122
123 .sess_get_message = pop3driver_get_message, 123 .sess_get_message = pop3driver_get_message,
124 .sess_get_message_by_uid = NULL, 124 .sess_get_message_by_uid = NULL,
125}; 125};
126 126
127mailsession_driver * pop3_session_driver = &local_pop3_session_driver; 127mailsession_driver * pop3_session_driver = &local_pop3_session_driver;
128 128
129static inline struct pop3_session_state_data * 129static inline struct pop3_session_state_data *
130get_data(mailsession * session) 130get_data(mailsession * session)
131{ 131{
132 return session->sess_data; 132 return session->sess_data;
133} 133}
134 134
135static mailpop3 * get_pop3_session(mailsession * session) 135static mailpop3 * get_pop3_session(mailsession * session)
136{ 136{
137 return get_data(session)->pop3_session; 137 return get_data(session)->pop3_session;
138} 138}
139 139
140static int pop3driver_initialize(mailsession * session) 140static int pop3driver_initialize(mailsession * session)
141{ 141{
142 struct pop3_session_state_data * data; 142 struct pop3_session_state_data * data;
143 mailpop3 * pop3; 143 mailpop3 * pop3;
144 144
145 pop3 = mailpop3_new(0, NULL); 145 pop3 = mailpop3_new(0, NULL);
146 if (session == NULL) 146 if (session == NULL)
147 goto err; 147 goto err;
148 148
149 data = malloc(sizeof(* data)); 149 data = malloc(sizeof(* data));
150 if (data == NULL) 150 if (data == NULL)
151 goto free; 151 goto free;
152 152
153 data->pop3_session = pop3; 153 data->pop3_session = pop3;
154 data->pop3_auth_type = POP3DRIVER_AUTH_TYPE_PLAIN; 154 data->pop3_auth_type = POP3DRIVER_AUTH_TYPE_PLAIN;
155 155
156 session->sess_data = data; 156 session->sess_data = data;
157 157
158 return MAIL_NO_ERROR; 158 return MAIL_NO_ERROR;
159 159
160 free: 160 free:
161 mailpop3_free(pop3); 161 mailpop3_free(pop3);
162 err: 162 err:
163 return MAIL_ERROR_MEMORY; 163 return MAIL_ERROR_MEMORY;
164} 164}
165 165
166static void pop3driver_uninitialize(mailsession * session) 166static void pop3driver_uninitialize(mailsession * session)
167{ 167{
168 struct pop3_session_state_data * data; 168 struct pop3_session_state_data * data;
169 169
170 data = get_data(session); 170 data = get_data(session);
171 171
172 mailpop3_free(data->pop3_session); 172 mailpop3_free(data->pop3_session);
173 free(data); 173 free(data);
174 174
175 session->sess_data = data; 175 session->sess_data = data;
176} 176}
177 177
178static int pop3driver_connect_stream(mailsession * session, mailstream * s) 178static int pop3driver_connect_stream(mailsession * session, mailstream * s)
179{ 179{
180 int r; 180 int r;
181 181
182 r = mailpop3_connect(get_pop3_session(session), s); 182 r = mailpop3_connect(get_pop3_session(session), s);
183 183
184 switch (r) { 184 switch (r) {
185 case MAILPOP3_NO_ERROR: 185 case MAILPOP3_NO_ERROR:
186 return MAIL_NO_ERROR_NON_AUTHENTICATED; 186 return MAIL_NO_ERROR_NON_AUTHENTICATED;
187 187
188 default: 188 default:
189 return pop3driver_pop3_error_to_mail_error(r); 189 return pop3driver_pop3_error_to_mail_error(r);
190 } 190 }
191} 191}
192 192
193static int pop3driver_starttls(mailsession * session) 193static int pop3driver_starttls(mailsession * session)
194{ 194{
195 int r; 195 int r;
196 int fd; 196 int fd;
197 mailstream_low * low; 197 mailstream_low * low;
198 mailstream_low * new_low; 198 mailstream_low * new_low;
199 mailpop3 * pop3; 199 mailpop3 * pop3;
200 200
201 pop3 = get_pop3_session(session); 201 pop3 = get_pop3_session(session);
202 202
203 r = mailpop3_stls(pop3); 203 r = mailpop3_stls(pop3);
204 204
205 switch (r) { 205 switch (r) {
206 case MAILPOP3_NO_ERROR: 206 case MAILPOP3_NO_ERROR:
207 break; 207 break;
208 default: 208 default:
209 return pop3driver_pop3_error_to_mail_error(r); 209 return pop3driver_pop3_error_to_mail_error(r);
210 } 210 }
211 211
212 low = mailstream_get_low(pop3->pop3_stream); 212 low = mailstream_get_low(pop3->pop3_stream);
213 fd = mailstream_low_get_fd(low); 213 fd = mailstream_low_get_fd(low);
214 if (fd == -1) 214 if (fd == -1)
215 return MAIL_ERROR_STREAM; 215 return MAIL_ERROR_STREAM;
216 216
217 new_low = mailstream_low_ssl_open(fd); 217 new_low = mailstream_low_ssl_open(fd);
218 if (new_low == NULL) 218 if (new_low == NULL)
219 return MAIL_ERROR_STREAM; 219 return MAIL_ERROR_STREAM;
220 mailstream_low_free(low); 220 mailstream_low_free(low);
221 mailstream_set_low(pop3->pop3_stream, new_low); 221 mailstream_set_low(pop3->pop3_stream, new_low);
222 222
223 return MAIL_NO_ERROR; 223 return MAIL_NO_ERROR;
224} 224}
225 225
226static int pop3driver_parameters(mailsession * session, 226static int pop3driver_parameters(mailsession * session,
227 int id, void * value) 227 int id, void * value)
228{ 228{
229 struct pop3_session_state_data * data; 229 struct pop3_session_state_data * data;
230 230
231 data = get_data(session); 231 data = get_data(session);
232 232
233 switch (id) { 233 switch (id) {
234 case POP3DRIVER_SET_AUTH_TYPE: 234 case POP3DRIVER_SET_AUTH_TYPE:
235 { 235 {
236 int * param; 236 int * param;
237 237
238 param = value; 238 param = value;
239 239
240 data->pop3_auth_type = * param; 240 data->pop3_auth_type = * param;
241 return MAIL_NO_ERROR; 241 return MAIL_NO_ERROR;
242 } 242 }
243 } 243 }
244 244
245 return MAIL_ERROR_INVAL; 245 return MAIL_ERROR_INVAL;
246} 246}
247 247
248static int pop3driver_login(mailsession * session, 248static int pop3driver_login(mailsession * session,
249 char * userid, char * password) 249 char * userid, char * password)
250{ 250{
251 int r; 251 int r;int ret ;
252 carray * msg_tab; 252 carray * msg_tab;
253 struct pop3_session_state_data * data; 253 struct pop3_session_state_data * data;
254 254
255 data = get_data(session); 255 data = get_data(session);
256 256
257 switch (data->pop3_auth_type) { 257 switch (data->pop3_auth_type) {
258 case POP3DRIVER_AUTH_TYPE_TRY_APOP: 258 case POP3DRIVER_AUTH_TYPE_TRY_APOP:
259 r = mailpop3_login_apop(get_pop3_session(session), userid, password); 259 r = mailpop3_login_apop(get_pop3_session(session), userid, password);
260 if (r != MAILPOP3_NO_ERROR) 260 if (r != MAILPOP3_NO_ERROR)
261 r = mailpop3_login(get_pop3_session(session), userid, password); 261 r = mailpop3_login(get_pop3_session(session), userid, password);
262 break; 262 break;
263 263
264 case POP3DRIVER_AUTH_TYPE_APOP: 264 case POP3DRIVER_AUTH_TYPE_APOP:
265 r = mailpop3_login_apop(get_pop3_session(session), userid, password); 265 r = mailpop3_login_apop(get_pop3_session(session), userid, password);
266 break; 266 break;
267 267
268 default: 268 default:
269 case POP3DRIVER_AUTH_TYPE_PLAIN: 269 case POP3DRIVER_AUTH_TYPE_PLAIN:
270 r = mailpop3_login(get_pop3_session(session), userid, password); 270 r = mailpop3_login(get_pop3_session(session), userid, password);
271 break; 271 break;
272 } 272 }
273 // LR 2 lines 273 // LR 2 lines
274 int ret = pop3driver_pop3_error_to_mail_error(r); 274 ret = pop3driver_pop3_error_to_mail_error(r);
275 if ( ret == MAIL_NO_ERROR ) 275 if ( ret == MAIL_NO_ERROR )
276 mailpop3_list(get_pop3_session(session), &msg_tab); 276 mailpop3_list(get_pop3_session(session), &msg_tab);
277 277
278 // LR 278 // LR
279 return ret; 279 return ret;
280} 280}
281 281
282static int pop3driver_logout(mailsession * session) 282static int pop3driver_logout(mailsession * session)
283{ 283{
284 int r; 284 int r;
285 285
286 r = mailpop3_quit(get_pop3_session(session)); 286 r = mailpop3_quit(get_pop3_session(session));
287 287
288 return pop3driver_pop3_error_to_mail_error(r); 288 return pop3driver_pop3_error_to_mail_error(r);
289} 289}
290 290
291static int pop3driver_noop(mailsession * session) 291static int pop3driver_noop(mailsession * session)
292{ 292{
293 int r; 293 int r;
294 294
295 r = mailpop3_noop(get_pop3_session(session)); 295 r = mailpop3_noop(get_pop3_session(session));
296 296
297 return pop3driver_pop3_error_to_mail_error(r); 297 return pop3driver_pop3_error_to_mail_error(r);
298} 298}
299 299
300static int pop3driver_status_folder(mailsession * session, char * mb, 300static int pop3driver_status_folder(mailsession * session, char * mb,
301 uint32_t * result_messages, 301 uint32_t * result_messages,
302 uint32_t * result_recent, 302 uint32_t * result_recent,
303 uint32_t * result_unseen) 303 uint32_t * result_unseen)
304{ 304{
305 uint32_t count; 305 uint32_t count;
306 int r; 306 int r;
307 307
308 r = pop3driver_messages_number(session, mb, &count); 308 r = pop3driver_messages_number(session, mb, &count);
309 if (r != MAIL_NO_ERROR) 309 if (r != MAIL_NO_ERROR)
310 return r; 310 return r;
311 311
312 * result_messages = count; 312 * result_messages = count;
313 * result_recent = count; 313 * result_recent = count;
314 * result_unseen = count; 314 * result_unseen = count;
315 315
316 return MAIL_NO_ERROR; 316 return MAIL_NO_ERROR;
317} 317}
318 318
319static int pop3driver_messages_number(mailsession * session, char * mb, 319static int pop3driver_messages_number(mailsession * session, char * mb,
320 uint32_t * result) 320 uint32_t * result)
321{ 321{
322 carray * msg_tab; 322 carray * msg_tab;
323 323
324 mailpop3_list(get_pop3_session(session), &msg_tab); 324 mailpop3_list(get_pop3_session(session), &msg_tab);
325 325
326 * result = carray_count(msg_tab) - 326 * result = carray_count(msg_tab) -
327 get_pop3_session(session)->pop3_deleted_count; 327 get_pop3_session(session)->pop3_deleted_count;
328 328
329 return MAIL_NO_ERROR; 329 return MAIL_NO_ERROR;
330} 330}
331 331
332 332
333/* messages operations */ 333/* messages operations */
334 334
335static int pop3driver_remove_message(mailsession * session, uint32_t num) 335static int pop3driver_remove_message(mailsession * session, uint32_t num)
336{ 336{
337 mailpop3 * pop3; 337 mailpop3 * pop3;
338 int r; 338 int r;
339 339
340 pop3 = get_pop3_session(session); 340 pop3 = get_pop3_session(session);
341 341
342 r = mailpop3_dele(pop3, num); 342 r = mailpop3_dele(pop3, num);
343 switch (r) { 343 switch (r) {
344 case MAILPOP3_ERROR_BAD_STATE: 344 case MAILPOP3_ERROR_BAD_STATE:
345 return MAIL_ERROR_BAD_STATE; 345 return MAIL_ERROR_BAD_STATE;
346 346
347 case MAILPOP3_ERROR_NO_SUCH_MESSAGE: 347 case MAILPOP3_ERROR_NO_SUCH_MESSAGE:
348 return MAIL_ERROR_MSG_NOT_FOUND; 348 return MAIL_ERROR_MSG_NOT_FOUND;
349 349
350 case MAILPOP3_ERROR_STREAM: 350 case MAILPOP3_ERROR_STREAM:
351 return MAIL_ERROR_STREAM; 351 return MAIL_ERROR_STREAM;
352 352
353 case MAILPOP3_NO_ERROR: 353 case MAILPOP3_NO_ERROR:
354 return MAIL_NO_ERROR; 354 return MAIL_NO_ERROR;
355 355
356 default: 356 default:
357 return MAIL_ERROR_REMOVE; 357 return MAIL_ERROR_REMOVE;
358 } 358 }
359} 359}
360 360
361static int pop3driver_get_messages_list(mailsession * session, 361static int pop3driver_get_messages_list(mailsession * session,
362 struct mailmessage_list ** result) 362 struct mailmessage_list ** result)
363{ 363{
364 mailpop3 * pop3; 364 mailpop3 * pop3;
365 365
366 pop3 = get_pop3_session(session); 366 pop3 = get_pop3_session(session);
367 367
368 return pop3_get_messages_list(pop3, session, 368 return pop3_get_messages_list(pop3, session,
369 pop3_message_driver, result); 369 pop3_message_driver, result);
370} 370}
371 371
372static int pop3driver_get_message(mailsession * session, 372static int pop3driver_get_message(mailsession * session,
373 uint32_t num, mailmessage ** result) 373 uint32_t num, mailmessage ** result)
374{ 374{
375 mailmessage * msg_info; 375 mailmessage * msg_info;
376 int r; 376 int r;
377 377
378 msg_info = mailmessage_new(); 378 msg_info = mailmessage_new();
379 if (msg_info == NULL) 379 if (msg_info == NULL)
380 return MAIL_ERROR_MEMORY; 380 return MAIL_ERROR_MEMORY;
381 381
382 r = mailmessage_init(msg_info, session, pop3_message_driver, num, 0); 382 r = mailmessage_init(msg_info, session, pop3_message_driver, num, 0);
383 if (r != MAIL_NO_ERROR) { 383 if (r != MAIL_NO_ERROR) {
384 mailmessage_free(msg_info); 384 mailmessage_free(msg_info);
385 return r; 385 return r;
386 } 386 }
387 387
388 * result = msg_info; 388 * result = msg_info;
389 389
390 return MAIL_NO_ERROR; 390 return MAIL_NO_ERROR;
391} 391}