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)
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)
IMAP: fix unexpected \Noselect in list command response (Bug #7198)

The bug was reported to upstream:
 http://www.dbmail.org/mantis/view.php?id=978

We need to order dm_db.c/mailboxes_by_regex()'s results by folder name.
This is to avoid subfolders appear before their parents in _ic_list_enter().
 This matters for '%' wildcard search.
 If subfolders appear first, 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.
With ordering we can avoid subfolders appearing before their parents.
IMAP: fix hierarchy elements masking out real folders in list response (Bug #7198)

The bug was reported to upstream:
 http://www.dbmail.org/mantis/view.php?id=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.
Imap: Folder in Cyrillic doesn't show \Haschildren flag (Bug #7641)

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.
Imap: Folder in Cyrillic doesn't show \Haschildren flag - test extension (Bug #7641)

Test case has been added for this problem.
Fails without the changes, and passes once the changes are added.