[evolution-data-server/gnome-3-30] I#35 - [IMAPx] Ignore incomplete BODYSTRUCTURE responses



commit 9c83bb413a654a8e1d023b7d94a7327c022846e2
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 27 08:13:18 2018 +0200

    I#35 - [IMAPx] Ignore incomplete BODYSTRUCTURE responses
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/issues/35

 src/camel/providers/imapx/camel-imapx-utils.c | 91 ++++++++++++++++++++-------
 1 file changed, 67 insertions(+), 24 deletions(-)
---
diff --git a/src/camel/providers/imapx/camel-imapx-utils.c b/src/camel/providers/imapx/camel-imapx-utils.c
index 4b6c45533..b079ee153 100644
--- a/src/camel/providers/imapx/camel-imapx-utils.c
+++ b/src/camel/providers/imapx/camel-imapx-utils.c
@@ -942,6 +942,30 @@ imapx_parse_ext_optional (CamelIMAPXInputStream *stream,
        return dinfo;
 }
 
+static gboolean
+imapx_is_budystructure_response_end (CamelIMAPXInputStream *stream,
+                                    gboolean *out_is_response_end,
+                                    GCancellable *cancellable,
+                                    GError **error)
+{
+       gint tok;
+       guint len;
+       guchar *token;
+
+       g_return_val_if_fail (out_is_response_end != NULL, FALSE);
+
+       tok = camel_imapx_input_stream_token (stream, &token, &len, cancellable, error);
+
+       if (tok == IMAPX_TOK_ERROR)
+               return FALSE;
+
+       camel_imapx_input_stream_ungettoken (stream, tok, token, len);
+
+       *out_is_response_end = tok == ')';
+
+       return TRUE;
+}
+
 struct _CamelMessageContentInfo *
 imapx_parse_body_fields (CamelIMAPXInputStream *stream,
                          GCancellable *cancellable,
@@ -954,7 +978,7 @@ imapx_parse_body_fields (CamelIMAPXInputStream *stream,
        gsize type_len;
        guint64 number;
        struct _CamelMessageContentInfo *cinfo;
-       gboolean success, is_broken_response = FALSE;
+       gboolean success, is_broken_response = FALSE, is_end = FALSE;
 
        /* body_fields     ::= body_fld_param SPACE body_fld_id SPACE
         * body_fld_desc SPACE body_fld_enc SPACE
@@ -1032,42 +1056,61 @@ imapx_parse_body_fields (CamelIMAPXInputStream *stream,
                return cinfo;
        }
 
-       /* body_fld_id     ::= nstring */
-       success = camel_imapx_input_stream_nstring (
-               stream, &token, cancellable, error);
+       success = imapx_is_budystructure_response_end (stream, &is_end, cancellable, error);
 
        if (!success)
                goto error;
 
-       cinfo->id = g_strdup ((gchar *) token);
+       if (!is_end) {
+               /* body_fld_id     ::= nstring */
+               success = camel_imapx_input_stream_nstring (stream, &token, cancellable, error);
+               if (!success)
+                       goto error;
 
-       /* body_fld_desc   ::= nstring */
-       success = camel_imapx_input_stream_nstring (
-               stream, &token, cancellable, error);
+               cinfo->id = g_strdup ((gchar *) token);
 
-       if (!success)
-               goto error;
+               success = imapx_is_budystructure_response_end (stream, &is_end, cancellable, error);
+               if (!success)
+                       goto error;
+       }
 
-       cinfo->description = g_strdup ((gchar *) token);
+       if (!is_end) {
+               /* body_fld_desc   ::= nstring */
+               success = camel_imapx_input_stream_nstring (stream, &token, cancellable, error);
+               if (!success)
+                       goto error;
 
-       /* body_fld_enc    ::= (<"> ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
-        * "QUOTED-PRINTABLE") <">) / string */
-       success = camel_imapx_input_stream_astring (
-               stream, &token, cancellable, error);
+               cinfo->description = g_strdup ((gchar *) token);
 
-       if (!success)
-               goto error;
+               success = imapx_is_budystructure_response_end (stream, &is_end, cancellable, error);
+               if (!success)
+                       goto error;
+       }
 
-       cinfo->encoding = g_strdup ((gchar *) token);
+       if (!is_end) {
+               /* body_fld_enc    ::= (<"> ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
+                * "QUOTED-PRINTABLE") <">) / string */
+               success = camel_imapx_input_stream_astring (stream, &token, cancellable, error);
+               if (!success)
+                       goto error;
 
-       /* body_fld_octets ::= number */
-       success = camel_imapx_input_stream_number (
-               stream, &number, cancellable, error);
+               cinfo->encoding = g_strdup ((gchar *) token);
 
-       if (!success)
-               goto error;
+               success = imapx_is_budystructure_response_end (stream, &is_end, cancellable, error);
+               if (!success)
+                       goto error;
+       }
 
-       cinfo->size = number;
+       if (!is_end) {
+               /* body_fld_octets ::= number */
+               success = camel_imapx_input_stream_number (
+                       stream, &number, cancellable, error);
+
+               if (!success)
+                       goto error;
+
+               cinfo->size = number;
+       }
 
        return cinfo;
 


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