Esempio n. 1
0
        /// <summary>
        /// Gets the maximum amount of simultaneous connections to specified host.
        /// </summary>
        /// <param name="ipAddress">IP Address connecting from.</param>
        /// <param name="record">MXRecord of the destination.</param>
        /// <returns>Max number of connections.</returns>
        internal static int GetMaxConnectionsToDestination(VirtualMTA ipAddress, MXRecord record)
        {
            int mxPatternID = -1;
            OutboundRuleCollection rules = OutboundRuleManager.GetRules(record, ipAddress, out mxPatternID);

            for (int i = 0; i < rules.Count; i++)
            {
                if (rules[i].Type == OutboundRuleType.MaxConnections)
                {
                    int tmp = 0;
                    if (int.TryParse(rules[i].Value, out tmp))
                    {
                        return(tmp);
                    }
                    else
                    {
                        Logging.Error("Failed to get max connections for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " value wasn't valid [" + rules[i].Value + "], defaulting to 1");
                        return(1);
                    }
                }
            }

            Logging.Error("Failed to get max connections for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " defaulting to 1");
            return(1);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the maximum amount of messages to send per hour from each ip address to mx.
        /// </summary>
        /// <param name="ipAddress">Outbound IP address</param>
        /// <param name="record">MX Record of destination server.</param>
        /// <param name="mxPatternID">ID of the pattern used to identify the rule.</param>
        /// <returns>Maximum number of messages per hour or -1 for unlimited.</returns>
        public static int GetMaxMessagesDestinationHour(VirtualMTA ipAddress, MXRecord record, out int mxPatternID)
        {
            OutboundRuleCollection rules = OutboundRuleManager.GetRules(record, ipAddress, out mxPatternID);

            for (int i = 0; i < rules.Count; i++)
            {
                if (rules[i].Type == OutboundRuleType.MaxMessagesPerHour)
                {
                    int tmp = 0;
                    if (int.TryParse(rules[i].Value, out tmp))
                    {
                        return(tmp);
                    }
                    else
                    {
                        Logging.Error("Failed to get max messages per hour for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " value wasn't valid [" + rules[i].Value + "], defaulting to unlimited");
                        return(-1);
                    }
                }
            }

            Logging.Error("Failed to get max messages per hour for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " defaulting to unlimited");
            return(-1);
        }