Jason R. Mastaler wrote:
> Ed Blackman <[EMAIL PROTECTED]> writes:
>> OR, I could simply change the 'sender' HMAC matching logic to use
>> the same sort of fallback algorithm I use for domain addresses
> 
> I like this idea better.  Onward!

See attached patch.

tmda-address works as previously discussed.  In outgoing filters, I
added a new action, 'domain'.  Both 'sender' and 'domain' actions
generate sender addresses, but 'domain' strips the local part and '@'
from the argument first.

Ed

diff -ur tmda/TMDA/Address.py tmda-cvs-0.83/TMDA/Address.py
--- tmda/TMDA/Address.py        Wed Jun 25 01:29:13 2003
+++ tmda-cvs-0.83/TMDA/Address.py       Thu Aug 28 16:30:10 2003
@@ -201,11 +201,24 @@
         self.address = tagged_local + '@' + domain
         return self
 
+    # Try to match against the HMAC generated from the full sender first.
+    # If that doesn't match, try to match against the full domain, removing
+    # domain parts (eg, 'foo.example.com' => 'example.com') until there's a
+    # match or there are no more parts left.
     def verify(self, sender):
+        sender = str(sender).lower()
         hmac = self.local_parts[-1]
-        try_hmac = Cookie.make_sender_cookie(str(sender).lower())
+        try_hmac = Cookie.make_sender_cookie(sender)
         if try_hmac != hmac:
-            raise BadCryptoError, "Invalid cryptographic tag."
+            domain = sender.split('@')[-1]
+            dot = '.'
+            domain_parts = domain.split(dot)
+
+            while try_hmac != hmac and domain_parts:
+              try_hmac = Cookie.make_sender_cookie(dot.join(domain_parts))
+              del domain_parts[0]
+            if try_hmac != hmac:
+              raise BadCryptoError, "Invalid cryptographic tag."
 
     def hmac(self):
         return self.local_parts[-1]
diff -ur tmda/TMDA/FilterParser.py tmda-cvs-0.83/TMDA/FilterParser.py
--- tmda/TMDA/FilterParser.py   Tue Aug 19 20:28:03 2003
+++ tmda-cvs-0.83/TMDA/FilterParser.py  Thu Aug 28 16:16:54 2003
@@ -251,7 +251,7 @@
     """, re.VERBOSE | re.IGNORECASE)
     
     out_action = re.compile(r"""
-    ( (?:(?:bare|sender|dated)(?:=\S+)?)
+    ( (?:(?:bare|sender|domain|dated)(?:=\S+)?)
     | (?:(?:exp(?:licit)?|as|ext(?:ension)?|kw|keyword)=\S+)
     | default )""", re.VERBOSE | re.IGNORECASE)
     
diff -ur tmda/bin/tmda-inject tmda-cvs-0.83/bin/tmda-inject
--- tmda/bin/tmda-inject        Fri Jul 11 19:02:59 2003
+++ tmda-cvs-0.83/bin/tmda-inject       Thu Aug 28 16:29:36 2003
@@ -186,6 +186,11 @@
        # Send a message with a tagged (sender) address
        sender_cookie_address = cookie_option or to_address
        field = Cookie.make_sender_address (from_address, sender_cookie_address)
+    elif cookie_type == 'domain':
+       # Send a message with a tagged (sender) address using only the
+       # domain portion of the address
+       domain_cookie_address = (cookie_option or to_address).split('@')[-1]
+       field = Cookie.make_sender_address (from_address, domain_cookie_address)
     elif cookie_type in ('as','exp','explicit') and cookie_option:
        # Send a message with an explicitly defined address.
        field = cookie_option

Reply via email to