Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private string ImgTagEvel(Match m)
        {
            string src = m.Groups["src"].Value;
            //var fn
            MHTAsset asset = currentContainer.Assets[src];

            return(currentContainer.AssetsNameConvision(asset));
        }
Exemplo n.º 3
0
        public void CopyTo(MHTAsset asset, string dest, bool overwrite = false)
        {
            string src = GetCacheFile(asset);

            if (overwrite == false && File.Exists(dest))
            {
                return;
            }
            File.Copy(src, dest, overwrite);
        }
Exemplo n.º 4
0
        public string GetCacheFile(MHTAsset asset, bool force = false)
        {
            string fn = Path.Combine(CacheDir, asset.Hash);

            if (false == File.Exists(fn) || force)
            {
                using (FileStream file = File.Open(fn, FileMode.Create, FileAccess.Write))
                    file.Write(asset.Bytes, 0, asset.Bytes.Length);
            }

            return(fn);
        }
Exemplo n.º 5
0
        public static MHTAsset FromPart(MIMEPart part)
        {
            var asset = new MHTAsset();

            try
            {
                asset.Raw      = part.Content;
                asset.Type     = part.MediaType;
                asset.Location = part.Header["Content-Location"];
                asset.Encoding = part.Header["Content-Transfer-Encoding"];
            } catch (Exception ex)
            {
                throw new Exception("不能将 MIMEPart 解析为 Asset", ex);
            }

            return(asset);
        }