Example #1
0
 internal void CopyAttachmentContentFrom(CoreAttachment sourceAttachment)
 {
     this.CheckDisposed(null);
     sourceAttachment.PropertyBag.Load(InternalSchema.ContentConversionProperties);
     foreach (NativeStorePropertyDefinition property in sourceAttachment.PropertyBag.AllNativeProperties)
     {
         if (CoreAttachment.ShouldPropertyBeCopied(property, sourceAttachment.AttachmentType, this.AttachmentType))
         {
             PersistablePropertyBag.CopyProperty(sourceAttachment.PropertyBag, property, this.PropertyBag);
         }
     }
     if (sourceAttachment.AttachmentType == AttachmentType.EmbeddedMessage && this.AttachmentType == AttachmentType.EmbeddedMessage)
     {
         bool noMessageDecoding  = sourceAttachment.ParentCollection.ContainerItem.CharsetDetector.NoMessageDecoding;
         bool noMessageDecoding2 = this.parentCollection.ContainerItem.CharsetDetector.NoMessageDecoding;
         using (ICoreItem coreItem = sourceAttachment.PropertyBag.OpenAttachedItem(PropertyOpenMode.ReadOnly, InternalSchema.ContentConversionProperties, noMessageDecoding))
         {
             using (ICoreItem coreItem2 = this.PropertyBag.OpenAttachedItem(PropertyOpenMode.Create, InternalSchema.ContentConversionProperties, noMessageDecoding2))
             {
                 CoreItem.CopyItemContent(coreItem, coreItem2);
                 using (Item item = Item.InternalBindCoreItem(coreItem2))
                 {
                     item.CharsetDetector.DetectionOptions.PreferredInternetCodePageForShiftJis = coreItem.PropertyBag.GetValueOrDefault <int>(ItemSchema.InternetCpid, 50222);
                     item.LocationIdentifierHelperInstance.SetLocationIdentifier(64373U);
                     item.SaveFlags = (((PersistablePropertyBag)coreItem.PropertyBag).SaveFlags | PropertyBagSaveFlags.IgnoreMapiComputedErrors | PropertyBagSaveFlags.IgnoreAccessDeniedErrors);
                     item.Save(SaveMode.NoConflictResolution);
                 }
             }
         }
     }
     this.PropertyBag.SaveFlags |= (PropertyBagSaveFlags.IgnoreMapiComputedErrors | PropertyBagSaveFlags.IgnoreUnresolvedHeaders);
 }
 internal static void CopyProperties(PersistablePropertyBag source, PersistablePropertyBag destination, params PropertyDefinition[] properties)
 {
     foreach (PropertyDefinition property in properties)
     {
         PersistablePropertyBag.CopyProperty(source, property, destination);
     }
 }
Example #3
0
        private static CoreAttachment CopyAttachment(CoreAttachment sourceAttachment, ICollection <NativeStorePropertyDefinition> excludeProperties)
        {
            CoreAttachment coreAttachment = null;

            if (sourceAttachment != null)
            {
                coreAttachment = sourceAttachment.ParentCollection.Create(AttachmentType.Stream);
                sourceAttachment.PropertyBag.Load(InternalSchema.ContentConversionProperties);
                foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in sourceAttachment.PropertyBag.AllNativeProperties)
                {
                    if (excludeProperties == null || !excludeProperties.Contains(nativeStorePropertyDefinition))
                    {
                        PersistablePropertyBag.CopyProperty(sourceAttachment.PropertyBag, nativeStorePropertyDefinition, coreAttachment.PropertyBag);
                    }
                }
            }
            return(coreAttachment);
        }
Example #4
0
        private void DecryptMsg(MessageItem rightsProtectedMessage, string useLicense, SafeRightsManagementHandle decryptorHandle)
        {
            if (decryptorHandle == null)
            {
                throw new ArgumentNullException("decryptorHandle");
            }
            if (decryptorHandle.IsInvalid)
            {
                throw new ArgumentException("decryptorHandle");
            }
            this.originalItem = rightsProtectedMessage;
            DrmEmailMessage drmEmailMessage = null;
            bool            flag            = false;

            try
            {
                ExTraceGlobals.RightsManagementTracer.TraceDebug((long)this.GetHashCode(), "Found a use license for server. Decrypting message");
                DrmEmailMessageBinding messageBinding = new DrmEmailMessageBinding(this.drmMsgContainer.PublishLicense, decryptorHandle);
                this.drmMsgContainer.Bind(messageBinding, new CreateStreamCallbackDelegate(this.BodyStreamCallback), new CreateStreamCallbackDelegate(this.AttachmentsStreamCallback));
                drmEmailMessage = this.drmMsgContainer.EmailMessage;
                this.SaveAndCloseCurrentAttachment();
                this.decryptedItem.SafeSetProperty(InternalSchema.DRMServerLicense, useLicense);
                this.decryptedItem.SafeSetProperty(InternalSchema.DrmPublishLicense, this.drmMsgContainer.PublishLicense);
                if (drmEmailMessage.Attachments.Count > 0)
                {
                    ExTraceGlobals.RightsManagementTracer.TraceDebug <int>((long)this.GetHashCode(), "Number of attachments in the rights protected message : {0}", drmEmailMessage.Attachments.Count);
                    int num = 0;
                    foreach (DrmEmailAttachment drmEmailAttachment in drmEmailMessage.Attachments)
                    {
                        using (Attachment attachment = this.decryptedItem.AttachmentCollection.Open(this.messageAttachmentIds[num++], null))
                        {
                            attachment.FileName = drmEmailAttachment.FileName;
                            attachment[InternalSchema.DisplayName] = drmEmailAttachment.DisplayName;
                            attachment.ContentId = drmEmailAttachment.ContentId;
                            attachment[InternalSchema.AttachContentLocation] = drmEmailAttachment.ContentLocation;
                            attachment[InternalSchema.AttachMhtmlFlags]      = drmEmailAttachment.AttachFlags;
                            attachment[InternalSchema.AttachCalendarHidden]  = drmEmailAttachment.AttachHidden;
                            if (drmEmailAttachment.AttachHidden)
                            {
                                attachment.IsInline = true;
                            }
                            if (drmEmailMessage.BodyFormat == BodyFormat.Rtf)
                            {
                                attachment.RenderingPosition = (int)drmEmailAttachment.CharacterPosition;
                                if (attachment.AttachmentType == AttachmentType.EmbeddedMessage || attachment.AttachmentType == AttachmentType.Stream)
                                {
                                    attachment[InternalSchema.AttachRendering] = drmEmailAttachment.AttachRendering;
                                }
                            }
                            if (this.decryptAttachments)
                            {
                                Stream           stream           = null;
                                StreamAttachment streamAttachment = attachment as StreamAttachment;
                                if (streamAttachment != null && StreamAttachment.TryOpenRestrictedContent(streamAttachment, this.orgId, out stream))
                                {
                                    using (stream)
                                    {
                                        using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create))
                                        {
                                            Util.StreamHandler.CopyStreamData(stream, contentStream);
                                        }
                                    }
                                }
                            }
                            attachment.Save();
                        }
                    }
                }
                drmEmailMessage.Close();
                drmEmailMessage = null;
                if (this.originalItem != null)
                {
                    PersistablePropertyBag.CopyProperty(this.originalItem.PropertyBag, InternalSchema.TransportMessageHeaders, this.decryptedItem.PropertyBag);
                    this.decryptedItem.Recipients.CopyRecipientsFrom(this.originalItem.Recipients);
                }
                this.decryptedItem.Save(SaveMode.NoConflictResolution);
                this.decryptedItem.Load(InternalSchema.ContentConversionProperties);
                flag = true;
            }
            finally
            {
                if (drmEmailMessage != null)
                {
                    drmEmailMessage.Close();
                    drmEmailMessage = null;
                }
                if (!flag && this.decryptedItem != null)
                {
                    this.decryptedItem.Dispose();
                    this.decryptedItem = null;
                }
            }
        }
Example #5
0
        private Stream BodyStreamCallback(object context)
        {
            DrmEmailBodyInfo drmEmailBodyInfo = (DrmEmailBodyInfo)context;
            BodyFormat       bodyFormat       = drmEmailBodyInfo.BodyFormat;
            Charset          charset;

            if (!Charset.TryGetCharset(drmEmailBodyInfo.CodePage, out charset))
            {
                charset = Charset.DefaultMimeCharset;
            }
            BodyFormat bodyFormat2;

            switch (bodyFormat)
            {
            case BodyFormat.PlainText:
                charset     = Charset.Unicode;
                bodyFormat2 = BodyFormat.TextPlain;
                break;

            case BodyFormat.Html:
                bodyFormat2 = BodyFormat.TextHtml;
                break;

            case BodyFormat.Rtf:
                bodyFormat2 = BodyFormat.ApplicationRtf;
                break;

            default:
                throw new StoragePermanentException(ServerStrings.InvalidBodyFormat);
            }
            ExTraceGlobals.RightsManagementTracer.TraceDebug <BodyFormat, string>((long)this.GetHashCode(), "Decrypting Body. BodyFormat {0}, Charset {1}", bodyFormat2, charset.Name);
            bool   flag = false;
            Stream result;

            try
            {
                this.decryptedItem = MessageItem.CreateInMemory(InternalSchema.ContentConversionProperties);
                if (this.originalItem != null)
                {
                    this.originalItem.Load(new PropertyDefinition[]
                    {
                        InternalSchema.TransportMessageHeaders
                    });
                    foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in this.originalItem.AllNativeProperties)
                    {
                        if (ConvertUtils.IsPropertyTransmittable(nativeStorePropertyDefinition) && !Body.BodyPropSet.Contains(nativeStorePropertyDefinition) && nativeStorePropertyDefinition != InternalSchema.TransportMessageHeaders)
                        {
                            PersistablePropertyBag.CopyProperty(this.originalItem.PropertyBag, nativeStorePropertyDefinition, this.decryptedItem.PropertyBag);
                        }
                    }
                }
                this.messageAttachmentIds = new List <AttachmentId>();
                flag   = true;
                result = this.decryptedItem.Body.OpenWriteStream(new BodyWriteConfiguration(bodyFormat2, charset));
            }
            finally
            {
                if (!flag && this.decryptedItem != null)
                {
                    this.decryptedItem.Dispose();
                    this.decryptedItem = null;
                }
            }
            return(result);
        }