private void CreateScriptParts(Message message, string baseUrl)
        {
            var html = message.HTMLBody;

            //unlikey to have same js multiple times...
            foreach (Match m in Patterns.ScriptPattern.Matches(html))
            {
                var scriptUrl         = m.Groups["Url"].Value;
                var absoluteScriptUrl = _webRequestHelper.GetAbsoluteUrl(baseUrl, scriptUrl);
                var id = Guid.NewGuid().ToString();

                var scriptPart = message.BodyPart.AddBodyPart();
                scriptPart.ContentMediaType        = "text/javascript";
                scriptPart.Charset                 = "iso-8859-1";
                scriptPart.ContentTransferEncoding = "quoted-printable";
                scriptPart.Fields["urn:schemas:mailheader:content-id"].Value          = id;
                scriptPart.Fields["urn:schemas:mailheader:content-disposition"].Value = "inline";
                scriptPart.Fields.Update();

                var stream        = scriptPart.GetDecodedContentStream();
                var scriptStream  = (IStream)stream;
                var scriptContent = _webRequestHelper.GetContent(absoluteScriptUrl);
                scriptStream.Write(scriptContent.Content, scriptContent.Content.Length, IntPtr.Zero);
                stream.Flush();
                stream.Close();

                message.HTMLBody = message.HTMLBody.Replace(scriptUrl, "cid:" + id);
            }
        }
Exemple #2
0
        private void CreateParts(List <LinkedResource> resources, Dictionary <string, string> urlCheck, string baseUrl, StringBuilder htmlString, Regex pattern)
        {
            foreach (Match m in pattern.Matches(htmlString.ToString()))
            {
                var url         = m.Groups["Url"].Value;
                var absoluteUrl = _webRequestHelper.GetAbsoluteUrl(baseUrl, url);

                if (!urlCheck.ContainsKey(absoluteUrl))
                {
                    var id = Guid.NewGuid().ToString();

                    var result = _webRequestHelper.GetContent(absoluteUrl);

                    var ms = new MemoryStream(result.Content);
                    var lr = new LinkedResource(ms, new ContentType(result.ContentType))
                    {
                        ContentId = id, TransferEncoding = TransferEncoding.Base64
                    };
                    resources.Add(lr);

                    htmlString.Replace(url, "cid:" + id);

                    urlCheck.Add(absoluteUrl, result.FileName);
                }
            }
        }