Imap client: Implement SUBSCRIBE and UNSUBSCRIBE.
* include/mailutils/imap.h (mu_imap_subscribe) (mu_imap_unsubscribe): New protos. * include/mailutils/sys/imap.h (MU_IMAP_CLIENT_SUBSCRIBE_RX) (MU_IMAP_CLIENT_UNSUBSCRIBE_RX): New states. * libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Add subscribe.c and unsubscribe.c * libproto/imap/subscribe.c: New file. * libproto/imap/unsubscribe.c: New file. * mu/imap.c: Implement subscribe/unsubscribe.
Showing
6 changed files
with
124 additions
and
1 deletions
... | @@ -91,6 +91,9 @@ int mu_imap_list (mu_imap_t imap, const char *refname, const char *mboxname, | ... | @@ -91,6 +91,9 @@ int mu_imap_list (mu_imap_t imap, const char *refname, const char *mboxname, |
91 | mu_list_t retlist); | 91 | mu_list_t retlist); |
92 | int mu_imap_list_new (mu_imap_t imap, const char *refname, const char *mboxname, | 92 | int mu_imap_list_new (mu_imap_t imap, const char *refname, const char *mboxname, |
93 | mu_list_t *plist); | 93 | mu_list_t *plist); |
94 | |||
95 | int mu_imap_subscribe (mu_imap_t imap, const char *mailbox); | ||
96 | int mu_imap_unsubscribe (mu_imap_t imap, const char *mailbox); | ||
94 | 97 | ||
95 | int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier); | 98 | int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier); |
96 | int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier); | 99 | int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier); | ... | ... |
... | @@ -67,6 +67,8 @@ enum mu_imap_client_state | ... | @@ -67,6 +67,8 @@ enum mu_imap_client_state |
67 | MU_IMAP_CLIENT_EXPUNGE_RX, | 67 | MU_IMAP_CLIENT_EXPUNGE_RX, |
68 | MU_IMAP_CLIENT_APPEND_RX, | 68 | MU_IMAP_CLIENT_APPEND_RX, |
69 | MU_IMAP_CLIENT_LIST_RX, | 69 | MU_IMAP_CLIENT_LIST_RX, |
70 | MU_IMAP_CLIENT_SUBSCRIBE_RX, | ||
71 | MU_IMAP_CLIENT_UNSUBSCRIBE_RX, | ||
70 | MU_IMAP_CLIENT_CLOSING | 72 | MU_IMAP_CLIENT_CLOSING |
71 | }; | 73 | }; |
72 | 74 | ... | ... |
libproto/imap/subscribe.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/imap.h> | ||
23 | #include <mailutils/sys/imap.h> | ||
24 | |||
25 | int | ||
26 | mu_imap_subscribe (mu_imap_t imap, const char *mailbox) | ||
27 | { | ||
28 | char const *argv[2]; | ||
29 | static struct imap_command com; | ||
30 | |||
31 | argv[0] = "SUBSCRIBE"; | ||
32 | argv[1] = mailbox; | ||
33 | |||
34 | com.session_state = MU_IMAP_SESSION_AUTH; | ||
35 | com.capa = NULL; | ||
36 | com.rx_state = MU_IMAP_CLIENT_SUBSCRIBE_RX; | ||
37 | com.argc = 2; | ||
38 | com.argv = argv; | ||
39 | com.extra = NULL; | ||
40 | com.tagged_handler = NULL; | ||
41 | com.untagged_handler = NULL; | ||
42 | |||
43 | return mu_imap_gencom (imap, &com); | ||
44 | } | ||
45 |
libproto/imap/unsubscribe.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/imap.h> | ||
23 | #include <mailutils/sys/imap.h> | ||
24 | |||
25 | int | ||
26 | mu_imap_unsubscribe (mu_imap_t imap, const char *mailbox) | ||
27 | { | ||
28 | char const *argv[2]; | ||
29 | static struct imap_command com; | ||
30 | |||
31 | argv[0] = "UNSUBSCRIBE"; | ||
32 | argv[1] = mailbox; | ||
33 | |||
34 | com.session_state = MU_IMAP_SESSION_AUTH; | ||
35 | com.capa = NULL; | ||
36 | com.rx_state = MU_IMAP_CLIENT_UNSUBSCRIBE_RX; | ||
37 | com.argc = 2; | ||
38 | com.argv = argv; | ||
39 | com.extra = NULL; | ||
40 | com.tagged_handler = NULL; | ||
41 | com.untagged_handler = NULL; | ||
42 | |||
43 | return mu_imap_gencom (imap, &com); | ||
44 | } | ||
45 |
... | @@ -818,6 +818,24 @@ com_create (int argc, char **argv) | ... | @@ -818,6 +818,24 @@ com_create (int argc, char **argv) |
818 | } | 818 | } |
819 | 819 | ||
820 | static int | 820 | static int |
821 | com_subscribe (int argc, char **argv) | ||
822 | { | ||
823 | int status = mu_imap_subscribe (imap, argv[1]); | ||
824 | if (status) | ||
825 | report_failure ("subscribe", status); | ||
826 | return 0; | ||
827 | } | ||
828 | |||
829 | static int | ||
830 | com_unsubscribe (int argc, char **argv) | ||
831 | { | ||
832 | int status = mu_imap_unsubscribe (imap, argv[1]); | ||
833 | if (status) | ||
834 | report_failure ("unsubscribe", status); | ||
835 | return 0; | ||
836 | } | ||
837 | |||
838 | static int | ||
821 | com_append (int argc, char **argv) | 839 | com_append (int argc, char **argv) |
822 | { | 840 | { |
823 | struct tm tmbuf, *tm = NULL; | 841 | struct tm tmbuf, *tm = NULL; |
... | @@ -1023,6 +1041,14 @@ struct mutool_command imap_comtab[] = { | ... | @@ -1023,6 +1041,14 @@ struct mutool_command imap_comtab[] = { |
1023 | com_list, | 1041 | com_list, |
1024 | N_("REF MBOX"), | 1042 | N_("REF MBOX"), |
1025 | N_("List matching mailboxes") }, | 1043 | N_("List matching mailboxes") }, |
1044 | { "subscribe", 2, 2, 0, | ||
1045 | com_subscribe, | ||
1046 | N_("MBOX"), | ||
1047 | N_("Subscribe to a mailbox") }, | ||
1048 | { "unsubscribe", 2, 2, 0, | ||
1049 | com_unsubscribe, | ||
1050 | N_("MBOX"), | ||
1051 | N_("Remove mailbox from subscription list") }, | ||
1026 | { "quit", 1, 1, 0, | 1052 | { "quit", 1, 1, 0, |
1027 | com_logout, | 1053 | com_logout, |
1028 | NULL, | 1054 | NULL, | ... | ... |
-
Please register or sign in to post a comment