Beispiel #1
0
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;
    }
  }
}
Beispiel #2
0
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);
}