Exemplo n.º 1
0
def sendmail(to, text):
    xtra = ''
    r = baseformat.splitter.match(text)

    if r:
        fromstr = 'sendirc@localhost'
        channel = r.group(2)
        time = baseformat.timeformat(r.group(3))
        user = r.group(4)
        rest = r.group(5)

        dt = datetime.datetime.fromtimestamp(int(r.group(3)[:-3]))
        xtra += 'Date: ' + dt.strftime('%a, %d %b %Y %H:%M:%S %z') + '\n'

        (leadstr, uperm, nick) = baseformat.nameformat_strip(user)
        xtra += 'X-BingFrom: ' + nick + '\n'

        if leadstr:
            userstr = leadstr + uperm + nick
        else:
            userstr = uperm + nick
            if not (nick.startswith('-') and nick.endswith('-')):
                userstr = '<' + userstr + '>'

        if channel:
            xtra += 'X-BingChan: ' + channel + '\n'

        subj = baseformat.combine_parts(channel, time, userstr, rest)
        body = userstr + ' ' + rest

    else:
        fromstr = 'noreply@localhost'
        subj = text
        body = text

    plainsubj = ''.join(map(lambda c: c[0], irccolor.colorize(subj)))
    plainbody = ''.join(map(lambda c: c[0], irccolor.colorize(body)))

    # TODO: use a Python library for sending
    ch = subprocess.Popen(['sendmail', to], stdin=subprocess.PIPE)

    full = ('To: ' + to + '\n' +
'From: ' + fromstr + '\n' +
'Subject: ' + plainsubj + '\n' +
xtra +
'\n' +
plainbody + '\n')

    ch.stdin.write(full)

    ch.stdin.close()
    ch.wait()
Exemplo n.º 2
0
#!/usr/bin/python

from __future__ import print_function

import sys
import time
import baseformat
import irccolor

notify_interval = 90

def blacklisted(channel, t, (l, p, nick), text):
    plain = ''.join(map(lambda c: c[0], irccolor.colorize(text))).strip()

    if plain == '':
        return channel + '.blank'

    return None

fonxes = {}

def register_fonx(bl):
    if bl not in fonxes:
        fonxes[bl] = 0
    fonxes[bl] += 1

def fonx_summary(fonxes):
    if not fonxes:
        return 'none fonxed'
    return ', '.join(map(lambda (x,y): x+' '+str(y), sorted(sorted(fonxes.items(), key=lambda x: x[0]), key=lambda x: x[1], reverse=True)))