private long WriteAttachedItem(ItemAttachment attachment) { Item item = ConvertUtils.OpenAttachedItem(attachment); long result = 0L; if (item != null) { try { this.limitsTracker.StartEmbeddedMessage(); Charset itemWindowsCharset = ConvertUtils.GetItemWindowsCharset(item, this.options); using (ItemToTnefConverter.TnefContentWriter embeddedMessageWriter = this.tnefWriter.GetEmbeddedMessageWriter(itemWindowsCharset)) { OutboundAddressCache outboundAddressCache = new OutboundAddressCache(this.options, this.limitsTracker); outboundAddressCache.CopyDataFromItem(item); if (this.tnefType == TnefType.LegacyTnef && this.options.ResolveRecipientsInAttachedMessages) { outboundAddressCache.Resolve(); } using (ItemToTnefConverter itemToTnefConverter = new ItemToTnefConverter(item, outboundAddressCache, embeddedMessageWriter, this.options, this.limitsTracker, this.tnefType, true)) { ConversionResult conversionResult = itemToTnefConverter.Convert(); result = conversionResult.BodySize + conversionResult.AccumulatedAttachmentSize; } } this.limitsTracker.EndEmbeddedMessage(); } finally { item.Dispose(); } } return(result); }
private long WriteAttachmentProperties(Attachment attachment) { long result = 0L; this.tnefWriter.StartAttribute(TnefAttributeTag.Attachment, TnefAttributeLevel.Attachment); foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in attachment.AllNativeProperties) { if (nativeStorePropertyDefinition.Equals(InternalSchema.AttachDataObj)) { result = this.WriteAttachDataObj(attachment); } else if (!nativeStorePropertyDefinition.Equals(InternalSchema.AttachDataBin) && this.propertyChecker.IsAttachmentPropertyWritable(nativeStorePropertyDefinition)) { object obj = attachment.TryGetProperty(nativeStorePropertyDefinition); PropertyError propertyError = obj as PropertyError; if (propertyError != null && PropertyError.IsPropertyValueTooBig(propertyError)) { this.WritePropertyStreamData(attachment.PropertyBag, nativeStorePropertyDefinition); } else if (propertyError == null) { obj = ExTimeZoneHelperForMigrationOnly.ToLegacyUtcIfDateTime(obj); this.tnefWriter.WriteProperty(nativeStorePropertyDefinition, obj); } } } ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { result = this.WriteAttachedItem(itemAttachment); } return(result); }
internal AttachmentInfo(StoreObjectId messageId, Attachment attachment) { this.fileName = attachment.FileName; this.fileExtension = attachment.FileExtension; this.displayName = attachment.DisplayName; this.contentType = attachment.ContentType; if (string.IsNullOrEmpty(this.contentType)) { this.contentType = attachment.CalculatedContentType; } this.isInline = attachment.IsInline; this.size = attachment.Size; this.attachmentType = attachment.AttachmentType; this.messageId = messageId; this.attachmentId = attachment.Id; this.contentId = attachment.ContentId; this.lastModifiedTime = attachment.LastModifiedTime; this.contentLocation = attachment.ContentLocation; if (attachment.AttachmentType == AttachmentType.Stream) { StreamAttachment streamAttachment = attachment as StreamAttachment; if (streamAttachment != null) { this.imageThumbnail = streamAttachment.LoadAttachmentThumbnail(); this.imageThumbnailHeight = streamAttachment.ImageThumbnailHeight; this.imageThumbnailWidth = streamAttachment.ImageThumbnailWidth; if (this.imageThumbnail != null) { this.salientRegions = streamAttachment.LoadAttachmentThumbnailSalientRegions(); } } } if (attachment.AttachmentType == AttachmentType.EmbeddedMessage) { ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { using (Item item = itemAttachment.GetItem()) { this.embeddedItemClass = item.ClassName; } } } if (attachment.AttachmentType == AttachmentType.Reference) { ReferenceAttachment referenceAttachment = attachment as ReferenceAttachment; if (referenceAttachment != null) { this.attachLongPathName = referenceAttachment.AttachLongPathName; this.providerType = referenceAttachment.ProviderType; } } }
private void WriteAttachedItem(ItemAttachment itemAttachment) { using (Item item = itemAttachment.GetItem(InternalSchema.ContentConversionProperties)) { this.limitsTracker.StartEmbeddedMessage(); using (MsgStorageWriter embeddedMessageWriter = this.PropertyWriter.GetEmbeddedMessageWriter()) { OutboundMsgConverter outboundMsgConverter = new OutboundMsgConverter(this.options); outboundMsgConverter.InternalConvertItemToMsgStorage(item, embeddedMessageWriter, this.limitsTracker); } this.limitsTracker.EndEmbeddedMessage(); } }
public ItemAttachment Create(StoreObjectType type) { EnumValidator.ThrowIfInvalid <StoreObjectType>(type, "type"); ItemAttachment result = null; using (DisposeGuard disposeGuard = default(DisposeGuard)) { CoreAttachment coreAttachment = this.CoreAttachmentCollection.CreateItemAttachment(type); disposeGuard.Add <CoreAttachment>(coreAttachment); result = (ItemAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.EmbeddedMessage)); disposeGuard.Success(); } return(result); }
public ItemAttachment AddExistingItem(IItem item) { Util.ThrowOnNullArgument(item, "item"); ItemAttachment result = null; using (DisposeGuard disposeGuard = default(DisposeGuard)) { CoreAttachment coreAttachment = this.CoreAttachmentCollection.CreateFromExistingItem(item); disposeGuard.Add <CoreAttachment>(coreAttachment); result = (ItemAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.EmbeddedMessage)); disposeGuard.Success(); } return(result); }
internal static Item OpenAttachedItem(ItemAttachment attachment) { Item result; try { result = attachment.GetItem(InternalSchema.ContentConversionProperties); } catch (ObjectNotFoundException arg) { StorageGlobals.ContextTraceDebug <ObjectNotFoundException>(ExTraceGlobals.CcOutboundGenericTracer, "ConvertUtils::OpenAttachedItem - unable to open embedded message, exc = {0}", arg); result = null; } return(result); }
private IImapMimeProvider GetAttachedItemConverter(ref MimePartInfo part, ref Item item, ref EncodingOptions itemEncodingOptions, List <IDisposable> disposeList) { if (part.ContentType != MimePartContentType.ItemAttachment) { return(null); } IImapMimeProvider imapMimeProvider; if (part.SmimePart == null) { Attachment attachment = item.AttachmentCollection.Open(part.AttachmentId, InternalSchema.ContentConversionProperties); disposeList.Add(attachment); ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment == null) { StorageGlobals.ContextTraceError(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item."); ExAssert.RetailAssert(false, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item."); return(null); } item = ConvertUtils.OpenAttachedItem(itemAttachment); if (item == null) { return(null); } disposeList.Add(item); ItemToMimeConverter itemToMimeConverter = new ItemToMimeConverter(item, this.options, ConverterFlags.IsEmbeddedMessage); imapMimeProvider = IImapMimeProvider.CreateInstance(itemToMimeConverter); disposeList.Add(imapMimeProvider); itemEncodingOptions = itemToMimeConverter.GetItemMimeEncodingOptions(this.options); if (part.AttachedItemStructure != null) { itemToMimeConverter.SetSkeletonAndSmimeDoc(part.AttachedItemStructure.Skeleton, part.AttachedItemStructure.SmimeDocument); } } else { imapMimeProvider = IImapMimeProvider.CreateInstance((MimePart)part.SmimePart.FirstChild, part.SmimeDocument); disposeList.Add(imapMimeProvider); itemEncodingOptions = this.itemEncodingOptions; } if (part.AttachedItemStructure == null) { part.AttachedItemStructure = imapMimeProvider.CalculateMimeStructure(Charset.GetCharset(itemEncodingOptions.CharsetName)); } part = part.AttachedItemStructure; return(imapMimeProvider); }
public MessageItem CreateSendAgain(StoreId parentFolderId) { this.CheckDisposed("CreateSendAgain"); if (parentFolderId == null) { throw new ArgumentNullException("parentFolderId"); } if (!this.IsSendAgainAllowed) { throw new NotSupportedException("CreateSendAgain() is not supported on this ReportMessage"); } MessageItem messageItem = null; bool flag = false; MessageItem result; try { using (ItemAttachment itemAttachment = (ItemAttachment)base.AttachmentCollection.TryOpenFirstAttachment(AttachmentType.EmbeddedMessage)) { if (itemAttachment == null) { throw new CorruptDataException(ServerStrings.ExReportMessageCorruptedDueToWrongItemAttachmentType); } using (Item item = itemAttachment.GetItem()) { if (!(item is MessageItem)) { throw new CorruptDataException(ServerStrings.ExReportMessageCorruptedDueToWrongItemAttachmentType); } messageItem = (MessageItem)Microsoft.Exchange.Data.Storage.Item.CloneItem(base.Session, parentFolderId, item, false, false, null); this.SetResendItem(messageItem, (MessageItem)item); } } flag = true; result = messageItem; } finally { if (!flag && messageItem != null) { messageItem.Dispose(); messageItem = null; } } return(result); }
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); }
protected override void BuildAttachments(BodyConversionCallbacks callbacks, InboundConversionOptions optionsForSmime) { using (ItemAttachment itemAttachment = this.newItem.AttachmentCollection.Create(AttachmentType.EmbeddedMessage) as ItemAttachment) { using (Item item = itemAttachment.GetItem(InternalSchema.ContentConversionProperties)) { this.originalItem.Load(InternalSchema.ContentConversionProperties); Item.CopyItemContent(this.originalItem, item); item.DeleteProperties(new PropertyDefinition[] { InternalSchema.EntryId, InternalSchema.MessageStatus, InternalSchema.SubmitFlags, InternalSchema.ReceivedRepresenting, InternalSchema.UrlCompName }); item[InternalSchema.Flags] = this.originalItem.GetValueOrDefault <MessageFlags>(InternalSchema.Flags); item[InternalSchema.HasBeenSubmitted] = false; item.SaveFlags |= this.newItem.SaveFlags; item.Save(SaveMode.NoConflictResolution); } itemAttachment.Save(); } }
private void SaveAndCloseCurrentAttachment() { if (this.currentAttachment != null) { if (this.currentAttachment.AttachmentType == AttachmentType.EmbeddedMessage) { ItemAttachment itemAttachment = this.currentAttachment as ItemAttachment; if (itemAttachment != null) { using (Item item = itemAttachment.GetItem()) { ItemConversion.ConvertMsgStorageToItem(this.temporaryStreamForEmbeddedMessage, item, new InboundConversionOptions(new EmptyRecipientCache(), string.Empty)); this.temporaryStreamForEmbeddedMessage = null; item.Save(SaveMode.NoConflictResolution); } } } this.currentAttachment.Save(); this.currentAttachment.Load(null); this.messageAttachmentIds.Add(this.currentAttachment.Id); this.currentAttachment.Dispose(); this.currentAttachment = null; } }
private static Item InternalOpenEmbeddedMessageAndAttachment(AttachmentCollection attachments, ExTimeZone organizerTimeZone, ExDateTime userStartTime, ExDateTime userEndTime, out ItemAttachment itemAttachment, bool detectDuplicatedAttachment, out AttachmentId[] duplicatedAttachmentIds, ICollection <PropertyDefinition> properties) { itemAttachment = null; duplicatedAttachmentIds = null; Item item = null; ItemAttachment itemAttachment2 = null; List <KeyValuePair <long, AttachmentHandle> > list = new List <KeyValuePair <long, AttachmentHandle> >(); List <AttachmentId> list2 = null; ExDateTime exDateTime = ExTimeZone.UtcTimeZone.ConvertDateTime(userStartTime); ExDateTime exDateTime2 = ExTimeZone.UtcTimeZone.ConvertDateTime(userEndTime); ExDateTime exDateTime3 = organizerTimeZone.ConvertDateTime(exDateTime); ExDateTime exDateTime4 = organizerTimeZone.ConvertDateTime(exDateTime2); exDateTime3 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime3); exDateTime4 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime4); if (properties == null) { properties = new PropertyDefinition[] { InternalSchema.StartTime, InternalSchema.EndTime }; } else { properties = InternalSchema.Combine <PropertyDefinition>(properties, new PropertyDefinition[] { InternalSchema.StartTime, InternalSchema.EndTime }); } CalendarItem calendarItem = attachments.ContainerItem as CalendarItem; List <RecurrenceManager.ExceptionSummary> list3; if (calendarItem != null) { if (calendarItem.ExceptionSummaryList == null) { ExTraceGlobals.RecurrenceTracer.TraceDebug((long)calendarItem.GetHashCode(), "For calendar item, retrieve exception summary information by walking through all hidden attachements"); calendarItem.ExceptionSummaryList = RecurrenceManager.GetExceptionSumaryList(attachments); } list3 = calendarItem.ExceptionSummaryList; } else { ExTraceGlobals.RecurrenceTracer.TraceDebug((long)attachments.GetHashCode(), "No calendar item exists, retrieve exception summary information by walking through all hidden attachements"); list3 = RecurrenceManager.GetExceptionSumaryList(attachments); } foreach (RecurrenceManager.ExceptionSummary exceptionSummary in list3) { ExDateTime utcStartTime = exceptionSummary.UtcStartTime; ExDateTime utcEndTime = exceptionSummary.UtcEndTime; TimeSpan timeSpan = utcStartTime - exDateTime; utcEndTime - exDateTime2; if (Math.Abs((exDateTime3 - exDateTime4 - (utcStartTime - utcEndTime)).Ticks) < 1200000000L && Math.Abs(timeSpan.Ticks) <= 504000000000L) { list.Add(new KeyValuePair <long, AttachmentHandle>(Math.Abs((utcStartTime - exDateTime3).Ticks), exceptionSummary.Handle)); } } list.Sort(delegate(KeyValuePair <long, AttachmentHandle> left, KeyValuePair <long, AttachmentHandle> right) { if (left.Key == right.Key) { return(0); } if (left.Key <= right.Key) { return(-1); } return(1); }); bool flag = false; try { foreach (KeyValuePair <long, AttachmentHandle> keyValuePair in list) { ItemAttachment itemAttachment3 = (ItemAttachment)attachments.Open(keyValuePair.Value, new AttachmentType?(AttachmentType.EmbeddedMessage), null); ExTraceGlobals.RecurrenceTracer.TraceDebug <ExDateTime, int>((long)keyValuePair.Value.GetHashCode(), "Open embedded message for StartTime: {0}, Probables queue length: {1}", userStartTime, list.Count); if (itemAttachment3 != null) { Item item2 = null; bool flag2 = true; try { if (itemAttachment3.IsItemOpen) { ExTraceGlobals.RecurrenceTracer.TraceError((long)keyValuePair.Value.GetHashCode(), "Embedded message is in erroneous open state, which should be guaranteed by master"); } else { item2 = itemAttachment3.GetItem(InternalSchema.Combine <PropertyDefinition>(MessageItemSchema.Instance.AutoloadProperties, properties)); TimeSpan timeSpan2 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiStartTime, ExDateTime.MinValue) - userStartTime; TimeSpan timeSpan3 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiEndTime, ExDateTime.MinValue) - userEndTime; if (timeSpan2.TotalMinutes < 1.0 && timeSpan2.TotalMinutes > -1.0 && timeSpan3.TotalMinutes < 1.0 && timeSpan3.TotalMinutes > -1.0) { if (item == null) { flag2 = false; itemAttachment2 = itemAttachment3; item = item2; if (!detectDuplicatedAttachment) { break; } list2 = new List <AttachmentId>(); } else { ExTraceGlobals.RecurrenceTracer.TraceDebug <AttachmentId, ExDateTime>((long)keyValuePair.Value.GetHashCode(), "Detected duplicated attachment {0} for StartTime: {1}", itemAttachment3.Id, userStartTime); list2.Add(itemAttachment3.Id); } } } } finally { if (flag2) { Util.DisposeIfPresent(item2); Util.DisposeIfPresent(itemAttachment3); } } } } flag = true; } finally { if (!flag) { Util.DisposeIfPresent(item); Util.DisposeIfPresent(itemAttachment2); } } itemAttachment = itemAttachment2; duplicatedAttachmentIds = ((list2 == null) ? null : list2.ToArray()); return(item); }
internal static Item OpenEmbeddedMessageAndAttachment(AttachmentCollection attachments, ExTimeZone organizerTimeZone, ExDateTime userStartTime, ExDateTime userEndTime, out ItemAttachment itemAttachment, ICollection <PropertyDefinition> properties) { AttachmentId[] array; return(RecurrenceManager.InternalOpenEmbeddedMessageAndAttachment(attachments, organizerTimeZone, userStartTime, userEndTime, out itemAttachment, false, out array, properties)); }
private void PopulateExceptionOccurrence(object[] occurrence, PropertyDefinition[] columns, ExceptionInfo exception, ref AttachmentCollection attachments, ref Item master, VersionedId versionedId) { object[] array = null; for (int i = 0; i < columns.Length; i++) { if (!columns[i].Equals(InternalSchema.ItemId) && !columns[i].Equals(InternalSchema.IsRecurring) && !columns[i].Equals(InternalSchema.IsException) && !columns[i].Equals(InternalSchema.AppointmentRecurring) && !columns[i].Equals(InternalSchema.MapiStartTime) && !columns[i].Equals(InternalSchema.MapiPRStartDate) && !columns[i].Equals(InternalSchema.MapiEndTime) && !columns[i].Equals(InternalSchema.MapiPREndDate) && !columns[i].Equals(InternalSchema.CalendarItemType) && !columns[i].Equals(InternalSchema.GlobalObjectId) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionStart) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionEnd) && !columns[i].Equals(InternalSchema.Codepage) && !RecurrenceManager.MasterOnlyProperties.Contains(columns[i])) { if (RecurrenceManager.CanPropertyBeInExceptionData(columns[i])) { object obj = exception.PropertyBag.TryGetProperty(columns[i]); PropertyError propertyError = obj as PropertyError; if (propertyError != null) { if (propertyError.PropertyErrorCode != PropertyErrorCode.NotFound) { throw PropertyError.ToException(new PropertyError[] { propertyError }); } } else { occurrence[i] = obj; } } else { ExTraceGlobals.RecurrenceTracer.Information <PropertyDefinition>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Opening embedded message for {0} property", columns[i]); if (array == null) { if (attachments == null) { if (master == null) { ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand. Fetching master message when constructing view"); StoreObjectId masterId = versionedId.ObjectId; bool flag = false; try { master = ItemBuilder.ConstructItem <Item>(this.storeSession, masterId, null, CalendarItemBaseSchema.Instance.AutoloadProperties, () => new StoreObjectPropertyBag(this.storeSession, this.storeSession.GetMapiProp(masterId), CalendarItemBaseSchema.Instance.AutoloadProperties), ItemCreateInfo.GenericItemInfo.Creator, Origin.Existing, ItemLevel.TopLevel); flag = true; } finally { if (!flag && master != null) { master.Dispose(); master = null; } } } attachments = master.AttachmentCollection; ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching attachments"); } ItemAttachment itemAttachment = null; using (Item item = RecurrenceManager.OpenEmbeddedMessageAndAttachment(attachments, TimeZoneHelper.GetRecurringTimeZoneFromPropertyBag(attachments.ContainerItem.PropertyBag), exception.StartTime, exception.EndTime, out itemAttachment, columns)) { ExTraceGlobals.RecurrenceTracer.Information <ExDateTime>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching Embedded Message for exception occurence dateId: {0}", exception.OccurrenceDateId); if (item != null) { array = item.GetProperties(columns); itemAttachment.Dispose(); } else { array = new object[columns.Length]; } } } if (array[i] != null && !(array[i] is PropertyError)) { occurrence[i] = array[i]; } } } } }