imap: Improved FETCH response parsing

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

Add number of bytes retrieved from the PP cache to req.bytecount,
set req.maxdownload only when starting a proper download.
imap: Added 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 done 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"

Because of steps 4 and 5, more processing is necessary after the transfer,
in the DONE phase. This commit introduces the handler used in APPEND_FINAL
state and changes imap_done() to finish the upload operation correctly.
imap: Enabled APPEND support in imap_perform()

Added logic in imap_perform() to do an APPEND instead of SELECT + FETCH
if an upload has been set up.
imap: Added custom command parameters to the per-request structure
imap: Added custom request preparation in imap_do()

Added CURLOPT_CUSTOMREQUEST processing code into imap_do() which will
parse the custom command into its name and parameters (so that it will
be possible to filter untagged responses by its name) and store that
into the new per-request variables.
imap: Added IMAP_CUSTOM state
imap: Added custom request perform and response handler functions

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

All untagged responses with the same name as the first word of the
custom request string are accepted, which would not for SELECT and
EXAMINE which have responses that cannot be easily identified. An
extra check has been provided for them so that any untagged response
is accepted in their case.

The filtering also does not work with the command STORE, whose responses
are tagged with keyword FETCH. This will be addressed in another commit.
imap: Enabled custom request 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 request 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 IMAP_FETCH_FINAL nor
IMAP_APPEND_FINAL state is entered when a custom command has
been performed.
imap: Do not allow FETCH or APPEND without a mailbox name

Added a check for the above in imap_do(), removed a now
superfluous NULL pointer test in imap_select().
imap: Fixed handling of responses to STORE custom command

The STORE command sends back untagged responses with FETCH keyword.
An exception was added into imap_custom() to make sure they don't get
filtered away for not containing the custom command name.
imap: Updated ftpserver.pl to be more compliant, added new commands

Enriched IMAP capabilities of ftpserver.pl in order to be able to
add tests for the new IMAP features.

* Added support for APPEND - Saves uploaded data to log/upload.$testno
* Added support for LIST - Returns some hardcoded list of mailboxes
* Added support for STORE - Returns hardcoded updated flags
* Changed handling of SELECT - Returns much more information in the
  usual set of untagged responses; uses hardcoded data from an example
  in the IMAP RFC
* Changed handling of FETCH - Fixed response format
imap: Added test816 for UID and SECTION URL parameters
imap: Added test817 and test818 for UIDVALIDITY verification

One test for a request with matching UIDVALIDITY, one for
a mismatched request which shall fail.
imap: Added test819 for skipping SELECT if in the same mailbox
imap: Added test820 for APPEND functionality