fputs("MIME-Version: 1.0\n", out);
fputs("Content-Transfer-Encoding: 8bit\n", out);
fputs("Content-Type: text/plain; charset=", out);
- mutt_canonical_charset(chsbuf, sizeof(chsbuf),
- Charset ? Charset : "us-ascii");
+ mutt_cs_canonical_charset(chsbuf, sizeof(chsbuf),
+ Charset ? Charset : "us-ascii");
mutt_addr_cat(buffer, sizeof(buffer), chsbuf, MimeSpecials);
fputs(buffer, out);
fputc('\n', out);
while (true)
{
ob = bufo, obl = sizeof(bufo);
- mutt_iconv(cd, &ib, &ibl, &ob, &obl, 0, "?");
+ mutt_cs_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_get_default_charset();
+ charset = mutt_cs_get_default_charset();
if (charset && Charset)
cd = mutt_iconv_open(Charset, charset, MUTT_ICONV_HOOK_FROM);
}
if (p)
From = mutt_addr_parse_list(NULL, p);
- mutt_set_langinfo_charset();
+ mutt_cs_set_langinfo_charset();
mutt_set_charset(Charset);
Matches = mutt_mem_calloc(Matches_listsize, sizeof(char *));
{
char buffer[STRING];
- mutt_canonical_charset(buffer, sizeof(buffer), charset);
+ mutt_cs_canonical_charset(buffer, sizeof(buffer), charset);
- if (mutt_is_utf8(buffer))
+ if (mutt_cs_is_utf8(buffer))
{
Charset_is_utf8 = true;
ReplacementChar = 0xfffd;
};
// clang-format on
-void fgetconv_close(FGETCONV **_fc)
+void mutt_cs_fgetconv_close(FGETCONV **_fc)
{
struct FgetConv *fc = (struct FgetConv *) *_fc;
FREE(_fc);
}
-int fgetconv(FGETCONV *_fc)
+int mutt_cs_fgetconv(FGETCONV *_fc)
{
struct FgetConv *fc = (struct FgetConv *) _fc;
if (fc->ibl)
{
size_t obl = sizeof(fc->bufo);
- mutt_iconv(fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl, fc->inrepls, 0);
+ mutt_cs_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)++;
}
return EOF;
}
-char *fgetconvs(char *buf, size_t l, FGETCONV *_fc)
+char *mutt_cs_fgetconvs(char *buf, size_t l, FGETCONV *_fc)
{
int c;
size_t r;
for (r = 0; r + 1 < l;)
{
- c = fgetconv(_fc);
+ c = mutt_cs_fgetconv(_fc);
if (c == EOF)
break;
buf[r++] = (char) c;
}
/**
- * mutt_canonical_charset - Canonicalise the charset of a string
+ * mutt_cs_canonical_charset - Canonicalise the charset of a string
*
* this first ties off any charset extension such as //TRANSLIT,
* canonicalizes the charset and re-adds the extension
*/
-void mutt_canonical_charset(char *dest, size_t dlen, const char *name)
+void mutt_cs_canonical_charset(char *dest, size_t dlen, const char *name)
{
char *p = NULL, *ext = NULL;
char in[LONG_STRING], scratch[LONG_STRING];
}
}
-int mutt_chscmp(const char *s, const char *chs)
+int mutt_cs_chscmp(const char *s, const char *chs)
{
char buffer[STRING];
int a, b;
if (!s)
return 0;
- /* charsets may have extensions mutt_canonical_charset()
+ /* charsets may have extensions mutt_cs_canonical_charset()
leaves intact; we expect `chs' to originate from neomutt
code, not user input (i.e. `chs' does _not_ have any
extension)
we simply check if the shorter string is a prefix for
the longer */
- mutt_canonical_charset(buffer, sizeof(buffer), s);
+ mutt_cs_canonical_charset(buffer, sizeof(buffer), s);
a = mutt_str_strlen(buffer);
b = mutt_str_strlen(chs);
return (mutt_str_strncasecmp(a > b ? buffer : chs, a > b ? chs : buffer, MIN(a, b)) == 0);
}
-char *mutt_get_default_charset(void)
+char *mutt_cs_get_default_charset(void)
{
static char fcharset[SHORT_STRING];
const char *c = AssumedCharset;
}
/**
- * mutt_iconv - Change the encoding of a string
+ * mutt_cs_iconv - Change the encoding of a string
*
* Like iconv, but keeps going even when the input is invalid
* 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_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf,
- size_t *outbytesleft, const char **inrepls, const char *outrepl)
+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)
{
size_t rc = 0, ret1;
const char *ib = *inbuf;
}
}
-void mutt_set_langinfo_charset(void)
+void mutt_cs_set_langinfo_charset(void)
{
char buf[LONG_STRING];
char buf2[LONG_STRING];
mutt_str_strfcpy(buf, nl_langinfo(CODESET), sizeof(buf));
- mutt_canonical_charset(buf2, sizeof(buf2), buf);
+ mutt_cs_canonical_charset(buf2, sizeof(buf2), buf);
/* finally, set $charset */
Charset = mutt_str_strdup(buf2);
iconv_t cd;
};
+/**
+ * struct MimeNames - MIME name lookup entry
+ */
struct MimeNames
{
const char *key;
extern const struct MimeNames PreferredMIMENames[];
-char * fgetconvs(char *buf, size_t l, FGETCONV *_fc);
-char * mutt_get_default_charset(void);
-int fgetconv(FGETCONV *_fc);
-int mutt_chscmp(const char *s, const char *chs);
-size_t mutt_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl);
-void fgetconv_close(FGETCONV **_fc);
-void mutt_canonical_charset(char *dest, size_t dlen, const char *name);
-void mutt_set_langinfo_charset(void);
+void mutt_cs_canonical_charset(char *dest, size_t dlen, const char *name);
+int mutt_cs_chscmp(const char *s, const char *chs);
+void mutt_cs_fgetconv_close(FGETCONV **fc);
+int mutt_cs_fgetconv(FGETCONV *fc);
+char * mutt_cs_fgetconvs(char *buf, size_t l, FGETCONV *fc);
+char * mutt_cs_get_default_charset(void);
+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);
+void mutt_cs_set_langinfo_charset(void);
-#define mutt_is_utf8(a) mutt_chscmp(a, "utf-8")
-#define mutt_is_us_ascii(a) mutt_chscmp(a, "us-ascii")
+#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")
#endif
iconv_t cd;
/* transform to MIME preferred charset names */
- mutt_canonical_charset(tocode1, sizeof(tocode1), tocode);
- mutt_canonical_charset(fromcode1, sizeof(fromcode1), fromcode);
+ mutt_cs_canonical_charset(tocode1, sizeof(tocode1), tocode);
+ mutt_cs_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_charset_hook(fromcode1)))
- mutt_canonical_charset(fromcode1, sizeof(fromcode1), tmp);
+ mutt_cs_canonical_charset(fromcode1, sizeof(fromcode1), tmp);
/* always apply iconv-hooks to suit system's iconv tastes */
tocode2 = mutt_iconv_hook(tocode1);
const char **inrepls = NULL;
char *outrepl = NULL;
- if (mutt_is_utf8(to))
+ if (mutt_cs_is_utf8(to))
outrepl = "\357\277\275";
- else if (mutt_is_utf8(from))
+ else if (mutt_cs_is_utf8(from))
inrepls = repls;
else
outrepl = "?";
obl = MB_LEN_MAX * ibl;
ob = buf = mutt_mem_malloc(obl + 1);
- mutt_iconv(cd, &ib, &ibl, &ob, &obl, inrepls, outrepl);
+ mutt_cs_iconv(cd, &ib, &ibl, &ob, &obl, inrepls, outrepl);
iconv_close(cd);
*ob = '\0';
fc->p = fc->ob = fc->bufo;
fc->ib = fc->bufi;
fc->ibl = 0;
- fc->inrepls = mutt_is_utf8(to) ? repls : repls + 1;
+ fc->inrepls = mutt_cs_is_utf8(to) ? repls : repls + 1;
}
else
fc = mutt_mem_malloc(sizeof(struct FgetConvNot));
{
iconv_t cd;
- if (mutt_is_utf8(s))
+ if (mutt_cs_is_utf8(s))
return true;
if (!strict)
*/
fc = fgetconv_open(fp, charset, Charset, MUTT_ICONV_HOOK_FROM);
- for (complete = true, armor_header = true; fgetconvs(buf, sizeof(buf), fc) != NULL;
+ for (complete = true, armor_header = true; mutt_cs_fgetconvs(buf, sizeof(buf), fc) != NULL;
complete = (strchr(buf, '\n') != NULL))
{
if (!complete)
state_puts(buf, s);
}
- fgetconv_close(&fc);
+ mutt_cs_fgetconv_close(&fc);
mutt_file_fclose(&fp);
}
int c;
rewind(pgpout);
fc = fgetconv_open(pgpout, "utf-8", Charset, 0);
- while ((c = fgetconv(fc)) != EOF)
+ while ((c = mutt_cs_fgetconv(fc)) != EOF)
{
state_putc(c, s);
if (c == '\n' && s->prefix)
state_puts(s->prefix, s);
}
- fgetconv_close(&fc);
+ mutt_cs_fgetconv_close(&fc);
}
if (s->flags & MUTT_DISPLAY)
*/
fc = fgetconv_open(fpin, charset, Charset, MUTT_ICONV_HOOK_FROM);
- for (complete = true, armor_header = true; fgetconvs(buf, sizeof(buf), fc) != NULL;
+ for (complete = true, armor_header = true; mutt_cs_fgetconvs(buf, sizeof(buf), fc) != NULL;
complete = (strchr(buf, '\n') != NULL))
{
if (!complete)
state_puts(buf, s);
}
- fgetconv_close(&fc);
+ mutt_cs_fgetconv_close(&fc);
}
/**
rewind(pgpout);
state_set_prefix(s);
fc = fgetconv_open(pgpout, expected_charset, Charset, MUTT_ICONV_HOOK_FROM);
- while ((ch = fgetconv(fc)) != EOF)
+ while ((ch = mutt_cs_fgetconv(fc)) != EOF)
state_prefix_putc(ch, s);
- fgetconv_close(&fc);
+ mutt_cs_fgetconv_close(&fc);
}
/*
else
from_charset = Charset;
- if (!mutt_is_us_ascii(body_charset))
+ if (!mutt_cs_is_us_ascii(body_charset))
{
int c;
FGETCONV *fc = NULL;
/* fromcode is assumed to be correct: we set flags to 0 */
fc = fgetconv_open(fp, from_charset, "utf-8", 0);
- while ((c = fgetconv(fc)) != EOF)
+ while ((c = mutt_cs_fgetconv(fc)) != EOF)
fputc(c, pgpin);
- fgetconv_close(&fc);
+ mutt_cs_fgetconv_close(&fc);
}
else
{
pc = mutt_param_get("charset", ct->parameter);
if (!pc)
mutt_param_set("charset",
- (AssumedCharset && *AssumedCharset) ?
- (const char *) mutt_get_default_charset() :
- "us-ascii",
- &ct->parameter);
+ (AssumedCharset && *AssumedCharset) ?
+ (const char *) mutt_cs_get_default_charset() :
+ "us-ascii",
+ &ct->parameter);
}
}
return 0;
}
}
- mutt_convert_string(ps, (const char *) mutt_get_default_charset(), Charset,
+ mutt_convert_string(ps, (const char *) mutt_cs_get_default_charset(), Charset,
MUTT_ICONV_HOOK_FROM);
return -1;
}
if (dlen)
*dlen = elen;
- mutt_canonical_charset(canonical_buf, sizeof(canonical_buf), tocode);
+ mutt_cs_canonical_charset(canonical_buf, sizeof(canonical_buf), tocode);
mutt_str_replace(&tocode, canonical_buf);
}
return tocode;
}
/* Hack to avoid labelling 8-bit data as us-ascii. */
- if (!icode && mutt_is_us_ascii(tocode))
+ if (!icode && mutt_cs_is_us_ascii(tocode))
tocode = "unknown-8bit";
/* Adjust t0 for maximum length of line. */
dlen = strlen(d);
}
- if (!mutt_is_us_ascii(charset))
+ if (!mutt_cs_is_us_ascii(charset))
encode = 1;
for (s = d, slen = dlen; slen; s++, slen--)
int c, linelen = 0;
char line[77], savechar;
- while ((c = fgetconv(fc)) != EOF)
+ while ((c = mutt_cs_fgetconv(fc)) != EOF)
{
/* Wrap the line if needed. */
if (linelen == 76 && ((istext && c != '\n') || !istext))
b64_init(&ctx);
- while ((ch = fgetconv(fc)) != EOF)
+ while ((ch = mutt_cs_fgetconv(fc)) != EOF)
{
if (SigInt == 1)
{
{
int ch;
- while ((ch = fgetconv(fc)) != EOF)
+ while ((ch = mutt_cs_fgetconv(fc)) != EOF)
{
if (SigInt == 1)
{
mutt_file_copy_stream(fpin, f);
mutt_sig_allow_interrupt(0);
- fgetconv_close(&fc);
+ mutt_cs_fgetconv_close(&fc);
mutt_file_fclose(&fpin);
if (SigInt == 1)
{
if (!chs)
{
- mutt_canonical_charset(chsbuf, sizeof(chsbuf), tocode);
+ mutt_cs_canonical_charset(chsbuf, sizeof(chsbuf), tocode);
mutt_param_set("charset", chsbuf, &b->parameter);
}
FREE(&b->charset);
mutt_file_fclose(&fp);
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
- mutt_param_set("charset",
- (!info->hibin ? "us-ascii" :
- Charset && !mutt_is_us_ascii(Charset) ? Charset : "unknown-8bit"),
- &b->parameter);
+ mutt_param_set(
+ "charset",
+ (!info->hibin ? "us-ascii" : Charset && !mutt_cs_is_us_ascii(Charset) ? Charset : "unknown-8bit"),
+ &b->parameter);
return info;
}
p = mutt_param_get("charset", b->parameter);
if (p)
- mutt_canonical_charset(d, dlen, NONULL(p));
+ mutt_cs_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_is_us_ascii(mutt_get_body_charset(chsbuf, sizeof(chsbuf), a)))
+ if (mutt_cs_is_us_ascii(mutt_get_body_charset(chsbuf, sizeof(chsbuf), a)))
a->noconv = false;
if (!a->force_charset && !a->noconv)