Skip to content

Instantly share code, notes, and snippets.

@smortex
Created September 30, 2023 21:50
Show Gist options
  • Save smortex/483e99e8f838a465f9dbfd82646bf094 to your computer and use it in GitHub Desktop.
Save smortex/483e99e8f838a465f9dbfd82646bf094 to your computer and use it in GitHub Desktop.
syslog-ng python function to unwrap e-mail addresses rewritten with SRS
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'])
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