Commit e5ec3ce6 e5ec3ce6c45278e853453c2332dbc140fe2a0ac6 by Sergey Poznyakoff

imap client: implement noop.

* include/mailutils/imap.h (mu_imap_noop): New proto.
* include/mailutils/sys/imap.h (mu_imap_client_state)
<MU_IMAP_NOOP_RX>: New state.
* libproto/imap/noop.c: New file.
* libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Add noop.c
* mu/imap.c (report_failure): New function.
(com_login,select_mbox,com_status): Use report_failure for
error reporting.
(com_noop): New function.
(imap_comtab)<noop>: New command.
1 parent 1981c519
......@@ -56,7 +56,9 @@ int mu_imap_login (mu_imap_t imap, const char *user, const char *pass);
int mu_imap_logout (mu_imap_t imap);
int mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc);
int mu_imap_noop (mu_imap_t imap);
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);
......
......@@ -46,6 +46,7 @@ enum mu_imap_client_state
MU_IMAP_ID_RX,
MU_IMAP_SELECT_RX,
MU_IMAP_STATUS_RX,
MU_IMAP_NOOP_RX,
MU_IMAP_CLOSING
};
......
......@@ -40,6 +40,7 @@ libmu_imap_la_SOURCES = \
id.c\
login.c\
logout.c\
noop.c\
resplist.c\
response.c\
resproc.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 <stdlib.h>
#include <mailutils/errno.h>
#include <mailutils/imap.h>
#include <mailutils/sys/imap.h>
int
mu_imap_noop (mu_imap_t imap)
{
int status;
if (imap == NULL)
return EINVAL;
if (!imap->io)
return MU_ERR_NO_TRANSPORT;
if (imap->state != MU_IMAP_CONNECTED)
return MU_ERR_SEQ;
switch (imap->state)
{
case MU_IMAP_CONNECTED:
status = _mu_imap_tag_next (imap);
MU_IMAP_CHECK_EAGAIN (imap, status);
status = mu_imapio_printf (imap->io, "%s NOOP\r\n", imap->tag_str);
MU_IMAP_CHECK_ERROR (imap, status);
MU_IMAP_FCLR (imap, MU_IMAP_RESP);
imap->state = MU_IMAP_NOOP_RX;
case MU_IMAP_NOOP_RX:
status = _mu_imap_response (imap, NULL, NULL);
MU_IMAP_CHECK_EAGAIN (imap, status);
switch (imap->resp_code)
{
case MU_IMAP_OK:
status = 0;
break;
case MU_IMAP_NO:
status = MU_ERR_FAILURE;
break;
case MU_IMAP_BAD:
status = MU_ERR_BADREPLY;
break;
}
imap->state = MU_IMAP_CONNECTED;
break;
default:
status = EINPROGRESS;
}
return status;
}
......@@ -112,6 +112,16 @@ com_verbose (int argc, char **argv)
}
static void
report_failure (const char *what, int status)
{
const char *str;
mu_error (_("%s failed: %s"), what, mu_strerror (status));
if (mu_imap_strerror (imap, &str) == 0)
mu_error (_("server reply: %s"), str);
}
static int connect_argc;
static char **connect_argv;
#define host connect_argv[0]
......@@ -425,13 +435,7 @@ com_login (int argc, char **argv)
if (status == 0)
imap_prompt_env ();
else
{
const char *str;
mu_error (_("authentication failed: %s"), mu_strerror (status));
if (mu_imap_strerror (imap, &str) == 0)
mu_error (_("server reply: %s"), str);
}
report_failure ("login", status);
return 0;
}
......@@ -532,13 +536,7 @@ select_mbox (int argc, char **argv, int writable)
imap_prompt_env ();
}
else
{
const char *str;
mu_error (_("select failed: %s"), mu_strerror (status));
if (mu_imap_strerror (imap, &str) == 0)
mu_error (_("server reply: %s"), str);
}
report_failure ("select", status);
return 0;
}
......@@ -578,13 +576,16 @@ com_status (int argc, char **argv)
print_imap_stats (&st);
}
else
{
const char *str;
mu_error (_("status failed: %s"), mu_strerror (status));
if (mu_imap_strerror (imap, &str) == 0)
mu_error (_("server reply: %s"), str);
}
report_failure ("status", status);
return 0;
}
static int
com_noop (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
{
int status = mu_imap_noop (imap);
if (status)
report_failure ("noop", status);
return 0;
}
......@@ -613,6 +614,9 @@ struct mutool_command imap_comtab[] = {
{ "id", 1, -1, com_id,
N_("[-test KW] [ARG [ARG...]]"),
N_("send ID command") },
{ "noop", 1, 1, com_noop,
NULL,
N_("no operation (keepalive)") },
{ "select", 1, 2, com_select,
N_("[MBOX]"),
N_("select a mailbox") },
......