internal override void CoreObjectUpdate(CoreAttachment coreAttachment)
 {
     base.CoreObjectUpdate(coreAttachment);
     StreamAttachmentBase.CoreObjectUpdateStreamAttachmentName(coreAttachment);
     try
     {
         StreamAttachmentBase.CoreObjectUpdateImageThumbnail(coreAttachment);
     }
     catch (FileNotFoundException)
     {
     }
 }
Esempio n. 2
0
        private Stream AttachmentsStreamCallback(object context)
        {
            if (this.decryptedItem == null)
            {
                throw new StoragePermanentException(ServerStrings.FailedToAddAttachments);
            }
            this.SaveAndCloseCurrentAttachment();
            AttachmentType attachmentType  = (AttachmentType)context;
            AttachmentType attachmentType2 = attachmentType;
            AttachmentType attachmentType3;

            if (attachmentType2 != AttachmentType.OleObject)
            {
                if (attachmentType2 != AttachmentType.ByValue)
                {
                    if (attachmentType2 != AttachmentType.EmbeddedMessage)
                    {
                        throw new StoragePermanentException(ServerStrings.InvalidAttachmentType);
                    }
                    attachmentType3 = AttachmentType.EmbeddedMessage;
                }
                else
                {
                    attachmentType3 = AttachmentType.Stream;
                }
            }
            else
            {
                attachmentType3 = AttachmentType.Ole;
            }
            AttachmentCollection attachmentCollection = this.decryptedItem.AttachmentCollection;

            this.currentAttachment = attachmentCollection.Create(attachmentType3);
            ExTraceGlobals.RightsManagementTracer.TraceDebug <AttachmentType>((long)this.GetHashCode(), "Decrypting Attachment. AttachmentType {0}", attachmentType3);
            StreamAttachmentBase streamAttachmentBase = this.currentAttachment as StreamAttachmentBase;

            if (streamAttachmentBase != null)
            {
                return(streamAttachmentBase.GetContentStream(PropertyOpenMode.Create));
            }
            this.temporaryStreamForEmbeddedMessage = Streams.CreateTemporaryStorageStream();
            return(this.temporaryStreamForEmbeddedMessage);
        }
        internal static void CoreObjectUpdateStreamAttachmentName(CoreAttachment coreAttachment)
        {
            ICorePropertyBag propertyBag = coreAttachment.PropertyBag;
            string           text        = (propertyBag.TryGetProperty(InternalSchema.AttachLongFileName) as string) ?? (propertyBag.TryGetProperty(InternalSchema.AttachFileName) as string);
            string           text2       = propertyBag.TryGetProperty(InternalSchema.DisplayName) as string;
            string           text3       = propertyBag.TryGetProperty(InternalSchema.AttachExtension) as string;

            if (!string.IsNullOrEmpty(text))
            {
                text = Attachment.TrimFilename(text);
            }
            if (!string.IsNullOrEmpty(text2))
            {
                text2 = Attachment.TrimFilename(text2);
            }
            if (!string.IsNullOrEmpty(text3))
            {
                text3 = '.' + Attachment.TrimFilename(text3);
            }
            string text4 = null;
            string text5 = null;
            string text6 = null;
            string text7 = null;

            Attachment.TryFindFileExtension(text, out text5, out text4);
            Attachment.TryFindFileExtension(text2, out text7, out text6);
            if (!string.IsNullOrEmpty(text5))
            {
                text3 = text5;
            }
            if (!string.IsNullOrEmpty(text7) && string.Compare(text3, text7, StringComparison.OrdinalIgnoreCase) != 0)
            {
                text6 += text7;
            }
            if (string.IsNullOrEmpty(text4))
            {
                text4 = Attachment.GenerateFilename();
            }
            if (EmailMessageHelpers.IsGeneratedFileName(text4) && string.IsNullOrEmpty(text3))
            {
                string text8 = propertyBag.TryGetProperty(InternalSchema.AttachMimeTag) as string;
                if (!string.IsNullOrEmpty(text8))
                {
                    text3 = StreamAttachmentBase.GetExtensionByContentType(text8);
                }
            }
            if (string.IsNullOrEmpty(text6))
            {
                text6 = text4;
            }
            if (!string.IsNullOrEmpty(text3))
            {
                text  = text4 + text3;
                text2 = text6 + text3;
            }
            else
            {
                text  = text4;
                text2 = text6;
                propertyBag.Delete(InternalSchema.AttachExtension);
            }
            propertyBag[InternalSchema.AttachLongFileName] = text;
            propertyBag[InternalSchema.DisplayName]        = text2;
            propertyBag[InternalSchema.AttachExtension]    = (text3 ?? string.Empty);
            bool      flag          = false;
            ICoreItem containerItem = coreAttachment.ParentCollection.ContainerItem;

            if (containerItem != null)
            {
                containerItem.PropertyBag.Load(new PropertyDefinition[]
                {
                    InternalSchema.IsAssociated
                });
                flag = containerItem.PropertyBag.GetValueOrDefault <bool>(InternalSchema.IsAssociated, false);
            }
            if (!flag)
            {
                propertyBag[InternalSchema.AttachFileName] = Attachment.Make8x3FileName(text, coreAttachment != null && coreAttachment.Session != null && coreAttachment.Session.IsMoveUser);
            }
        }