imap client: implement folder API.
* libmailutils/list/listlist.c (mu_list_append_list): Do nothing if the source list is empty. * include/mailutils/sys/imap.h (_mu_imap_url_init) (_mu_imaps_url_init): New protos. * libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Restore url.c * libproto/imap/mbox.c: Deleted * libproto/imap/url.c: Rewrite. * libproto/imap/folder.c: Rewrite from scratch. * configure.ac: Build libproto/imap/tests/Makefile * include/mailutils/imap.h (mu_imap_session_state) (mu_imap_iserror, mu_imap_clearerr) (mu_imap_login_secret): New protos. * include/mailutils/sys/imap.h (_mu_imap_list_element_is_nil): New proto. * libmailutils/mailbox/folder.c (mu_folder_list): Pass MU_FOLDER_ATTRIBUTE_ALL. * libproto/imap/fake-folder.c: Remove. * libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Remove fake-folder.c Add url.c and folder.c * libproto/imap/create.c (mu_imap_session_state) (mu_imap_iserror, mu_imap_clearerr): New functions. * libproto/imap/delete.c: Check input parameters. * libproto/imap/fetch.c: Use _mu_imap_list_element_is_nil to check for empty lists. * libproto/imap/genlist.c: Likewise. * libproto/imap/rename.c: Likewise. * libproto/imap/subscribe.c: Likewise. * libproto/imap/unsubscribe.c: Likewise. * libproto/imap/resplist.c: Treat NIL and () equally. * libproto/imap/login.c (mu_imap_login_secret): New function. * mu/imap.c: Fix a typo.
Showing
23 changed files
with
394 additions
and
43 deletions
... | @@ -1460,6 +1460,7 @@ AC_CONFIG_FILES([ | ... | @@ -1460,6 +1460,7 @@ AC_CONFIG_FILES([ |
1460 | libproto/pop/Makefile | 1460 | libproto/pop/Makefile |
1461 | libproto/nntp/Makefile | 1461 | libproto/nntp/Makefile |
1462 | libproto/imap/Makefile | 1462 | libproto/imap/Makefile |
1463 | libproto/imap/tests/Makefile | ||
1463 | libmu_compat/Makefile | 1464 | libmu_compat/Makefile |
1464 | maidag/Makefile | 1465 | maidag/Makefile |
1465 | mail/Makefile | 1466 | mail/Makefile | ... | ... |
... | @@ -47,6 +47,10 @@ void mu_imap_destroy (mu_imap_t *pimap); | ... | @@ -47,6 +47,10 @@ void mu_imap_destroy (mu_imap_t *pimap); |
47 | int mu_imap_connect (mu_imap_t imap); | 47 | int mu_imap_connect (mu_imap_t imap); |
48 | int mu_imap_disconnect (mu_imap_t imap); | 48 | int mu_imap_disconnect (mu_imap_t imap); |
49 | 49 | ||
50 | int mu_imap_session_state (mu_imap_t imap); | ||
51 | int mu_imap_iserror (mu_imap_t imap); | ||
52 | void mu_imap_clearerr (mu_imap_t imap); | ||
53 | |||
50 | int mu_imap_capability (mu_imap_t imap, int reread, mu_iterator_t *piter); | 54 | int mu_imap_capability (mu_imap_t imap, int reread, mu_iterator_t *piter); |
51 | int mu_imap_capability_test (mu_imap_t imap, const char *name, | 55 | int mu_imap_capability_test (mu_imap_t imap, const char *name, |
52 | const char **pret); | 56 | const char **pret); |
... | @@ -54,6 +58,8 @@ int mu_imap_capability_test (mu_imap_t imap, const char *name, | ... | @@ -54,6 +58,8 @@ int mu_imap_capability_test (mu_imap_t imap, const char *name, |
54 | int mu_imap_starttls (mu_imap_t imap); | 58 | int mu_imap_starttls (mu_imap_t imap); |
55 | 59 | ||
56 | int mu_imap_login (mu_imap_t imap, const char *user, const char *pass); | 60 | int mu_imap_login (mu_imap_t imap, const char *user, const char *pass); |
61 | int mu_imap_login_secret (mu_imap_t imap, const char *user, | ||
62 | mu_secret_t secret); | ||
57 | int mu_imap_logout (mu_imap_t imap); | 63 | int mu_imap_logout (mu_imap_t imap); |
58 | 64 | ||
59 | int mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc); | 65 | int mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc); | ... | ... |
... | @@ -215,6 +215,8 @@ int _mu_imap_response (mu_imap_t imap, mu_imap_response_action_t fun, | ... | @@ -215,6 +215,8 @@ int _mu_imap_response (mu_imap_t imap, mu_imap_response_action_t fun, |
215 | 215 | ||
216 | int _mu_imap_list_element_is_string (struct imap_list_element *elt, | 216 | int _mu_imap_list_element_is_string (struct imap_list_element *elt, |
217 | const char *str); | 217 | const char *str); |
218 | int _mu_imap_list_element_is_nil (struct imap_list_element *elt); | ||
219 | |||
218 | int _mu_imap_list_nth_element_is_string (mu_list_t list, size_t n, | 220 | int _mu_imap_list_nth_element_is_string (mu_list_t list, size_t n, |
219 | const char *str); | 221 | const char *str); |
220 | 222 | ||
... | @@ -225,7 +227,18 @@ struct imap_list_element *_mu_imap_list_at (mu_list_t list, int idx); | ... | @@ -225,7 +227,18 @@ struct imap_list_element *_mu_imap_list_at (mu_list_t list, int idx); |
225 | int _mu_imap_parse_fetch_response (mu_list_t resp, mu_list_t *result_list); | 227 | int _mu_imap_parse_fetch_response (mu_list_t resp, mu_list_t *result_list); |
226 | 228 | ||
227 | void _mu_close_handler (mu_imap_t imap); | 229 | void _mu_close_handler (mu_imap_t imap); |
228 | 230 | ||
231 | /* ----------------------------- */ | ||
232 | /* URL Auxiliaries */ | ||
233 | /* ----------------------------- */ | ||
234 | int _mu_imap_url_init (mu_url_t url); | ||
235 | int _mu_imaps_url_init (mu_url_t url); | ||
236 | |||
237 | /* ----------------------------- */ | ||
238 | /* Folder interface */ | ||
239 | /* ----------------------------- */ | ||
240 | |||
241 | |||
229 | # ifdef __cplusplus | 242 | # ifdef __cplusplus |
230 | } | 243 | } |
231 | # endif | 244 | # endif | ... | ... |
... | @@ -99,7 +99,9 @@ mu_list_insert_list (mu_list_t list, void *item, mu_list_t new_list, | ... | @@ -99,7 +99,9 @@ mu_list_insert_list (mu_list_t list, void *item, mu_list_t new_list, |
99 | void | 99 | void |
100 | mu_list_append_list (mu_list_t list, mu_list_t new_list) | 100 | mu_list_append_list (mu_list_t list, mu_list_t new_list) |
101 | { | 101 | { |
102 | if (list->count == 0) | 102 | if (new_list->count == 0) |
103 | return; | ||
104 | else if (list->count == 0) | ||
103 | { | 105 | { |
104 | list->head = new_list->head; | 106 | list->head = new_list->head; |
105 | list->head.next->prev = list->head.prev->next = &list->head; | 107 | list->head.next->prev = list->head.prev->next = &list->head; | ... | ... |
... | @@ -368,7 +368,8 @@ mu_folder_list (mu_folder_t folder, const char *dirname, void *pattern, | ... | @@ -368,7 +368,8 @@ mu_folder_list (mu_folder_t folder, const char *dirname, void *pattern, |
368 | size_t max_level, | 368 | size_t max_level, |
369 | mu_list_t *pflist) | 369 | mu_list_t *pflist) |
370 | { | 370 | { |
371 | return mu_folder_enumerate (folder, dirname, pattern, 0, max_level, | 371 | return mu_folder_enumerate (folder, dirname, pattern, |
372 | MU_FOLDER_ATTRIBUTE_ALL, max_level, | ||
372 | pflist, NULL, NULL); | 373 | pflist, NULL, NULL); |
373 | } | 374 | } |
374 | 375 | ... | ... |
... | @@ -21,16 +21,14 @@ lib_LTLIBRARIES = libmu_imap.la | ... | @@ -21,16 +21,14 @@ lib_LTLIBRARIES = libmu_imap.la |
21 | libmu_imap_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@ | 21 | libmu_imap_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@ |
22 | libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@ | 22 | libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@ |
23 | 23 | ||
24 | # FIXME: Put these back when ready | 24 | SUBDIRS = . tests |
25 | 25 | ||
26 | # folder.c\ | 26 | # FIXME: Put this back when ready |
27 | # mbox.c\ | 27 | # mbox.c |
28 | # url.c | ||
29 | libmu_imap_la_SOURCES = \ | 28 | libmu_imap_la_SOURCES = \ |
30 | appmsg.c\ | 29 | appmsg.c\ |
31 | appstr.c\ | 30 | appstr.c\ |
32 | appstrsiz.c\ | 31 | appstrsiz.c\ |
33 | fake-folder.c\ | ||
34 | fetch.c\ | 32 | fetch.c\ |
35 | gencom.c\ | 33 | gencom.c\ |
36 | genlist.c\ | 34 | genlist.c\ |
... | @@ -68,5 +66,6 @@ libmu_imap_la_SOURCES = \ | ... | @@ -68,5 +66,6 @@ libmu_imap_la_SOURCES = \ |
68 | tag.c\ | 66 | tag.c\ |
69 | trace.c\ | 67 | trace.c\ |
70 | unselect.c\ | 68 | unselect.c\ |
71 | unsubscribe.c | 69 | unsubscribe.c\ |
72 | 70 | folder.c\ | |
71 | url.c | ... | ... |
... | @@ -64,3 +64,30 @@ _mu_imap_init (mu_imap_t imap) | ... | @@ -64,3 +64,30 @@ _mu_imap_init (mu_imap_t imap) |
64 | imap->session_state = MU_IMAP_SESSION_INIT; | 64 | imap->session_state = MU_IMAP_SESSION_INIT; |
65 | return 0; | 65 | return 0; |
66 | } | 66 | } |
67 | |||
68 | int | ||
69 | mu_imap_session_state (mu_imap_t imap) | ||
70 | { | ||
71 | if (!imap) | ||
72 | return -1; | ||
73 | return imap->session_state; | ||
74 | } | ||
75 | |||
76 | int | ||
77 | mu_imap_iserror (mu_imap_t imap) | ||
78 | { | ||
79 | if (!imap) | ||
80 | return -1; | ||
81 | return imap->client_state == MU_IMAP_CLIENT_ERROR; | ||
82 | } | ||
83 | |||
84 | void | ||
85 | mu_imap_clearerr (mu_imap_t imap) | ||
86 | { | ||
87 | if (imap) | ||
88 | { | ||
89 | imap->client_state = MU_IMAP_CLIENT_READY; | ||
90 | if (imap->io) | ||
91 | mu_imapio_clearerr (imap->io); | ||
92 | } | ||
93 | } | ... | ... |
... | @@ -31,6 +31,9 @@ mu_imap_delete (mu_imap_t imap, const char *mailbox) | ... | @@ -31,6 +31,9 @@ mu_imap_delete (mu_imap_t imap, const char *mailbox) |
31 | char const *argv[2]; | 31 | char const *argv[2]; |
32 | static struct imap_command com; | 32 | static struct imap_command com; |
33 | 33 | ||
34 | if (!mailbox) | ||
35 | return EINVAL; | ||
36 | |||
34 | argv[0] = "DELETE"; | 37 | argv[0] = "DELETE"; |
35 | argv[1] = mailbox; | 38 | argv[1] = mailbox; |
36 | 39 | ... | ... |
libproto/imap/fake-folder.c
deleted
100644 → 0
... | @@ -354,11 +354,11 @@ static int | ... | @@ -354,11 +354,11 @@ static int |
354 | elt_to_string (struct imap_list_element *elt, char **pstr) | 354 | elt_to_string (struct imap_list_element *elt, char **pstr) |
355 | { | 355 | { |
356 | char *p; | 356 | char *p; |
357 | 357 | ||
358 | if (elt->type != imap_eltype_string) | 358 | if (_mu_imap_list_element_is_nil (elt)) |
359 | return EINVAL; | ||
360 | if (mu_c_strcasecmp (elt->v.string, "NIL") == 0) | ||
361 | p = NULL; | 359 | p = NULL; |
360 | else if (elt->type != imap_eltype_string) | ||
361 | return EINVAL; | ||
362 | else | 362 | else |
363 | { | 363 | { |
364 | p = strdup (elt->v.string); | 364 | p = strdup (elt->v.string); |
... | @@ -386,13 +386,13 @@ _fill_subaddr (void *item, void *data) | ... | @@ -386,13 +386,13 @@ _fill_subaddr (void *item, void *data) |
386 | return 0; | 386 | return 0; |
387 | 387 | ||
388 | arg = _mu_imap_list_at (elt->v.list, 0); | 388 | arg = _mu_imap_list_at (elt->v.list, 0); |
389 | if (arg && arg->type == imap_eltype_string && strcmp (arg->v.string, "NIL")) | 389 | if (arg && arg->type == imap_eltype_string) |
390 | personal = arg->v.string; | 390 | personal = arg->v.string; |
391 | arg = _mu_imap_list_at (elt->v.list, 2); | 391 | arg = _mu_imap_list_at (elt->v.list, 2); |
392 | if (arg && arg->type == imap_eltype_string && strcmp (arg->v.string, "NIL")) | 392 | if (arg && arg->type == imap_eltype_string) |
393 | local = arg->v.string; | 393 | local = arg->v.string; |
394 | arg = _mu_imap_list_at (elt->v.list, 3); | 394 | arg = _mu_imap_list_at (elt->v.list, 3); |
395 | if (arg && arg->type == imap_eltype_string && strcmp (arg->v.string, "NIL")) | 395 | if (arg && arg->type == imap_eltype_string) |
396 | domain = arg->v.string; | 396 | domain = arg->v.string; |
397 | 397 | ||
398 | if (domain && local) | 398 | if (domain && local) |
... | @@ -414,13 +414,10 @@ _fill_subaddr (void *item, void *data) | ... | @@ -414,13 +414,10 @@ _fill_subaddr (void *item, void *data) |
414 | static int | 414 | static int |
415 | elt_to_address (struct imap_list_element *elt, mu_address_t *paddr) | 415 | elt_to_address (struct imap_list_element *elt, mu_address_t *paddr) |
416 | { | 416 | { |
417 | if (elt->type != imap_eltype_list) | 417 | if (_mu_imap_list_element_is_nil (elt)) |
418 | { | 418 | *paddr = NULL; |
419 | if (mu_c_strcasecmp (elt->v.string, "NIL") == 0) | 419 | else if (elt->type != imap_eltype_list) |
420 | *paddr = NULL; | 420 | return EINVAL; |
421 | else | ||
422 | return EINVAL; | ||
423 | } | ||
424 | else | 421 | else |
425 | { | 422 | { |
426 | struct addr_env addr_env; | 423 | struct addr_env addr_env; | ... | ... |
This diff is collapsed.
Click to expand it.
... | @@ -104,13 +104,15 @@ list_untagged_handler (mu_imap_t imap, mu_list_t resp, void *data) | ... | @@ -104,13 +104,15 @@ list_untagged_handler (mu_imap_t imap, mu_list_t resp, void *data) |
104 | } | 104 | } |
105 | 105 | ||
106 | elt = _mu_imap_list_at (resp, 2); | 106 | elt = _mu_imap_list_at (resp, 2); |
107 | if (!(elt && elt->type == imap_eltype_string)) | 107 | if (!elt) |
108 | return; | 108 | return; |
109 | if (mu_c_strcasecmp (elt->v.string, "NIL") == 0) | 109 | if (_mu_imap_list_element_is_nil (elt)) |
110 | { | 110 | { |
111 | rp->separator = 0; | 111 | rp->separator = 0; |
112 | rp->level = 0; | 112 | rp->level = 0; |
113 | } | 113 | } |
114 | else if (elt->type != imap_eltype_string) | ||
115 | return; | ||
114 | else | 116 | else |
115 | { | 117 | { |
116 | rp->separator = elt->v.string[0]; | 118 | rp->separator = elt->v.string[0]; |
... | @@ -131,6 +133,9 @@ mu_imap_genlist (mu_imap_t imap, int lsub, | ... | @@ -131,6 +133,9 @@ mu_imap_genlist (mu_imap_t imap, int lsub, |
131 | struct list_closure clos; | 133 | struct list_closure clos; |
132 | int rc; | 134 | int rc; |
133 | 135 | ||
136 | if (!refname || !mboxname) | ||
137 | return EINVAL; | ||
138 | |||
134 | argv[0] = lsub ? "LSUB" : "LIST"; | 139 | argv[0] = lsub ? "LSUB" : "LIST"; |
135 | argv[1] = refname; | 140 | argv[1] = refname; |
136 | argv[2] = mboxname; | 141 | argv[2] = mboxname; | ... | ... |
... | @@ -22,6 +22,7 @@ | ... | @@ -22,6 +22,7 @@ |
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include <mailutils/errno.h> | 23 | #include <mailutils/errno.h> |
24 | #include <mailutils/stream.h> | 24 | #include <mailutils/stream.h> |
25 | #include <mailutils/secret.h> | ||
25 | #include <mailutils/sys/imap.h> | 26 | #include <mailutils/sys/imap.h> |
26 | 27 | ||
27 | int | 28 | int |
... | @@ -77,3 +78,12 @@ mu_imap_login (mu_imap_t imap, const char *user, const char *pass) | ... | @@ -77,3 +78,12 @@ mu_imap_login (mu_imap_t imap, const char *user, const char *pass) |
77 | return status; | 78 | return status; |
78 | } | 79 | } |
79 | 80 | ||
81 | int | ||
82 | mu_imap_login_secret (mu_imap_t imap, const char *user, mu_secret_t secret) | ||
83 | { | ||
84 | int rc = mu_imap_login (imap, user, mu_secret_password (secret)); | ||
85 | mu_secret_password_unref (secret); | ||
86 | return rc; | ||
87 | } | ||
88 | |||
89 | ... | ... |
libproto/imap/mbox.c
deleted
100644 → 0
This diff is collapsed.
Click to expand it.
... | @@ -29,6 +29,9 @@ mu_imap_rename (mu_imap_t imap, const char *mailbox, const char *new_mailbox) | ... | @@ -29,6 +29,9 @@ mu_imap_rename (mu_imap_t imap, const char *mailbox, const char *new_mailbox) |
29 | char const *argv[3]; | 29 | char const *argv[3]; |
30 | static struct imap_command com; | 30 | static struct imap_command com; |
31 | 31 | ||
32 | if (!mailbox || !new_mailbox) | ||
33 | return EINVAL; | ||
34 | |||
32 | argv[0] = "RENAME"; | 35 | argv[0] = "RENAME"; |
33 | argv[1] = mailbox; | 36 | argv[1] = mailbox; |
34 | argv[2] = new_mailbox; | 37 | argv[2] = new_mailbox; | ... | ... |
... | @@ -57,6 +57,7 @@ _mu_imap_response_list_create (mu_imap_t imap, mu_list_t *plist) | ... | @@ -57,6 +57,7 @@ _mu_imap_response_list_create (mu_imap_t imap, mu_list_t *plist) |
57 | 57 | ||
58 | #define IS_LBRACE(p) ((p)[0] == '(') | 58 | #define IS_LBRACE(p) ((p)[0] == '(') |
59 | #define IS_RBRACE(p) ((p)[0] == ')') | 59 | #define IS_RBRACE(p) ((p)[0] == ')') |
60 | #define IS_NIL(p) (strcmp (p, "NIL") == 0) | ||
60 | 61 | ||
61 | static struct imap_list_element * | 62 | static struct imap_list_element * |
62 | _new_imap_list_element (mu_imap_t imap, enum imap_eltype type) | 63 | _new_imap_list_element (mu_imap_t imap, enum imap_eltype type) |
... | @@ -181,6 +182,7 @@ _parse_element (struct parsebuf *pb) | ... | @@ -181,6 +182,7 @@ _parse_element (struct parsebuf *pb) |
181 | 182 | ||
182 | if (IS_RBRACE (tok)) | 183 | if (IS_RBRACE (tok)) |
183 | { | 184 | { |
185 | parsebuf_gettok (pb); | ||
184 | elt = _new_imap_list_element (pb->pb_imap, imap_eltype_list); | 186 | elt = _new_imap_list_element (pb->pb_imap, imap_eltype_list); |
185 | if (!elt) | 187 | if (!elt) |
186 | { | 188 | { |
... | @@ -203,6 +205,16 @@ _parse_element (struct parsebuf *pb) | ... | @@ -203,6 +205,16 @@ _parse_element (struct parsebuf *pb) |
203 | parsebuf_seterr (pb, MU_ERR_PARSE); | 205 | parsebuf_seterr (pb, MU_ERR_PARSE); |
204 | return NULL; | 206 | return NULL; |
205 | } | 207 | } |
208 | else if (IS_NIL (tok)) | ||
209 | { | ||
210 | elt = _new_imap_list_element (pb->pb_imap, imap_eltype_list); | ||
211 | if (!elt) | ||
212 | { | ||
213 | parsebuf_seterr (pb, ENOMEM); | ||
214 | return NULL; | ||
215 | } | ||
216 | elt->v.list = NULL; | ||
217 | } | ||
206 | else | 218 | else |
207 | { | 219 | { |
208 | char *s; | 220 | char *s; |
... | @@ -255,6 +267,12 @@ _mu_imap_list_element_is_string (struct imap_list_element *elt, | ... | @@ -255,6 +267,12 @@ _mu_imap_list_element_is_string (struct imap_list_element *elt, |
255 | return strcmp (elt->v.string, str) == 0; | 267 | return strcmp (elt->v.string, str) == 0; |
256 | } | 268 | } |
257 | 269 | ||
270 | int | ||
271 | _mu_imap_list_element_is_nil (struct imap_list_element *elt) | ||
272 | { | ||
273 | return elt->type == imap_eltype_list && mu_list_is_empty (elt->v.list); | ||
274 | } | ||
275 | |||
258 | struct imap_list_element * | 276 | struct imap_list_element * |
259 | _mu_imap_list_at (mu_list_t list, int idx) | 277 | _mu_imap_list_at (mu_list_t list, int idx) |
260 | { | 278 | { | ... | ... |
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | # include <config.h> | 19 | # include <config.h> |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #include <errno.h> | ||
22 | #include <mailutils/imap.h> | 23 | #include <mailutils/imap.h> |
23 | #include <mailutils/sys/imap.h> | 24 | #include <mailutils/sys/imap.h> |
24 | 25 | ||
... | @@ -28,6 +29,9 @@ mu_imap_subscribe (mu_imap_t imap, const char *mailbox) | ... | @@ -28,6 +29,9 @@ mu_imap_subscribe (mu_imap_t imap, const char *mailbox) |
28 | char const *argv[2]; | 29 | char const *argv[2]; |
29 | static struct imap_command com; | 30 | static struct imap_command com; |
30 | 31 | ||
32 | if (!mailbox) | ||
33 | return EINVAL; | ||
34 | |||
31 | argv[0] = "SUBSCRIBE"; | 35 | argv[0] = "SUBSCRIBE"; |
32 | argv[1] = mailbox; | 36 | argv[1] = mailbox; |
33 | 37 | ... | ... |
libproto/imap/tests/.gitignore
0 → 100644
1 | imapfolder |
libproto/imap/tests/Makefile.am
0 → 100644
1 | ## This file is part of GNU Mailutils. | ||
2 | ## Copyright (C) 2003, 2005, 2006, 2007, 2010, 2011 Free Software | ||
3 | ## Foundation, Inc. | ||
4 | ## | ||
5 | ## GNU Mailutils is free software; you can redistribute it and/or | ||
6 | ## modify it under the terms of the GNU General Public License as | ||
7 | ## published by the Free Software Foundation; either version 3, or (at | ||
8 | ## your option) any later version. | ||
9 | ## | ||
10 | ## GNU Mailutils is distributed in the hope that it will be useful, but | ||
11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | ## General Public License for more details. | ||
14 | ## | ||
15 | ## You should have received a copy of the GNU General Public License | ||
16 | ## along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | noinst_PROGRAMS = \ | ||
19 | imapfolder | ||
20 | |||
21 | INCLUDES = @MU_LIB_COMMON_INCLUDES@ | ||
22 | LDADD = \ | ||
23 | @MU_LIB_IMAP@\ | ||
24 | @MU_LIB_AUTH@\ | ||
25 | @MU_AUTHLIBS@\ | ||
26 | @MU_LIB_MAILUTILS@ |
libproto/imap/tests/imapfolder.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2011 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <mailutils/mailutils.h> | ||
23 | |||
24 | struct command | ||
25 | { | ||
26 | char *verb; | ||
27 | int nargs; | ||
28 | char *args; | ||
29 | void (*handler) (mu_folder_t folder, char **argv); | ||
30 | }; | ||
31 | |||
32 | static int | ||
33 | _print_list_entry (void *item, void *data) | ||
34 | { | ||
35 | struct mu_list_response *resp = item; | ||
36 | mu_printf ("%c%c %c %4d %s\n", | ||
37 | (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY) ? 'd' : '-', | ||
38 | (resp->type & MU_FOLDER_ATTRIBUTE_FILE) ? 'f' : '-', | ||
39 | resp->separator ? resp->separator : ' ', | ||
40 | resp->level, | ||
41 | resp->name); | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static void | ||
46 | com_list (mu_folder_t folder, char **argv) | ||
47 | { | ||
48 | int rc; | ||
49 | mu_list_t list; | ||
50 | |||
51 | mu_printf ("listing %s %s\n", argv[0], argv[1]); | ||
52 | rc = mu_folder_list (folder, argv[0], argv[1], 0, &list); | ||
53 | if (rc) | ||
54 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_list", argv[0], rc); | ||
55 | else | ||
56 | { | ||
57 | mu_list_foreach (list, _print_list_entry, NULL); | ||
58 | mu_list_destroy (&list); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | static void | ||
63 | com_lsub (mu_folder_t folder, char **argv) | ||
64 | { | ||
65 | int rc; | ||
66 | mu_list_t list; | ||
67 | |||
68 | mu_printf ("listing subscriptions for '%s' '%s'\n", argv[0], argv[1]); | ||
69 | rc = mu_folder_lsub (folder, argv[0], argv[1], &list); | ||
70 | if (rc) | ||
71 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_lsub", argv[0], rc); | ||
72 | else | ||
73 | { | ||
74 | mu_list_foreach (list, _print_list_entry, NULL); | ||
75 | mu_list_destroy (&list); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | static void | ||
80 | com_delete (mu_folder_t folder, char **argv) | ||
81 | { | ||
82 | int rc; | ||
83 | |||
84 | mu_printf ("deleting %s\n", argv[0]); | ||
85 | rc = mu_folder_delete (folder, argv[0]); | ||
86 | if (rc) | ||
87 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_lsub", argv[0], rc); | ||
88 | else | ||
89 | mu_printf ("delete successful\n"); | ||
90 | } | ||
91 | |||
92 | static void | ||
93 | com_rename (mu_folder_t folder, char **argv) | ||
94 | { | ||
95 | int rc; | ||
96 | |||
97 | mu_printf ("renaming %s to %s\n", argv[0], argv[1]); | ||
98 | rc = mu_folder_rename (folder, argv[0], argv[1]); | ||
99 | if (rc) | ||
100 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_rename", argv[0], rc); | ||
101 | else | ||
102 | mu_printf ("rename successful\n"); | ||
103 | } | ||
104 | |||
105 | static void | ||
106 | com_subscribe (mu_folder_t folder, char **argv) | ||
107 | { | ||
108 | int rc; | ||
109 | |||
110 | mu_printf ("subscribing %s\n", argv[0]); | ||
111 | rc = mu_folder_subscribe (folder, argv[0]); | ||
112 | if (rc) | ||
113 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_subscribe", argv[0], rc); | ||
114 | else | ||
115 | mu_printf ("subscribe successful\n"); | ||
116 | } | ||
117 | |||
118 | static void | ||
119 | com_unsubscribe (mu_folder_t folder, char **argv) | ||
120 | { | ||
121 | int rc; | ||
122 | |||
123 | mu_printf ("unsubscribing %s\n", argv[0]); | ||
124 | rc = mu_folder_unsubscribe (folder, argv[0]); | ||
125 | if (rc) | ||
126 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_unsubscribe", argv[0], rc); | ||
127 | else | ||
128 | mu_printf ("unsubscribe successful\n"); | ||
129 | } | ||
130 | |||
131 | static struct command comtab[] = { | ||
132 | { "list", 2, "REF MBX", com_list }, | ||
133 | { "lsub", 2, "REF MBX", com_lsub }, | ||
134 | { "delete", 1, "MBX", com_delete }, | ||
135 | { "rename", 2, "OLD NEW", com_rename }, | ||
136 | { "delete", 1, "MBOX", com_delete }, | ||
137 | { "subscribe", 1, "MBX", com_subscribe }, | ||
138 | { "unsubscribe", 1, "MBX", com_unsubscribe }, | ||
139 | { NULL } | ||
140 | }; | ||
141 | |||
142 | static struct command * | ||
143 | find_command (const char *name) | ||
144 | { | ||
145 | struct command *cp; | ||
146 | |||
147 | for (cp = comtab; cp->verb; cp++) | ||
148 | if (strcmp (cp->verb, name) == 0) | ||
149 | return cp; | ||
150 | return NULL; | ||
151 | } | ||
152 | |||
153 | static void | ||
154 | usage () | ||
155 | { | ||
156 | struct command *cp; | ||
157 | |||
158 | mu_printf ( | ||
159 | "usage: %s [debug=SPEC] url=URL OP ARG [ARG...] [OP ARG [ARG...]...]\n", | ||
160 | mu_program_name); | ||
161 | mu_printf ("OPerations and corresponding ARGuments are:\n"); | ||
162 | for (cp = comtab; cp->verb; cp++) | ||
163 | mu_printf (" %s %s\n", cp->verb, cp->args); | ||
164 | } | ||
165 | |||
166 | int | ||
167 | main (int argc, char **argv) | ||
168 | { | ||
169 | int i; | ||
170 | int rc; | ||
171 | mu_folder_t folder; | ||
172 | char *fname = NULL; | ||
173 | |||
174 | mu_set_program_name (argv[0]); | ||
175 | mu_registrar_record (mu_imap_record); | ||
176 | mu_registrar_record (mu_imaps_record); | ||
177 | |||
178 | if (argc == 1) | ||
179 | { | ||
180 | usage (); | ||
181 | exit (0); | ||
182 | } | ||
183 | |||
184 | for (i = 1; i < argc; i++) | ||
185 | { | ||
186 | if (strncmp (argv[i], "debug=", 6) == 0) | ||
187 | mu_debug_parse_spec (argv[i] + 6); | ||
188 | else if (strncmp (argv[i], "url=", 4) == 0) | ||
189 | fname = argv[i] + 4; | ||
190 | else | ||
191 | break; | ||
192 | } | ||
193 | |||
194 | if (!fname) | ||
195 | { | ||
196 | mu_error ("URL not specified"); | ||
197 | exit (1); | ||
198 | } | ||
199 | |||
200 | rc = mu_folder_create (&folder, fname); | ||
201 | if (rc) | ||
202 | { | ||
203 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_create", fname, rc); | ||
204 | return 1; | ||
205 | } | ||
206 | |||
207 | rc = mu_folder_open (folder, MU_STREAM_READ); | ||
208 | if (rc) | ||
209 | { | ||
210 | mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_open", fname, rc); | ||
211 | return 1; | ||
212 | } | ||
213 | |||
214 | while (i < argc) | ||
215 | { | ||
216 | char *comargs[2]; | ||
217 | struct command *cmd; | ||
218 | |||
219 | cmd = find_command (argv[i]); | ||
220 | if (!cmd) | ||
221 | { | ||
222 | mu_error ("unknown command %s\n", argv[i]); | ||
223 | break; | ||
224 | } | ||
225 | |||
226 | i++; | ||
227 | if (i + cmd->nargs > argc) | ||
228 | { | ||
229 | mu_error ("not enough arguments for %s", cmd->verb); | ||
230 | break; | ||
231 | } | ||
232 | memcpy (comargs, argv + i, cmd->nargs * sizeof (comargs[0])); | ||
233 | i += cmd->nargs; | ||
234 | |||
235 | cmd->handler (folder, comargs); | ||
236 | } | ||
237 | |||
238 | mu_folder_close (folder); | ||
239 | mu_folder_destroy (&folder); | ||
240 | |||
241 | return 0; | ||
242 | } |
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | # include <config.h> | 19 | # include <config.h> |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #include <errno.h> | ||
22 | #include <mailutils/imap.h> | 23 | #include <mailutils/imap.h> |
23 | #include <mailutils/sys/imap.h> | 24 | #include <mailutils/sys/imap.h> |
24 | 25 | ||
... | @@ -28,6 +29,9 @@ mu_imap_unsubscribe (mu_imap_t imap, const char *mailbox) | ... | @@ -28,6 +29,9 @@ mu_imap_unsubscribe (mu_imap_t imap, const char *mailbox) |
28 | char const *argv[2]; | 29 | char const *argv[2]; |
29 | static struct imap_command com; | 30 | static struct imap_command com; |
30 | 31 | ||
32 | if (!mailbox) | ||
33 | return EINVAL; | ||
34 | |||
31 | argv[0] = "UNSUBSCRIBE"; | 35 | argv[0] = "UNSUBSCRIBE"; |
32 | argv[1] = mailbox; | 36 | argv[1] = mailbox; |
33 | 37 | ... | ... |
... | @@ -20,18 +20,15 @@ | ... | @@ -20,18 +20,15 @@ |
20 | # include <config.h> | 20 | # include <config.h> |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | #ifdef ENABLE_IMAP | ||
24 | |||
25 | #include <errno.h> | 23 | #include <errno.h> |
26 | #include <stdlib.h> | 24 | #include <stdlib.h> |
27 | #include <string.h> | 25 | #include <string.h> |
28 | #include <errno.h> | 26 | #include <errno.h> |
29 | #ifdef HAVE_STRINGS_H | 27 | #include <string.h> |
30 | # include <strings.h> | ||
31 | #endif | ||
32 | 28 | ||
33 | #include <mailutils/sys/registrar.h> | 29 | #include <mailutils/sys/registrar.h> |
34 | #include <mailutils/sys/url.h> | 30 | #include <mailutils/sys/url.h> |
31 | #include <mailutils/sys/imap.h> | ||
35 | 32 | ||
36 | static void url_imap_destroy (mu_url_t url); | 33 | static void url_imap_destroy (mu_url_t url); |
37 | 34 | ||
... | @@ -47,7 +44,7 @@ url_imap_destroy (mu_url_t url MU_ARG_UNUSED) | ... | @@ -47,7 +44,7 @@ url_imap_destroy (mu_url_t url MU_ARG_UNUSED) |
47 | */ | 44 | */ |
48 | 45 | ||
49 | int | 46 | int |
50 | _url_imap_init (mu_url_t url) | 47 | _mu_imap_url_init (mu_url_t url) |
51 | { | 48 | { |
52 | if (url->port == 0) | 49 | if (url->port == 0) |
53 | url->port = MU_IMAP_PORT; | 50 | url->port = MU_IMAP_PORT; |
... | @@ -78,7 +75,7 @@ _url_imap_init (mu_url_t url) | ... | @@ -78,7 +75,7 @@ _url_imap_init (mu_url_t url) |
78 | */ | 75 | */ |
79 | 76 | ||
80 | int | 77 | int |
81 | _url_imaps_init (mu_url_t url) | 78 | _mu_imaps_url_init (mu_url_t url) |
82 | { | 79 | { |
83 | if (url->port == 0) | 80 | if (url->port == 0) |
84 | url->port = MU_IMAPS_PORT; | 81 | url->port = MU_IMAPS_PORT; |
... | @@ -102,4 +99,3 @@ _url_imaps_init (mu_url_t url) | ... | @@ -102,4 +99,3 @@ _url_imaps_init (mu_url_t url) |
102 | return 0; | 99 | return 0; |
103 | } | 100 | } |
104 | 101 | ||
105 | #endif /* ENABLE_IMAP */ | ... | ... |
... | @@ -160,7 +160,7 @@ imap_prompt_env () | ... | @@ -160,7 +160,7 @@ imap_prompt_env () |
160 | 160 | ||
161 | /* Callbacks */ | 161 | /* Callbacks */ |
162 | static void | 162 | static void |
163 | imap_popauth_callback (void *data, int code, size_t sdat, void *pdat) | 163 | imap_preauth_callback (void *data, int code, size_t sdat, void *pdat) |
164 | { | 164 | { |
165 | const char *text = pdat; | 165 | const char *text = pdat; |
166 | if (text) | 166 | if (text) |
... | @@ -425,7 +425,7 @@ com_connect (int argc, char **argv) | ... | @@ -425,7 +425,7 @@ com_connect (int argc, char **argv) |
425 | 425 | ||
426 | /* Set callbacks */ | 426 | /* Set callbacks */ |
427 | mu_imap_register_callback_function (imap, MU_IMAP_CB_PREAUTH, | 427 | mu_imap_register_callback_function (imap, MU_IMAP_CB_PREAUTH, |
428 | imap_popauth_callback, | 428 | imap_preauth_callback, |
429 | NULL); | 429 | NULL); |
430 | mu_imap_register_callback_function (imap, MU_IMAP_CB_BYE, | 430 | mu_imap_register_callback_function (imap, MU_IMAP_CB_BYE, |
431 | imap_bye_callback, | 431 | imap_bye_callback, | ... | ... |
-
Please register or sign in to post a comment