internal static string GetAttachment(MailboxSession mailboxSession, string attachmentId, Stream outStream, int offset, int count, Unlimited <ByteQuantifiedSize> maxAttachmentSize, ItemIdMapping idmapping, bool rightsManagementSupport, out int total)
        {
            string[] array = attachmentId.Split(new char[]
            {
                ':'
            });
            if (array.Length != 2 && array.Length != 3)
            {
                return(AttachmentHelper.GetAttachmentByUrlCompName(mailboxSession, attachmentId, outStream, offset, count, maxAttachmentSize, out total));
            }
            StoreObjectId itemId;
            string        text;

            if (array.Length == 2)
            {
                itemId = AttachmentHelper.GetItemId(array[0]);
                text   = array[1];
            }
            else
            {
                itemId = AttachmentHelper.GetItemId(idmapping, array[0], array[1]);
                text   = array[2];
            }
            if (itemId == null)
            {
                throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentId));
            }
            AirSyncDiagnostics.TraceDebug <StoreObjectId, string>(ExTraceGlobals.RequestsTracer, null, "Getting attachment with itemId {0} and attachmentIndex {1}.", itemId, text);
            return(AttachmentHelper.GetAttachment(mailboxSession, itemId, text, outStream, offset, count, maxAttachmentSize, rightsManagementSupport, out total));
        }
        // Token: 0x06000C3C RID: 3132 RVA: 0x00040194 File Offset: 0x0003E394
        protected override int InternalExecute(int count)
        {
            FolderSyncState folderSyncState = null;
            int             result;

            try
            {
                string        text          = HttpUtility.UrlDecode(base.FileReference);
                int           num           = text.IndexOf(':');
                ItemIdMapping itemIdMapping = null;
                if (num != -1 && num != text.LastIndexOf(':'))
                {
                    string text2 = text.Substring(0, num);
                    SyncCollection.CollectionTypes collectionType = AirSyncUtility.GetCollectionType(text2);
                    if (collectionType != SyncCollection.CollectionTypes.Mailbox && collectionType != SyncCollection.CollectionTypes.Unknown)
                    {
                        base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NoAttachmentsOnVItem");
                        AirSyncPermanentException ex = new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.InvalidCombinationOfIDs, null, false);
                        throw ex;
                    }
                    folderSyncState = base.SyncStateStorage.GetFolderSyncState(new MailboxSyncProviderFactory(base.Session), text2);
                    if (folderSyncState == null)
                    {
                        throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(text));
                    }
                    itemIdMapping = (ItemIdMapping)folderSyncState[CustomStateDatumType.IdMapping];
                    if (itemIdMapping == null)
                    {
                        throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(text));
                    }
                }
                int num2;
                base.ContentType = AttachmentHelper.GetAttachment(base.Session, text, base.OutStream, base.MinRange, count, base.MaxAttachmentSize, itemIdMapping, base.RightsManagementSupport, out num2);
                result           = num2;
            }
            finally
            {
                if (folderSyncState != null)
                {
                    folderSyncState.Dispose();
                    folderSyncState = null;
                }
            }
            return(result);
        }
Exemple #3
0
        // Token: 0x06000767 RID: 1895 RVA: 0x00029340 File Offset: 0x00027540
        protected override int InternalExecute(int count)
        {
            string[] array = HttpUtility.UrlDecode(base.FileReference).Split(new char[]
            {
                ':'
            });
            if (array.Length != 2)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_TooManyFolders, false)
                      {
                          ErrorStringForProtocolLogger = "InvalidEntityAttachemtnId"
                      };
            }
            StoreObjectId itemId = StoreId.EwsIdToStoreObjectId(array[0]);
            IEvents       events = EntitySyncItem.GetEvents(this.CalendaringContainer, base.Session, itemId);

            if (events == null)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, false)
                      {
                          ErrorStringForProtocolLogger = "EventsNotFound"
                      };
            }
            IAttachments attachments = events[array[0]].Attachments;

            if (attachments == null)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, false)
                      {
                          ErrorStringForProtocolLogger = "EntityNotFound"
                      };
            }
            IAttachment attachment = attachments.Read(array[1], null);

            if (attachment == null)
            {
                throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, false)
                      {
                          ErrorStringForProtocolLogger = "EntityAttachementNotFound"
                      };
            }
            base.ContentType = attachment.ContentType;
            FileAttachment fileAttachment = attachment as FileAttachment;
            ItemAttachment itemAttachment = attachment as ItemAttachment;

            if (fileAttachment != null)
            {
                if (!base.MaxAttachmentSize.IsUnlimited && fileAttachment.Content.Length > (int)base.MaxAttachmentSize.Value.ToBytes())
                {
                    throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge);
                }
                count = ((count == -1) ? fileAttachment.Content.Length : Math.Min(count, fileAttachment.Content.Length - base.MinRange));
                base.OutStream.Write(fileAttachment.Content, base.MinRange, count);
                return(count);
            }
            else
            {
                if (itemAttachment != null)
                {
                    int result;
                    AttachmentHelper.GetAttachment(base.Session, itemId, attachment.Id, base.OutStream, base.MinRange, count, base.MaxAttachmentSize, base.RightsManagementSupport, out result);
                    return(result);
                }
                throw new AirSyncPermanentException(StatusCode.Sync_InvalidWaitTime, new LocalizedString(string.Format("Attachment type \"{0}\" is not supported.", attachment.GetType().FullName)), false)
                      {
                          ErrorStringForProtocolLogger = "UnsupportedEntityAttachementType"
                      };
            }
        }
        internal override Command.ExecutionState ExecuteCommand()
        {
            string          attachmentName  = this.AttachmentName;
            string          value           = string.Empty;
            FolderSyncState folderSyncState = null;

            AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "GetAttachmentCommand.Execute(). AttachmentName: '{0}'", attachmentName);
            try
            {
                int incBy = 0;
                if (base.Request.ContentType != null && !string.Equals(base.Request.ContentType, "message/rfc822", StringComparison.OrdinalIgnoreCase))
                {
                    base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidContentType");
                    throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.First140Error, null, false);
                }
                int           num           = attachmentName.IndexOf(':');
                ItemIdMapping itemIdMapping = null;
                if (num != -1 && num != attachmentName.LastIndexOf(':'))
                {
                    folderSyncState = base.SyncStateStorage.GetFolderSyncState(new MailboxSyncProviderFactory(base.MailboxSession), attachmentName.Substring(0, num));
                    if (folderSyncState == null)
                    {
                        throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentName));
                    }
                    itemIdMapping = (ItemIdMapping)folderSyncState[CustomStateDatumType.IdMapping];
                    if (itemIdMapping == null)
                    {
                        throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentName));
                    }
                }
                PolicyData policyData = ADNotificationManager.GetPolicyData(base.User);
                if (policyData != null && !policyData.AttachmentsEnabled)
                {
                    base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AttachmentsNotEnabledGetAttCmd");
                    throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, null, false);
                }
                Unlimited <ByteQuantifiedSize> maxAttachmentSize = (policyData != null) ? policyData.MaxAttachmentSize : Unlimited <ByteQuantifiedSize> .UnlimitedValue;
                value = AttachmentHelper.GetAttachment(base.MailboxSession, attachmentName, base.OutputStream, maxAttachmentSize, itemIdMapping, out incBy);
                base.ProtocolLogger.IncrementValue(ProtocolLoggerData.Attachments);
                base.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.AttachmentBytes, incBy);
            }
            catch (FormatException innerException)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidAttachmentName");
                AirSyncPermanentException ex = new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.InvalidIDs, innerException, false);
                throw ex;
            }
            catch (ObjectNotFoundException innerException2)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AttachmentNotFound");
                AirSyncPermanentException ex2 = new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.None, innerException2, false);
                throw ex2;
            }
            catch (IOException innerException3)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOException");
                throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.None, innerException3, false);
            }
            catch (DataTooLargeException innerException4)
            {
                base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AttachmentIsTooLarge");
                PolicyData policyData2 = ADNotificationManager.GetPolicyData(base.User);
                if (policyData2 != null)
                {
                    policyData2.MaxAttachmentSize.ToString();
                }
                else
                {
                    GlobalSettings.MaxDocumentDataSize.ToString(CultureInfo.InvariantCulture);
                }
                throw new AirSyncPermanentException(HttpStatusCode.RequestEntityTooLarge, StatusCode.AttachmentIsTooLarge, innerException4, false);
            }
            finally
            {
                if (folderSyncState != null)
                {
                    folderSyncState.Dispose();
                    folderSyncState = null;
                }
            }
            base.Context.Response.AppendHeader("Content-Type", value);
            return(Command.ExecutionState.Complete);
        }
 internal static string GetAttachment(MailboxSession mailboxSession, string attachmentId, Stream outStream, Unlimited <ByteQuantifiedSize> maxAttachmentSize, ItemIdMapping idmapping, out int total)
 {
     return(AttachmentHelper.GetAttachment(mailboxSession, attachmentId, outStream, 0, -1, maxAttachmentSize, idmapping, false, out total));
 }