Skip to content

IMAP UTF-7 encoding/decoding library for Erlang

License

Notifications You must be signed in to change notification settings

DOBRO/erlang-imap-utf7

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imap_utf7

imap_utf7 on Hex.pm CI Status Code coverage License

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].

Functions

Encoding

imap_utf7:encode(MailboxName) -> MailboxNameEncoded
  when
    MailboxName         :: binary(),
    MailboxNameEncoded  :: binary().

Encodes UTF-8 MailboxName and returns MailboxNameEncoded in a modified UTF-7 encoding.

Decoding

imap_utf7:decode(MailboxNameEncoded) -> MailboxName
  when
    MailboxNameEncoded  :: binary(),
    MailboxName         :: binary().

Decodes UTF-7 MailboxNameEncoded end returns MailboxName in UTF-8 encoding.

Examples

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">>

Building and testing

# using rebar3:
$ rebar3 compile
$ rebar3 dialyzer
$ rebar3 ct
$ rebar3 cover

About

IMAP UTF-7 encoding/decoding library for Erlang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages