public string DecodeParameterValue(string source) { bool flag = false; bool flag2 = true; StringBuilder builder = new StringBuilder(); foreach (string str in source.Replace("\\\"", "").Split(new char[] { ' ' })) { bool flag3 = flag; string str2 = MailMessageRFCDecoder.ParseBase64Item(str); if (str2 != "") { flag = true; } else { flag = false; str2 = str; } if ((!flag || !flag3) && !flag2) { builder.Append(' '); } flag2 = false; builder.Append(str2); } return(builder.ToString()); }
public string ParseSubject(string header) { if (header == null) { throw new ArgumentNullException("header"); } StringBuilder builder = new StringBuilder(""); Match match = regSubject.Match(header); if (match.Success && (match.Groups.Count > 0)) { MatchCollection matchs = regSubjectItem.Matches(match.Groups[1].Value); if (matchs.Count == 0) { builder = new StringBuilder(match.Groups[1].Value); } else { foreach (Match match2 in matchs) { builder.Append(MailMessageRFCDecoder.ParseBase64Item(match2.Value)); } } } return(builder.ToString()); }
public override byte[] ReadLine() { byte[] collection = new byte[] { 13, 10 }; if (base.EndOfMessage) { throw new InvalidOperationException("End of the message was reached"); } int endOfLinePosition = base.GetEndOfLinePosition(this._buffer, 0); while (endOfLinePosition == -1) { bool flag; byte[] buffer3; byte[] line = base._sourceReader.ReadLine(); if (base._sourceReader.EndOfMessage) { base._endOfMessage = true; base._finalBoundaryReached = true; break; } EBoundaryType type = BoundaryChecker.CheckBoundary(line, base._boundary); if (type != EBoundaryType.NotBoundary) { base._endOfMessage = true; base._finalBoundaryReached = type == EBoundaryType.Final; return(this._buffer.ToArray()); } if ((line.Length > 0) && (line[line.Length - 1] == 0x3d)) { flag = false; buffer3 = new byte[line.Length - 1]; Array.Copy(line, 0, buffer3, 0, line.Length - 1); } else { flag = true; buffer3 = line; } byte[] buffer4 = MailMessageRFCDecoder.DecodeFromQuotedPrintable(buffer3); this._buffer.AddRange(buffer4); if (flag) { this._buffer.AddRange(collection); } int offset = (this._buffer.Count - buffer4.Length) - 1; offset -= flag ? 2 : 0; endOfLinePosition = base.GetEndOfLinePosition(this._buffer, offset); } List <byte> range = this._buffer.GetRange(0, endOfLinePosition); this._buffer.RemoveRange(0, endOfLinePosition + 2); return(range.ToArray()); }
public EmailAddress ParseEmail(string text) { string str; EmailAddress address; if (text == null) { throw new ArgumentNullException("text"); } string input = ""; Match match = regAddressDifDisplayName.Match(text); if (match.Success && (match.Groups.Count > 1)) { input = match.Groups[1].Value; str = match.Groups[2].Value; } else { match = regAddressDisplayName.Match(text); if (match.Success && (match.Groups.Count > 1)) { input = match.Groups[1].Value; str = match.Groups[2].Value; } else { match = regAddressEasy.Match(text); if (match.Success && (match.Groups.Count > 1)) { str = match.Groups[1].Value; } else { return(null); } } } if (regSubjectItem.IsMatch(input)) { input = MailMessageRFCDecoder.ParseBase64Item(input); } try { address = new EmailAddress(str, input.Trim()); } catch { return(null); } return(address); }
public IList <string> ParseKeywords(string text) { if (text == null) { throw new ArgumentNullException("text"); } List <string> list = new List <string>(); Match match = regKeywords.Match(text); if (match.Success && (match.Groups.Count > 1)) { foreach (Match match2 in regKeyword.Matches(match.Groups[1].Value)) { list.Add(regSubjectItem.IsMatch(match2.Groups[1].Value) ? MailMessageRFCDecoder.ParseBase64Item(match2.Groups[1].Value) : match2.Groups[1].Value); } } return(list); }
public string ParseComments(string text) { if (text == null) { throw new ArgumentNullException("text"); } Match match = regComments.Match(text); if (!match.Success || (match.Groups.Count <= 1)) { return(null); } if (!regSubjectItem.IsMatch(match.Groups[1].Value)) { return(match.Groups[1].Value); } return(MailMessageRFCDecoder.ParseBase64Item(match.Groups[1].Value)); }
public override byte[] ReadLine() { if (base.EndOfMessage) { throw new InvalidOperationException("End of the message was reached"); } int endOfLinePosition = base.GetEndOfLinePosition(this._buffer, 0); if (this._reachedBoundary == EBoundaryType.NotBoundary) { while (endOfLinePosition == -1) { byte[] line = base._sourceReader.ReadLine(); if (base._sourceReader.EndOfMessage) { base._endOfMessage = true; base._finalBoundaryReached = true; break; } EBoundaryType type = BoundaryChecker.CheckBoundary(line, base._boundary); if (type != EBoundaryType.NotBoundary) { this._reachedBoundary = type; byte[] buffer2 = this._buffer.ToArray(); this._buffer.Clear(); return(buffer2); } byte[] collection = MailMessageRFCDecoder.DecodeFromBase64(line); this._buffer.AddRange(collection); endOfLinePosition = base.GetEndOfLinePosition(this._buffer, (this._buffer.Count - collection.Length) - 1); } } else { base._endOfMessage = true; base._finalBoundaryReached = this._reachedBoundary == EBoundaryType.Final; return(null); } List <byte> range = this._buffer.GetRange(0, endOfLinePosition); this._buffer.RemoveRange(0, endOfLinePosition + 2); return(range.ToArray()); }
/// <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 virtual void ParseFromQuotedPrintable(IMessageReader reader, ContentType contentType, ContentDisposition contentDisposition, string boundary) { byte[] buffer; bool flag = false; byte[] data = new byte[] { 13, 10 }; Label_0019: buffer = reader.ReadLine(); if (!reader.EndOfMessage) { switch (BoundaryChecker.CheckBoundary(buffer, boundary)) { case EBoundaryType.NotBoundary: { byte[] buffer2; if (flag) { this.ContentWriter.Write(data); } if ((buffer.Length > 0) && (buffer[buffer.Length - 1] == 0x3d)) { buffer2 = new byte[buffer.Length - 1]; Array.Copy(buffer, buffer2, (int)(buffer.Length - 1)); flag = false; } else { buffer2 = buffer; flag = true; } byte[] buffer4 = MailMessageRFCDecoder.DecodeFromQuotedPrintable(buffer2); this.ContentWriter.Write(buffer4); goto Label_0019; } case EBoundaryType.Final: this.RaiseFinalBoundaryReached(); break; } } }
public virtual void ParseFromBase64(IMessageReader reader, ContentType contentType, ContentDisposition contentDisposition, string boundary) { byte[] buffer; Label_0000: buffer = reader.ReadLine(); if (!reader.EndOfMessage) { switch (BoundaryChecker.CheckBoundary(buffer, boundary)) { case EBoundaryType.NotBoundary: { byte[] data = MailMessageRFCDecoder.DecodeFromBase64(buffer); this.ContentWriter.Write(data); goto Label_0000; } case EBoundaryType.Final: this.RaiseFinalBoundaryReached(); break; } } }
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)); }