From: Andrew Engelbrecht Date: Wed, 22 Jul 2015 01:19:03 +0000 (-0400) Subject: added the beginnings of language support X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=adcef2f74c37cdf9f359602b96407ee7220e3b15;p=edward.git added the beginnings of language support --- diff --git a/edward b/edward index ca332ef..a5f7113 100755 --- 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):