private Attachment TryOpenFirstAttachment(MessageItem messageItem) { using (IEnumerator <AttachmentHandle> enumerator = messageItem.AttachmentCollection.GetEnumerator()) { if (enumerator.MoveNext()) { AttachmentHandle handle = enumerator.Current; return(messageItem.AttachmentCollection.Open(handle, AttachmentType.EmbeddedMessage)); } } return(null); }
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); } }