[gmime] Fixed parsing of group addresses like "name:" (e.g. empty w/ no '; ')



commit e1a6898315fdb365ddbe47706fac3664135ab457
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Wed Feb 8 12:52:13 2017 -0500

    Fixed parsing of group addresses like "name:" (e.g. empty w/ no ';')

 gmime/gmime.c            |    2 +-
 gmime/internet-address.c |   30 +++++++++++++-----------------
 tests/test-mime.c        |   10 +++++-----
 3 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/gmime/gmime.c b/gmime/gmime.c
index e33a9b5..18a29b3 100644
--- a/gmime/gmime.c
+++ b/gmime/gmime.c
@@ -102,7 +102,7 @@ g_mime_init (void)
        
        if (initialized++)
                return;
-
+       
        /* seed the random number generator (needed by boundary generator) */
        srand ((unsigned int) time (NULL));
        
diff --git a/gmime/internet-address.c b/gmime/internet-address.c
index 44ee15a..5a2a88a 100644
--- a/gmime/internet-address.c
+++ b/gmime/internet-address.c
@@ -1635,32 +1635,24 @@ mailbox_parse (GMimeParserOptions *options, const char **in, const char *name, I
 static gboolean address_list_parse (InternetAddressList *list, GMimeParserOptions *options, const char **in, 
gboolean is_group);
 
 static gboolean
-group_parse (GMimeParserOptions *options, const char **in, const char *name, InternetAddress **address)
+group_parse (InternetAddressGroup *group, GMimeParserOptions *options, const char **in)
 {
-       InternetAddressGroup *group;
        const char *inptr = *in;
        
        /* skip over the ':' */
        inptr++;
        
-       if (*inptr == '\0') {
-               *address = NULL;
-               *in = inptr;
+       if (*inptr != '\0') {
+               address_list_parse (group->members, options, &inptr, TRUE);
                
-               return FALSE;
-       }
-       
-       group = (InternetAddressGroup *) internet_address_group_new (name);
-       address_list_parse (group->members, options, &inptr, TRUE);
-       
-       if (*inptr != ';') {
-               while (*inptr && *inptr != ';')
+               if (*inptr != ';') {
+                       while (*inptr && *inptr != ';')
+                               inptr++;
+               } else {
                        inptr++;
-       } else {
-               inptr++;
+               }
        }
        
-       *address = (InternetAddress *) group;
        *in = inptr;
        
        return TRUE;
@@ -1774,6 +1766,7 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
        
        if (*inptr == ':') {
                /* rfc2822 group address */
+               InternetAddressGroup *group;
                const char *phrase = start;
                gboolean retval;
                char *name;
@@ -1792,8 +1785,11 @@ address_parse (GMimeParserOptions *options, AddressParserFlags flags, const char
                        name = g_strdup ("");
                }
                
-               retval = group_parse (options, &inptr, name, address);
+               group = (InternetAddressGroup *) internet_address_group_new (name);
+               *address = (InternetAddress *) group;
                g_free (name);
+               
+               retval = group_parse (group, options, &inptr);
                *in = inptr;
                
                return retval;
diff --git a/tests/test-mime.c b/tests/test-mime.c
index 7b2fa85..68c6837 100644
--- a/tests/test-mime.c
+++ b/tests/test-mime.c
@@ -241,12 +241,12 @@ test_addrspec (GMimeParserOptions *options, gboolean test_broken)
                        
                        str = internet_address_list_to_string (addrlist, FALSE);
                        if (strcmp (addrspec[i].display, str) != 0)
-                               throw (exception_new ("display addr-spec %s does not match: %s", 
addrspec[i].display, str));
+                               throw (exception_new ("display strings do not match.\ninput: %s\nexpected: 
%s\nactual: %s", addrspec[i].input, addrspec[i].display, str));
                        g_free (str);
                        
                        str = internet_address_list_to_string (addrlist, TRUE);
                        if (strcmp (addrspec[i].encoded, str) != 0)
-                               throw (exception_new ("encoded addr-spec %s does not match: %s", 
addrspec[i].encoded, str));
+                               throw (exception_new ("encoded strings do not match.\nexpected: %s\nactual: 
%s", addrspec[i].encoded, str));
                        
                        testsuite_check_passed ();
                } catch (ex) {
@@ -266,16 +266,16 @@ test_addrspec (GMimeParserOptions *options, gboolean test_broken)
                        testsuite_check ("broken_addrspec[%u]", i);
                        try {
                                if (!(addrlist = internet_address_list_parse (options, 
broken_addrspec[i].input)))
-                                       throw (exception_new ("could not parse addr-spec"));
+                                       throw (exception_new ("could not parse: %s", 
broken_addrspec[i].input));
                                
                                str = internet_address_list_to_string (addrlist, FALSE);
                                if (strcmp (broken_addrspec[i].display, str) != 0)
-                                       throw (exception_new ("display addr-spec %s does not match: %s", 
broken_addrspec[i].display, str));
+                                       throw (exception_new ("display strings do not match.\ninput: 
%s\nexpected: %s\nactual: %s", broken_addrspec[i].input, broken_addrspec[i].display, str));
                                g_free (str);
                                
                                str = internet_address_list_to_string (addrlist, TRUE);
                                if (strcmp (broken_addrspec[i].encoded, str) != 0)
-                                       throw (exception_new ("encoded addr-spec %s does not match: %s", 
broken_addrspec[i].encoded, str));
+                                       throw (exception_new ("encoded strings do not match.\nexpected: 
%s\nactual: %s", broken_addrspec[i].encoded, str));
                                
                                testsuite_check_passed ();
                        } catch (ex) {


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