<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using log4net;
using Microsoft.Exchange.WebServices.Data;

namespace Mail2Bug.Email.EWS
{
    public class EWSIncomingMessage : IIncomingEmailMessage
    {
        private readonly EmailMessage _message;

        public EWSIncomingMessage(EmailMessage message)
        {
            _message = message;

            message.Load(new PropertySet(
                    ItemSchema.Subject,
                    ItemSchema.Body, 
                    EmailMessageSchema.ConversationIndex,
                    ItemSchema.ConversationId,
                    EmailMessageSchema.Sender,
                    EmailMessageSchema.From,
                    EmailMessageSchema.ToRecipients,
                    EmailMessageSchema.CcRecipients,
                    ItemSchema.MimeContent,
                    ItemSchema.DateTimeReceived,
                    ItemSchema.DateTimeSent,
                    EmailMessageSchema.ConversationTopic,
                    ItemSchema.Attachments,
                    ItemSchema.HasAttachments,
                    MeetingRequestSchema.Location,
                    MeetingRequestSchema.Start,
                    MeetingRequestSchema.End
                ));
            
            Attachments = BuildAttachmentList(message);
        }

        public string Subject { get { return _message.Subject; } }
        public string ConversationTopic { get { return _message.ConversationTopic; } }
        public string RawBody { get { return _message.Body.Text ?? string.Empty; } }
        public string PlainTextBody { get { return GetPlainTextBody(_message); } }
        public string ConversationGuid { get { return _message.ConversationId.UniqueId; } }

        public string ConversationIndex
        {
            get { return string.Join("", _message.ConversationIndex.Select(b => b.ToString("X2"))); }
        }

        public string SenderName { get { return _message.Sender.Name; } }
        public string SenderAlias { get { return GetAliasFromEmailAddress(_message.Sender.Address); } }
        public string SenderAddress { get { return _message.Sender.Address; } }
        public IEnumerable<string> ToAddresses { get { return _message.ToRecipients.Select(x => x.Address); } }
        public IEnumerable<string> CcAddresses { get { return _message.CcRecipients.Select(x => x.Address); } }
        public IEnumerable<string> ToNames { get { return _message.ToRecipients.Select(x => x.Name); } }
        public IEnumerable<string> CcNames { get { return _message.CcRecipients.Select(x => x.Name); } }
        public DateTime SentOn { get { return _message.DateTimeSent; } }
        public DateTime ReceivedOn { get { return _message.DateTimeReceived; } }
        public bool IsHtmlBody { get { return _message.Body.BodyType == BodyType.HTML; } }

        public string Location
        {
            get
            {
                var x = _message as MeetingRequest;
                return (x == null) ? "Not a meeting request - no location" : x.Location;<commit_msg>Use Extended property to get the ConversationGuid<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using log4net;
using Microsoft.Exchange.WebServices.Data;

namespace Mail2Bug.Email.EWS
{
    public class EWSIncomingMessage : IIncomingEmailMessage
    {
        private readonly EmailMessage _message;
        private readonly byte[] _conversationId;

        public EWSIncomingMessage(EmailMessage message)
        {
            _message = message;

            message.Load(new PropertySet(
                    ItemSchema.Subject,
                    ItemSchema.Body, 
                    EmailMessageSchema.ConversationIndex,
                    ItemSchema.ConversationId,
                    EmailMessageSchema.Sender,
                    EmailMessageSchema.From,
                    EmailMessageSchema.ToRecipients,
                    EmailMessageSchema.CcRecipients,
                    ItemSchema.MimeContent,
                    ItemSchema.DateTimeReceived,
                    ItemSchema.DateTimeSent,
                    EmailMessageSchema.ConversationTopic,
                    ItemSchema.Attachments,
                    ItemSchema.HasAttachments,
                    MeetingRequestSchema.Location,
                    MeetingRequestSchema.Start,
                    MeetingRequestSchema.End
                ));
            
            Attachments = BuildAttachmentList(message);
        }

        public string Subject { get { return _message.Subject; } }
        public string ConversationTopic { get { return _message.ConversationTopic; } }
        public string RawBody { get { return _message.Body.Text ?? string.Empty; } }
        public string PlainTextBody { get { return GetPlainTextBody(_message); } }

        public string ConversationGuid
        {
            get { return string.Join("", _conversationId.Select(b => b.ToString("X2"))); }
        }

        public string ConversationIndex
        {
            get { return string.Join("", _message.ConversationIndex.Select(b => b.ToString("X2"))); }
        }

        public string SenderName { get { return _message.Sender.Name; } }
        public string SenderAlias { get { return GetAliasFromEmailAddress(_message.Sender.Address); } }
        public string SenderAddress { get { return _message.Sender.Address; } }
        public IEnumerable<string> ToAddresses { get { return _message.ToRecipients.Select(x => x.Address); } }
        public IEnumerable<string> CcAddresses { get { return _message.CcRecipients.Select(x => x.Address); } }
        public IEnumerable<string> ToNames { get { return _message.ToRecipients.Select(x => x.Name); } }
        public IEnumerable<string> CcNames { get { return _message.CcRecipients.Select(x => x.Name); } }
        public DateTime SentOn { get { return _message.DateTimeSent; } }
        public DateTime ReceivedOn { get { return _message.DateTimeReceived; } }
        public bool IsHtmlBody { get { return _message.Body.BodyType == BodyType.HTML; } }

        public string Location
        {
            get
            {
                var x = _message as MeetingRequest;
                return (x == null) ? "Not a meeting request - no location" : x.Location;
{'fraction_non_alphanumeric': 0.0803092458188703, 'fraction_numerical': 0.001104449353108236, 'mean_word_length': 2.0891812865497075, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5886820', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1528, 'n_words': 353}