Ejemplo n.º 1
0
        public void IrmDecryptIfRestricted()
        {
            if (!Utilities.IsIrmRestricted(this.message))
            {
                return;
            }
            RightsManagedMessageItem rightsManagedMessageItem = (RightsManagedMessageItem)this.message;

            if (!this.userContext.IsIrmEnabled)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled;
                return;
            }
            if (!rightsManagedMessageItem.CanDecode)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.NotSupported;
                return;
            }
            try
            {
                Utilities.IrmDecryptIfRestricted(this.message, this.userContext, !this.isPreviewForm);
            }
            catch (MissingRightsManagementLicenseException ex)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(ex);
                if (!Utilities.IsPrefetchRequest(OwaContext.Current) && !this.isEmbeddedItem && ex.MessageStoreId != null && !string.IsNullOrEmpty(ex.PublishLicense))
                {
                    OwaStoreObjectId messageId = OwaStoreObjectId.CreateFromItemId(ex.MessageStoreId, null, ex.MessageInArchive ? OwaStoreObjectIdType.ArchiveMailboxObject : OwaStoreObjectIdType.MailBoxObject, ex.MailboxOwnerLegacyDN);
                    this.userContext.AsyncAcquireIrmLicenses(messageId, ex.PublishLicense, ex.RequestCorrelator);
                }
            }
            catch (RightsManagementPermanentException exception)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception);
            }
            catch (RightsManagementTransientException exception2)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception2);
            }
        }
Ejemplo n.º 2
0
        private void IrmDecryptIfRestricted()
        {
            if (!Utilities.IsIrmRestricted(this.message))
            {
                return;
            }
            RightsManagedMessageItem rightsManagedMessageItem = (RightsManagedMessageItem)this.message;

            if (!base.UserContext.IsIrmEnabled)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled;
                return;
            }
            if (!rightsManagedMessageItem.CanDecode)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.NotSupported;
                return;
            }
            try
            {
                if (Utilities.IrmDecryptIfRestricted(this.message, base.UserContext, true))
                {
                    RightsManagedMessageItem rightsManagedMessageItem2 = (RightsManagedMessageItem)this.message;
                    if (!rightsManagedMessageItem2.UsageRights.IsUsageRightGranted(ContentRight.Print))
                    {
                        this.irmDecryptionStatus = new RightsManagedMessageDecryptionStatus(RightsManagementFailureCode.UserRightNotGranted, null);
                    }
                }
            }
            catch (RightsManagementPermanentException exception)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception);
            }
            catch (RightsManagementTransientException exception2)
            {
                this.irmDecryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception2);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        internal static void SetAlternateIrmBody(Item item, BodyFormat bodyFormat, UserContext userContext, StoreObjectId parentFolderId, RightsManagedMessageDecryptionStatus decryptionStatus, bool isProtectedVoicemail)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            if (parentFolderId == null)
            {
                throw new ArgumentNullException("parentFolderId");
            }
            if (!decryptionStatus.Failed)
            {
                return;
            }
            string text = ReplyForwardUtilities.CreateReplyForwardHeader(bodyFormat, item, userContext, parentFolderId);

            text += Utilities.GetAlternateBodyForIrm(userContext, bodyFormat, decryptionStatus, isProtectedVoicemail);
            ItemUtility.SetItemBody(item, bodyFormat, text);
        }
Ejemplo n.º 5
0
        // Token: 0x06000C4C RID: 3148 RVA: 0x00040FE8 File Offset: 0x0003F1E8
        private void IrmRemoveRestriction(Item item)
        {
            if (!Command.CurrentCommand.Context.User.IrmEnabled || !Command.CurrentCommand.Context.Request.IsSecureConnection)
            {
                AirSyncDiagnostics.TraceError <string, bool, bool>(ExTraceGlobals.RequestsTracer, null, "User {0} is not IrmEnabled or the client access server is not IrmEnabled or request received over non SSL. IrmEnabled: {1}, SSLConnection: {2}.", Command.CurrentCommand.Context.User.DisplayName, Command.CurrentCommand.Context.User.IrmEnabled, Command.CurrentCommand.Context.Request.IsSecureConnection);
                throw new AirSyncPermanentException(StatusCode.IRM_FeatureDisabled, false)
                      {
                          ErrorStringForProtocolLogger = "RemoveRestrictionFeatureDisabled"
                      };
            }
            if (AirSyncUtility.IsProtectedVoicemailItem(item))
            {
                AirSyncDiagnostics.TraceError <string>(ExTraceGlobals.RequestsTracer, null, "User {0} called remove restrictions on protected voice mail - not supported", Command.CurrentCommand.Context.User.DisplayName);
                throw new AirSyncPermanentException(StatusCode.IRM_OperationNotPermitted, false)
                      {
                          ErrorStringForProtocolLogger = "RemoveRestrictionOnProtectedVoicemail"
                      };
            }
            RightsManagedMessageItem rightsManagedMessageItem = item as RightsManagedMessageItem;

            if (rightsManagedMessageItem == null)
            {
                AirSyncDiagnostics.TraceError <string>(ExTraceGlobals.RequestsTracer, null, "User {0} called remove restrictions on non IRM message", Command.CurrentCommand.Context.User.DisplayName);
                throw new AirSyncPermanentException(StatusCode.IRM_OperationNotPermitted, false)
                      {
                          ErrorStringForProtocolLogger = "RemoveRestrictionOnNonIRMMessage"
                      };
            }
            rightsManagedMessageItem.OpenAsReadWrite();
            RightsManagedMessageDecryptionStatus rightsManagedMessageDecryptionStatus = RightsManagedMessageDecryptionStatus.Success;

            try
            {
                rightsManagedMessageItem.Decode(AirSyncUtility.GetOutboundConversionOptions(), true);
            }
            catch (RightsManagementPermanentException exception)
            {
                rightsManagedMessageDecryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception);
            }
            catch (RightsManagementTransientException exception2)
            {
                rightsManagedMessageDecryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception2);
            }
            if (rightsManagedMessageDecryptionStatus.Failed)
            {
                AirSyncDiagnostics.TraceError <string>(ExTraceGlobals.RequestsTracer, null, "Failed to decode item : {0}", rightsManagedMessageDecryptionStatus.FailureCode.ToString());
                throw new AirSyncPermanentException(StatusCode.IRM_PermanentError, rightsManagedMessageDecryptionStatus.Exception, false)
                      {
                          ErrorStringForProtocolLogger = "RemoveRestrictionDecodeFailed"
                      };
            }
            try
            {
                rightsManagedMessageItem.SetRestriction(null);
            }
            catch (RightsManagementPermanentException ex)
            {
                if (ex.FailureCode == RightsManagementFailureCode.UserRightNotGranted)
                {
                    AirSyncDiagnostics.TraceError <string>(ExTraceGlobals.RequestsTracer, null, "Failed to remove restrictions on item : {0}", ex.ToString());
                    throw new AirSyncPermanentException(StatusCode.IRM_OperationNotPermitted, ex, false)
                          {
                              ErrorStringForProtocolLogger = "RemoveRestrictionRightNotGranted"
                          };
                }
                throw;
            }
            ConflictResolutionResult conflictResolutionResult = rightsManagedMessageItem.Save(SaveMode.ResolveConflicts);

            if (conflictResolutionResult.SaveStatus == SaveResult.IrresolvableConflict)
            {
                AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, null, "Failed to remove restrictions on item because of conflicts");
                throw new AirSyncPermanentException(StatusCode.IRM_PermanentError, false)
                      {
                          ErrorStringForProtocolLogger = "RemoveRestrictionConflict"
                      };
            }
            item.Load();
        }
Ejemplo n.º 6
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);
        }
        private Stream LoadAttachmentDocument(bool isLoadingStream, out RightsManagedMessageDecryptionStatus decryptionStatus)
        {
            decryptionStatus = RightsManagedMessageDecryptionStatus.Success;
            StringBuilder       stringBuilder     = new StringBuilder();
            List <AttachmentId> list              = new List <AttachmentId>();
            UserContext         userContext       = this.owaContext.UserContext;
            string           queryStringParameter = Utilities.GetQueryStringParameter(this.owaContext.HttpContext.Request, "ewsid", false);
            bool             flag = string.IsNullOrEmpty(queryStringParameter);
            OwaStoreObjectId owaStoreObjectId;
            string           text;

            if (!flag)
            {
                stringBuilder.Append("service.svc/s/GetFileAttachment?id=");
                stringBuilder.Append(Utilities.UrlEncode(queryStringParameter));
                string canary15CookieValue = Utilities.GetCanary15CookieValue();
                if (canary15CookieValue != null)
                {
                    stringBuilder.Append("&X-OWA-CANARY=" + canary15CookieValue);
                }
                IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(queryStringParameter, BasicTypes.Attachment, list);
                owaStoreObjectId = OwaStoreObjectId.CreateFromMailboxItemId(idHeaderInformation.ToStoreObjectId());
                text             = owaStoreObjectId.ToString();
            }
            else
            {
                text             = Utilities.GetQueryStringParameter(this.owaContext.HttpContext.Request, "id");
                owaStoreObjectId = OwaStoreObjectId.CreateFromString(text);
                stringBuilder.Append("attachment.ashx?attach=1&id=");
                stringBuilder.Append(Utilities.UrlEncode(text));
            }
            Stream result;

            using (Item item = Utilities.GetItem <Item>(userContext, owaStoreObjectId, new PropertyDefinition[]
            {
                ItemSchema.SentRepresentingDisplayName,
                ItemSchema.Subject
            }))
            {
                if (!Utilities.IsPublic(item) && userContext.IsIrmEnabled && isLoadingStream)
                {
                    item.OpenAsReadWrite();
                }
                if (Utilities.IsIrmRestricted(item))
                {
                    if (!userContext.IsIrmEnabled || userContext.IsBasicExperience)
                    {
                        decryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled;
                        return(null);
                    }
                    RightsManagedMessageItem rightsManagedMessageItem = (RightsManagedMessageItem)item;
                    if (!rightsManagedMessageItem.CanDecode)
                    {
                        decryptionStatus = RightsManagedMessageDecryptionStatus.NotSupported;
                        return(null);
                    }
                    try
                    {
                        Utilities.IrmDecryptIfRestricted(item, userContext, true);
                    }
                    catch (RightsManagementPermanentException exception)
                    {
                        decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception);
                        return(null);
                    }
                    catch (RightsManagementTransientException exception2)
                    {
                        decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception2);
                        return(null);
                    }
                }
                this.messageFrom    = ItemUtility.GetProperty <string>(item, ItemSchema.SentRepresentingDisplayName, string.Empty);
                this.messageSubject = ItemUtility.GetProperty <string>(item, ItemSchema.Subject, string.Empty);
                this.messageId      = text;
                if (flag)
                {
                    Utilities.FillAttachmentIdList(item, this.owaContext.HttpContext.Request, list);
                }
                using (StreamAttachment streamAttachment = Utilities.GetAttachment(item, list, userContext) as StreamAttachment)
                {
                    if (streamAttachment == null)
                    {
                        throw new OwaInvalidRequestException("Attachment is not a stream attachment");
                    }
                    this.mimeType     = (streamAttachment.ContentType ?? streamAttachment.CalculatedContentType);
                    this.fileName     = ((!string.IsNullOrEmpty(streamAttachment.DisplayName)) ? streamAttachment.DisplayName : streamAttachment.FileName);
                    this.fileSize     = streamAttachment.Size;
                    this.documentPath = this.fileName;
                    this.documentIdStringBuilder.Append(Convert.ToBase64String(userContext.MailboxSession.MailboxOwner.MailboxInfo.GetDatabaseGuid().ToByteArray()));
                    this.documentIdStringBuilder.Append("-");
                    for (int i = 0; i < list.Count; i++)
                    {
                        this.documentIdStringBuilder.Append(list[i].ToBase64String());
                        this.documentIdStringBuilder.Append("-");
                        if (flag)
                        {
                            stringBuilder.Append("&attid");
                            stringBuilder.Append(i.ToString(CultureInfo.InstalledUICulture));
                            stringBuilder.Append("=");
                            stringBuilder.Append(Utilities.UrlEncode(list[i].ToBase64String()));
                        }
                    }
                    if (flag)
                    {
                        stringBuilder.Append("&attcnt=");
                        stringBuilder.Append(list.Count);
                    }
                    this.documentIdStringBuilder.Append(streamAttachment.LastModifiedTime.UtcTicks);
                    this.openLink = stringBuilder.ToString();
                    if (isLoadingStream)
                    {
                        Stream       contentStream = streamAttachment.GetContentStream();
                        MsoIpiResult msoIpiResult  = MsoIpiResult.Unknown;
                        try
                        {
                            msoIpiResult = ProtectorsManager.Instance.IsProtected(this.fileName, contentStream);
                        }
                        catch (AttachmentProtectionException exception3)
                        {
                            decryptionStatus = new RightsManagedMessageDecryptionStatus(RightsManagementFailureCode.CorruptData, exception3);
                            return(null);
                        }
                        if (msoIpiResult == MsoIpiResult.Protected)
                        {
                            this.isIrmProtected = true;
                            contentStream.Dispose();
                            if (!userContext.IsIrmEnabled || userContext.IsBasicExperience)
                            {
                                decryptionStatus = RightsManagedMessageDecryptionStatus.FeatureDisabled;
                                result           = null;
                            }
                            else
                            {
                                UseLicenseAndUsageRights useLicenseAndUsageRights;
                                bool   flag2;
                                Stream stream;
                                try
                                {
                                    stream = StreamAttachment.OpenRestrictedAttachment(streamAttachment, this.owaContext.ExchangePrincipal.MailboxInfo.OrganizationId, this.owaContext.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), this.owaContext.LogonIdentity.UserSid, this.owaContext.ExchangePrincipal.RecipientTypeDetails, out useLicenseAndUsageRights, out flag2);
                                }
                                catch (RightsManagementPermanentException exception4)
                                {
                                    decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception4);
                                    return(null);
                                }
                                catch (RightsManagementTransientException exception5)
                                {
                                    decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception5);
                                    return(null);
                                }
                                if (flag2 && ObjectClass.IsMessage(item.ClassName, false) && !Utilities.IsIrmRestricted(item))
                                {
                                    object obj = item.TryGetProperty(MessageItemSchema.IsDraft);
                                    if (obj is bool && !(bool)obj && !DrmClientUtils.IsCachingOfLicenseDisabled(useLicenseAndUsageRights.UseLicense))
                                    {
                                        streamAttachment[AttachmentSchema.DRMRights]     = useLicenseAndUsageRights.UsageRights;
                                        streamAttachment[AttachmentSchema.DRMExpiryTime] = useLicenseAndUsageRights.ExpiryTime;
                                        using (Stream stream2 = streamAttachment.OpenPropertyStream(AttachmentSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create))
                                        {
                                            DrmEmailCompression.CompressUseLicense(useLicenseAndUsageRights.UseLicense, stream2);
                                        }
                                        streamAttachment[AttachmentSchema.DRMPropsSignature] = useLicenseAndUsageRights.DRMPropsSignature;
                                        streamAttachment.Save();
                                        item.Save(SaveMode.ResolveConflicts);
                                    }
                                }
                                string      conversationOwnerFromPublishLicense = DrmClientUtils.GetConversationOwnerFromPublishLicense(useLicenseAndUsageRights.PublishingLicense);
                                RmsTemplate rmsTemplate = RmsTemplate.CreateFromPublishLicense(useLicenseAndUsageRights.PublishingLicense);
                                this.isPrintRestricted = !useLicenseAndUsageRights.UsageRights.IsUsageRightGranted(ContentRight.Print);
                                this.isCopyRestricted  = !useLicenseAndUsageRights.UsageRights.IsUsageRightGranted(ContentRight.Extract);
                                SanitizingStringBuilder <OwaHtml> sanitizingStringBuilder = new SanitizingStringBuilder <OwaHtml>();
                                string str = string.Format(LocalizedStrings.GetNonEncoded(-500320626), rmsTemplate.Name, rmsTemplate.Description);
                                sanitizingStringBuilder.Append(str);
                                if (!string.IsNullOrEmpty(conversationOwnerFromPublishLicense))
                                {
                                    sanitizingStringBuilder.Append("<br>");
                                    sanitizingStringBuilder.Append(string.Format(LocalizedStrings.GetNonEncoded(1670455506), conversationOwnerFromPublishLicense));
                                }
                                this.irmInfobarMessage = sanitizingStringBuilder.ToSanitizedString <SanitizedHtmlString>();
                                result = stream;
                            }
                        }
                        else
                        {
                            contentStream.Seek(0L, SeekOrigin.Begin);
                            result = contentStream;
                        }
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
        private static SanitizedHtmlString GetIrmErrorDetails(UserContext userContext, RightsManagedMessageDecryptionStatus decryptionStatus)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            SanitizingStringBuilder <OwaHtml> sanitizingStringBuilder = new SanitizingStringBuilder <OwaHtml>();
            RightsManagementFailureCode       failureCode             = decryptionStatus.FailureCode;

            if (failureCode > RightsManagementFailureCode.PreLicenseAcquisitionFailed)
            {
                switch (failureCode)
                {
                case RightsManagementFailureCode.FailedToExtractTargetUriFromMex:
                case RightsManagementFailureCode.FailedToDownloadMexData:
                    sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-843834599));
                    goto IL_308;

                case RightsManagementFailureCode.GetServerInfoFailed:
                    goto IL_19E;

                case RightsManagementFailureCode.InternalLicensingDisabled:
                    break;

                case RightsManagementFailureCode.ExternalLicensingDisabled:
                    sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(-641698444), new object[]
                    {
                        WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                    });
                    goto IL_308;

                default:
                    switch (failureCode)
                    {
                    case RightsManagementFailureCode.ServerRightNotGranted:
                        sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-271360565));
                        goto IL_308;

                    case RightsManagementFailureCode.InvalidLicensee:
                        goto IL_189;

                    case RightsManagementFailureCode.FeatureDisabled:
                        break;

                    case RightsManagementFailureCode.NotSupported:
                        sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(-1308596751), new object[]
                        {
                            WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                        });
                        goto IL_308;

                    case RightsManagementFailureCode.CorruptData:
                        sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-987520932));
                        goto IL_308;

                    default:
                        if (failureCode != RightsManagementFailureCode.Success)
                        {
                            goto IL_19E;
                        }
                        goto IL_308;
                    }
                    break;
                }
                sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(-1308596751), new object[]
                {
                    WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                });
                goto IL_308;
            }
            if (failureCode == RightsManagementFailureCode.UserRightNotGranted)
            {
                sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetNonEncoded(149546568), new object[]
                {
                    WebReadyViewUtilities.GetOfficeDownloadAnchor(userContext.UserCulture)
                });
                goto IL_308;
            }
            if (failureCode != RightsManagementFailureCode.PreLicenseAcquisitionFailed)
            {
                goto IL_19E;
            }
IL_189:
            sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-492186842));
            goto IL_308;
IL_19E:
            sanitizingStringBuilder.Append(LocalizedStrings.GetNonEncoded(-624237727));
            Exception exception = decryptionStatus.Exception;

            if (Globals.ShowDebugInformation && exception != null && exception.InnerException != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                userContext.RenderThemeImage(stringBuilder, ThemeFileId.Expand, string.Empty, new object[0]);
                sanitizingStringBuilder.AppendFormat("<div onclick=\"document.getElementById('divDtls').style.display='';this.style.display='none';adjHght();\" style=\"cursor: pointer; color: #3165cd;\">" + stringBuilder.ToString() + "&nbsp;{0}</div><div id=\"divDtls\" style='display:none'>", new object[]
                {
                    LocalizedStrings.GetNonEncoded(-610047827)
                });
                string text = string.Empty;
                RightsManagementFailureCode failureCode2 = decryptionStatus.FailureCode;
                Exception innerException = exception.InnerException;
                if (innerException is RightsManagementException)
                {
                    RightsManagementException ex = (RightsManagementException)innerException;
                    text = ex.RmsUrl;
                }
                int num = 0;
                while (num < 10 && innerException.InnerException != null)
                {
                    innerException = innerException.InnerException;
                    num++;
                }
                sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetHtmlEncoded(1633606253), new object[]
                {
                    innerException.Message
                });
                if (!string.IsNullOrEmpty(text))
                {
                    sanitizingStringBuilder.Append("<br>");
                    sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetHtmlEncoded(2115316283), new object[]
                    {
                        text
                    });
                }
                if (failureCode2 != RightsManagementFailureCode.Success)
                {
                    sanitizingStringBuilder.Append("<br>");
                    sanitizingStringBuilder.AppendFormat(LocalizedStrings.GetHtmlEncoded(970140031), new object[]
                    {
                        failureCode2
                    });
                }
                sanitizingStringBuilder.Append("</div>");
            }
IL_308:
            return(sanitizingStringBuilder.ToSanitizedString <SanitizedHtmlString>());
        }
        public Stream LoadDocument(bool isLoadingStream, out RightsManagedMessageDecryptionStatus decryptionStatus)
        {
            decryptionStatus             = RightsManagedMessageDecryptionStatus.Success;
            this.documentIdStringBuilder = new StringBuilder();
            string queryStringParameter  = Utilities.GetQueryStringParameter(this.owaContext.HttpContext.Request, "t");
            string queryStringParameter2 = Utilities.GetQueryStringParameter(this.owaContext.HttpContext.Request, "pn", false);

            if (string.IsNullOrEmpty(queryStringParameter2))
            {
                this.currentPageNumber = 1;
            }
            else if (!int.TryParse(queryStringParameter2, out this.currentPageNumber) || this.currentPageNumber < 0)
            {
                throw new OwaInvalidRequestException("The page number is invalid");
            }
            Stream result;

            if (queryStringParameter.Equals("wss"))
            {
                result = this.LoadWSSDocument(isLoadingStream);
            }
            else if (queryStringParameter.Equals("unc"))
            {
                result = this.LoadUNCDocument(isLoadingStream);
            }
            else
            {
                if (!queryStringParameter.Equals("att"))
                {
                    throw new OwaInvalidRequestException("The type(t) parameter is invalid");
                }
                result = this.LoadAttachmentDocument(isLoadingStream, out decryptionStatus);
            }
            if (this.mimeType == null || this.mimeType.Equals("application/octet-stream", StringComparison.OrdinalIgnoreCase))
            {
                this.mimeType = string.Empty;
            }
            if (string.IsNullOrEmpty(this.fileName))
            {
                this.fileName = LocalizedStrings.GetNonEncoded(1797976510);
            }
            int num = this.fileName.LastIndexOf('.');

            if (num > 0)
            {
                this.fileExtension = this.fileName.Substring(num);
            }
            else
            {
                this.fileExtension = string.Empty;
            }
            if (this.fileExtension == null)
            {
                this.fileExtension = string.Empty;
            }
            if (!OwaRegistryKeys.WebReadyDocumentViewingWithInlineImage)
            {
                this.isSupportPaging = false;
            }
            else if (!string.IsNullOrEmpty(this.fileExtension))
            {
                this.isSupportPaging = (Array.IndexOf <string>(WebReadyViewUtilities.wordFileType, this.fileExtension.ToLowerInvariant()) < 0);
            }
            else
            {
                this.isSupportPaging = (Array.IndexOf <string>(WebReadyViewUtilities.wordFileType, this.mimeType.ToLowerInvariant()) < 0);
            }
            return(result);
        }