From d8bf59b600b6a08eeb963d8ad0c28db3e3f78980 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 5 Aug 2013 13:14:25 +0200 Subject: add imap service --- src/leap/services/mail/imap.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/leap/services/mail/imap.py (limited to 'src/leap/services/mail') diff --git a/src/leap/services/mail/imap.py b/src/leap/services/mail/imap.py new file mode 100644 index 00000000..65fbe3b5 --- /dev/null +++ b/src/leap/services/mail/imap.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# imap.py +# Copyright (C) 2013 LEAP +# +# 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, either version 3 of the License, or +# (at your option) any later version. +# +# 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, see . +""" +Initialization of imap service +""" +import logging +import sys + +from leap.mail.imap.service import imap +from twisted.python import log + +logger = logging.getLogger(__name__) + + +def start_imap_service(*args, **kwargs): + """ + Initializes and run imap service. + """ + logger.debug('Launching imap service') + + # XXX handle this in a more appropriate manner + log.startLogging(open('/tmp/leap-imap.log', 'w')) + log.startLogging(sys.stdout) + + imap.run_service(*args, **kwargs) -- cgit v1.2.3 From f757e73a4d2fb05e90dba306c4d918f6aa7f1413 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 5 Aug 2013 13:38:12 +0200 Subject: start imap service --- src/leap/services/mail/imap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/leap/services/mail') diff --git a/src/leap/services/mail/imap.py b/src/leap/services/mail/imap.py index 65fbe3b5..5fdc7492 100644 --- a/src/leap/services/mail/imap.py +++ b/src/leap/services/mail/imap.py @@ -29,6 +29,8 @@ logger = logging.getLogger(__name__) def start_imap_service(*args, **kwargs): """ Initializes and run imap service. + + :returns: twisted.internet.task.LoopingCall instance """ logger.debug('Launching imap service') @@ -36,4 +38,4 @@ def start_imap_service(*args, **kwargs): log.startLogging(open('/tmp/leap-imap.log', 'w')) log.startLogging(sys.stdout) - imap.run_service(*args, **kwargs) + return imap.run_service(*args, **kwargs) -- cgit v1.2.3 From baf3738bec7a712f90316f79255d4c91259e3fdf Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 6 Aug 2013 18:04:38 -0300 Subject: Add multiple schemas support for SMTP --- src/leap/services/mail/smtpspec.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/leap/services/mail') diff --git a/src/leap/services/mail/smtpspec.py b/src/leap/services/mail/smtpspec.py index 270dfb76..9fc1984a 100644 --- a/src/leap/services/mail/smtpspec.py +++ b/src/leap/services/mail/smtpspec.py @@ -15,7 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -smtp_config_spec = { +# Schemas dict +# To add a schema for a version you should follow the form: +# { '1': schema_v1, '2': schema_v2, ... etc } +# so for instance, to add the '2' version, you should do: +# eipservice_config_spec['2'] = schema_v2 +smtp_config_spec = {} + +smtp_config_spec['1'] = { 'description': 'sample smtp service config', 'type': 'object', 'properties': { @@ -49,3 +56,15 @@ smtp_config_spec = { } } } + + +def get_schema(version): + """ + Returns the schema corresponding to the version given. + + :param version: the version of the schema to get. + :type version: str + :rtype: dict or None if the version is not supported. + """ + schema = smtp_config_spec.get(version, None) + return schema -- cgit v1.2.3 From 4ee2773660a571b180732ef41446399edf8501ac Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 6 Aug 2013 18:05:06 -0300 Subject: Update code to use the new SMTP schema selection. --- src/leap/services/mail/smtpbootstrapper.py | 8 ++++++-- src/leap/services/mail/smtpconfig.py | 9 ++------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src/leap/services/mail') diff --git a/src/leap/services/mail/smtpbootstrapper.py b/src/leap/services/mail/smtpbootstrapper.py index e8af5349..48040035 100644 --- a/src/leap/services/mail/smtpbootstrapper.py +++ b/src/leap/services/mail/smtpbootstrapper.py @@ -72,10 +72,12 @@ class SMTPBootstrapper(AbstractBootstrapper): if self._download_if_needed and mtime: headers['if-modified-since'] = mtime + api_version = self._provider_config.get_api_version() + # there is some confusion with this uri, config_uri = "%s/%s/config/smtp-service.json" % ( - self._provider_config.get_api_uri(), - self._provider_config.get_api_version()) + self._provider_config.get_api_uri(), api_version) + logger.debug('Downloading SMTP config from: %s' % config_uri) srp_auth = SRPAuth(self._provider_config) @@ -91,6 +93,8 @@ class SMTPBootstrapper(AbstractBootstrapper): cookies=cookies) res.raise_for_status() + self._smtp_config.set_api_version(api_version) + # Not modified if res.status_code == 304: logger.debug("SMTP definition has not been modified") diff --git a/src/leap/services/mail/smtpconfig.py b/src/leap/services/mail/smtpconfig.py index 30371005..ca974fcf 100644 --- a/src/leap/services/mail/smtpconfig.py +++ b/src/leap/services/mail/smtpconfig.py @@ -21,7 +21,7 @@ SMTP configuration import logging from leap.common.config.baseconfig import BaseConfig -from leap.services.mail.smtpspec import smtp_config_spec +from leap.services.mail.smtpspec import get_schema logger = logging.getLogger(__name__) @@ -33,12 +33,7 @@ class SMTPConfig(BaseConfig): def __init__(self): BaseConfig.__init__(self) - - def _get_spec(self): - """ - Returns the spec object for the specific configuration - """ - return smtp_config_spec + self._get_schema = get_schema def get_hosts(self): return self._safe_get_value("hosts") -- cgit v1.2.3 From 959c24f3eae90f5b306aa99401bc11c5021b0faa Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 7 Aug 2013 14:50:16 -0300 Subject: Define abstract methods from BaseConfig. --- src/leap/services/mail/smtpconfig.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/leap/services/mail') diff --git a/src/leap/services/mail/smtpconfig.py b/src/leap/services/mail/smtpconfig.py index ca974fcf..ea0f9c37 100644 --- a/src/leap/services/mail/smtpconfig.py +++ b/src/leap/services/mail/smtpconfig.py @@ -33,7 +33,14 @@ class SMTPConfig(BaseConfig): def __init__(self): BaseConfig.__init__(self) - self._get_schema = get_schema + + def _get_schema(self): + """ + Returns the schema corresponding to the version given. + + :rtype: dict or None if the version is not supported. + """ + return get_schema(self._api_version) def get_hosts(self): return self._safe_get_value("hosts") -- cgit v1.2.3 From 3fd9833f3392050068b42e9fd3f7b982b1040d64 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 8 Aug 2013 14:01:18 +0200 Subject: remove separate logging --- src/leap/services/mail/imap.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/leap/services/mail') diff --git a/src/leap/services/mail/imap.py b/src/leap/services/mail/imap.py index 5fdc7492..4dceb2ad 100644 --- a/src/leap/services/mail/imap.py +++ b/src/leap/services/mail/imap.py @@ -34,8 +34,9 @@ def start_imap_service(*args, **kwargs): """ logger.debug('Launching imap service') - # XXX handle this in a more appropriate manner - log.startLogging(open('/tmp/leap-imap.log', 'w')) - log.startLogging(sys.stdout) + # Uncomment the next two lines to get a separate debugging log + # TODO handle this by a separate flag. + #log.startLogging(open('/tmp/leap-imap.log', 'w')) + #log.startLogging(sys.stdout) return imap.run_service(*args, **kwargs) -- cgit v1.2.3 From 55f51fee46c6b6a9189161a9a5648410400772ad Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Thu, 8 Aug 2013 12:10:18 -0300 Subject: Add multiple schema support for Soledad. Also fix comment typo. --- src/leap/services/mail/smtpspec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/leap/services/mail') diff --git a/src/leap/services/mail/smtpspec.py b/src/leap/services/mail/smtpspec.py index 9fc1984a..ff9d1bf8 100644 --- a/src/leap/services/mail/smtpspec.py +++ b/src/leap/services/mail/smtpspec.py @@ -19,7 +19,7 @@ # To add a schema for a version you should follow the form: # { '1': schema_v1, '2': schema_v2, ... etc } # so for instance, to add the '2' version, you should do: -# eipservice_config_spec['2'] = schema_v2 +# smtp_config_spec['2'] = schema_v2 smtp_config_spec = {} smtp_config_spec['1'] = { -- cgit v1.2.3