Exemplo n.º 1
0
 /// <summary>
 /// Only use for test harness.
 /// </summary>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static SmtpAgent Create(SmtpAgentSettings settings)
 {
     m_initialized = false;
     InitializeContainer(settings);
     Log.For<MessageArrivalEventHandler>().Debug(settings);
     return new SmtpAgent(settings);
 }
Exemplo n.º 2
0
 internal SmtpAgent(SmtpAgentSettings settings)
 {
     if (settings == null)
     {
         throw new ArgumentNullException("settings");
     }
     
     this.Init(settings);
 }
Exemplo n.º 3
0
 private static void InitializeContainer(SmtpAgentSettings settings)
 {
     lock (m_initSync)
     {
         if (!m_initialized)
         {
             SimpleDependencyResolver dependencyResolver = new SimpleDependencyResolver();
             if (settings.HasContainer && settings.Container.HasComponents)
             {
                 try
                 {
                     dependencyResolver.Register(settings.Container);
                 }
                 catch(Exception ex)
                 {
                     LogError(settings, ex);
                 }
             }
             EnsureDefaults(dependencyResolver, settings);
             IoC.Initialize(dependencyResolver);
             m_initialized = true;
         }
     }
 }
Exemplo n.º 4
0
 internal ConfigService(SmtpAgentSettings settings)
 {
     m_settings = settings;
 }
Exemplo n.º 5
0
 public void CleanMessages(SmtpAgentSettings settings)
 {
     CleanMessages(TestPickupFolder);
     CleanMessages(settings.Incoming);
     CleanMessages(settings.Outgoing);
     CleanMessages(settings.RawMessage);
     settings.IncomingRoutes.ToList().ForEach(
         route => {
                     if(route as FolderRoute != null)
                     {   
                         CleanMessages(((FolderRoute)route).CopyFolders);
                     }
         });
 }
Exemplo n.º 6
0
 internal MonitorService(SmtpAgentSettings settings)
 {
     m_settings = settings;
 }
Exemplo n.º 7
0
        //---------------------------------------------------
        //
        //  Agent Initialization
        //
        //---------------------------------------------------
        void Init(SmtpAgentSettings settings)
        {
            m_settings = settings;
            m_settings.Validate();

            m_auditor = IoC.ResolveAll<IAuditor<IBuildAuditLogMessage>>().ToList();
            
            m_logger = Log.For(this);

            m_diagnostics = new AgentDiagnostics(this);
            m_configService = new ConfigService(m_settings);
            m_monitorService = new MonitorService(m_settings);

            using (new MethodTracer(Logger))
            {
                try
                {
                    //
                    // First, setup defaults using Xml Config
                    //
                    this.InitDomains();
                    this.InitFolders();
                    this.InitRoutes();
                    this.InitNotifications();
                    //
                    // Call config service, if any was configured
                    //
                    this.InitDomainsFromConfigService();
                    //
                    // Finally, we can agent...
                    //
                    this.InitAgent();
                    this.SubscribeToAgentEvents();
                    this.ConfigureServicePoints();
                }
                catch (Exception ex)
                {
                    Logger.Error("While initializing {0}", ex.ToString());
                    throw;
                }
            }
        }
Exemplo n.º 8
0
        public void TestFilterCertificateByPolicy_outgoingPolicyCompliant_assertNoCertsFiltered()
        {
            string            configPath = GetSettingsPath("TestSmtpAgentConfig.xml");
            SmtpAgentSettings settings   = SmtpAgentSettings.LoadSettings(configPath);

            CleanMessages(settings);
            CleanMonitor();

            SetPolicyTestSettings(settings);

            //
            // Mock all policy resolvers
            //
            Mock <PrivatePolicyResolver> mockPrivatePolicyResolver;
            Mock <PublicPolicyResolver>  mockPublicPolicyResolver;
            Mock <TrustPolicyResolver>   mockTrustPolicyResolver;
            Mock <IPolicyFilter>         mockPolicyFilter;

            MockPrivatePolicyResolver(settings, out mockPrivatePolicyResolver, out mockPublicPolicyResolver, out mockTrustPolicyResolver, out mockPolicyFilter);

            Mock <IPolicyExpression> policyExpression = new Mock <IPolicyExpression>();

            mockPrivatePolicyResolver.Setup(r => r.GetIncomingPolicy(It.IsAny <MailAddress>()))
            .Returns(new List <IPolicyExpression>()
            {
                policyExpression.Object
            });
            mockPolicyFilter.Setup(r => r.IsCompliant(It.IsAny <X509Certificate2>(), It.IsAny <IPolicyExpression>()))
            .Returns(true);

            SmtpAgent smtpAgent = SmtpAgentFactory.Create(settings);


            //
            // Process loopback messages.  Leaves un-encrypted mdns in pickup folder
            // Go ahead and pick them up and Process them as if they where being handled
            // by the SmtpAgent by way of (IIS)SMTP hand off.
            //
            var sendingMessage = LoadMessage(TestMessage);

            Assert.DoesNotThrow(() => RunEndToEndTest(sendingMessage, smtpAgent));

            //
            // grab the clear text mdns and delete others.
            //
            bool foundMdns = false;

            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("disposition-notification"))
                {
                    foundMdns = true;
                    Assert.DoesNotThrow(() => RunMdnOutBoundProcessingTest(LoadMessage(messageText), smtpAgent));
                }
            }
            Assert.True(foundMdns);

            mockPublicPolicyResolver.Verify(r => r.GetOutgoingPolicy(new MailAddress("*****@*****.**"))
                                            , Times.Exactly(1));
            mockPublicPolicyResolver.Verify(r => r.GetOutgoingPolicy(new MailAddress("*****@*****.**"))
                                            , Times.Exactly(1));
            mockPolicyFilter.Verify(p => p.IsCompliant(It.IsAny <X509Certificate2>(), It.IsAny <IPolicyExpression>()), Times.Exactly(2));
            //
            // These two are never called.  These code paths do not exist.
            //
            mockPublicPolicyResolver.Verify(r => r.GetIncomingPolicy(It.IsAny <MailAddress>()), Times.Never());
            mockTrustPolicyResolver.Verify(r => r.GetOutgoingPolicy(It.IsAny <MailAddress>()), Times.Never());
        }
Exemplo n.º 9
0
        static void LogError(SmtpAgentSettings settings, Exception ex)
        {
            // if we blow up here we should write out to the EventLog w/o any logger
            // dependencies, etc...
            string source = settings == null
                            || settings.LogSettings == null
                            || string.IsNullOrEmpty(settings.LogSettings.EventLogSource)
                                ? null
                                : settings.LogSettings.EventLogSource;

            EventLogHelper.WriteError(source, "While loading SmtpAgent settings - " + ex);
        }
Exemplo n.º 10
0
 static void EnsureDefaults(SimpleDependencyResolver dependencyResolver, SmtpAgentSettings settings)
 {
     if (!dependencyResolver.IsRegistered<ILogFactory>())
     {
         dependencyResolver.Register<ILogFactory>(new NLogFactory(settings.LogSettings));
     }
     if (!dependencyResolver.IsRegistered<IAuditor<IBuildAuditLogMessage>>() && !dependencyResolver.IsRegistered<IAuditor>())
     {
         dependencyResolver.Register<IAuditor<IBuildAuditLogMessage>>(new SmtpAgentEventLogAuditor(new EventLogAuditor()));
     }
     if (dependencyResolver.IsRegistered<IAuditor>())
     {
         //
         // wrap legacy IAuditor
         //
         dependencyResolver.Register<IAuditor<IBuildAuditLogMessage>>(new SmtpAgentEventLogAuditor(dependencyResolver.Resolve<IAuditor>()));
     }
 }