diff src/context.cpp @ 259:be939802c64e

add recipient rate limits by email from address or domain
author Carl Byington <carl@five-ten-sg.com>
date Sat, 21 Jul 2012 08:34:04 -0700
parents d6d5c50b9278
children e118fd2c6af0
line wrap: on
line diff
--- a/src/context.cpp	Sun Jul 01 10:34:43 2012 -0700
+++ b/src/context.cpp	Sat Jul 21 08:34:04 2012 -0700
@@ -843,8 +843,22 @@
 
 int CONTEXT::find_rate(const char *user) {
     if (rcpt_per_hour.empty()) return default_rcpt_rate;
-    rcpt_rates::iterator i = rcpt_per_hour.find(user);
-    return (i == rcpt_per_hour.end()) ? default_rcpt_rate : (*i).second;
+    rcpt_rates::iterator i = rcpt_per_hour.find(user);  // look for authen id, or sender user@email limiting
+    if (i != rcpt_per_hour.end()) return (*i).second;   // found authen id, or user@email limiting
+    const char *f = strchr(user, '@');
+    if (!f) return default_rcpt_rate;
+    i = rcpt_per_hour.find(f);                          // look for @domain limiting
+    if (i != rcpt_per_hour.end()) return (*i).second;   // found @domain limiting
+    return default_rcpt_rate;
+}
+
+
+bool CONTEXT::is_unauthenticated_limited(const char *user) {
+    rcpt_rates::iterator i = rcpt_per_hour.find(user);  // look for sender user@email limiting
+    if (i != rcpt_per_hour.end()) return true;          // found user@email limiting
+    const char *f = strchr(user, '@');
+    i = rcpt_per_hour.find(f);                  // look for sender @domain limiting
+    return (i != rcpt_per_hour.end());          // found @domain limiting
 }