re-nest parse_fetch_rsp()

prefer early exits over else branches, which is easier to follow.
This commit is contained in:
Oswald Buddenhagen 2019-11-22 16:54:31 +01:00
parent 81c4bfeefa
commit 47b477b3fb

View File

@ -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) { for (tmp = list->child; tmp; tmp = tmp->next) {
if (is_atom( tmp )) { if (!is_atom( tmp ))
continue;
if (!strcmp( "UID", tmp->val )) { if (!strcmp( "UID", tmp->val )) {
tmp = tmp->next; tmp = tmp->next;
if (!is_atom( tmp ) || (uid = strtoul( tmp->val, &ep, 10 ), *ep)) { 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. continue; // This *is* the UID.
} else if (!strcmp( "FLAGS", tmp->val )) { } else if (!strcmp( "FLAGS", tmp->val )) {
tmp = tmp->next; tmp = tmp->next;
if (is_list( tmp )) { 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" ); error( "IMAP error: unable to parse FLAGS\n" );
goto ffail; 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 )) { } else if (!strcmp( "INTERNALDATE", tmp->val )) {
tmp = tmp->next; tmp = tmp->next;
if (is_atom( tmp )) { if (!is_atom( tmp )) {
if ((date = parse_date( tmp->val )) == -1) { error( "IMAP error: unable to parse INTERNALDATE\n" );
error( "IMAP error: unable to parse INTERNALDATE format\n" );
goto ffail; goto ffail;
} }
} else { if ((date = parse_date( tmp->val )) == -1) {
error( "IMAP error: unable to parse INTERNALDATE\n" ); error( "IMAP error: unable to parse INTERNALDATE format\n" );
goto ffail; goto ffail;
} }
} else if (!strcmp( "RFC822.SIZE", tmp->val )) { } 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 )) { } else if (!strcmp( "BODY[]", tmp->val )) {
tmp = tmp->next; tmp = tmp->next;
if (is_atom( tmp )) { if (!is_atom( tmp )) {
body = tmp;
} else {
error( "IMAP error: unable to parse BODY[]\n" ); error( "IMAP error: unable to parse BODY[]\n" );
goto ffail; goto ffail;
} }
body = tmp;
} else if (!strcmp( "BODY[HEADER.FIELDS", tmp->val )) { } else if (!strcmp( "BODY[HEADER.FIELDS", tmp->val )) {
tmp = tmp->next; 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; tmp = tmp->next;
if (!is_atom( tmp ) || strcmp( tmp->val, "]" )) if (!is_atom( tmp ) || strcmp( tmp->val, "]" ))
goto bfail; goto bfail;
@ -1109,12 +1111,6 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
if (!is_atom( tmp )) if (!is_atom( tmp ))
goto bfail; goto bfail;
parse_fetched_header( tmp->val, uid, &tuid, &msgid ); 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; need_uid = 1;
} }