Example #1
0
        // Token: 0x06001396 RID: 5014 RVA: 0x00070B58 File Offset: 0x0006ED58
        public static Stream ConvertToPlainTextStream(Item item, long truncationSizeByChars, out long totalDataSize, out IList <AttachmentLink> attachmentLinks)
        {
            BodyReadConfiguration configuration = new BodyReadConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextPlain, "utf-8");
            AirSyncStream         airSyncStream = new AirSyncStream();
            int  num  = 0;
            Body body = null;

            if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item))
            {
                body = ((RightsManagedMessageItem)item).ProtectedBody;
            }
            else
            {
                body = item.Body;
            }
            uint streamHash;

            using (Stream stream = body.OpenReadStream(configuration))
            {
                num = StreamHelper.CopyStream(stream, airSyncStream, Encoding.UTF8, (int)truncationSizeByChars, true, out streamHash);
            }
            airSyncStream.StreamHash = (int)streamHash;
            totalDataSize            = ((truncationSizeByChars < 0L || (long)num < truncationSizeByChars) ? ((long)num) : body.Size);
            attachmentLinks          = null;
            return(airSyncStream);
        }
Example #2
0
        // Token: 0x06001398 RID: 5016 RVA: 0x00070CE0 File Offset: 0x0006EEE0
        public static Stream ConvertToRtfStream(Item item, long truncationSizeByBytes, out long totalDataSize, out IList <AttachmentLink> attachmentLinks)
        {
            BodyReadConfiguration configuration = new BodyReadConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.ApplicationRtf, "utf-8");
            AirSyncStream         airSyncStream = new AirSyncStream();
            Body body = null;

            if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item))
            {
                body = ((RightsManagedMessageItem)item).ProtectedBody;
            }
            else
            {
                body = item.Body;
            }
            uint streamHash;

            using (Stream stream = body.OpenReadStream(configuration))
            {
                airSyncStream.DoBase64Conversion = true;
                StreamHelper.CopyStream(stream, airSyncStream, (int)truncationSizeByBytes, out streamHash);
            }
            airSyncStream.StreamHash = (int)streamHash;
            totalDataSize            = ((truncationSizeByBytes < 0L || airSyncStream.Length < truncationSizeByBytes) ? airSyncStream.Length : body.Size);
            attachmentLinks          = null;
            return(airSyncStream);
        }
        // Token: 0x06001445 RID: 5189 RVA: 0x00074BE4 File Offset: 0x00072DE4
        public virtual void PreProcessProperty()
        {
            Item item = (Item)base.XsoItem;

            if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item))
            {
                this.actualBody = ((RightsManagedMessageItem)item).ProtectedBody;
            }
            else
            {
                this.actualBody = item.Body;
            }
            this.originalItem      = null;
            this.isIrmErrorMessage = false;
            if (BodyConversionUtilities.IsIRMFailedToDecode(item))
            {
                MessageItem messageItem = this.CreateIrmErrorMessage();
                if (messageItem != null)
                {
                    base.XsoItem           = messageItem;
                    this.originalItem      = item;
                    this.isIrmErrorMessage = true;
                }
            }
        }
        // Token: 0x0600144E RID: 5198 RVA: 0x000750E0 File Offset: 0x000732E0
        private Stream GetRtfData(long truncationSize, out long totalDataSize, out IList <AttachmentLink> attachmentLinks)
        {
            if (truncationSize == 0L)
            {
                totalDataSize   = this.Size;
                attachmentLinks = null;
                return(XsoContentProperty.emptyStream);
            }
            Item item = (Item)base.XsoItem;

            item.Load();
            return(BodyConversionUtilities.ConvertToRtfStream(item, truncationSize, out totalDataSize, out attachmentLinks));
        }
        private bool LoadRightsManagementLicenseData(Item mailboxItem, RightsManagementLicenseData rightsManagementLicenseData)
        {
            if (!BodyConversionUtilities.IsMessageRestrictedAndDecoded(mailboxItem) && !BodyConversionUtilities.IsIRMFailedToDecode(mailboxItem))
            {
                return(false);
            }
            if (BodyConversionUtilities.IsIRMFailedToDecode(mailboxItem))
            {
                rightsManagementLicenseData.InitNoRightsTemplate();
                return(true);
            }
            RightsManagedMessageItem rightsManagedMessageItem = mailboxItem as RightsManagedMessageItem;

            rightsManagementLicenseData.EditAllowed               = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Edit));
            rightsManagementLicenseData.ReplyAllowed              = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Reply));
            rightsManagementLicenseData.ReplyAllAllowed           = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.ReplyAll));
            rightsManagementLicenseData.ForwardAllowed            = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Forward));
            rightsManagementLicenseData.PrintAllowed              = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Print));
            rightsManagementLicenseData.ExtractAllowed            = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Extract));
            rightsManagementLicenseData.ProgrammaticAccessAllowed = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.ObjectModel));
            rightsManagementLicenseData.Owner = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Owner));
            if (!AirSyncUtility.IsProtectedVoicemailItem(mailboxItem))
            {
                rightsManagementLicenseData.ExportAllowed = new bool?(rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Export));
            }
            else
            {
                rightsManagementLicenseData.ExportAllowed = new bool?(false);
            }
            if (rightsManagedMessageItem.UsageRights.IsUsageRightGranted(ContentRight.Forward) && (!rightsManagedMessageItem.Restriction.RequiresRepublishingWhenRecipientsChange || rightsManagedMessageItem.CanRepublish))
            {
                rightsManagementLicenseData.ModifyRecipientsAllowed = new bool?(true);
            }
            else
            {
                rightsManagementLicenseData.ModifyRecipientsAllowed = new bool?(false);
            }
            rightsManagementLicenseData.ContentExpiryDate = new ExDateTime?(rightsManagedMessageItem.UserLicenseExpiryTime);
            rightsManagementLicenseData.ContentOwner      = rightsManagedMessageItem.ConversationOwner.EmailAddress;
            RmsTemplate restriction = rightsManagedMessageItem.Restriction;

            if (restriction != null)
            {
                Guid id = restriction.Id;
                rightsManagementLicenseData.TemplateID          = restriction.Id.ToString();
                rightsManagementLicenseData.TemplateName        = restriction.GetName(Command.CurrentCommand.MailboxSession.PreferedCulture);
                rightsManagementLicenseData.TemplateDescription = restriction.GetDescription(Command.CurrentCommand.MailboxSession.PreferedCulture);
            }
            return(true);
        }
Example #6
0
        private Stream GetTextBody(int length)
        {
            Item item = (Item)base.XsoItem;

            if (string.Equals(item.ClassName, "IPM.Note.SMIME", StringComparison.OrdinalIgnoreCase))
            {
                string s = Strings.SMIMENotSupportedBodyText.ToString(item.Session.PreferedCulture);
                this.textData = new MemoryStream(Encoding.UTF8.GetBytes(s));
                return(this.textData);
            }
            long num;
            IList <AttachmentLink> list;
            Stream result = BodyConversionUtilities.ConvertToPlainTextStream(item, (long)length, out num, out list);

            this.textSize = (int)num;
            return(result);
        }
Example #7
0
        // Token: 0x06001395 RID: 5013 RVA: 0x00070AF4 File Offset: 0x0006ECF4
        public static Stream ConvertToBodyStream(Item item, long truncationSize, out long totalDataSize, out IList <AttachmentLink> attachmentLinks)
        {
            Microsoft.Exchange.Data.Storage.BodyFormat format = item.Body.Format;
            switch (format)
            {
            case Microsoft.Exchange.Data.Storage.BodyFormat.TextPlain:
                return(BodyConversionUtilities.ConvertToPlainTextStream(item, truncationSize, out totalDataSize, out attachmentLinks));

            case Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml:
                return(BodyConversionUtilities.ConvertHtmlStream(item, truncationSize, out totalDataSize, out attachmentLinks));

            case Microsoft.Exchange.Data.Storage.BodyFormat.ApplicationRtf:
                return(BodyConversionUtilities.ConvertToRtfStream(item, truncationSize, out totalDataSize, out attachmentLinks));

            default:
                throw new ConversionException("Unsupported bodyFormat for this function: " + format);
            }
        }
Example #8
0
        // Token: 0x06001397 RID: 5015 RVA: 0x00070BF8 File Offset: 0x0006EDF8
        public static Stream ConvertHtmlStream(Item item, long truncationSizeByChars, out long totalDataSize, out IList <AttachmentLink> attachmentLinks)
        {
            SafeHtmlCallback      safeHtmlCallback = new SafeHtmlCallback(item);
            bool                  flag             = truncationSizeByChars == -1L;
            BodyReadConfiguration bodyReadConfiguration;

            if (flag)
            {
                bodyReadConfiguration = new BodyReadConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml, "utf-8");
                bodyReadConfiguration.SetHtmlOptions(HtmlStreamingFlags.FilterHtml, safeHtmlCallback);
            }
            else
            {
                bodyReadConfiguration = new BodyReadConfiguration(Microsoft.Exchange.Data.Storage.BodyFormat.TextHtml, "utf-8");
                bodyReadConfiguration.SetHtmlOptions(HtmlStreamingFlags.FilterHtml, safeHtmlCallback, new int?(1024));
            }
            AirSyncStream airSyncStream = new AirSyncStream();
            Body          body          = null;

            if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(item))
            {
                body = ((RightsManagedMessageItem)item).ProtectedBody;
            }
            else
            {
                body = item.Body;
            }
            uint streamHash;

            using (Stream stream = body.OpenReadStream(bodyReadConfiguration))
            {
                StreamHelper.CopyStream(stream, airSyncStream, Encoding.UTF8, (int)truncationSizeByChars, true, out streamHash);
            }
            airSyncStream.StreamHash = (int)streamHash;
            totalDataSize            = ((truncationSizeByChars < 0L || airSyncStream.Length < truncationSizeByChars) ? airSyncStream.Length : body.Size);
            attachmentLinks          = safeHtmlCallback.AttachmentLinks;
            return(airSyncStream);
        }
        // Token: 0x060013E0 RID: 5088 RVA: 0x00072734 File Offset: 0x00070934
        public IEnumerator <Attachment12Data> GetEnumerator()
        {
            Item             message        = base.XsoItem as Item;
            Attachment12Data attachmentData = null;

            if (message == null)
            {
                throw new UnexpectedTypeException("Item", base.XsoItem);
            }
            MeetingRequest meetingRequest = base.XsoItem as MeetingRequest;

            if (meetingRequest == null || !meetingRequest.IsDelegated())
            {
                string idbase = null;
                if (this.idmapping != null)
                {
                    idbase = this.idmapping[MailboxSyncItemId.CreateForNewItem(message.Id.ObjectId)];
                }
                if (idbase == null)
                {
                    idbase = message.Id.ObjectId.ToBase64String();
                }
                if (message is MessageItem && ((MessageItem)message).IsRestricted && !BodyConversionUtilities.IsMessageRestrictedAndDecoded(message) && !BodyConversionUtilities.IsIRMFailedToDecode(message))
                {
                    object prop = message.TryGetProperty(MessageItemSchema.DRMLicense);
                    if (prop is byte[][])
                    {
                        byte[][] license = (byte[][])prop;
                        if (license.Length > 0)
                        {
                            attachmentData                   = new Attachment14Data();
                            attachmentData.DisplayName       = "message.rpmsg.license";
                            attachmentData.Method            = 1;
                            attachmentData.EstimatedDataSize = (long)license[0].Length;
                            attachmentData.IsInline          = false;
                            attachmentData.FileReference     = HttpUtility.UrlEncode(idbase + ":DRMLicense");
                            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "Add DRM license as attachment, message is MessageItem {0}, message.IsRestricted {1}, IsDecoded {2}, FailedToDecode {3}", new object[]
                            {
                                message is MessageItem,
                                ((MessageItem)message).IsRestricted,
                                BodyConversionUtilities.IsMessageRestrictedAndDecoded(message),
                                BodyConversionUtilities.IsIRMFailedToDecode(message)
                            });
                            yield return(attachmentData);
                        }
                        else
                        {
                            AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.XsoTracer, this, "The license property on the DRM message is incorrect. Length = {0}", license.Length);
                        }
                    }
                    else
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "The license property on the DRM message is incorrect. prop = {0}", new object[]
                        {
                            prop
                        });
                    }
                }
                AttachmentCollection attachmentCollection = null;
                if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(message))
                {
                    attachmentCollection = ((RightsManagedMessageItem)message).ProtectedAttachmentCollection;
                }
                else
                {
                    if (BodyConversionUtilities.IsIRMFailedToDecode(message))
                    {
                        goto IL_3FC;
                    }
                    attachmentCollection = message.AttachmentCollection;
                }
                int index = -1;
                foreach (AttachmentHandle handle in attachmentCollection)
                {
                    using (Attachment attachment = attachmentCollection.Open(handle))
                    {
                        if (BodyUtility.IsClearSigned(message) && (string.Equals(attachment.FileName, "smime.p7m", StringComparison.OrdinalIgnoreCase) || string.Equals(attachment.ContentType, "multipart/signed", StringComparison.OrdinalIgnoreCase)))
                        {
                            continue;
                        }
                        attachmentData = this.GetAttachmentData(message, attachment, idbase, ref index);
                    }
                    if (attachmentData != null)
                    {
                        yield return(attachmentData);
                    }
                }
            }
IL_3FC:
            yield break;
        }
        // Token: 0x060013E1 RID: 5089 RVA: 0x00072750 File Offset: 0x00070950
        protected virtual Attachment12Data GetAttachmentData(Item message, Attachment attachment, string idbase, ref int index)
        {
            index++;
            Attachment14Data attachment14Data = new Attachment14Data();

            attachment14Data.Id = attachment.Id;
            if (BodyConversionUtilities.IsMessageRestrictedAndDecoded(message) && AirSyncUtility.IsProtectedVoicemailItem(message))
            {
                if (AttachmentHelper.IsProtectedVoiceAttachment(attachment.DisplayName))
                {
                    string valueOrDefault = message.GetValueOrDefault <string>(MessageItemSchema.RequireProtectedPlayOnPhone);
                    if (valueOrDefault != null && valueOrDefault.Equals("true", StringComparison.OrdinalIgnoreCase))
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "Skip attachment requires protected play on phone");
                        return(null);
                    }
                    attachment14Data.DisplayName = AttachmentHelper.GetUnprotectedVoiceAttachmentName(attachment.DisplayName);
                }
                else
                {
                    if (AttachmentHelper.IsProtectedTranscriptAttachment(attachment.DisplayName))
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.XsoTracer, this, "Skip protected transcript attachment");
                        return(null);
                    }
                    attachment14Data.DisplayName = attachment.DisplayName;
                }
            }
            else
            {
                attachment14Data.DisplayName = attachment.DisplayName;
            }
            if (string.IsNullOrEmpty(attachment14Data.DisplayName))
            {
                if (!string.IsNullOrEmpty(attachment.FileName))
                {
                    attachment14Data.DisplayName = attachment.FileName;
                    if (attachment.AttachmentType == AttachmentType.Ole && attachment.DisplayName.LastIndexOf('.') < 0)
                    {
                        Attachment14Data attachment14Data2 = attachment14Data;
                        attachment14Data2.DisplayName += ".jpg";
                    }
                }
                else if (attachment.AttachmentType == AttachmentType.EmbeddedMessage)
                {
                    using (Item itemAsReadOnly = ((ItemAttachment)attachment).GetItemAsReadOnly(null))
                    {
                        attachment14Data.DisplayName = (itemAsReadOnly.TryGetProperty(ItemSchema.Subject) as string);
                    }
                }
            }
            if (string.IsNullOrEmpty(attachment14Data.DisplayName))
            {
                attachment14Data.DisplayName = "????";
            }
            AirSyncDiagnostics.TraceDebug <int, string>(ExTraceGlobals.XsoTracer, this, "Attachment {0}, display name {1}", index, attachment14Data.DisplayName);
            attachment14Data.FileReference     = HttpUtility.UrlEncode(idbase + ":" + index);
            attachment14Data.Method            = Convert.ToByte((int)attachment.TryGetProperty(AttachmentSchema.AttachMethod));
            attachment14Data.EstimatedDataSize = attachment.Size;
            if (attachment.IsInline)
            {
                if (string.IsNullOrEmpty(attachment.ContentId))
                {
                    attachment14Data.ContentId = Guid.NewGuid().ToString();
                }
                else
                {
                    attachment14Data.ContentId = attachment.ContentId;
                }
            }
            if (attachment.ContentLocation != null)
            {
                attachment14Data.ContentLocation = attachment.ContentLocation.ToString();
            }
            if (!BodyConversionUtilities.IsMessageRestrictedAndDecoded(message))
            {
                attachment14Data.IsInline = attachment.IsInline;
            }
            return(attachment14Data);
        }
        // Token: 0x06001447 RID: 5191 RVA: 0x00074CF4 File Offset: 0x00072EF4
        public Stream GetData(BodyType type, long truncationSize, out long totalDataSize, out IEnumerable <AirSyncAttachmentInfo> attachments)
        {
            Item item = base.XsoItem as Item;

            attachments = null;
            if (item == null)
            {
                totalDataSize = 0L;
                return(null);
            }
            IList <AttachmentLink> list = null;
            Stream stream;

            if (string.Equals(item.ClassName, "IPM.Note.SMIME", StringComparison.OrdinalIgnoreCase) && truncationSize != 0L)
            {
                switch (type)
                {
                case BodyType.PlainText:
                {
                    string s = Strings.SMIMENotSupportedBodyText.ToString(item.Session.PreferedCulture);
                    stream        = new MemoryStream(Encoding.UTF8.GetBytes(s));
                    totalDataSize = stream.Length;
                    return(stream);
                }

                case BodyType.Html:
                {
                    string s = XsoContentProperty.GetSMIMENotSupportedBodyHtml(item.Session);
                    stream        = new MemoryStream(Encoding.UTF8.GetBytes(s));
                    totalDataSize = stream.Length;
                    return(stream);
                }
                }
            }
            switch (type)
            {
            case BodyType.None:
                throw new ConversionException("Invalid body type requested");

            case BodyType.PlainText:
                stream = BodyConversionUtilities.ConvertToPlainTextStream(item, truncationSize, out totalDataSize, out list);
                break;

            case BodyType.Html:
                stream = BodyConversionUtilities.ConvertHtmlStream(item, truncationSize, out totalDataSize, out list);
                break;

            case BodyType.Rtf:
                return(this.GetRtfData(truncationSize, out totalDataSize, out list));

            case BodyType.Mime:
                throw new ConversionException("Invalid body type requested");

            default:
                stream        = null;
                totalDataSize = 0L;
                break;
            }
            if (list != null)
            {
                attachments = from attachmentLink in list
                              select new AirSyncAttachmentInfo
                {
                    AttachmentId = attachmentLink.AttachmentId,
                    IsInline     = (attachmentLink.IsMarkedInline ?? attachmentLink.IsOriginallyInline),
                    ContentId    = attachmentLink.ContentId
                };
            }
            return(stream);
        }