Method: Net::IMAP.decode_utf7

Defined in:
lib/net/imap.rb

.decode_utf7(s) ⇒ Object

Decode a string from modified UTF-7 format to UTF-8.

UTF-7 is a 7-bit encoding of Unicode [UTF7]. IMAP uses a slightly modified version of this to encode mailbox names containing non-ASCII characters; see [IMAP] section 5.1.3.

Net::IMAP does not automatically encode and decode mailbox names to and from utf7.



825
826
827
828
829
830
831
832
833
834
835
836
837
838
# File 'lib/net/imap.rb', line 825

def self.decode_utf7(s)
  return s.gsub(/&(.*?)-/n) {
    if $1.empty?
      "&"
    else
      base64 = $1.tr(",", "/")
      x = base64.length % 4
      if x > 0
        base64.concat("=" * (4 - x))
      end
      u16tou8(base64.unpack("m")[0])
    end
  }
end