Created
September 30, 2023 21:50
-
-
Save smortex/483e99e8f838a465f9dbfd82646bf094 to your computer and use it in GitHub Desktop.
syslog-ng python function to unwrap e-mail addresses rewritten with SRS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def unwrap(message, address): | |
address = address.decode("utf-8") | |
result = re.search(r"\ASRS0=[^=]+=[^=]+=(?P<domain_name>[^=]+)=(?P<local_part>[^@]+)@", address) | |
if result == None: | |
result = re.search(r"\ASRS1=[^=]+=[^=]+==[^=]+=[^=]+=(?P<domain_name>[^=]+)=(?P<local_part>[^@]+)@", address) | |
if result == None: | |
return address | |
return "{0}@{1}".format(result['local_part'], result['domain_name']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from sender_rewriting_scheme import unwrap | |
def test_srs_unwrap(): | |
assert unwrap(None, b'[email protected]') == '[email protected]' | |
assert unwrap(None, b'[email protected]') == '[email protected]' | |
assert unwrap(None, b'[email protected]') == '[email protected]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment