/
email-0mq.py
43 lines (35 loc) · 1.12 KB
/
email-0mq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
import base64
import email.utils
import re
import smtplib
import yaml
import zmq
from email.mime.text import MIMEText
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.setsockopt(zmq.SUBSCRIBE, '')
socket.connect('tcp://127.0.0.1:2428')
while True:
msg = socket.recv()
msg = re.sub('\n:', '\n', msg)
msg = re.sub('^---| !binary \|-\n','',msg)
y = yaml.load(msg)
f = open('/var/log/0mq.log','a')
f.write(msg)
f.close()
# Ignore client events that aren't PUBLIC
if not y['tags'][3]:
continue
nick = base64.b64decode(y['tags'][3])
nick = re.sub('^nick_','',nick)
message = base64.b64decode(y['message'])
# Change your email-to-sms address as provided by your mobile provider
fromaddr = 'weechat@irc.example.com'
toaddr = '1234567890@messaging.sprintpcs.com'
msg = MIMEText("<{0}> {1}".format(nick, message))
msg['To'] = email.utils.formataddr(('eightyeight', toaddr))
msg['From'] = email.utils.formataddr(('WeeChat', fromaddr))
s = smtplib.SMTP('localhost')
s.sendmail(fromaddr, [toaddr], msg.as_string())
s.quit()