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()
def main(): global fonxes try: fonx = open('/tmp/fonx', 'a') line = sys.stdin.readline() nextnotify = time.time() + notify_interval while line: r = baseformat.splitter.match(line) if r: channel = r.group(2) t = r.group(3) name = baseformat.nameformat_strip(r.group(4)) text = r.group(5) bl = blacklisted(channel, t, name, text) if bl == None: print(line, end='') sys.stdout.flush() else: register_fonx(bl) print(line, end='', file=fonx) fonx.flush() else: print(line, end='') sys.stdout.flush() if time.time() > nextnotify: if fonxes: print('fonx\t' + str(int(round(time.time() * 1000))) + '\tfonxed\t' + fonx_summary(fonxes)) nextnotify = time.time() + notify_interval fonxes = {} line = sys.stdin.readline() except KeyboardInterrupt: pass