From 01acc2c7d40532f376be6dd58ee89e056766b671 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Thu, 11 Nov 2010 13:08:05 +0100 Subject: [PATCH] new command 'weboob-config confirm' --- weboob/applications/weboobcfg/weboobcfg.py | 31 ++++++++++++++++++++++ weboob/backends/aum/backend.py | 27 ++++++++++++++++++- weboob/capabilities/account.py | 6 +++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/weboob/applications/weboobcfg/weboobcfg.py b/weboob/applications/weboobcfg/weboobcfg.py index 67899548..183b9b4a 100644 --- a/weboob/applications/weboobcfg/weboobcfg.py +++ b/weboob/applications/weboobcfg/weboobcfg.py @@ -17,9 +17,11 @@ import os +import sys import subprocess import re +from weboob.capabilities.account import ICapAccount from weboob.tools.application.repl import ReplApplication from weboob.tools.ordereddict import OrderedDict @@ -70,6 +72,35 @@ class WeboobCfg(ReplApplication): """ self.register_backend(line) + def do_confirm(self, backend_name): + """ + confirm BACKEND + + For a backend which support CapAccount, parse a confirmation mail + after using the 'register' command to automatically confirm the + subscribe. + + It take mail from stdin. Use it with postfix for example. + """ + # Do not use the ReplApplication.load_backends() method because we + # don't want to prompt user to create backend. + self.weboob.load_backends(names=[backend_name]) + try: + backend = self.weboob.get_backend(backend_name) + except KeyError: + print >>sys.stderr, 'Error: backend "%s" not found.' % backend_name + return 1 + + if not backend.has_caps(ICapAccount): + print >>sys.stderr, 'Error: backend "%s" does not support accounts management' % backend_name + return 1 + + mail = sys.stdin.read() + if not backend.confirm_account(mail): + print >>sys.stderr, 'Error: Unable to confirm account creation' + return 1 + return 0 + def do_list(self, line): """ list diff --git a/weboob/backends/aum/backend.py b/weboob/backends/aum/backend.py index 4be55d50..964c5d44 100644 --- a/weboob/backends/aum/backend.py +++ b/weboob/backends/aum/backend.py @@ -17,6 +17,8 @@ from __future__ import with_statement +import email +import re import datetime from dateutil import tz @@ -409,9 +411,32 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapDating, ICapCh country= account.properties['country'].value, godfather= account.properties['godfather'].value) except CaptchaError: - getLogger('aum').debug('Unable to resolve captcha. Retrying...') + getLogger('aum').info('Unable to resolve captcha. Retrying...') browser = None + REGISTER_REGEXP = re.compile('.*http://www.adopteunmec.com/register4.php\?([^\' ]*)\'') + def confirm_account(self, mail): + msg = email.message_from_string(mail) + + content = u'' + for part in msg.walk(): + s = part.get_payload(decode=True) + content += unicode(s, 'iso-8859-15') + + url = None + for s in content.split(): + m = self.REGISTER_REGEXP.match(s) + if m: + url = '/register4.php?' + m.group(1) + break + + if url: + browser = self.BROWSER('') + browser.openurl(url) + return True + + return False + def get_account(self): """ Get the current account. diff --git a/weboob/capabilities/account.py b/weboob/capabilities/account.py index 94b84b82..0cbb4d4d 100644 --- a/weboob/capabilities/account.py +++ b/weboob/capabilities/account.py @@ -47,6 +47,12 @@ class ICapAccount(IBaseCap): """ raise NotImplementedError() + def confirm_account(self, mail): + """ + From an email go to the confirm link. + """ + raise NotImplementedError() + def get_account(self): """ Get the current account.