slackmail/slackpost.py
Anna Schumaker 6110e5ff3b slackpost.py: Write a script for posting to slack
The idea is that postfix will pipe an email message into this script,
which will then post the reply to slack.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
2015-05-26 21:21:46 -04:00

30 lines
583 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)
text = headers.get_payload().split("\n")[0]
channel.post(text)