class Net::IMAP

def self.decode_utf7(s)

mailbox names to and from UTF-7.
Net::IMAP does _not_ automatically encode and decode

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

Decode a string from modified UTF-7 format to UTF-8.
def self.decode_utf7(s)
  return s.gsub(/&([A-Za-z0-9+,]+)?-/n) {
    if base64 = $1
      (base64.tr(",", "/") + "===").unpack1("m").encode(Encoding::UTF_8, Encoding::UTF_16BE)
    else
      "&"
    end
  }
end