summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/core
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-12-08 18:10:13 +0100
committerKali Kaneko <kali@leap.se>2017-12-20 15:27:06 +0100
commitd2e5f8406b6101971c196f40e39322e36d6bdb33 (patch)
treecfe3fb852f80effd52b7a75688cd2a5118fe9a1f /src/leap/bitmask/core
parentd5bd7394344afd2c6466f368a0de7566094a0d0d (diff)
[feat] Add msg_status call to the mail API
To get the status of a single message providing it's mailbox and message-id. For now it only returns encryption/signature status. - Resolves: #6914
Diffstat (limited to 'src/leap/bitmask/core')
-rw-r--r--src/leap/bitmask/core/dispatcher.py12
-rw-r--r--src/leap/bitmask/core/mail_services.py32
2 files changed, 40 insertions, 4 deletions
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index e97e6c0b..20c0615b 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -286,6 +286,18 @@ class MailCmd(SubCommand):
return mail.get_token(userid)
@register_method('dict')
+ def do_MSG_STATUS(self, mail, *parts, **kw):
+ try:
+ userid = parts[2]
+ mbox = parts[3]
+ message_id = parts[4]
+ except IndexError:
+ raise DispatchError(
+ 'wrong number of arguments: expected 3')
+ d = mail.do_msg_status(userid, mbox, message_id)
+ return d
+
+ @register_method('dict')
def do_MIXNET_STATUS(self, mail, *parts, **kw):
try:
userid = parts[2]
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index ac5000fa..24bc48fa 100644
--- a/src/leap/bitmask/core/mail_services.py
+++ b/src/leap/bitmask/core/mail_services.py
@@ -22,6 +22,7 @@ This should be moved to the different submodules when it stabilizes.
"""
import json
import os
+import re
import shutil
import tempfile
from collections import defaultdict
@@ -48,6 +49,7 @@ try:
from leap.bitmask.mail.smtp import service as smtp_service
from leap.bitmask.mail.incoming.service import IncomingMail
from leap.bitmask.mail.incoming.service import INCOMING_CHECK_PERIOD
+ from leap.bitmask.mail.utils import first
from leap.soledad.client.api import Soledad
HAS_MAIL = True
except ImportError:
@@ -625,6 +627,32 @@ class StandardMailService(service.MultiService, HookableService):
token = self._service_tokens.get(userid)
return {'user': userid, 'token': token}
+ @defer.inlineCallbacks
+ def do_msg_status(self, userid, mbox, msgid):
+ account = self._get_account(userid)
+ msg = yield account.get_message_by_msgid(mbox, msgid)
+ if msg is None:
+ raise Exception("Not found message id: " + msgid)
+
+ headers = msg.get_headers()
+ encryption = headers.get(IncomingMail.LEAP_ENCRYPTION_HEADER, '')
+ signature = headers.get(IncomingMail.LEAP_SIGNATURE_HEADER, '')
+
+ status = {}
+ pubkey_re = re.compile(' pubkey="([0-9A-F]*)"')
+ fingerprint = first(pubkey_re.findall(signature))
+ status['signature'] = signature.split(';')[0]
+ status['sign_fp'] = fingerprint
+ status['encryption'] = encryption
+
+ if ((IncomingMail.LEAP_ENCRYPTION_DECRYPTED == encryption) and
+ (IncomingMail.LEAP_SIGNATURE_VALID == status['signature'])):
+ status['secured'] = True
+ else:
+ status['secured'] = False
+
+ defer.returnValue(status)
+
def do_msg_add(self, userid, raw_msg, mailbox=None):
if not mailbox:
mailbox = INBOX_NAME
@@ -898,10 +926,6 @@ def _get_config_for_service(service, basedir, provider):
return config
-def first(xs):
- return xs[0]
-
-
def _pick_server(config, strategy=first):
"""
Picks a server from a list of possible choices.