public MailboxEntry Build() { var mbe = new MailboxEntry { EntityId = _ind, Body = _body ?? string.Empty, CreatedAt = _createdAt.ToTS(), Subject = _subject ?? string.Empty, MessageId = _messageId ?? string.Empty }; if (_viewedAt.HasValue) { mbe.ViewedAt = _viewedAt.Value.ToTS(); } if (_sender != null) { mbe.Sender = _sender; } if (_recipients != null) { mbe.Recipients.Add(_recipients); } return(mbe); }
public void Init() { _Id = 1; //_Port = 995; _Port = 110; _UseSSL = false; _Server = "mail.bugnetproject.com"; _Username = "******"; _Password = "******"; _BodyTemplate = "{0} {1} {2}"; _InlineAttachedPictures = false; _ReportingUserName = "******"; _DeleteAllMessages= false; _ProcessAttachments = false; _entry = new MailboxEntry(); //_entry.AttachmentFileNames.Clear(); List<Project> p = Project.GetAllProjects(); List<IssueType> issT = IssueType.GetIssueTypesByProjectId(p[0].Id); // _entry.ProjectMailbox = new ProjectMailbox("*****@*****.**", p[0].Id, "Admin", "", issT[0].Id); }
public void Init() { _Id = 1; //_Port = 995; _Port = 110; _UseSSL = false; _Server = "mail.bugnetproject.com"; _Username = "******"; _Password = "******"; _BodyTemplate = "{0} {1} {2}"; _InlineAttachedPictures = false; _ReportingUserName = "******"; _DeleteAllMessages = false; _ProcessAttachments = false; _entry = new MailboxEntry(); //_entry.AttachmentFileNames.Clear(); List <Project> p = Project.GetAllProjects(); List <IssueType> issT = IssueType.GetIssueTypesByProjectId(p[0].Id); // _entry.ProjectMailbox = new ProjectMailbox("*****@*****.**", p[0].Id, "Admin", "", issT[0].Id); }
// Token: 0x06000B56 RID: 2902 RVA: 0x00024249 File Offset: 0x00022449 public RecipientOrOrganizationIdParameter(MailboxEntry storeMailboxEntry) { this.RecipientParameter = new MailboxIdParameter(storeMailboxEntry); }
public StoreMailboxIdParameter(MailboxEntry mailbox) : this(mailbox.Identity) { }
internal override IEnumerable <T> GetObjects <T>(ObjectId rootId, IConfigDataProvider session, OptionalIdentityData optionalData, out LocalizedString?notFoundReason) { if (!typeof(MailboxEntry).IsAssignableFrom(typeof(T))) { throw new ArgumentException(Strings.ErrorInvalidType(typeof(T).Name), "type"); } if (session == null) { throw new ArgumentNullException("session"); } if (rootId == null) { throw new ArgumentNullException("rootId"); } if (!(session is MapiAdministrationSession)) { throw new ArgumentException(Strings.ErrorInvalidType(typeof(MapiAdministrationSession).Name), "session"); } if (string.IsNullOrEmpty(this.displayName) && null == base.MapiObjectId) { throw new InvalidOperationException(Strings.ErrorOperationOnInvalidObject); } notFoundReason = null; List <T> list = new List <T>(); Guid mailboxGuid = Guid.Empty; if (base.MapiObjectId != null) { mailboxGuid = ((MailboxId)base.MapiObjectId).MailboxGuid; } QueryFilter filter = new MailboxContextFilter(mailboxGuid, this.flags); try { IEnumerable <T> enumerable = session.FindPaged <T>(filter, rootId, true, null, 0); if (null != base.MapiObjectId) { bool flag = Guid.Empty != ((MailboxId)base.MapiObjectId).MailboxGuid; bool flag2 = !string.IsNullOrEmpty(((MailboxId)base.MapiObjectId).MailboxExchangeLegacyDn); if (flag || flag2) { foreach (T t in enumerable) { IConfigurable configurable = t; MailboxEntry mailboxEntry = (MailboxEntry)configurable; if (flag && mailboxEntry.Identity.MailboxGuid == ((MailboxId)base.MapiObjectId).MailboxGuid) { list.Add((T)((object)mailboxEntry)); } else if (flag2 && string.Equals(mailboxEntry.Identity.MailboxExchangeLegacyDn, ((MailboxId)base.MapiObjectId).MailboxExchangeLegacyDn, StringComparison.OrdinalIgnoreCase)) { list.Add((T)((object)mailboxEntry)); } } } } if (list.Count == 0 && typeof(MailboxStatistics).IsAssignableFrom(typeof(T)) && !string.IsNullOrEmpty(this.displayName)) { foreach (T t2 in enumerable) { IConfigurable configurable2 = t2; MailboxStatistics mailboxStatistics = (MailboxStatistics)configurable2; if (string.Equals(this.displayName, mailboxStatistics.DisplayName, StringComparison.OrdinalIgnoreCase)) { list.Add((T)((object)mailboxStatistics)); } } } } catch (MapiObjectNotFoundException) { } return(list); }
/// <summary> /// Reads the mail. /// </summary> public MailboxReaderResult ReadMail() { var result = new MailboxReaderResult(); IList <Project> projects = new List <Project>(); LogInfo("MailboxReader: Begin read mail."); try { using (var pop3Client = new POP3_Client()) { // configure the logger pop3Client.Logger = new Logger(); pop3Client.Logger.WriteLog += LogPop3Client; // connect to the server pop3Client.Connect(Config.Server, Config.Port, Config.UseSsl); // authenticate pop3Client.Login(Config.Username, Config.Password); // process the messages on the server foreach (POP3_ClientMessage message in pop3Client.Messages) { var mailHeader = Mail_Message.ParseFromByte(message.HeaderToByte()); if (mailHeader != null) { var messageFrom = string.Empty; if (mailHeader.From.Count > 0) { messageFrom = string.Join("; ", mailHeader.From.ToList().Select(p => p.Address).ToArray()).Trim(); } var recipients = mailHeader.To.Mailboxes.Select(mailbox => mailbox.Address).ToList(); if (mailHeader.Cc != null) { recipients.AddRange(mailHeader.Cc.Mailboxes.Select(mailbox => mailbox.Address)); } if (mailHeader.Bcc != null) { recipients.AddRange(mailHeader.Bcc.Mailboxes.Select(mailbox => mailbox.Address)); } // loop through the mailboxes foreach (var address in recipients) { var pmbox = ProjectMailboxManager.GetByMailbox(address); // cannot find the mailbox skip the rest if (pmbox == null) { LogWarning(string.Format("MailboxReader: could not find project mailbox: {0} skipping.", address)); continue; } var project = projects.FirstOrDefault(p => p.Id == pmbox.ProjectId); if (project == null) { project = ProjectManager.GetById(pmbox.ProjectId); // project is disabled skip if (project.Disabled) { LogWarning(string.Format("MailboxReader: Project {0} - {1} is flagged as disabled skipping.", project.Id, project.Code)); continue; } projects.Add(project); } var entry = new MailboxEntry { Title = mailHeader.Subject.Trim(), From = messageFrom, ProjectMailbox = pmbox, Date = mailHeader.Date, Project = project, Content = "Email Body could not be parsed." }; var mailbody = Mail_Message.ParseFromByte(message.MessageToByte()); if (string.IsNullOrEmpty(mailbody.BodyHtmlText)) // no html must be text { entry.Content = mailbody.BodyText.Replace("\n\r", "<br/>").Replace("\r\n", "<br/>").Replace("\r", ""); } else { //TODO: Enhancements could include regular expressions / string matching or not matching // for particular strings values in the subject or body. // strip the <body> out of the message (using code from below) var bodyExtractor = new Regex("<body.*?>(?<content>.*)</body>", RegexOptions.IgnoreCase | RegexOptions.Singleline); var match = bodyExtractor.Match(mailbody.BodyHtmlText); var emailContent = match.Success && match.Groups["content"] != null ? match.Groups["content"].Value : mailbody.BodyHtmlText; entry.Content = emailContent.Replace("<", "<").Replace(">", ">"); entry.IsHtml = true; } if (Config.ProcessAttachments && project.AllowAttachments) { foreach (var attachment in mailbody.GetAttachments(Config.ProcessInlineAttachedPictures).Where(p => p.ContentType != null)) { entry.MailAttachments.Add(attachment); } } //save this message SaveMailboxEntry(entry); // add the entry if the save did not throw any exceptions result.MailboxEntries.Add(entry); LogInfo(string.Format( "MailboxReader: Message #{0} processing finished, found [{1}] attachments, total saved [{2}].", message.SequenceNumber, entry.MailAttachments.Count, entry.AttachmentsSavedCount)); // delete the message?. if (!Config.DeleteAllMessages) { continue; } try { message.MarkForDeletion(); } catch (Exception) { } } } else { LogWarning(string.Format("pop3Client: Message #{0} header could not be parsed.", message.SequenceNumber)); } } } } catch (Exception ex) { LogException(ex); result.LastException = ex; result.Status = ResultStatuses.FailedWithException; } LogInfo("MailboxReader: End read mail."); return(result); }
/// <summary> /// Saves the mailbox entry. /// </summary> /// <param name="entry">The entry.</param> void SaveMailboxEntry(MailboxEntry entry) { try { //load template var body = string.Format("<div >Sent by:{1} on: {2}<br/>{0}</div>", entry.Content.Trim(), entry.From, entry.Date); if (Config.BodyTemplate.Trim().Length > 0) { var data = new Dictionary <string, object> { { "MailboxEntry", entry } }; body = NotificationManager.GenerateNotificationContent(Config.BodyTemplate, data); } var projectId = entry.ProjectMailbox.ProjectId; var mailIssue = IssueManager.GetDefaultIssueByProjectId( projectId, entry.Title.Trim(), body.Trim(), entry.ProjectMailbox.AssignToUserName, Config.ReportingUserName); if (!IssueManager.SaveOrUpdate(mailIssue)) { return; } entry.IssueId = mailIssue.Id; entry.WasProcessed = true; var project = ProjectManager.GetById(projectId); var projectFolderPath = Path.Combine(Config.UploadsFolderPath, project.UploadPath); var doc = new HtmlDocument(); doc.LoadHtml(mailIssue.Description); // load the issue body to we can process it for inline images (if exist) //If there is an attached file present then add it to the database //and copy it to the directory specified in the web.config file foreach (MIME_Entity mimeEntity in entry.MailAttachments) { string fileName; var isInline = false; var contentType = mimeEntity.ContentType.Type.ToLower(); var attachment = new IssueAttachment { Id = 0, Description = "File attached by mailbox reader", DateCreated = DateTime.Now, ContentType = mimeEntity.ContentType.TypeWithSubtype, CreatorDisplayName = Config.ReportingUserName, CreatorUserName = Config.ReportingUserName, IssueId = mailIssue.Id, ProjectFolderPath = projectFolderPath }; switch (contentType) { case "application": attachment.Attachment = ((MIME_b_SinglepartBase)mimeEntity.Body).Data; break; case "attachment": case "image": case "video": case "audio": attachment.Attachment = ((MIME_b_SinglepartBase)mimeEntity.Body).Data; break; case "message": // we need to pull the actual email message out of the entity, and strip the "content type" out so that // email programs will read the file properly var messageBody = mimeEntity.ToString().Replace(mimeEntity.Header.ToString(), ""); if (messageBody.StartsWith("\r\n")) { messageBody = messageBody.Substring(2); } attachment.Attachment = Encoding.UTF8.GetBytes(messageBody); break; default: LogWarning(string.Format("MailboxReader: Attachment type could not be processed {0}", mimeEntity.ContentType.Type)); break; } if (contentType.Equals("attachment")) // this is an attached email { fileName = mimeEntity.ContentDisposition.Param_FileName; } else if (contentType.Equals("message")) // message has no filename so we create one { fileName = string.Format("Attached_Message_{0}.eml", entry.AttachmentsSavedCount); } else { isInline = true; fileName = string.IsNullOrWhiteSpace(mimeEntity.ContentType.Param_Name) ? string.Format("untitled.{0}", mimeEntity.ContentType.SubType) : mimeEntity.ContentType.Param_Name; } attachment.FileName = fileName; var saveFile = IsAllowedFileExtension(fileName); var fileSaved = false; // can we save the file? if (saveFile) { fileSaved = IssueAttachmentManager.SaveOrUpdate(attachment); if (fileSaved) { entry.AttachmentsSavedCount++; } else { LogWarning("MailboxReader: Attachment could not be saved, please see previous logs"); } } if (!entry.IsHtml || !isInline) { continue; } if (string.IsNullOrWhiteSpace(mimeEntity.ContentID)) { continue; } var contentId = mimeEntity.ContentID.Replace("<", "").Replace(">", "").Replace("[", "").Replace("]", ""); // this is pretty greedy but since people might be sending screenshots I doubt they will send in dozens of images // embedded in the email. one would hope foreach (var node in doc.DocumentNode.SelectNodes(XpathElementCaseInsensitive("img")).ToList()) { var attr = node.Attributes.FirstOrDefault(p => p.Name.ToLowerInvariant() == "src");// get the src attribute if (attr == null) { continue; // image has no src attribute } if (!attr.Value.Contains(contentId)) { continue; // is the attribute value the content id? } // swap out the content of the parent node html will our link to the image var anchor = string.Format("<span class='inline-mail-attachment'>Inline Attachment: <a href='DownloadAttachment.axd?id={0}' target='_blank'>{1}</a></span>", attachment.Id, fileName); // for each image in the body if the file was saved swap out the inline link for a link to the saved attachment // otherwise blank out the content link so we don't get a missing image link node.ParentNode.InnerHtml = fileSaved ? anchor : ""; } mailIssue.Description = doc.DocumentNode.InnerHtml; mailIssue.LastUpdateUserName = mailIssue.OwnerUserName; mailIssue.LastUpdate = DateTime.Now; IssueManager.SaveOrUpdate(mailIssue); } } catch (Exception ex) { LogException(ex); throw; } }
// Token: 0x06000A5D RID: 2653 RVA: 0x000229AB File Offset: 0x00020BAB public GeneralMailboxIdParameter(MailboxEntry storeMailboxEntry) : base(storeMailboxEntry) { }
// Token: 0x06000A51 RID: 2641 RVA: 0x000228DE File Offset: 0x00020ADE public MailboxIdParameter(MailboxEntry storeMailboxEntry) : this((storeMailboxEntry == null) ? null : storeMailboxEntry.Identity) { }
public LogonableObjectIdParameter(MailboxEntry storeMailboxEntry) : base(storeMailboxEntry) { }
private bool ProcessNewIssue(List <string> recipients, POP3_ClientMessage message, Mail_Message mailHeader, IList <Project> projects, MailboxReaderResult result) { var messageFrom = string.Empty; if (mailHeader.From.Count > 0) { messageFrom = string.Join("; ", mailHeader.From.ToList().Select(p => p.Address).ToArray()).Trim(); } bool processed = false; // loop through the mailboxes foreach (var address in recipients) { var pmbox = ProjectMailboxManager.GetByMailbox(address); // cannot find the mailbox skip the rest if (pmbox == null) { LogWarning(string.Format("MailboxReader: could not find project mailbox: {0} skipping.", address)); continue; } var project = projects.FirstOrDefault(p => p.Id == pmbox.ProjectId); if (project == null) { project = ProjectManager.GetById(pmbox.ProjectId); // project is disabled skip if (project.Disabled) { LogWarning(string.Format("MailboxReader: Project {0} - {1} is flagged as disabled skipping.", project.Id, project.Code)); continue; } projects.Add(project); } var entry = new MailboxEntry { Title = mailHeader.Subject.Trim(), From = messageFrom, ProjectMailbox = pmbox, Date = mailHeader.Date, Project = project, Content = "Email Body could not be parsed." }; var mailbody = Mail_Message.ParseFromByte(message.MessageToByte()); bool isHtml; List <MIME_Entity> attachments = null; string content = GetMessageContent(mailbody, project, out isHtml, ref attachments); entry.Content = content; entry.IsHtml = isHtml; foreach (var attachment in attachments) { entry.MailAttachments.Add(attachment); } //save this message Issue issue = SaveMailboxEntry(entry); //send notifications for the new issue SendNotifications(issue); // add the entry if the save did not throw any exceptions result.MailboxEntries.Add(entry); processed = true; } return(processed); }