#!/usr/bin/env python # -*- coding: utf-8 -*- # vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai """ Copyright(C) 2010 Romain Bignon This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ from email.mime.text import MIMEText from smtplib import SMTP from email.Header import Header from email.Utils import parseaddr, formataddr import time import sys from html2text import html2text from weboob.capabilities.messages import ICapMessages from weboob.tools.application import BaseApplication class Monboob(BaseApplication): APPNAME = 'monboob' CONFIG = {'interval': 15, 'domain': 'weboob.example.org', 'recipient': 'weboob@example.org', 'smtp': 'localhost', 'html': False} def main(self, argv): self.load_config() if not self.config: print >>sys.stderr, "Error: %s is not configured yet. Please call 'monboob -c'" % argv[0] print >>sys.stderr, "Also, you need to use 'weboobcfg' to set backend configs" return -1 self.weboob.load_backends(ICapMessages, storage=self.create_storage()) self.weboob.repeat(self.config.get('interval'), self.process) self.weboob.loop() def process(self): for name, backend in self.weboob.iter_backends(): for message in backend.iter_new_messages(): self.send_email(backend, message) def send_email(self, backend, mail): domain = self.config.get('domain') recipient = self.config.get('recipient') reply_id = '' if mail.get_reply_id(): reply_id = u'<%s.%s@%s>' % (backend.name, mail.get_full_reply_id(), domain) subject = mail.get_title() sender = u'%s <%s@%s>' % (mail.get_from(), backend.name, domain) # assume that get_date() returns an UTC datetime date = time.strftime('%a, %d %b %Y %H:%M:%S +0000', mail.get_date().timetuple()) msg_id = u'<%s.%s@%s>' % (backend.name, mail.get_full_id(), domain) if self.config.get('html'): body = mail.get_content() content_type = 'html' else: body = html2text(mail.get_content()) content_type = 'plain' if mail.get_signature(): if self.config.get('html'): body += u'
--
%s