slackmail: Support emailing channels and private groups

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-06-09 10:27:55 -04:00
parent ca89d98e3a
commit 19496e737c
1 changed files with 19 additions and 16 deletions

View File

@ -7,31 +7,34 @@ from email.mime.text import MIMEText
import textwrap
s = smtplib.SMTP("localhost")
repl = "--- Reply above this line ---".ljust(40)
smtp = smtplib.SMTP("localhost")
reply = "--- Reply above this line ---".ljust(40)
def mail_thread(thread):
if not thread.is_member():
return
if (thread.unread_count() == 0) or (thread.unread_count() == None):
return
for channel in slack.channels.list():
if not channel.is_member():
continue
if channel.unread_count() == 0 or channel.unread_count() == None:
continue
chan = ("channel=%s" % channel.id()).rjust(40)
text = [ "%s%s" % (repl, chan), ""]
text += [ str(channel) ] + [ "" ]
for message in channel.read():
header = ("thread=%s" % thread.id()).rjust(40)
header = "%s%s" % (reply, header)
text = [ header, "" ]
for message in thread.read():
text += [ str(message) ]
print("\n".join(text))
print()
msg = MIMEText("\n".join(text))
msg["Subject"] = "[%s] %s" % (slack.team(), channel.name())
msg["Subject"] = "[%s] %s" % (slack.team(), thread.name())
msg["From"] = "SlackMail@OcarinaProject.net"
msg["To"] = slack.user().email()
s.sendmail(slack.team(), slack.user().email(), msg.as_string())
smtp.sendmail(slack.team(), slack.user().email(), msg.as_string())
def mail_threads(thread_list):
for thread in thread_list:
mail_thread(thread)
s.quit()
mail_threads(slack.channels.list())
mail_threads(slack.groups.list())
smtp.quit()