Example #1
0
        public static ApprovalRequestWriter GetInstance(ApprovalApplicationId?applicationId, OrganizationId organizationId, InitiationMessage initiationMessage)
        {
            if (applicationId != null)
            {
                switch (applicationId.Value)
                {
                case ApprovalApplicationId.AutoGroup:
                    return(AutoGroupApprovalRequestWriter.GetInstance(initiationMessage));

                case ApprovalApplicationId.ModeratedRecipient:
                    return(ModerationApprovalRequestWriter.GetInstance(organizationId, initiationMessage));
                }
            }
            return(DefaultApprovalRequestWriter.GetInstance(initiationMessage));
        }
        private void WriteApprovalRequestBody(Body destiniationBody, DsnHumanReadableWriter writer, ApprovalInformation info, bool writePreview)
        {
            if (writePreview)
            {
                Charset outputCharset;
                bool    flag = !ModerationApprovalRequestWriter.CheckInputOutputCharsetMatch(info.Codepages, this.originalMessageBodyCharset, out outputCharset);
                if (!flag && this.TryWriteApprovalRequestBodyWithPreview(destiniationBody, writer, info, outputCharset))
                {
                    return;
                }
                ModerationApprovalRequestWriter.diag.TraceError <bool, string>((long)this.GetHashCode(), "Failed to write preview for message.  Falling back to no preview. Charset mismatch:{0}. Approval data:{1}.", flag, this.initiationMessage.ApprovalData);
                info = writer.GetApprovalRequestMessageInformation(this.initiationMessage.Subject, this.originalSenderDisplayName, this.originalToFormattedLine, this.originalCcFormattedLine, this.moderatedRecipients, false, info.Culture);
            }
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml, info.MessageCharset.Name);

            using (Stream stream = destiniationBody.OpenWriteStream(configuration))
            {
                writer.WriteHtmlModerationBody(stream, info);
            }
        }
 private void CacheDataFromOriginalMessage()
 {
     try
     {
         if (this.isOriginalMessageDataCached)
         {
             ModerationApprovalRequestWriter.diag.TraceDebug((long)this.GetHashCode(), "Original data cached.");
         }
         else
         {
             this.isOriginalMessageDataCached = true;
             ModerationApprovalRequestWriter.diag.TraceDebug((long)this.GetHashCode(), "Getting original message for cache.");
             this.CacheModeratedRecipients();
             this.originalMessageStream = this.GetOriginalMessageReadStream();
             if (this.originalMessageStream == null)
             {
                 ModerationApprovalRequestWriter.diag.TraceError(0L, "There is no original message attached in initiation message.");
             }
             else
             {
                 this.originalMimeDom = new MimeDocument();
                 this.originalMimeDom.Load(this.originalMessageStream, CachingMode.Source);
                 this.originalEmailMessage    = EmailMessage.Create(this.originalMimeDom);
                 this.originalToFormattedLine = ModerationApprovalRequestWriter.FormatRecipients(this.originalEmailMessage.To);
                 this.originalCcFormattedLine = ModerationApprovalRequestWriter.FormatRecipients(this.originalEmailMessage.Cc);
                 EmailRecipient sender = this.originalEmailMessage.Sender;
                 if (sender != null && !string.IsNullOrEmpty(sender.DisplayName))
                 {
                     if (!string.IsNullOrEmpty(sender.SmtpAddress) && this.organizationId != null && !IsInternalResolver.IsInternal(new RoutingAddress(sender.SmtpAddress), this.organizationId))
                     {
                         this.originalSenderDisplayName = sender.DisplayName + "(" + sender.SmtpAddress + ")";
                     }
                     else
                     {
                         this.originalSenderDisplayName = sender.DisplayName;
                     }
                 }
                 else
                 {
                     this.originalSenderDisplayName = (string)this.initiationMessage.Requestor;
                 }
                 this.originalMesssageBodyFormat = this.originalEmailMessage.Body.BodyFormat;
                 string  charsetName = this.originalEmailMessage.Body.CharsetName;
                 Charset charset;
                 if (!string.IsNullOrEmpty(charsetName) && Charset.TryGetCharset(charsetName, out charset) && charset.IsAvailable)
                 {
                     ModerationApprovalRequestWriter.diag.TraceDebug <string>((long)this.GetHashCode(), "original message body has charset {0}", charsetName);
                     this.originalMessageBodyCharset = charset;
                 }
                 else
                 {
                     ModerationApprovalRequestWriter.diag.TraceDebug <string>((long)this.GetHashCode(), "original message charset not valid {0}", charsetName);
                 }
                 this.hasInlineAttachment = false;
                 if (this.originalMesssageBodyFormat == Microsoft.Exchange.Data.Transport.Email.BodyFormat.Rtf)
                 {
                     if (this.originalEmailMessage.Attachments != null && this.originalEmailMessage.Attachments.Count > 0)
                     {
                         this.hasInlineAttachment = true;
                     }
                 }
                 else if (this.originalMesssageBodyFormat != Microsoft.Exchange.Data.Transport.Email.BodyFormat.Text && this.originalMesssageBodyFormat == Microsoft.Exchange.Data.Transport.Email.BodyFormat.Html && this.originalEmailMessage.Attachments != null && this.originalEmailMessage.Attachments.Count > 0)
                 {
                     foreach (Attachment attachment in this.originalEmailMessage.Attachments)
                     {
                         if (attachment.AttachHidden || attachment.AttachmentType == AttachmentType.Inline)
                         {
                             this.hasInlineAttachment = true;
                             break;
                         }
                     }
                 }
                 this.isOpaqueMessage = this.originalEmailMessage.IsOpaqueMessage;
             }
         }
     }
     catch (ExchangeDataException arg)
     {
         ModerationApprovalRequestWriter.diag.TraceError <ExchangeDataException>((long)this.GetHashCode(), "Cannot cache all data required for moderation approval request {0}", arg);
     }
 }