The library provides functions for encoding/decoding Erlang UTF-8 binaries to and from modified UTF-7 encoding in accordance with RFC 3501.
From RFC 3501, section 5.1.3. "Mailbox International Naming Convention":
By convention, international mailbox names in IMAP4rev1 are specified using a modified version of the UTF-7 encoding described in [UTF-7].
imap_utf7:encode(MailboxName) -> MailboxNameEncoded
when
MailboxName :: binary(),
MailboxNameEncoded :: binary().
Encodes UTF-8 MailboxName
and returns MailboxNameEncoded
in a modified UTF-7 encoding.
imap_utf7:decode(MailboxNameEncoded) -> MailboxName
when
MailboxNameEncoded :: binary(),
MailboxName :: binary().
Decodes UTF-7 MailboxNameEncoded
end returns MailboxName
in UTF-8 encoding.
Encoding:
> imap_utf7:encode(<<"Входящие"/utf8>>).
<<"&BBIERQQ+BDQETwRJBDgENQ-">>
> imap_utf7:encode(<<"Boîte de réception"/utf8>>).
<<"Bo&AO4-te de r&AOk-ception">>
> imap_utf7:encode(<<"收件箱"/utf8>>).
<<"&ZTZO9nux-">>
> imap_utf7:encode(<<"受信トレイ"/utf8>>).
<<"&U9dP4TDIMOwwpA-">>
> imap_utf7:encode(<<"Inbox">>).
<<"Inbox">>
Decoding:
> imap_utf7:decode(<<"&BBIERQQ+BDQETwRJBDgENQ-">>).
<<208,146,209,133,208,190,208,180,209,143,209,137,208,184,
208,181>>
> imap_utf7:decode(<<"&BBIERQQ+BDQETwRJBDgENQ-">>) =:= <<"Входящие"/utf8>>.
true
> imap_utf7:decode(<<"Bo&AO4-te de r&AOk-ception">>).
<<"Boîte de réception"/utf8>>
> imap_utf7:decode(<<"&ZTZO9nux-">>) =:= <<"收件箱"/utf8>>.
true
> imap_utf7:decode(<<"&U9dP4TDIMOwwpA-">>) =:= <<"受信トレイ"/utf8>>.
true
> imap_utf7:decode(<<"Inbox">>).
<<"Inbox">>
# using rebar3:
$ rebar3 compile
$ rebar3 dialyzer
$ rebar3 ct
$ rebar3 cover