summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-07-25 20:47:55 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-07-25 20:47:55 +0300
commite9562a6f19d4baff5116df161954c91e684a6e3f (patch)
treeb6c38ce1fdd05bca3464eae97508440213bc1f75
parentb3c4a8be9286967ecfd7c720f2eafd598db06cb3 (diff)
downloadmailutils-e9562a6f19d4baff5116df161954c91e684a6e3f.tar.gz
mailutils-e9562a6f19d4baff5116df161954c91e684a6e3f.tar.bz2
decodemail: double-quote decoded personal parts of email addresses
* decodemail/decodemail.c: Take care to double-quote decoded personal parts of email addresses. * libmailutils/address/parse822.c (mu_parse822_quoted_string): Don't skip 8-bit characters.
-rw-r--r--decodemail/decodemail.c88
-rw-r--r--libmailutils/address/parse822.c7
2 files changed, 87 insertions, 8 deletions
diff --git a/decodemail/decodemail.c b/decodemail/decodemail.c
index 34d7f8706..9dd507eb1 100644
--- a/decodemail/decodemail.c
+++ b/decodemail/decodemail.c
@@ -336,6 +336,79 @@ crd_error (mu_coord_t crd, size_t n, char const *fmt, ...)
mu_stream_write (mu_strerr, "\n", 1, NULL);
}
+static inline int
+is_address_header (char const *name)
+{
+ return !mu_c_strcasecmp (name, MU_HEADER_TO) ||
+ !mu_c_strcasecmp (name, MU_HEADER_CC) ||
+ !mu_c_strcasecmp (name, MU_HEADER_BCC);
+}
+
+static void
+qstring_format (mu_stream_t stream, char const *s)
+{
+ char const *cp;
+ mu_stream_write (stream, "\"", 1, NULL);
+ while (*(cp = mu_str_skip_cset_comp (s, "\\\"")))
+ {
+ mu_stream_write (stream, s, cp - s, NULL);
+ mu_stream_write (stream, "\\", 1, NULL);
+ mu_stream_write (stream, cp, 1, NULL);
+ s = cp + 1;
+ }
+ if (*s)
+ mu_stream_write (stream, s, strlen (s), NULL);
+ mu_stream_write (stream, "\"", 1, NULL);
+}
+
+static int
+address_decode (char const *name, char const *value, char const *charset,
+ mu_header_t newhdr)
+{
+ int rc;
+ mu_address_t addr;
+ mu_stream_t mstr;
+ mu_transport_t trans[2];
+
+ rc = mu_memory_stream_create (&mstr, MU_STREAM_RDWR);
+ if (rc)
+ return rc;
+
+ rc = mu_address_create (&addr, value);
+ if (rc == 0)
+ {
+ mu_address_t cur;
+ for (cur = addr; cur; cur = cur->next)
+ {
+ char *s;
+
+ rc = mu_rfc2047_decode (charset, cur->personal, &s);
+ if (rc == 0)
+ {
+ qstring_format (mstr, s);
+ free (s);
+ }
+ else
+ qstring_format (mstr, cur->personal);
+ mu_stream_printf (mstr, " <%s>", cur->email);
+ if (cur->next)
+ mu_stream_write (mstr, ", ", 2, NULL);
+ }
+ mu_stream_write (mstr, "", 1, NULL);
+ rc = mu_stream_err (mstr);
+ if (rc == 0)
+ {
+ mu_stream_ioctl (mstr, MU_IOCTL_TRANSPORT,
+ MU_IOCTL_OP_GET,
+ trans);
+ mu_header_append (newhdr, name, (char*)trans[0]);
+ }
+ mu_stream_destroy (&mstr);
+ mu_address_destroy (&addr);
+ }
+ return rc;
+}
+
/*
* Decode a single message or message part.
*
@@ -459,7 +532,13 @@ message_decode (mu_message_t msg, mu_coord_t *crd, size_t dim)
else if (!mu_c_strcasecmp (name,
MU_HEADER_CONTENT_TRANSFER_ENCODING))
continue;
-
+ else if (is_address_header (name))
+ {
+ if (address_decode (name, value, charset, newhdr))
+ mu_header_append (newhdr, name, value);
+ continue;
+ }
+
rc = mu_rfc2047_decode (charset, value, &s);
if (rc == 0)
{
@@ -562,7 +641,12 @@ message_decode (mu_message_t msg, mu_coord_t *crd, size_t dim)
if (mu_c_strcasecmp (name, MU_HEADER_MIME_VERSION) == 0 ||
mu_c_strcasecmp (name, MU_HEADER_CONTENT_TYPE) == 0)
continue;
-
+ else if (is_address_header (name))
+ {
+ if (address_decode (name, value, charset, newhdr) == 0)
+ mu_header_append (newhdr, name, value);
+ continue;
+ }
rc = mu_rfc2047_decode (charset, value, &s);
if (rc == 0)
{
diff --git a/libmailutils/address/parse822.c b/libmailutils/address/parse822.c
index 05ca9c08c..8094c5e87 100644
--- a/libmailutils/address/parse822.c
+++ b/libmailutils/address/parse822.c
@@ -464,14 +464,9 @@ mu_parse822_quoted_string (const char **p, const char *e, char **qstr)
/* invalid character... */
*p += 1;
}
- else if (mu_parse822_is_char (c))
- {
- rc = str_append_char (qstr, c);
- *p += 1;
- }
else
{
- /* invalid character... */
+ rc = str_append_char (qstr, c);
*p += 1;
}
if (rc)

Return to:

Send suggestions and report system problems to the System administrator.