From e653aa169e9c1fbb00e1920cd461a7be6c9e11af Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Fri, 24 Jun 2016 18:50:01 +0200 Subject: [feat] use one single mail_auth token instead of imap/smtp tokens The core was not addapted to the mail_auth token. --- src/leap/bitmask/cli/bitmask_cli.py | 13 ++++--------- src/leap/bitmask/core/dispatcher.py | 15 +++++---------- src/leap/bitmask/core/mail_services.py | 33 ++++++++------------------------- 3 files changed, 17 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py index 5be6e9fc..49c5c3d3 100755 --- a/src/leap/bitmask/cli/bitmask_cli.py +++ b/src/leap/bitmask/cli/bitmask_cli.py @@ -107,10 +107,8 @@ GENERAL COMMANDS: help='displays status about the mail service') parser.add_argument('--enable', action='store_true') parser.add_argument('--disable', action='store_true') - parser.add_argument('--get-imap-token', action='store_true', - help='returns token for the IMAP service') - parser.add_argument('--get-smtp-token', action='store_true', - help='returns token for the SMTP service') + parser.add_argument('--get-token', action='store_true', + help='returns token for the mail service') parser.add_argument('--get-smtp-certificate', action='store_true', help='downloads a new smtp certificate') parser.add_argument('--check-smtp-certificate', action='store_true', @@ -276,11 +274,8 @@ def send_command(cli): elif subargs.disable: data += ['disable'] - elif subargs.get_imap_token: - data += ['get_imap_token'] - - elif subargs.get_smtp_token: - data += ['get_smtp_token'] + elif subargs.get_token: + data += ['get_token'] elif subargs.get_smtp_certificate: data += ['get_smtp_certificate'] diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py index c07f5b95..ec3593e8 100644 --- a/src/leap/bitmask/core/dispatcher.py +++ b/src/leap/bitmask/core/dispatcher.py @@ -104,28 +104,23 @@ class MailCmd(SubCommand): label = 'mail' @register_method('dict') - def do_ENABLE(self, service, *parts): + def do_ENABLE(self, service, *parts, **kw): d = service.do_enable_service(self.label) return d @register_method('dict') - def do_DISABLE(self, service, *parts): + def do_DISABLE(self, service, *parts, **kw): d = service.do_disable_service(self.label) return d @register_method('dict') - def do_STATUS(self, mail, *parts): + def do_STATUS(self, mail, *parts, **kw): d = mail.do_status() return d @register_method('dict') - def do_GET_IMAP_TOKEN(self, mail, *parts): - d = mail.get_imap_token() - return d - - @register_method('dict') - def do_GET_SMTP_TOKEN(self, mail, *parts): - d = mail.get_smtp_token() + def do_GET_TOKEN(self, mail, *parts, **kw): + d = mail.get_token() return d @register_method('dict') diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py index 6a9155c6..b00db866 100644 --- a/src/leap/bitmask/core/mail_services.py +++ b/src/leap/bitmask/core/mail_services.py @@ -380,8 +380,7 @@ class StandardMailService(service.MultiService, HookableService): self._soledad_sessions = {} self._keymanager_sessions = {} self._sendmail_opts = {} - self._imap_tokens = {} - self._smtp_tokens = {} + self._service_tokens = {} self._active_user = None super(StandardMailService, self).__init__() self.initializeChildrenServices() @@ -414,20 +413,12 @@ class StandardMailService(service.MultiService, HookableService): incoming = self.getServiceNamed('incoming_mail') incoming.startInstance(userid) - def registerIMAPToken(token): - self._imap_tokens[userid] = token + def registerToken(token): + self._service_tokens[userid] = token self._active_user = userid - return token - def registerSMTPToken(token): - self._smtp_tokens[userid] = token - return token - - d = soledad.get_or_create_service_token('imap') - d.addCallback(registerIMAPToken) - d.addCallback( - lambda _: soledad.get_or_create_service_token('smtp')) - d.addCallback(registerSMTPToken) + d = soledad.get_or_create_service_token('mail_auth') + d.addCallback(registerToken) return d def stopInstance(self): @@ -450,21 +441,13 @@ class StandardMailService(service.MultiService, HookableService): def do_status(self): return 'mail: %s' % 'running' if self.running else 'disabled' - def get_imap_token(self): - active_user = self._active_user - if not active_user: - return defer.succeed('NO ACTIVE USER') - token = self._imap_tokens.get(active_user) - # TODO return just the tuple, no format. - return defer.succeed("IMAP TOKEN (%s): %s" % (active_user, token)) - - def get_smtp_token(self): + def get_token(self): active_user = self._active_user if not active_user: return defer.succeed('NO ACTIVE USER') - token = self._smtp_tokens.get(active_user) + token = self._service_tokens.get(active_user) # TODO return just the tuple, no format. - return defer.succeed("SMTP TOKEN (%s): %s" % (active_user, token)) + return defer.succeed("MAIL TOKEN (%s): %s" % (active_user, token)) def do_get_smtp_cert_path(self, userid): username, provider = userid.split('@') -- cgit v1.2.3