예제 #1
0
        internal EmailMessageHash(EmailMessage emailMessage)
        {
            if (emailMessage == null)
            {
                throw new ArgumentNullException("emailMessage");
            }
            int num = 0;

            if (emailMessage.Attachments != null)
            {
                num = emailMessage.Attachments.Count;
            }
            int           capacity      = 8 + 9 * num;
            StringBuilder stringBuilder = new StringBuilder(capacity);

            using (Stream contentReadStream = emailMessage.Body.GetContentReadStream())
            {
                stringBuilder.AppendFormat("{0:X8}", EmailMessageHash.ComputeCRC(contentReadStream));
            }
            if (num > 0)
            {
                foreach (Attachment attachment in emailMessage.Attachments)
                {
                    using (Stream contentReadStream2 = attachment.GetContentReadStream())
                    {
                        stringBuilder.AppendFormat(",{0:X8}", EmailMessageHash.ComputeCRC(contentReadStream2));
                    }
                }
            }
            this.cachedHashString = stringBuilder.ToString();
        }
예제 #2
0
        internal static bool TryGetFromHeader(HeaderList mimeHeader, out EmailMessageHash result)
        {
            result = null;
            string property = XHeaderUtils.GetProperty(mimeHeader, "X-MS-Exchange-Forest-EmailMessageHash");

            if (string.IsNullOrEmpty(property))
            {
                return(false);
            }
            result = new EmailMessageHash(property);
            return(true);
        }
예제 #3
0
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs e)
        {
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)e;
            Header header = storeDriverDeliveryEventArgsImpl.MailItem.Message.MimeDocument.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Network-Message-Id");

            this.diagnosticsSession.TraceDebug <string>("Processing message {0}", (header != null) ? header.Value : "unknown");
            if (this.mimeHeaders != null)
            {
                this.diagnosticsSession.TraceDebug("Already processed this message", new object[0]);
                return;
            }
            this.mimeHeaders = storeDriverDeliveryEventArgsImpl.MailItem.Message.MimeDocument.RootPart.Headers;
            string property = this.GetProperty("X-MS-Exchange-Forest-IndexAgent");

            if (property == null || !XHeaderStream.IsVersionSupported(property))
            {
                this.diagnosticsSession.TraceDebug("X-header not present.", new object[0]);
                return;
            }
            bool             invalidAnnotationToken = false;
            EmailMessageHash emailMessageHash;

            if (EmailMessageHash.TryGetFromHeader(this.mimeHeaders, out emailMessageHash))
            {
                EmailMessageHash emailMessageHash2 = new EmailMessageHash(storeDriverDeliveryEventArgsImpl.MailItem.Message);
                this.diagnosticsSession.TraceDebug <EmailMessageHash>("Computed hash value for current message: {0}.", emailMessageHash2);
                if (!StringComparer.OrdinalIgnoreCase.Equals(emailMessageHash.ToString(), emailMessageHash2.ToString()))
                {
                    this.diagnosticsSession.TraceDebug <EmailMessageHash, EmailMessageHash>("The current hash value ({0}) doesn't match the original({1})", emailMessageHash2, emailMessageHash);
                    invalidAnnotationToken = true;
                }
            }
            try
            {
                using (XHeaderStream xheaderStream = new XHeaderStream(new Func <string, string>(this.GetProperty)))
                {
                    this.PromoteProperties(xheaderStream, storeDriverDeliveryEventArgsImpl.ReplayItem, invalidAnnotationToken);
                }
            }
            catch (Exception arg)
            {
                this.diagnosticsSession.TraceError <Exception>("Exception during PromoteProperties: {0}", arg);
            }
        }