[gmime] Report violations of RFC 5322 address specifications (#55)
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Report violations of RFC 5322 address specifications (#55)
- Date: Sun, 3 Mar 2019 10:23:33 +0000 (UTC)
commit d7d6254cceb87169616d96ceacd502f9505bbfda
Author: albrechtd <albrecht dress arcor de>
Date: Mon Jan 28 21:50:43 2019 +0100
Report violations of RFC 5322 address specifications (#55)
Use the GMimeParserWarning facility to report a warning if
(1) parsing an address failed with any error or
(2) multiple adresses in a mailbox-list are not separated properly.
examples/msgcheck.c | 2 ++
gmime/gmime-parser-options.h | 4 +++-
gmime/internet-address.c | 11 +++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/examples/msgcheck.c b/examples/msgcheck.c
index 88addefc..2f78a616 100644
--- a/examples/msgcheck.c
+++ b/examples/msgcheck.c
@@ -52,6 +52,8 @@ errcode2str(GMimeParserWarning errcode)
return "truncated message";
case GMIME_WARN_MALFORMED_MESSAGE:
return "malformed message";
+ case GMIME_WARN_INVALID_ADDRESS_SPEC:
+ return "invalid address specification";
case GMIME_CRIT_INVALID_HEADER_NAME:
return "invalid header name, parser may skip the message or parts of it";
case GMIME_CRIT_CONFLICTING_HEADER:
diff --git a/gmime/gmime-parser-options.h b/gmime/gmime-parser-options.h
index a8dedbee..2c17b798 100644
--- a/gmime/gmime-parser-options.h
+++ b/gmime/gmime-parser-options.h
@@ -52,6 +52,7 @@ typedef enum {
* @GMIME_WARN_MALFORMED_MULTIPART: no items in a `multipart/...`
* @GMIME_WARN_TRUNCATED_MESSAGE: the message is truncated
* @GMIME_WARN_MALFORMED_MESSAGE: the message is malformed
+ * @GMIME_WARN_INVALID_ADDRESS_SPEC: invalid address specification
* @GMIME_CRIT_INVALID_HEADER_NAME: invalid header name, the parser may skip the message or parts of it
* @GMIME_CRIT_CONFLICTING_HEADER: conflicting header
* @GMIME_CRIT_CONFLICTING_PARAMETER: conflicting header parameter
@@ -73,7 +74,8 @@ typedef enum {
GMIME_CRIT_CONFLICTING_HEADER,
GMIME_CRIT_CONFLICTING_PARAMETER,
GMIME_CRIT_MULTIPART_WITHOUT_BOUNDARY,
- GMIME_WARN_INVALID_PARAMETER
+ GMIME_WARN_INVALID_PARAMETER,
+ GMIME_WARN_INVALID_ADDRESS_SPEC
} GMimeParserWarning;
/**
diff --git a/gmime/internet-address.c b/gmime/internet-address.c
index d515088e..b899d471 100644
--- a/gmime/internet-address.c
+++ b/gmime/internet-address.c
@@ -2050,6 +2050,8 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
}
error:
+ if (g_mime_parser_options_get_warning_callback (options) != NULL)
+ _g_mime_parser_options_warn (options, offset, GMIME_WARN_INVALID_ADDRESS_SPEC, *in);
*address = NULL;
*in = inptr;
@@ -2059,6 +2061,7 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
static gboolean
address_list_parse (InternetAddressList *list, GMimeParserOptions *options, const char **in, gboolean
is_group, gint64 offset)
{
+ gboolean can_warn = g_mime_parser_options_get_warning_callback (options) != NULL;
InternetAddress *address;
const char *charset;
const char *inptr;
@@ -2072,6 +2075,8 @@ address_list_parse (InternetAddressList *list, GMimeParserOptions *options, cons
return FALSE;
while (*inptr) {
+ gboolean separator_between_addrs = FALSE;
+
if (is_group && *inptr == ';')
break;
@@ -2086,6 +2091,9 @@ address_list_parse (InternetAddressList *list, GMimeParserOptions *options, cons
if (charset)
address->charset = g_strdup (charset);
+
+ if (INTERNET_ADDRESS_IS_GROUP(address))
+ separator_between_addrs = TRUE;
}
/* Note: we loop here in case there are any null addresses between commas */
@@ -2099,8 +2107,11 @@ address_list_parse (InternetAddressList *list, GMimeParserOptions *options, cons
if (*inptr != ',')
break;
+ separator_between_addrs = TRUE;
inptr++;
} while (TRUE);
+ if (can_warn && !(separator_between_addrs || (*inptr == '\0') || (is_group && (*inptr ==
';'))))
+ _g_mime_parser_options_warn (options, offset, GMIME_WARN_INVALID_ADDRESS_SPEC, *in);
}
*in = inptr;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]