commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-471-ge5ec3ce


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-471-ge5ec3ce
Date: Thu, 24 Nov 2011 23:08:25 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=e5ec3ce6c45278e853453c2332dbc140fe2a0ac6

The branch, master has been updated
       via  e5ec3ce6c45278e853453c2332dbc140fe2a0ac6 (commit)
       via  1981c5192804ef834c7abdef68ed22b1e967c594 (commit)
       via  4faa3659d6140a25f05cf03e27429c7f1408851c (commit)
      from  80b012f7f89ca6acbf1191ef1b8073239509b941 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e5ec3ce6c45278e853453c2332dbc140fe2a0ac6
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Nov 25 01:06:52 2011 +0200

    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.

commit 1981c5192804ef834c7abdef68ed22b1e967c594
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Nov 25 00:54:46 2011 +0200

    Minor change.
    
    * mu/imap.c: Add missing gettext markers.

commit 4faa3659d6140a25f05cf03e27429c7f1408851c
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Nov 25 00:36:29 2011 +0200

    Process untagged responses synchronously.
    
    * include/mailutils/imap.h (mu_imap_response_action_t): Move to
    sys/imap.h
    (mu_imap_foreach_response): Remove.
    * include/mailutils/sys/imap.h (_mu_imap)<untagged_resp>: Remove.
    All sources updated.
    (_mu_imap_response): Change sigature.
    (_mu_imap_untagged_response_clear)
    (_mu_imap_untagged_response_add): Remove.
    (_mu_imap_untagged_response_to_list)
    (_mu_imap_process_untagged_response): New protos.
    * libproto/imap/connect.c: Use _mu_imap_untagged_response_to_list
    and _mu_imap_process_untagged_response.
    * libproto/imap/create.c: Update.
    * libproto/imap/destroy.c: Update.
    * libproto/imap/disconnect.c: Update.
    * libproto/imap/capability.c: Update calls to _mu_imap_response
    * libproto/imap/id.c: Likewise.
    * libproto/imap/login.c: Likewise.
    * libproto/imap/logout.c: Likewise.
    * libproto/imap/select.c: Likewise.
    * libproto/imap/status.c: Likewise.
    * libproto/imap/resplist.c (_mu_imap_untagged_response_clear): Remove.
    (_mu_imap_untagged_response_add): Remove.
    (_mu_imap_untagged_response_to_list): New function.
    * libproto/imap/response.c (_mu_imap_response): Take response-processing
    function and its closure as arguments.
    * libproto/imap/resproc.c (_mu_imap_process_untagged_response): New
    function.
    (mu_imap_foreach_response): Remove.
    
    * mu/imap.c: Install a BYE callback.

-----------------------------------------------------------------------

Summary of changes:
 include/mailutils/imap.h           |   11 +----
 include/mailutils/sys/imap.h       |   21 ++++++----
 libproto/imap/Makefile.am          |    1 +
 libproto/imap/capability.c         |   19 +++-----
 libproto/imap/connect.c            |   13 ++++--
 libproto/imap/create.c             |    2 -
 libproto/imap/destroy.c            |    1 -
 libproto/imap/disconnect.c         |    1 -
 libproto/imap/id.c                 |   46 +++++++++------------
 libproto/imap/login.c              |    4 +-
 libproto/imap/logout.c             |    2 +-
 libproto/imap/{logout.c => noop.c} |   35 +++++++++++-----
 libproto/imap/resplist.c           |   15 +-----
 libproto/imap/response.c           |   13 ++++--
 libproto/imap/resproc.c            |   30 +++----------
 libproto/imap/select.c             |    5 +-
 libproto/imap/status.c             |   35 ++++++++--------
 mu/imap.c                          |   79 ++++++++++++++++++++++--------------
 18 files changed, 164 insertions(+), 169 deletions(-)
 copy libproto/imap/{logout.c => noop.c} (69%)

diff --git a/include/mailutils/imap.h b/include/mailutils/imap.h
index 01faba0..5448ef2 100644
--- a/include/mailutils/imap.h
+++ b/include/mailutils/imap.h
@@ -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);
 
@@ -101,13 +103,6 @@ int mu_imap_status (mu_imap_t imap, const char *mbox, 
struct mu_imap_stat *ps);
 
 extern struct mu_kwd _mu_imap_status_name_table[];
 
-typedef void (*mu_imap_response_action_t) (mu_imap_t imap, mu_list_t resp,
-                                          void *data);
-
-int mu_imap_foreach_response (mu_imap_t imap, mu_imap_response_action_t fun,
-                             void *data);
-  
-
   /* The following five callbacks correspond to members of struct
      mu_imap_stat and take a pointer to struct mu_imap_stat as their
      only argument. */
diff --git a/include/mailutils/sys/imap.h b/include/mailutils/sys/imap.h
index c7c9a35..58bffd4 100644
--- a/include/mailutils/sys/imap.h
+++ b/include/mailutils/sys/imap.h
@@ -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
   };
 
@@ -63,9 +64,6 @@ struct _mu_imap
     /* Holds the recect response code */
     enum mu_imap_response resp_code;
     
-    /* Untagged responses */
-    mu_list_t untagged_resp;
-
     /* Error string (if any) */
     char *errstr;
     size_t errsize;
@@ -162,11 +160,18 @@ void _mu_imap_clrerrstr (mu_imap_t imap);
 int _mu_imap_tag_next (mu_imap_t imap);
 int _mu_imap_tag_clr (mu_imap_t imap);
 
-int _mu_imap_response (mu_imap_t imap);
-
-int _mu_imap_untagged_response_clear (mu_imap_t imap);
-int _mu_imap_untagged_response_add (mu_imap_t imap);
-
+
+typedef void (*mu_imap_response_action_t) (mu_imap_t imap, mu_list_t resp,
+                                          void *data);
+
+int _mu_imap_untagged_response_to_list (mu_imap_t imap, mu_list_t *plist);
+int _mu_imap_process_untagged_response (mu_imap_t imap, mu_list_t list,
+                                       mu_imap_response_action_t fun,
+                                       void *data);
+ 
+int _mu_imap_response (mu_imap_t imap, mu_imap_response_action_t fun,
+                      void *data);
+  
 int _mu_imap_list_element_is_string (struct imap_list_element *elt,
                                     const char *str);
 int _mu_imap_collect_flags (struct imap_list_element *arg, int *res);
diff --git a/libproto/imap/Makefile.am b/libproto/imap/Makefile.am
index ee89f90..c14b76d 100644
--- a/libproto/imap/Makefile.am
+++ b/libproto/imap/Makefile.am
@@ -40,6 +40,7 @@ libmu_imap_la_SOURCES = \
  id.c\
  login.c\
  logout.c\
+ noop.c\
  resplist.c\
  response.c\
  resproc.c\
diff --git a/libproto/imap/capability.c b/libproto/imap/capability.c
index 14dff87..a90d5f9 100644
--- a/libproto/imap/capability.c
+++ b/libproto/imap/capability.c
@@ -115,23 +115,18 @@ mu_imap_capability (mu_imap_t imap, int reread, 
mu_iterator_t *piter)
       imap->state = MU_IMAP_CAPABILITY_RX;
 
     case MU_IMAP_CAPABILITY_RX:
-      status = _mu_imap_response (imap);
+      status = _mu_imap_response (imap, _capability_response_action,
+                                 NULL);
+      imap->state = MU_IMAP_CONNECTED;
       MU_IMAP_CHECK_EAGAIN (imap, status);
       if (imap->resp_code != MU_IMAP_OK)
        return MU_ERR_REPLY;
       else
        {
-         imap->state = MU_IMAP_CONNECTED;
-         status = mu_imap_foreach_response (imap,
-                                            _capability_response_action,
-                                            NULL);
-         if (status == 0)
-           {
-             if (piter)
-               status = mu_list_get_iterator (imap->capa, piter);
-             else
-               status = 0;
-           }
+         if (piter)
+           status = mu_list_get_iterator (imap->capa, piter);
+         else
+           status = 0;
        }  
       break;
       
diff --git a/libproto/imap/connect.c b/libproto/imap/connect.c
index 552530b..e9be515 100644
--- a/libproto/imap/connect.c
+++ b/libproto/imap/connect.c
@@ -44,9 +44,6 @@ mu_imap_connect (mu_imap_t imap)
     return EINVAL;
 
   _mu_imap_clrerrstr (imap);
-  status = _mu_imap_untagged_response_clear (imap);
-  if (status)
-    return status;
   
   switch (imap->state)
     {
@@ -87,8 +84,14 @@ mu_imap_connect (mu_imap_t imap)
        }
       else
        {
-         _mu_imap_untagged_response_add (imap);
-         mu_imap_foreach_response (imap, NULL, NULL);
+         mu_list_t list;
+
+         status = _mu_imap_untagged_response_to_list (imap, &list);
+         if (status)
+           break;
+         _mu_imap_process_untagged_response (imap, list, NULL, NULL);
+         mu_list_destroy (&list);
+
          switch (imap->state)
            {
            case MU_IMAP_CONNECTED:
diff --git a/libproto/imap/create.c b/libproto/imap/create.c
index 96cc4ac..9b2743e 100644
--- a/libproto/imap/create.c
+++ b/libproto/imap/create.c
@@ -53,8 +53,6 @@ _mu_imap_init (mu_imap_t imap)
     {
       int rc;
       
-      if (imap->untagged_resp)
-       mu_list_clear (imap->untagged_resp);
       mu_list_destroy (&imap->capa);
       _mu_imap_clrerrstr (imap);
       rc = _mu_imap_tag_clr (imap);
diff --git a/libproto/imap/destroy.c b/libproto/imap/destroy.c
index ff8076f..3bf131e 100644
--- a/libproto/imap/destroy.c
+++ b/libproto/imap/destroy.c
@@ -39,7 +39,6 @@ mu_imap_destroy (mu_imap_t *pimap)
       if (imap->tag_buf)
        free (imap->tag_buf);
       
-      mu_list_destroy (&imap->untagged_resp);
       mu_list_destroy (&imap->capa);
       
       mu_imapio_destroy (&imap->io);
diff --git a/libproto/imap/disconnect.c b/libproto/imap/disconnect.c
index 6803008..7683b26 100644
--- a/libproto/imap/disconnect.c
+++ b/libproto/imap/disconnect.c
@@ -35,7 +35,6 @@ mu_imap_disconnect (mu_imap_t imap)
   imap->state = MU_IMAP_NO_STATE;
   MU_IMAP_FCLR (imap, MU_IMAP_RESP);
 
-  mu_list_clear (imap->untagged_resp);
   mu_list_clear (imap->capa);
   
   /* Close the stream.  */
diff --git a/libproto/imap/id.c b/libproto/imap/id.c
index 527cd69..05938ab 100644
--- a/libproto/imap/id.c
+++ b/libproto/imap/id.c
@@ -49,36 +49,30 @@ _id_mapper (void **itmv, size_t itmc, void *call_data)
 }
 
 static void
-_id_response_action (mu_imap_t imap, mu_list_t response, void *data)
+parse_id_reply (mu_imap_t imap, mu_list_t resp, void *data)
 {
-  mu_assoc_t assoc = data;
+  int rc;
+  mu_assoc_t *passoc = data;
   struct imap_list_element *elt;
 
-  elt = _mu_imap_list_at (response, 0);
+  if (!data)
+    return;
+  elt = _mu_imap_list_at (resp, 0);
   if (elt && _mu_imap_list_element_is_string (elt, "ID"))
     {
-      elt = _mu_imap_list_at (response, 1);
+      elt = _mu_imap_list_at (resp, 1);
       if (elt->type == imap_eltype_list)
-       mu_list_gmap (elt->v.list, _id_mapper, 2, assoc);
-    }
-}
+       {
+         mu_assoc_t assoc;
 
-static int
-parse_id_reply (mu_imap_t imap, mu_assoc_t *passoc)
-{
-  int rc;
-  mu_assoc_t assoc;
-  
-  rc = mu_assoc_create (&assoc, sizeof (char**), MU_ASSOC_ICASE);
-  if (rc)
-    return rc;
-  mu_assoc_set_free (assoc, _id_free);
-  
-  rc = mu_imap_foreach_response (imap, _id_response_action, assoc);
-  if (rc)
-    return rc;
-  *passoc = assoc;
-  return 0;
+         rc = mu_assoc_create (&assoc, sizeof (char**), MU_ASSOC_ICASE);
+         if (rc)
+           return;
+         mu_assoc_set_free (assoc, _id_free);
+         mu_list_gmap (elt->v.list, _id_mapper, 2, assoc);
+         *passoc = assoc;
+       }
+    }
 }
   
 int
@@ -130,14 +124,12 @@ mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t 
*passoc)
       imap->state = MU_IMAP_ID_RX;
 
     case MU_IMAP_ID_RX:
-      status = _mu_imap_response (imap);
+      status = _mu_imap_response (imap, parse_id_reply, passoc);
       MU_IMAP_CHECK_EAGAIN (imap, status);
       switch (imap->resp_code)
        {
        case MU_IMAP_OK:
-         imap->imap_state = MU_IMAP_STATE_AUTH;
-         if (passoc)
-           status = parse_id_reply (imap, passoc);
+         status = 0;
          break;
 
        case MU_IMAP_NO:
diff --git a/libproto/imap/login.c b/libproto/imap/login.c
index d4b05fd..b0d3597 100644
--- a/libproto/imap/login.c
+++ b/libproto/imap/login.c
@@ -54,7 +54,8 @@ mu_imap_login (mu_imap_t imap, const char *user, const char 
*pass)
       imap->state = MU_IMAP_LOGIN_RX;
 
     case MU_IMAP_LOGIN_RX:
-      status = _mu_imap_response (imap);
+      status = _mu_imap_response (imap, NULL, NULL);
+      imap->state = MU_IMAP_CONNECTED;
       MU_IMAP_CHECK_EAGAIN (imap, status);
       switch (imap->resp_code)
        {
@@ -70,7 +71,6 @@ mu_imap_login (mu_imap_t imap, const char *user, const char 
*pass)
          status = MU_ERR_BADREPLY;
          break;
        }
-      imap->state = MU_IMAP_CONNECTED;
       break;
 
     default:
diff --git a/libproto/imap/logout.c b/libproto/imap/logout.c
index 3565bb7..11bef62 100644
--- a/libproto/imap/logout.c
+++ b/libproto/imap/logout.c
@@ -47,7 +47,7 @@ mu_imap_logout (mu_imap_t imap)
       imap->state = MU_IMAP_LOGOUT_RX;
 
     case MU_IMAP_LOGOUT_RX:
-      status = _mu_imap_response (imap);
+      status = _mu_imap_response (imap, NULL, NULL);
       MU_IMAP_CHECK_EAGAIN (imap, status);
       imap->state = MU_IMAP_NO_STATE;
       imap->imap_state = MU_IMAP_STATE_LOGOUT;
diff --git a/libproto/imap/logout.c b/libproto/imap/noop.c
similarity index 69%
copy from libproto/imap/logout.c
copy to libproto/imap/noop.c
index 3565bb7..6d7accc 100644
--- a/libproto/imap/logout.c
+++ b/libproto/imap/noop.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   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
@@ -19,12 +19,13 @@
 # include <config.h>
 #endif
 
+#include <stdlib.h>
 #include <mailutils/errno.h>
-#include <mailutils/stream.h>
+#include <mailutils/imap.h>
 #include <mailutils/sys/imap.h>
 
 int
-mu_imap_logout (mu_imap_t imap)
+mu_imap_noop (mu_imap_t imap)
 {
   int status;
   
@@ -40,17 +41,29 @@ mu_imap_logout (mu_imap_t imap)
     case MU_IMAP_CONNECTED:
       status = _mu_imap_tag_next (imap);
       MU_IMAP_CHECK_EAGAIN (imap, status);
-      status = mu_imapio_printf (imap->io, "%s LOGOUT\r\n",
-                                imap->tag_str); 
-      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_LOGOUT_RX;
+      imap->state = MU_IMAP_NOOP_RX;
 
-    case MU_IMAP_LOGOUT_RX:
-      status = _mu_imap_response (imap);
+    case MU_IMAP_NOOP_RX:
+      status = _mu_imap_response (imap, NULL, NULL);
       MU_IMAP_CHECK_EAGAIN (imap, status);
-      imap->state = MU_IMAP_NO_STATE;
-      imap->imap_state = MU_IMAP_STATE_LOGOUT;
+      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:
diff --git a/libproto/imap/resplist.c b/libproto/imap/resplist.c
index de2e523..4a42633 100644
--- a/libproto/imap/resplist.c
+++ b/libproto/imap/resplist.c
@@ -55,16 +55,6 @@ _mu_imap_response_list_create (mu_imap_t imap, mu_list_t 
*plist)
   return 0;
 }
 
-int
-_mu_imap_untagged_response_clear (mu_imap_t imap)
-{
-  if (imap->untagged_resp)
-    mu_list_clear (imap->untagged_resp);
-  else
-    return _mu_imap_response_list_create (imap, &imap->untagged_resp);
-  return 0;
-}
-
 #define IS_LBRACE(p) ((p)[0] == '(')
 #define IS_RBRACE(p) ((p)[0] == ')')
 
@@ -235,7 +225,7 @@ _parse_element (struct parsebuf *pb)
 }
 
 int
-_mu_imap_untagged_response_add (mu_imap_t imap)
+_mu_imap_untagged_response_to_list (mu_imap_t imap, mu_list_t *plist)
 {
   struct imap_list_element *elt;
   struct parsebuf pb;
@@ -251,7 +241,8 @@ _mu_imap_untagged_response_add (mu_imap_t imap)
       imap->state = MU_IMAP_ERROR;
       return pb.pb_err;
     }
-  mu_list_append (imap->untagged_resp, elt);
+  *plist = elt->v.list;
+  free (elt);
   return 0;
 }
 
diff --git a/libproto/imap/response.c b/libproto/imap/response.c
index 0f959e2..653b074 100644
--- a/libproto/imap/response.c
+++ b/libproto/imap/response.c
@@ -35,7 +35,8 @@ response_to_errstr (mu_imap_t imap, size_t argc, char **argv)
 }
 
 int
-_mu_imap_response (mu_imap_t imap)
+_mu_imap_response (mu_imap_t imap, mu_imap_response_action_t fun,
+                  void *data)
 {
   int status = 0;
 
@@ -46,9 +47,6 @@ _mu_imap_response (mu_imap_t imap)
     return 0;
 
   _mu_imap_clrerrstr (imap);
-  status = _mu_imap_untagged_response_clear (imap);
-  if (status)
-    return status;
   
   while (1)
     {
@@ -68,7 +66,12 @@ _mu_imap_response (mu_imap_t imap)
            
          if (strcmp (wv[0], "*") == 0)
            {
-             _mu_imap_untagged_response_add (imap);/* FIXME: error checking */
+             mu_list_t list;
+             status = _mu_imap_untagged_response_to_list (imap, &list);
+             if (status)
+               break;
+             _mu_imap_process_untagged_response (imap, list, fun, data);
+             mu_list_destroy (&list);
              continue;
            }
          else if (strlen (wv[0]) == imap->tag_len &&
diff --git a/libproto/imap/resproc.c b/libproto/imap/resproc.c
index 3097795..d40d9b2 100644
--- a/libproto/imap/resproc.c
+++ b/libproto/imap/resproc.c
@@ -306,21 +306,15 @@ _process_unsolicited_response (mu_imap_t imap, mu_list_t 
resp)
   return 1;
 }
 
-static int
-_process_response (void *item, void *data)
+int
+_mu_imap_process_untagged_response (mu_imap_t imap, mu_list_t list,
+                                   mu_imap_response_action_t fun,
+                                   void *data)
 {
-  struct imap_list_element *elt = item;
-  struct response_closure *clos = data;
-
-  if (elt->type != imap_eltype_list)
-    {
-      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
-               ("ignoring string response \"%s\"", elt->v.string));
-    }
-  else if (_process_unsolicited_response (clos->imap, elt->v.list))
+  if (_process_unsolicited_response (imap, list))
     {
-      if (clos->fun)
-       clos->fun (clos->imap, elt->v.list, clos->data);
+      if (fun)
+       fun (imap, list, data);
       else
        mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
                  ("ignoring unexpected response"));
@@ -328,14 +322,4 @@ _process_response (void *item, void *data)
   return 0;
 }
 
-int
-mu_imap_foreach_response (mu_imap_t imap, mu_imap_response_action_t fun,
-                         void *data)
-{
-  struct response_closure clos;
-  clos.imap = imap;
-  clos.fun = fun;
-  clos.data = data;
-  return mu_list_foreach (imap->untagged_resp, _process_response, &clos);
-}
                          
diff --git a/libproto/imap/select.c b/libproto/imap/select.c
index 83a0926..5d30db3 100644
--- a/libproto/imap/select.c
+++ b/libproto/imap/select.c
@@ -111,7 +111,8 @@ mu_imap_select (mu_imap_t imap, const char *mbox, int 
writable,
       imap->state = MU_IMAP_SELECT_RX;
 
     case MU_IMAP_SELECT_RX:
-      status = _mu_imap_response (imap);
+      memset (&imap->mbox_stat, 0, sizeof (imap->mbox_stat));
+      status = _mu_imap_response (imap, _select_response_action, NULL);
       MU_IMAP_CHECK_EAGAIN (imap, status);
       switch (imap->resp_code)
        {
@@ -125,8 +126,6 @@ mu_imap_select (mu_imap_t imap, const char *mbox, int 
writable,
              return errno;
            }
          imap->mbox_writable = writable;
-         memset (&imap->mbox_stat, 0, sizeof (imap->mbox_stat));
-         mu_imap_foreach_response (imap, _select_response_action, NULL);
          if (ps)
            *ps = imap->mbox_stat;
          break;
diff --git a/libproto/imap/status.c b/libproto/imap/status.c
index 3870572..b8969ce 100644
--- a/libproto/imap/status.c
+++ b/libproto/imap/status.c
@@ -182,27 +182,26 @@ mu_imap_status (mu_imap_t imap, const char *mboxname, 
struct mu_imap_stat *ps)
       imap->state = MU_IMAP_STATUS_RX;
 
     case MU_IMAP_STATUS_RX:
-      status = _mu_imap_response (imap);
-      MU_IMAP_CHECK_EAGAIN (imap, status);
-      switch (imap->resp_code)
-       {
-       case MU_IMAP_OK:
+      {
+       struct status_data sd = { mboxname, ps };
+
+       status = _mu_imap_response (imap, _status_response_action, &sd);
+       MU_IMAP_CHECK_EAGAIN (imap, status);
+       switch (imap->resp_code)
          {
-           struct status_data sd = { mboxname, ps };
-           status = mu_imap_foreach_response (imap, _status_response_action,
-                                              &sd);
-         }
-         break;
+         case MU_IMAP_OK:
+           break;
 
-       case MU_IMAP_NO:
-         status = EACCES;
-         break;
+         case MU_IMAP_NO:
+           status = EACCES;
+           break;
 
-       case MU_IMAP_BAD:
-         status = MU_ERR_BADREPLY;
-         break;
-       }
-      imap->state = MU_IMAP_CONNECTED;
+         case MU_IMAP_BAD:
+           status = MU_ERR_BADREPLY;
+           break;
+         }
+       imap->state = MU_IMAP_CONNECTED;
+      }
       break;
 
     default:
diff --git a/mu/imap.c b/mu/imap.c
index 6fc0a24..892fb87 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -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]
@@ -162,6 +172,18 @@ imap_popauth_callback (void *data, int code, va_list ap)
   else
     mu_diag_output (MU_DIAG_INFO, _("session authenticated"));
 }
+
+static void
+imap_bye_callback (void *data, int code, va_list ap)
+{
+  int rcode = va_arg (ap, int);
+  const char *text = va_arg (ap, const char *);
+  if (text)
+    mu_diag_output (MU_DIAG_INFO, _("server is closing connection: %s"), text);
+  else
+    mu_diag_output (MU_DIAG_INFO, _("server is closing connection"));
+}
+
 
 static int
 com_disconnect (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
@@ -194,7 +216,7 @@ com_connect (int argc, char **argv)
 #ifdef WITH_TLS
            tls = 1;
 #else
-            mu_error ("TLS not supported");
+            mu_error (_("TLS not supported"));
            return 0;
 #endif
        }
@@ -240,7 +262,7 @@ com_connect (int argc, char **argv)
              mu_stream_unref (tcp);
              if (status)
                {
-                 mu_error ("cannot create TLS stream: %s",
+                 mu_error (_("cannot create TLS stream: %s"),
                            mu_strerror (status));
                  return 0;
                }
@@ -259,6 +281,9 @@ com_connect (int argc, char **argv)
          mu_imap_register_callback_function (imap, MU_IMAP_CB_PREAUTH,
                                              imap_popauth_callback,
                                              NULL);
+         mu_imap_register_callback_function (imap, MU_IMAP_CB_BYE,
+                                             imap_bye_callback,
+                                             NULL);
 
          
          status = mu_imap_connect (imap);
@@ -276,7 +301,7 @@ com_connect (int argc, char **argv)
        mu_imap_destroy (&imap);
     }
   else
-    mu_error ("Failed to create imap: %s", mu_strerror (status));
+    mu_error (_("Failed to create imap connection: %s"), mu_strerror (status));
   
   if (!status)
     {
@@ -308,7 +333,7 @@ com_logout (int argc MU_ARG_UNUSED, char **argv 
MU_ARG_UNUSED)
        }
     }
   else
-    mu_printf ("Try 'exit' to leave %s\n", mu_program_name);
+    mu_printf (_("Try 'exit' to leave %s\n"), mu_program_name);
   return status;
 }
 
@@ -346,11 +371,11 @@ com_capability (int argc, char **argv)
              if (*elt)
                mu_printf ("%s: %s\n", argv[i], elt);
              else
-               mu_printf ("%s is set\n", argv[i]);
+               mu_printf (_("%s is set\n"), argv[i]);
              break;
 
            case MU_ERR_NOENT:
-             mu_printf ("%s is not set\n", argv[i]);
+             mu_printf (_("%s is not set\n"), argv[i]);
              break;
 
            default:
@@ -396,7 +421,7 @@ com_login (int argc, char **argv)
          mu_error (_("login: password required"));
          return 1;
        }
-      status = mu_getpass (mu_strin, mu_strout, "Password:", &passbuf);
+      status = mu_getpass (mu_strin, mu_strout, _("Password:"), &passbuf);
       if (status)
        return status;
       pwd = passbuf;
@@ -410,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;
 }
 
@@ -433,7 +452,7 @@ com_id (int argc, char **argv)
       argv++;
       if (argv[0] == NULL)
        {
-         mu_error ("id -test requires an argument");
+         mu_error (_("id -test requires an argument"));
          return 0;
        }
       test = argv[0];
@@ -451,7 +470,7 @@ com_id (int argc, char **argv)
              mu_printf ("%s: %s\n", test, *(char **)res);
            }
          else
-           mu_printf ("%s is not set\n", test);
+           mu_printf (_("%s is not set\n"), test);
        }
       else
        {
@@ -517,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;
 }
 
@@ -563,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;
 }
 
@@ -598,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") },


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]