Commit 7dc0082f authored by Thomas Roessler's avatar Thomas Roessler

Add the charset-hook command.

parent 20bd486b
......@@ -37,7 +37,8 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP TODO configure acconfig.h attach.h \
mailbox.h mapping.h mime.h mutt.h mutt_curses.h mutt_menu.h \
mutt_regex.h mutt_socket.h mx.h pager.h parse.h pgp.h protos.h \
reldate.h rfc1524.h rfc2047.h rfc822.h sha.h sha_locl.h \
sort.h mime.types VERSION prepare _regex.h OPS.MIX
sort.h mime.types VERSION prepare _regex.h OPS.MIX \
\\$$output.in
BUILT_SOURCES = mutt_dotlock.c keymap_defs.h
......
......@@ -617,12 +617,18 @@ CHARSET *mutt_get_charset (const char *name)
CHARSET *charset;
char buffer[SHORT_STRING];
char *real_charset;
char *hooked;
if (!name || !*name)
return (NULL);
init_charsets();
canonical_charset(buffer, sizeof(buffer), name);
canonical_charset (buffer, sizeof(buffer), name);
/* needs to be documented */
if ((hooked = mutt_charset_hook (buffer)))
canonical_charset (buffer, sizeof (buffer), hooked);
dprint (2, (debugfile, "mutt_get_charset: Looking for %s\n", buffer));
......
......@@ -84,7 +84,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
memset (&pattern, 0, sizeof (pattern));
pattern.data = safe_strdup (path);
}
else if (DefaultHook
else if (DefaultHook && !(data & M_CHARSETHOOK)
#ifdef _PGPPATH
&& !(data & M_PGPHOOK)
#endif /* _PGPPATH */
......@@ -153,9 +153,9 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
{
rx = safe_malloc (sizeof (regex_t));
#ifdef M_PGPHOOK
if ((rc = REGCOMP (rx, pattern.data, ((data & M_PGPHOOK) ? REG_ICASE : 0))) != 0)
if ((rc = REGCOMP (rx, pattern.data, ((data & (M_PGPHOOK|M_CHARSETHOOK)) ? REG_ICASE : 0))) != 0)
#else
if ((rc = REGCOMP (rx, pattern.data, 0)) != 0)
if ((rc = REGCOMP (rx, pattern.data, (data & M_CHARSETHOOK) ? REG_ICASE : 0)) != 0)
#endif /* _PGPPATH */
{
regerror (rc, rx, err->data, err->dsize);
......@@ -330,18 +330,27 @@ void mutt_select_fcc (char *path, size_t pathlen, HEADER *hdr)
mutt_pretty_mailbox (path);
}
#ifdef _PGPPATH
char *mutt_pgp_hook (ADDRESS *adr)
static char *_mutt_string_hook (const char *match, int hook)
{
HOOK *tmp = Hooks;
for (; tmp; tmp = tmp->next)
{
if ((tmp->type & M_PGPHOOK) && ((adr->mailbox &&
regexec (tmp->rx.rx, adr->mailbox, 0, NULL, 0) == 0) ^ tmp->rx.not))
if ((tmp->type & M_PGPHOOK) && ((match &&
regexec (tmp->rx.rx, match, 0, NULL, 0) == 0) ^ tmp->rx.not))
return (tmp->command);
}
return (NULL);
}
#endif /* _PGPPATH */
char *mutt_charset_hook (const char *chs)
{
return _mutt_string_hook (chs, M_CHARSETHOOK);
}
#ifdef _PGPPATH
char *mutt_pgp_hook (ADDRESS *adr)
{
return _mutt_string_hook (adr->mailbox, M_PGPHOOK);
}
#endif /* _PGPPATH */
......@@ -338,6 +338,7 @@ struct command_t Commands[] = {
{ "auto_view", parse_list, UL &AutoViewList },
{ "alternative_order", parse_list, UL &AlternativeOrderList},
{ "bind", mutt_parse_bind, 0 },
{ "charset-hook", mutt_parse_hook, M_CHARSETHOOK },
#ifdef HAVE_COLOR
{ "color", mutt_parse_color, 0 },
{ "uncolor", mutt_parse_uncolor, 0 },
......
......@@ -140,8 +140,9 @@ typedef enum
#define M_SENDHOOK (1<<2)
#define M_FCCHOOK (1<<3)
#define M_SAVEHOOK (1<<4)
#define M_CHARSETHOOK (1<<5)
#ifdef _PGPPATH
#define M_PGPHOOK (1<<5)
#define M_PGPHOOK (1<<6)
#endif
/* tree characters for linearize_tree and print_enriched_string */
......
......@@ -109,6 +109,7 @@ const char *mutt_attach_fmt (
unsigned long data,
format_flag flags);
char *mutt_charset_hook (const char *);
char *mutt_expand_path (char *, size_t);
char *mutt_find_hook (int, const char *);
char *mutt_gen_msgid (void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment