* Like iconv_open, but canonicalises the charsets
*/
-iconv_t mutt_iconv_open (const char *tocode, const char *fromcode)
+iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags)
{
char tocode1[SHORT_STRING];
char fromcode1[SHORT_STRING];
char *tmp;
mutt_canonical_charset (tocode1, sizeof (tocode1), tocode);
- if ((tmp = mutt_charset_hook (tocode1)))
+ if ((flags & M_ICONV_HOOK_TO) && (tmp = mutt_charset_hook (tocode1)))
mutt_canonical_charset (tocode1, sizeof (tocode1), tmp);
mutt_canonical_charset (fromcode1, sizeof (fromcode1), fromcode);
- if ((tmp = mutt_charset_hook (fromcode1)))
+ if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook (fromcode1)))
mutt_canonical_charset (fromcode1, sizeof (fromcode1), tmp);
return iconv_open (tocode1, fromcode1);
* Used in rfc2047.c and rfc2231.c
*/
-int mutt_convert_string (char **ps, const char *from, const char *to)
+int mutt_convert_string (char **ps, const char *from, const char *to, int flags)
{
iconv_t cd;
const char *repls[] = { "\357\277\275", "?", 0 };
if (!s || !*s)
return 0;
- if (to && from && (cd = mutt_iconv_open (to, from)) != (iconv_t)-1)
+ if (to && from && (cd = mutt_iconv_open (to, from, flags)) != (iconv_t)-1)
{
int len;
const char *ib;
iconv_t cd;
};
-FGETCONV *fgetconv_open (FILE *file, const char *from, const char *to)
+FGETCONV *fgetconv_open (FILE *file, const char *from, const char *to, int flags)
{
struct fgetconv_s *fc;
iconv_t cd = (iconv_t)-1;
static const char *repls[] = { "\357\277\275", "?", 0 };
if (from && to)
- cd = mutt_iconv_open (to, from);
+ cd = mutt_iconv_open (to, from, flags);
if (cd != (iconv_t)-1)
{
#include <iconv.h>
-int mutt_convert_string (char **, const char *, const char *);
+int mutt_convert_string (char **, const char *, const char *, int);
-iconv_t mutt_iconv_open (const char *, const char *);
+iconv_t mutt_iconv_open (const char *, const char *, int);
size_t mutt_iconv (iconv_t, const char **, size_t *, char **, size_t *, const char **, const char *);
typedef void * FGETCONV;
-FGETCONV *fgetconv_open (FILE *, const char *, const char *);
+FGETCONV *fgetconv_open (FILE *, const char *, const char *, int);
int fgetconv (FGETCONV *);
void fgetconv_close (FGETCONV **);
void mutt_set_langinfo_charset (void);
+#define M_ICONV_HOOK_FROM 1
+#define M_ICONV_HOOK_TO 2
+
#endif /* _CHARSET_H */
mp = safe_malloc (sizeof (struct msg));
mp->key = safe_strdup (orig);
mp->data = safe_strdup (orig);
- mutt_convert_string (&mp->data, PoCharset ? PoCharset : "utf-8", MessageCharset);
+ mutt_convert_string (&mp->data, PoCharset ? PoCharset : "utf-8",
+ MessageCharset, 0);
# ifdef DEBUG
if (debugfile)
}
*d = '\0';
- if (_chs && (cd = mutt_iconv_open (_chs, "utf-8")) != (iconv_t)-1)
+ if (_chs && (cd = mutt_iconv_open (_chs, "utf-8", 0)) != (iconv_t)-1)
{
int n = s - uid + 1; /* chars available in original buffer */
char *buf;
{
char *charset = mutt_get_parameter ("charset", b->parameter);
if (charset && Charset)
- cd = mutt_iconv_open (Charset, charset);
+ cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM);
}
fseek (s->fpin, b->offset, 0);
if (Charset)
{
char *t = safe_strdup (*s);
- if (!mutt_convert_string (&t, Charset, "UTF-8"))
+ if (!mutt_convert_string (&t, Charset, "UTF-8", 0))
utf8_to_utf7 (t, strlen (t), s, 0);
safe_free ((void **) &t);
}
if (Charset)
{
char *t = utf7_to_utf8 (*s, strlen (*s), 0, 0);
- if (t && !mutt_convert_string (&t, "UTF-8", Charset))
+ if (t && !mutt_convert_string (&t, "UTF-8", Charset, 0))
{
safe_free ((void **) s);
*s = t;
size_t obl, n;
int e;
- cd = mutt_iconv_open (to, from);
+ cd = mutt_iconv_open (to, from, 0);
if (cd == (iconv_t)(-1))
return (size_t)(-1);
obl = 4 * flen + 1;
if (fromcode)
{
- cd = mutt_iconv_open (tocode, fromcode);
+ cd = mutt_iconv_open (tocode, fromcode, 0);
assert (cd != (iconv_t)(-1));
ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode);
if (iconv (cd, &ib, &ibl, &ob, &obl) == (size_t)(-1) ||
if (fromcode)
{
- cd = mutt_iconv_open (tocode, fromcode);
+ cd = mutt_iconv_open (tocode, fromcode, 0);
assert (cd != (iconv_t)(-1));
ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode);
n1 = iconv (cd, &ib, &ibl, &ob, &obl);
}
if (charset)
- mutt_convert_string (&d0, charset, Charset);
+ mutt_convert_string (&d0, charset, Charset, M_ICONV_HOOK_FROM);
strfcpy (d, d0, len);
safe_free ((void **) &charset);
safe_free ((void **) &d0);
s = rfc2231_get_charset (p->value, charset, sizeof (charset));
rfc2231_decode_one (p->value, s);
- mutt_convert_string (&p->value, charset, Charset);
+ mutt_convert_string (&p->value, charset, Charset, M_ICONV_HOOK_FROM);
*last = p;
last = &p->next;
if (value)
{
if (encoded)
- mutt_convert_string (&value, charset, Charset);
+ mutt_convert_string (&value, charset, Charset, M_ICONV_HOOK_FROM);
*head = mutt_new_parameter ();
(*head)->attribute = safe_strdup (attribute);
(*head)->value = value;
}
if (a->type == TYPETEXT && (!a->noconv))
- fc = fgetconv_open (fpin, Charset, mutt_get_body_charset (send_charset, sizeof (send_charset), a));
+ fc = fgetconv_open (fpin, Charset,
+ mutt_get_body_charset (send_charset, sizeof (send_charset), a),
+ M_ICONV_HOOK_TO);
else
- fc = fgetconv_open (fpin, 0, 0);
+ fc = fgetconv_open (fpin, 0, 0, 0);
if (a->encoding == ENCQUOTEDPRINTABLE)
encode_quoted (fc, f, mutt_is_text_type (a->type, a->subtype));
CONTENT_STATE *states;
size_t *score;
- cd1 = mutt_iconv_open ("UTF-8", fromcode);
+ cd1 = mutt_iconv_open ("UTF-8", fromcode, M_ICONV_HOOK_FROM);
if (cd1 == (iconv_t)(-1))
return -1;
memset (infos, 0, ncodes * sizeof (CONTENT));
for (i = 0; i < ncodes; i++)
if (strcasecmp (tocodes[i], "UTF-8"))
- cd[i] = mutt_iconv_open (tocodes[i], "UTF-8");
+ cd[i] = mutt_iconv_open (tocodes[i], "UTF-8", 0);
else
/* Special case for conversion to UTF-8 */
cd[i] = (iconv_t)(-1), score[i] = (size_t)(-1);