42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
#!/usr/bin/python
|
|
# Copyright 2015 (c) Anna Schumaker.
|
|
|
|
import slack
|
|
import smtplib
|
|
from email.mime.text import MIMEText
|
|
import textwrap
|
|
|
|
|
|
smtp = smtplib.SMTP("localhost")
|
|
reply = "--- Reply above this line ---"
|
|
|
|
def mail_thread(thread):
|
|
if not thread.is_member():
|
|
return
|
|
if (thread.unread_count() == 0) or (thread.unread_count() == None):
|
|
return
|
|
|
|
header = "%s thread=%s" % (reply, thread.id())
|
|
text = [ header, "" ]
|
|
for message in thread.read():
|
|
text += [ str(message) ]
|
|
text += [ thread.url(slack.url()) ]
|
|
|
|
print("\n".join(text))
|
|
print()
|
|
|
|
msg = MIMEText("\n".join(text))
|
|
msg["Subject"] = "[%s] %s" % (slack.team(), thread.name())
|
|
msg["From"] = "SlackMail@OcarinaProject.net"
|
|
msg["To"] = slack.user().email()
|
|
smtp.sendmail(slack.team(), slack.user().email(), msg.as_string())
|
|
|
|
def mail_threads(thread_list):
|
|
for thread in thread_list:
|
|
mail_thread(thread)
|
|
|
|
mail_threads(slack.channels.list())
|
|
mail_threads(slack.groups.list())
|
|
mail_threads(slack.im.list())
|
|
smtp.quit()
|