private static string GetAttachmentByUrlCompName(MailboxSession mailboxSession, string attachmentId, Stream outStream, int offset, int count, Unlimited <ByteQuantifiedSize> maxAttachmentSize, out int total) { attachmentId = "/" + attachmentId; int andCheckLastSlashLocation = AttachmentHelper.GetAndCheckLastSlashLocation(attachmentId, attachmentId); string text = attachmentId.Substring(0, andCheckLastSlashLocation); string text2 = attachmentId.Substring(andCheckLastSlashLocation + 1); andCheckLastSlashLocation = AttachmentHelper.GetAndCheckLastSlashLocation(text, attachmentId); string propertyValue = text.Substring(0, andCheckLastSlashLocation); StoreId storeId = null; QueryFilter seekFilter = new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.UrlName, propertyValue); using (Folder folder = Folder.Bind(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Root))) { using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.DeepTraversal, AirSyncUtility.XsoFilters.GetHierarchyFilter, null, AttachmentHelper.folderPropertyIds)) { if (queryResult.SeekToCondition(SeekReference.OriginBeginning, seekFilter)) { object[][] rows = queryResult.GetRows(1); storeId = (rows[0][0] as StoreId); } } } if (storeId == null) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentId)); } AirSyncDiagnostics.TraceDebug <StoreId>(ExTraceGlobals.RequestsTracer, null, "Getting attachment with parentStoreId {0}.", storeId); StoreId storeId2 = null; seekFilter = new ComparisonFilter(ComparisonOperator.Equal, FolderSchema.UrlName, text); using (Folder folder2 = Folder.Bind(mailboxSession, storeId)) { using (QueryResult queryResult2 = folder2.ItemQuery(ItemQueryType.None, null, null, AttachmentHelper.itemPropertyIds)) { if (queryResult2.SeekToCondition(SeekReference.OriginBeginning, seekFilter)) { object[][] rows2 = queryResult2.GetRows(1); storeId2 = (rows2[0][0] as StoreId); } } } if (storeId2 == null) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentId)); } AirSyncDiagnostics.TraceDebug <StoreId>(ExTraceGlobals.RequestsTracer, null, "Getting attachment with itemStoreId {0}.", storeId2); PropertyTagPropertyDefinition propertyTagPropertyDefinition = PropertyTagPropertyDefinition.CreateCustom("UrlCompName", 284360734U); string attachmentItself; using (Item item = Item.Bind(mailboxSession, storeId2)) { AttachmentCollection attachmentCollection = item.AttachmentCollection; attachmentCollection.Load(new PropertyDefinition[] { propertyTagPropertyDefinition }); AttachmentId attachmentId2 = null; foreach (AttachmentHandle handle in attachmentCollection) { using (Attachment attachment = attachmentCollection.Open(handle)) { if (text2.Equals((string)attachment[propertyTagPropertyDefinition], StringComparison.Ordinal)) { attachmentId2 = attachment.Id; break; } } } if (attachmentId2 == null) { foreach (AttachmentHandle handle2 in attachmentCollection) { using (Attachment attachment2 = attachmentCollection.Open(handle2)) { string str = (string)attachment2[propertyTagPropertyDefinition]; if (text2.EndsWith("_" + str, StringComparison.Ordinal)) { attachmentId2 = attachment2.Id; break; } } } } if (attachmentId2 == null) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentId)); } AirSyncDiagnostics.TraceDebug <AttachmentId>(ExTraceGlobals.RequestsTracer, null, "Getting attachment with attachment ID {0}.", attachmentId2); using (Attachment attachment3 = attachmentCollection.Open(attachmentId2)) { if (!maxAttachmentSize.IsUnlimited && attachment3.Size > (long)maxAttachmentSize.Value.ToBytes()) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } attachmentItself = AttachmentHelper.GetAttachmentItself(attachment3, outStream, offset, count, out total); } } return(attachmentItself); }