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-125-gc9e2cda


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-125-gc9e2cda
Date: Tue, 05 Oct 2010 20:43:13 +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=c9e2cdac6f0c33f1175f19ca9095bc26f5a099ac

The branch, master has been updated
       via  c9e2cdac6f0c33f1175f19ca9095bc26f5a099ac (commit)
       via  c2b45bdeb4d02ff41ca157f83f90399ea7ea5e1f (commit)
       via  b4f0301366ab4953e3650a0340231a9b94df93ce (commit)
       via  8575afa0eb3a3f38642e28ec5ab109bc128c62dd (commit)
       via  63d1c19652942be6b600a5855880667f16fdb8a3 (commit)
      from  c5cc666d68f00af1bbe8e13c2c7a8bd0b224d891 (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 c9e2cdac6f0c33f1175f19ca9095bc26f5a099ac
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Oct 5 23:39:37 2010 +0300

    Improve mu shell interface.
    
    * mu/mu.h (mutool_command) <doc>: Rename to docstring.
    <argdoc>: New member.
    * mu/pop.c (com_apop): 2nd arg (password) is optional.  If not
    supplied, ask for it using the mu_getpass function.
    (pop_comtab): Add argdocs.  Use N_ wrappers around translatable
    strings.
    * mu/shell.c (default_comtab: Add argdocs.  Use N_ wrappers around
    translatable strings.
    (print_comtab): Rewrite.
    (shell_history): Use pager.

commit c2b45bdeb4d02ff41ca157f83f90399ea7ea5e1f
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Oct 5 23:38:19 2010 +0300

    Minor bugfixes in pop client code.
    
    * libproto/pop/pop3_carrier.c (mu_pop3_set_carrier): Switch to
    MU_POP3_CONNECT state.
    * libproto/pop/pop3_disconnect.c (mu_pop3_disconnect): Check if
    the stream is actually open before trying to close it.

commit b4f0301366ab4953e3650a0340231a9b94df93ce
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Oct 5 23:37:30 2010 +0300

    Add a missing function.
    
    * libmailutils/strskip.c (mu_str_skip_cset): New function.

commit 8575afa0eb3a3f38642e28ec5ab109bc128c62dd
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Oct 5 21:53:39 2010 +0300

    Implement echo control on fd streams.  Implement mu_getpass function.
    
    * configure.ac: Test for tcgetattr and tcsetattr.
    * gnulib.modules (getpass-gnu): Remove.
    * include/mailutils/mutil.h (mu_getpass): New proto.
    * include/mailutils/stream.h (MU_IOCTL_GET_ECHO)
    (MU_IOCTL_SET_ECHO): New ioctls.
    * include/mailutils/sys/file_stream.h (_MU_FILE_STREAM_ECHO_OFF): New flag.
    (_mu_file_stream) <echo_state>: New member.
    * libmailutils/getpass.c: New file.
    * libmailutils/Makefile.am (libmailutils_la_SOURCES): Add getpass.c.
    * libmailutils/file_stream.c (fd_done): Free echo_state.
    (fd_ioctl): Implement MU_IOCTL_GET_ECHO and MU_IOCTL_SET_ECHO.
    * mu/mu.h (mustrin): New extern.
    * mu/pop.c (com_pass): Use mu_getpass.
    * mu/shell.c (mustrin): New variable.
    (readline): Use mu_stream_getline instead of getline.
    (mutool_shell): Create mustrin.
    * pop3d/popauth.c (options): Fix typo.
    (fill_pass): Use mu_getpass.

commit 63d1c19652942be6b600a5855880667f16fdb8a3
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Oct 5 19:57:42 2010 +0300

    Implement pager in mu shell.
    
    * mu/mu.h (mutool_shell_interactive): New extern.
    (mutool_open_pager): New proto.
    * mu/pop.c (com_list, com_top, com_retr): Use pager.
    * mu/shell.c (mutool_shell_interactive, mustrout): New
    variables.
    (print_comtab, print_help): Print to stream.
    (shell_help): Use pager if necessary.
    (mutool_open_pager): New function.
    (mutool_shell): Create mutool_stream_out and destroy it before
    returning.
    (all functions): Use mu_stream_printf instead of printf.

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

Summary of changes:
 configure.ac                          |    2 +-
 gnulib.modules                        |    1 -
 include/mailutils/mutil.h             |    2 +
 include/mailutils/stream.h            |    3 +
 include/mailutils/sys/file_stream.h   |    4 +-
 libmailutils/Makefile.am              |    1 +
 libmailutils/file_stream.c            |   94 ++++++++++++++++--
 libmailutils/{nullrec.c => getpass.c} |   60 +++++++-----
 libmailutils/strskip.c                |    9 ++
 libproto/pop/pop3_carrier.c           |    1 +
 libproto/pop/pop3_disconnect.c        |    4 +-
 mu/mu.h                               |    7 +-
 mu/pop.c                              |  160 ++++++++++++++++--------------
 mu/shell.c                            |  176 +++++++++++++++++++++++++++-----
 pop3d/popauth.c                       |   68 ++++++++++---
 15 files changed, 435 insertions(+), 157 deletions(-)
 copy libmailutils/{nullrec.c => getpass.c} (54%)

diff --git a/configure.ac b/configure.ac
index 509a569..796c468 100644
--- a/configure.ac
+++ b/configure.ac
@@ -515,7 +515,7 @@ extern char *strsignal (int);
 ])
 
 AC_CHECK_FUNCS(mkstemp sigaction sysconf getdelim setreuid \
- setresuid seteuid setlocale vfork _exit)
+ setresuid seteuid setlocale vfork _exit tcgetattr tcsetattr)
 
 AC_FUNC_FSEEKO
 AC_FUNC_SETVBUF_REVERSED
diff --git a/gnulib.modules b/gnulib.modules
index 4368cf7..6639959 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -8,7 +8,6 @@ autobuild
 argp
 crypto/des
 getline
-getpass-gnu
 gettext
 gitlog-to-changelog
 intprops
diff --git a/include/mailutils/mutil.h b/include/mailutils/mutil.h
index 7acc021..86d2243 100644
--- a/include/mailutils/mutil.h
+++ b/include/mailutils/mutil.h
@@ -157,6 +157,8 @@ extern int mu_stream_flags_to_mode (int flags, int isdir);
 extern int mu_parse_stream_perm_string (int *pmode, const char *str,
                                        const char **endp);
   
+extern int mu_getpass (mu_stream_t in, mu_stream_t out, const char *prompt,
+                      char **passptr);
 
 #ifdef __cplusplus
 }
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index c076ade..d951f34 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -74,6 +74,9 @@ enum mu_buffer_type
 #define MU_IOCTL_GET_TRANSPORT_BUFFER 10
 #define MU_IOCTL_SET_TRANSPORT_BUFFER 11
 
+#define MU_IOCTL_GET_ECHO        12     
+#define MU_IOCTL_SET_ECHO        13  
+  
 #define MU_TRANSPORT_INPUT  0
 #define MU_TRANSPORT_OUTPUT 1
 #define MU_TRANSPORT_VALID_TYPE(n) \
diff --git a/include/mailutils/sys/file_stream.h 
b/include/mailutils/sys/file_stream.h
index 70c576a..581d289 100644
--- a/include/mailutils/sys/file_stream.h
+++ b/include/mailutils/sys/file_stream.h
@@ -21,7 +21,8 @@
 #include <mailutils/stream.h>
 #include <mailutils/sys/stream.h>
 
-#define _MU_FILE_STREAM_TEMP 0x01
+#define _MU_FILE_STREAM_TEMP     0x01
+#define _MU_FILE_STREAM_ECHO_OFF 0x02
 
 struct _mu_file_stream
 {
@@ -29,6 +30,7 @@ struct _mu_file_stream
   int fd;
   int flags;
   char *filename;
+  void *echo_state;
 };
 
 int _mu_file_stream_create (struct _mu_file_stream **pstream, size_t size,
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index e05edd8..3f083e0 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -84,6 +84,7 @@ libmailutils_la_SOURCES = \
  folder.c\
  freeitem.c\
  gdebug.c\
+ getpass.c\
  gocs.c\
  hdritr.c\
  header.c\
diff --git a/libmailutils/file_stream.c b/libmailutils/file_stream.c
index 247768c..578f482 100644
--- a/libmailutils/file_stream.c
+++ b/libmailutils/file_stream.c
@@ -23,6 +23,9 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#if HAVE_TERMIOS_H
+# include <termios.h>
+#endif
 
 #include <mailutils/types.h>
 #include <mailutils/alloc.h>
@@ -183,6 +186,8 @@ fd_done (struct _mu_stream *str)
     fd_close (str);
   if (fstr->filename)
     free (fstr->filename);
+  if (fstr->echo_state)
+    free (fstr->echo_state);
 }
 
 const char *
@@ -194,6 +199,10 @@ fd_error_string (struct _mu_stream *str, int rc)
     return mu_strerror (rc);
 }
 
+#ifndef TCSASOFT
+# define TCSASOFT 0
+#endif
+
 static int
 fd_ioctl (struct _mu_stream *str, int code, void *ptr)
 {
@@ -218,17 +227,86 @@ fd_ioctl (struct _mu_stream *str, int code, void *ptr)
       break;
       
     case MU_IOCTL_GET_TRANSPORT_BUFFER:
-      {
-        struct mu_buffer_query *qp = ptr;
-       return mu_stream_get_buffer (str, qp);
-      }
+      if (!ptr)
+       return EINVAL;
+      else
+       {
+         struct mu_buffer_query *qp = ptr;
+         return mu_stream_get_buffer (str, qp);
+       }
       
     case MU_IOCTL_SET_TRANSPORT_BUFFER:
-      {
-        struct mu_buffer_query *qp = ptr;
-       return mu_stream_set_buffer (str, qp->buftype, qp->bufsize);
-      }
+      if (!ptr)
+       return EINVAL;
+      else
+       {
+         struct mu_buffer_query *qp = ptr;
+         return mu_stream_set_buffer (str, qp->buftype, qp->bufsize);
+       }
+
+    case MU_IOCTL_SET_ECHO:
+      if (!ptr)
+       return EINVAL;
+      else
+       {
+         int status;
+         struct termios t;
+         int state = *(int*)ptr;
+#if HAVE_TCGETATTR
+         if (state == 0)
+           {
+             if (fstr->flags & _MU_FILE_STREAM_ECHO_OFF)
+               return 0;
+             status = tcgetattr (fstr->fd, &t);
+             if (status == 0)
+               {
+                 fstr->echo_state = malloc (sizeof (t));
+                 if (!fstr->echo_state)
+                   return ENOMEM;
+                 memcpy (fstr->echo_state, &t, sizeof (t));
+
+                 t.c_lflag &= ~(ECHO | ISIG);
+                 status = tcsetattr (fstr->fd, TCSAFLUSH | TCSASOFT, &t);
+                 if (status == 0)
+                   fstr->flags |= _MU_FILE_STREAM_ECHO_OFF;
+               }
+             if (status)
+               {
+                 status = errno;
+                 if (fstr->echo_state)
+                   {
+                     free (fstr->echo_state);
+                     fstr->echo_state = NULL;
+                   }
+               }
+           }
+         else
+           {
+             if (!(fstr->flags & _MU_FILE_STREAM_ECHO_OFF))
+               return 0;
+             if (tcsetattr (fstr->fd, TCSAFLUSH | TCSASOFT, fstr->echo_state))
+               status = errno;
+             else
+               {
+                 status = 0;
+                 free (fstr->echo_state);
+                 fstr->echo_state = NULL;
+                 fstr->flags &= ~_MU_FILE_STREAM_ECHO_OFF;
+               }
+           }
+         return status;
+#else
+         return ENOSYS;
+#endif
+       }
       
+    case MU_IOCTL_GET_ECHO:
+      if (!ptr)
+       return EINVAL;
+      else
+       *(int*)ptr = fstr->flags & _MU_FILE_STREAM_ECHO_OFF;
+      break;
+         
     default:
       return ENOSYS;
     }
diff --git a/libmailutils/nullrec.c b/libmailutils/getpass.c
similarity index 54%
copy from libmailutils/nullrec.c
copy to libmailutils/getpass.c
index 9d080cd..8a37c52 100644
--- a/libmailutils/nullrec.c
+++ b/libmailutils/getpass.c
@@ -15,35 +15,45 @@
    You should have received a copy of the GNU Lesser General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-/* This file provides replacement definitions for mu_record_t defined
-   in those MU libraries which are disabled at configure time. */
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 
 #include <stdlib.h>
-#include <mailutils/types.h>
-#include <mailutils/registrar.h>
-
-#ifndef ENABLE_IMAP
-mu_record_t mu_imap_record = NULL;
-mu_record_t mu_imaps_record = NULL;
-#endif
+#include <string.h>
 
-#ifndef ENABLE_POP
-mu_record_t mu_pop_record = NULL;
-mu_record_t mu_pops_record = NULL;
-#endif
-
-#ifndef ENABLE_NNTP
-mu_record_t mu_nntp_record = NULL;
-#endif
-
-#ifndef ENABLE_MH
-mu_record_t mu_mh_record = NULL;
-#endif
-
-#ifndef ENABLE_MAILDIR
-mu_record_t mu_maildir_record = NULL;
-#endif
+#include <mailutils/types.h>
+#include <mailutils/stream.h>
+#include <mailutils/mutil.h>
+#include <mailutils/cstr.h>
+
+int
+mu_getpass (mu_stream_t in, mu_stream_t out, const char *prompt,
+           char **passptr)
+{
+  int status;
+  int echo_state = 0;
+  size_t size = 0;
+  char *buf = NULL;
+
+  status = mu_stream_write (out, prompt, strlen (prompt), NULL);
+  if (status)
+    return status;
+  mu_stream_flush (out);
+  status = mu_stream_ioctl (in, MU_IOCTL_SET_ECHO, &echo_state);
+  if (status == 0)
+    echo_state = 1;
+  status = mu_stream_getline (in, &buf, &size, NULL);
+  if (echo_state)
+    {
+      mu_stream_ioctl (in, MU_IOCTL_SET_ECHO, &echo_state);
+      mu_stream_write (out, "\n", 1, NULL);
+    }
+  if (status == 0)
+    {
+      mu_rtrim_cset (buf, "\n");
+      *passptr = buf;
+    }
+  return 0;
+}
 
diff --git a/libmailutils/strskip.c b/libmailutils/strskip.c
index f24d119..5b676d0 100644
--- a/libmailutils/strskip.c
+++ b/libmailutils/strskip.c
@@ -41,6 +41,14 @@ mu_str_skip_class_comp (const char *str, int class)
 }
 
 char *
+mu_str_skip_cset (const char *str, const char *cset)
+{
+  for (; *str && strchr (cset, *str); str++)
+    ;
+  return (char*) str;
+}
+
+char *
 mu_str_skip_cset_comp (const char *str, const char *cset)
 {
   for (; *str && strchr (cset, *str) == NULL; str++)
@@ -48,3 +56,4 @@ mu_str_skip_cset_comp (const char *str, const char *cset)
   return (char*) str;
 }
 
+
diff --git a/libproto/pop/pop3_carrier.c b/libproto/pop/pop3_carrier.c
index 7331756..485790f 100644
--- a/libproto/pop/pop3_carrier.c
+++ b/libproto/pop/pop3_carrier.c
@@ -42,6 +42,7 @@ mu_pop3_set_carrier (mu_pop3_t pop3, mu_stream_t carrier)
   pop3->carrier = carrier;
   if (MU_POP3_FISSET (pop3, MU_POP3_TRACE))
     _mu_pop3_trace_enable (pop3);
+  pop3->state = MU_POP3_CONNECT;
   return 0;
 }
 
diff --git a/libproto/pop/pop3_disconnect.c b/libproto/pop/pop3_disconnect.c
index 621a566..1c3d231 100644
--- a/libproto/pop/pop3_disconnect.c
+++ b/libproto/pop/pop3_disconnect.c
@@ -49,5 +49,7 @@ mu_pop3_disconnect (mu_pop3_t pop3)
     }
 
   /* Close the stream.  */
-  return mu_stream_close (pop3->carrier);
+  if (mu_stream_is_open (pop3->carrier))
+    return mu_stream_close (pop3->carrier);
+  return 0;
 }
diff --git a/mu/mu.h b/mu/mu.h
index a251d7d..7ab5b70 100644
--- a/mu/mu.h
+++ b/mu/mu.h
@@ -24,7 +24,8 @@ struct mutool_command
   int argmax;           /* Max. allowed number of arguments (-1 means not
                           limited */
   mutool_action_t func;        /* Function to call to do the job. */
-  const char *doc;     /* Documentation for this function.  */
+  const char *argdoc;   /* Documentation for the arguments */
+  const char *docstring;/* Documentation for this function.  */
 };
 
 
@@ -37,5 +38,7 @@ int mutool_acl (int argc, char **argv);
 
 extern char *mutool_shell_prompt;
 extern mu_vartab_t mutool_prompt_vartab;
-
+extern int mutool_shell_interactive;
+extern mu_stream_t mustrin, mustrout;
 int mutool_shell (const char *name, struct mutool_command *cmd);
+mu_stream_t mutool_open_pager (void);
diff --git a/mu/pop.c b/mu/pop.c
index e4b9a25..86d3e8a 100644
--- a/mu/pop.c
+++ b/mu/pop.c
@@ -244,24 +244,24 @@ com_verbose (int argc, char **argv)
     {
       if (QRY_VERBOSE ())
        {
-         printf ("verbose is on");
+         mu_stream_printf (mustrout, "verbose is on");
          if (HAS_VERBOSE_MASK ())
            {
              char *delim = " (";
            
              if (QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE))
                {
-                 printf("%ssecure", delim);
+                 mu_stream_printf (mustrout, "%ssecure", delim);
                  delim = ", ";
                }
              if (QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD))
-               printf("%spayload", delim);
-             printf (")");
+               mu_stream_printf (mustrout, "%spayload", delim);
+             mu_stream_printf (mustrout, ")");
            }
-         printf ("\n");
+         mu_stream_printf (mustrout, "\n");
        }
       else
-       printf ("verbose is off\n");
+       mu_stream_printf (mustrout, "verbose is off\n");
     }
   else
     {
@@ -304,13 +304,25 @@ static int
 com_apop (int argc, char **argv)
 {
   int status;
+  char *pwd, *passbuf = NULL;
 
-  status = mu_pop3_apop (pop3, argv[1], argv[2]);
+  if (argc == 3)
+    pwd = argv[2];
+  else
+    {
+      status = mu_getpass (mustrin, mustrout, "Password:", &passbuf);
+      if (status)
+       return status;
+      pwd = passbuf;
+    }
+  
+  status = mu_pop3_apop (pop3, argv[1], pwd);
   if (status == 0)
     {
       username = strdup (argv[1]);
       pop_session_status = pop_session_logged_in;
     }
+  free (passbuf);
   return status;
 }
 
@@ -346,13 +358,13 @@ com_capa (int argc, char **argv)
            {
            case 0:
              if (*elt)
-               printf ("%s: %s\n", argv[i], elt);
+               mu_stream_printf (mustrout, "%s: %s\n", argv[i], elt);
              else
-               printf ("%s is set\n", argv[i]);
+               mu_stream_printf (mustrout, "%s is set\n", argv[i]);
              break;
 
            case MU_ERR_NOENT:
-             printf ("%s is not set\n", argv[i]);
+             mu_stream_printf (mustrout, "%s is not set\n", argv[i]);
              break;
 
            default:
@@ -371,7 +383,7 @@ com_capa (int argc, char **argv)
            {
              char *capa = NULL;
              mu_iterator_current (iterator, (void **) &capa);
-             printf ("CAPA: %s\n", capa ? capa : "");
+             mu_stream_printf (mustrout, "CAPA: %s\n", capa ? capa : "");
            }
          mu_iterator_destroy (&iterator);
        }
@@ -385,6 +397,7 @@ com_uidl (int argc, char **argv)
   int status = 0;
   if (argc == 1)
     {
+      mu_stream_t out = mutool_open_pager ();
       mu_iterator_t uidl_iterator = NULL;
       status = mu_pop3_uidl_all (pop3, &uidl_iterator);
       if (status == 0)
@@ -395,10 +408,11 @@ com_uidl (int argc, char **argv)
            {
              char *uidl = NULL;
              mu_iterator_current (uidl_iterator, (void **) &uidl);
-             printf ("UIDL: %s\n", uidl ? uidl : "");
+             mu_stream_printf (out, "UIDL: %s\n", uidl ? uidl : "");
            }
          mu_iterator_destroy (&uidl_iterator);
        }
+      mu_stream_destroy (&out);
     }
   else
     {
@@ -406,7 +420,7 @@ com_uidl (int argc, char **argv)
       unsigned int msgno = strtoul (argv[1], NULL, 10);
       status = mu_pop3_uidl (pop3, msgno, &uidl);
       if (status == 0)
-       printf ("Msg: %d UIDL: %s\n", msgno, uidl ? uidl : "");
+       mu_stream_printf (mustrout, "Msg: %d UIDL: %s\n", msgno, uidl ? uidl : 
"");
       free (uidl);
     }
   return status;
@@ -418,6 +432,7 @@ com_list (int argc, char **argv)
   int status = 0;
   if (argc == 1)
     {
+      mu_stream_t out = mutool_open_pager ();
       mu_iterator_t list_iterator;
       status = mu_pop3_list_all (pop3, &list_iterator);
       if (status == 0)
@@ -428,9 +443,10 @@ com_list (int argc, char **argv)
            {
              char *list = NULL;
              mu_iterator_current (list_iterator, (void **) &list);
-             printf ("LIST: %s\n", (list) ? list : "");
+             mu_stream_printf (out, "LIST: %s\n", (list) ? list : "");
            }
          mu_iterator_destroy (&list_iterator);
+         mu_stream_destroy (&out);
        }
     }
   else
@@ -439,7 +455,7 @@ com_list (int argc, char **argv)
       unsigned int msgno = strtoul (argv[1], NULL, 10);
       status = mu_pop3_list (pop3, msgno, &size);
       if (status == 0)
-       printf ("Msg: %u Size: %lu\n", msgno, (unsigned long) size);
+       mu_stream_printf (mustrout, "Msg: %u Size: %lu\n", msgno, (unsigned 
long) size);
     }
   return status;
 }
@@ -450,42 +466,18 @@ com_noop (int argc MU_ARG_UNUSED, char **argv 
MU_ARG_UNUSED)
   return mu_pop3_noop (pop3);
 }
 
-static void
-echo_off (struct termios *stored_settings)
-{
-  struct termios new_settings;
-  tcgetattr (0, stored_settings);
-  new_settings = *stored_settings;
-  new_settings.c_lflag &= (~ECHO);
-  tcsetattr (0, TCSANOW, &new_settings);
-}
-
-static void
-echo_on (struct termios *stored_settings)
-{
-  tcsetattr (0, TCSANOW, stored_settings);
-}
-
 static int
 com_pass (int argc, char **argv)
 {
   int status;
-  char pass[256];
-  char *pwd;
+  char *pwd, *passbuf = NULL;
   
   if (argc == 1)
     {
-      struct termios stored_settings;
-
-      printf ("passwd:");
-      fflush (stdout);
-      echo_off (&stored_settings);
-      fgets (pass, sizeof pass, stdin);
-      echo_on (&stored_settings);
-      putchar ('\n');
-      fflush (stdout);
-      pass[strlen (pass) - 1] = '\0';  /* nuke the trailing line.  */
-      pwd = pass;
+      status = mu_getpass (mustrin, mustrout, "Password:", &passbuf);
+      if (status)
+       return status;
+      pwd = passbuf;
     }
   else
     pwd = argv[1];
@@ -495,6 +487,7 @@ com_pass (int argc, char **argv)
       pop_session_status = pop_session_logged_in;
       pop_prompt_vartab ();
     }
+  free (passbuf);
   return status;
 }
 
@@ -506,8 +499,8 @@ com_stat (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
   int status = 0;
 
   status = mu_pop3_stat (pop3, &count, &size);
-  printf ("Mesgs: %lu Size %lu\n",
-         (unsigned long) count, (unsigned long) size);
+  mu_stream_printf (mustrout, "Mesgs: %lu Size %lu\n",
+                   (unsigned long) count, (unsigned long) size);
   return status;
 }
 
@@ -549,10 +542,9 @@ com_top (int argc, char **argv)
 
   if (status == 0)
     {
-      size_t n = 0;
-      char buf[128];
-      while ((mu_stream_readline (stream, buf, sizeof buf, &n) == 0) && n)
-       printf ("%s", buf);
+      mu_stream_t out = mutool_open_pager ();
+      mu_stream_copy (out, stream, 0, NULL);
+      mu_stream_destroy (&out);
       mu_stream_destroy (&stream);
     }
   return status;
@@ -570,10 +562,9 @@ com_retr (int argc, char **argv)
 
   if (status == 0)
     {
-      size_t n = 0;
-      char buf[128];
-      while ((mu_stream_readline (stream, buf, sizeof buf, &n) == 0) && n)
-       printf ("%s", buf);
+      mu_stream_t out = mutool_open_pager ();
+      mu_stream_copy (out, stream, 0, NULL);
+      mu_stream_destroy (&out);
       mu_stream_destroy (&stream);
     }
   return status;
@@ -706,49 +697,70 @@ com_quit (int argc MU_ARG_UNUSED, char **argv 
MU_ARG_UNUSED)
        }
       else
        {
-         printf ("Try 'exit' to leave %s\n", mu_program_name);
+         mu_stream_printf (mustrout, "Try 'exit' to leave %s\n", 
mu_program_name);
        }
     }
   else
-    printf ("Try 'exit' to leave %s\n", mu_program_name);
+    mu_stream_printf (mustrout, "Try 'exit' to leave %s\n", mu_program_name);
   return status;
 }
 
 struct mutool_command pop_comtab[] = {
-  { "apop",       3,  3, com_apop,
-    "Authenticate with APOP: APOP user secret" },
+  { "apop",       2,  3, com_apop,
+    N_("USER [PASS]"),
+    N_("authenticate with APOP") },
   { "capa",       1, -1, com_capa,
-    "List capabilities: capa [-reread] [names...]" },
+    /* TRANSLATORS: -reread is a keyword; do not translate. */
+    N_("[-reread] [NAME...]"),
+    N_("list server capabilities") },
   { "disconnect", 1, 1,
-    com_disconnect, "Close connection: disconnect" },
+    com_disconnect,
+    NULL,
+    N_("close connection") },
   { "dele",       2, 2, com_dele,
-    "Mark message: DELE msgno" },
+    N_("NUMBER"),
+    N_("mark message for deletion") },
   { "list",       1, 2, com_list,
-    "List messages: LIST [msgno]" },
+    N_("[NUMBER]"),
+    N_("list messages") },
   { "noop",       1, 1, com_noop,
-    "Send no operation: NOOP" },
+    NULL,
+    N_("send a \"no operation\"") },
   { "pass",       1, 2, com_pass,
-    "Send passwd: PASS [passwd]" },
+    N_("[PASSWORD]"),
+    N_("send password") },
   { "connect",    1, 4, com_connect,
-    "Open connection: connect [-tls] hostname port" },
+    /* TRANSLATORS: --tls is a keyword. */
+    N_("[-tls] HOSTNAME [PORT]"),
+    N_("open connection") },
   { "quit",       1, 1, com_quit,
-    "Go to Update state : QUIT" },
+    NULL,
+    N_("quit pop3 session") },
   { "retr",       2, 2, com_retr,
-    "Dowload message: RETR msgno" },
+    "NUMBER",
+    N_("retrieve a message") },
   { "rset",       1, 1, com_rset,
-    "Unmark all messages: RSET" },
+    NULL,
+    N_("remove deletion marks") },
   { "stat",       1, 1, com_stat,
-    "Get the size and count of mailbox : STAT" },
+    NULL,
+    N_("get the mailbox size and number of messages in it") },
   { "stls",       1, 1, com_stls,
-    "Start TLS negotiation" },
+    NULL,
+    N_("start TLS negotiation") },
   { "top",        2, 3, com_top,
-    "Get the header of message: TOP msgno [lines]" },
+    "MSGNO [NUMBER]",
+    N_("display message headers and first NUMBER (default 5) lines of"
+       " its body") },
   { "uidl",       1, 2, com_uidl,
-    "Get the unique id of message: UIDL [msgno]" },
+    N_("[NUMBER]"),
+    N_("show unique message identifiers") },
   { "user",       2, 2, com_user,
-    "send login: USER user" },
+    N_("NAME"),
+    N_("send login") },
   { "verbose",    1, 4, com_verbose,
-    "Enable Protocol tracing: verbose [on|off|mask|unmask] [x1 [x2]]" },
+    "[on|off|mask|unmask] [secret [payload]]",
+    N_("control the protocol tracing") },
   { NULL }
 };
 
diff --git a/mu/shell.c b/mu/shell.c
index 6a04fb3..e102eca 100644
--- a/mu/shell.c
+++ b/mu/shell.c
@@ -32,6 +32,8 @@
 
 char *mutool_shell_prompt;
 mu_vartab_t mutool_prompt_vartab;
+int mutool_shell_interactive;
+mu_stream_t mustrin, mustrout;
 
 static char *
 expand_prompt ()
@@ -53,37 +55,105 @@ static int shell_history (int, char **);
 #endif
 
 struct mutool_command default_comtab[] = {
-  { "prompt",   -1, -1, shell_prompt,  "set command prompt" },
-  { "exit",       1, 1, shell_exit,    "exit program" },
-  { "help",       1, 2, shell_help,    "display this text" },
-  { "?",          1, 1, shell_help,    "synonym for `help'" },
+  { "prompt",   -1, -1, shell_prompt,
+    N_("STRING"),
+    N_("set command prompt") },
+  { "exit",       1, 1, shell_exit,    NULL,        N_("exit program") },
+  { "help",       1, 2, shell_help,
+    N_("[COMMAND]"),
+    N_("display this text") },
+  { "?",          1, 1, shell_help,
+    N_("[COMMAND]"),
+    N_("synonym for `help'") },
 #ifdef WITH_READLINE
-  { "history",    1, 1, shell_history, "show command history" },
+  { "history",    1, 1, shell_history,
+    NULL,
+    N_("show command history") },
 #endif
   { NULL }
 };
 
+#define DESCRCOL 25
+#define NUMCOLS  80
+#define DESCRWIDTH (NUMCOLS - DESCRCOL)
+
 /* Print a single comtab entry */
 static void
-print_comtab (struct mutool_command *tab)
+print_comtab (mu_stream_t stream, struct mutool_command *tab)
 {
-  printf ("%s\t\t%s\n", tab->name, tab->doc);
+  size_t size = 0;
+  const char *text;
+  
+  if (tab->docstring == NULL)
+    return;
+
+  mu_stream_printf (stream, "%s ", tab->name);
+  size += strlen (tab->name) + 1;
+  if (tab->argdoc)
+    {
+      text = gettext (tab->argdoc);
+      mu_stream_printf (stream, "%s", text);
+      size += strlen (text);
+    }
+  if (size >= DESCRCOL)
+    mu_stream_printf (stream, "\n%-*s", DESCRCOL, "");
+  else
+    mu_stream_printf (stream, "%-*s", (int) (DESCRCOL - size), "");
+
+  text = gettext (tab->docstring);
+  size = strlen (text);
+  
+  while (*text)
+    {
+      size_t len = size;
+      if (len > DESCRWIDTH)
+       {
+         /* Fold the text */
+         size_t n = 0;
+         
+         while (n < len)
+           {
+             size_t delta;
+             char *p;
+             
+             p = mu_str_skip_cset_comp (text + n, " \t");
+             delta = p - (text + n);
+             if (n + delta > DESCRWIDTH)
+               break;
+             n += delta;
+             
+             p = mu_str_skip_cset (text + n, " \t");
+             delta = p - (text + n);
+             if (n + delta > DESCRWIDTH)
+               break;
+             n += delta;
+           }
+
+         len = n;
+       }
+      mu_stream_write (stream, text, len, NULL);
+      text += len;
+      size -= len;
+      mu_stream_write (stream, "\n", 1, NULL);
+      if (size)
+       mu_stream_printf (stream, "%-*s", DESCRCOL, "");
+    }
 }  
 
 /* Print a single comtab entry.
    FIXME: Way too primitive. Rewrite. */
 int
-print_help (struct mutool_command *tab, size_t n)
+print_help (mu_stream_t stream, struct mutool_command *tab, size_t n)
 {
   if (n)
     {
       for (; n > 0 && tab->name; tab++, n--)
-       print_comtab (tab);
+       print_comtab (stream, tab);
     }
   else
     {
       for (; tab->name; tab++)
-       print_comtab (tab);
+       print_comtab (stream, tab);
     }
   return 0;
 }
@@ -102,16 +172,16 @@ list_commands (struct mutool_command *tab, const char 
*name)
       if (printed == 6)
        {
          printed = 0;
-         printf ("\n");
+         mu_stream_printf (mustrout, "\n");
        }
       if (mu_c_strncasecmp (tab->name, name, namelen) == 0)
        {
-         printf ("%s\t", tab->name);
+         mu_stream_printf (mustrout, "%s\t", tab->name);
          printed++;
        }
     }
   if (printed && printed < 6)
-    printf ("\n");
+    mu_stream_printf (mustrout, "\n");
 }
 
 static struct mutool_command *
@@ -139,23 +209,28 @@ int
 shell_help (int argc, char **argv)
 {
   char *name = argv[1];
+  
   if (name)
     {
       struct mutool_command *com = find_command (argv[1]);
 
       if (com)
-       print_comtab (com);
+       print_comtab (mustrout, com);
       else
        {
-         printf ("No commands match `%s'.  Possibilties are:\n", name);
+         mu_stream_printf (mustrout,
+                           "No commands match `%s'.  Possibilties are:\n",
+                           name);
          list_commands (shell_comtab, name);
        }
     }
   else
     {
-      print_help (shell_comtab, user_command_count);
-      printf ("\n");
-      print_help (shell_comtab + user_command_count, 0);
+      mu_stream_t str = mutool_open_pager ();
+      print_help (str, shell_comtab, user_command_count);
+      mu_stream_printf (str, "\n");
+      print_help (str, shell_comtab + user_command_count, 0);
+      mu_stream_destroy (&str);
     }
   return 0;
 }
@@ -173,6 +248,21 @@ shell_prompt (int argc, char **argv)
   return 0;
 }
 
+mu_stream_t
+mutool_open_pager ()
+{
+  char *pager;
+  if (mutool_shell_interactive && (pager = getenv ("PAGER")) != NULL)
+    {
+      mu_stream_t stream;
+      int rc = mu_prog_stream_create (&stream, pager, MU_STREAM_WRITE);
+      if (rc == 0)
+       return stream;
+      mu_error (_("cannot start pager: %s"), mu_strerror (rc));
+    }
+  mu_stream_ref (mustrout);
+  return mustrout;
+}
 
 
 #ifdef WITH_READLINE
@@ -313,7 +403,7 @@ retrieve_history (char *str)
       return 1;
 
     case 2:
-      printf ("%s\n", out);
+      mu_stream_printf (mustrout, "%s\n", out);
       free (out);
       return 1;
     }
@@ -325,11 +415,13 @@ shell_history (int argc, char **argv)
 {
   int i;
   HIST_ENTRY **hlist;
-
+  mu_stream_t out = mutool_open_pager ();
+  
   hlist = history_list ();
   for (i = 0; i < history_length; i++)
-    printf ("%4d) %s\n", i + 1, hlist[i]->line);
+    mu_stream_printf (out, "%4d) %s\n", i + 1, hlist[i]->line);
 
+  mu_stream_destroy (&out);
   return 0;
 }
 
@@ -345,11 +437,16 @@ readline (char *prompt)
 
   if (prompt)
     {
-      printf ("%s", prompt);
+      mu_stream_printf (mustrout, "%s", prompt);
       fflush (stdout);
     }
-  if (getline (&buf, &size, stdin) <= 0)
-    return NULL;
+  if (mu_stream_getline (mustrin, &buf, &size, &n) || n == 0)
+    {
+      free (buf);
+      buf = NULL;
+      size = 0;
+      return NULL;
+    }
   return buf;
 }
 
@@ -440,9 +537,30 @@ shell_exit (int argc MU_ARG_UNUSED, char **argv 
MU_ARG_UNUSED)
 int
 mutool_shell (const char *name, struct mutool_command *cmd)
 {
+  int rc;
   size_t n;
-  int interactive = isatty (0);
-  char *(*input_line) () = interactive ?
+  char *(*input_line) ();
+
+  rc = mu_stdio_stream_create (&mustrin, MU_STDIN_FD,
+                              MU_STREAM_READ);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create",
+                      "MU_STDIN_FD", rc);
+      return 1;
+    } 
+ 
+  rc = mu_stdio_stream_create (&mustrout, MU_STDOUT_FD,
+                              MU_STREAM_WRITE);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create",
+                      "MU_STDOUT_FD", rc);
+      return 1;
+    } 
+ 
+  mutool_shell_interactive = isatty (0);
+  input_line = mutool_shell_interactive ?
                              input_line_interactive : input_line_script;
 
   for (n = 0; cmd[n].name; n++)
@@ -471,7 +589,7 @@ mutool_shell (const char *name, struct mutool_command *cmd)
          int status;
 
 #ifdef WITH_READLINE
-         if (interactive)
+         if (mutool_shell_interactive)
            {
              if (retrieve_history (s))
                continue;
@@ -486,7 +604,9 @@ mutool_shell (const char *name, struct mutool_command *cmd)
 
       free (line);
     }
-  if (interactive)
+  if (mutool_shell_interactive)
     finish_readline ();
+  mu_stream_destroy (&mustrin);
+  mu_stream_destroy (&mustrout);
   return 0;
 }
diff --git a/pop3d/popauth.c b/pop3d/popauth.c
index 9f73d60..f8505f9 100644
--- a/pop3d/popauth.c
+++ b/pop3d/popauth.c
@@ -74,7 +74,7 @@ static struct argp_option options[] =
   { NULL, 0, NULL, 0,
     N_("Default action is:\n"
     "  For the file owner: --list\n"
-    "  For a user: --modify --username <username>\n"), 2 },
+    "  For a user: --modify --user <username>\n"), 2 },
   
   { NULL, 0, NULL, 0, N_("Options are:"), 3 },
   { "file", 'f', N_("FILE"), 0, N_("read input from FILE (default stdin)"), 3 
},
@@ -105,7 +105,7 @@ set_db_perms (struct argp_state *astate, char *opt, int 
*pperm)
 {
   int perm = 0;
    
-  if (mu_isdigit(opt[0]))
+  if (mu_isdigit (opt[0]))
     {
       char *p;
       perm = strtoul (opt, &p, 8);
@@ -446,21 +446,57 @@ fill_pass (struct action_data *ap)
   if (!ap->passwd)
     {
       char *p;
+      mu_stream_t in, out;
+      int rc;
+      
+      rc = mu_stdio_stream_create (&in, MU_STDIN_FD, MU_STREAM_READ);
+      if (rc)
+       {
+         mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create",
+                          "MU_STDIN_FD", rc);
+         return;
+       }
+ 
+      rc = mu_stdio_stream_create (&out, MU_STDOUT_FD, MU_STREAM_WRITE);
+      if (rc)
+       {
+         mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create",
+                          "MU_STDOUT_FD", rc);
+         return;
+       }
 
-      while (1) {
-       if (ap->passwd)
-         free (ap->passwd);
-       p = getpass (_("Password:"));
-       if (!p)
-         exit (EX_DATAERR);
-       ap->passwd = strdup (p);
-       /* TRANSLATORS: Please try to format this string so that it has
-          the same length as the translation of 'Password:' above */
-       p = getpass (_("Confirm :"));
-       if (strcmp (ap->passwd, p) == 0)
-         break;
-       mu_error (_("Passwords differ. Please retry."));
-      } 
+      while (1)
+       {
+         if (ap->passwd)
+           free (ap->passwd);
+         rc = mu_getpass (in, out, _("Password:"), &p);
+         if (rc)
+           {
+             mu_diag_funcall (MU_DIAG_ERROR, "mu_getpass", NULL, rc);
+             exit (EX_DATAERR);
+           }
+         
+         if (!p)
+           exit (EX_DATAERR);
+         
+         ap->passwd = strdup (p);
+         /* TRANSLATORS: Please try to format this string so that it has
+            the same length as the translation of 'Password:' above */
+         rc = mu_getpass (in, out, _("Confirm :"), &p);
+         if (rc)
+           {
+             mu_diag_funcall (MU_DIAG_ERROR, "mu_getpass", NULL, rc);
+             exit (EX_DATAERR);
+           }
+         
+         if (!p)
+           exit (EX_DATAERR);
+         if (strcmp (ap->passwd, p) == 0)
+           break;
+         mu_error (_("Passwords differ. Please retry."));
+       }
+      mu_stream_destroy (&in);
+      mu_stream_destroy (&out);
     }
 }
 


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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