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-621-g62e22dc


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-621-g62e22dc
Date: Thu, 19 Jul 2012 05:43:14 +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=62e22dcc8419437e03225ae55223aaf97227b1e1

The branch, master has been updated
       via  62e22dcc8419437e03225ae55223aaf97227b1e1 (commit)
      from  8ad474712f6758cdff637c5391867706957dfd74 (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 62e22dcc8419437e03225ae55223aaf97227b1e1
Author: Sergey Poznyakoff <address@hidden>
Date:   Thu Jul 19 08:31:14 2012 +0300

    mail: provide mechanism for listing and editing attachments from the shell
    
    * NEWS: Update.
    * mail/escape.c (escape_check_args): Take two additional arguments
    specifying minimum and maximum number of parameters to expect.
    All uses updated. Remove static qualifier.
    * mail/mail.h (send_attach_file): Rename to send_attach_file_default
    (escape_check_args,escape_list_attachments)
    (escape_attach,escape_remove_attachment): New protos.
    * mail/send.c (send_attach_file): Take encoding and content type
    as arguments.
    (send_attach_file_default): New function.
    (escape_list_attachments)
    (escape_attach,escape_remove_attachment): New functions.
    * mail/table.c: New escapes: l, +, ^
    
    * include/mailutils/list.h (mu_list_remove_nth)
    (mu_list_remove_nth_nd): New protos.
    * libmailutils/list/Makefile.am (liblist_la_SOURCES): Add removenth.c
    * libmailutils/list/removenth.c: New file.

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

Summary of changes:
 NEWS                                        |   16 ++++-
 doc/imprimatur                              |    2 +-
 include/mailutils/list.h                    |    4 +
 libmailutils/list/Makefile.am               |    1 +
 libmailutils/list/{remove.c => removenth.c} |   21 +++---
 mail/escape.c                               |   35 +++++++---
 mail/mail.c                                 |    2 +-
 mail/mail.h                                 |    9 ++-
 mail/send.c                                 |  102 +++++++++++++++++++++++++--
 mail/table.c                                |    3 +
 10 files changed, 166 insertions(+), 29 deletions(-)
 copy libmailutils/list/{remove.c => removenth.c} (78%)

diff --git a/NEWS b/NEWS
index 8cac522..7e55823 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU mailutils NEWS -- history of user-visible changes. 2012-07-18
+GNU mailutils NEWS -- history of user-visible changes. 2012-07-19
 Copyright (C) 2002-2012 Free Software Foundation, Inc.
 See the end of file for copying conditions.
 
@@ -135,6 +135,20 @@ Here, the file "prog" will be attached witg the content 
type
 "main.c" and "ext.h" will be marked with content type "text/c" and
 encoded using "quoted-printable" algorithm.
 
+The mail shell provides the following new escapes to handle attachments:
+
+ ~l
+    Lists all attachments.  The output is a numbered list of
+    attachments with their corresponding content types and
+    encodings.
+    
+ ~+ filename [content-type [encoding]]
+    Attach the file `filename'.  Optional arguments supply the content
+    type and encoding to use instead of the defaults.
+
+ ~^ N
+    Delete Nth attachment.
+
 ** MH: improved compatibility with other implementations
 
 ** MH inc: new option --moveto
diff --git a/doc/imprimatur b/doc/imprimatur
index f32ef19..04255b6 160000
--- a/doc/imprimatur
+++ b/doc/imprimatur
@@ -1 +1 @@
-Subproject commit f32ef1983968e755cd580b06e369476d7e7f88b6
+Subproject commit 04255b6d5551952b4e0c94da15988f573e3e9fc4
diff --git a/include/mailutils/list.h b/include/mailutils/list.h
index 09bfccb..4d3e014 100644
--- a/include/mailutils/list.h
+++ b/include/mailutils/list.h
@@ -118,6 +118,10 @@ int mu_list_remove   (mu_list_t _list, void *_item);
   /* A non-destructive version of mu_list_remove: removes the _item but does
      not deallocate it. */
 int mu_list_remove_nd  (mu_list_t _list, void *_item);
+  /* Remove Nth element from the list. */
+int mu_list_remove_nth (mu_list_t list, size_t n);
+  /* Remove Nth element from the list, non-destructive. */
+int mu_list_remove_nth_nd (mu_list_t list, size_t n);
   /* Find _old_item in _list and if found, replace it with _new_item,
      deallocating the removed item via the `destroy_item' method. */
 int mu_list_replace  (mu_list_t _list, void *_old_item, void *_new_item);
diff --git a/libmailutils/list/Makefile.am b/libmailutils/list/Makefile.am
index bd648a6..7e2324c 100644
--- a/libmailutils/list/Makefile.am
+++ b/libmailutils/list/Makefile.am
@@ -42,6 +42,7 @@ liblist_la_SOURCES = \
  prepend.c\
  push.c\
  remove.c\
+ removenth.c\
  replace.c\
  rfold.c\
  setcomp.c\
diff --git a/libmailutils/list/remove.c b/libmailutils/list/removenth.c
similarity index 78%
copy from libmailutils/list/remove.c
copy to libmailutils/list/removenth.c
index 5ebd312..80550ee 100644
--- a/libmailutils/list/remove.c
+++ b/libmailutils/list/removenth.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999-2001, 2004-2005, 2007-2008, 2010-2012 Free
-   Software Foundation, Inc.
+   Copyright (C) 2012 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
@@ -24,20 +23,22 @@
 #include <mailutils/errno.h>
 
 int
-mu_list_remove (mu_list_t list, void *item)
+mu_list_remove_nth (mu_list_t list, size_t n)
 {
   struct list_data *current;
   mu_list_comparator_t comp;
   int status = MU_ERR_NOENT;
-
+  size_t i;
+    
   if (list == NULL)
     return EINVAL;
-  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
+  if (n >= list->count)
+    return ERANGE;
   mu_monitor_wrlock (list->monitor);
-  for (current = list->head.next;
-       current != &list->head; current = current->next)
+  for (current = list->head.next, i = 0; current != &list->head;
+       current = current->next, i++)
     {
-      if (comp (current->item, item) == 0)
+      if (i == n)
        {
          struct list_data *previous = current->prev;
          
@@ -56,10 +57,10 @@ mu_list_remove (mu_list_t list, void *item)
 }
 
 int
-mu_list_remove_nd (mu_list_t list, void *item)
+mu_list_remove_nth_nd (mu_list_t list, size_t n)
 {
   mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL);
-  int rc = mu_list_remove (list, item);
+  int rc = mu_list_remove_nth (list, n);
   mu_list_set_destroy_item (list, dptr);
   return rc;
 }
diff --git a/mail/escape.c b/mail/escape.c
index c0c0dcb..c1ec448 100644
--- a/mail/escape.c
+++ b/mail/escape.c
@@ -156,16 +156,29 @@ escape_continue (void)
   mu_printf (_("(continue)\n"));
 }
 
-static int 
-escape_check_args (int argc, char **argv)
+int 
+escape_check_args (int argc, char **argv, int minargs, int maxargs)
 {
-  if (argc == 1)
+  char *escape = "~";
+  if (argc < minargs)
     {
-      char *escape = "~";
+      minargs--;
       mailvar_get (&escape, "escape", mailvar_type_string, 0);
-      mu_error (_("%c%s requires an argument"), escape[0], argv[0]);
+      mu_error (ngettext ("%c%s requires at least %d argument",
+                         "%c%s requires at least %d arguments",
+                         minargs), escape[0], argv[0], minargs);
       return 1;
     }
+  if (maxargs > 1 && argc > maxargs)
+    {
+      maxargs--;
+      mailvar_get (&escape, "escape", mailvar_type_string, 0);
+      mu_error (ngettext ("%c%s accepts at most %d argument",
+                         "%c%s accepts at most %d arguments",
+                         maxargs), escape[0], argv[0], maxargs);
+      return 1;
+    }
+    
   return 0;
 }
 
@@ -184,7 +197,7 @@ escape_command (int argc, char **argv, compose_env_t *env)
   const struct mail_command_entry *entry;
   int status;
   
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   if (argv[1][0] == '#')
     return 0;
@@ -416,6 +429,8 @@ escape_editor (int argc, char **argv, compose_env_t *env)
   return escape_run_editor (getenv ("EDITOR"), argc, argv, env);
 }
 
+/* ~l -- escape_list_attachments (send.c) */
+
 /* ~v */
 int
 escape_visual (int argc, char **argv, compose_env_t *env)
@@ -457,7 +472,7 @@ escape_headers (int argc, char **argv, compose_env_t *env)
 int
 escape_insert (int argc, char **argv, compose_env_t *env)
 {
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   mailvar_variable_format (env->compstr, mailvar_find_variable (argv[1], 0),
                           NULL);
@@ -574,7 +589,7 @@ escape_read (int argc, char **argv, compose_env_t *env 
MU_ARG_UNUSED)
   mu_stream_t instr;
   int rc;
   
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   filename = util_fullpath (argv[1]);
 
@@ -597,7 +612,7 @@ int
 escape_subj (int argc, char **argv, compose_env_t *env)
 {
   char *buf;
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   mu_argcv_string (argc - 1, argv + 1, &buf);
   compose_header_set (env, MU_HEADER_SUBJECT, buf, COMPOSE_REPLACE);
@@ -623,7 +638,7 @@ escape_write (int argc, char **argv, compose_env_t *env)
   int rc;
   mu_off_t size;
   
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   filename = util_fullpath (argv[1]);
   /* FIXME: check for existence first */
diff --git a/mail/mail.c b/mail/mail.c
index e2eb63d..400bb0c 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -95,7 +95,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 
     case 'A':
       args->hint |= HINT_SEND_MODE;
-      if (send_attach_file (arg))
+      if (send_attach_file_default (arg))
        exit (1);
       break;
       
diff --git a/mail/mail.h b/mail/mail.h
index c116b1b..c754dfd 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -258,7 +258,9 @@ extern char *mail_expand_name (const char *name);
 
 extern void send_append_header (char *text);
 extern void send_append_header2 (char *name, char *value, int mode);
-extern int send_attach_file (const char *name);
+extern int send_attach_file_default (const char *name);
+
+extern int escape_check_args (int argc, char **argv, int minargs, int maxargs);
 
 extern int escape_shell (int argc, char **argv, compose_env_t *env);
 extern int escape_command (int argc, char **argv, compose_env_t *env);
@@ -280,6 +282,11 @@ extern int escape_visual (int argc, char **argv, 
compose_env_t *env);
 extern int escape_write (int argc, char **argv, compose_env_t *env);
 extern int escape_exit (int argc, char **argv, compose_env_t *env);
 extern int escape_pipe (int argc, char **argv, compose_env_t *env);
+extern int escape_list_attachments  (int argc, char **argv,
+                                    compose_env_t *env);
+extern int escape_attach (int argc, char **argv, compose_env_t *env);
+extern int escape_remove_attachment (int argc, char **argv,
+                                    compose_env_t *env);
 
 /* Cursor */
 extern void set_cursor (unsigned value);
diff --git a/mail/send.c b/mail/send.c
index 3b8d446..053a289 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -154,11 +154,13 @@ atchinfo_free (void *p)
 }
 
 int
-send_attach_file (const char *name)
+send_attach_file (const char *name,
+                 const char *content_type, const char *encoding)
 {
   int rc;
   struct stat st;
   struct atchinfo *aptr;
+  mu_list_t list;
   
   if (stat (name, &st))
     {
@@ -180,6 +182,16 @@ send_attach_file (const char *name)
       return 1;
     }
 
+  if (!encoding)
+    encoding = "base64";
+  mu_filter_get_list (&list);
+  rc = mu_list_locate (list, encoding, NULL);
+  if (rc)
+    {
+      mu_error (_("unsupported encoding: %s"), encoding);
+      return 1;
+    }
+  
   if (!attlist)
     {
       rc = mu_list_create (&attlist);
@@ -191,10 +203,10 @@ send_attach_file (const char *name)
       mu_list_set_destroy_item (attlist, atchinfo_free);
     }
   aptr = mu_alloc (sizeof (*aptr));
-  aptr->encoding = mu_strdup (default_encoding ?
-                             default_encoding : "base64");
-  aptr->content_type = mu_strdup (default_content_type ?
-                                 default_content_type :
+
+  aptr->encoding = mu_strdup (encoding);  
+  aptr->content_type = mu_strdup (content_type ?
+                                 content_type :
                                    "application/octet-stream");
   aptr->filename = mu_strdup (name);
   rc = mu_list_append (attlist, aptr);
@@ -206,6 +218,86 @@ send_attach_file (const char *name)
   return 0;
 }
 
+int
+send_attach_file_default (const char *name)
+{
+  return send_attach_file (name, default_content_type, default_encoding);
+}
+
+int
+escape_list_attachments (int argc, char **argv, compose_env_t *env)
+{
+  mu_iterator_t itr;
+  int i;
+  
+  if (mu_list_is_empty (attlist) ||
+      mu_list_get_iterator (attlist, &itr))
+    {
+      mu_printf ("%s\n", _("No attachments"));
+      return 0;
+    }
+  
+  for (mu_iterator_first (itr), i = 1; !mu_iterator_is_done (itr);
+       mu_iterator_next (itr), i++)
+    {
+      struct atchinfo *aptr;
+      if (mu_iterator_current (itr, (void**)&aptr))
+       continue;
+         
+      mu_printf ("%3d %-12s %-30s %-s\n",
+                i, aptr->filename, aptr->content_type, aptr->encoding);
+    }
+  mu_iterator_destroy (&itr);
+
+  return 0;
+}
+
+int
+escape_attach (int argc, char **argv, compose_env_t *env)
+{
+  const char *encoding = default_encoding;
+  const char *content_type = default_content_type;
+  
+  switch (argc)
+    {
+    case 4:
+      encoding = argv[3];
+    case 3:
+      content_type = argv[2];
+    case 2:
+      return send_attach_file (argv[1], content_type, encoding);
+    default:
+      return escape_check_args (argc, argv, 2, 4);
+    }
+  return 1;
+}
+
+int
+escape_remove_attachment (int argc, char **argv, compose_env_t *env)
+{
+  size_t count;
+  unsigned long n;
+  char *p;
+  
+  if (escape_check_args (argc, argv, 2, 2))
+    return 1;
+  n = strtoul (argv[1], &p, 10);
+  if (*p)
+    {
+      mu_error (_("not a valid number: %s"), argv[1]);
+      return 1;
+    }
+  
+  mu_list_count (attlist, &count);
+  if (n == 0 || n > count)
+    {
+      mu_error (_("index out of range"));
+      return 1;
+    }
+
+  return mu_list_remove_nth (attlist, n - 1);
+}
+
 static int
 saveatt (void *item, void *data)
 {
diff --git a/mail/table.c b/mail/table.c
index 41eda1d..a496612 100644
--- a/mail/table.c
+++ b/mail/table.c
@@ -226,6 +226,8 @@ static const struct mail_escape_entry mail_escape_table[] = 
{
   {"!",        "!",    "![shell-command]", escape_shell },
   {":",        ":",    ":[mail-command]",  escape_command },
   {"-",        "-",    "-[mail-command]",  escape_command },
+  {"+",        "+",    "+[name [content-type [encoding]]]", escape_attach },
+  {"^",        "^",    "^[N]",             escape_remove_attachment },
   {"?",        "?",    "?",                escape_help },
   {"A",        "A",    "A",                escape_sign },
   {"a",        "a",    "a",                escape_sign },
@@ -237,6 +239,7 @@ static const struct mail_escape_entry mail_escape_table[] = 
{
   {"F",        "F",    "F[mesg-list]",     escape_print },
   {"h",        "h",    "h",                escape_headers },
   {"i",        "i",    "i[var-name]",      escape_insert },
+  {"l",        "l",    "l",                escape_list_attachments },
   {"m",        "m",    "m[mesg-list]",     escape_quote },
   {"M",        "M",    "M[mesg-list]",     escape_quote },
   {"p",        "p",    "p",                escape_type_input },


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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