added the beginnings of language support
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Wed, 22 Jul 2015 01:19:03 +0000 (21:19 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 18:28:39 +0000 (13:28 -0500)
edward

diff --git a/edward b/edward
index ca332ef597f05652d8a777b9427c774af78f565f..a5f71132c4f5e223a580013c14eb52ae49b4526a 100755 (executable)
--- a/edward
+++ b/edward
@@ -36,6 +36,7 @@ import gpgme
 import re
 import io
 import os
+import importlib
 
 import email.parser
 import email.message
@@ -47,6 +48,8 @@ from email.mime.nonmultipart    import MIMENonMultipart
 
 import edward_config
 
+langs = ["an", "de", "el", "en", "fr", "ja", "pt-br", "ro", "ru", "tr"]
+
 match_types =  [('clearsign',
                 '-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----'),
                 ('message',
@@ -95,10 +98,15 @@ def main ():
                               edward_config.sign_with_key)
 
     email_text = sys.stdin.read()
-    result = parse_pgp_mime(email_text, gpgme_ctx)
-    email_from, email_subject = email_from_subject(email_text)
+    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)
 
-    print(flatten_eddy(result))
+    reply_plaintext = build_reply(email_struct)
+
+    debug(lang.replies['success_decrypt'])
+    print(reply_plaintext)
 
 #    encrypt_to_key = choose_reply_encryption_key(gpgme_ctx, fingerprints)
 #
@@ -291,14 +299,14 @@ def gpg_on_payload_pieces (eddy_obj, gpgme_ctx):
             pass
 
 
-def flatten_eddy (eddy_obj):
+def build_reply (eddy_obj):
 
-    string = "\n".join(do_to_eddys_pieces(flatten_payload_pieces, eddy_obj, None))
+    string = "\n".join(do_to_eddys_pieces(build_reply_pieces, eddy_obj, None))
 
     return string
 
 
-def flatten_payload_pieces (eddy_obj, _ignore):
+def build_reply_pieces (eddy_obj, _ignore):
 
     string = ""
     for piece in eddy_obj.payload_pieces:
@@ -308,14 +316,14 @@ def flatten_payload_pieces (eddy_obj, _ignore):
             string += "Hmmm... I wasn't able to get that part.\n"
         elif piece.piece_type == "message":
             # recursive!
-            string += flatten_eddy(piece.gpg_data.plainobj)
+            string += build_reply(piece.gpg_data.plainobj)
         elif piece.piece_type == "pubkey":
             string += "thanks for your public key:"
             for key in piece.gpg_data.keys:
                 string += "\n" + key
         elif piece.piece_type == "clearsign":
             string += "*** Begin signed part ***\n"
-            string += flatten_eddy(piece.gpg_data.plainobj)
+            string += build_reply(piece.gpg_data.plainobj)
             string += "\n*** End signed part ***"
 
     return string
@@ -401,6 +409,18 @@ def email_to_from_subject (email_text):
     return email_to, email_from, email_subject
 
 
+def import_lang(email_to):
+
+    for lang in langs:
+        if "edward-" + lang in email_to:
+            lang = "lang." + re.sub('-', '_', lang)
+            language = importlib.import_module(lang)
+
+            return language
+
+    return importlib.import_module("lang.en")
+
+
 def generate_encrypted_mime (plaintext, email_from, email_subject, encrypt_to_key,
                     gpgme_ctx):