imap: Simplified the imap_state_append_resp() function

Introduced the result code variable to simplify the state changes and
remove the hard returns.