internal static bool SetRecipients(IRuleEvaluationContext context, MessageItem message, IList <ProxyAddress> senderAddresses, AdrEntry[] recipients, bool promoteToEnvelope) { message.Recipients.Clear(); int num = 0; foreach (AdrEntry entry in recipients) { Participant participant = RuleUtil.ParticipantFromAddressEntry(entry); if (participant != null) { if (promoteToEnvelope && RuleUtil.IsRecipientSameAsSender(senderAddresses, participant.EmailAddress)) { context.TraceDebug <string>("Skipping recipient {0} because that was the original sender.", participant.EmailAddress); } else { context.TraceDebug <Participant>("Adding recipient {0}.", participant); Recipient recipient = message.Recipients.Add(participant); recipient[ItemSchema.Responsibility] = promoteToEnvelope; num++; } } } return(num > 0); }
public override void Execute() { if (!this.ShouldExecuteOnThisStage) { return; } if (base.Context.DetectLoop()) { base.Context.TraceDebug("Forward action: Loop detected, message will not be forwarded."); return; } string argument = this.IsForwarding ? "Forward" : "Redirect"; base.Context.TraceDebug <string>("{0} action: Creating message.", argument); using (MessageItem messageItem = this.CreateMessage()) { messageItem[ItemSchema.IsAutoForwarded] = true; base.Context.CopyProperty(base.Context.Message, messageItem, ItemSchema.SpamConfidenceLevel); IList <ProxyAddress> senderProxyAddresses = base.GetSenderProxyAddresses(); if (this.IsForwarding) { base.Context.SetMailboxOwnerAsSender(messageItem); this.SetFromForMeetingMessages(messageItem); if (RuleUtil.SetRecipients(base.Context, messageItem, senderProxyAddresses, this.recipients, true)) { base.Context.TraceDebug <string>("{0} action: Submitting message.", argument); base.SubmitMessage(messageItem); base.Context.TraceDebug <string>("{0} action: Message submitted.", argument); } else { base.Context.TraceDebug <string>("{0} action: There are no recipients.", argument); } } else { messageItem.From = base.Context.Message.From; MailboxSession mailboxSession = base.Context.StoreSession as MailboxSession; PublicFolderSession publicFolderSession = base.Context.StoreSession as PublicFolderSession; string value = string.Empty; if (mailboxSession != null) { value = mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(); } else if (publicFolderSession != null) { value = publicFolderSession.MailboxPrincipal.MailboxInfo.PrimarySmtpAddress.ToString(); } if (!string.IsNullOrEmpty(value)) { messageItem[ItemSchema.ResentFrom] = value; } RuleUtil.SetRecipients(base.Context, messageItem, null, base.Context.Message.Recipients, false); if (publicFolderSession != null) { messageItem.MarkAllRecipientAsSubmitted(); } IEnumerable <Participant> enumerable = from recipient in this.recipients select RuleUtil.ParticipantFromAddressEntry(recipient); string text = base.Context.Message.TryGetProperty(ItemSchema.ResentFrom) as string; IList <Participant> list = new List <Participant>(); foreach (Participant participant in enumerable) { if (RuleUtil.IsRecipientSameAsSender(senderProxyAddresses, participant.EmailAddress) || (!string.IsNullOrEmpty(text) && string.Equals(text, participant.EmailAddress, StringComparison.OrdinalIgnoreCase))) { base.Context.TraceDebug <string>("Skipping redirectee {0} because that was the original sender or resent-from user.", participant.EmailAddress); } else { list.Add(participant); } } if (list.Count > 0) { base.Context.TraceDebug <string>("{0} action: Submitting message.", argument); base.SubmitMessage(messageItem, base.Context.Recipient, enumerable); base.Context.TraceDebug <string>("{0} action: Message submitted.", argument); } else { base.Context.TraceDebug <string>("{0} action: There are no recipients.", argument); } } } }