choose reply from address; fix language selection
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Tue, 28 Jul 2015 20:39:17 +0000 (16:39 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 18:28:41 +0000 (13:28 -0500)
edward
edward_config.py

diff --git a/edward b/edward
index b4bdaa87737b3cecb09510ef354460a2ceb3fa20..26d87d159084ecb510238b8ea0b5abbe6ae22877 100755 (executable)
--- a/edward
+++ b/edward
@@ -249,7 +249,7 @@ def main ():
     email_struct = parse_pgp_mime(email_text, gpgme_ctx)
 
     email_to, email_from, email_subject = email_to_from_subject(email_text)
-    lang = import_lang(email_to)
+    lang, email_reply_from = import_lang_pick_address(email_to, edward_config.hostname)
 
     replyinfo_obj = ReplyInfo()
     replyinfo_obj.replies = lang.replies
@@ -1082,31 +1082,41 @@ def email_to_from_subject (email_text):
     return email_to, email_from, email_subject
 
 
-def import_lang(email_to):
-    """Imports appropriate language file for basic i18n support
+def import_lang_pick_address(email_to, hostname):
+    """Imports language file for i18n support; makes reply from address
 
     The language imported depends on the To: address of the email received by
     edward. an -en ending implies the English language, whereas a -ja ending
     implies Japanese. The list of supported languages is listed in the 'langs'
-    list at the beginning of the program.
+    list at the beginning of the program. This function also chooses the
+    language-dependent address which can be used as the From address in the
+    reply email.
 
     Args:
         email_to: the string containing the email address that the mail was
-        sent to.
+            sent to.
+        hostname: the hostname part of the reply email's from address
 
     Returns:
         the reference to the imported language module. The only variable in
         this file is the 'replies' dictionary.
     """
 
-    lang_module = "lang.en"
+    # default
+    use_lang = "en"
 
     if email_to != None:
         for lang in langs:
             if "edward-" + lang in email_to:
-                lang_module = "lang." + re.sub('-', '_', lang)
+                use_lang = lang
+                break
 
-    return importlib.import_module(lang_module)
+    lang_mod_name = "lang." + re.sub('-', '_', use_lang)
+    lang_module = importlib.import_module(lang_mod_name)
+
+    email_reply_from = "edward-" + use_lang + "@" + hostname
+
+    return lang_module, email_reply_from
 
 
 def generate_encrypted_mime (plaintext, email_to, email_subject, encrypt_to_key,
index a1c1b47927643d485b303f0d389a3abf50137755..f38f99f157168d844cd28b33544381d5b1523b10 100644 (file)
@@ -28,5 +28,7 @@ Code sourced from these projects:
 gnupghome = "./tests/testgnupghome/"
 sign_with_key = "2470F96DB3CB20D2A39F89BA88611B2A4205FDDF"
 
+hostname = "localhost"
+
 debug = False