public IActionResult Update(string emailUser, [FromBody] EmailEntry emailEntry) { IEmailEntry existingItem = _emailDatabase.Find(emailUser); if (existingItem == null) { return(NotFound()); } bool updated = false; IEmailEntry proxyEmailEntry = new ProxyEmailEntry(existingItem); foreach (PropertyInfo info in emailEntry.GetType().GetProperties()) { object newValue = info.GetValue(emailEntry); if (newValue != null) { info.SetValue(proxyEmailEntry, newValue); updated = true; } } if (updated) { _emailDatabase.Update(existingItem); } return(new ObjectResult(existingItem) { StatusCode = StatusCodes.Status200OK, }); }
/// <summary> /// Checks whether we should forward the receiving email. /// </summary> /// <param name="email">The email.</param> /// <returns> /// Whether the email should be forwarded to the relay email /// </returns> public bool ShouldForward(string email) { IEmailEntry emailEntry = emailEntryCache.Get(email); if (emailEntry != null) { return(!emailEntry.Blacklisted); } return(true); }
public IActionResult Get(string emailUser) { IEmailEntry emailEntry = _emailDatabase.Find(emailUser); if (emailEntry == null) { return(NotFound()); } else { return(new ObjectResult(emailEntry) { StatusCode = StatusCodes.Status200OK, }); } }
public IActionResult Create([FromBody] EmailEntry emailEntry) { IEmailEntry existingItem = _emailDatabase.Find(emailEntry.EmailUser); if (existingItem == null) { _emailDatabase.Insert(emailEntry); return(new ObjectResult(emailEntry) { StatusCode = StatusCodes.Status201Created }); } else { return(Conflict()); } }
public IActionResult Delete(string emailUser) { IEmailEntry emailEntry = _emailDatabase.Find(emailUser); if (emailEntry == null) { return(NoContent()); } else { _emailDatabase.Delete(emailEntry); return(new ObjectResult(emailEntry) { StatusCode = StatusCodes.Status200OK, }); } }
public ProxyEmailEntry(IEmailEntry backingEntry) { _backingEntry = backingEntry; }
/// <inheritdoc/> public void Delete(IEmailEntry emailEntry) { _connection?.Delete(emailEntry); }
/// <inheritdoc/> public void Update(IEmailEntry emailEntry) { _connection?.Update(emailEntry); }
/// <inheritdoc/> public void Insert(IEmailEntry emailEntry) { _connection?.Insert(emailEntry); }
/// <summary> /// Forwards the email to the relay email address. /// </summary> /// <param name="mimeMessage">The MIME message.</param> public void ForwardEmail(MimeMessage mimeMessage) { Metadata metadata = MetadataFactory.GenerateFrom(mimeMessage); // Add tags to the subject string subject = mimeMessage.Subject; IEmailEntry emailEntry = emailEntryCache.Get(toCache.Get(mimeMessage)); if (!string.IsNullOrEmpty(emailEntry?.Tag)) { metadata.Tag = emailEntry.Tag; subject = $"[{emailEntry.Tag}] {subject}"; } Email email = new Email( new System.Net.Mail.MailAddress(_options.GetSender()), new System.Net.Mail.MailAddress(_options.RelayEmail)) { Subject = subject, }; foreach (MimeEntity mimeEntity in mimeMessage.BodyParts) { if (mimeEntity.IsAttachment) { if (!(mimeEntity is MimePart mimePart)) { continue; } Attachment temporaryAttachment; using (MemoryStream memoryStream = new MemoryStream()) { mimePart.Content.DecodeTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); temporaryAttachment = new TemporaryAttachment(memoryStream) { DisplayFileName = mimePart.FileName, ContentType = mimePart.ContentType.MimeType, Encoding = mimePart.ContentTransferEncoding.GetRaw(), }; } email.Attachments.Add(temporaryAttachment); } else if (mimeEntity is TextPart textPart) { string text = textPart.Text; if (textPart.ContentType.MimeType == Constants.TextMimeType) { text = MetadataSerializer.SerializeForText(metadata, text); } else if (textPart.ContentType.MimeType == Constants.HtmlMimeType) { text = MetadataSerializer.SerializeForHtml(metadata, text); } email.TextContents.Add( new Text() { RawText = text, MimeType = textPart.ContentType.MimeType, Charset = textPart.ContentType.Charset, }); } } _sender.SendEmail(email); emailEntryCache.Clear(); toCache.Clear(); }