From 87f06fd837dedecf119867b414332006e312f56b Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 10 May 2017 11:43:16 -0700 Subject: [PATCH] zephyr_mirror: Add support for discuss-format messages. --- bots/zephyr_mirror_backend.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bots/zephyr_mirror_backend.py b/bots/zephyr_mirror_backend.py index 248f401f24..31987f6d99 100755 --- a/bots/zephyr_mirror_backend.py +++ b/bots/zephyr_mirror_backend.py @@ -294,10 +294,17 @@ def process_loop(log): except Exception: logger.exception("Error updating subscriptions from Zulip:") -def parse_zephyr_body(zephyr_data): - # type: (str) -> Tuple[str, str] +def parse_zephyr_body(zephyr_data, notice_format): + # type: (str, str) -> Tuple[str, str] try: (zsig, body) = zephyr_data.split("\x00", 1) + if (notice_format == 'New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4' or + notice_format == 'New transaction [$1] entered in $2\nFrom: $3\nSubject: $4'): + # Logic based off of owl_zephyr_get_message in barnowl + fields = body.split('\x00') + if len(fields) == 5: + body = 'New transaction [%s] entered in %s\nFrom: %s (%s)\nSubject: %s' % ( + fields[0], fields[1], fields[2], fields[4], fields[3]) except ValueError: (zsig, body) = ("", zephyr_data) return (zsig, body) @@ -357,7 +364,7 @@ def decrypt_zephyr(zephyr_class, instance, body): def process_notice(notice, log): # type: (zulip, IO) -> None - (zsig, body) = parse_zephyr_body(notice.message) + (zsig, body) = parse_zephyr_body(notice.message, notice.format) is_personal = False is_huddle = False