/// <summary> /// Return a combined collection of all recipients in routing headers (to/cc/bcc) /// </summary> /// <returns>A collection of recipients</returns> public DirectAddressCollection GetRecipientsInRoutingHeaders() { DirectAddressCollection addresses = new DirectAddressCollection(); if (this.To != null) { addresses.Add(this.To); } if (this.Cc != null) { addresses.Add(this.Cc); } if (this.Bcc != null) { addresses.Add(this.Bcc); } return(addresses); }
/// <summary> /// Enforces the trust model on an incoming message by marking /// the <c>Status</c> property of <see cref="DirectAddress"/> instances for the receivers /// </summary> /// <param name="message">The <see cref="IncomingMessage"/> to validate trust for.</param> /// <exception cref="AgentException">If this message has no signatures</exception> public void Enforce(IncomingMessage message) { if (message == null) { throw new ArgumentNullException("message"); } if (!message.HasSignatures) { throw new AgentException(AgentError.UnsignedMessage); } // // The message could have multiple signatures, including, possibly, some not by the sender // this.FindSenderSignatures(message); if (!message.HasSenderSignatures) { throw new AgentException(AgentError.MissingSenderSignature); } // // For each recipient, find at least one valid sender signature that the recipient trusts // DirectAddress sender = message.Sender; DirectAddressCollection recipients = message.DomainRecipients; foreach (DirectAddress recipient in recipients) { recipient.Status = TrustEnforcementStatus.Failed; // // First, find a signature that this recipient trusts // MessageSignature trustedSignature = this.FindTrustedSignature(message, recipient, recipient.TrustAnchors); if (trustedSignature != null) { recipient.Status = TrustEnforcementStatus.Success; // // Signature has already been verified by FindTrustedSignature! // } } }
/// <summary> /// Verify that the recipient list in the Message Envelope matches that in the message /// </summary> public bool AreAddressesInRoutingHeaders(IEnumerable <DirectAddress> addresses) { if (addresses == null) { throw new ArgumentException("addresses"); } // // Get the list of recipients as specified in the message itself // DirectAddressCollection recipientsInHeaders = this.GetRecipientsInRoutingHeaders(); foreach (DirectAddress address in addresses) { if (!recipientsInHeaders.Contains(address.Address)) { return(false); } } return(true); }
/// <summary> /// Encrypts, verifies recipient trust, and signs an RFC 5322 formatted message /// The provided sender and recipient addresses will be used instead of the header information in the <c>messageText</c>. /// </summary> /// <param name="messageText"> /// An RFC 5322 formatted message string /// </param> /// <param name="recipients"> /// An <see cref="DirectAddressCollection"/> instance specifying message recipients. /// </param> /// <param name="sender"> /// An <see cref="DirectAddress"/> instance specifying message sender /// </param> /// <returns> /// An <see cref="OutgoingMessage"/> instance containing the encrypted and trust verified message. /// </returns> public OutgoingMessage ProcessOutgoing(string messageText, DirectAddressCollection recipients, DirectAddress sender) { OutgoingMessage message = new OutgoingMessage(this.WrapMessage(messageText), recipients, sender); return(this.ProcessOutgoing(message)); }
/// <summary> /// Decrypts and verifies trust in a signed and encrypted RFC 5322 formatted message, providing a sender and recipient addresses. /// The provided sender and recipient addresses will be used instead of the header information in the <c>messageText</c>. /// </summary> /// <param name="messageText"> /// An RFC 5322 formatted message string. /// </param> /// <param name="recipients"> /// A <see cref="DirectAddressCollection"/> instance representing recipient addresses. /// </param> /// <param name="sender"> /// An <see cref="DirectAddress"/> instance representing the sender address /// </param> /// <returns> /// An <see cref="IncomingMessage"/> instance with the trust verified decrypted and verified message. /// </returns> public IncomingMessage ProcessIncoming(string messageText, DirectAddressCollection recipients, DirectAddress sender) { IncomingMessage message = new IncomingMessage(messageText, recipients, sender); return(this.ProcessIncoming(message)); }
/// <summary> /// Remove addresses from Routing headers /// </summary> /// <param name="addresses"><see cref="DirectAddressCollection"/> containing addresses to remove</param> public void RemoveFromRoutingHeaders(DirectAddressCollection addresses) { this.UpdateRoutingHeaders(addresses); }
/// <summary> /// Creates an instance from a <see cref="Message"/> instance, with explicitly assigned raw message, recipients and sender, /// which take precendece over what may be in the message object or text. /// </summary> /// <param name="message">The <see cref="Message"/> this envelopes</param> /// <param name="recipients">The <see cref="DirectAddressCollection"/> of reciepients; takes precedence over the <c>To:</c> header</param> /// <param name="sender">The <see cref="DirectAddress"/> of the sender; takes precendence over the <c>From:</c> header.</param> /// <param name="rawMessage">The RFC 5322 message string to use ae the raw message for this instance.</param> protected MessageEnvelope(Message message, string rawMessage, DirectAddressCollection recipients, DirectAddress sender) : this(message, recipients, sender) { this.RawMessage = rawMessage; }
/// <summary> /// Creates an instance from an RFC 5322 message string and explicitly assigned sender and receivers, which take precendence over what may be /// in the message headers. /// </summary> /// <param name="messageText">The RFC 5322 message string to intialize this envelope from. Stored as <c>RawMessage</c></param> /// <param name="recipients">The <see cref="DirectAddressCollection"/> of reciepients; takes precedence over the <c>To:</c> header</param> /// <param name="sender">The <see cref="DirectAddress"/> of the sender - typically the MAIL FROM in SMTP; takes precendence over the <c>From:</c> header.</param> public MessageEnvelope(string messageText, DirectAddressCollection recipients, DirectAddress sender) : this(MimeSerializer.Default.Deserialize <Message>(messageText), recipients, sender) { this.RawMessage = messageText; }
/// <summary> /// Creates an instance from an RFC 5322 format message string., specifying recipients and sender. /// </summary> /// <param name="messageText">RFC 5322 message string, signed and encrypted.</param> /// <param name="recipients">An <see cref="DirectAddressCollection"/> of recipients, takes precedence over recipients in the message</param> /// <param name="sender">Sender <see cref="DirectAddress"/>, takes precendence over the <c>To</c> field in the message.</param> public IncomingMessage(string messageText, DirectAddressCollection recipients, DirectAddress sender) : base(messageText, recipients, sender) { }
/// <summary> /// Creates an instance from a <see cref="Message"/> instance, specifying recipients and sender. /// </summary> /// <param name="message"><see cref="Message"/> instance, signed and encrypted.</param> /// <param name="recipients">An <see cref="DirectAddress"/> of recipients, takes precedence over recipients in the message</param> /// <param name="sender">Sender <see cref="DirectAddressCollection"/>, takes precendence over the <c>To</c> field in the message.</param> public IncomingMessage(Message message, DirectAddressCollection recipients, DirectAddress sender) : base(message, recipients, sender) { }
internal OutgoingMessage(Message message, string messageText, DirectAddressCollection recipients, DirectAddress sender) : base(message, recipients, sender) { }
/// <summary> /// Creates an instance from a <see cref="Message"/> instance, specifying recipients and sender. /// </summary> /// <param name="message"><see cref="Message"/> instance representing the message to be prepped for send.</param> /// <param name="recipients">An <see cref="DirectAddressCollection"/> of recipients, takes precedence over recipients in the message</param> /// <param name="rejectedRecipients">An <see cref="DirectAddressCollection"/> of rejected recipients</param> /// <param name="sender">Sender <see cref="DirectAddress"/>, takes precendence over the <c>To</c> field in the message.</param> /// <param name="usingDeliveryStatus">Indicate if message requests DeliveryStatus</param> public OutgoingMessage(Message message, DirectAddressCollection recipients, DirectAddressCollection rejectedRecipients, DirectAddress sender, bool usingDeliveryStatus) : base(message, recipients, rejectedRecipients, sender) { this.UsingDeliveryStatus = usingDeliveryStatus; }