[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-mailutils] bug in mail alias handling
From: |
Sergey Poznyakoff |
Subject: |
Re: [bug-mailutils] bug in mail alias handling |
Date: |
Mon, 16 Jan 2006 15:09:58 EET |
Walter Neumann <address@hidden> wrote:
> If mail is given more than one address in the command line it fails
> to parse aliases.
Thank you. I've fixed it in the CVS. Here is the patch for 0.6.92:
Index: NEWS
===================================================================
RCS file: /cvsroot/mailutils/mailutils/NEWS,v
retrieving revision 1.53
diff -p -u -r1.53 NEWS
--- NEWS 30 Oct 2005 18:44:01 -0000 1.53
+++ NEWS 16 Jan 2006 12:26:06 -0000
@@ -21,8 +21,17 @@ obtain loader options (which is recommen
* mail: New option --exec (-E) allows to execute arbitrary mail commands
before opening the mailbox. Any number of --exec options can be given.
+** New variables `recursivealiases' and `inplacealiases' control the way
+mail aliases are expanded. When `recursivealiases' is set, aliases
+will be expanded recursively. When `inplacealiases' is set, alias
+expansion takes place before entering compose mode (by default, it is
+carried out when exiting compose mode, right before sending the
+message). The default is `set recursivealiases noinplacealiases'.
+
* Bugfixes:
** mail: Fix handling of conditional expressions
+** mail: When several recipients were specified, no alias expansion took
+place.
Version 0.6.91:
Index: doc/texinfo/programs.texi
===================================================================
RCS file: /cvsroot/mailutils/mailutils/doc/texinfo/programs.texi,v
retrieving revision 1.58
diff -p -u -r1.58 programs.texi
--- doc/texinfo/programs.texi 30 Oct 2005 10:51:41 -0000 1.58
+++ doc/texinfo/programs.texi 16 Jan 2006 12:26:06 -0000
@@ -1999,6 +1999,15 @@ composed.
String used by the @code{~m} tilde escape for indenting quoted messages.
address@hidden inplacealiases
address@hidden: Boolean
address@hidden: False
+
+If set, @command{mail} will expand aliases in the address header field
+before entering send mode (@pxref{Composing Mail}). By default, the
+address header fields are left intact while composing, the alias
+expansion takes place immediately before sending message.
+
@item keepsave
@*Type: Boolean.
@*Default: False.
@@ -2132,6 +2141,12 @@ configuration file upon startup. See @re
When set, any outgoing message will be saved to the named file.
address@hidden recursivealiases
address@hidden: Boolean
address@hidden: True
+
+When set, @command{mail} will expand aliases recursively.
+
@item regex
@*Type: Boolean.
@*Default: True.
Index: mail/alias.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/alias.c,v
retrieving revision 1.17
diff -p -u -r1.17 alias.c
--- mail/alias.c 27 Aug 2005 11:37:35 -0000 1.17
+++ mail/alias.c 16 Jan 2006 12:26:06 -0000
@@ -258,11 +258,75 @@ alias_destroy (char *name)
}
}
+static void
+recursive_alias_expand (char *name, mu_list_t exlist, mu_list_t origlist)
+{
+ mu_list_t alist;
+ mu_iterator_t itr;
+
+ if (!alias_lookup (name, &alist))
+ {
+ if (mu_list_locate (exlist, name, NULL) == MU_ERR_NOENT)
+ mu_list_append (exlist, name);
+ return;
+ }
+
+ mu_list_get_iterator (alist, &itr);
+ for (mu_iterator_first (itr);
+ !mu_iterator_is_done (itr);
+ mu_iterator_next (itr))
+ {
+ char *word;
+
+ mu_iterator_current (itr, (void **)&word);
+ if (mu_list_locate (origlist, word, NULL) == MU_ERR_NOENT)
+ {
+ mu_list_prepend (origlist, word);
+ recursive_alias_expand (word, exlist, origlist);
+ mu_list_remove (origlist, word);
+ }
+ }
+ mu_iterator_destroy (&itr);
+}
+
+static int
+string_comp (const void *item, const void *value)
+{
+ return strcmp (item, value);
+}
+
char *
alias_expand (char *name)
{
mu_list_t list;
+ if (util_getenv (NULL, "recursivealiases", Mail_env_boolean, 0) == 0)
+ {
+ char *s;
+ mu_list_t origlist;
+
+ int status = mu_list_create (&list);
+ if (status)
+ {
+ mu_error (_("Cannot create list: %s"), mu_strerror (status));
+ return NULL;
+ }
+ status = mu_list_create (&origlist);
+ if (status)
+ {
+ mu_list_destroy (&origlist);
+ mu_error (_("Cannot create list: %s"), mu_strerror (status));
+ return NULL;
+ }
+ mu_list_set_comparator (list, string_comp);
+ mu_list_set_comparator (origlist, string_comp);
+ recursive_alias_expand (name, list, origlist);
+ s = util_slist_to_string (list, ",");
+ mu_list_destroy (&origlist);
+ mu_list_destroy (&list);
+ return s;
+ }
+
if (!alias_lookup (name, &list))
return NULL;
return util_slist_to_string (list, ",");
Index: mail/mail.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/mail.c,v
retrieving revision 1.95
diff -p -u -r1.95 mail.c
--- mail/mail.c 30 Oct 2005 10:03:04 -0000 1.95
+++ mail/mail.c 16 Jan 2006 12:26:06 -0000
@@ -268,6 +268,8 @@ static char *default_setup[] = {
"sender mail-followup-to reply-to from",
"set nocmd",
"set metamail",
+ "set recursivealiases",
+ "set noinplacealiases",
/* Start in mail reading mode */
"set mode=read",
Index: mail/mail.h
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/mail.h,v
retrieving revision 1.79
diff -p -u -r1.79 mail.h
--- mail/mail.h 27 Aug 2005 11:37:40 -0000 1.79
+++ mail/mail.h 16 Jan 2006 12:26:06 -0000
@@ -370,6 +370,8 @@ void util_rfc2047_decode (char **value);
void util_mark_read (mu_message_t msg);
+int is_address_field (const char *name);
+
extern int ml_got_interrupt (void);
extern void ml_clear_interrupt (void);
extern void ml_readline_init (void);
Index: mail/send.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/send.c,v
retrieving revision 1.49
diff -p -u -r1.49 send.c
--- mail/send.c 15 Nov 2005 15:13:16 -0000 1.49
+++ mail/send.c 16 Jan 2006 12:26:06 -0000
@@ -221,6 +221,9 @@ compose_header_set (compose_env_t * env,
int status;
char *old_value;
+ if (!value || value[0] == 0)
+ return EINVAL;
+
if (!env->header
&& (status = mu_header_create (&env->header, NULL, 0, NULL)) != 0)
{
@@ -232,23 +235,50 @@ compose_header_set (compose_env_t * env,
{
case COMPOSE_REPLACE:
case COMPOSE_APPEND:
- status = mu_header_set_value (env->header, name, value, mode);
+ if (is_address_field (name)
+ && util_getenv (NULL, "inplacealiases", Mail_env_boolean, 0) == 0)
+ {
+ char *exp = alias_expand (value);
+ status = mu_header_set_value (env->header, name, exp ? exp : value,
+ mode);
+ free (exp);
+ }
+ else
+ status = mu_header_set_value (env->header, name, value, mode);
break;
case COMPOSE_SINGLE_LINE:
- if (!value || value[0] == 0)
- return EINVAL;
-
if (mu_header_aget_value (env->header, name, &old_value) == 0
&& old_value[0])
{
- status = util_merge_addresses (&old_value, value);
- if (status == 0)
- status = mu_header_set_value (env->header, name, old_value, 1);
+ if (is_address_field (name)
+ && util_getenv (NULL, "inplacealiases", Mail_env_boolean, 0) == 0)
+ {
+ char *exp = alias_expand (value);
+ status = util_merge_addresses (&old_value, exp ? exp : value);
+ if (status == 0)
+ status = mu_header_set_value (env->header, name, old_value, 1);
+ free (exp);
+ }
+ else
+ {
+ size_t size = strlen (old_value) + strlen (value) + 2;
+ char *p = realloc (old_value, size);
+ if (!p)
+ status = ENOMEM;
+ else
+ {
+ old_value = p;
+ strcat (old_value, ",");
+ strcat (old_value, value);
+ status = mu_header_set_value (env->header, name, old_value,
+ 1);
+ }
+ }
free (old_value);
}
else
- status = mu_header_set_value (env->header, name, value, 1);
+ status = compose_header_set (env, name, value, COMPOSE_REPLACE);
}
return status;
Index: mail/util.c
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/util.c,v
retrieving revision 1.84
diff -p -u -r1.84 util.c
--- mail/util.c 5 Dec 2005 09:32:06 -0000 1.84
+++ mail/util.c 16 Jan 2006 12:26:06 -0000
@@ -1254,7 +1254,7 @@ util_merge_addresses (char **addr_str, c
return rc;
}
-static int
+int
is_address_field (const char *name)
{
static char *address_fields[] = {
@@ -1301,7 +1301,7 @@ util_header_expand (mu_header_t *phdr)
if (is_address_field (name))
{
- char *p, *s, *exp;
+ char *p, *s, *exp = NULL;
mu_address_t addr = NULL;
if (mu_header_aget_value (hdr, name, &exp) == 0)
@@ -1316,7 +1316,9 @@ util_header_expand (mu_header_t *phdr)
while (*p && isspace (*p))
p++;
- exp = alias_expand (p);
+ /* If inplacealiases was set, the value was already expanded */
+ if (util_getenv (NULL, "inplacealiases", Mail_env_boolean, 0))
+ exp = alias_expand (p);
rc = mu_address_create (&new_addr, exp ? exp : p);
if (rc)
{
Index: mail/testsuite/mail/send.exp
===================================================================
RCS file: /cvsroot/mailutils/mailutils/mail/testsuite/mail/send.exp,v
retrieving revision 1.4
diff -p -u -r1.4 send.exp
--- mail/testsuite/mail/send.exp 17 May 2005 13:13:37 -0000 1.4
+++ mail/testsuite/mail/send.exp 16 Jan 2006 12:26:06 -0000
@@ -20,6 +20,7 @@
mail_start "--file=%mbox1"
mail_command "set sendmail=\"sendmail:$top_builddir/examples/mta\""
+mail_command "set inplacealiases"
mail_command "setenv MTA_DIAG=\"$MU_FOLDER_DIR/mta.diag\""
mail_test -noprompt "reply 1" \
Regards,
Sergey