Handle unicode characters in email mirror.

Fixes #2328.
This commit is contained in:
Umair Khan 2017-04-05 14:46:14 +05:00 committed by Tim Abbott
parent a9cb193b51
commit be65125d3d
2 changed files with 33 additions and 1 deletions

View File

@ -33,6 +33,35 @@ class WorkerTest(TestCase):
callback = self.consumers[queue_name]
callback(data)
def test_mirror_worker(self):
# type: () -> None
fake_client = self.FakeClient()
data = [
dict(
message=u'\xf3test',
time=time.time(),
rcpt_to='hamlet@zulip.com',
),
dict(
message='\xf3test',
time=time.time(),
rcpt_to='hamlet@zulip.com',
),
dict(
message='test',
time=time.time(),
rcpt_to='hamlet@zulip.com',
),
]
for element in data:
fake_client.queue.append(('email_mirror', element))
with patch('zerver.worker.queue_processors.mirror_email'):
with simulated_queue_client(lambda: fake_client):
worker = queue_processors.MirrorWorker()
worker.setup()
worker.start()
def test_UserActivityWorker(self):
# type: () -> None
fake_client = self.FakeClient()

View File

@ -29,10 +29,12 @@ from zerver.tornado.socket import req_redis_key
from confirmation.models import Confirmation
from zerver.lib.db import reset_queries
from zerver.lib.redis_utils import get_redis_client
from zerver.lib.str_utils import force_str
from zerver.context_processors import common_context
import os
import sys
import six
import ujson
from collections import defaultdict
import email
@ -373,7 +375,8 @@ class MirrorWorker(QueueProcessingWorker):
# management command, not here.
def consume(self, event):
# type: (Mapping[str, Any]) -> None
mirror_email(email.message_from_string(event["message"]),
message = force_str(event["message"])
mirror_email(email.message_from_string(message),
rcpt_to=event["rcpt_to"], pre_checked=True)
@assign_queue('test', queue_type="test")