/// <summary>
 /// Returns a RFC2045 charset string for a given charset.
 /// </summary>
 /// <returns></returns>
 protected string MimeCharsetToString(MimeCharset charset)
 {
     switch (charset)
     {
         case MimeCharset.Ascii:
             return "us-ascii";
         case MimeCharset.Utf7:
             return "UTF-7";
         case MimeCharset.Utf8:
             return "UTF-8";
         default:
             return "us-ascii";
     }
 }
 /// <summary>
 /// Gets the text from the part with a given encoding.
 /// </summary>
 /// <param name="charset">The charset to use (e.g. MimeCharset.Ascii)</param>
 /// <returns>The text from the part</returns>
 public string GetText(MimeCharset charset)
 {
     switch (charset)
     {
         case MimeCharset.Ascii:
             return System.Text.Encoding.ASCII.GetString(_buffer);
         case MimeCharset.Utf7:
             return System.Text.Encoding.UTF7.GetString(_buffer);
         case MimeCharset.Utf8:
             return System.Text.Encoding.UTF8.GetString(_buffer);
     }
     return null;
 }
 /// <summary>
 /// Sets the underlying part buffer from a string using the given character set.
 /// </summary>
 /// <param name="val">The string to put in the part.</param>
 /// <param name="charset">The charcter set used to convert the string to bytes.</param>
 public void SetText(string val, MimeCharset charset)
 {
     _charset = charset;
     switch (charset)
     {
         case MimeCharset.Ascii:
             _buffer = System.Text.Encoding.ASCII.GetBytes(val);
             break;
         case MimeCharset.Utf7:
             _buffer = System.Text.Encoding.UTF7.GetBytes(val);
             break;
         case MimeCharset.Utf8:
             _buffer = System.Text.Encoding.UTF8.GetBytes(val);
             break;
     }
 }
 /// <summary>
 /// Set body of the message from plain text
 /// </summary>
 /// <param name="plainText">plain text to set the body</param>
 /// <param name="charset"></param>
 public void SetBodyFromPlainText(string plainText, MimeCharset charset)
 {
     SetText(plainText, charset);
 }