To avoid a clash with the configset functions to come.
s = mutt_str_strdup(buf);
if (!s)
return;
- if (mutt_cs_convert_string(&s, Charset, ConfigCharset, 0) == 0)
+ if (mutt_ch_convert_string(&s, Charset, ConfigCharset, 0) == 0)
mutt_str_strfcpy(buf, s, buflen);
FREE(&s);
}
{
char *desc = mutt_str_strdup(folder->ff->nd->desc);
if (NewsgroupsCharset && *NewsgroupsCharset)
- mutt_cs_convert_string(&desc, NewsgroupsCharset, Charset, MUTT_ICONV_HOOK_FROM);
+ mutt_ch_convert_string(&desc, NewsgroupsCharset, Charset, MUTT_ICONV_HOOK_FROM);
mutt_filter_unprintable(&desc);
snprintf(fmt, sizeof(fmt), "%%%ss", prec);
fputs("MIME-Version: 1.0\n", out);
fputs("Content-Transfer-Encoding: 8bit\n", out);
fputs("Content-Type: text/plain; charset=", out);
- mutt_cs_canonical_charset(chsbuf, sizeof(chsbuf),
+ mutt_ch_canonical_charset(chsbuf, sizeof(chsbuf),
Charset ? Charset : "us-ascii");
mutt_addr_cat(buffer, sizeof(buffer), chsbuf, MimeSpecials);
fputs(buffer, out);
while (true)
{
ob = bufo, obl = sizeof(bufo);
- mutt_cs_iconv(cd, &ib, &ibl, &ob, &obl, 0, "?");
+ mutt_ch_iconv(cd, &ib, &ibl, &ob, &obl, 0, "?");
if (ob == bufo)
break;
state_prefix_put(bufo, ob - bufo, s);
{
char *charset = mutt_param_get("charset", b->parameter);
if (!charset && AssumedCharset && *AssumedCharset)
- charset = mutt_cs_get_default_charset();
+ charset = mutt_ch_get_default_charset();
if (charset && Charset)
- cd = mutt_cs_iconv_open(Charset, charset, MUTT_ICONV_HOOK_FROM);
+ cd = mutt_ch_iconv_open(Charset, charset, MUTT_ICONV_HOOK_FROM);
}
else if (istext && b->charset)
- cd = mutt_cs_iconv_open(Charset, b->charset, MUTT_ICONV_HOOK_FROM);
+ cd = mutt_ch_iconv_open(Charset, b->charset, MUTT_ICONV_HOOK_FROM);
fseeko(s->fpin, b->offset, SEEK_SET);
switch (b->encoding)
if (convert && !mutt_str_is_ascii(c, size))
{
p = mutt_str_substr_dup(c, c + size);
- if (mutt_cs_convert_string(&p, Charset, "utf-8", 0) == 0)
+ if (mutt_ch_convert_string(&p, Charset, "utf-8", 0) == 0)
{
c = p;
size = mutt_str_strlen(c) + 1;
if (convert && !mutt_str_is_ascii(*c, size))
{
char *tmp = mutt_str_strdup(*c);
- if (mutt_cs_convert_string(&tmp, "utf-8", Charset, 0) == 0)
+ if (mutt_ch_convert_string(&tmp, "utf-8", Charset, 0) == 0)
{
mutt_str_replace(c, tmp);
}
* * SpamList
* * NoSpamList
* - Neomutt functions
- * * mutt_cs_convert_string()
+ * * mutt_ch_convert_string()
* * mutt_encode_path()
* * mutt_new_body()
* * mutt_env_new()
p = mutt_str_strdup(linebuf + read);
if (p)
{
- mutt_cs_convert_string(&p, "utf-8", Charset, 0);
+ mutt_ch_convert_string(&p, "utf-8", Charset, 0);
mutt_history_add(hclass, p, false);
FREE(&p);
}
}
tmp = mutt_str_strdup(s);
- mutt_cs_convert_string(&tmp, Charset, "utf-8", 0);
+ mutt_ch_convert_string(&tmp, Charset, "utf-8", 0);
/* Format of a history item (1 line): "<histclass>:<string>|".
We add a '|' in order to avoid lines ending with '\'. */
{
/* These are managed separately by the charset code */
enum LookupType type = (data & MUTT_CHARSETHOOK) ? MUTT_LOOKUP_CHARSET : MUTT_LOOKUP_ICONV;
- if (!mutt_cs_lookup_add(type, pattern.data, command.data, err))
+ if (!mutt_ch_lookup_add(type, pattern.data, command.data, err))
goto error;
FREE(&pattern.data);
FREE(&command.data);
return -1;
}
delete_hooks(0);
- mutt_cs_lookup_remove();
+ mutt_ch_lookup_remove();
}
else
{
}
if (type & (MUTT_CHARSETHOOK | MUTT_ICONVHOOK))
{
- mutt_cs_lookup_remove();
+ mutt_ch_lookup_remove();
return 0;
}
if (current_hook_type == type)
if (Charset)
{
char *t = mutt_str_strdup(*s);
- if (t && !mutt_cs_convert_string(&t, Charset, "utf-8", 0))
+ if (t && !mutt_ch_convert_string(&t, Charset, "utf-8", 0))
{
FREE(s);
if (idata->unicode)
else
t = utf7_to_utf8(*s, strlen(*s), 0, 0);
- if (t && !mutt_cs_convert_string(&t, "utf-8", Charset, 0))
+ if (t && !mutt_ch_convert_string(&t, "utf-8", Charset, 0))
{
FREE(s);
*s = t;
{
if (!*p)
continue;
- if (!mutt_cs_check_charset(p, strict))
+ if (!mutt_ch_check_charset(p, strict))
{
rc = -1;
break;
currentline = mutt_str_strdup(linebuf);
if (!currentline)
continue;
- mutt_cs_convert_string(¤tline, ConfigCharset, Charset, 0);
+ mutt_ch_convert_string(¤tline, ConfigCharset, Charset, 0);
}
else
currentline = linebuf;
if (p)
From = mutt_addr_parse_list(NULL, p);
- mutt_cs_set_langinfo_charset();
+ mutt_ch_set_langinfo_charset();
mutt_set_charset(Charset);
Matches = mutt_mem_calloc(MatchesListsize, sizeof(char *));
{
char buffer[STRING];
- mutt_cs_canonical_charset(buffer, sizeof(buffer), charset);
+ mutt_ch_canonical_charset(buffer, sizeof(buffer), charset);
- if (mutt_cs_is_utf8(buffer))
+ if (mutt_ch_is_utf8(buffer))
{
Charset_is_utf8 = true;
ReplacementChar = 0xfffd;
*
* | Function | Description
* | :----------------------------- | :---------------------------------------------------------
- * | mutt_cs_canonical_charset() | Canonicalise the charset of a string
- * | mutt_cs_charset_lookup() | Look for a replacement character set
- * | mutt_cs_check_charset() | Does iconv understand a character set?
- * | mutt_cs_chscmp() | Are the names of two character sets equivalent?
- * | mutt_cs_convert_string() | Convert a string between encodings
- * | mutt_cs_fgetconv() | Convert a file's character set
- * | mutt_cs_fgetconvs() | Convert a file's charset into a string buffer
- * | mutt_cs_fgetconv_close() | Close an fgetconv handle
- * | mutt_cs_fgetconv_open() | Prepare a file for charset conversion
- * | mutt_cs_get_default_charset() | Get the default character set
- * | mutt_cs_iconv() | Change the encoding of a string
- * | mutt_cs_iconv_lookup() | Look for a replacement character set
- * | mutt_cs_iconv_open() | Set up iconv for conversions
- * | mutt_cs_lookup_add() | Add a new character set lookup
- * | mutt_cs_lookup_remove() | Remove all the character set lookups
- * | mutt_cs_set_langinfo_charset() | Set the user's choice of character set
+ * | mutt_ch_canonical_charset() | Canonicalise the charset of a string
+ * | mutt_ch_charset_lookup() | Look for a replacement character set
+ * | mutt_ch_check_charset() | Does iconv understand a character set?
+ * | mutt_ch_chscmp() | Are the names of two character sets equivalent?
+ * | mutt_ch_convert_string() | Convert a string between encodings
+ * | mutt_ch_fgetconv() | Convert a file's character set
+ * | mutt_ch_fgetconvs() | Convert a file's charset into a string buffer
+ * | mutt_ch_fgetconv_close() | Close an fgetconv handle
+ * | mutt_ch_fgetconv_open() | Prepare a file for charset conversion
+ * | mutt_ch_get_default_charset() | Get the default character set
+ * | mutt_ch_iconv() | Change the encoding of a string
+ * | mutt_ch_iconv_lookup() | Look for a replacement character set
+ * | mutt_ch_iconv_open() | Set up iconv for conversions
+ * | mutt_ch_lookup_add() | Add a new character set lookup
+ * | mutt_ch_lookup_remove() | Remove all the character set lookups
+ * | mutt_ch_set_langinfo_charset() | Set the user's choice of character set
*/
#include "config.h"
}
/**
- * mutt_cs_canonical_charset - Canonicalise the charset of a string
+ * mutt_ch_canonical_charset - Canonicalise the charset of a string
* @param buf Buffer for canonical character set name
* @param buflen Length of buffer
* @param name Name to be canonicalised
* This first ties off any charset extension such as "//TRANSLIT",
* canonicalizes the charset and re-adds the extension
*/
-void mutt_cs_canonical_charset(char *buf, size_t buflen, const char *name)
+void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
{
char *p = NULL, *ext = NULL;
char in[LONG_STRING], scratch[LONG_STRING];
}
/**
- * mutt_cs_chscmp - Are the names of two character sets equivalent?
+ * mutt_ch_chscmp - Are the names of two character sets equivalent?
* @param cs1 First character set
* @param cs2 Second character set
* @retval num true if the names are equivalent
*
- * Charsets may have extensions that mutt_cs_canonical_charset() leaves intact;
+ * Charsets may have extensions that mutt_ch_canonical_charset() leaves intact;
* we expect 'cs2' to originate from neomutt code, not user input (i.e. 'cs2'
* does _not_ have any extension) we simply check if the shorter string is a
* prefix for the longer.
*/
-int mutt_cs_chscmp(const char *cs1, const char *cs2)
+int mutt_ch_chscmp(const char *cs1, const char *cs2)
{
if (!cs1 || !cs2)
return 0;
char buffer[STRING];
- mutt_cs_canonical_charset(buffer, sizeof(buffer), cs1);
+ mutt_ch_canonical_charset(buffer, sizeof(buffer), cs1);
int len1 = mutt_str_strlen(buffer);
int len2 = mutt_str_strlen(cs2);
}
/**
- * mutt_cs_get_default_charset - Get the default character set
+ * mutt_ch_get_default_charset - Get the default character set
* @retval ptr Name of the default character set
*
* @warning This returns a pointer to a static buffer. Do not free it.
*/
-char *mutt_cs_get_default_charset(void)
+char *mutt_ch_get_default_charset(void)
{
static char fcharset[SHORT_STRING];
const char *c = AssumedCharset;
}
/**
- * mutt_cs_set_langinfo_charset - Set the user's choice of character set
+ * mutt_ch_set_langinfo_charset - Set the user's choice of character set
*
* Lookup the character map used by the user's locale and store it in Charset.
*/
-void mutt_cs_set_langinfo_charset(void)
+void mutt_ch_set_langinfo_charset(void)
{
char buf[LONG_STRING];
char buf2[LONG_STRING];
mutt_str_strfcpy(buf, nl_langinfo(CODESET), sizeof(buf));
- mutt_cs_canonical_charset(buf2, sizeof(buf2), buf);
+ mutt_ch_canonical_charset(buf2, sizeof(buf2), buf);
/* finally, set $charset */
Charset = mutt_str_strdup(buf2);
}
/**
- * mutt_cs_lookup_add - Add a new character set lookup
+ * mutt_ch_lookup_add - Add a new character set lookup
* @param type Type of character set, e.g. MUTT_LOOKUP_CHARSET
* @param pat Pattern to match
* @param replace Replacement string
*
* Add a regex for a character set and a replacement name.
*/
-bool mutt_cs_lookup_add(enum LookupType type, const char *pat,
+bool mutt_ch_lookup_add(enum LookupType type, const char *pat,
const char *replace, struct Buffer *err)
{
if (!pat || !replace)
}
/**
- * mutt_cs_lookup_remove - Remove all the character set lookups
+ * mutt_ch_lookup_remove - Remove all the character set lookups
*
* Empty the list of replacement character set names.
*/
-void mutt_cs_lookup_remove(void)
+void mutt_ch_lookup_remove(void)
{
struct Lookup *l = NULL;
struct Lookup *tmp = NULL;
}
/**
- * mutt_cs_charset_lookup - Look for a replacement character set
+ * mutt_ch_charset_lookup - Look for a replacement character set
* @param chs Character set to lookup
* @retval ptr Replacement character set (if a 'charset-hook' matches)
* @retval NULL No matching hook
* Look through all the 'charset-hook's.
* If one matches return the replacement character set.
*/
-const char *mutt_cs_charset_lookup(const char *chs)
+const char *mutt_ch_charset_lookup(const char *chs)
{
return lookup_charset(MUTT_LOOKUP_CHARSET, chs);
}
/**
- * mutt_cs_iconv_open - Set up iconv for conversions
+ * mutt_ch_iconv_open - Set up iconv for conversions
* @param tocode Current character set
* @param fromcode Target character set
* @param flags Flags, e.g. #MUTT_ICONV_HOOK_FROM
* applied to tocode. Highlight note: The top-well-named MUTT_ICONV_HOOK_FROM
* acts on charset-hooks, not at all on iconv-hooks.
*/
-iconv_t mutt_cs_iconv_open(const char *tocode, const char *fromcode, int flags)
+iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, int flags)
{
char tocode1[SHORT_STRING];
char fromcode1[SHORT_STRING];
iconv_t cd;
/* transform to MIME preferred charset names */
- mutt_cs_canonical_charset(tocode1, sizeof(tocode1), tocode);
- mutt_cs_canonical_charset(fromcode1, sizeof(fromcode1), fromcode);
+ mutt_ch_canonical_charset(tocode1, sizeof(tocode1), tocode);
+ mutt_ch_canonical_charset(fromcode1, sizeof(fromcode1), fromcode);
/* maybe apply charset-hooks and recanonicalise fromcode,
* but only when caller asked us to sanitize a potentially wrong
* charset name incoming from the wild exterior. */
if (flags & MUTT_ICONV_HOOK_FROM)
{
- tmp = mutt_cs_charset_lookup(fromcode1);
+ tmp = mutt_ch_charset_lookup(fromcode1);
if (tmp)
- mutt_cs_canonical_charset(fromcode1, sizeof(fromcode1), tmp);
+ mutt_ch_canonical_charset(fromcode1, sizeof(fromcode1), tmp);
}
/* always apply iconv-hooks to suit system's iconv tastes */
- tocode2 = mutt_cs_iconv_lookup(tocode1);
+ tocode2 = mutt_ch_iconv_lookup(tocode1);
tocode2 = (tocode2) ? tocode2 : tocode1;
- fromcode2 = mutt_cs_iconv_lookup(fromcode1);
+ fromcode2 = mutt_ch_iconv_lookup(fromcode1);
fromcode2 = (fromcode2) ? fromcode2 : fromcode1;
/* call system iconv with names it appreciates */
}
/**
- * mutt_cs_iconv - Change the encoding of a string
+ * mutt_ch_iconv - Change the encoding of a string
* @param[in] cd Iconv conversion descriptor
* @param[in,out] inbuf Buffer to convert
* @param[in,out] inbytesleft Length of buffer to convert
* If you're supplying inrepls, the source charset should be stateless;
* if you're supplying an outrepl, the target charset should be.
*/
-size_t mutt_cs_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf,
+size_t mutt_ch_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf,
size_t *outbytesleft, const char **inrepls, const char *outrepl)
{
size_t rc = 0, ret1;
}
/**
- * mutt_cs_iconv_lookup - Look for a replacement character set
+ * mutt_ch_iconv_lookup - Look for a replacement character set
* @param chs Character set to lookup
* @retval ptr Replacement character set (if a 'iconv-hook' matches)
* @retval NULL No matching hook
* Look through all the 'iconv-hook's.
* If one matches return the replacement character set.
*/
-const char *mutt_cs_iconv_lookup(const char *chs)
+const char *mutt_ch_iconv_lookup(const char *chs)
{
return lookup_charset(MUTT_LOOKUP_ICONV, chs);
}
/**
- * mutt_cs_convert_string - Convert a string between encodings
+ * mutt_ch_convert_string - Convert a string between encodings
* @param[in,out] ps String to convert
* @param[in] from Current character set
* @param[in] to Target character set
* @retval 0 Success
* @retval -1 Error
*
- * Parameter flags is given as-is to mutt_cs_iconv_open().
+ * Parameter flags is given as-is to mutt_ch_iconv_open().
* See there for its meaning and usage policy.
*/
-int mutt_cs_convert_string(char **ps, const char *from, const char *to, int flags)
+int mutt_ch_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_cs_iconv_open(to, from, flags)) != (iconv_t) -1)
+ if (to && from && (cd = mutt_ch_iconv_open(to, from, flags)) != (iconv_t) -1)
{
size_t len;
const char *ib = NULL;
const char **inrepls = NULL;
char *outrepl = NULL;
- if (mutt_cs_is_utf8(to))
+ if (mutt_ch_is_utf8(to))
outrepl = "\357\277\275";
- else if (mutt_cs_is_utf8(from))
+ else if (mutt_ch_is_utf8(from))
inrepls = repls;
else
outrepl = "?";
obl = MB_LEN_MAX * ibl;
ob = buf = mutt_mem_malloc(obl + 1);
- mutt_cs_iconv(cd, &ib, &ibl, &ob, &obl, inrepls, outrepl);
+ mutt_ch_iconv(cd, &ib, &ibl, &ob, &obl, inrepls, outrepl);
iconv_close(cd);
*ob = '\0';
}
/**
- * mutt_cs_check_charset - Does iconv understand a character set?
+ * mutt_ch_check_charset - Does iconv understand a character set?
* @param cs Character set to check
* @param strict Check strictly by using iconv
* @retval bool true if character set is valid
* If `strict` is true, or the charset is not in #PreferredMIMENames, then
* iconv() with be run.
*/
-bool mutt_cs_check_charset(const char *cs, bool strict)
+bool mutt_ch_check_charset(const char *cs, bool strict)
{
iconv_t cd;
- if (mutt_cs_is_utf8(cs))
+ if (mutt_ch_is_utf8(cs))
return true;
if (!strict)
}
}
- cd = mutt_cs_iconv_open(cs, cs, 0);
+ cd = mutt_ch_iconv_open(cs, cs, 0);
if (cd != (iconv_t)(-1))
{
iconv_close(cd);
}
/**
- * mutt_cs_fgetconv_open - Prepare a file for charset conversion
+ * mutt_ch_fgetconv_open - Prepare a file for charset conversion
* @param file FILE ptr to prepare
* @param from Current character set
* @param to Destination character set
* @param flags Flags, e.g. MUTT_ICONV_HOOK_FROM
* @retval ptr fgetconv handle
*
- * Parameter flags is given as-is to mutt_cs_iconv_open().
+ * Parameter flags is given as-is to mutt_ch_iconv_open().
*/
-struct FgetConv *mutt_cs_fgetconv_open(FILE *file, const char *from, const char *to, int flags)
+struct FgetConv *mutt_ch_fgetconv_open(FILE *file, const char *from, const char *to, int flags)
{
struct FgetConv *fc = NULL;
iconv_t cd = (iconv_t) -1;
static const char *repls[] = { "\357\277\275", "?", 0 };
if (from && to)
- cd = mutt_cs_iconv_open(to, from, flags);
+ cd = mutt_ch_iconv_open(to, from, flags);
if (cd != (iconv_t) -1)
{
fc->p = fc->ob = fc->bufo;
fc->ib = fc->bufi;
fc->ibl = 0;
- fc->inrepls = mutt_cs_is_utf8(to) ? repls : repls + 1;
+ fc->inrepls = mutt_ch_is_utf8(to) ? repls : repls + 1;
}
else
fc = mutt_mem_malloc(sizeof(struct FgetConvNot));
}
/**
- * mutt_cs_fgetconv_close - Close an fgetconv handle
+ * mutt_ch_fgetconv_close - Close an fgetconv handle
* @param fc fgetconv handle
*/
-void mutt_cs_fgetconv_close(struct FgetConv **fc)
+void mutt_ch_fgetconv_close(struct FgetConv **fc)
{
if ((*fc)->cd != (iconv_t) -1)
iconv_close((*fc)->cd);
}
/**
- * mutt_cs_fgetconv - Convert a file's character set
+ * mutt_ch_fgetconv - Convert a file's character set
* @param fc FgetConv handle
* @retval num Next character in the converted file
* @retval EOF Error
* Each call to this function will return one converted character.
* The buffer is refilled automatically when empty.
*/
-int mutt_cs_fgetconv(struct FgetConv *fc)
+int mutt_ch_fgetconv(struct FgetConv *fc)
{
if (!fc)
return EOF;
if (fc->ibl)
{
size_t obl = sizeof(fc->bufo);
- mutt_cs_iconv(fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl, fc->inrepls, 0);
+ mutt_ch_iconv(fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl, fc->inrepls, 0);
if (fc->p < fc->ob)
return (unsigned char) *(fc->p)++;
}
}
/**
- * mutt_cs_fgetconvs - Convert a file's charset into a string buffer
+ * mutt_ch_fgetconvs - Convert a file's charset into a string buffer
* @param buf Buffer for result
* @param buflen Length of buffer
* @param fc FgetConv handle
*
* Read a file into a buffer, converting the character set as it goes.
*/
-char *mutt_cs_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
+char *mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
{
int c;
size_t r;
for (r = 0; (r + 1) < buflen;)
{
- c = mutt_cs_fgetconv(fc);
+ c = mutt_ch_fgetconv(fc);
if (c == EOF)
break;
buf[r++] = (char) c;
extern const struct MimeNames PreferredMIMENames[];
-void mutt_cs_canonical_charset(char *buf, size_t buflen, const char *name);
-int mutt_cs_chscmp(const char *cs1, const char *cs2);
-char * mutt_cs_get_default_charset(void);
-void mutt_cs_set_langinfo_charset(void);
-
-bool mutt_cs_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
-void mutt_cs_lookup_remove(void);
-const char * mutt_cs_charset_lookup(const char *chs);
-
-iconv_t mutt_cs_iconv_open(const char *tocode, const char *fromcode, int flags);
-size_t mutt_cs_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl);
-const char * mutt_cs_iconv_lookup(const char *chs);
-int mutt_cs_convert_string(char **ps, const char *from, const char *to, int flags);
-bool mutt_cs_check_charset(const char *cs, bool strict);
-
-struct FgetConv *mutt_cs_fgetconv_open(FILE *file, const char *from, const char *to, int flags);
-void mutt_cs_fgetconv_close(struct FgetConv **fc);
-int mutt_cs_fgetconv(struct FgetConv *fc);
-char * mutt_cs_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
-
-#define mutt_cs_is_utf8(a) mutt_cs_chscmp(a, "utf-8")
-#define mutt_cs_is_us_ascii(a) mutt_cs_chscmp(a, "us-ascii")
+void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
+int mutt_ch_chscmp(const char *cs1, const char *cs2);
+char * mutt_ch_get_default_charset(void);
+void mutt_ch_set_langinfo_charset(void);
+
+bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
+void mutt_ch_lookup_remove(void);
+const char * mutt_ch_charset_lookup(const char *chs);
+
+iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, int flags);
+size_t mutt_ch_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl);
+const char * mutt_ch_iconv_lookup(const char *chs);
+int mutt_ch_convert_string(char **ps, const char *from, const char *to, int flags);
+bool mutt_ch_check_charset(const char *cs, bool strict);
+
+struct FgetConv *mutt_ch_fgetconv_open(FILE *file, const char *from, const char *to, int flags);
+void mutt_ch_fgetconv_close(struct FgetConv **fc);
+int mutt_ch_fgetconv(struct FgetConv *fc);
+char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
+
+#define mutt_ch_is_utf8(a) mutt_ch_chscmp(a, "utf-8")
+#define mutt_ch_is_us_ascii(a) mutt_ch_chscmp(a, "us-ascii")
#endif
#endif /* HAVE_LIBIDN */
/* we don't want charset-hook effects, so we set flags to 0 */
- if (mutt_cs_convert_string(&local_user, "utf-8", Charset, 0) == -1)
+ if (mutt_ch_convert_string(&local_user, "utf-8", Charset, 0) == -1)
goto cleanup;
- if (mutt_cs_convert_string(&local_domain, "utf-8", Charset, 0) == -1)
+ if (mutt_ch_convert_string(&local_domain, "utf-8", Charset, 0) == -1)
goto cleanup;
/* make sure that we can convert back and come out with the same
{
reversed_user = mutt_str_strdup(local_user);
- if (mutt_cs_convert_string(&reversed_user, Charset, "utf-8", 0) == -1)
+ if (mutt_ch_convert_string(&reversed_user, Charset, "utf-8", 0) == -1)
{
mutt_debug(
1, "Not reversible. Charset conv to utf-8 failed for user = '%s'.\n", reversed_user);
reversed_domain = mutt_str_strdup(local_domain);
- if (mutt_cs_convert_string(&reversed_domain, Charset, "utf-8", 0) == -1)
+ if (mutt_ch_convert_string(&reversed_domain, Charset, "utf-8", 0) == -1)
{
mutt_debug(
1,
intl_domain = mutt_str_strdup(domain);
/* we don't want charset-hook effects, so we set flags to 0 */
- if (mutt_cs_convert_string(&intl_user, Charset, "utf-8", 0) == -1)
+ if (mutt_ch_convert_string(&intl_user, Charset, "utf-8", 0) == -1)
goto cleanup;
- if (mutt_cs_convert_string(&intl_domain, Charset, "utf-8", 0) == -1)
+ if (mutt_ch_convert_string(&intl_domain, Charset, "utf-8", 0) == -1)
goto cleanup;
#ifdef HAVE_LIBIDN
void mutt_encode_path(char *dest, size_t dlen, const char *src)
{
char *p = mutt_str_strdup(src);
- int rc = mutt_cs_convert_string(&p, Charset, "utf-8", 0);
+ int rc = mutt_ch_convert_string(&p, Charset, "utf-8", 0);
/* `src' may be NULL, such as when called from the pop3 driver. */
mutt_str_strfcpy(dest, (rc == 0) ? NONULL(p) : NONULL(src), dlen);
FREE(&p);
/* fromcode "utf-8" is sure, so we don't want
* charset-hook corrections: flags must be 0.
*/
- mutt_cs_convert_string(&tstr, "utf-8", Charset, 0);
+ mutt_ch_convert_string(&tstr, "utf-8", Charset, 0);
fputs(tstr, fp);
FREE(&tstr);
}
* be a wrong label, so we want the ability to do corrections via
* charset-hooks. Therefore we set flags to MUTT_ICONV_HOOK_FROM.
*/
- fc = mutt_cs_fgetconv_open(fp, charset, Charset, MUTT_ICONV_HOOK_FROM);
+ fc = mutt_ch_fgetconv_open(fp, charset, Charset, MUTT_ICONV_HOOK_FROM);
- for (complete = true, armor_header = true; mutt_cs_fgetconvs(buf, sizeof(buf), fc) != NULL;
+ for (complete = true, armor_header = true; mutt_ch_fgetconvs(buf, sizeof(buf), fc) != NULL;
complete = (strchr(buf, '\n') != NULL))
{
if (!complete)
state_puts(buf, s);
}
- mutt_cs_fgetconv_close(&fc);
+ mutt_ch_fgetconv_close(&fc);
mutt_file_fclose(&fp);
}
struct FgetConv *fc = NULL;
int c;
rewind(pgpout);
- fc = mutt_cs_fgetconv_open(pgpout, "utf-8", Charset, 0);
- while ((c = mutt_cs_fgetconv(fc)) != EOF)
+ fc = mutt_ch_fgetconv_open(pgpout, "utf-8", Charset, 0);
+ while ((c = mutt_ch_fgetconv(fc)) != EOF)
{
state_putc(c, s);
if (c == '\n' && s->prefix)
state_puts(s->prefix, s);
}
- mutt_cs_fgetconv_close(&fc);
+ mutt_ch_fgetconv_close(&fc);
}
if (s->flags & MUTT_DISPLAY)
}
*d = '\0';
- if (chs && (cd = mutt_cs_iconv_open(chs, "utf-8", 0)) != (iconv_t) -1)
+ if (chs && (cd = mutt_ch_iconv_open(chs, "utf-8", 0)) != (iconv_t) -1)
{
int n = s - uid + 1; /* chars available in original buffer */
char *buf = NULL;
* be a wrong label, so we want the ability to do corrections via
* charset-hooks. Therefore we set flags to MUTT_ICONV_HOOK_FROM.
*/
- fc = mutt_cs_fgetconv_open(fpin, charset, Charset, MUTT_ICONV_HOOK_FROM);
+ fc = mutt_ch_fgetconv_open(fpin, charset, Charset, MUTT_ICONV_HOOK_FROM);
- for (complete = true, armor_header = true; mutt_cs_fgetconvs(buf, sizeof(buf), fc) != NULL;
+ for (complete = true, armor_header = true; mutt_ch_fgetconvs(buf, sizeof(buf), fc) != NULL;
complete = (strchr(buf, '\n') != NULL))
{
if (!complete)
state_puts(buf, s);
}
- mutt_cs_fgetconv_close(&fc);
+ mutt_ch_fgetconv_close(&fc);
}
/**
l = mutt_str_strlen(gpgcharset);
if ((l > 0) && (gpgcharset[l - 1] == '\n'))
gpgcharset[l - 1] = 0;
- if (!mutt_cs_check_charset(gpgcharset, 0))
+ if (!mutt_ch_check_charset(gpgcharset, 0))
mutt_str_replace(&gpgcharset, "UTF-8");
}
}
rewind(pgpout);
state_set_prefix(s);
- fc = mutt_cs_fgetconv_open(pgpout, expected_charset, Charset, MUTT_ICONV_HOOK_FROM);
- while ((ch = mutt_cs_fgetconv(fc)) != EOF)
+ fc = mutt_ch_fgetconv_open(pgpout, expected_charset, Charset, MUTT_ICONV_HOOK_FROM);
+ while ((ch = mutt_ch_fgetconv(fc)) != EOF)
state_prefix_putc(ch, s);
- mutt_cs_fgetconv_close(&fc);
+ mutt_ch_fgetconv_close(&fc);
}
/*
else
from_charset = Charset;
- if (!mutt_cs_is_us_ascii(body_charset))
+ if (!mutt_ch_is_us_ascii(body_charset))
{
int c;
struct FgetConv *fc = NULL;
send_charset = "utf-8";
/* fromcode is assumed to be correct: we set flags to 0 */
- fc = mutt_cs_fgetconv_open(fp, from_charset, "utf-8", 0);
- while ((c = mutt_cs_fgetconv(fc)) != EOF)
+ fc = mutt_ch_fgetconv_open(fp, from_charset, "utf-8", 0);
+ while ((c = mutt_ch_fgetconv(fc)) != EOF)
fputc(c, pgpin);
- mutt_cs_fgetconv_close(&fc);
+ mutt_ch_fgetconv_close(&fc);
}
else
{
if (!pc)
mutt_param_set("charset",
(AssumedCharset && *AssumedCharset) ?
- (const char *) mutt_cs_get_default_charset() :
+ (const char *) mutt_ch_get_default_charset() :
"us-ascii",
&ct->parameter);
}
size_t obl, n;
int e;
- cd = mutt_cs_iconv_open(to, from, 0);
+ cd = mutt_ch_iconv_open(to, from, 0);
if (cd == (iconv_t)(-1))
return (size_t)(-1);
obl = 4 * flen + 1;
return 0;
}
}
- mutt_cs_convert_string(ps, (const char *) mutt_cs_get_default_charset(),
+ mutt_ch_convert_string(ps, (const char *) mutt_ch_get_default_charset(),
Charset, MUTT_ICONV_HOOK_FROM);
return -1;
}
if (dlen)
*dlen = elen;
- mutt_cs_canonical_charset(canonical_buf, sizeof(canonical_buf), tocode);
+ mutt_ch_canonical_charset(canonical_buf, sizeof(canonical_buf), tocode);
mutt_str_replace(&tocode, canonical_buf);
}
return tocode;
if (fromcode)
{
- cd = mutt_cs_iconv_open(tocode, fromcode, 0);
+ cd = mutt_ch_iconv_open(tocode, fromcode, 0);
assert(cd != (iconv_t)(-1));
ib = d;
ibl = dlen;
if (fromcode)
{
- cd = mutt_cs_iconv_open(tocode, fromcode, 0);
+ cd = mutt_ch_iconv_open(tocode, fromcode, 0);
assert(cd != (iconv_t)(-1));
ib = d;
ibl = dlen;
}
/* Hack to avoid labelling 8-bit data as us-ascii. */
- if (!icode && mutt_cs_is_us_ascii(tocode))
+ if (!icode && mutt_ch_is_us_ascii(tocode))
tocode = "unknown-8bit";
/* Adjust t0 for maximum length of line. */
}
if (charset)
- mutt_cs_convert_string(&d0, charset, Charset, MUTT_ICONV_HOOK_FROM);
+ mutt_ch_convert_string(&d0, charset, Charset, MUTT_ICONV_HOOK_FROM);
mutt_filter_unprintable(&d0);
mutt_str_strfcpy(d, d0, len);
rc = 0;
} while (par && (strcmp(par->attribute, attribute) == 0));
if (encoded)
- mutt_cs_convert_string(&value, charset, Charset, MUTT_ICONV_HOOK_FROM);
+ mutt_ch_convert_string(&value, charset, Charset, MUTT_ICONV_HOOK_FROM);
*head = mutt_param_new();
(*head)->attribute = mutt_str_strdup(attribute);
(*head)->value = value;
s = rfc2231_get_charset(p->value, charset, sizeof(charset));
rfc2231_decode_one(p->value, s);
- mutt_cs_convert_string(&p->value, charset, Charset, MUTT_ICONV_HOOK_FROM);
+ mutt_ch_convert_string(&p->value, charset, Charset, MUTT_ICONV_HOOK_FROM);
mutt_filter_unprintable(&p->value);
*last = p;
dlen = strlen(d);
}
- if (!mutt_cs_is_us_ascii(charset))
+ if (!mutt_ch_is_us_ascii(charset))
encode = 1;
for (s = d, slen = dlen; slen; s++, slen--)
int c, linelen = 0;
char line[77], savechar;
- while ((c = mutt_cs_fgetconv(fc)) != EOF)
+ while ((c = mutt_ch_fgetconv(fc)) != EOF)
{
/* Wrap the line if needed. */
if (linelen == 76 && ((istext && c != '\n') || !istext))
b64_init(&ctx);
- while ((ch = mutt_cs_fgetconv(fc)) != EOF)
+ while ((ch = mutt_ch_fgetconv(fc)) != EOF)
{
if (SigInt == 1)
{
{
int ch;
- while ((ch = mutt_cs_fgetconv(fc)) != EOF)
+ while ((ch = mutt_ch_fgetconv(fc)) != EOF)
{
if (SigInt == 1)
{
}
if (a->type == TYPETEXT && (!a->noconv))
- fc = mutt_cs_fgetconv_open(
+ fc = mutt_ch_fgetconv_open(
fpin, a->charset, mutt_get_body_charset(send_charset, sizeof(send_charset), a), 0);
else
- fc = mutt_cs_fgetconv_open(fpin, 0, 0, 0);
+ fc = mutt_ch_fgetconv_open(fpin, 0, 0, 0);
mutt_sig_allow_interrupt(1);
if (a->encoding == ENCQUOTEDPRINTABLE)
mutt_file_copy_stream(fpin, f);
mutt_sig_allow_interrupt(0);
- mutt_cs_fgetconv_close(&fc);
+ mutt_ch_fgetconv_close(&fc);
mutt_file_fclose(&fpin);
if (SigInt == 1)
struct ContentState *states = NULL;
size_t *score = NULL;
- cd1 = mutt_cs_iconv_open("utf-8", fromcode, 0);
+ cd1 = mutt_ch_iconv_open("utf-8", fromcode, 0);
if (cd1 == (iconv_t)(-1))
return -1;
for (int i = 0; i < ncodes; i++)
{
if (mutt_str_strcasecmp(tocodes[i], "utf-8") != 0)
- cd[i] = mutt_cs_iconv_open(tocodes[i], "utf-8", 0);
+ cd[i] = mutt_ch_iconv_open(tocodes[i], "utf-8", 0);
else
{
/* Special case for conversion to UTF-8 */
{
if (!chs)
{
- mutt_cs_canonical_charset(chsbuf, sizeof(chsbuf), tocode);
+ mutt_ch_canonical_charset(chsbuf, sizeof(chsbuf), tocode);
mutt_param_set("charset", chsbuf, &b->parameter);
}
FREE(&b->charset);
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
mutt_param_set("charset",
(!info->hibin ? "us-ascii" :
- Charset && !mutt_cs_is_us_ascii(Charset) ? Charset : "unknown-8bit"),
+ Charset && !mutt_ch_is_us_ascii(Charset) ? Charset : "unknown-8bit"),
&b->parameter);
return info;
p = mutt_param_get("charset", b->parameter);
if (p)
- mutt_cs_canonical_charset(d, dlen, NONULL(p));
+ mutt_ch_canonical_charset(d, dlen, NONULL(p));
else
mutt_str_strfcpy(d, "us-ascii", dlen);
char chsbuf[STRING];
/* override noconv when it's us-ascii */
- if (mutt_cs_is_us_ascii(mutt_get_body_charset(chsbuf, sizeof(chsbuf), a)))
+ if (mutt_ch_is_us_ascii(mutt_get_body_charset(chsbuf, sizeof(chsbuf), a)))
a->noconv = false;
if (!a->force_charset && !a->noconv)