email_mirror: Convert subjects back to str from Redis's bytes.

Redis and the Redis client know nothing but bytes.  When we take a
`bytes` object it returns and pass it down as `subject` here, it
causes an exception deep inside message processing if the realm has
any filters, when `bugdown.subject_links` attempts to search the
subject for the filters, which are of course `str` patterns.

For symmetry, make the conversion to bytes on the storing side
explicit too.
This commit is contained in:
Greg Price
2017-08-25 15:16:15 -07:00
committed by Tim Abbott
parent 20c0d27317
commit dfbd80f302

View File

@@ -117,7 +117,7 @@ def create_missed_message_address(user_profile, message):
data = { data = {
'user_profile_id': user_profile.id, 'user_profile_id': user_profile.id,
'recipient_id': recipient_id, 'recipient_id': recipient_id,
'subject': message.subject, 'subject': message.subject.encode('utf-8'),
} }
while True: while True:
@@ -155,7 +155,7 @@ def send_to_missed_message_address(address, message):
result = redis_client.hmget(key, 'user_profile_id', 'recipient_id', 'subject') result = redis_client.hmget(key, 'user_profile_id', 'recipient_id', 'subject')
if not all(val is not None for val in result): if not all(val is not None for val in result):
raise ZulipEmailForwardError('Missing missed message address data') raise ZulipEmailForwardError('Missing missed message address data')
user_profile_id, recipient_id, subject = result user_profile_id, recipient_id, subject_b = result # type: (bytes, bytes, bytes)
user_profile = get_user_profile_by_id(user_profile_id) user_profile = get_user_profile_by_id(user_profile_id)
recipient = Recipient.objects.get(id=recipient_id) recipient = Recipient.objects.get(id=recipient_id)
@@ -179,7 +179,8 @@ def send_to_missed_message_address(address, message):
recipient_type_name = 'private' recipient_type_name = 'private'
internal_send_message(user_profile.realm, user_profile.email, internal_send_message(user_profile.realm, user_profile.email,
recipient_type_name, recipient_str, subject, body) recipient_type_name, recipient_str,
subject_b.decode('utf-8'), body)
logging.info("Successfully processed email from %s to %s" % ( logging.info("Successfully processed email from %s to %s" % (
user_profile.email, recipient_str)) user_profile.email, recipient_str))