#include "mutt_curses.h"
#include <string.h>
+#include <ctype.h>
ADDRESS *mutt_lookup_alias (const char *s)
{
{
ALIAS *new, *t;
char buf[LONG_STRING], prompt[SHORT_STRING], *pc;
+ char fixed[LONG_STRING];
FILE *rc;
ADDRESS *adr = NULL;
}
else
buf[0] = '\0';
+
+ /* Don't suggest a bad alias name in the event of a strange local part. */
+ mutt_check_alias_name (buf, buf);
+retry_name:
/* add a new alias */
if (mutt_get_field (_("Alias as: "), buf, sizeof (buf), 0) != 0 || !buf[0])
return;
mutt_error _("You already have an alias defined with that name!");
return;
}
-
+
+ if (mutt_check_alias_name (buf, fixed))
+ {
+ switch (mutt_yesorno (_("Warning: This alias name may not work. Fix it?"), 1))
+ {
+ case 1:
+ strfcpy (buf, fixed, sizeof (buf));
+ goto retry_name;
+ case -1:
+ return;
+ }
+ }
+
new = safe_calloc (1, sizeof (ALIAS));
new->self = new;
new->name = safe_strdup (buf);
mutt_expand_path (buf, sizeof (buf));
if ((rc = fopen (buf, "a")))
{
+ if (mutt_check_alias_name (new->name, NULL))
+ mutt_quote_filename (buf, sizeof (buf), new->name);
+ else
+ strfcpy (buf, new->name, sizeof (buf));
+ fprintf (rc, "alias %s ", buf);
buf[0] = 0;
rfc822_write_address (buf, sizeof (buf), new->addr);
- fprintf (rc, "alias %s ", new->name);
write_safe_address (rc, buf);
fputc ('\n', rc);
fclose (rc);
mutt_perror (buf);
}
+/*
+ * Sanity-check an alias name: Only characters which are non-special to both
+ * the RFC 822 and the mutt configuration parser are permitted.
+ */
+
+static int check_alias_name_char (char c)
+{
+ return (c == '-' || c == '_' || c == '+' || c == '=' || c == '.' ||
+ isalnum (c));
+}
+
+int mutt_check_alias_name (const char *s, char *d)
+{
+ int rv = 0;
+ for (; *s; s++)
+ {
+ if (!check_alias_name_char (*s))
+ {
+ if (!d)
+ return -1;
+ else
+ {
+ *d++ = '_';
+ rv = -1;
+ }
+ }
+ else if (d)
+ *d++ = *s;
+ }
+ if (d)
+ *d++ = *s;
+ return rv;
+}
+
/*
* This routine looks to see if the user has an alias defined for the given
* address.
{
ALIAS *tmp = Aliases;
ALIAS *last = NULL;
- char *p;
- size_t len;
- if ((p = strpbrk (s->dptr, " \t")) == NULL)
+ if (!MoreArgs (s))
{
strfcpy (err->data, _("alias: no address"), err->dsize);
return (-1);
}
- len = p - s->dptr;
+ mutt_extract_token (buf, s, 0);
/* check to see if an alias with this name already exists */
for (; tmp; tmp = tmp->next)
{
- if (!mutt_strncasecmp (tmp->name, s->dptr, len) && *(tmp->name + len) == 0)
+ if (!mutt_strcasecmp (tmp->name, buf->data))
break;
last = tmp;
}
/* create a new alias */
tmp = (ALIAS *) safe_calloc (1, sizeof (ALIAS));
tmp->self = tmp;
- tmp->name = safe_malloc (len + 1);
- memcpy (tmp->name, s->dptr, len);
- tmp->name[len] = 0;
+ tmp->name = safe_strdup (buf->data);
/* give the main addressbook code a chance */
if (CurrentMenu == MENU_ALIAS)
set_option (OPTMENUCALLER);
if (CurrentMenu == MENU_ALIAS)
set_option (OPTFORCEREDRAWINDEX);
}
- s->dptr = p;
mutt_extract_token (buf, s, M_TOKEN_QUOTE | M_TOKEN_SPACE | M_TOKEN_SEMICOLON);
tmp->addr = mutt_parse_adrlist (tmp->addr, buf->data);
int mutt_builtin_editor (const char *, HEADER *, HEADER *);
int mutt_can_decode (BODY *);
int mutt_change_flag (HEADER *, int);
+int mutt_check_alias_name (const char *, char *);
int mutt_check_encoding (const char *);
int mutt_check_key (const char *);
int mutt_check_menu (const char *);