Browse Source

re-nest parse_fetch_rsp()

prefer early exits over else branches, which is easier to follow.
1.4
Oswald Buddenhagen 5 years ago
parent
commit
47b477b3fb
  1. 38
      src/drv_imap.c

38
src/drv_imap.c

@ -1056,7 +1056,8 @@ 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 (!is_atom( tmp ))
continue;
if (!strcmp( "UID", tmp->val )) {
tmp = tmp->next;
if (!is_atom( tmp ) || (uid = strtoul( tmp->val, &ep, 10 ), *ep)) {
@ -1066,23 +1067,21 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
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 {
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 )) {
if ((date = parse_date( tmp->val )) == -1) {
error( "IMAP error: unable to parse INTERNALDATE format\n" );
if (!is_atom( tmp )) {
error( "IMAP error: unable to parse INTERNALDATE\n" );
goto ffail;
}
} else {
error( "IMAP error: unable to parse INTERNALDATE\n" );
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 )) {
@ -1093,15 +1092,18 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
}
} else if (!strcmp( "BODY[]", tmp->val )) {
tmp = tmp->next;
if (is_atom( tmp )) {
body = tmp;
} else {
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 )) {
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;
@ -1109,12 +1111,6 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
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;
}
}
}
need_uid = 1;
}

Loading…
Cancel
Save