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)
This commit is contained in:
Keegan McAllister 2012-10-23 11:22:51 -04:00
parent 47e9117a66
commit 254de02246

View file

@ -77,6 +77,11 @@ start_time = time.time()
def humbug_username(zephyr_username): def humbug_username(zephyr_username):
return zephyr_username.lower().split("@")[0] + "@mit.edu" 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): def send_humbug(zeph):
if options.forward_class_messages: if options.forward_class_messages:
zeph["forged"] = "yes" zeph["forged"] = "yes"
@ -100,6 +105,7 @@ def send_humbug(zeph):
elif isinstance(zeph[key], str): elif isinstance(zeph[key], str):
zeph[key] = zeph[key].decode("utf-8") zeph[key] = zeph[key].decode("utf-8")
zeph['content'] = unwrap_lines(zeph['content'])
return humbug_client.send_message(zeph) return humbug_client.send_message(zeph)
def fetch_fullname(username): def fetch_fullname(username):