works correctly
This commit is contained in:
parent
8c4340bed3
commit
454cf3497a
1 changed files with 20 additions and 14 deletions
34
weboob2mail
34
weboob2mail
|
|
@ -28,7 +28,7 @@ import time
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from weboob import Weboob
|
from weboob import Weboob
|
||||||
from weboob.capabilities import CAP_MAILS
|
from weboob.capabilities.messages import ICapMessages
|
||||||
from weboob.tools.application import BaseApplication
|
from weboob.tools.application import BaseApplication
|
||||||
|
|
||||||
class User:
|
class User:
|
||||||
|
|
@ -39,42 +39,48 @@ class User:
|
||||||
|
|
||||||
class Application(BaseApplication):
|
class Application(BaseApplication):
|
||||||
APPNAME = 'weboob2mail'
|
APPNAME = 'weboob2mail'
|
||||||
|
CONFIG = {'interval': 15,
|
||||||
|
'domain': 'weboob.example.org',
|
||||||
|
'recipient': 'weboob@example.org',
|
||||||
|
'smtp': 'localhost'}
|
||||||
|
|
||||||
def main(self, argv):
|
def main(self, argv):
|
||||||
if not self.config.values:
|
if not self.config:
|
||||||
print >>sys.stderr, "Error: %s is not configured yet. Please call 'weboob2mail -c'" % argv[0]
|
print >>sys.stderr, "Error: %s is not configured yet. Please call 'weboob2mail -c'" % argv[0]
|
||||||
print >>sys.stderr, "Also, you need to use 'weboobcfg' to set backend configs"
|
print >>sys.stderr, "Also, you need to use 'weboobcfg' to set backend configs"
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
self.weboob.loadmodules(CAP_MAILS)
|
self.weboob.loadmodules(ICapMessages)
|
||||||
|
|
||||||
self.weboob.schedule(interval, self.process)
|
self.weboob.schedule(self.config['interval'], self.process)
|
||||||
|
self.weboob.config.save()
|
||||||
self.weboob.loop()
|
self.weboob.loop()
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
backends = self.weboob.getBackends()
|
backends = self.weboob.getBackends()
|
||||||
for b in backends:
|
for name, b in backends.iteritems():
|
||||||
messages = b.getNewMessages()
|
messages = b.getNewMessages()
|
||||||
for m in messages:
|
for m in messages:
|
||||||
self.send_email(m)
|
self.send_email(name, m)
|
||||||
|
|
||||||
def send_email(self, mail):
|
def send_email(self, backend_name, mail):
|
||||||
domain = self.config.items['domain']
|
domain = self.config['domain']
|
||||||
recipient = self.config.items['recipient']
|
recipient = self.config['recipient']
|
||||||
|
|
||||||
reply_id = ''
|
reply_id = ''
|
||||||
if mail.getReplyID():
|
if mail.getReplyID():
|
||||||
reply_id = u'%s@%s' % (mail.getFullReplyID(), domain)
|
reply_id = u'%s.%s@%s' % (backend_name, mail.getFullReplyID(), domain)
|
||||||
subject = u'%s%s' % ((reply_id) and 'Re: ' or '', mail.getTitle())
|
subject = u'%s%s' % ((reply_id) and 'Re: ' or '', mail.getTitle())
|
||||||
sender = u'%s <%d@%s>' % (mail.getFrom(), mail.getThreadID(), domain)
|
sender = u'%s <%s.%s.%s@%s>' % (mail.getFrom(), backend_name, mail.getThreadID(), mail.getID(), domain)
|
||||||
|
|
||||||
# assume that getDate() returns an UTC datetime
|
# assume that getDate() returns an UTC datetime
|
||||||
date = time.strftime('%a, %d %b %Y %H:%M:%S +0000', mail.getDate().timetuple())
|
date = time.strftime('%a, %d %b %Y %H:%M:%S +0000', mail.getDate().timetuple())
|
||||||
msg_id = u'%s@%s' % (mail.getFullID(), domain)
|
msg_id = u'%s.%s@%s' % (backend_name, mail.getFullID(), domain)
|
||||||
body = mail.getContent()
|
body = mail.getContent()
|
||||||
|
|
||||||
body += u'\n\n-- \n'
|
if mail.getSignature():
|
||||||
body += mail.getSignature()
|
body += u'\n\n-- \n'
|
||||||
|
body += mail.getSignature()
|
||||||
|
|
||||||
# Header class is smart enough to try US-ASCII, then the charset we
|
# Header class is smart enough to try US-ASCII, then the charset we
|
||||||
# provide, then fall back to UTF-8.
|
# provide, then fall back to UTF-8.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue