zephyr_mirror: Use a function to compute Zephyr usernames.

(imported from commit 73c066944942169d5a37fada110ed95aa2c10c94)
This commit is contained in:
Tim Abbott 2012-11-02 15:46:50 -04:00
parent fb4e45e644
commit e0a71e7d6c

View file

@ -81,6 +81,9 @@ start_time = time.time()
def to_humbug_username(zephyr_username): def to_humbug_username(zephyr_username):
return zephyr_username.lower().split("@")[0] + "@mit.edu" 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): def unwrap_lines(body):
# Split into paragraphs at two consecutive newlines, or a newline followed # Split into paragraphs at two consecutive newlines, or a newline followed
# by an indent. # by an indent.
@ -355,9 +358,8 @@ def forward_to_zephyr(message):
wrapped_content = "\n".join("\n".join(textwrap.wrap(line)) wrapped_content = "\n".join("\n".join(textwrap.wrap(line))
for line in message["content"].split("\n")) 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" % \ print "%s: humbug=>zephyr: Forwarding message from %s" % \
(datetime.datetime.now(), sender_email) (datetime.datetime.now(), message["sender_email"])
if message['type'] == "stream": if message['type'] == "stream":
zephyr_class = message["display_recipient"] zephyr_class = message["display_recipient"]
instance = message["subject"] instance = message["subject"]
@ -373,12 +375,11 @@ def forward_to_zephyr(message):
zephyr_class = "message" zephyr_class = "message"
zwrite_args = ["zwrite", "-s", zsig, "-c", zephyr_class, "-i", instance] zwrite_args = ["zwrite", "-s", zsig, "-c", zephyr_class, "-i", instance]
elif message['type'] == "personal": elif message['type'] == "personal":
recipient = message["display_recipient"]["email"] recipient = to_zephyr_username(message["display_recipient"]["email"])
recipient = recipient.replace("@mit.edu", "@ATHENA.MIT.EDU")
zwrite_args = ["zwrite", "-s", zsig, recipient] zwrite_args = ["zwrite", "-s", zsig, recipient]
elif message['type'] == "huddle": elif message['type'] == "huddle":
zwrite_args = ["zwrite", "-s", zsig, "-C"] 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"]]) for user in message["display_recipient"]])
p = subprocess.Popen(zwrite_args, stdin=subprocess.PIPE, p = subprocess.Popen(zwrite_args, stdin=subprocess.PIPE,