// Token: 0x06001AD3 RID: 6867 RVA: 0x00065D98 File Offset: 0x00063F98
        private static IdAndSession GetIdAndSession(CallContext callContext, string id, bool isAttachmentId)
        {
            IdAndSession idAndSession;

            try
            {
                if (isAttachmentId)
                {
                    idAndSession = new IdConverter(callContext).ConvertAttachmentIdToIdAndSessionReadOnly(id);
                }
                else
                {
                    idAndSession = new IdConverter(callContext).ConvertItemIdToIdAndSessionReadOnly(id);
                }
                if (idAndSession == null)
                {
                    List <AttachmentId> attachmentIds       = new List <AttachmentId>();
                    IdHeaderInformation idHeaderInformation = IdConverter.ConvertFromConcatenatedId(id, BasicTypes.Attachment, attachmentIds, false);
                    throw new OwaInvalidRequestException("Unsupported Attachment ID. Storage type: " + idHeaderInformation.IdStorageType);
                }
            }
            catch (InvalidStoreIdException)
            {
                throw new OwaInvalidRequestException("Invalid attachment ID: " + id);
            }
            catch (AccessDeniedException)
            {
                throw new OwaInvalidRequestException("You do not have permission to access this mailbox.");
            }
            if (idAndSession.Session == null)
            {
                throw new OwaInvalidRequestException("The mailbox was not specified.");
            }
            return(idAndSession);
        }
Example #2
0
        internal static void ReplaceAttachmentContent(string smtpAddress, string cultureName, string ewsAttachmentID, bool isArchive, Stream source)
        {
            ADSessionSettings   adsessionSettings;
            ExchangePrincipal   exchangePrincipal   = WacUtilities.GetExchangePrincipal(smtpAddress, out adsessionSettings, isArchive);
            CultureInfo         cultureInfo         = CultureInfo.GetCultureInfo(cultureName);
            List <AttachmentId> attachmentIds       = new List <AttachmentId>();
            IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(ewsAttachmentID, BasicTypes.Attachment, attachmentIds);

            idHeaderInformation.ToStoreObjectId();
            using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(exchangePrincipal, cultureInfo, "Client=OWA;Action=WAC"))
            {
                WacUtilities.ProcessAttachment(mailboxSession, ewsAttachmentID, exchangePrincipal, PropertyOpenMode.Modify, delegate(IExchangePrincipal principal, Attachment attachment, Stream stream, bool anyContentProtected)
                {
                    BinaryReader binaryReader = new BinaryReader(source);
                    stream.Seek(0L, SeekOrigin.Begin);
                    int num       = 10000;
                    int num2      = 0;
                    byte[] buffer = new byte[num];
                    for (;;)
                    {
                        int num3 = binaryReader.Read(buffer, 0, num);
                        num2    += num3;
                        if (num3 == 0)
                        {
                            break;
                        }
                        stream.Write(buffer, 0, num3);
                    }
                    stream.SetLength((long)num2);
                    attachment.Save();
                });
            }
        }
Example #3
0
        internal static StoreObjectId GetStoreObjectId(string ewsAttachmentId)
        {
            List <AttachmentId> attachmentIds       = new List <AttachmentId>();
            IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(ewsAttachmentId, BasicTypes.Attachment, attachmentIds);

            return(idHeaderInformation.ToStoreObjectId());
        }
Example #4
0
        private AttachmentRetriever(string id, IdConverterDependencies converterDependencies)
        {
            bool flag = false;

            try
            {
                ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "Initialize IdAndSession to get attachment, id = {0}", id);
                List <AttachmentId> attachmentIds     = new List <AttachmentId>();
                IdHeaderInformation headerInformation = ServiceIdConverter.ConvertFromConcatenatedId(id, BasicTypes.ItemOrAttachment, attachmentIds);
                Item         item = null;
                IdAndSession idAndSession;
                try
                {
                    idAndSession = IdConverter.ConvertId(converterDependencies, headerInformation, IdConverter.ConvertOption.IgnoreChangeKey | IdConverter.ConvertOption.NoBind, BasicTypes.ItemOrAttachment, attachmentIds, null, this.GetHashCode(), false, ref item);
                }
                finally
                {
                    if (item != null)
                    {
                        item.Dispose();
                        item = null;
                    }
                }
                this.attachmentHierarchy = new AttachmentHierarchy(idAndSession, false, true);
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    this.Dispose();
                }
            }
        }
        private static VersionedId EwsIdToVersionedId(string ewsId, string changeKey, out MailboxId mailboxId)
        {
            IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(ewsId, BasicTypes.Item, null);

            mailboxId = idHeaderInformation.MailboxId;
            byte[]          byteArrayChangeKey;
            StoreObjectType objectType;

            WebServiceMailboxSearchGroup.ParseChangeKeyString(changeKey, out byteArrayChangeKey, out objectType);
            return(VersionedId.Deserialize(idHeaderInformation.StoreIdBytes, byteArrayChangeKey, objectType));
        }
Example #6
0
        public static string GetOwnerIdForMailbox(string ewsAttachmentId)
        {
            IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(ewsAttachmentId, BasicTypes.Attachment, null);

            return("ExchangeMbx_" + idHeaderInformation.MailboxId.MailboxGuid);
        }
        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);
        }