Example #1
0
 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();
     }
 }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
 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();
     }
 }
Example #6
0
 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);
        }