242
/* this first ties off any charset extension such as //TRANSLIT,
243
canonicalizes the charset and re-adds the extension */
242
244
void mutt_canonical_charset (char *dest, size_t dlen, const char *name)
246
char scratch[LONG_STRING];
248
if (!ascii_strcasecmp (name, "utf-8") || !ascii_strcasecmp (name, "utf8"))
248
char in[LONG_STRING], scratch[LONG_STRING];
250
strfcpy (in, name, sizeof (in));
251
if ((ext = strchr (in, '/')))
254
if (!ascii_strcasecmp (in, "utf-8") || !ascii_strcasecmp (in, "utf8"))
250
256
strfcpy (dest, "utf-8", dlen);
254
260
/* catch some common iso-8859-something misspellings */
255
if (!ascii_strncasecmp (name, "8859", 4) && name[4] != '-')
256
snprintf (scratch, sizeof (scratch), "iso-8859-%s", name +4);
257
else if (!ascii_strncasecmp (name, "8859-", 5))
258
snprintf (scratch, sizeof (scratch), "iso-8859-%s", name + 5);
259
else if (!ascii_strncasecmp (name, "iso8859", 7) && name[7] != '-')
260
snprintf (scratch, sizeof (scratch), "iso_8859-%s", name + 7);
261
else if (!ascii_strncasecmp (name, "iso8859-", 8))
262
snprintf (scratch, sizeof (scratch), "iso_8859-%s", name + 8);
261
if (!ascii_strncasecmp (in, "8859", 4) && in[4] != '-')
262
snprintf (scratch, sizeof (scratch), "iso-8859-%s", in +4);
263
else if (!ascii_strncasecmp (in, "8859-", 5))
264
snprintf (scratch, sizeof (scratch), "iso-8859-%s", in + 5);
265
else if (!ascii_strncasecmp (in, "iso8859", 7) && in[7] != '-')
266
snprintf (scratch, sizeof (scratch), "iso_8859-%s", in + 7);
267
else if (!ascii_strncasecmp (in, "iso8859-", 8))
268
snprintf (scratch, sizeof (scratch), "iso_8859-%s", in + 8);
264
strfcpy (scratch, NONULL(name), sizeof (scratch));
270
strfcpy (scratch, in, sizeof (scratch));
266
272
for (i = 0; PreferredMIMENames[i].key; i++)
267
273
if (!ascii_strcasecmp (scratch, PreferredMIMENames[i].key) ||
268
274
!mutt_strcasecmp (scratch, PreferredMIMENames[i].key))
270
276
strfcpy (dest, PreferredMIMENames[i].pref, dlen);
274
280
strfcpy (dest, scratch, dlen);
276
282
/* for cosmetics' sake, transform to lowercase. */
277
283
for (p = dest; *p; p++)
278
284
*p = ascii_tolower (*p);
289
safe_strcat (dest, dlen, "/");
290
safe_strcat (dest, dlen, ext);
281
294
int mutt_chscmp (const char *s, const char *chs)
283
296
char buffer[STRING];
285
299
if (!s) return 0;
301
/* charsets may have extensions mutt_canonical_charset()
302
leaves intact; we expect `chs' to originate from mutt
303
code, not user input (i.e. `chs' does _not_ have any
305
we simply check if the shorter string is a prefix for
287
307
mutt_canonical_charset (buffer, sizeof (buffer), s);
288
return !ascii_strcasecmp (buffer, chs);
308
a = mutt_strlen (buffer);
309
b = mutt_strlen (chs);
310
return !ascii_strncasecmp (a > b ? buffer : chs,
311
a > b ? chs : buffer, MIN(a,b));
291
314
char *mutt_get_default_charset ()