commit 654e373392a9fad1f55c9f2991aaf00502cf6e80
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Fri Nov 22 16:54:31 2019 +0100

    re-nest parse_fetch_rsp()
    
    prefer early exits over else branches, which is easier to follow.

 src/drv_imap.c | 112 ++++++++++++++++++++++++-------------------------
 1 file changed, 54 insertions(+), 58 deletions(-)

diff --git a/src/drv_imap.c b/src/drv_imap.c
index 65ce22d..ac66a91 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -1055,65 +1055,61 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char 
*s ATTR_UNUSED )
        }
 
        for (tmp = list->child; tmp; tmp = tmp->next) {
-               if (is_atom( tmp )) {
-                       if (!strcmp( "UID", tmp->val )) {
-                               tmp = tmp->next;
-                               if (!is_atom( tmp ) || (uid = strtoul( 
tmp->val, &ep, 10 ), *ep)) {
-                                       error( "IMAP error: unable to parse 
UID\n" );
-                                       goto ffail;
-                               }
-                               continue;  // This *is* the UID.
-                       } else if (!strcmp( "FLAGS", tmp->val )) {
-                               tmp = tmp->next;
-                               if (is_list( tmp )) {
-                                       if (!parse_fetched_flags( tmp->child, 
&mask, &status ))
-                                               goto ffail;
-                                       continue;  // This may legitimately 
come without UID.
-                               } else {
-                                       error( "IMAP error: unable to parse 
FLAGS\n" );
-                                       goto ffail;
-                               }
-                       } else if (!strcmp( "INTERNALDATE", tmp->val )) {
-                               tmp = tmp->next;
-                               if (is_atom( tmp )) {
-                                       if ((date = parse_date( tmp->val )) == 
-1) {
-                                               error( "IMAP error: unable to 
parse INTERNALDATE format\n" );
-                                               goto ffail;
-                                       }
-                               } else {
-                                       error( "IMAP error: unable to parse 
INTERNALDATE\n" );
-                                       goto ffail;
-                               }
-                       } else if (!strcmp( "RFC822.SIZE", tmp->val )) {
-                               tmp = tmp->next;
-                               if (!is_atom( tmp ) || (size = strtoul( 
tmp->val, &ep, 10 ), *ep)) {
-                                       error( "IMAP error: unable to parse 
RFC822.SIZE\n" );
-                                       goto ffail;
-                               }
-                       } else if (!strcmp( "BODY[]", tmp->val )) {
-                               tmp = tmp->next;
-                               if (is_atom( tmp )) {
-                                       body = tmp;
-                               } else {
-                                       error( "IMAP error: unable to parse 
BODY[]\n" );
-                                       goto ffail;
-                               }
-                       } else if (!strcmp( "BODY[HEADER.FIELDS", tmp->val )) {
-                               tmp = tmp->next;
-                               if (is_list( tmp )) {
-                                       tmp = tmp->next;
-                                       if (!is_atom( tmp ) || strcmp( 
tmp->val, "]" ))
-                                               goto bfail;
-                                       tmp = tmp->next;
-                                       if (!is_atom( tmp ))
-                                               goto bfail;
-                                       parse_fetched_header( tmp->val, uid, 
&tuid, &msgid );
-                               } else {
-                                 bfail:
-                                       error( "IMAP error: unable to parse 
BODY[HEADER.FIELDS ...]\n" );
-                                       goto ffail;
-                               }
+               if (!is_atom( tmp ))
+                       continue;
+               if (!strcmp( "UID", tmp->val )) {
+                       tmp = tmp->next;
+                       if (!is_atom( tmp ) || (uid = strtoul( tmp->val, &ep, 
10 ), *ep)) {
+                               error( "IMAP error: unable to parse UID\n" );
+                               goto ffail;
+                       }
+                       continue;  // This *is* the UID.
+               } else if (!strcmp( "FLAGS", tmp->val )) {
+                       tmp = tmp->next;
+                       if (!is_list( tmp )) {
+                               error( "IMAP error: unable to parse FLAGS\n" );
+                               goto ffail;
+                       }
+                       if (!parse_fetched_flags( tmp->child, &mask, &status ))
+                               goto ffail;
+                       continue;  // This may legitimately come without UID.
+               } else if (!strcmp( "INTERNALDATE", tmp->val )) {
+                       tmp = tmp->next;
+                       if (!is_atom( tmp )) {
+                               error( "IMAP error: unable to parse 
INTERNALDATE\n" );
+                               goto ffail;
+                       }
+                       if ((date = parse_date( tmp->val )) == -1) {
+                               error( "IMAP error: unable to parse 
INTERNALDATE format\n" );
+                               goto ffail;
+                       }
+               } else if (!strcmp( "RFC822.SIZE", tmp->val )) {
+                       tmp = tmp->next;
+                       if (!is_atom( tmp ) || (size = strtoul( tmp->val, &ep, 
10 ), *ep)) {
+                               error( "IMAP error: unable to parse 
RFC822.SIZE\n" );
+                               goto ffail;
+                       }
+               } else if (!strcmp( "BODY[]", tmp->val )) {
+                       tmp = tmp->next;
+                       if (!is_atom( tmp )) {
+                               error( "IMAP error: unable to parse BODY[]\n" );
+                               goto ffail;
+                       }
+                       body = tmp;
+               } else if (!strcmp( "BODY[HEADER.FIELDS", tmp->val )) {
+                       tmp = tmp->next;
+                       if (!is_list( tmp )) {
+                         bfail:
+                               error( "IMAP error: unable to parse 
BODY[HEADER.FIELDS ...]\n" );
+                               goto ffail;
                        }
+                       tmp = tmp->next;
+                       if (!is_atom( tmp ) || strcmp( tmp->val, "]" ))
+                               goto bfail;
+                       tmp = tmp->next;
+                       if (!is_atom( tmp ))
+                               goto bfail;
+                       parse_fetched_header( tmp->val, uid, &tuid, &msgid );
                }
                need_uid = 1;
        }


_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to