Exemple #1
0
        internal static bool ResubmitApprovedMessage(MessageItem messageItem, TransportMailItem transportMailItem, string approverAddress)
        {
            DateTime   utcNow     = DateTime.UtcNow;
            HeaderList headerList = (transportMailItem.RootPart != null) ? transportMailItem.RootPart.Headers : null;

            if (!ModerationHelper.RestoreOriginalMessage(messageItem, transportMailItem, TraceHelper.ModeratedTransportTracer, TraceHelper.MessageProbeActivityId))
            {
                return(false);
            }
            transportMailItem.RootPart.Headers.RemoveAll("X-MS-Exchange-Organization-Approval-Approved");
            TextHeader textHeader = (TextHeader)Header.Create("X-MS-Exchange-Organization-Approval-Approved");

            textHeader.Value = (string)transportMailItem.Recipients[0].Email;
            foreach (MailRecipient mailRecipient in transportMailItem.Recipients)
            {
                if (mailRecipient.Status == Status.Ready)
                {
                    textHeader.Value = (string)mailRecipient.Email;
                    break;
                }
            }
            transportMailItem.RootPart.Headers.AppendChild(textHeader);
            if (transportMailItem.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Moderation-SavedArrivalTime") == null)
            {
                Header header = transportMailItem.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-OriginalArrivalTime");
                string value  = null;
                if (header != null)
                {
                    value = header.Value;
                }
                if (!string.IsNullOrEmpty(value))
                {
                    transportMailItem.RootPart.Headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-Moderation-SavedArrivalTime", value));
                }
            }
            TextHeader textHeader2     = (TextHeader)Header.Create("X-Moderation-Data");
            ExDateTime?valueAsNullable = messageItem.GetValueAsNullable <ExDateTime>(MessageItemSchema.ApprovalDecisionTime);

            if (valueAsNullable != null)
            {
                textHeader2.Value = valueAsNullable.ToString();
                transportMailItem.RootPart.Headers.AppendChild(textHeader2);
            }
            if (headerList != null)
            {
                Header[] array = headerList.FindAll(HeaderId.Received);
                foreach (Header header2 in array)
                {
                    Header header3 = Header.Create(HeaderId.Received);
                    header2.CopyTo(header3);
                    transportMailItem.RootPart.Headers.PrependChild(header3);
                }
            }
            transportMailItem.RootPart.Headers.RemoveAll("X-MS-Exchange-Organization-OriginalArrivalTime");
            transportMailItem.RootPart.Headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-OriginalArrivalTime", Util.FormatOrganizationalMessageArrivalTime(utcNow)));
            transportMailItem.UpdateDirectionalityAndScopeHeaders();
            transportMailItem.UpdateCachedHeaders();
            MessageTrackingLog.TrackReceiveForApprovalRelease(transportMailItem, approverAddress, messageItem.InternetMessageId);
            return(true);
        }
        private void SendApprovalRequest(ApprovalRequestWriter writer, ICollection <RoutingAddress> p1DecisionMakers, CultureInfo cultureInfo, string messageId, byte[] corelationBlob)
        {
            IList <RoutingAddress> decisionMakers = this.initiationMessage.DecisionMakers;

            byte[] conversationIndex = this.initiationMessageItem.ConversationIndex;
            (string)this.initiationMessage.Requestor;
            using (MessageItemApprovalRequest messageItemApprovalRequest = this.requestCreate(this.mbxTransportMailItem))
            {
                messageItemApprovalRequest.SetSender(this.approvalRequestSender);
                foreach (RoutingAddress routingAddress in decisionMakers)
                {
                    bool flag = p1DecisionMakers == null || p1DecisionMakers.Contains(routingAddress);
                    messageItemApprovalRequest.AddRecipient(routingAddress, flag);
                    InitiationProcessor.diag.TraceDebug <RoutingAddress, bool>(0L, "Added recipient '{0}' with promote to P1={1}.", routingAddress, flag);
                }
                CultureInfo cultureInfo2;
                if (!writer.WriteSubjectAndBody(messageItemApprovalRequest, cultureInfo, out cultureInfo2))
                {
                    InitiationProcessor.diag.TraceError <ApprovalRequestWriter>(0L, "Approval request body cannot be written with writer {0}", writer);
                }
                messageItemApprovalRequest.ApprovalRequestor = this.initiationMessage.Requestor;
                messageItemApprovalRequest.MessageItem[ItemSchema.NormalizedSubject] = this.initiationMessageItem.ConversationTopic;
                messageItemApprovalRequest.MessageItem.Importance = this.initiationMessageItem.Importance;
                messageItemApprovalRequest.MessageItem.References = InitiationProcessor.ConstructApprovalRequestReferences(this.initiationMessageItem);
                ConversationIndex o = ConversationIndex.CreateFromParent(conversationIndex);
                if (!ConversationIndex.Empty.Equals(o))
                {
                    messageItemApprovalRequest.MessageItem.ConversationIndex = o.ToByteArray();
                }
                if (cultureInfo2 != null)
                {
                    InitiationProcessor.diag.TraceDebug <CultureInfo>(0L, "Approval request written in {0}", cultureInfo2);
                    messageItemApprovalRequest.MessageItem[MessageItemSchema.MessageLocaleId] = cultureInfo2.LCID;
                }
                foreach (Attachment attachment in this.initiationMessage.EmailMessage.Attachments)
                {
                    messageItemApprovalRequest.AddAttachment(attachment, this.mbxTransportMailItem.ADRecipientCache.ADSession);
                }
                if (this.initiationMessage.EmailMessage.RootPart != null && this.initiationMessage.EmailMessage.RootPart.Headers != null)
                {
                    HeaderList headers = this.initiationMessage.EmailMessage.RootPart.Headers;
                    Header[]   array   = headers.FindAll("X-MS-Exchange-Inbox-Rules-Loop");
                    if (array != null && array.Length > 0)
                    {
                        string[] array2 = new string[array.Length];
                        for (int i = 0; i < array.Length; i++)
                        {
                            array2[i] = array[i].Value;
                        }
                        messageItemApprovalRequest.MessageItem.SafeSetProperty(MessageItemSchema.XLoop, array2);
                    }
                }
                InitiationProcessor.AddVotingToApprovalRequest(messageItemApprovalRequest, this.initiationMessage.VotingActions, cultureInfo2);
                messageItemApprovalRequest.Send(messageId, corelationBlob, this.mbxTransportMailItem);
            }
        }