[gmime] Added new parser option to allow addresses w/o a domain



commit eb1039c888978126c03415979eb407db3fd9d503
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Tue Apr 18 12:51:46 2017 -0400

    Added new parser option to allow addresses w/o a domain

 gmime/gmime-parser-options.c |   52 ++++++++++++++++++++++++++++++++++++++++++
 gmime/gmime-parser-options.h |    3 ++
 gmime/internet-address.c     |    3 +-
 3 files changed, 57 insertions(+), 1 deletions(-)
---
diff --git a/gmime/gmime-parser-options.c b/gmime/gmime-parser-options.c
index cb3fd9c..3e002ca 100644
--- a/gmime/gmime-parser-options.c
+++ b/gmime/gmime-parser-options.c
@@ -46,6 +46,7 @@ struct _GMimeParserOptions {
        GMimeRfcComplianceMode addresses;
        GMimeRfcComplianceMode parameters;
        GMimeRfcComplianceMode rfc2047;
+       gboolean allow_no_domain;
        char **charsets;
 };
 
@@ -102,6 +103,7 @@ g_mime_parser_options_new (void)
        options->addresses = GMIME_RFC_COMPLIANCE_LOOSE;
        options->parameters = GMIME_RFC_COMPLIANCE_LOOSE;
        options->rfc2047 = GMIME_RFC_COMPLIANCE_LOOSE;
+       options->allow_no_domain = FALSE;
        
        options->charsets = g_malloc (sizeof (char *) * 3);
        options->charsets[0] = g_strdup ("utf-8");
@@ -130,6 +132,7 @@ g_mime_parser_options_clone (GMimeParserOptions *options)
                options = default_options;
        
        clone = g_slice_new (GMimeParserOptions);
+       clone->allow_no_domain = options->allow_no_domain;
        clone->addresses = options->addresses;
        clone->parameters = options->parameters;
        clone->rfc2047 = options->rfc2047;
@@ -208,6 +211,55 @@ g_mime_parser_options_set_address_compliance_mode (GMimeParserOptions *options,
 
 
 /**
+ * g_mime_parser_options_get_allow_addresses_without_domain:
+ * @options: (nullable): a #GMimeParserOptions or %NULL
+ *
+ * Gets whether or not the rfc822 address parser should allow addresses without a domain.
+ *
+ * In general, you'll probably want this value to be %FALSE (the default) as it allows 
+ * maximum interoperability with existing (broken) mail clients and other mail software
+ * such as sloppily written perl scripts (aka spambots) that do not properly quote the
+ * name when it contains a comma.
+ *
+ * This option exists in order to allow parsing of mailbox addresses that do not have a
+ * domain component. These types of addresses are rare and were typically only used when
+ * sending mail to other users on the same UNIX system.
+ *
+ * Returns: %TRUE if the address parser should allow addresses without a domain.
+ **/
+GMimeRfcComplianceMode
+g_mime_parser_options_get_allow_addresses_without_domain (GMimeParserOptions *options)
+{
+       return options ? options->allow_no_domain : default_options->allow_no_domain;
+}
+
+
+/**
+ * g_mime_parser_options_set_allow_addresses_without_domain:
+ * @options: a #GMimeParserOptions
+ * @allow: %TRUE if the parser should allow addresses without a domain or %FALSE otherwise
+ *
+ * Sets whether the rfc822 address parser should allow addresses without a domain.
+ *
+ * In general, you'll probably want this value to be %FALSE (the default) as it allows 
+ * maximum interoperability with existing (broken) mail clients and other mail software
+ * such as sloppily written perl scripts (aka spambots) that do not properly quote the
+ * name when it contains a comma.
+ *
+ * This option exists in order to allow parsing of mailbox addresses that do not have a
+ * domain component. These types of addresses are rare and were typically only used when
+ * sending mail to other users on the same UNIX system.
+ **/
+void
+g_mime_parser_options_set_allow_addresses_without_domain (GMimeParserOptions *options, gboolean allow)
+{
+       g_return_if_fail (options != NULL);
+       
+       options->allow_no_domain = allow;
+}
+
+
+/**
  * g_mime_parser_options_get_parameter_compliance_mode:
  * @options: (nullable): a #GMimeParserOptions or %NULL
  *
diff --git a/gmime/gmime-parser-options.h b/gmime/gmime-parser-options.h
index fc3bc28..a2d23b3 100644
--- a/gmime/gmime-parser-options.h
+++ b/gmime/gmime-parser-options.h
@@ -61,6 +61,9 @@ GMimeParserOptions *g_mime_parser_options_clone (GMimeParserOptions *options);
 GMimeRfcComplianceMode g_mime_parser_options_get_address_compliance_mode (GMimeParserOptions *options);
 void g_mime_parser_options_set_address_compliance_mode (GMimeParserOptions *options, GMimeRfcComplianceMode 
mode);
 
+gboolean g_mime_parser_options_allow_addresses_without_domain (GMimeParserOptions *options);
+void g_mime_parser_options_set_allow_addresses_without_domain (GMimeParserOptions *options, gboolean allow);
+
 GMimeRfcComplianceMode g_mime_parser_options_get_parameter_compliance_mode (GMimeParserOptions *options);
 void g_mime_parser_options_set_parameter_compliance_mode (GMimeParserOptions *options, 
GMimeRfcComplianceMode mode);
 
diff --git a/gmime/internet-address.c b/gmime/internet-address.c
index bbd91b6..f5c3c7f 100644
--- a/gmime/internet-address.c
+++ b/gmime/internet-address.c
@@ -1790,6 +1790,7 @@ static gboolean
 address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char **in, const char **charset, 
InternetAddress **address)
 {
        GMimeRfcComplianceMode mode = g_mime_parser_options_get_address_compliance_mode (options);
+       int min_words = g_mime_parser_options_get_allow_addresses_without_domain (options) ? 1 : 0;
        gboolean trim_leading_quote = FALSE;
        const char *inptr = *in;
        const char *start;
@@ -1844,7 +1845,7 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
                words++;
                
                /* Note: some clients don't quote commas in the name */
-               if (*inptr == ',' && words > 1) {
+               if (*inptr == ',' && words > min_words) {
                        inptr++;
                        
                        length = (size_t) (inptr - start);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]