Beispiel #1
0
        protected string ChangeImgSrcToLocal(string html, ImageCopySettings settings, int publisherId)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            foreach (HtmlNode img in doc.DocumentNode.Descendants("img"))
            {
                try
                {
                    string newFileName = GenerateNewImageName();
                    DownloadRemoteImageFile(img.Attributes["src"].Value,
                                            GenerateFilePath(newFileName, publisherId, settings));
                    img.Attributes["src"].Value = GenerateUrl(newFileName, publisherId, settings);
                }
                catch (Exception ex)
                {
                    logger.Error("Cannot change img src to local", ex);
                }
            }

            string result = string.Empty;

            using (StringWriter writer = new StringWriter())
            {
                doc.Save(writer);
                result = writer.ToString();
            }
            return(result);
        }
Beispiel #2
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                logger.Debug("email message processing");
                string            emailBaseFolder = AppSettingsHelper.GetValueFromAppSettings(Common.Enums.AppSettingsKey.hmailServerEmailBaseFolder);
                List <string>     emailFiles      = Directory.GetFiles(emailBaseFolder, "*.eml", SearchOption.AllDirectories).ToList();
                ImageCopySettings settings        = new ImageCopySettings();
                EmailRepo         repo            = new EmailRepo();
                PublisherRepo     publisherRepo   = new PublisherRepo();
                foreach (var email in emailFiles)
                {
                    try
                    {
                        CDO.Message message = ReadMessage(email);

                        int    publisherId = GetPublisherIdFromEmail(message);
                        string emailHTML   = ChangeImgSrcToLocal(message.HTMLBody, settings, publisherId);
                        repo.AddEmail(new Common.Models.Email()
                        {
                            EmailHeaders  = GetEmailHeaders(message),
                            HTML          = emailHTML,
                            HTMLText      = emailHTML,
                            ReceivedGMT   = message.ReceivedTime.ToUniversalTime(),
                            SenderAddress = message.From,
                            SenderName    = message.Sender,
                            SubjectLine   = message.Subject,
                            Text          = message.TextBody,
                            PublisherID   = publisherId,
                            Copy          = message.CC
                        });
                        File.Delete(email);
                        publisherRepo.UpdateLastReceivedEmailDate(publisherId);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Beispiel #3
0
 protected string GenerateUrl(string fileName, int publisherId, ImageCopySettings settings)
 {
     return(Path.Combine(settings.EmailStorageBaseWebAddress, publisherId.ToString(), fileName).Replace("\\", "/"));
 }
Beispiel #4
0
 protected string GenerateFilePath(string fileName, int publisherId, ImageCopySettings settings)
 {
     return(Path.Combine(settings.EmailStorageBaseAddress, publisherId.ToString(), fileName));
 }