private void ProcessClassificationsForJournalReport(StoreDriverDeliveryEventArgsImpl argsImpl)
        {
            ClassificationSummary classificationSummary = this.GetClassificationSummary(argsImpl);

            if (classificationSummary != null && classificationSummary.IsValid && classificationSummary.IsClassified)
            {
                using (ItemAttachment itemAttachment = this.TryOpenFirstAttachment(argsImpl.ReplayItem) as ItemAttachment)
                {
                    if (itemAttachment != null)
                    {
                        using (MessageItem itemAsMessage = itemAttachment.GetItemAsMessage(StoreObjectSchema.ContentConversionProperties))
                        {
                            if (itemAsMessage != null)
                            {
                                ClassificationApplicationAgent.diag.TraceDebug <string>(0L, "Promote banner for recipient {0} on embedded message of journal report", argsImpl.MailRecipient.Email.ToString());
                                itemAsMessage[ItemSchema.IsClassified]              = classificationSummary.IsClassified;
                                itemAsMessage[ItemSchema.Classification]            = classificationSummary.DisplayName;
                                itemAsMessage[ItemSchema.ClassificationDescription] = classificationSummary.RecipientDescription;
                                itemAsMessage[ItemSchema.ClassificationGuid]        = classificationSummary.ClassificationID.ToString();
                                itemAsMessage[ItemSchema.ClassificationKeep]        = classificationSummary.RetainClassificationEnabled;
                                itemAsMessage.Save(SaveMode.NoConflictResolution);
                                itemAttachment.Save();
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public static void Pack(Signal signal, MessageItem mailMessage)
        {
            List <Item> list = new List <Item>();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream, Encoding.UTF8))
                {
                    binaryWriter.Write(1);
                    list = signal.WriteObject(binaryWriter);
                    using (TextWriter textWriter = mailMessage.Body.OpenTextWriter(BodyFormat.TextPlain))
                    {
                        textWriter.Write(Convert.ToBase64String(memoryStream.ToArray()));
                    }
                }
            }
            foreach (Item item in list)
            {
                ExchangeItem exchangeItem = item as ExchangeItem;
                if (exchangeItem != null)
                {
                    if (exchangeItem.Item.IsNew)
                    {
                        throw new ArgumentException("Item must be saved in order to attach.");
                    }
                    using (ItemAttachment itemAttachment = mailMessage.AttachmentCollection.AddExistingItem(exchangeItem.Item))
                    {
                        itemAttachment.ContentId = exchangeItem.AttachContentId.ToString();
                        itemAttachment.Save();
                    }
                }
            }
        }
 internal static void CreateAttachment(IItem parentItem, Attachment16Data attachmentData)
 {
     AirSyncDiagnostics.TraceDebug <byte>(ExTraceGlobals.RequestsTracer, null, "CreateAttachment with AttachMethod:{0}", attachmentData.Method);
     if (attachmentData.Method == 1)
     {
         if (attachmentData.Content == null)
         {
             throw new ConversionException(string.Format(" Attachment content can not be null.", new object[0]));
         }
         IStreamAttachment streamAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.Stream) as IStreamAttachment;
         AttachmentHelper.CopyCommonAttachmentProperties(streamAttachment, attachmentData);
         using (Stream contentStream = streamAttachment.GetContentStream())
         {
             contentStream.Write(attachmentData.Content, 0, attachmentData.Content.Length);
         }
         streamAttachment.Save();
     }
     else
     {
         if (attachmentData.Method != 5)
         {
             throw new ConversionException(string.Format("UnSupported Value '{0}' for Attachment Method. Only 1 & 5 is supported AttachemntType", attachmentData.Method));
         }
         ItemAttachment itemAttachment = parentItem.IAttachmentCollection.CreateIAttachment(AttachmentType.EmbeddedMessage) as ItemAttachment;
         AttachmentHelper.CopyCommonAttachmentProperties(itemAttachment, attachmentData);
         using (Stream stream = new MemoryStream(attachmentData.Content))
         {
             stream.Seek(0L, SeekOrigin.Begin);
             InboundConversionOptions inboundConversionOptions = AirSyncUtility.GetInboundConversionOptions();
             inboundConversionOptions.ClearCategories = false;
             try
             {
                 using (Item item = itemAttachment.GetItem())
                 {
                     ItemConversion.ConvertAnyMimeToItem(item, stream, inboundConversionOptions);
                     item.Save(SaveMode.NoConflictResolution);
                 }
             }
             catch (ExchangeDataException innerException)
             {
                 throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException, false);
             }
             catch (ConversionFailedException innerException2)
             {
                 throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.InvalidMIME, innerException2, false);
             }
         }
         itemAttachment.Save();
     }
     AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, null, "AttachmentHelper:CreateAttachments:: AttachmentCreated successful. AttachmentCount:{0}", parentItem.IAttachmentCollection.Count);
 }
        // Token: 0x0600003E RID: 62 RVA: 0x00004434 File Offset: 0x00002634
        private void AttachOriginalMessageToNotification(MessageItem initiationMessage, MessageItem notificationMessage, out string originalSenderDisplayname)
        {
            originalSenderDisplayname = string.Empty;
            if (string.IsNullOrEmpty(this.defaultAcceptedDomain))
            {
                ModeratedDLApplication.diag.TraceDebug((long)this.GetHashCode(), "Cannot attach original message to notification without domain for content conversion.");
                return;
            }
            AttachmentCollection attachmentCollection = initiationMessage.AttachmentCollection;

            foreach (AttachmentHandle handle in attachmentCollection)
            {
                using (Attachment attachment = attachmentCollection.Open(handle))
                {
                    if ("OriginalMessage".Equals(attachment.FileName, StringComparison.OrdinalIgnoreCase))
                    {
                        StreamAttachment streamAttachment = attachment as StreamAttachment;
                        if (streamAttachment != null)
                        {
                            using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.ReadOnly))
                            {
                                using (ItemAttachment itemAttachment = (ItemAttachment)notificationMessage.AttachmentCollection.Create(AttachmentType.EmbeddedMessage))
                                {
                                    using (Item item = itemAttachment.GetItem())
                                    {
                                        InboundConversionOptions options = new InboundConversionOptions(this.defaultAcceptedDomain);
                                        ItemConversion.ConvertAnyMimeToItem(item, contentStream, options);
                                        item[MessageItemSchema.Flags] = MessageFlags.None;
                                        originalSenderDisplayname     = (item.TryGetProperty(MessageItemSchema.SenderDisplayName) as string);
                                        item.Save(SaveMode.NoConflictResolution);
                                        itemAttachment[AttachmentSchema.DisplayName] = initiationMessage.Subject;
                                        itemAttachment.Save();
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
Exemple #5
0
        public static MessageItem CreateForwardMessageWithItemAttached(Item itemToAttach, UserContext userContext)
        {
            MessageItem messageItem = MessageItem.Create(userContext.MailboxSession, userContext.DraftsFolderId);

            messageItem[ItemSchema.ConversationIndexTracking] = true;
            string property;

            if (itemToAttach is Contact)
            {
                property = ItemUtility.GetProperty <string>(itemToAttach, StoreObjectSchema.DisplayName, string.Empty);
            }
            else if (itemToAttach is DistributionList)
            {
                property = ItemUtility.GetProperty <string>(itemToAttach, StoreObjectSchema.DisplayName, string.Empty);
            }
            else
            {
                property = ItemUtility.GetProperty <string>(itemToAttach, ItemSchema.Subject, string.Empty);
            }
            if (property.Length <= 255)
            {
                messageItem[ItemSchema.Subject] = property;
            }
            else
            {
                messageItem[ItemSchema.Subject] = property.Substring(0, 255);
            }
            using (ItemAttachment itemAttachment = messageItem.AttachmentCollection.AddExistingItem(itemToAttach))
            {
                itemAttachment.Save();
            }
            if (Globals.ArePerfCountersEnabled)
            {
                OwaSingleCounters.ItemsCreated.Increment();
            }
            return(messageItem);
        }
        private Command.ExecutionState ForwardUsingXso(StoreObjectId smartId)
        {
            Item             smartItem        = base.GetSmartItem(smartId);
            MessageItem      messageItem      = null;
            VersionedId      versionedId      = null;
            MessageItem      messageItem2     = null;
            CalendarItemBase calendarItemBase = null;

            try
            {
                StoreObjectId defaultFolderId = base.MailboxSession.GetDefaultFolderId(DefaultFolderType.Drafts);
                messageItem = MessageItem.Create(base.MailboxSession, defaultFolderId);
                base.ParseMimeToMessage(messageItem);
                messageItem.Save(SaveMode.NoConflictResolution);
                messageItem.Load();
                versionedId = messageItem.Id;
                messageItem.Dispose();
                messageItem = MessageItem.Bind(base.MailboxSession, versionedId);
                RmsTemplate            rmsTemplate = null;
                SendMailBase.IrmAction irmAction   = base.GetIrmAction(delegate(RightsManagedMessageItem originalRightsManagedItem)
                {
                    if (originalRightsManagedItem == null)
                    {
                        throw new ArgumentNullException("originalRightsManagedItem");
                    }
                    if (!originalRightsManagedItem.UsageRights.IsUsageRightGranted(ContentRight.Forward))
                    {
                        throw new AirSyncPermanentException(StatusCode.IRM_OperationNotPermitted, false)
                        {
                            ErrorStringForProtocolLogger = "sfcEOperationNotPermitted"
                        };
                    }
                }, ref smartItem, out rmsTemplate);
                Microsoft.Exchange.Data.Storage.BodyFormat bodyFormat = messageItem.Body.Format;
                MeetingMessage meetingMessage = smartItem as MeetingMessage;
                string         text;
                if ((base.ReplaceMime || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage) && meetingMessage != null && !meetingMessage.IsDelegated() && (meetingMessage is MeetingRequest || meetingMessage is MeetingCancellation))
                {
                    text = string.Empty;
                }
                else
                {
                    using (TextReader textReader = messageItem.Body.OpenTextReader(bodyFormat))
                    {
                        text = textReader.ReadToEnd();
                    }
                    Body body = (irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseInlineOriginalBody || irmAction == SendMailBase.IrmAction.ReusePublishingLicenseInlineOriginalBody) ? ((RightsManagedMessageItem)smartItem).ProtectedBody : smartItem.Body;
                    if (body.Format == Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml)
                    {
                        if (bodyFormat == Microsoft.Exchange.Data.Storage.BodyFormat.TextPlain)
                        {
                            XmlDocument  xmlDocument  = new SafeXmlDocument();
                            XmlNode      xmlNode      = xmlDocument.CreateElement("PRE");
                            XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("STYLE");
                            xmlAttribute.Value = "word-wrap:break-word; font-size:10.0pt; font-family:Tahoma; color:black";
                            xmlNode.Attributes.Append(xmlAttribute);
                            xmlNode.InnerText = text;
                            text = xmlNode.OuterXml;
                        }
                        bodyFormat = Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml;
                    }
                }
                ReplyForwardConfiguration replyForwardConfiguration = new ReplyForwardConfiguration(bodyFormat);
                replyForwardConfiguration.ConversionOptionsForSmime = AirSyncUtility.GetInboundConversionOptions();
                replyForwardConfiguration.AddBodyPrefix(text);
                if (base.Version >= 120)
                {
                    if (smartItem is MessageItem)
                    {
                        messageItem2 = ((MessageItem)smartItem).CreateForward(defaultFolderId, replyForwardConfiguration);
                        if (irmAction == SendMailBase.IrmAction.CreateNewPublishingLicense || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseInlineOriginalBody || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage)
                        {
                            messageItem2 = base.GetRightsManagedReplyForward(messageItem2, irmAction, rmsTemplate);
                        }
                    }
                    else if (smartItem is CalendarItem)
                    {
                        CalendarItem calendarItem = (CalendarItem)smartItem;
                        calendarItemBase = base.GetCalendarItemBaseToReplyOrForward(calendarItem);
                        messageItem2     = calendarItemBase.CreateForward(defaultFolderId, replyForwardConfiguration);
                        if (!calendarItem.IsMeeting)
                        {
                            BodyConversionUtilities.CopyBody(messageItem, messageItem2);
                        }
                    }
                    if (messageItem2 == null)
                    {
                        base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ForwardFailed");
                        throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.MailSubmissionFailed, null, false);
                    }
                    if (base.ReplaceMime || irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage)
                    {
                        RightsManagedMessageItem rightsManagedMessageItem = messageItem2 as RightsManagedMessageItem;
                        if (rightsManagedMessageItem != null)
                        {
                            rightsManagedMessageItem.ProtectedAttachmentCollection.RemoveAll();
                        }
                        else
                        {
                            messageItem2.AttachmentCollection.RemoveAll();
                        }
                    }
                    base.CopyMessageContents(messageItem, messageItem2, false, (irmAction == SendMailBase.IrmAction.CreateNewPublishingLicenseAttachOriginalMessage) ? smartItem : null);
                    base.SendMessage(messageItem2);
                }
                else if (smartItem is MessageItem)
                {
                    using (ItemAttachment itemAttachment = messageItem.AttachmentCollection.AddExistingItem(smartItem))
                    {
                        MessageItem messageItem3 = (MessageItem)smartItem;
                        itemAttachment.FileName = messageItem3.Subject + itemAttachment.FileExtension;
                        itemAttachment.Save();
                    }
                    base.SendMessage(messageItem);
                }
                else if (smartItem is CalendarItem)
                {
                    CalendarItem calendarItem2 = (CalendarItem)smartItem;
                    messageItem2 = calendarItem2.CreateForward(defaultFolderId, replyForwardConfiguration);
                    if (messageItem2 == null)
                    {
                        base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ForwardFailed2");
                        throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.MailSubmissionFailed, null, false);
                    }
                    if (!calendarItem2.IsMeeting)
                    {
                        BodyConversionUtilities.CopyBody(messageItem, messageItem2);
                    }
                    base.CopyMessageContents(messageItem, messageItem2, false, null);
                    base.SendMessage(messageItem2);
                }
            }
            finally
            {
                if (messageItem != null)
                {
                    if (versionedId != null)
                    {
                        base.MailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                        {
                            versionedId
                        });
                    }
                    messageItem.Dispose();
                }
                if (smartItem != null)
                {
                    smartItem.Dispose();
                }
                if (messageItem2 != null)
                {
                    messageItem2.Dispose();
                }
                if (calendarItemBase != null)
                {
                    calendarItemBase.Dispose();
                }
            }
            return(Command.ExecutionState.Complete);
        }
Exemple #7
0
        // Token: 0x060022C1 RID: 8897 RVA: 0x000C69B8 File Offset: 0x000C4BB8
        public PreFormActionResponse Execute(OwaContext owaContext, out ApplicationElement applicationElement, out string type, out string state, out string action)
        {
            if (owaContext == null)
            {
                throw new ArgumentNullException("owaContext");
            }
            applicationElement = ApplicationElement.NotSet;
            type   = string.Empty;
            action = string.Empty;
            state  = string.Empty;
            Item                  item       = null;
            Item                  item2      = null;
            Item                  item3      = null;
            bool                  flag       = false;
            BodyFormat            bodyFormat = BodyFormat.TextPlain;
            PreFormActionResponse result;

            try
            {
                HttpContext           httpContext           = owaContext.HttpContext;
                UserContext           userContext           = owaContext.UserContext;
                PreFormActionResponse preFormActionResponse = new PreFormActionResponse(httpContext.Request, new string[]
                {
                    "cb",
                    "smime"
                });
                item = ReplyForwardUtilities.GetItemForRequest(owaContext, out item2);
                if (item != null && !ItemUtility.IsForwardSupported(item))
                {
                    throw new OwaInvalidRequestException("Forwarding of such a type item is not supported.");
                }
                CalendarItemBase calendarItemBase = item as CalendarItemBase;
                if (item is Task || item is ContactBase || (calendarItemBase != null && !calendarItemBase.IsMeeting))
                {
                    item3 = ReplyForwardUtilities.CreateForwardMessageWithItemAttached(item, userContext);
                    preFormActionResponse.Action = "New";
                    preFormActionResponse.AddParameter("exdltdrft", "1");
                }
                else
                {
                    bool   flag2 = false;
                    string queryStringParameter = Utilities.GetQueryStringParameter(httpContext.Request, "smime", false);
                    RightsManagedMessageDecryptionStatus decryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled;
                    if (userContext.IsIrmEnabled)
                    {
                        try
                        {
                            flag = Utilities.IrmDecryptForReplyForward(owaContext, ref item, ref item2, ref bodyFormat, out decryptionStatus);
                        }
                        catch (RightsManagementPermanentException exception)
                        {
                            decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception);
                        }
                    }
                    if (!flag)
                    {
                        bodyFormat = ReplyForwardUtilities.GetReplyForwardBodyFormat(item, userContext);
                    }
                    bool flag3 = Utilities.IsSMimeControlNeededForEditForm(queryStringParameter, owaContext);
                    flag2 = ((flag3 && Utilities.IsSMime(item)) || flag);
                    bool flag4 = userContext.IsSmsEnabled && ObjectClass.IsSmsMessage(owaContext.FormsRegistryContext.Type);
                    ReplyForwardFlags replyForwardFlags = ReplyForwardFlags.None;
                    if (flag2)
                    {
                        replyForwardFlags |= ReplyForwardFlags.DropBody;
                    }
                    if (flag4 || flag)
                    {
                        replyForwardFlags |= ReplyForwardFlags.DropHeader;
                    }
                    StoreObjectId parentFolderId = Utilities.GetParentFolderId(item2, item);
                    item3 = ReplyForwardUtilities.CreateForwardItem(flag3 ? BodyFormat.TextHtml : bodyFormat, item, replyForwardFlags, userContext, parentFolderId);
                    if (flag)
                    {
                        item3.AttachmentCollection.RemoveAll();
                        using (ItemAttachment itemAttachment = item3.AttachmentCollection.AddExistingItem(item))
                        {
                            itemAttachment.Save();
                            goto IL_205;
                        }
                    }
                    if (Utilities.IsIrmRestrictedAndNotDecrypted(item))
                    {
                        ReplyForwardUtilities.SetAlternateIrmBody(item3, flag3 ? BodyFormat.TextHtml : bodyFormat, userContext, parentFolderId, decryptionStatus, ObjectClass.IsVoiceMessage(item.ClassName));
                        item3.AttachmentCollection.RemoveAll();
                    }
IL_205:
                    preFormActionResponse.Action = "Forward";
                    if (flag2)
                    {
                        preFormActionResponse.AddParameter("srcId", Utilities.GetItemIdQueryString(httpContext.Request));
                        if (Utilities.GetQueryStringParameter(httpContext.Request, "cb", false) == null && Utilities.IsWebBeaconsAllowed(item))
                        {
                            preFormActionResponse.AddParameter("cb", "1");
                        }
                    }
                    if (flag4)
                    {
                        item3.ClassName = "IPM.Note.Mobile.SMS";
                    }
                }
                item3.Save(SaveMode.ResolveConflicts);
                item3.Load();
                ReplyForwardUtilities.DeleteLevelOneAttachments(item3, userContext);
                preFormActionResponse.ApplicationElement = ApplicationElement.Item;
                preFormActionResponse.Type = item3.ClassName;
                preFormActionResponse.AddParameter("id", OwaStoreObjectId.CreateFromStoreObject(item3).ToBase64String());
                if (userContext.IsInOtherMailbox(item))
                {
                    preFormActionResponse.AddParameter("fOMF", "1");
                }
                if (flag)
                {
                    preFormActionResponse.AddParameter("fIrmAsAttach", "1");
                }
                result = preFormActionResponse;
            }
            finally
            {
                if (item != null)
                {
                    item.Dispose();
                    item = null;
                }
                if (item2 != null)
                {
                    item2.Dispose();
                    item2 = null;
                }
                if (item3 != null)
                {
                    item3.Dispose();
                    item3 = null;
                }
            }
            return(result);
        }
        // Token: 0x0600155B RID: 5467 RVA: 0x0007CE68 File Offset: 0x0007B068
        protected void CopyMessageContents(MessageItem source, MessageItem destination, bool copyOriginalRecipients, Item attachmentItem)
        {
            source.Load();
            string inReplyTo  = destination.InReplyTo;
            string references = destination.References;

            destination.Subject           = ((source.TryGetProperty(ItemSchema.SubjectPrefix) as string) ?? string.Empty) + ((source.TryGetProperty(ItemSchema.NormalizedSubject) as string) ?? string.Empty);
            destination.InReplyTo         = inReplyTo;
            destination.Importance        = source.Importance;
            destination.InternetMessageId = source.InternetMessageId;
            destination.Categories.Clear();
            destination.Categories.AddRange(source.Categories);
            destination.IconIndex = source.IconIndex;
            destination.IsRead    = source.IsRead;
            destination.IsReadReceiptRequested = source.IsReadReceiptRequested;
            destination.References             = references;
            if (copyOriginalRecipients)
            {
                this.originalRecipients = new HashSet <RecipientId>();
                foreach (Recipient recipient in destination.Recipients)
                {
                    this.originalRecipients.Add(recipient.Id);
                }
            }
            destination.Recipients.Clear();
            foreach (Recipient recipient2 in source.Recipients)
            {
                destination.Recipients.Add(recipient2.Participant, recipient2.RecipientItemType);
            }
            if (source.ReplyTo != null)
            {
                foreach (Participant item in source.ReplyTo)
                {
                    destination.ReplyTo.Add(item);
                }
            }
            RightsManagedMessageItem rightsManagedMessageItem = destination as RightsManagedMessageItem;
            AttachmentCollection     attachmentCollection     = (rightsManagedMessageItem != null) ? rightsManagedMessageItem.ProtectedAttachmentCollection : destination.AttachmentCollection;

            if (rightsManagedMessageItem == null && attachmentItem != null)
            {
                throw new InvalidOperationException("attachmentItem must be null for non-IRM messages");
            }
            if (this.ReplaceMime || attachmentItem != null)
            {
                if (rightsManagedMessageItem == null)
                {
                    Body.CopyBody(source, destination, GlobalSettings.DisableCharsetDetectionInCopyMessageContents);
                }
                else
                {
                    using (Stream stream = source.Body.OpenReadStream(new BodyReadConfiguration(source.Body.Format, source.Body.Charset)))
                    {
                        using (Stream stream2 = rightsManagedMessageItem.ProtectedBody.OpenWriteStream(new BodyWriteConfiguration(source.Body.Format, source.Body.Charset)))
                        {
                            Util.StreamHandler.CopyStreamData(stream, stream2);
                        }
                    }
                }
            }
            foreach (AttachmentHandle handle in source.AttachmentCollection)
            {
                using (Attachment attachment = source.AttachmentCollection.Open(handle))
                {
                    int num = 0;
                    if (attachment is StreamAttachment)
                    {
                        num = 1;
                    }
                    else if (attachment is OleAttachment)
                    {
                        num = 2;
                    }
                    if (num > 0)
                    {
                        Microsoft.Exchange.Data.Storage.AttachmentType type = (num == 1) ? Microsoft.Exchange.Data.Storage.AttachmentType.Stream : Microsoft.Exchange.Data.Storage.AttachmentType.Ole;
                        StreamAttachmentBase streamAttachmentBase           = (StreamAttachmentBase)attachment;
                        using (StreamAttachmentBase streamAttachmentBase2 = (StreamAttachmentBase)attachmentCollection.Create(type))
                        {
                            using (Stream contentStream = streamAttachmentBase2.GetContentStream())
                            {
                                using (Stream contentStream2 = streamAttachmentBase.GetContentStream())
                                {
                                    int    num2   = 4096;
                                    byte[] buffer = new byte[num2];
                                    int    count;
                                    while ((count = contentStream2.Read(buffer, 0, num2)) > 0)
                                    {
                                        contentStream.Write(buffer, 0, count);
                                    }
                                    streamAttachmentBase2.ContentType = streamAttachmentBase.ContentType;
                                    streamAttachmentBase2[AttachmentSchema.DisplayName] = streamAttachmentBase.DisplayName;
                                    streamAttachmentBase2.FileName = streamAttachmentBase.FileName;
                                    streamAttachmentBase2[AttachmentSchema.AttachContentId] = streamAttachmentBase[AttachmentSchema.AttachContentId];
                                    streamAttachmentBase2.IsInline = streamAttachmentBase.IsInline;
                                }
                            }
                            streamAttachmentBase2.Save();
                            continue;
                        }
                    }
                    ItemAttachment itemAttachment = (ItemAttachment)attachment;
                    using (Item item2 = itemAttachment.GetItem())
                    {
                        using (ItemAttachment itemAttachment2 = attachmentCollection.AddExistingItem(item2))
                        {
                            itemAttachment2.Save();
                        }
                    }
                }
            }
            if (attachmentItem != null)
            {
                using (ItemAttachment itemAttachment3 = attachmentCollection.AddExistingItem(attachmentItem))
                {
                    itemAttachment3.Save();
                }
            }
        }
        // Token: 0x06000304 RID: 772 RVA: 0x000131B8 File Offset: 0x000113B8
        private bool SendItemAsAttachement(ContentSetting policy, ItemData itemData, out StoreObjectId messageId)
        {
            Exception ex = null;

            messageId = null;
            using (MessageItem messageItem = MessageItem.Create(base.MailboxData.MailboxSession, this.sendFolderId))
            {
                Participant officialFileParticipant = this.GetOfficialFileParticipant(policy);
                string      text = base.MailboxData.MailboxSmtpAddress + ":";
                if (policy.AddressForJournaling != null)
                {
                    messageItem[MessageItemSchema.ElcAutoCopyLabel] = text + policy.LabelForJournaling;
                }
                else
                {
                    messageItem[MessageItemSchema.ElcAutoCopyLabel] = text;
                }
                messageItem.ClassName = this.GetMessageClass(policy.MessageFormatForJournaling);
                messageItem.Subject   = "Autocopy report";
                Participant v = this.NdrParticipant;
                if (v != null)
                {
                    messageItem.ReplyTo.Add(this.NdrParticipant);
                }
                messageItem.Recipients.Add(officialFileParticipant, RecipientItemType.To);
                try
                {
                    using (Item item = Item.Bind(base.MailboxData.MailboxSession, itemData.Id, ItemBindOption.LoadRequiredPropertiesOnly))
                    {
                        using (ItemAttachment itemAttachment = messageItem.AttachmentCollection.AddExistingItem(item))
                        {
                            itemAttachment.Save();
                        }
                    }
                    messageItem.SendWithoutSavingMessage();
                    AutoCopyEnforcer.Tracer.TraceDebug <object, string, VersionedId>((long)this.GetHashCode(), "{0}: sent journaling message to '{1}' for item '{2}'.", TraceContext.Get(), officialFileParticipant.EmailAddress, itemData.Id);
                    AutoCopyEnforcer.TracerPfd.TracePfd((long)this.GetHashCode(), "PFD IWE {0} {1}: sent journaling message to '{2}' for item '{3}'.", new object[]
                    {
                        29975,
                        TraceContext.Get(),
                        officialFileParticipant.EmailAddress,
                        itemData.Id
                    });
                }
                catch (ObjectNotFoundException ex2)
                {
                    ex = ex2;
                }
                catch (VirusMessageDeletedException ex3)
                {
                    ex = ex3;
                }
                catch (VirusScanInProgressException ex4)
                {
                    ex = ex4;
                }
                catch (CorruptDataException ex5)
                {
                    ex = ex5;
                }
                catch (VirusDetectedException ex6)
                {
                    ex = ex6;
                }
                catch (MessageSubmissionExceededException ex7)
                {
                    ex = ex7;
                }
                if (ex != null)
                {
                    messageId = messageItem.StoreObjectId;
                    AutoCopyEnforcer.Tracer.TraceError <AutoCopyEnforcer, VersionedId, Exception>((long)this.GetHashCode(), "{0}: Unable to process the message '{1}' due to exception '{2}'. Skipping this item.", this, itemData.Id, ex);
                    return(false);
                }
            }
            return(true);
        }
Exemple #10
0
        public PreFormActionResponse Execute(OwaContext owaContext, out ApplicationElement applicationElement, out string type, out string state, out string action)
        {
            if (owaContext == null)
            {
                throw new ArgumentNullException("owaContext");
            }
            applicationElement = ApplicationElement.NotSet;
            type   = string.Empty;
            action = string.Empty;
            state  = string.Empty;
            Item                  item       = null;
            Item                  item2      = null;
            Item                  item3      = null;
            bool                  flag       = false;
            BodyFormat            bodyFormat = BodyFormat.TextPlain;
            PreFormActionResponse result;

            try
            {
                HttpContext httpContext = owaContext.HttpContext;
                UserContext userContext = owaContext.UserContext;
                item = ReplyForwardUtilities.GetItemForRequest(owaContext, out item2);
                RightsManagedMessageDecryptionStatus decryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled;
                if (userContext.IsIrmEnabled)
                {
                    try
                    {
                        flag = Utilities.IrmDecryptForReplyForward(owaContext, ref item, ref item2, ref bodyFormat, out decryptionStatus);
                    }
                    catch (RightsManagementPermanentException exception)
                    {
                        decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception);
                    }
                }
                if (!flag)
                {
                    bodyFormat = ReplyForwardUtilities.GetReplyForwardBodyFormat(item, userContext);
                }
                string            queryStringParameter = Utilities.GetQueryStringParameter(httpContext.Request, "smime", false);
                bool              flag2             = Utilities.IsSMimeControlNeededForEditForm(queryStringParameter, owaContext);
                bool              flag3             = userContext.IsSmsEnabled && ObjectClass.IsSmsMessage(owaContext.FormsRegistryContext.Type);
                bool              flag4             = ObjectClass.IsMeetingRequest(owaContext.FormsRegistryContext.Type);
                bool              flag5             = flag3 || (flag2 && Utilities.IsSMime(item)) || flag;
                ReplyForwardFlags replyForwardFlags = ReplyForwardFlags.None;
                if (flag5)
                {
                    replyForwardFlags |= ReplyForwardFlags.DropBody;
                }
                if (flag3 || flag)
                {
                    replyForwardFlags |= ReplyForwardFlags.DropHeader;
                }
                StoreObjectId parentFolderId = Utilities.GetParentFolderId(item2, item);
                item3 = ReplyForwardUtilities.CreateReplyAllItem(flag2 ? BodyFormat.TextHtml : bodyFormat, item, replyForwardFlags, userContext, parentFolderId);
                if (flag)
                {
                    using (ItemAttachment itemAttachment = item3.AttachmentCollection.AddExistingItem(item))
                    {
                        itemAttachment.Save();
                        goto IL_172;
                    }
                }
                if (Utilities.IsIrmRestrictedAndNotDecrypted(item))
                {
                    ReplyForwardUtilities.SetAlternateIrmBody(item3, flag2 ? BodyFormat.TextHtml : bodyFormat, userContext, parentFolderId, decryptionStatus, ObjectClass.IsVoiceMessage(item.ClassName));
                }
IL_172:
                type = "IPM.Note";
                if (flag3)
                {
                    item3.ClassName = "IPM.Note.Mobile.SMS";
                    type            = "IPM.Note.Mobile.SMS";
                    ReplyForwardUtilities.RemoveInvalidRecipientsFromSmsMessage((MessageItem)item3);
                }
                item3.Save(SaveMode.ResolveConflicts);
                item3.Load();
                PreFormActionResponse preFormActionResponse = new PreFormActionResponse(httpContext.Request, new string[]
                {
                    "cb",
                    "smime"
                });
                preFormActionResponse.ApplicationElement = ApplicationElement.Item;
                preFormActionResponse.Type   = type;
                preFormActionResponse.Action = "Reply";
                preFormActionResponse.AddParameter("id", OwaStoreObjectId.CreateFromStoreObject(item3).ToBase64String());
                if (flag5)
                {
                    preFormActionResponse.AddParameter("srcId", Utilities.GetItemIdQueryString(httpContext.Request));
                    if (Utilities.GetQueryStringParameter(httpContext.Request, "cb", false) == null && Utilities.IsWebBeaconsAllowed(item))
                    {
                        preFormActionResponse.AddParameter("cb", "1");
                    }
                }
                if (userContext.IsInOtherMailbox(item))
                {
                    preFormActionResponse.AddParameter("fOMF", "1");
                }
                if (item.GetValueOrDefault <bool>(MessageItemSchema.MessageBccMe) && !flag4)
                {
                    preFormActionResponse.AddParameter("fRABcc", "1");
                }
                if (flag)
                {
                    preFormActionResponse.AddParameter("fIrmAsAttach", "1");
                }
                result = preFormActionResponse;
            }
            finally
            {
                if (item != null)
                {
                    item.Dispose();
                    item = null;
                }
                if (item2 != null)
                {
                    item2.Dispose();
                    item2 = null;
                }
                if (item3 != null)
                {
                    item3.Dispose();
                    item3 = null;
                }
            }
            return(result);
        }
        public void AddAttachment(Attachment attachment, IRecipientSession adRecipientSession)
        {
            bool     flag     = false;
            MimePart mimePart = attachment.MimePart;
            Header   header   = null;

            if (mimePart != null)
            {
                header = mimePart.Headers.FindFirst("X-MS-Exchange-Organization-Approval-AttachToApprovalRequest");
            }
            string text;

            if (header != null && header.TryGetValue(out text))
            {
                if (text.Equals("Never"))
                {
                    return;
                }
                if (text.Equals("AsMessage"))
                {
                    flag = true;
                }
            }
            if (flag)
            {
                using (Stream contentReadStream = attachment.GetContentReadStream())
                {
                    using (ItemAttachment itemAttachment = (ItemAttachment)this.messageItem.AttachmentCollection.Create(AttachmentType.EmbeddedMessage))
                    {
                        using (Item item = itemAttachment.GetItem())
                        {
                            ItemConversion.ConvertAnyMimeToItem(item, contentReadStream, new InboundConversionOptions(Components.Configuration.FirstOrgAcceptedDomainTable.DefaultDomainName)
                            {
                                UserADSession = adRecipientSession
                            });
                            item[MessageItemSchema.Flags] = MessageFlags.None;
                            item.Save(SaveMode.NoConflictResolution);
                            string valueOrDefault = item.GetValueOrDefault <string>(ItemSchema.Subject);
                            if (!string.IsNullOrEmpty(valueOrDefault))
                            {
                                itemAttachment[AttachmentSchema.DisplayName] = valueOrDefault;
                            }
                            itemAttachment.Save();
                        }
                    }
                    return;
                }
            }
            using (StreamAttachment streamAttachment = (StreamAttachment)this.messageItem.AttachmentCollection.Create(AttachmentType.Stream))
            {
                streamAttachment.FileName = attachment.FileName;
                using (Stream contentStream = streamAttachment.GetContentStream())
                {
                    using (Stream contentReadStream2 = attachment.GetContentReadStream())
                    {
                        ApprovalProcessor.CopyStream(contentReadStream2, contentStream, this.Buffer);
                    }
                    contentStream.Flush();
                }
                streamAttachment.Save();
            }
        }