File: utf7.el.html
UTF-7 - A Mail-Safe Transformation Format of Unicode - RFC 2152
This is a transformation format of Unicode that contains only 7-bit
ASCII octets and is intended to be readable by humans in the limiting
case that the document consists of characters from the US-ASCII
repertoire.
In short, runs of characters outside US-ASCII are encoded as base64
inside delimiters.
A variation of UTF-7 is specified in IMAP 4rev1 (RFC 2060) as the way
to represent characters outside US-ASCII in mailbox names in IMAP.
This library supports both variants, but the IMAP variation was the
reason I wrote it.
The routines convert UTF-7 -> UTF-16 (16 bit encoding of Unicode)
-> current character set, and vice versa.
However, until Emacs supports Unicode, the only Emacs character set
supported here is ISO-8859.1, which can trivially be converted to/from
Unicode.
When decoding results in a character outside the Emacs character set,
an error is thrown. It is up to the application to recover.
UTF-7 should be done by providing a coding system. Mule-UCS does already, but I don't know if it does the IMAP version and it's not clear whether that should really be a coding system. The UTF-16 part of the conversion can be done with coding systems available with Mule-UCS or some versions of Emacs. Unfortunately these were done wrongly (regarding handling of byte-order marks and how the variants were named), so we don't have a consistent name for the necessary coding system. The code below doesn't seem to DTRT generally. E.g.:
(utf7-encode "a+£")
=> "a+ACsAow-"
$ echo "a+£"|iconv -f utf-8 -t utf-7
a+-+AKM
-- fx
Defined variables (3)
utf7-direct-encoding-chars | Character ranges which do not need escaping in UTF-7. |
utf7-imap-direct-encoding-chars | Character ranges which do not need escaping in the IMAP variant of UTF-7. |
utf7-utf-16-coding-system | Coding system which encodes big endian UTF-16 without a BOM signature. |
Defined functions (10)
utf7-decode | (STRING &optional FOR-IMAP) |
utf7-decode-internal | (&optional FOR-IMAP) |
utf7-encode | (STRING &optional FOR-IMAP) |
utf7-encode-internal | (&optional FOR-IMAP) |
utf7-fragment-decode | (START END &optional FOR-IMAP) |
utf7-fragment-encode | (START END &optional FOR-IMAP) |
utf7-get-u16char-converter | (WHICH-WAY) |
utf7-imap-get-pad-length | (LEN MODULUS) |
utf7-latin1-u16-char-converter | () |
utf7-u16-latin1-char-converter | () |