38 lines
755 B
Python
Executable File
38 lines
755 B
Python
Executable File
#!/usr/bin/python
|
|
# Copyright 2015 (c) Anna Schumaker.
|
|
#
|
|
|
|
import slack
|
|
import sys
|
|
from email.parser import Parser
|
|
|
|
headers = Parser().parsestr(sys.stdin.read())
|
|
|
|
if headers['from'] != "Anna Schumaker <schumaker.anna@gmail.com>":
|
|
sys.exit(1)
|
|
|
|
|
|
# Determine which channel to post to
|
|
channel = None
|
|
subject = headers['subject']
|
|
ch_name = subject.split("[%s]" % slack.team())[-1].strip()
|
|
|
|
for c in slack.channels.list():
|
|
if c.name() == ch_name:
|
|
channel = c
|
|
break
|
|
|
|
if channel == None:
|
|
sys.exit(1)
|
|
|
|
lines = headers.get_payload().strip().split("\n")
|
|
for i in range(len(lines)):
|
|
if len(lines[i]) == 0:
|
|
continue
|
|
if lines[i][0] == ">":
|
|
break
|
|
|
|
lines = lines[0:i-1]
|
|
text = ' '.join(lines).strip()
|
|
channel.post(text)
|