if (headers[x])
{
if (flags & CH_DECODE)
- rfc2047_decode (headers[x], headers[x], mutt_strlen (headers[x]) + 1);
+ rfc2047_decode (&headers[x]);
/* We couldn't do the prefixing when reading because RFC 2047
* decoding may have concatenated lines.
else if (!mutt_strcasecmp ("description", line + 8))
{
mutt_str_replace (&p->description, c);
- rfc2047_decode (p->description, p->description, mutt_strlen (p->description) + 1);
+ rfc2047_decode (&p->description);
}
}
#ifdef SUN_ATTACHMENT
{
safe_free ((void **) &p->description);
p->description = safe_strdup (c);
- rfc2047_decode (p->description, p->description, mutt_strlen (p->description) + 1);
+ rfc2047_decode (&p->description);
}
}
#endif
LIST *last = NULL;
char *line = safe_malloc (LONG_STRING);
char *p;
- char in_reply_to[STRING];
+ char *in_reply_to = 0;
long loc;
int matched;
size_t linelen = LONG_STRING;
- in_reply_to[0] = 0;
-
if (hdr)
{
if (hdr->content == NULL)
if (hdr)
{
mutt_str_replace (&hdr->content->description, p);
- rfc2047_decode (hdr->content->description,
- hdr->content->description,
- mutt_strlen (hdr->content->description) + 1);
+ rfc2047_decode (&hdr->content->description);
}
matched = 1;
}
{
if (hdr)
{
- strfcpy (in_reply_to, p, sizeof (in_reply_to));
- rfc2047_decode (in_reply_to, in_reply_to,
- sizeof (in_reply_to));
+ in_reply_to = strdup (p);
+ rfc2047_decode (&in_reply_to);
}
}
break;
}
else
last = e->userhdrs = mutt_new_list ();
- rfc2047_decode (line, line, linelen);
+ rfc2047_decode (&line);
last->data = safe_strdup (line);
}
}
/* if an in-reply-to was given, check to see if it is in the references
* list already. if not, add it so we can do a better job of threading.
*/
- if (in_reply_to[0] && (p = extract_message_id (in_reply_to)) != NULL)
+ if (in_reply_to && (p = extract_message_id (in_reply_to)) != NULL)
{
if (!e->references ||
(e->references && mutt_strcmp (e->references->data, p) != 0))
{
regmatch_t pmatch[1];
- rfc2047_decode (e->subject, e->subject, mutt_strlen (e->subject) + 1);
+ rfc2047_decode (&e->subject);
if (regexec (ReplyRegexp.rx, e->subject, 1, pmatch, 0) == 0)
e->real_subj = e->subject + pmatch[0].rm_eo;
}
}
+ safe_free ((void *) &in_reply_to);
return (e);
}
/* try to decode anything that looks like a valid RFC2047 encoded
* header field, ignoring RFC822 parsing rules
*/
-void rfc2047_decode (char *d, const char *s, size_t dlen)
+void rfc2047_decode (char **pd)
{
const char *p, *q;
size_t n;
int found_encoded = 0;
- int in_place = (d == s);
-
- dlen--; /* save room for the terminal nul */
+ char *d0, *d;
+ const char *s = *pd;
+ size_t dlen;
+
+ if (!*s)
+ return;
+
+ dlen = MB_LEN_MAX * strlen (s); /* should be enough */
+ d = d0 = safe_malloc (dlen + 1);
while (*s && dlen > 0)
{
(q = strstr (q + 1, "?=")) == NULL)
{
/* no encoded words */
- if (d != s)
- strfcpy (d, s, dlen + 1);
- return;
+ strncpy (d, s, dlen);
+ d += dlen;
+ break;
}
if (p != s)
}
}
- rfc2047_decode_word (d, p, in_place ? q + 2 - p : dlen);
+ rfc2047_decode_word (d, p, dlen);
found_encoded = 1;
s = q + 2;
n = mutt_strlen (d);
d += n;
}
*d = 0;
+ *pd = strdup (d0);
+ safe_free ((void **) &d0);
}
void rfc2047_decode_adrlist (ADDRESS *a)
while (a)
{
if (a->personal && strstr (a->personal, "=?") != NULL)
- rfc2047_decode (a->personal, a->personal, mutt_strlen (a->personal) + 1);
+ rfc2047_decode (&a->personal);
#ifdef EXACT_ADDRESS
if (a->val && strstr (a->val, "=?") != NULL)
- rfc2047_decode (a->val, a->val, mutt_strlen (a->val) + 1);
+ rfc2047_decode (&a->val);
#endif
a = a->next;
}
void rfc2047_encode_string (char *, size_t, const unsigned char *);
void rfc2047_encode_adrlist (ADDRESS *);
-void rfc2047_decode (char *, const char *, size_t);
+void rfc2047_decode (char **);
void rfc2047_decode_adrlist (ADDRESS *);
*/
if (option (OPTRFC2047PARAMS) && p->value && strstr (p->value, "=?"))
- rfc2047_decode (p->value, p->value, strlen (p->value) + 1);
+ rfc2047_decode (&p->value);
*last = p;
last = &p->next;
static void decode_descriptions (BODY *b)
{
BODY *t;
- char tmp[LONG_STRING];
for (t = b; t; t = t->next)
{
if (t->description)
{
- /* this should really have the same interface as rfc2047_encode_string. */
- rfc2047_decode (tmp, t->description, sizeof (tmp));
- mutt_str_replace (&t->description, tmp);
+ rfc2047_decode (&t->description);
}
if (t->parts)
decode_descriptions (t->parts);
LIST *item;
for (item = env->userhdrs; item; item = item->next)
- rfc2047_decode (item->data, item->data, mutt_strlen (item->data) + 1);
+ rfc2047_decode (&item->data);
rfc822_free_address (&env->mail_followup_to);
rfc2047_decode_adrlist (env->cc);
rfc2047_decode_adrlist (env->from);
rfc2047_decode_adrlist (env->reply_to);
- rfc2047_decode (env->subject, env->subject, mutt_strlen (env->subject) + 1);
+ rfc2047_decode (&env->subject);
}
static void _mutt_bounce_message (FILE *fp, HEADER *h, ADDRESS *to, const char *resent_from)