From acdfb6afa04828c1f53ba042097ee1e42f6f8b68 Mon Sep 17 00:00:00 2001 From: Jessica McKellar Date: Thu, 29 Aug 2013 13:25:06 -0400 Subject: [PATCH] email mirror: make being one of many recipients okay. Previously the email gateway had to be the only address in a recipient field or we'd mis-parse the recipient. This commit also makes the mirror correctly handle addresses of the form "Jessica McKellar ". (imported from commit 7435f2b59b8f47dc599cc869f64597a730af7d12) --- zerver/management/commands/email-mirror.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zerver/management/commands/email-mirror.py b/zerver/management/commands/email-mirror.py index ed874efb33..6033184077 100755 --- a/zerver/management/commands/email-mirror.py +++ b/zerver/management/commands/email-mirror.py @@ -18,6 +18,7 @@ Run this management command out of a cron job. import email from os import path from email.header import decode_header +from email.utils import getaddresses import logging import re import sys @@ -159,9 +160,11 @@ def delete(result, proto): def find_emailgateway_recipient(message): # We can't use Delivered-To; that is emailgateway@zulip.com. for header in ("To", "Cc", "Bcc"): - recipient = message.get(header) - if recipient and recipient.lower().endswith("@streams.zulip.com"): - return recipient + recipients = getaddresses(message.get_all(header, [])) + for recipient_name, recipient_email in recipients: + if recipient_email.lower().endswith("@streams.zulip.com"): + return recipient_email + raise ZulipEmailForwardError("Missing recipient @streams.zulip.com") def fetch(result, proto, mailboxes):