#! /usr/bin/python """Email proxy for Avaya's Voicemail Pro (which embeds G-Lock's EasyMail Pro). Voicemail Pro has the capability to send email alerts when a voicemail message is left in a given voicemail box. We use this capability at Amor Ministries, for example, to run an "emergency extension"--if one of our customers has an emergency after hours, they can leave a voicemail message in this box, and various people will be paged to address the issue. Unfortunately, the emails that Voicemail Pro sends out don't follow RFC 821, which requires "MAIL FROM" before "DATA". This causes Exim, which requires spec compliance, to choke. This module runs as an SMTP proxy, fixing up the email from Voicemail Pro and forwarding it on to a designated recipient. It only runs on localhost for security reasons. """ import asyncore import datetime import smtpd def log(msg): msg = "%s %s\n" % (datetime.datetime.now(), msg) open(r"/var/log/vmprofixup.log", "ab").write(msg) class VoicemailProProxy(smtpd.PureProxy): def process_message(self, peer, mailfrom, rcpttos, data): # Fixup the mailfrom; # Exim requires that it contain a domain, but it's coming through as "Voicemail2". refused = self._deliver("vemergency@amor.org", rcpttos, data) log("Delivery results: %s" % repr(refused)) p = VoicemailProProxy(("192.168.0.6", 2525), ("localhost", 25)) try: log("starting") asyncore.loop() except: p.close() log("stopped")