コード例 #1
0
 public override void Execute()
 {
     if (!this.ShouldExecuteOnThisStage)
     {
         return;
     }
     if (base.Context.DetectLoop())
     {
         string[] valueOrDefault = base.Context.Message.GetValueOrDefault <string[]>(MessageItemSchema.XLoop, null);
         if (valueOrDefault == null || valueOrDefault.Length != 1)
         {
             return;
         }
         base.Context.TraceDebug("Sending to Delegates even though loop was detected due to 1 XLoop header in the message.");
     }
     base.Context.TraceDebug("Delegate action: Creating message to forward.");
     using (MessageItem messageItem = RuleMessageUtils.CreateDelegateForward(base.Context.Message, base.Context.StoreSession.PreferedCulture, base.Context.DefaultDomainName, base.Context.XLoopValue, base.Context))
     {
         if (this.ShouldSubmit(messageItem))
         {
             this.SetDelegateProperties(messageItem);
             if (base.Context.PropertiesForDelegateForward != null)
             {
                 foreach (KeyValuePair <PropertyDefinition, object> keyValuePair in base.Context.PropertiesForDelegateForward)
                 {
                     base.Context.TraceDebug <PropertyDefinition, object>("Delegate action: setting {0} to {1}", keyValuePair.Key, keyValuePair.Value ?? "(null)");
                     messageItem.SetOrDeleteProperty(keyValuePair.Key, keyValuePair.Value);
                 }
             }
             messageItem.AutoResponseSuppress = AutoResponseSuppress.All;
             RuleUtil.SetRecipients(base.Context, messageItem, null, this.recipients, true);
             base.SubmitMessage(messageItem);
         }
     }
 }
コード例 #2
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);
                    }
                }
            }
        }