Unverified Commit e653aa16 authored by meskio's avatar meskio
Browse files

[feat] use one single mail_auth token instead of imap/smtp tokens

The core was not addapted to the mail_auth token.
parent edaef12d
......@@ -10,6 +10,8 @@ I've added a new category `Misc` so we can track doc/style/packaging stuff.
- Use mail_auth token in the core instead of imap/smtp tokens.
- `#1234 <https://leap.se/code/issues/1234>`_: Description of the new feature corresponding with issue #1234.
- New feature without related issue number.
......@@ -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']
......@@ -104,28 +104,23 @@ class MailCmd(SubCommand):
label = 'mail'
def do_ENABLE(self, service, *parts):
def do_ENABLE(self, service, *parts, **kw):
d = service.do_enable_service(self.label)
return d
def do_DISABLE(self, service, *parts):
def do_DISABLE(self, service, *parts, **kw):
d = service.do_disable_service(self.label)
return d
def do_STATUS(self, mail, *parts):
def do_STATUS(self, mail, *parts, **kw):
d = mail.do_status()
return d
def do_GET_IMAP_TOKEN(self, mail, *parts):
d = mail.get_imap_token()
return d
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
......@@ -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__()
......@@ -414,20 +413,12 @@ class StandardMailService(service.MultiService, HookableService):
incoming = self.getServiceNamed('incoming_mail')
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')
lambda _: soledad.get_or_create_service_token('smtp'))
d = soledad.get_or_create_service_token('mail_auth')
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('@')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment