public static void ReadAttachmentIds(BinaryReader reader, List <AttachmentId> attachmentIds) { byte b = reader.ReadByte(); if (b == 0) { ServiceIdConverter.TraceDebug("[IdConverter::ReadAttachmentIds] Number of attachment indicator was set to 0. Shouldn't be there at all in that case"); throw new InvalidIdException(); } if (b > 255) { ServiceIdConverter.TraceDebug("[IdConverter::ReadAttachmentIds] Number of attachments in id is greater than allowed value"); throw new InvalidIdMalformedException(); } for (int i = 0; i < (int)b; i++) { short num = reader.ReadInt16(); if (num <= 0) { throw new InvalidIdMalformedException(); } byte[] array = reader.ReadBytes((int)num); if (array.Length != (int)num) { ServiceIdConverter.TraceDebug("[IdConverter::ReadAttachmentIds] Attachment Id length did not match actual length"); throw new InvalidIdMalformedException(); } attachmentIds.Add(AttachmentId.Deserialize(array)); } }
internal void UpdateAttachmentId(AttachmentId attachmentId, int attachmentNumber) { this.CheckDisposed(null); if (this.isInitialized) { AttachmentHandle attachmentHandle = this.GetAttachmentHandle(attachmentNumber); attachmentHandle.AttachmentId = attachmentId; this.attachmentIdMap[attachmentId] = attachmentHandle; } }
internal bool Remove(AttachmentId id) { this.CheckDisposed(null); Util.ThrowOnNullArgument(id, "id"); ExTraceGlobals.StorageTracer.Information((long)this.GetHashCode(), "Storage.CoreAttachmentCollection.Remove(AttachmentId)"); this.InitCollection("Remove", true); AttachmentHandle attachmentHandle = null; return(this.attachmentIdMap.TryGetValue(id, out attachmentHandle) && this.Remove(attachmentHandle)); }
internal bool Contains(AttachmentId id) { this.CheckDisposed(null); Util.ThrowOnNullArgument(id, "id"); ExTraceGlobals.StorageTracer.Information((long)this.GetHashCode(), "Storage.CoreAttachmentCollection.Contains"); this.InitCollection("Contains", false); AttachmentHandle attachmentHandle = null; return(this.attachmentIdMap.TryGetValue(id, out attachmentHandle) && attachmentHandle != null); }
public void OnAttachmentLoad(AttachmentPropertyBag attachmentBag) { if (!attachmentBag.UseCreateFlagOnConnect) { AttachmentId attachmentId = attachmentBag.AttachmentId; if (attachmentId != null) { this.AttachmentCollection.UpdateAttachmentId(attachmentId, attachmentBag.AttachmentNumber); } } }
public bool Remove(AttachmentId attachmentId) { Util.ThrowOnNullArgument(attachmentId, "attachmentId"); bool result = this.CoreAttachmentCollection.Remove(attachmentId); CalendarItemBase calendarItemBase = this.ContainerItem as CalendarItemBase; if (calendarItemBase != null) { calendarItemBase.LocationIdentifierHelperInstance.SetLocationIdentifier(63349U, LastChangeAction.AttachmentRemoved); } return(result); }
internal CoreAttachment Open(AttachmentId attachmentId, ICollection <PropertyDefinition> preloadProperties) { this.CheckDisposed(null); Util.ThrowOnNullArgument(attachmentId, "attachmentId"); this.InitCollection("Open", false); AttachmentHandle handle; if (!this.attachmentIdMap.TryGetValue(attachmentId, out handle)) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachment); } return(this.InternalOpen(handle, preloadProperties)); }
internal static AttachmentLink Find(AttachmentId attachmentId, IList <AttachmentLink> attachmentLinks) { if (attachmentId != null && attachmentLinks != null) { foreach (AttachmentLink attachmentLink in attachmentLinks) { if (attachmentId.Equals(attachmentLink.AttachmentId)) { return(attachmentLink); } } } return(null); }
public AttachmentLink FindAttachmentByIdOrContentId(AttachmentId attachmentId, string contentId) { Util.ThrowOnNullArgument(attachmentId, "attachmentId"); if (this.AttachmentCollection == null) { throw new InvalidOperationException("Target item not specified; cannot invoke attachment-specific methods"); } bool flag = string.IsNullOrEmpty(contentId); foreach (AttachmentLink attachmentLink in this.AttachmentLinks) { if (attachmentLink.AttachmentId.Equals(attachmentId) || (!flag && contentId.Equals(attachmentLink.ContentId, StringComparison.Ordinal))) { return(attachmentLink); } } return(null); }
public void UnprotectAttachment(AttachmentId attachmentId) { using (Attachment attachment = this.ProtectedAttachmentCollection.Open(attachmentId)) { StreamAttachment streamAttachment = attachment as StreamAttachment; if (streamAttachment == null) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachment); } using (Stream stream = StreamAttachment.OpenRestrictedContent(streamAttachment, this.orgId)) { using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create)) { Util.StreamHandler.CopyStreamData(stream, contentStream); } } attachment.Save(); } }
internal static void DeleteAttachment(Item message, ExTimeZone organizerTimeZone, ExDateTime startTime, ExDateTime endTime) { bool valueOrDefault = message.GetValueOrDefault <bool>(InternalSchema.MapiHasAttachment, true); if (!valueOrDefault) { ExTraceGlobals.RecurrenceTracer.TraceDebug((long)message.GetHashCode(), "RecurrenceManager::DeleteAttachment: There are no attachments on this message"); return; } ItemAttachment itemAttachment = null; AttachmentId attachmentId = null; AttachmentId[] array; using (RecurrenceManager.InternalOpenEmbeddedMessageAndAttachment(message.AttachmentCollection, organizerTimeZone, startTime, endTime, out itemAttachment, true, out array, null)) { if (itemAttachment != null) { using (itemAttachment) { if (itemAttachment.IsCalendarException) { CalendarItem calendarItem = message as CalendarItem; if (calendarItem != null) { calendarItem.ClearExceptionSummaryList(); } } attachmentId = itemAttachment.Id; } } } if (attachmentId != null) { message.AttachmentCollection.Remove(attachmentId); foreach (AttachmentId attachmentId2 in array) { message.AttachmentCollection.Remove(attachmentId2); } return; } ExTraceGlobals.RecurrenceTracer.TraceDebug <ExDateTime, ExDateTime>((long)message.GetHashCode(), "RecurrenceManager::DeleteAttachment, Couldn't find attachment for startTime: {0} endTime: {1}", startTime, endTime); }
internal static string CreateContentId(ICoreItem containerItem, AttachmentId id, string domain) { byte[] array; if (containerItem != null && containerItem.Session != null && containerItem.Id != null && id != null) { array = Util.MergeArrays <byte>(new ICollection <byte>[] { containerItem.Id.GetBytes(), id.ToByteArray() }); array = CryptoUtil.GetSha1Hash(array); } else { array = Guid.NewGuid().ToByteArray(); } if (!string.IsNullOrEmpty(domain)) { return(string.Format("{0}@{1}", HexConverter.ByteArrayToHexString(array), domain)); } return(string.Format("{0}@1", HexConverter.ByteArrayToHexString(array))); }
internal MimePartInfo(Charset charset, MimePartInfo.Callback writerCallback, MimePartContentType contentType, AttachmentId attachmentId, MimePart skeletonPart, MimeDocument skeleton, MimePart smimePart, MimeDocument smimeDocument, ref int partIndex) { this.charset = charset; this.contentType = contentType; this.writerCallback = writerCallback; this.partIndex = partIndex++; this.attachmentId = attachmentId; this.skeletonPart = skeletonPart; this.skeleton = skeleton; this.smimePart = smimePart; this.smimeDocument = smimeDocument; this.bodyLines = -1; this.bodyBytes = -1; }
internal MimePartInfo(Charset charset, MimePartInfo.Callback writerCallback, MimePartContentType contentType, AttachmentId attachmentId, MimePart skeletonPart, MimeDocument skeleton, ref int partIndex) : this(charset, writerCallback, contentType, attachmentId, skeletonPart, skeleton, null, null, ref partIndex) { }
internal CoreAttachment Open(AttachmentId attachmentId) { return(this.Open(attachmentId, null)); }
public bool Contains(AttachmentId attachmentId) { Util.ThrowOnNullArgument(attachmentId, "attachmentId"); return(this.CoreAttachmentCollection.Contains(attachmentId)); }
public Attachment Open(AttachmentId id, ICollection <PropertyDefinition> propertyDefinitions) { Util.ThrowOnNullArgument(id, "id"); return(AttachmentCollection.CreateTypedAttachment(this.CoreAttachmentCollection.Open(id, propertyDefinitions), null)); }
public Attachment Open(AttachmentId id) { return(this.Open(id, null)); }
public virtual bool Remove(AttachmentId attachmentId) { throw new NotImplementedException(); }
private AttachmentLink InternalFindByBodyReference(string bodyReference, Uri baseUri) { Uri uri; if (!Uri.TryCreate(bodyReference, UriKind.RelativeOrAbsolute, out uri)) { ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: bodyReference not a valid URI\r\n'{0}'", bodyReference); return(null); } if (!uri.IsWellFormedOriginalString()) { ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: bodyReference not a valid URI\r\n'{0}'", bodyReference); return(null); } if (uri.IsAbsoluteUri && uri.Scheme == "cid") { using (IEnumerator <AttachmentLink> enumerator = this.AttachmentLinks.GetEnumerator()) { while (enumerator.MoveNext()) { AttachmentLink attachmentLink = enumerator.Current; AttachmentId attachmentId = attachmentLink.AttachmentId; string text; if (string.Equals(uri.LocalPath, attachmentLink.ContentId, StringComparison.OrdinalIgnoreCase)) { text = attachmentLink.ContentId; } else if (string.Equals(uri.LocalPath, attachmentLink.Filename, StringComparison.OrdinalIgnoreCase)) { text = attachmentLink.Filename; } else { if (!string.Equals(uri.LocalPath, attachmentLink.DisplayName, StringComparison.OrdinalIgnoreCase)) { continue; } text = attachmentLink.DisplayName; } Uri contentLocation; if (!Uri.TryCreate("cid:" + text, UriKind.RelativeOrAbsolute, out contentLocation)) { ExTraceGlobals.StorageTracer.TraceError <string, AttachmentId>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: attachmentContentKey[{1}] not a valid URI\r\n'{0}'", text, attachmentId); return(null); } if (!contentLocation.IsWellFormedOriginalString()) { ExTraceGlobals.StorageTracer.TraceError <string, AttachmentId>((long)this.GetHashCode(), "BodyConversionCallbacksBase.InternalFindId: attachmentContentKey[{1}] not a valid URI\r\n'{0}'", text, attachmentId); return(null); } return(attachmentLink); } goto IL_2A1; } } if (uri.IsAbsoluteUri && uri.Scheme == "objattph") { if (this.attachmentsByPositionEnumerator == null) { this.CreateAttachmentsByPositionEnumerator(); } if (this.attachmentsByPositionEnumerator.MoveNext()) { KeyValuePair <int, AttachmentLink> keyValuePair = this.attachmentsByPositionEnumerator.Current; return(keyValuePair.Value); } return(null); } else { Uri uri2; if (uri.IsAbsoluteUri) { uri2 = uri; } else if (baseUri != null) { if (!Uri.TryCreate(baseUri, uri, out uri2)) { ExTraceGlobals.StorageTracer.TraceError <Uri, Uri>((long)this.GetHashCode(), "AttachmentCollection.InternalFindId: can't build absolute URI from bodyReference and base\r\n'{0}'\r\n'{1}'", uri, baseUri); uri2 = uri; } } else { uri2 = uri; } foreach (AttachmentLink attachmentLink2 in this.AttachmentLinks) { AttachmentId attachmentId2 = attachmentLink2.AttachmentId; Uri contentLocation = attachmentLink2.ContentLocation; Uri contentBase = attachmentLink2.ContentBase; if (!(contentLocation == null)) { Uri obj; if (contentLocation.IsAbsoluteUri) { obj = contentLocation; } else if (contentBase != null) { if (!Uri.TryCreate(contentBase, contentLocation, out obj)) { ExTraceGlobals.StorageTracer.TraceError <Uri, AttachmentId>((long)this.GetHashCode(), "AttachmentCollection.InternalFindId: attachContentLocation[{1}] not a valid URI\r\n'{0}'", contentLocation, attachmentId2); obj = contentLocation; } } else { obj = contentLocation; } try { if (uri2.Equals(obj)) { return(attachmentLink2); } } catch (UriFormatException) { } } } } IL_2A1: return(null); }
public PersistablePropertyBag OpenAttachment(ICollection <PropertyDefinition> prefetchProperties, AttachmentPropertyBag attachmentBag) { ICollection <PropertyDefinition> attachmentLoadList = this.AttachmentCollection.GetAttachmentLoadList(prefetchProperties, attachmentBag.Schema); int attachmentNumber = attachmentBag.AttachmentNumber; MapiAttach mapiAttach = null; StoreObjectPropertyBag storeObjectPropertyBag = null; bool flag = false; try { StoreSession session = this.AttachmentCollection.ContainerItem.Session; bool flag2 = false; try { if (session != null) { session.BeginMapiCall(); session.BeginServerHealthCall(); flag2 = true; } if (StorageGlobals.MapiTestHookBeforeCall != null) { StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod()); } mapiAttach = this.AttachmentCollection.ContainerItem.MapiMessage.OpenAttach(attachmentNumber); } catch (MapiPermanentException ex) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex, session, this, "{0}. MapiException = {1}.", new object[] { string.Format("MapiAttachmentProvider::OpenMapiAttachment({0})", attachmentNumber), ex }); } catch (MapiRetryableException ex2) { throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenAttachment, ex2, session, this, "{0}. MapiException = {1}.", new object[] { string.Format("MapiAttachmentProvider::OpenMapiAttachment({0})", attachmentNumber), ex2 }); } finally { try { if (session != null) { session.EndMapiCall(); if (flag2) { session.EndServerHealthCall(); } } } finally { if (StorageGlobals.MapiTestHookAfterCall != null) { StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod()); } } } storeObjectPropertyBag = this.CreateStorePropertyBag(mapiAttach, attachmentLoadList); byte[] array = ((IDirectPropertyBag)storeObjectPropertyBag).GetValue(InternalSchema.RecordKey) as byte[]; if (array != null) { AttachmentId attachmentId = new AttachmentId(array); if (!attachmentId.Equals(attachmentBag.AttachmentId)) { throw new StoragePermanentException(ServerStrings.MapiCannotMatchAttachmentIds(attachmentId.ToBase64String(), attachmentBag.AttachmentId.ToBase64String())); } } flag = true; } finally { if (!flag) { if (storeObjectPropertyBag != null) { storeObjectPropertyBag.Dispose(); storeObjectPropertyBag = null; } if (mapiAttach != null) { mapiAttach.Dispose(); mapiAttach = null; } } } return(storeObjectPropertyBag); }