Example #1
0
        public void Open(string filepath = null)
        {
            if (filepath == null)
            {
                var dialog = new OpenFileDialog
                {
                    CheckFileExists  = true,
                    Filter           = "MHT 文件格式(*.mht)|*.mht",
                    InitialDirectory = Directory.GetCurrentDirectory()
                };
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                filepath = dialog.FileName;
            }

            var          file    = new FileStream(filepath, FileMode.Open, FileAccess.Read);
            var          reader  = new StreamReader(file);
            string       content = reader.ReadToEnd();
            MHTContainer mht     = MHTContainer.ParseContent(content);
            MSGContainer msg     = MSGContainer.FromMHT(mht);

            MSG = msg;

            new MSGFormater().Format(msg);
            labelMessageTarget.Text = "消息对象: " + msg.To;

            BindDataList(msg.Messages);
        }
Example #2
0
        public static MSGContainer FromMHT(MHTContainer mht)
        {
            var container = new MSGContainer();
            //container.AssetsFileGetter = mht.GetAssetFile;
            //container.AssetsGetter = loc => MHTAsset.FromPart(mht.Locations[loc]);
            // 设置Assets列表
            var assets = new Dictionary <string, MHTAsset>();

            foreach (var part in mht.Locations)
            {
                try
                {
                    assets[part.Key] = MHTAsset.FromPart(part.Value);
                } catch
                {
                }
            }
            container.Assets = assets;

            string msgs = mht.Parts[1].Content;             // 消息部分
            // 解析
            var reader = new StringReader(msgs);

            var parser = new MSGMHTParser(reader);

            while (parser.MoveNext())
            {
                container.Messages.Add(parser.Current);
            }
            container.To = parser.To;
            return(container);
        }
Example #3
0
 public static void Main(string[] args)
 {
     var    file    = new FileStream("msg.mht", FileMode.Open, FileAccess.Read);
     var    reader  = new StreamReader(file);
     string content = reader.ReadToEnd();
     //var part = MIMEPart.ParseContent(content);
     MHTContainer mht = MHTContainer.ParseContent(content);
     MSGContainer msg = MSGContainer.FromMHT(mht);
 }
Example #4
0
        public static void ExportBy(MSGContainer container, string name, string filename = null)
        {
            if (!Exporters.ContainsKey(name))
            {
                throw new Exception(name + " 导出器未找到");
            }
            Type type = Exporters[name];

            var exporter = (MSGExporter)Activator.CreateInstance(type, container);

            ;

            exporter.ExportTo(filename);
        }
Example #5
0
        public void Format(MSGContainer container)
        {
            currentContainer = container;
            container.AssetsNameConvision = a =>
            {
                string fn  = a.Hash;
                string ext = ExtTagRegex.Match(a.Type).Groups["ext"].Value;
                fn += "." + ext;
                return(Path.Combine(ImageBaseDirectory, fn));
            };

            foreach (MSGContent msg in container.Messages)
            {
                FormatContent(msg);
            }
        }
 public SQLiteExporter(MSGContainer msg) : base(msg)
 {
     Filter        = "SQLite database|*.sqlite";
     FileExtension = "sqlite";
 }
Example #7
0
 public MSGExporter(MSGContainer msg)
 {
     MSG    = msg;
     Filter = "All Files|*.*";
 }
Example #8
0
 public JSONExporter(MSGContainer msg) : base(msg)
 {
     FileExtension = "json";
     Filter        = "JSON|*.json";
 }