/// <summary> /// Formats a given name to a valid file system name. /// </summary> /// <param name="name">The name.</param> /// <returns>A file system name.</returns> public static string FormatFileSystemName(string name) { Match match = Utf8Regex.Match(name); if (match.Success) { name = MailMessageRFCDecoder.GetStringFromBase64(match.Groups[1].Value, "UTF-8"); } else if ((match = IsoRegex.Match(name)).Success) { name = MailMessageRFCDecoder.GetStringFromQuotedPrintable(match.Groups[1].Value, "iso-8859-1"); } Regex invalidFileSystemNameRegex = new Regex(@"[" + string.Join("", Path.GetInvalidFileNameChars()) + "]+"); if (invalidFileSystemNameRegex.IsMatch(name)) { return(invalidFileSystemNameRegex.Replace(name, "")); } return(name); }
public string Parse(byte[] source, EContentTransferEncoding contentTransferEncoding, string charset) { Encoding encoding; switch (contentTransferEncoding) { case EContentTransferEncoding.Base64: return(MailMessageRFCDecoder.GetStringFromBase64(source, charset)); case EContentTransferEncoding.QuotedPrintable: return(MailMessageRFCDecoder.GetStringFromQuotedPrintable(source, charset)); } try { encoding = Encoding.GetEncoding(charset); } catch (ArgumentException) { return(Encoding.UTF8.GetString(source, 0, source.Length)); } return(encoding.GetString(source, 0, source.Length)); }