~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to files/mailudp.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
#
3
 
#
4
 
# copy this to your home dir and make a .forward file like this:
5
 
# (bart@r8):~
6
 
# $ cat .forward
7
 
# \bart
8
 
# "|~/mailudp.py"
9
 
#
10
 
# edit config vars below to match your bot's config
11
 
 
12
 
__copyright__ = 'this file is in the public domain'
13
 
 
14
 
import socket, sys, re
15
 
 
16
 
# config
17
 
host = 'gozerbot.org'
18
 
port = 5600
19
 
passwd = 'mekker'
20
 
printto = 'dunk_'
21
 
# end config
22
 
 
23
 
def out(what):
24
 
    z = '%s %s %s' % (passwd, printto, what)
25
 
    z = z[:400]
26
 
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
27
 
    sock.sendto(z, (host, port))
28
 
 
29
 
fromre = re.compile('^From: (.*)\n', re.M)
30
 
subjectre = re.compile('^Subject: (.*)\n', re.M)
31
 
 
32
 
frm = ""
33
 
subject = ""
34
 
 
35
 
a = sys.stdin.readlines()
36
 
 
37
 
for i in a:
38
 
    try:
39
 
        b = fromre.search(i)
40
 
        if b:
41
 
            frm = b.group(0).strip()
42
 
        c = subjectre.search(i)
43
 
        if c:
44
 
            subject = c.group(0).strip()
45
 
        if frm and subject:
46
 
            break
47
 
    except Exception:
48
 
        pass
49
 
 
50
 
if frm and subject:
51
 
    result = "%s %s" % (frm, subject)
52
 
    out(result)