Commit bc02e5c2 bc02e5c2d416789b39aa538c3213b3365f3fab75 by Sergey Poznyakoff

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.
1 parent 31459010
......@@ -91,6 +91,9 @@ int mu_imap_list (mu_imap_t imap, const char *refname, const char *mboxname,
mu_list_t retlist);
int mu_imap_list_new (mu_imap_t imap, const char *refname, const char *mboxname,
mu_list_t *plist);
int mu_imap_subscribe (mu_imap_t imap, const char *mailbox);
int mu_imap_unsubscribe (mu_imap_t imap, const char *mailbox);
int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier);
int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier);
......
......@@ -67,6 +67,8 @@ enum mu_imap_client_state
MU_IMAP_CLIENT_EXPUNGE_RX,
MU_IMAP_CLIENT_APPEND_RX,
MU_IMAP_CLIENT_LIST_RX,
MU_IMAP_CLIENT_SUBSCRIBE_RX,
MU_IMAP_CLIENT_UNSUBSCRIBE_RX,
MU_IMAP_CLIENT_CLOSING
};
......
......@@ -61,7 +61,9 @@ libmu_imap_la_SOURCES = \
state.c\
status.c\
store.c\
subscribe.c\
tag.c\
trace.c\
unselect.c
unselect.c\
unsubscribe.c
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2011 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/imap.h>
#include <mailutils/sys/imap.h>
int
mu_imap_subscribe (mu_imap_t imap, const char *mailbox)
{
char const *argv[2];
static struct imap_command com;
argv[0] = "SUBSCRIBE";
argv[1] = mailbox;
com.session_state = MU_IMAP_SESSION_AUTH;
com.capa = NULL;
com.rx_state = MU_IMAP_CLIENT_SUBSCRIBE_RX;
com.argc = 2;
com.argv = argv;
com.extra = NULL;
com.tagged_handler = NULL;
com.untagged_handler = NULL;
return mu_imap_gencom (imap, &com);
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2011 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <mailutils/imap.h>
#include <mailutils/sys/imap.h>
int
mu_imap_unsubscribe (mu_imap_t imap, const char *mailbox)
{
char const *argv[2];
static struct imap_command com;
argv[0] = "UNSUBSCRIBE";
argv[1] = mailbox;
com.session_state = MU_IMAP_SESSION_AUTH;
com.capa = NULL;
com.rx_state = MU_IMAP_CLIENT_UNSUBSCRIBE_RX;
com.argc = 2;
com.argv = argv;
com.extra = NULL;
com.tagged_handler = NULL;
com.untagged_handler = NULL;
return mu_imap_gencom (imap, &com);
}
......@@ -818,6 +818,24 @@ com_create (int argc, char **argv)
}
static int
com_subscribe (int argc, char **argv)
{
int status = mu_imap_subscribe (imap, argv[1]);
if (status)
report_failure ("subscribe", status);
return 0;
}
static int
com_unsubscribe (int argc, char **argv)
{
int status = mu_imap_unsubscribe (imap, argv[1]);
if (status)
report_failure ("unsubscribe", status);
return 0;
}
static int
com_append (int argc, char **argv)
{
struct tm tmbuf, *tm = NULL;
......@@ -1023,6 +1041,14 @@ struct mutool_command imap_comtab[] = {
com_list,
N_("REF MBOX"),
N_("List matching mailboxes") },
{ "subscribe", 2, 2, 0,
com_subscribe,
N_("MBOX"),
N_("Subscribe to a mailbox") },
{ "unsubscribe", 2, 2, 0,
com_unsubscribe,
N_("MBOX"),
N_("Remove mailbox from subscription list") },
{ "quit", 1, 1, 0,
com_logout,
NULL,
......