changeset 3919:87c6a9ad850f

sendmail: added encodeSpamSafeEmail. This uses the same translation dict as decodeSpamSafeEmail
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 03 Aug 2008 21:36:17 +0200
parents b54044da7d09
children de8ffca86cc9
files MoinMoin/mail/sendmail.py
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/mail/sendmail.py	Sun Aug 03 21:33:58 2008 +0200
+++ b/MoinMoin/mail/sendmail.py	Sun Aug 03 21:36:17 2008 +0200
@@ -156,6 +156,26 @@
     logging.debug("Mail sent OK")
     return (1, _("Mail sent OK"))
 
+def encodeSpamSafeEmail(email_address, obfuscation_text=''):
+    """ Encodes a standard email address to an obfuscated address
+    @param email_address: mail address to encode.
+                          Known signs and their all-uppercase words translation:
+                          "." -> " DOT "
+                          "@" -> " AT "
+                          "-" -> " DASH "
+    @param obfuscation_text: optional text to obfuscate the email.
+                             All characters in the string must be alphabetic
+                             and they will be added in uppercase.
+    """
+    address = email_address.lower()
+    # uppercase letters will be stripped by decodeSpamSafeEmail
+    for word, sign in _transdict.items():
+        address = address.replace(sign, ' %s ' % word)
+    if obfuscation_text.isalpha():
+        # is the obfuscation_text alphabetic
+        address = address.replace(' AT ', ' AT %s ' % obfuscation_text.upper())
+
+    return address
 
 def decodeSpamSafeEmail(address):
     """ Decode obfuscated email address to standard email address