zephyr_mirror: Clean up send_humbug() interface.
(imported from commit 76d53e83eacedead2dabbf921e240afc4e4d09db)
This commit is contained in:
parent
f077cb81f0
commit
942a9fd661
|
@ -90,24 +90,31 @@ def unwrap_lines(body):
|
||||||
return '\n\n'.join(p.replace('\n', ' ') for p in re.split(r'\n[ \t\n]', body))
|
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):
|
||||||
|
message = {}
|
||||||
if options.forward_class_messages:
|
if options.forward_class_messages:
|
||||||
zeph["forged"] = "yes"
|
message["forged"] = "yes"
|
||||||
zeph["sender"] = to_humbug_username(zeph["sender"])
|
message['type'] = zeph['type']
|
||||||
zeph['fullname'] = username_to_fullname(zeph['sender'])
|
message['time'] = zeph['time']
|
||||||
zeph['shortname'] = zeph['sender'].split('@')[0]
|
message['sender'] = to_humbug_username(zeph['sender'])
|
||||||
|
message['fullname'] = username_to_fullname(zeph['sender'])
|
||||||
|
message['shortname'] = zeph['sender'].split('@')[0]
|
||||||
if "subject" in zeph:
|
if "subject" in zeph:
|
||||||
zeph["subject"] = zeph["subject"][:60]
|
message["subject"] = zeph["subject"][:60]
|
||||||
if zeph['type'] == 'stream':
|
if zeph['type'] == 'stream':
|
||||||
# Forward messages sent to -c foo -i bar to stream bar subject "instance"
|
# Forward messages sent to -c foo -i bar to stream bar subject "instance"
|
||||||
if zeph["stream"] == "message":
|
if zeph["stream"] == "message":
|
||||||
zeph['stream'] = zeph['subject']
|
message['stream'] = zeph['subject']
|
||||||
zeph['subject'] = "instance %s" % (zeph['stream'])
|
message['subject'] = "instance %s" % (zeph['stream'])
|
||||||
elif zeph["stream"] == "tabbott-test5":
|
elif zeph["stream"] == "tabbott-test5":
|
||||||
zeph['stream'] = zeph['subject']
|
message['stream'] = zeph['subject']
|
||||||
zeph['subject'] = "test instance %s" % (zeph['stream'])
|
message['subject'] = "test instance %s" % (zeph['stream'])
|
||||||
|
else:
|
||||||
|
message["stream"] = zeph["stream"]
|
||||||
|
else:
|
||||||
|
message["recipient"] = zeph["recipient"]
|
||||||
|
message['content'] = unwrap_lines(zeph['content'])
|
||||||
|
|
||||||
zeph['content'] = unwrap_lines(zeph['content'])
|
return humbug_client.send_message(message)
|
||||||
return humbug_client.send_message(zeph)
|
|
||||||
|
|
||||||
def fetch_fullname(username):
|
def fetch_fullname(username):
|
||||||
try:
|
try:
|
||||||
|
@ -227,7 +234,6 @@ def process_notice(notice, log):
|
||||||
(datetime.datetime.now())
|
(datetime.datetime.now())
|
||||||
return
|
return
|
||||||
|
|
||||||
sender = notice.sender.lower().replace("athena.mit.edu", "mit.edu")
|
|
||||||
zephyr_class = notice.cls.lower()
|
zephyr_class = notice.cls.lower()
|
||||||
instance = notice.instance.lower()
|
instance = notice.instance.lower()
|
||||||
|
|
||||||
|
@ -238,8 +244,8 @@ def process_notice(notice, log):
|
||||||
# Map "CC: sipbtest espuser" => "starnine@mit.edu,espuser@mit.edu"
|
# Map "CC: sipbtest espuser" => "starnine@mit.edu,espuser@mit.edu"
|
||||||
huddle_recipients_list = [to_humbug_username(x.strip()) for x in
|
huddle_recipients_list = [to_humbug_username(x.strip()) for x in
|
||||||
body.split("\n")[0][4:].split()]
|
body.split("\n")[0][4:].split()]
|
||||||
if sender not in huddle_recipients_list:
|
if notice.sender not in huddle_recipients_list:
|
||||||
huddle_recipients_list.append(sender)
|
huddle_recipients_list.append(to_humbug_username(notice.sender))
|
||||||
huddle_recipients = ",".join(huddle_recipients_list)
|
huddle_recipients = ",".join(huddle_recipients_list)
|
||||||
if (zephyr_class == "mail" and instance == "inbox"):
|
if (zephyr_class == "mail" and instance == "inbox"):
|
||||||
is_personal = True
|
is_personal = True
|
||||||
|
@ -254,21 +260,21 @@ def process_notice(notice, log):
|
||||||
if is_huddle:
|
if is_huddle:
|
||||||
zeph = { 'type' : 'personal',
|
zeph = { 'type' : 'personal',
|
||||||
'time' : str(notice.time),
|
'time' : str(notice.time),
|
||||||
'sender' : sender,
|
'sender' : notice.sender,
|
||||||
'recipient' : huddle_recipients,
|
'recipient' : huddle_recipients,
|
||||||
'zsig' : zsig, # logged here but not used by app
|
'zsig' : zsig, # logged here but not used by app
|
||||||
'content' : body.split("\n", 1)[1] }
|
'content' : body.split("\n", 1)[1] }
|
||||||
elif is_personal:
|
elif is_personal:
|
||||||
zeph = { 'type' : 'personal',
|
zeph = { 'type' : 'personal',
|
||||||
'time' : str(notice.time),
|
'time' : str(notice.time),
|
||||||
'sender' : sender,
|
'sender' : notice.sender,
|
||||||
'recipient' : to_humbug_username(notice.recipient),
|
'recipient' : to_humbug_username(notice.recipient),
|
||||||
'zsig' : zsig, # logged here but not used by app
|
'zsig' : zsig, # logged here but not used by app
|
||||||
'content' : body }
|
'content' : body }
|
||||||
else:
|
else:
|
||||||
zeph = { 'type' : 'stream',
|
zeph = { 'type' : 'stream',
|
||||||
'time' : str(notice.time),
|
'time' : str(notice.time),
|
||||||
'sender' : sender,
|
'sender' : notice.sender,
|
||||||
'stream' : zephyr_class,
|
'stream' : zephyr_class,
|
||||||
'subject' : instance,
|
'subject' : instance,
|
||||||
'zsig' : zsig, # logged here but not used by app
|
'zsig' : zsig, # logged here but not used by app
|
||||||
|
|
Loading…
Reference in a new issue