From e0a71e7d6cc2e699a4686f0e8b0379dc06d3d26c Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 2 Nov 2012 15:46:50 -0400 Subject: [PATCH] zephyr_mirror: Use a function to compute Zephyr usernames. (imported from commit 73c066944942169d5a37fada110ed95aa2c10c94) --- bots/zephyr_mirror.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bots/zephyr_mirror.py b/bots/zephyr_mirror.py index e448c25..7b953fc 100755 --- a/bots/zephyr_mirror.py +++ b/bots/zephyr_mirror.py @@ -81,6 +81,9 @@ start_time = time.time() def to_humbug_username(zephyr_username): return zephyr_username.lower().split("@")[0] + "@mit.edu" +def to_zephyr_username(humbug_username): + return humbug_username.lower().split("@")[0] + "@ATHENA.MIT.EDU" + def unwrap_lines(body): # Split into paragraphs at two consecutive newlines, or a newline followed # by an indent. @@ -355,9 +358,8 @@ def forward_to_zephyr(message): wrapped_content = "\n".join("\n".join(textwrap.wrap(line)) for line in message["content"].split("\n")) - sender_email = message["sender_email"].replace("mit.edu", "ATHENA.MIT.EDU") print "%s: humbug=>zephyr: Forwarding message from %s" % \ - (datetime.datetime.now(), sender_email) + (datetime.datetime.now(), message["sender_email"]) if message['type'] == "stream": zephyr_class = message["display_recipient"] instance = message["subject"] @@ -373,12 +375,11 @@ def forward_to_zephyr(message): zephyr_class = "message" zwrite_args = ["zwrite", "-s", zsig, "-c", zephyr_class, "-i", instance] elif message['type'] == "personal": - recipient = message["display_recipient"]["email"] - recipient = recipient.replace("@mit.edu", "@ATHENA.MIT.EDU") + recipient = to_zephyr_username(message["display_recipient"]["email"]) zwrite_args = ["zwrite", "-s", zsig, recipient] elif message['type'] == "huddle": zwrite_args = ["zwrite", "-s", zsig, "-C"] - zwrite_args.extend([user["email"].replace("@mit.edu", "") + zwrite_args.extend([to_zephyr_username(user["email"]).replace("@ATHENA.MIT.EDU", "") for user in message["display_recipient"]]) p = subprocess.Popen(zwrite_args, stdin=subprocess.PIPE,