コード例 #1
0
        private static Email ForwardEmail(Email email)
        {
            var result = email;

            email.FromAddress.Email = email.FromAddress.Name = GetPhoneNumber(email.PlainTextBody, Prefix, Postfix);

            return result;
        }
コード例 #2
0
        public bool CreateEmail(Email email)
        {
            if (email.EmailReference.IsNullOrEmpty())
                return false;

            _emailContext.Emails.Add(email);

            return _emailContext.SaveChanges() > 0;
        }
コード例 #3
0
        private static Email ForwardEmail(Email email)
        {
            var result = email;
            var subject = $"Forwarded Message from {email.Subject}";

            email.FromAddress.Name = email.FromAddress.Email = email.Subject;
            result.Subject = subject;

            return result;
        }
コード例 #4
0
        public bool SendEmail(IMailboxSettings mailboxSettings, Email email)
        {
            bool success;

            lock (_key)
            {
                success = _mailAdaptor.SendEmail(mailboxSettings, email);
            }

            return success;
        }
        public void Subject_Does_Not_Contain_Mobile_Number_Rule_Is_Not_Applied()
        {
            //arrange
            const string subject = "The quick brown fox";
            var email = new Email { Subject = subject };

            //act
            var result = _rule.ApplyRule(email);

            //assert
            result.RuleApplied.Should().BeFalse();
        }
コード例 #6
0
        public void Subject_Is_Not_Valid_Email_Address_Rule_Is_Not_Applied()
        {
            //arrange
            const string subject = "The quick brown fox";
            var email = new Email { Subject = subject };

            _validatorMock.Setup(x => x.IsValidEmail(subject)).Returns(false);

            //act
            var result = _rule.ApplyRule(email);

            //assert
            result.RuleApplied.Should().BeFalse();
        }
コード例 #7
0
        public void All_Rules_Are_Tried_If_No_Rules_Apply()
        {
            //arrange
            var email = new Email();

            _mockRule1.Setup(x => x.ApplyRule(email)).Returns(new RuleResult { RuleApplied = false });
            _mockRule2.Setup(x => x.ApplyRule(email)).Returns(new RuleResult { RuleApplied = false });
            _mockRule3.Setup(x => x.ApplyRule(email)).Returns(new RuleResult { RuleApplied = false });

            //act
            _forwardService.ProcessEmail(email);

            //assert
            _mockRule1.Verify(x => x.ApplyRule(email), Times.Once());
            _mockRule2.Verify(x => x.ApplyRule(email), Times.Once());
            _mockRule3.Verify(x => x.ApplyRule(email), Times.Once());
        }
コード例 #8
0
        private Email ForwardEmailFromAutoMessaging(Email email, string tenantEmailAddress)
        {
            var result = email;
            var subject = email.Subject.Split(']')[1];

            var fromAddress = result.FromAddress;
            result.Subject = subject;
            result.EmailAddresses.Clear();
            result.EmailAddresses.Add(fromAddress);
            result.EmailAddresses.Add(new EmailAddress
            {
                Email = tenantEmailAddress,
                Type = EmailAddressType.To
            });

            return result;
        }
コード例 #9
0
        public void Rules_Are_Tried_Until_Rule_Applies_And_Rest_Are_Ignored()
        {
            //arrange
            var email = new Email();

            _mockRule1.Setup(x => x.ApplyRule(email)).Returns(new RuleResult { RuleApplied = false });
            _mockRule2.Setup(x => x.ApplyRule(email)).Returns(new RuleResult { RuleApplied = true });
            _mockRule3.Setup(x => x.ApplyRule(email)).Returns(new RuleResult { RuleApplied = false });

            //act
            _forwardService.ProcessEmail(email);

            //assert
            _mockRule1.Verify(x => x.ApplyRule(email), Times.Once());
            _mockRule2.Verify(x => x.ApplyRule(email), Times.Once());
            _mockRule3.Verify(x => x.ApplyRule(email), Times.Never());
        }
コード例 #10
0
        public ForwardResult ProcessEmail(Email email)
        {
            foreach (
                var result in
                    _forwardingRuleFactory.GetRules()
                        .Select(rule => rule.ApplyRule(email))
                        .Where(result => result.RuleApplied))
            {
                return new ForwardResult
                {
                    RuleApplied = result.RuleName,
                    EmailResult = result.Email,
                };
            }

            return new ForwardResult {EmailResult = email};
        }
コード例 #11
0
        public void CreateReference_Sets_NoteReference()
        {
            //arrange
            const string reference = "ABCDE12345";
            var mockReferenceGenerator = new Mock<IReferenceGenerator>();
            var email = new Email();

            mockReferenceGenerator.Setup(x => x.CreateReference(It.IsAny<int>())).Returns(reference);

            //act
            email.CreateReference(mockReferenceGenerator.Object);

            //assert
            email.EmailReference.Should().NotBeNullOrWhiteSpace();
            email.EmailReference.Should().Be(reference);

            mockReferenceGenerator.Verify(x => x.CreateReference(It.IsAny<int>()), Times.Once);
        }
コード例 #12
0
        public RuleResult ApplyRule(Email email)
        {
            if (IsValidEmailAddress(email.Subject))
            {
                return new RuleResult
                {
                    RuleName = RuleName,
                    RuleApplied = true,
                    Email = ForwardEmail(email),
                };
            }

            return new RuleResult
            {
                RuleName = RuleName,
                RuleApplied = false,
                Email = email,
            };
        }
コード例 #13
0
        public RuleResult ApplyRule(Email email)
        {
            if (IsPhoneNumberInBody(email.PlainTextBody))
            {
                return new RuleResult
                {
                    RuleName = RuleName,
                    RuleApplied = true,
                    Email = ForwardEmail(email),
                };
            }

            return new RuleResult
            {
                RuleName = RuleName,
                RuleApplied = false,
                Email = email
            };
        }
コード例 #14
0
        public RuleResult ApplyRule(Email email)
        {
            if (IsPhoneNumberInSubject(email.Subject))
            {
                return new RuleResult
                {
                    RuleName = RuleName,
                    RuleApplied = true,
                    Email = ForwardEmail(email),
                };
            }

            return new RuleResult
            {
                RuleName = RuleName,
                RuleApplied = false,
                Email = email
            };
        }
コード例 #15
0
        public RuleResult ApplyRule(Email email)
        {
            var emailAddress = GetEmailAddressFromSubject(email.Subject);
            if (!string.IsNullOrEmpty(emailAddress))
            {
                return new RuleResult
                {
                    RuleName = RuleName,
                    RuleApplied = true,
                    Email = ForwardEmailFromAutoMessaging(email, emailAddress)
                };
            }

            return new RuleResult
            {
                RuleName = RuleName,
                RuleApplied = false,
                Email = email
            };
        }
        public void Subject_Contains_Mobile_Number_Rule_Is_Applied()
        {
            //arrange
            const string subject = "Dynmark MMS Alert Service. To 447717989072, from 447873128112, on 2014-07-28 16:20 (Monday, 28 July at 16:20)- M";

            var email = new Email
            {
                Subject = subject,
                EmailAddresses =
                    new List<EmailAddress>
                    {
                        new EmailAddress {Name = "Test", Email = "*****@*****.**", Type = EmailAddressType.From}
                    }
            };

            //act
            var result = _rule.ApplyRule(email);

            //assert
            result.RuleApplied.Should().BeTrue();
        }
        public void Subject_Contains_Mobile_Number_Rule_Is_Applied()
        {
            //arrange
            const string body = "Message sent in by 07532 451297 to 447717989072 on Thursday, 21st March at 19:09:32. Message content follows: You've been sent a picture message by 447532451297 open it at http://www.vodafone.co.uk/getmyphoto your password is rfb51zsy";

            var email = new Email
            {
                PlainTextBody = body,
                EmailAddresses =
                    new List<EmailAddress>
                    {
                        new EmailAddress {Name = "Test", Email = "*****@*****.**", Type = EmailAddressType.From}
                    }
            };

            //act
            var result = _rule.ApplyRule(email);

            //assert
            result.RuleApplied.Should().BeTrue();
        }
コード例 #18
0
        public static IMail MapToIMail(Email message)
        {
            var builder = new MailBuilder();

            ProcessEmailAddresses(builder, message.EmailAddresses);

            builder.Subject = message.Subject;
            builder.Text = message.PlainTextBody;
            builder.PriorityHigh();

            if (!string.IsNullOrEmpty(message.HtmlBody))
                builder.Html = message.HtmlBody;

            foreach (var ea in message.Attachments)
            {
                var attachment = builder.AddAttachment(ea.ByteArray);
                attachment.FileName = ea.AttachmentName;
                attachment.ContentType = ContentType.Parse(ea.MimeType);
            }

            return builder.Create();
        }
コード例 #19
0
        public void Subject_Is_Valid_Email_Address_Rule_Is_Applied()
        {
            //arrange
            const string subject = "*****@*****.**";

            var email = new Email
            {
                Subject = subject,
                EmailAddresses =
                    new List<EmailAddress>
                    {
                        new EmailAddress {Name = "Test", Email = "*****@*****.**", Type = EmailAddressType.From}
                    }
            };

            _validatorMock.Setup(x => x.IsValidEmail(subject)).Returns(true);

            //act
            var result = _rule.ApplyRule(email);

            //assert
            result.RuleApplied.Should().BeTrue();
        }
コード例 #20
0
        public bool SendEmail(IMailboxSettings mailboxSettings, Email email)
        {
            using (var client = new Smtp())
            {
                try
                {
                    client.ConnectSSL(mailboxSettings.ServerAddress, mailboxSettings.ServerPort);
                    client.LoginOAUTH2(email.FromAddress.Email, _oAuth2Authenticator.GetOAuth2AccessToken(email.FromAddress.Email));

                    return client.SendMessage(EmailMapper.MapToIMail(email)).Status == SendMessageStatus.Success;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
        }
コード例 #21
0
 private ForwardResult ApplyProcessingRules(IMailboxSettings mailboxSettings, Email email)
 {
     return mailboxSettings.ApplyForwardingRules
         ? _forwardService.ProcessEmail(email)
         : new ForwardResult {EmailResult = email};
 }
コード例 #22
0
        public string Send(Email email)
        {
            var config = _mailboxConfiguration.Mailboxes.FirstOrDefault(x => x.Outbound);

            if (config.IsNull())
                return string.Empty;

            _emailRepository.CreateEmail(email.CreateReference(_referenceGenerator).SetDirection(Direction.Outbound).SetAccountName(config.AccountName));

            if (!_emailServiceSettings.SendEnabled)
                return email.EmailReference;

            var result = _emailProvider.SendEmail(config, email);

            _emailRepository.UpdateStatus(email.EmailReference, result ? Status.Success : Status.Error);

            return result ? email.EmailReference : string.Empty;
        }
コード例 #23
-1
        public static Email MapEmailToCoreEmail(string accountName, long emailId, IMail email)
        {
            var message = new Email
            {
                AccountName = accountName,
                EmailUid = emailId,
                EmailAddresses = ProcessEmailAddresses(email),
                Subject = email.Subject,
                HtmlBody = email.GetBodyAsHtml(),
                PlainTextBody = email.GetBodyAsText(),
                Date = email.Date?.ToUniversalTime() ?? DateTime.UtcNow,
                Direction = Direction.Inbound,
                Status = Status.Unknown,
            };

            message.Attachments.AddRange(ExtractAttachments(email.NonVisuals));
            message.Attachments.AddRange(ExtractAttachments(email.Visuals));

            return message;
        }