示例#1
0
        /// <summary>
        /// Deletes the specified E mail message id list.
        /// </summary>
        /// <param name="EMailMessageIdList">The E mail message id list.</param>
        public static void Delete(ArrayList EMailMessageIdList)
        {
            using (DbTransaction tran = DbTransaction.Begin())
            {
                foreach (int EMailMessageId in EMailMessageIdList)
                {
                    if (PortalConfig.UseAntiSpamFilter && PortalConfig.AutoFillBlackList)
                    {
                        string senderEmail = EMailMessageRow.GetSenderEmail(EMailMessageId);

                        if (!string.IsNullOrEmpty(senderEmail) && !BlackListItem.Contains(senderEmail))
                        {
                            BlackListItem.Create(senderEmail);
                        }
                    }

                    EMailMessageRow.Delete(EMailMessageId);
                }

                tran.Commit();
            }
        }
示例#2
0
        /// <summary>
        /// Checks the specified email box.
        /// </summary>
        /// <param name="emailBox">The email box.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public static EMailMessageAntiSpamRuleRusult Check(EMailRouterPop3Box emailBox, Pop3Message message)
        {
            // 2007-01-09: Check Empty From and Sender
            if (message.Sender == null && message.From == null || message.To == null)
            {
                return(EMailMessageAntiSpamRuleRusult.Deny);
            }

            EMailMessageAntiSpamRule[] antiSpamRules = EMailMessageAntiSpamRule.List();

            // Load Rules
            //EMailMessageAntiSpamRule[] antiSpamRules = _antiSpamRules;

            // Check Rules

            foreach (EMailMessageAntiSpamRule rule in antiSpamRules)
            {
                if (((EMailMessageAntiSpamRuleType)rule.RuleType) != EMailMessageAntiSpamRuleType.Service)
                {
                    string KeyValue = GetStringFromEmailByKey(message, rule.Key);

                    if (KeyValue != null)
                    {
                        switch ((EMailMessageAntiSpamRuleType)rule.RuleType)
                        {
                        case EMailMessageAntiSpamRuleType.Contains:
                            foreach (string ContainsSubStr in rule.Value.Split(';'))
                            {
                                string TrimContainsSubStr = ContainsSubStr.Trim();
                                if (TrimContainsSubStr != string.Empty)
                                {
                                    if (TrimContainsSubStr.IndexOfAny(new char[] { '*', '?' }) != -1)
                                    {
                                        if (Pattern.Match(KeyValue, TrimContainsSubStr))
                                        {
                                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                                        }
                                    }
                                    else
                                    {
                                        if (KeyValue.IndexOf(TrimContainsSubStr) != -1)
                                        {
                                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                                        }
                                    }
                                }
                            }
                            break;

                        case EMailMessageAntiSpamRuleType.IsEqual:
                            if (string.Compare(KeyValue, rule.Value, true) == 0)
                            {
                                return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                            }
                            break;

                        case EMailMessageAntiSpamRuleType.RegexMatch:
                            Match match = Regex.Match(KeyValue, rule.Value);
                            if ((match.Success && (match.Index == 0)) && (match.Length == KeyValue.Length))
                            {
                                return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    string FromEmail = EMailMessage.GetSenderEmail(message);

                    switch (rule.Key)
                    {
                    case BlackListServiceName:
                        if (BlackListItem.Contains(FromEmail))
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;

                    case WhiteListServiceName:
                        if (WhiteListItem.Contains(FromEmail))
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;

                    case TicketServiceName:
                        if (message.Subject != null && TicketUidUtil.LoadFromString(message.Subject) != string.Empty)
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;

                    case IncidentBoxRulesServiceName:
                        // Step 1. Get Incident Info
                        IEMailIncidentMapping mappingHandler = EMailIncidentMappingHandler.LoadHandler(emailBox.Settings.SelectedHandlerId);
                        IncidentInfo          incidentInfo   = mappingHandler.Create(emailBox, message);

                        // Step 2. Evaluate IncidentBoxRules
                        IncidentBox box = IncidentBoxRule.Evaluate(incidentInfo, false);
                        if (box != null)
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;
                    }
                }
            }

            return(EMailMessageAntiSpamRuleRusult.Pending);
        }