imap: Improved FETCH response parsing

Added safer parsing of the untagged FETCH response line and the size of
continuation data.
imap: Updated setting of transfer variables in imap_state_fetch_resp()

Add number of bytes retrieved from the PP cache to req.bytecount and set
req.maxdownload only when starting a proper download.
imap: Introduced IMAP_APPEND and IMAP_APPEND_FINAL states
imap: Added APPEND perform and response handler functions

Added imap_append() function to initiate upload and imap_append_resp()
to handle the continuation response and start the transfer.
imap: Implemented APPEND final processing

The APPEND operation needs to be performed in several steps:
  1) We send "<tag> APPEND <mailbox> <flags> {<size>}\r\n"
  2) Server responds with continuation respose "+ ...\r\n"
  3) We start the transfer and send <size> bytes of data
  4) Only now we end the request command line by sending "\r\n"
  5) Server responds with "<tag> OK ...\r\n"

This commit performs steps 4 and 5, in the DONE phase, as more
processing is required after the transfer.
imap: Enabled APPEND support in imap_perform()

Added logic in imap_perform() to perform an APPEND rather than SELECT
and FETCH if an upload has been specified.
imap: Moved imap_append() to be with the other perform functions
imap: Standardised imapcode condition tests

For consistency changed two if(constant != imapcode) tests to be
if(imapcode != constant).
imap: Changed successful response logic in imap_state_append_resp()

For consistency changed the logic of the imap_state_append_resp()
function to test for an unsucessful continuation response rather than a
succesful one.
imap: Simplified the imap_state_append_resp() function

Introduced the result code variable to simplify the state changes and
remove the hard returns.
imap: Minor code tidy up

Minor tidy up of code layout and comments following recent changes.
imap: Introduced IMAP_CUSTOM state
imap: Introduced custom request parameters

Added custom request parameters to the per-request structure.
imap: Added custom request parsing

Added imap_parse_custom_request() for parsing the CURLOPT_CUSTOMREQUEST
parameter which URL decodes the value and separates the request from
any parameters - This makes it easier to filter untagged responses
by the request command.
pop3: Fixed unnecessary parent structure reference

Updated pop3 code following recent imap changes.
imap: Added custom request perform and response handler functions

Added imap_custom(), which initiates the custom command processing,
and an associated response handler imap_state_custom_resp(), which
handles any responses by sending them to the client as body data.

All untagged responses with the same name as the first word of the
custom request string are accepted, with the exception of SELECT and
EXAMINE which have responses that cannot be easily identified. An
extra check has been provided for them so that any untagged responses
are accepted for them.
imap: Enabled custom requests in imap_perform()

Modified imap_perform() to start with the custom command instead of
SELECT when a custom command is to be performed and no mailbox has
been given.
imap: Enabled custom requests in imap_select_resp()

Changed imap_select_resp() to invoke imap_custom() instead of
imap_fetch() after the mailbox has been selected if a custom
command has been set.
imap: Fixed custom request handling in imap_done()

Fixed imap_done() so that neither the FINAL states are not entered when
a custom command has been performed.
imap: Fixed typo in variable assignment