summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-07-27 13:54:45 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-07-27 13:54:45 +0300
commit90cf55bc239b7665280714fbdba1e54e78ddaa3a (patch)
treed9880960ec182385e38d2a7bf192d9228373d7de
parent332c95eff31ccc1b8fe8206e7a58b5600aada168 (diff)
downloadmailutils-90cf55bc239b7665280714fbdba1e54e78ddaa3a.tar.gz
mailutils-90cf55bc239b7665280714fbdba1e54e78ddaa3a.tar.bz2
decodemail: quote personal part of an address header only if necessary
* decodemail/decodemail.c (is_address_header): Add "From:". (qstring_format): Format as a quoted string only if really necessary. (message_decode): Fix improper use of address_decode.
-rw-r--r--decodemail/decodemail.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/decodemail/decodemail.c b/decodemail/decodemail.c
index 9dd507eb1..5da0bbaf5 100644
--- a/decodemail/decodemail.c
+++ b/decodemail/decodemail.c
@@ -339,26 +339,45 @@ crd_error (mu_coord_t crd, size_t n, char const *fmt, ...)
static inline int
is_address_header (char const *name)
{
- return !mu_c_strcasecmp (name, MU_HEADER_TO) ||
+ return !mu_c_strcasecmp (name, MU_HEADER_FROM) ||
+ !mu_c_strcasecmp (name, MU_HEADER_TO) ||
!mu_c_strcasecmp (name, MU_HEADER_CC) ||
!mu_c_strcasecmp (name, MU_HEADER_BCC);
}
+static int
+qstring_needed (char const *s)
+{
+ for (; *s; s++)
+ {
+ if (mu_isascii (*s) && !mu_istspec (*s))
+ continue;
+ return 1;
+ }
+ return 0;
+}
+
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, "\\\"")))
+ if (qstring_needed (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;
+ 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);
}
- if (*s)
+ else
mu_stream_write (stream, s, strlen (s), NULL);
- mu_stream_write (stream, "\"", 1, NULL);
}
static int
@@ -643,7 +662,7 @@ message_decode (mu_message_t msg, mu_coord_t *crd, size_t dim)
continue;
else if (is_address_header (name))
{
- if (address_decode (name, value, charset, newhdr) == 0)
+ if (address_decode (name, value, charset, newhdr))
mu_header_append (newhdr, name, value);
continue;
}

Return to:

Send suggestions and report system problems to the System administrator.