#endif
@import "lib-lua/base.cpkg"
+static rx_t *charset_hooks = NULL;
+static rx_t *iconv_hooks = NULL;
+
@package MCharset {
/*
** .pp
** instead of or after \fTiso-8859-1\fP.
*/
string_t send_charset = m_strdup("us-ascii:iso-8859-1:utf-8");
+
+ void charset_hook(rx_t local, const string_t alias) {
+ rx_set_template(local, alias);
+ rx_list_append(&charset_hooks, local);
+ };
+
+ void iconv_hook(rx_t local, const string_t alias) {
+ rx_set_template(local, alias);
+ rx_list_append(&iconv_hooks, local);
+ };
};
int Charset_is_utf8 = 0;
/* Like iconv_open, but canonicalises the charsets */
iconv_t mutt_iconv_open(const char *tocode, const char *fromcode, int flags)
{
- char tocode1[STRING];
- char fromcode1[STRING];
- const char *tmp;
-
+ char to1[STRING];
+ char from1[STRING];
+ char tmp[STRING];
iconv_t cd;
- if ((flags & M_ICONV_HOOK_TO) && (tmp = mutt_charset_hook(tocode1))) {
- charset_canonicalize(tocode1, sizeof(tocode1), tmp);
+ if ((flags & M_ICONV_HOOK_TO)
+ && rx_list_match2(charset_hooks, tocode, tmp, sizeof(tmp))) {
+ charset_canonicalize(to1, sizeof(to1), tmp);
} else {
- charset_canonicalize(tocode1, sizeof(tocode1), tocode);
+ charset_canonicalize(to1, sizeof(to1), tocode);
}
- if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook(fromcode1))) {
- charset_canonicalize(fromcode1, sizeof(fromcode1), tmp);
+ if ((flags & M_ICONV_HOOK_FROM)
+ && rx_list_match2(charset_hooks, fromcode, tmp, sizeof(tmp))) {
+ charset_canonicalize(from1, sizeof(from1), tmp);
} else {
- charset_canonicalize(fromcode1, sizeof(fromcode1), fromcode);
+ charset_canonicalize(from1, sizeof(from1), fromcode);
}
- cd = iconv_open(tocode1, fromcode1);
- if (cd != MUTT_ICONV_ERROR)
+ if ((cd = iconv_open(to1, from1)) != MUTT_ICONV_ERROR)
return cd;
{
- const char *to = mutt_iconv_hook(tocode1);
- const char *from = mutt_iconv_hook(fromcode1);
+ char to2[STRING];
+ char from2[STRING];
- return to && from ? iconv_open(to, from) : MUTT_ICONV_ERROR;
+ if (rx_list_match2(iconv_hooks, to1, to2, sizeof(to2))
+ && rx_list_match2(iconv_hooks, from1, from2, sizeof(from2)))
+ return iconv_open(to2, from2);
}
+ return MUTT_ICONV_ERROR;
}