diff --git a/Toxy.Test/CnmEmailParserTest.cs b/Toxy.Test/CnmEmailParserTest.cs deleted file mode 100644 index 99d72ff..0000000 --- a/Toxy.Test/CnmEmailParserTest.cs +++ /dev/null @@ -1,31 +0,0 @@ -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Toxy.Test -{ - [TestFixture] - public class CnmEmailParserTest - { - - [Test] - public void ReadCnmTest() - { - string path = TestDataSample.GetCNMPath("Y0B6E8H2.CNM"); - ParserContext context = new ParserContext(path); - IEmailParser parser = ParserFactory.CreateEmail(context) as IEmailParser; - ToxyEmail email = parser.Parse(); - Assert.IsNotNullOrEmpty(email.From); - Assert.AreEqual(1, email.To.Count); - Assert.AreEqual("Тюльпаны ", email.From); - Assert.AreEqual("", email.To[0]); - - Assert.AreEqual("Тюльпаны", email.Subject); - Assert.IsTrue(email.TextBody.StartsWith("Тел: 960-51-57;Продажа тюльпанов")); - Assert.IsTrue(email.HtmlBody.StartsWith(" 3) - throw new ApplicationException("Can't found time"); - - string str = r.ReadLine(); - int semicolon = str.IndexOf(';'); - if (semicolon != -1) - { - if ((semicolon + 1) == str.Length) - continue; - else - str = str.Substring(semicolon + 1); - } - str = str.Trim(); - if (DateTime.TryParse(str, out dt)) - break; - } - } - } - catch - { - dt = DateTime.MinValue; - } - - Time = dt; - File = source; - } - - public FileInfo File { get; private set; } - public DateTime Time { get; private set; } - - public Stream TextHtml { get; set; } - public string TextPlain { get; set; } - public string Headers { get; set; } - public List Files { get; set; } - public string From { get; set; } - public string To { get; set; } - public string Subject { get; set; } - public string Errors { get; set; } - - StringBuilder _headersBuffer; - StringBuilder _errorsBuffer; - - public bool HasErrors - { - get - { - return (Errors != null); - } - } - - public bool IsParsed - { - get - { - return (Headers != null); - } - } - - public void Parse() - { - if (File != null) - using (FileStream s = File.OpenRead()) - Parser.Parse(this, s); - } - - #region IMessageConstructor Members - - public void AddHeader(string name, string value) - { - if (_headersBuffer == null) - _headersBuffer = new StringBuilder(); - - _headersBuffer.AppendLine(string.Format("{0}: {1}", name, value)); - - if (name.EqualsIgnoreCase("from")) - From = value.Trim(); - else if (name.EqualsIgnoreCase("to")) - To = value.Trim(); - else if (name.EqualsIgnoreCase("subject")) - Subject = value.Trim(); - } - - public IAttachmentConstructor GetAttachmentConstructor(HeaderCollection headers) - { - AttachmentFormat format = headers.GetAttachmentFormat(); - bool requiredBody = false; - Stream stream = null; - - if (format == AttachmentFormat.Html) - { - requiredBody = true; - stream = new MemoryStream(); - } - else if (format == AttachmentFormat.PlainText) - { - requiredBody = true; - stream = new MemoryStream(); - } - - Attachment att = new Attachment( - headers, - stream, - new DecoderSelector(), - requiredBody, - (err, comm) => ErrorHandler(err, comm)); - - return att; - } - - public void CompleteAttachment(IAttachmentConstructor att) - { - Attachment a = (Attachment)att; - try - { - if (a.IsAttachmentMessageBody) - { - if (a.IsAttachmentMessageBodyHtml) - TextHtml = new MemoryStream(a.ToArray()); - else if (a.IsAttachmentMessageBodyTextPlain) - TextPlain = a.Headers.GetEncoding(1251).GetString(a.ToArray()).Trim(); - } - else - { - if (!string.IsNullOrEmpty(a.Headers.MimeContentName)) - { - if (Files == null) - Files = new List(); - - Files.Add(a); - } - } - } - finally - { - a.CloseInnerStream(); - } - } - - public void CompleteConstruction() - { - if (_headersBuffer != null) - { - Headers = _headersBuffer.ToString().TrimEnd(); - _headersBuffer = null; - } - if (_errorsBuffer != null) - { - Errors = _errorsBuffer.ToString().TrimEnd(); - _errorsBuffer = null; - } - } - - public void ErrorHandler(ParserError err, string comment) - { - if (_errorsBuffer == null) - _errorsBuffer = new StringBuilder(); - - _errorsBuffer.AppendLine(string.Format("{0}: {1}", err, comment)); - } - - #endregion - } -} diff --git a/ToxyFramework/ParserFactory.cs b/ToxyFramework/ParserFactory.cs index 927a148..46d5339 100644 --- a/ToxyFramework/ParserFactory.cs +++ b/ToxyFramework/ParserFactory.cs @@ -73,9 +73,7 @@ static ParserFactory() parserMapping.Add(".docx", typeDocx); #endregion - var typeRtf = new List(); - typeRtf.Add(typeof(RTFTextParser)); - parserMapping.Add(".rtf", typeRtf); + var typePdf = new List(); typePdf.Add(typeof(PDFTextParser)); @@ -94,17 +92,13 @@ static ParserFactory() typeEml.Add(typeof(EMLTextParser)); parserMapping.Add(".eml", typeEml); - var typeCnm = new List(); - typeCnm.Add(typeof(CnmEmailParser)); - parserMapping.Add(".cnm", typeCnm); - var typeMsg = new List(); typeMsg.Add(typeof(MsgEmailParser)); typeMsg.Add(typeof(MsgTextParser)); parserMapping.Add(".msg", typeMsg); #endregion - var typeVcard= new List(); + var typeVcard = new List(); typeVcard.Add(typeof(VCardDocumentParser)); typeVcard.Add(typeof(VCardTextParser)); parserMapping.Add(".vcf", typeVcard); @@ -188,7 +182,6 @@ public static IDomParser CreateDom(ParserContext context) IDomParser parser = (IDomParser)obj; return parser; } - public static VCardDocumentParser CreateVCard(ParserContext context) { object obj = CreateObject(context, typeof(VCardDocumentParser), "CreateVCard"); diff --git a/ToxyFramework/Parsers/Email/CnmEmailParser.cs b/ToxyFramework/Parsers/Email/CnmEmailParser.cs deleted file mode 100644 index 1d9c4ae..0000000 --- a/ToxyFramework/Parsers/Email/CnmEmailParser.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.IO; - -namespace Toxy.Parsers -{ - public class CnmEmailParser : IEmailParser - { - public CnmEmailParser(ParserContext context) - { - this.Context = context; - } - public ToxyEmail Parse() - { - if (!File.Exists(Context.Path)) - throw new FileNotFoundException("File " + Context.Path + " is not found"); - - FileInfo fi = new FileInfo(Context.Path); - CnmFile reader = new CnmFile(fi); - reader.Parse(); - ToxyEmail email=new ToxyEmail(); - email.From = reader.From; - email.To = new List(reader.To.Split(';')); - email.TextBody = reader.TextPlain; - using (var sr=new StreamReader(reader.TextHtml)) - { - email.HtmlBody = sr.ReadToEnd(); - } - email.Subject = reader.Subject; - return email; - } - - public ParserContext Context - { - get; - set; - } - } -} diff --git a/ToxyFramework/Parsers/RTFTextParser.cs b/ToxyFramework/Parsers/RTFTextParser.cs deleted file mode 100644 index 24daed3..0000000 --- a/ToxyFramework/Parsers/RTFTextParser.cs +++ /dev/null @@ -1,25 +0,0 @@ -using DCSoft.RTF; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Toxy.Parsers -{ - public class RTFTextParser : PlainTextParser - { - public RTFTextParser(ParserContext context): base(context) - { - this.Context = context; - } - - public override string Parse() - { - RTFDomDocument doc = new RTFDomDocument(); - doc.Load(this.Context.Path); - if (doc.HtmlContent == null) - return doc.InnerText; - else - return doc.HtmlContent; - } - } -}