slackmail: Support emailing channels and private groups
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
ca89d98e3a
commit
19496e737c
35
slackmail.py
35
slackmail.py
|
@ -7,31 +7,34 @@ from email.mime.text import MIMEText
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
|
||||||
s = smtplib.SMTP("localhost")
|
smtp = smtplib.SMTP("localhost")
|
||||||
repl = "--- Reply above this line ---".ljust(40)
|
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)
|
||||||
for channel in slack.channels.list():
|
header = "%s%s" % (reply, header)
|
||||||
if not channel.is_member():
|
text = [ header, "" ]
|
||||||
continue
|
for message in thread.read():
|
||||||
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():
|
|
||||||
text += [ str(message) ]
|
text += [ str(message) ]
|
||||||
|
|
||||||
print("\n".join(text))
|
print("\n".join(text))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
msg = MIMEText("\n".join(text))
|
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["From"] = "SlackMail@OcarinaProject.net"
|
||||||
msg["To"] = slack.user().email()
|
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()
|
||||||
|
|
Loading…
Reference in New Issue