#!/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 ": 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") # Strip out quoted text if lines[-1][0] == ">": while lines[-1][0] == ">": lines.pop(-1) lines.pop(-1) text = ' '.join(lines).strip() channel.post(text)