Example #1
0
 private void GetAttachmentsFromItemByStoreId(StoreSession session, StoreId storeId, List <ModernAttachment> outModernAttachments)
 {
     if (session == null || storeId == null || outModernAttachments == null || this.IsAttachmentCountExceeded())
     {
         return;
     }
     try
     {
         using (Item item = Item.Bind(session, storeId, ItemBindOption.LoadRequiredPropertiesOnly, GetModernAttachmentsCommand.bindItemPropDefs))
         {
             this.perfItemsBoundCount++;
             if (item.AttachmentCollection != null)
             {
                 IdAndSession             idAndSession = new IdAndSession(item.Id, item.Session);
                 IList <AttachmentHandle> handles      = item.AttachmentCollection.GetHandles();
                 for (int i = 0; i < handles.Count; i++)
                 {
                     AttachmentHandle attachmentHandle = handles[i];
                     using (Attachment attachment = item.AttachmentCollection.Open(attachmentHandle))
                     {
                         if (GetModernAttachmentsCommand.Utilities.ShowAttachment(attachment, 100000))
                         {
                             ModernAttachment modernAttachment = new ModernAttachment();
                             GetModernAttachmentsCommand.PopulateAttachmentProperties(idAndSession, item, attachment, modernAttachment);
                             GetModernAttachmentsCommand.PopulateItemProperties(idAndSession, item, modernAttachment);
                             modernAttachment.Info       = new ModernAttachment.AttachmentInfo();
                             modernAttachment.Info.Index = i;
                             modernAttachment.Info.Path  = new string[]
                             {
                                 GetModernAttachmentsCommand.Utilities.FormatParam("ATT.N", attachmentHandle.AttachNumber)
                             };
                             outModernAttachments.Add(modernAttachment);
                             this.perfAttachmentCount++;
                         }
                         this.perfAttachmentsEnumeratedCount++;
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         StructuredErrors structuredErrors = this.ConvertToNestedErrors(exception);
         structuredErrors.Path = new string[]
         {
             "GetAttachmentsFromItemByStoreId",
             GetModernAttachmentsCommand.Utilities.FormatParam("storeId", storeId.ToBase64String())
         };
         this.response.AddError(structuredErrors);
     }
 }
Example #2
0
        private static void PopulateItemProperties(IdAndSession idAndSession, Item item, ModernAttachment outAttachment)
        {
            ItemType itemType = ItemType.CreateFromStoreObjectType(item.StoreObjectId.ObjectType);

            itemType.ItemClass        = item.ClassName;
            itemType.Subject          = (item[ItemSchema.Subject] as string);
            itemType.ItemId           = GetModernAttachmentsCommand.Utilities.GetItemId(idAndSession, item.Id);
            itemType.DateTimeCreated  = GetModernAttachmentsCommand.Utilities.FormatExDateTime(item.CreationTime);
            itemType.LastModifiedTime = GetModernAttachmentsCommand.Utilities.FormatExDateTime(item.LastModifiedTime);
            itemType.Size             = new int?((int)item.Size());
            ConversationId conversationId = PropertyCommand.GetPropertyValueFromStoreObject(item, ItemSchema.ConversationId) as ConversationId;
            string         id             = IdConverter.ConversationIdToEwsId(idAndSession.Session.MailboxGuid, conversationId);

            itemType.ConversationId = new ItemId(id, null);
            outAttachment.Data.Item = itemType;
        }
Example #3
0
        private static void PopulateAttachmentProperties(IdAndSession idAndSession, Item item, Attachment attachment, ModernAttachment outAttachment)
        {
            if (outAttachment == null || attachment == null || item == null)
            {
                return;
            }
            outAttachment.Data = new ModernAttachment.AttachmentData();
            outAttachment.Data.AttachmentEx = new AttachmentTypeEx();
            switch (attachment.AttachmentType)
            {
            case AttachmentType.NoAttachment:
                break;

            case AttachmentType.Stream:
            {
                StreamAttachment streamAttachment = attachment as StreamAttachment;
                if (streamAttachment != null)
                {
                    FileAttachmentType fileAttachmentType = new FileAttachmentType();
                    outAttachment.Data.Attachment     = fileAttachmentType;
                    fileAttachmentType.IsContactPhoto = streamAttachment.IsContactPhoto;
                }
                break;
            }

            case AttachmentType.EmbeddedMessage:
            {
                ItemAttachment itemAttachment = attachment as ItemAttachment;
                if (itemAttachment != null)
                {
                    outAttachment.Data.Attachment = new ItemAttachmentType();
                }
                break;
            }

            case AttachmentType.Ole:
            {
                OleAttachment oleAttachment = attachment as OleAttachment;
                if (oleAttachment != null)
                {
                    FileAttachmentType fileAttachmentType2 = new FileAttachmentType();
                    outAttachment.Data.Attachment      = fileAttachmentType2;
                    fileAttachmentType2.IsContactPhoto = oleAttachment.IsContactPhoto;
                }
                break;
            }

            case AttachmentType.Reference:
            {
                ReferenceAttachment referenceAttachment = attachment as ReferenceAttachment;
                if (referenceAttachment != null)
                {
                    UserContext userContext = UserContextManager.GetUserContext(HttpContext.Current);
                    if (userContext != null && userContext.FeaturesManager != null && userContext.FeaturesManager.ClientServerSettings.AttachmentsFilePicker.Enabled)
                    {
                        ReferenceAttachmentType referenceAttachmentType = new ReferenceAttachmentType();
                        outAttachment.Data.Attachment = referenceAttachmentType;
                        referenceAttachmentType.AttachLongPathName  = referenceAttachment.AttachLongPathName;
                        referenceAttachmentType.ProviderEndpointUrl = referenceAttachment.ProviderEndpointUrl;
                        referenceAttachmentType.ProviderType        = referenceAttachment.ProviderType;
                    }
                    else
                    {
                        outAttachment.Data.Attachment = new FileAttachmentType();
                    }
                }
                break;
            }

            default:
                return;
            }
            if (outAttachment.Data.Attachment == null)
            {
                outAttachment.Data.Attachment = new AttachmentType();
            }
            IdAndSession idAndSession2;

            if (idAndSession == null)
            {
                idAndSession2 = new IdAndSession(item.Id, item.Session);
            }
            else
            {
                idAndSession2 = idAndSession.Clone();
            }
            idAndSession2.AttachmentIds.Add(attachment.Id);
            outAttachment.Data.Attachment.AttachmentId     = new AttachmentIdType(idAndSession2.GetConcatenatedId().Id);
            outAttachment.Data.Attachment.ContentId        = (string.IsNullOrEmpty(attachment.ContentId) ? null : attachment.ContentId);
            outAttachment.Data.Attachment.ContentLocation  = ((attachment.ContentLocation == null) ? null : attachment.ContentLocation.PathAndQuery);
            outAttachment.Data.Attachment.ContentType      = attachment.ContentType;
            outAttachment.Data.Attachment.IsInline         = attachment.IsInline;
            outAttachment.Data.Attachment.LastModifiedTime = GetModernAttachmentsCommand.Utilities.FormatExDateTime(attachment.LastModifiedTime);
            outAttachment.Data.Attachment.Name             = attachment.DisplayName;
            outAttachment.Data.Attachment.Size             = (int)attachment.Size;
        }