From 254de0224617037bd43999ca1cb04a6ab4d8ad15 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 23 Oct 2012 11:22:51 -0400 Subject: [PATCH] zephyr_mirror: Un-linewrap messages coming in from Zephyr Reinstated from 65d00bf911231cb15d3a6713e64ed8dff28a613a . The server's Markdown parser now treats newlines as line breaks, so we need this again. (imported from commit 242ed53b7f1308f21a6e6a194e24c176545a079b) --- zephyr_mirror.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zephyr_mirror.py b/zephyr_mirror.py index 0725149..e453e88 100755 --- a/zephyr_mirror.py +++ b/zephyr_mirror.py @@ -77,6 +77,11 @@ start_time = time.time() def humbug_username(zephyr_username): return zephyr_username.lower().split("@")[0] + "@mit.edu" +def unwrap_lines(body): + # Split into paragraphs at two consecutive newlines, or a newline followed + # by an indent. + return '\n\n'.join(p.replace('\n', ' ') for p in re.split(r'\n[ \t\n]', body)) + def send_humbug(zeph): if options.forward_class_messages: zeph["forged"] = "yes" @@ -100,6 +105,7 @@ def send_humbug(zeph): elif isinstance(zeph[key], str): zeph[key] = zeph[key].decode("utf-8") + zeph['content'] = unwrap_lines(zeph['content']) return humbug_client.send_message(zeph) def fetch_fullname(username):