From bb27d25787a04c89c17971535cb3d1797af9e090 Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Tue, 28 Jul 2015 16:39:17 -0400 Subject: [PATCH] choose reply from address; fix language selection --- edward | 26 ++++++++++++++++++-------- edward_config.py | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/edward b/edward index b4bdaa8..26d87d1 100755 --- 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, diff --git a/edward_config.py b/edward_config.py index a1c1b47..f38f99f 100644 --- a/edward_config.py +++ b/edward_config.py @@ -28,5 +28,7 @@ Code sourced from these projects: gnupghome = "./tests/testgnupghome/" sign_with_key = "2470F96DB3CB20D2A39F89BA88611B2A4205FDDF" +hostname = "localhost" + debug = False -- 2.25.1