title: IMAP folder path encoding (IMAP UTF-7) for .NET?
body: <p>The IMAP specification (<a href="http://www.faqs.org/rfcs/rfc2060.html" rel="nofollow noreferrer">RFC 2060</a>, 5.1.3. Mailbox International Naming Convention) describes how to handle non-ASCII characters in folder names. It defines a <strong>modified</strong> UTF-7 encoding:</p>
  
  <blockquote>
    <p>By convention, international mailbox
    names are specified using a
    modified version of the UTF-7 encoding
    described in [UTF-7]. The purpose
    of these modifications is to correct
    the following problems with UTF-7:</p>
    
    <ol>
    <li><p>UTF-7 uses the "+" character for shifting; this conflicts with
    the common use of "+" in mailbox names, in particular USENET
    newsgroup names.</p></li>
    <li><p>UTF-7's encoding is BASE64 which uses the "/" character; this
    conflicts with the use of "/" as a popular hierarchy delimiter.</p></li>
    <li><p>UTF-7 prohibits the unencoded usage of "\"; this conflicts with
         the use of "\" as a popular hierarchy delimiter.</p></li>
    <li><p>UTF-7 prohibits the unencoded usage of "~"; this conflicts with
         the use of "~" in some servers as a home directory indicator.</p></li>
    <li><p>UTF-7 permits multiple alternate forms to represent the same
         string; in particular, printable US-ASCII chararacters can be
         represented in encoded form.</p></li>
    </ol>
    
    <p>In modified UTF-7, printable US-ASCII characters except for "&amp;" represent themselves;
    that is, characters with octet values 0x20-0x25
    and 0x27-0x7e. The character "&amp;"
    (0x26) is represented by the two-octet sequence "&amp;-".</p>
    
    <p>All other characters (octet values
    0x00-0x1f, 0x7f-0xff, and all Unicode 16-bit octets) are represented
    in modified BASE64, with a further
    modification from [UTF-7] that "," is
    used instead of "/".<br>
    Modified BASE64 MUST NOT be used to represent
    any printing US-ASCII character
    which can represent itself.</p>
    
    <p>"&amp;" is used to shift to modified
    BASE64 and "-" to shift back to US-ASCII. All names start in US-ASCII,
    and MUST end in US-ASCII (that is,
    a name that ends with a Unicode 16-bit
    octet MUST end with a "-").</p>
  </blockquote>
  
  <p>Before I'll start implementing it, my question: is there some <strong>.NET code/library</strong> out there (or even in the framework) that does the job? I couldn't find .NET resources (only <a href="http://search.cpan.org/~pmakholm/Encode-IMAPUTF7-1.01/lib/Encode/IMAPUTF7.pm" rel="nofollow noreferrer">implementations for other languages/frameworks</a>).</p>
  
  <p><em>Thank you!</em></p>