Skip to content

Commit

Permalink
rfc2047_decode change from EGE.
Browse files Browse the repository at this point in the history
--HG--
branch : HEAD
  • Loading branch information
Thomas Roessler committed May 18, 2000
1 parent ed09a33 commit 5b6b2a3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion copy.c
Expand Up @@ -205,7 +205,7 @@ mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags,
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.
Expand Down
24 changes: 10 additions & 14 deletions parse.c
Expand Up @@ -427,7 +427,7 @@ BODY *mutt_read_mime_header (FILE *fp, int digest)
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
Expand All @@ -443,7 +443,7 @@ BODY *mutt_read_mime_header (FILE *fp, int digest)
{
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
Expand Down Expand Up @@ -932,13 +932,11 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
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)
Expand Down Expand Up @@ -1044,9 +1042,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
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;
}
Expand Down Expand Up @@ -1088,9 +1084,8 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
{
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;
Expand Down Expand Up @@ -1266,7 +1261,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
}
else
last = e->userhdrs = mutt_new_list ();
rfc2047_decode (line, line, linelen);
rfc2047_decode (&line);
last->data = safe_strdup (line);
}
}
Expand All @@ -1281,7 +1276,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
/* 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))
Expand Down Expand Up @@ -1309,7 +1304,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
{
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;
Expand All @@ -1325,6 +1320,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
}
}

safe_free ((void *) &in_reply_to);
return (e);
}

Expand Down
28 changes: 18 additions & 10 deletions rfc2047.c
Expand Up @@ -373,14 +373,20 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
/* 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)
{
Expand All @@ -390,9 +396,9 @@ void rfc2047_decode (char *d, const char *s, size_t dlen)
(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)
Expand All @@ -410,25 +416,27 @@ void rfc2047_decode (char *d, const char *s, size_t dlen)
}
}

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);
dlen -= n;
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;
}
Expand Down
2 changes: 1 addition & 1 deletion rfc2047.h
Expand Up @@ -19,5 +19,5 @@
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 *);
2 changes: 1 addition & 1 deletion rfc2231.c
Expand Up @@ -112,7 +112,7 @@ void rfc2231_decode_parameters (PARAMETER **headp)
*/

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;
Expand Down
5 changes: 1 addition & 4 deletions send.c
Expand Up @@ -969,15 +969,12 @@ static void encode_descriptions (BODY *b, short recurse)
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);
Expand Down
4 changes: 2 additions & 2 deletions sendlib.c
Expand Up @@ -1810,7 +1810,7 @@ void mutt_unprepare_envelope (ENVELOPE *env)
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);

Expand All @@ -1819,7 +1819,7 @@ void mutt_unprepare_envelope (ENVELOPE *env)
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)
Expand Down

0 comments on commit 5b6b2a3

Please sign in to comment.