APPENDUID feature

http://tools.ietf.org/html/rfc4315
-----
[Page 2:]
The following response codes are extensions to the response codes
defined in [IMAP] section 7.1.

APPENDUID

Followed by the UIDVALIDITY of the destination mailbox and the UID
assigned to the appended message in the destination mailbox,
indicates that the message has been appended to the destination
mailbox with that UID.
-----

The SESSION_OK macro has been refactored to SESSION_OK_COMMON.
This is to notice if upstream changes the macro (resolving conflicts is better than duplicating code).
The refactored macro enables response codes.
SESSION_OK calls SESSION_OK_COMMON, so that it will behave the same as previously.
SESSION_OK_WITH_RESP_CODE may be used to send OK response with response code.
_ic_append_enter() has been changed:
 Creates a GString buffer.
 Copies the APPENDUID response code's contents to it with g_string_printf().
 Calls SESSION_OK_WITH_RESP_CODE with the buffer's contents.

Test changes:
 MyIMAP extends Net::IMAP.
 Greeting test is now improved.
 Testcase for append (regressions, answer format and data validity).

(ported and extended based on commit 34206bbc83e0a3b0213b698d35f81df090778b4b)

Conflicts:
	test-scripts/testimap.py

Signed-off-by: Paul J Stevens <paul@nfg.nl>
COPYUID feature (Feature #3789)

http://tools.ietf.org/html/rfc4315
-----
[Page 2-3:]
The following response codes are extensions to the response codes
defined in [IMAP] section 7.1.

COPYUID

Followed by the UIDVALIDITY of the destination mailbox, a UID set
containing the UIDs of the message(s) in the source mailbox that
were copied to the destination mailbox and containing the UIDs
assigned to the copied message(s) in the destination mailbox,
indicates that the message(s) have been copied to the destination
mailbox with the stated UID(s).

The source UID set is in the order the message(s) were copied; the
destination UID set corresponds to the source UID set and is in
the same order.
-----

ImapSession struct extended with new_ids list.
_do_copy() saves new_ids into this list.
_ic_copy_enter():
 retrieves old and new uids.
 Converts them to string.
 Creates and fills response code buffer.
 Calls SESSION_OK_WITH_RESP_CODE with the buffer's contents.

Test changes:
 ActiveSupport is included.
 Testcase for copy (regressions, answer format and data validity).

(ported and extended based on commit e374300699d18240986fd25ad701bbb4f74afb73)

Conflicts:
	src/imapcommands.c

Signed-off-by: Paul J Stevens <paul@nfg.nl>
IMAP: fix hierarchy elements masking out real folders in list response (#978)

The \Noselect flag was appearing unexpectedly in specific cases in list command responses.
This was reproducible for '%' wildcard search.
It was caused by the hierarchy elements found earlier and masking out real folders.
 If subfolders appear first in mailboxes_by_regex()'s response, then the
 partial hierarchy name is found before the real folder.
 All partial hierarchy elements receive \Noselect flag, so showing the
 name from the partial match will include this.
We could change the ordering of returned folders in mailboxes_by_regex(),
 but that would be only a workaround.
The real folders should have a higher priority than the hierarchy elements.
Store the found real folders and hierarchy elements into two separate trees
 before writing them out.
Insert folders from the lower priority tree (the hierarchy elements) to the
 higher priority one, except those that are already there.
 This way they won't mask real folders out.
Iterate the higher priority tree, and output folders to the socket.
It was necessary to insert new functions for the two iterations.
Several parts of the code have been refactored.
A new MailBox state info pointer needs to be reserved and stored into these
 trees.
Freeing can happen at different points.

Tests extended.

Conflicts:
	src/dm_mailboxstate.c
	src/imapcommands.c

Signed-off-by: Paul J Stevens <paul@nfg.nl>
Imap: Folder in Cyrillic doesn't show \Haschildren flag (#987)

This was a string-processing error in dm_db.c/mailbox_match_new().
mailbox_match_new() is called at least from two places with a folder name pattern
 that contains '%' (this is for matching subfolders).
In the old version it was not excluding '%' from replacing it (in specific cases)
 with '_' ('&BBoEOARXBDI-/%' => '&BBoEOARXBDI___').
The '%' sign was replaced with '_' in the 'sensitive' part, and that is
 included in the SQL just when there is a utf7-imap-encoded part in the name.
 That's why the bug was reproducible just for names including parts in utf7-imap encoding.
This way there wasn't any match when counting subfolders of eg. Cyrillic folders.

Also a smaller fix was applied to properly change from verbatim to non-verbatim state.
The '-' sign - closing modified BASE64 data - is still part of that data.

Tests extended.
post-merge cleanup

just some PEP8 cleanups
post-merge: fix uninitialized vars
post-merge: fix incorrect pointer usage
post-merge: disable failing test
improve test
IMAP: remove redundant logging during STORE
POP3/IMAP: simplify message accessors
IMAP: increase buffer size for dates in sql queries
IMAP: prevent assertion in sequence-set parser
IMAP: include user-id in login accepted log-message
IMAP: regression fix
IMAP: COPYUID cleanup
IMAP: add UIDPLUS capability
IMAP: small leak plugged
IMAP: add WITHIN search capability
IMAP: add LOGINDISABLED capability