static int mutt_idna_to_local (const char *in, char **out, int flags) { *out = NULL; if (!option (OPTUSEIDN)) goto notrans; if (!in) goto notrans; /* Is this the right function? Interesting effects with some bad identifiers! */ if (idna_to_unicode_8z8z (in, out, IDNA_ALLOW_UNASSIGNED) != IDNA_SUCCESS) goto notrans; /* we don't want charset-hook effects, so we set flags to 0 */ if (mutt_convert_string (out, "utf-8", Charset, 0) == -1) goto notrans; /* * make sure that we can convert back and come out with the same * domain name. */ if ((flags & MI_MAY_BE_IRREVERSIBLE) == 0) { int irrev = 0; char *t2 = NULL; char *tmp = safe_strdup (*out); /* we don't want charset-hook effects, so we set flags to 0 */ if (mutt_convert_string (&tmp, Charset, "utf-8", 0) == -1) irrev = 1; if (!irrev && idna_to_ascii_8z (tmp, &t2, IDNA_ALLOW_UNASSIGNED) != IDNA_SUCCESS) irrev = 1; if (!irrev && ascii_strcasecmp (t2, in)) { dprint (1, (debugfile, "mutt_idna_to_local: Not reversible. in = '%s', t2 = '%s'.\n", in, t2)); irrev = 1; } FREE (&t2); FREE (&tmp); if (irrev) goto notrans; } return 0; notrans: FREE (out); /* __FREE_CHECKED__ */ *out = safe_strdup (in); return 1; }
static int mutt_local_to_idna (const char *in, char **out) { int rv = 0; char *tmp = safe_strdup (in); *out = NULL; if (!in) { *out = NULL; return -1; } /* we don't want charset-hook effects, so we set flags to 0 */ if (mutt_convert_string (&tmp, Charset, "utf-8", 0) == -1) rv = -1; if (!rv && idna_to_ascii_8z (tmp, out, IDNA_ALLOW_UNASSIGNED) != IDNA_SUCCESS) rv = -2; FREE (&tmp); if (rv < 0) { FREE (out); /* __FREE_CHECKED__ */ *out = safe_strdup (in); } return rv; }
static unsigned char * dump_char_size(char *c, unsigned char *d, int *off, ssize_t size, int convert) { char *p = c; if (c == NULL) { size = 0; d = dump_int(size, d, off); return d; } if (convert && !is_ascii (c, size)) { p = mutt_substrdup (c, c + size); if (mutt_convert_string (&p, Charset, "utf-8", 0) == 0) { c = p; size = mutt_strlen (c) + 1; } } d = dump_int(size, d, off); lazy_realloc(&d, *off + size); memcpy(d + *off, p, size); *off += size; if (p != c) FREE(&p); return d; }
static void rfc2231_join_continuations (PARAMETER **head, struct rfc2231_parameter *par) { struct rfc2231_parameter *q; char attribute[STRING]; char charset[STRING]; char *value = NULL; char *valp; int encoded; size_t l, vl; while (par) { value = NULL; l = 0; strfcpy (attribute, par->attribute, sizeof (attribute)); if ((encoded = par->encoded)) valp = rfc2231_get_charset (par->value, charset, sizeof (charset)); else valp = par->value; do { if (encoded && par->encoded) rfc2231_decode_one (par->value, valp); vl = strlen (par->value); safe_realloc (&value, l + vl + 1); strcpy (value + l, par->value); /* __STRCPY_CHECKED__ */ l += vl; q = par->next; rfc2231_free_parameter (&par); if ((par = q)) valp = par->value; } while (par && !strcmp (par->attribute, attribute)); if (value) { if (encoded) mutt_convert_string (&value, charset, Charset, MUTT_ICONV_HOOK_FROM); *head = mutt_new_parameter (); (*head)->attribute = safe_strdup (attribute); (*head)->value = value; head = &(*head)->next; } } }
static void recode_buf (char *buf, size_t buflen) { char *s; if (!ConfigCharset || !*ConfigCharset || !Charset) return; s = safe_strdup (buf); if (!s) return; if (mutt_convert_string (&s, Charset, ConfigCharset, 0) == 0) strfcpy (buf, s, buflen); FREE(&s); }
EXPORTNOT char *remote_recode_to(char *buf) { if (!buf || !(*buf)) return buf; if (remote_conv_out == EKG_ICONV_BAD) return buf; else { char *newbuf = mutt_convert_string(buf, remote_conv_out, remote_conv_outf); if (!newbuf) return buf; xfree(buf); return newbuf; } }
static void restore_char(char **c, const unsigned char *d, int *off, int convert) { unsigned int size; restore_int(&size, d, off); if (size == 0) { *c = NULL; return; } *c = safe_malloc(size); memcpy(*c, d + *off, size); if (convert && !is_ascii (*c, size)) { char *tmp = safe_strdup (*c); if (mutt_convert_string (&tmp, "utf-8", Charset, 0) == 0) { mutt_str_replace (c, tmp); } else { FREE(&tmp); } } *off += size; }
void rfc2231_decode_parameters (PARAMETER **headp) { PARAMETER *head = NULL; PARAMETER **last; PARAMETER *p, *q; struct rfc2231_parameter *conthead = NULL; struct rfc2231_parameter *conttmp; char *s, *t; char charset[STRING]; int encoded; int index; short dirty = 0; /* set to 1 when we may have created * empty parameters. */ if (!headp) return; purge_empty_parameters (headp); for (last = &head, p = *headp; p; p = q) { q = p->next; if (!(s = strchr (p->attribute, '*'))) { /* * Using RFC 2047 encoding in MIME parameters is explicitly * forbidden by that document. Nevertheless, it's being * generated by some software, including certain Lotus Notes to * Internet Gateways. So we actually decode it. */ if (option (OPTRFC2047PARAMS) && p->value && strstr (p->value, "=?")) rfc2047_decode (&p->value); else if (AssumedCharset && *AssumedCharset) convert_nonmime_string (&p->value); *last = p; last = &p->next; p->next = NULL; } else if (*(s + 1) == '\0') { *s = '\0'; s = rfc2231_get_charset (p->value, charset, sizeof (charset)); rfc2231_decode_one (p->value, s); mutt_convert_string (&p->value, charset, Charset, M_ICONV_HOOK_FROM); mutt_filter_unprintable (&p->value); *last = p; last = &p->next; p->next = NULL; dirty = 1; } else { *s = '\0'; s++; /* let s point to the first character of index. */ for (t = s; *t && isdigit ((unsigned char) *t); t++) ; encoded = (*t == '*'); *t = '\0'; index = atoi (s); conttmp = rfc2231_new_parameter (); conttmp->attribute = p->attribute; conttmp->value = p->value; conttmp->encoded = encoded; conttmp->index = index; p->attribute = NULL; p->value = NULL; FREE (&p); rfc2231_list_insert (&conthead, conttmp); } } if (conthead) { rfc2231_join_continuations (last, conthead); dirty = 1; } *headp = head; if (dirty) purge_empty_parameters (headp); }