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.
Showing
5 changed files
with
104 additions
and
22 deletions
... | @@ -56,7 +56,9 @@ int mu_imap_login (mu_imap_t imap, const char *user, const char *pass); | ... | @@ -56,7 +56,9 @@ int mu_imap_login (mu_imap_t imap, const char *user, const char *pass); |
56 | int mu_imap_logout (mu_imap_t imap); | 56 | int mu_imap_logout (mu_imap_t imap); |
57 | 57 | ||
58 | int mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc); | 58 | int mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc); |
59 | 59 | ||
60 | int mu_imap_noop (mu_imap_t imap); | ||
61 | |||
60 | int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier); | 62 | int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier); |
61 | int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier); | 63 | int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier); |
62 | 64 | ... | ... |
... | @@ -46,6 +46,7 @@ enum mu_imap_client_state | ... | @@ -46,6 +46,7 @@ enum mu_imap_client_state |
46 | MU_IMAP_ID_RX, | 46 | MU_IMAP_ID_RX, |
47 | MU_IMAP_SELECT_RX, | 47 | MU_IMAP_SELECT_RX, |
48 | MU_IMAP_STATUS_RX, | 48 | MU_IMAP_STATUS_RX, |
49 | MU_IMAP_NOOP_RX, | ||
49 | MU_IMAP_CLOSING | 50 | MU_IMAP_CLOSING |
50 | }; | 51 | }; |
51 | 52 | ... | ... |
libproto/imap/noop.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 <stdlib.h> | ||
23 | #include <mailutils/errno.h> | ||
24 | #include <mailutils/imap.h> | ||
25 | #include <mailutils/sys/imap.h> | ||
26 | |||
27 | int | ||
28 | mu_imap_noop (mu_imap_t imap) | ||
29 | { | ||
30 | int status; | ||
31 | |||
32 | if (imap == NULL) | ||
33 | return EINVAL; | ||
34 | if (!imap->io) | ||
35 | return MU_ERR_NO_TRANSPORT; | ||
36 | if (imap->state != MU_IMAP_CONNECTED) | ||
37 | return MU_ERR_SEQ; | ||
38 | |||
39 | switch (imap->state) | ||
40 | { | ||
41 | case MU_IMAP_CONNECTED: | ||
42 | status = _mu_imap_tag_next (imap); | ||
43 | MU_IMAP_CHECK_EAGAIN (imap, status); | ||
44 | status = mu_imapio_printf (imap->io, "%s NOOP\r\n", imap->tag_str); | ||
45 | MU_IMAP_CHECK_ERROR (imap, status); | ||
46 | MU_IMAP_FCLR (imap, MU_IMAP_RESP); | ||
47 | imap->state = MU_IMAP_NOOP_RX; | ||
48 | |||
49 | case MU_IMAP_NOOP_RX: | ||
50 | status = _mu_imap_response (imap, NULL, NULL); | ||
51 | MU_IMAP_CHECK_EAGAIN (imap, status); | ||
52 | switch (imap->resp_code) | ||
53 | { | ||
54 | case MU_IMAP_OK: | ||
55 | status = 0; | ||
56 | break; | ||
57 | |||
58 | case MU_IMAP_NO: | ||
59 | status = MU_ERR_FAILURE; | ||
60 | break; | ||
61 | |||
62 | case MU_IMAP_BAD: | ||
63 | status = MU_ERR_BADREPLY; | ||
64 | break; | ||
65 | } | ||
66 | imap->state = MU_IMAP_CONNECTED; | ||
67 | break; | ||
68 | |||
69 | default: | ||
70 | status = EINPROGRESS; | ||
71 | } | ||
72 | return status; | ||
73 | } | ||
74 |
... | @@ -112,6 +112,16 @@ com_verbose (int argc, char **argv) | ... | @@ -112,6 +112,16 @@ com_verbose (int argc, char **argv) |
112 | 112 | ||
113 | } | 113 | } |
114 | 114 | ||
115 | static void | ||
116 | report_failure (const char *what, int status) | ||
117 | { | ||
118 | const char *str; | ||
119 | |||
120 | mu_error (_("%s failed: %s"), what, mu_strerror (status)); | ||
121 | if (mu_imap_strerror (imap, &str) == 0) | ||
122 | mu_error (_("server reply: %s"), str); | ||
123 | } | ||
124 | |||
115 | static int connect_argc; | 125 | static int connect_argc; |
116 | static char **connect_argv; | 126 | static char **connect_argv; |
117 | #define host connect_argv[0] | 127 | #define host connect_argv[0] |
... | @@ -425,13 +435,7 @@ com_login (int argc, char **argv) | ... | @@ -425,13 +435,7 @@ com_login (int argc, char **argv) |
425 | if (status == 0) | 435 | if (status == 0) |
426 | imap_prompt_env (); | 436 | imap_prompt_env (); |
427 | else | 437 | else |
428 | { | 438 | report_failure ("login", status); |
429 | const char *str; | ||
430 | |||
431 | mu_error (_("authentication failed: %s"), mu_strerror (status)); | ||
432 | if (mu_imap_strerror (imap, &str) == 0) | ||
433 | mu_error (_("server reply: %s"), str); | ||
434 | } | ||
435 | return 0; | 439 | return 0; |
436 | } | 440 | } |
437 | 441 | ||
... | @@ -532,13 +536,7 @@ select_mbox (int argc, char **argv, int writable) | ... | @@ -532,13 +536,7 @@ select_mbox (int argc, char **argv, int writable) |
532 | imap_prompt_env (); | 536 | imap_prompt_env (); |
533 | } | 537 | } |
534 | else | 538 | else |
535 | { | 539 | report_failure ("select", status); |
536 | const char *str; | ||
537 | |||
538 | mu_error (_("select failed: %s"), mu_strerror (status)); | ||
539 | if (mu_imap_strerror (imap, &str) == 0) | ||
540 | mu_error (_("server reply: %s"), str); | ||
541 | } | ||
542 | return 0; | 540 | return 0; |
543 | } | 541 | } |
544 | 542 | ||
... | @@ -578,13 +576,16 @@ com_status (int argc, char **argv) | ... | @@ -578,13 +576,16 @@ com_status (int argc, char **argv) |
578 | print_imap_stats (&st); | 576 | print_imap_stats (&st); |
579 | } | 577 | } |
580 | else | 578 | else |
581 | { | 579 | report_failure ("status", status); |
582 | const char *str; | 580 | return 0; |
583 | 581 | } | |
584 | mu_error (_("status failed: %s"), mu_strerror (status)); | 582 | |
585 | if (mu_imap_strerror (imap, &str) == 0) | 583 | static int |
586 | mu_error (_("server reply: %s"), str); | 584 | com_noop (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED) |
587 | } | 585 | { |
586 | int status = mu_imap_noop (imap); | ||
587 | if (status) | ||
588 | report_failure ("noop", status); | ||
588 | return 0; | 589 | return 0; |
589 | } | 590 | } |
590 | 591 | ||
... | @@ -613,6 +614,9 @@ struct mutool_command imap_comtab[] = { | ... | @@ -613,6 +614,9 @@ struct mutool_command imap_comtab[] = { |
613 | { "id", 1, -1, com_id, | 614 | { "id", 1, -1, com_id, |
614 | N_("[-test KW] [ARG [ARG...]]"), | 615 | N_("[-test KW] [ARG [ARG...]]"), |
615 | N_("send ID command") }, | 616 | N_("send ID command") }, |
617 | { "noop", 1, 1, com_noop, | ||
618 | NULL, | ||
619 | N_("no operation (keepalive)") }, | ||
616 | { "select", 1, 2, com_select, | 620 | { "select", 1, 2, com_select, |
617 | N_("[MBOX]"), | 621 | N_("[MBOX]"), |
618 | N_("select a mailbox") }, | 622 | N_("select a mailbox") }, | ... | ... |
-
Please register or sign in to post a comment