2015-05-26 09:21:44 -04:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Copyright 2015 (c) Anna Schumaker.
|
2015-05-26 09:44:17 -04:00
|
|
|
|
2015-05-26 14:44:59 -04:00
|
|
|
import slack
|
2015-05-26 16:48:22 -04:00
|
|
|
import smtplib
|
|
|
|
from email.mime.text import MIMEText
|
2015-05-28 14:05:27 -04:00
|
|
|
import textwrap
|
2015-05-26 16:48:22 -04:00
|
|
|
|
|
|
|
|
2015-06-09 10:27:55 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
header = ("thread=%s" % thread.id()).rjust(40)
|
|
|
|
header = "%s%s" % (reply, header)
|
|
|
|
text = [ header, "" ]
|
|
|
|
for message in thread.read():
|
2015-05-26 16:42:12 -04:00
|
|
|
text += [ str(message) ]
|
2016-11-16 09:39:46 -05:00
|
|
|
text += [ "\n", thread.url(slack.url()) ]
|
2015-05-26 16:00:11 -04:00
|
|
|
|
2015-05-26 16:42:12 -04:00
|
|
|
print("\n".join(text))
|
|
|
|
print()
|
2015-05-26 16:48:22 -04:00
|
|
|
|
|
|
|
msg = MIMEText("\n".join(text))
|
2015-06-09 10:27:55 -04:00
|
|
|
msg["Subject"] = "[%s] %s" % (slack.team(), thread.name())
|
2015-05-26 17:00:20 -04:00
|
|
|
msg["From"] = "SlackMail@OcarinaProject.net"
|
2015-05-27 09:12:43 -04:00
|
|
|
msg["To"] = slack.user().email()
|
2015-06-09 10:27:55 -04:00
|
|
|
smtp.sendmail(slack.team(), slack.user().email(), msg.as_string())
|
2015-05-26 16:48:22 -04:00
|
|
|
|
2015-06-09 10:27:55 -04:00
|
|
|
def mail_threads(thread_list):
|
|
|
|
for thread in thread_list:
|
|
|
|
mail_thread(thread)
|
2015-05-26 16:48:22 -04:00
|
|
|
|
2015-06-09 10:27:55 -04:00
|
|
|
mail_threads(slack.channels.list())
|
|
|
|
mail_threads(slack.groups.list())
|
2016-11-16 15:52:42 -05:00
|
|
|
mail_threads(slack.im.list())
|
2015-06-09 10:27:55 -04:00
|
|
|
smtp.quit()
|