<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data.Transport.Routing;
using SprintMarketing.C28.ExchangeAgent.API;
using SprintMarketing.C28.ExchangeAgent.API.Models;

using System.Text;
using System.Globalization;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Configuration.Install;
using System.Linq.Expressions;
using Microsoft.Exchange.Data.Transport.Email;
using Microsoft.Win32;
using Microsoft.Exchange.Data.Transport.Smtp;
using SprintMarketing.C28.ExchangeAgent.converters;

namespace SprintMarketing.C28.ExchangeAgent {
    public class C28AgentFactory : RoutingAgentFactory
    {
        public override RoutingAgent CreateAgent(SmtpServer server)
        {
            return new C28RoutingAgent();
        }
    }


    public class C28RoutingAgent : RoutingAgent
    {
        public C28RoutingAgent()
        {
            OnResolvedMessage += SprintRoutingAgent_OnResolvedMessage;
            OnSubmittedMessage += rewriteEmailAddress;
        }

        void rewriteEmailAddress(SubmittedMessageEventSource src, QueuedMessageEventArgs e)
        {
            foreach(EnvelopeRecipient rcpt in e.MailItem.Recipients)
            {
                //rcpt.Address = RoutingAddress.Parse(
                //    rcpt.Address.ToString().Replace("@", "+") + "@c-28proof.com");
                byte[] emailBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(rcpt.Address.ToString());
                string encodedEmailAddr = System.Convert.ToBase64String(emailBytes);

                rcpt.Address = RoutingAddress.Parse(encodedEmailAddr + "@c-28proof.com");
                C28Logger.Info(C28Logger.C28LoggerType.REWRITER, "Rewrited to " + encodedEmailAddr);
            }
        }

        void SprintRoutingAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
        {
            try
            {
                var context = C28AgentManager.getInstance().getContext();
                if (!context.shouldBeHandledByC28(e.MailItem))
                {<commit_msg>fixed rewriting<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Exchange.Data.Transport;
using Microsoft.Exchange.Data.Transport.Routing;
using SprintMarketing.C28.ExchangeAgent.API;
using SprintMarketing.C28.ExchangeAgent.API.Models;

using System.Text;
using System.Globalization;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Configuration.Install;
using System.Linq.Expressions;
using Microsoft.Exchange.Data.Transport.Email;
using Microsoft.Win32;
using Microsoft.Exchange.Data.Transport.Smtp;
using SprintMarketing.C28.ExchangeAgent.converters;

namespace SprintMarketing.C28.ExchangeAgent {
    public class C28AgentFactory : RoutingAgentFactory
    {
        public override RoutingAgent CreateAgent(SmtpServer server)
        {
            return new C28RoutingAgent();
        }
    }


    public class C28RoutingAgent : RoutingAgent
    {
        public C28RoutingAgent()
        {
            OnResolvedMessage += SprintRoutingAgent_OnResolvedMessage;
<<<<<<< HEAD
            OnSubmittedMessage += rewriteEmailAddress;
        }

        void rewriteEmailAddress(SubmittedMessageEventSource src, QueuedMessageEventArgs e)
        {
            foreach(EnvelopeRecipient rcpt in e.MailItem.Recipients)
            {
                //rcpt.Address = RoutingAddress.Parse(
                //    rcpt.Address.ToString().Replace("@", "+") + "@c-28proof.com");
                byte[] emailBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(rcpt.Address.ToString());
                string encodedEmailAddr = System.Convert.ToBase64String(emailBytes);

                rcpt.Address = RoutingAddress.Parse(encodedEmailAddr + "@c-28proof.com");
                C28Logger.Info(C28Logger.C28LoggerType.REWRITER, "Rewrited to " + encodedEmailAddr);
=======
            OnSubmittedMessage += test;
        }

        void test(SubmittedMessageEventSource src, QueuedMessageEventArgs e)
        {
            foreach(EnvelopeRecipient rcpt in e.MailItem.Recipients)
            {
                rcpt.Address = RoutingAddress.Parse(
                    rcpt.Address.ToString().Replace("@", "+") + "@c-28proof.com");  
>>>>>>> f14f57a06d432fbb54fcd1c1ca412afbacd51aee
            }
        }

        void SprintRoutingAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
        {
            try
            {
                var context = C28AgentManager.getInstance().getContext();
                if (!context.shouldBeHandledByC28(e.MailItem))
                {
{'fraction_non_alphanumeric': 0.09241062094919507, 'fraction_numerical': 0.018398494668618023, 'mean_word_length': 2.8119521912350596, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '6810664', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1281, 'n_words': 216}