summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-08-03 14:27:48 -0400
committerKali Kaneko <kali@leap.se>2015-08-03 14:27:48 -0400
commita778140a3dfa2907d2e1d45cfa87ee3b2dd5329a (patch)
treedb4b3587b6295730e059279925cbb97fbdb7cb7b
parentf27ad9a3fdb2a6746ddb13fe4c117614c4b59364 (diff)
parent5027dd2dd3c7679a7eea025d838a7d472c355623 (diff)
Merge remote-tracking branch 'leapcode/pr/188' into develop
-rw-r--r--src/leap/mail/_version.py13
-rw-r--r--src/leap/mail/adaptors/models.py6
-rw-r--r--src/leap/mail/adaptors/tests/test_models.py7
-rw-r--r--src/leap/mail/imap/mailbox.py6
-rw-r--r--src/leap/mail/imap/messages.py7
-rw-r--r--src/leap/mail/imap/server.py16
-rw-r--r--src/leap/mail/imap/service/imap.py6
-rw-r--r--src/leap/mail/imap/tests/__init__.py20
-rw-r--r--src/leap/mail/imap/tests/test_imap.py20
-rw-r--r--src/leap/mail/imap/tests/test_imap_store_fetch.py12
-rw-r--r--src/leap/mail/imap/tests/walktree.py4
-rw-r--r--src/leap/mail/incoming/service.py12
-rw-r--r--src/leap/mail/mail.py4
-rw-r--r--src/leap/mail/smtp/__init__.py4
-rw-r--r--src/leap/mail/sync_hooks.py5
-rw-r--r--src/leap/mail/utils.py7
-rw-r--r--src/leap/mail/walk.py86
17 files changed, 136 insertions, 99 deletions
diff --git a/src/leap/mail/_version.py b/src/leap/mail/_version.py
index d80ec47..b77d552 100644
--- a/src/leap/mail/_version.py
+++ b/src/leap/mail/_version.py
@@ -1,3 +1,7 @@
+import subprocess
+import sys
+import re
+import os.path
IN_LONG_VERSION_PY = True
# This file helps to compute a version number in source trees obtained from
@@ -14,10 +18,6 @@ git_refnames = "$Format:%d$"
git_full = "$Format:%H$"
-import subprocess
-import sys
-
-
def run_command(args, cwd=None, verbose=False):
try:
# remember shell=False, so use git.cmd on windows, not just git
@@ -38,11 +38,6 @@ def run_command(args, cwd=None, verbose=False):
return stdout
-import sys
-import re
-import os.path
-
-
def get_expanded_variables(versionfile_source):
# the code embedded in _version.py can just fetch the value of these
# variables. When used from setup.py, we don't want to import
diff --git a/src/leap/mail/adaptors/models.py b/src/leap/mail/adaptors/models.py
index 88e0e4e..2bf9e60 100644
--- a/src/leap/mail/adaptors/models.py
+++ b/src/leap/mail/adaptors/models.py
@@ -115,10 +115,8 @@ class DocumentWrapper(object):
def _normalize_dict(_dict):
items = _dict.items()
- not_callable = lambda (k, v): not callable(v)
- not_private = lambda(k, v): not k.startswith('_')
- for cond in not_callable, not_private:
- items = filter(cond, items)
+ items = filter(lambda (k, v): not callable(v), items)
+ items = filter(lambda (k, v): not k.startswith('_'), items)
items = [(k, v) if not k.endswith('_') else (k[:-1], v)
for (k, v) in items]
items = [(k.replace('-', '_'), v) for (k, v) in items]
diff --git a/src/leap/mail/adaptors/tests/test_models.py b/src/leap/mail/adaptors/tests/test_models.py
index efe0bf2..b82cfad 100644
--- a/src/leap/mail/adaptors/tests/test_models.py
+++ b/src/leap/mail/adaptors/tests/test_models.py
@@ -39,7 +39,8 @@ class SerializableModelsTestCase(unittest.TestCase):
class IgnoreMe(object):
pass
- killmeplease = lambda x: x
+ def killmeplease(x):
+ return x
serialized = M.serialize()
expected = {'foo': 42, 'bar': 33, 'baaz': None}
@@ -88,7 +89,9 @@ class DocumentWrapperTestCase(unittest.TestCase):
class Wrapper(models.DocumentWrapper):
class model(models.SerializableModel):
foo = 42
- getwrapper = lambda: Wrapper(bar=1)
+
+ def getwrapper():
+ return Wrapper(bar=1)
self.assertRaises(RuntimeError, getwrapper)
def test_no_model_wrapper(self):
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py
index 4339bd2..c52a2e3 100644
--- a/src/leap/mail/imap/mailbox.py
+++ b/src/leap/mail/imap/mailbox.py
@@ -878,9 +878,9 @@ class IMAPMailbox(object):
# A better place for this would be the COPY/APPEND dispatcher
# in server.py, but qtreactor hangs when I do that, so this seems
# to work fine for now.
- #d.addCallback(lambda r: self.reactor.callLater(0, self.notify_new))
- #deferLater(self.reactor, 0, self._do_copy, message, d)
- #return d
+ # d.addCallback(lambda r: self.reactor.callLater(0, self.notify_new))
+ # deferLater(self.reactor, 0, self._do_copy, message, d)
+ # return d
d = self.collection.copy_msg(message.message,
self.collection.mbox_uuid)
diff --git a/src/leap/mail/imap/messages.py b/src/leap/mail/imap/messages.py
index 9af4c99..d1c7b93 100644
--- a/src/leap/mail/imap/messages.py
+++ b/src/leap/mail/imap/messages.py
@@ -217,10 +217,13 @@ def _format_headers(headers, negate, *names):
return {str('content-type'): str('')}
names = map(lambda s: s.upper(), names)
+
if negate:
- cond = lambda key: key.upper() not in names
+ def cond(key):
+ return key.upper() not in names
else:
- cond = lambda key: key.upper() in names
+ def cond(key):
+ return key.upper() in names
if isinstance(headers, list):
headers = dict(headers)
diff --git a/src/leap/mail/imap/server.py b/src/leap/mail/imap/server.py
index 2b670c1..050521a 100644
--- a/src/leap/mail/imap/server.py
+++ b/src/leap/mail/imap/server.py
@@ -122,9 +122,9 @@ class LEAPIMAPServer(imap4.IMAP4Server):
elif part.text:
_w(str(part) + ' ')
_f()
- return imap4.FileProducer(msg.getBodyFile()
- ).beginProducing(self.transport
- )
+ return imap4.FileProducer(
+ msg.getBodyFile()
+ ).beginProducing(self.transport)
elif part.mime:
hdrs = imap4._formatHeaders(msg.getHeaders(True))
@@ -151,10 +151,10 @@ class LEAPIMAPServer(imap4.IMAP4Server):
_fd.seek(0)
else:
_fd = fd
- return imap4.FileProducer(_fd
- # END PATCHED #########################3
- ).beginProducing(self.transport
- )
+ return imap4.FileProducer(
+ _fd
+ # END PATCHED #########################3
+ ).beginProducing(self.transport)
else:
mf = imap4.IMessageFile(msg, None)
if mf is not None:
@@ -459,7 +459,7 @@ class LEAPIMAPServer(imap4.IMAP4Server):
mailboxes.addCallback(self._cbSubscribed)
mailboxes.addCallback(
self._cbListWork, tag, sub, cmdName,
- ).addErrback(self._ebListWork, tag)
+ ).addErrback(self._ebListWork, tag)
def _cbSubscribed(self, mailboxes):
subscribed = [
diff --git a/src/leap/mail/imap/service/imap.py b/src/leap/mail/imap/service/imap.py
index 92d05cc..c3ae59a 100644
--- a/src/leap/mail/imap/service/imap.py
+++ b/src/leap/mail/imap/service/imap.py
@@ -17,7 +17,6 @@
"""
IMAP service initialization
"""
-# TODO: leave only an implementor of IService in here
import logging
import os
@@ -29,13 +28,14 @@ from twisted.internet.protocol import ServerFactory
from twisted.mail import imap4
from twisted.python import log
-logger = logging.getLogger(__name__)
-
from leap.common.events import emit, catalog
from leap.common.check import leap_check
from leap.mail.imap.account import IMAPAccount
from leap.mail.imap.server import LEAPIMAPServer
+# TODO: leave only an implementor of IService in here
+
+logger = logging.getLogger(__name__)
DO_MANHOLE = os.environ.get("LEAP_MAIL_MANHOLE", None)
if DO_MANHOLE:
diff --git a/src/leap/mail/imap/tests/__init__.py b/src/leap/mail/imap/tests/__init__.py
index f3d5ca6..5cf60ed 100644
--- a/src/leap/mail/imap/tests/__init__.py
+++ b/src/leap/mail/imap/tests/__init__.py
@@ -1,4 +1,4 @@
-#-*- encoding: utf-8 -*-
+# -*- encoding: utf-8 -*-
"""
leap/email/imap/tests/__init__.py
----------------------------------
@@ -10,13 +10,6 @@ code, using twisted.trial, for testing leap_mx.
@copyright: © 2013 Kali Kaneko, see COPYLEFT file
"""
-__all__ = ['test_imap']
-
-
-def run():
- """xxx fill me in"""
- pass
-
import os
import u1db
@@ -25,11 +18,18 @@ from leap.common.testing.basetest import BaseLeapTest
from leap.soledad.client import Soledad
from leap.soledad.common.document import SoledadDocument
+__all__ = ['test_imap']
+
-#-----------------------------------------------------------------------------
+def run():
+ """xxx fill me in"""
+ pass
+
+# -----------------------------------------------------------------------------
# Some tests inherit from BaseSoledadTest in order to have a working Soledad
# instance in each test.
-#-----------------------------------------------------------------------------
+# -----------------------------------------------------------------------------
+
class BaseSoledadIMAPTest(BaseLeapTest):
"""
diff --git a/src/leap/mail/imap/tests/test_imap.py b/src/leap/mail/imap/tests/test_imap.py
index af1bd69..62c3c41 100644
--- a/src/leap/mail/imap/tests/test_imap.py
+++ b/src/leap/mail/imap/tests/test_imap.py
@@ -387,8 +387,11 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
acc.addMailbox('this/mbox'),
acc.addMailbox('that/mbox')])
- dc1 = lambda: acc.subscribe('this/mbox')
- dc2 = lambda: acc.subscribe('that/mbox')
+ def dc1():
+ return acc.subscribe('this/mbox')
+
+ def dc2():
+ return acc.subscribe('that/mbox')
def login():
return self.client.login(TEST_USER, TEST_PASSWD)
@@ -439,7 +442,7 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
d1 = self.connected.addCallback(strip(add_mailbox))
d1.addCallback(strip(login))
d1.addCallback(strip(select))
- #d1.addErrback(self._ebGeneral)
+ # d1.addErrback(self._ebGeneral)
d2 = self.loopback()
@@ -668,9 +671,14 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
acc = self.server.theAccount
- dc1 = lambda: acc.addMailbox('root_subthing', creation_ts=42)
- dc2 = lambda: acc.addMailbox('root_another_thing', creation_ts=42)
- dc3 = lambda: acc.addMailbox('non_root_subthing', creation_ts=42)
+ def dc1():
+ return acc.addMailbox('root_subthing', creation_ts=42)
+
+ def dc2():
+ return acc.addMailbox('root_another_thing', creation_ts=42)
+
+ def dc3():
+ return acc.addMailbox('non_root_subthing', creation_ts=42)
def login():
return self.client.login(TEST_USER, TEST_PASSWD)
diff --git a/src/leap/mail/imap/tests/test_imap_store_fetch.py b/src/leap/mail/imap/tests/test_imap_store_fetch.py
index 6da8581..81f88fe 100644
--- a/src/leap/mail/imap/tests/test_imap_store_fetch.py
+++ b/src/leap/mail/imap/tests/test_imap_store_fetch.py
@@ -43,10 +43,14 @@ class StoreAndFetchTestCase(IMAP4HelperMixin):
self.connected.addCallback(
self._addSignedMessage).addCallback(
- lambda uid: self.function(
- uids, uid=uid) # do NOT use seq numbers!
- ).addCallback(result).addCallback(
- self._cbStopClient).addErrback(self._ebGeneral)
+ lambda uid: self.function(
+ uids, uid=uid
+ ) # do NOT use seq numbers!
+ ).addCallback(
+ result
+ ).addCallback(
+ self._cbStopClient
+ ).addErrback(self._ebGeneral)
d = loopback.loopbackTCP(self.server, self.client, noisy=False)
d.addCallback(lambda x: self.assertEqual(self.result, self.expected))
diff --git a/src/leap/mail/imap/tests/walktree.py b/src/leap/mail/imap/tests/walktree.py
index 695f487..f259a55 100644
--- a/src/leap/mail/imap/tests/walktree.py
+++ b/src/leap/mail/imap/tests/walktree.py
@@ -1,4 +1,4 @@
-#t -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
# walktree.py
# Copyright (C) 2013 LEAP
#
@@ -19,6 +19,7 @@ Tests for the walktree module.
"""
import os
import sys
+import pprint
from email import parser
from leap.mail import walk as W
@@ -118,7 +119,6 @@ if DEBUG and DO_CHECK:
print "Structure: OK"
-import pprint
print
print "RAW DOCS"
pprint.pprint(raw_docs)
diff --git a/src/leap/mail/incoming/service.py b/src/leap/mail/incoming/service.py
index 3daf86b..2bc6751 100644
--- a/src/leap/mail/incoming/service.py
+++ b/src/leap/mail/incoming/service.py
@@ -429,9 +429,9 @@ class IncomingMail(Service):
fromHeader = msg.get('from', None)
senderAddress = None
- if (fromHeader is not None
- and (msg.get_content_type() == MULTIPART_ENCRYPTED
- or msg.get_content_type() == MULTIPART_SIGNED)):
+ if (fromHeader is not None and
+ (msg.get_content_type() == MULTIPART_ENCRYPTED or
+ msg.get_content_type() == MULTIPART_SIGNED)):
senderAddress = parseaddr(fromHeader)[1]
def add_leap_header(ret):
@@ -635,8 +635,10 @@ class IncomingMail(Service):
url = shlex.split(fields['url'])[0] # remove quotations
urlparts = urlparse(url)
addressHostname = address.split('@')[1]
- if (urlparts.scheme == 'https'
- and urlparts.hostname == addressHostname):
+ if (
+ urlparts.scheme == 'https' and
+ urlparts.hostname == addressHostname
+ ):
def fetch_error(failure):
if failure.check(keymanager_errors.KeyNotFound):
logger.warning("Url from OpenPGP header %s failed"
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index 6a7c558..540a493 100644
--- a/src/leap/mail/mail.py
+++ b/src/leap/mail/mail.py
@@ -85,7 +85,7 @@ def _encode_payload(payload, ctype=""):
# soledad when it's creating the documents.
# if not charset:
# charset = get_email_charset(payload)
- #------------------------------------------------------
+ # -----------------------------------------------------
if not charset:
charset = "utf-8"
@@ -113,7 +113,7 @@ def _unpack_headers(headers_dict):
inner = zip(
itertools.cycle([k]),
map(lambda l: l.rstrip('\n'), splitted))
- headers_l = headers_l[:i] + inner + headers_l[i+1:]
+ headers_l = headers_l[:i] + inner + headers_l[i + 1:]
return headers_l
diff --git a/src/leap/mail/smtp/__init__.py b/src/leap/mail/smtp/__init__.py
index 3ef016b..2ff14d7 100644
--- a/src/leap/mail/smtp/__init__.py
+++ b/src/leap/mail/smtp/__init__.py
@@ -24,11 +24,11 @@ from twisted.internet import reactor
from twisted.internet.error import CannotListenError
from leap.mail.outgoing.service import OutgoingMail
-logger = logging.getLogger(__name__)
-
from leap.common.events import emit, catalog
from leap.mail.smtp.gateway import SMTPFactory
+logger = logging.getLogger(__name__)
+
def setup_smtp_gateway(port, userid, keymanager, smtp_host, smtp_port,
smtp_cert, smtp_key, encrypted_only):
diff --git a/src/leap/mail/sync_hooks.py b/src/leap/mail/sync_hooks.py
index bd8d88d..8efbb7c 100644
--- a/src/leap/mail/sync_hooks.py
+++ b/src/leap/mail/sync_hooks.py
@@ -32,10 +32,11 @@ from twisted.python import log
from leap.soledad.client.interfaces import ISoledadPostSyncPlugin
from leap.mail import constants
-
logger = logging.getLogger(__name__)
-_get_doc_type_preffix = lambda s: s[:2]
+
+def _get_doc_type_preffix(s):
+ return s[:2]
class MailProcessingPostSyncHook(object):
diff --git a/src/leap/mail/utils.py b/src/leap/mail/utils.py
index 029e9f5..64fca98 100644
--- a/src/leap/mail/utils.py
+++ b/src/leap/mail/utils.py
@@ -254,6 +254,7 @@ def validate_address(address):
# String manipulation
#
+
class CustomJsonScanner(object):
"""
This class is a context manager definition used to monkey patch the default
@@ -299,13 +300,13 @@ class CustomJsonScanner(object):
end = s.find("\"", idx)
while not found:
try:
- if s[end-1] != "\\":
+ if s[end - 1] != "\\":
found = True
else:
- end = s.find("\"", end+1)
+ end = s.find("\"", end + 1)
except Exception:
found = True
- return s[idx:end].decode("string-escape"), end+1
+ return s[idx:end].decode("string-escape"), end + 1
def __enter__(self):
"""
diff --git a/src/leap/mail/walk.py b/src/leap/mail/walk.py
index 9f5098d..f613309 100644
--- a/src/leap/mail/walk.py
+++ b/src/leap/mail/walk.py
@@ -26,35 +26,49 @@ from leap.mail.utils import first
DEBUG = os.environ.get("BITMASK_MAIL_DEBUG")
if DEBUG:
- get_hash = lambda s: sha256.SHA256(s).hexdigest()[:10]
+ def get_hash(s):
+ return sha256.SHA256(s).hexdigest()[:10]
else:
- get_hash = lambda s: sha256.SHA256(s).hexdigest()
+ def get_hash(s):
+ return sha256.SHA256(s).hexdigest()
"""
Get interesting message parts
"""
-get_parts = lambda msg: [
- {'multi': part.is_multipart(),
- 'ctype': part.get_content_type(),
- 'size': len(part.as_string()),
- 'parts': len(part.get_payload())
- if isinstance(part.get_payload(), list)
- else 1,
- 'headers': part.items(),
- 'phash': get_hash(part.get_payload())
- if not part.is_multipart() else None}
- for part in msg.walk()]
+
+
+def get_parts(msg):
+ return [
+ {
+ 'multi': part.is_multipart(),
+ 'ctype': part.get_content_type(),
+ 'size': len(part.as_string()),
+ 'parts':
+ len(part.get_payload())
+ if isinstance(part.get_payload(), list)
+ else 1,
+ 'headers': part.items(),
+ 'phash':
+ get_hash(part.get_payload())
+ if not part.is_multipart()
+ else None
+ } for part in msg.walk()]
"""
Utility lambda functions for getting the parts vector and the
payloads from the original message.
"""
-get_parts_vector = lambda parts: (x.get('parts', 1) for x in parts)
-get_payloads = lambda msg: ((x.get_payload(),
- dict(((str.lower(k), v) for k, v in (x.items()))))
- for x in msg.walk())
+
+def get_parts_vector(parts):
+ return (x.get('parts', 1) for x in parts)
+
+
+def get_payloads(msg):
+ return ((x.get_payload(),
+ dict(((str.lower(k), v) for k, v in (x.items()))))
+ for x in msg.walk())
def get_body_phash(msg):
@@ -73,18 +87,22 @@ index the content. Here we remove any mutable part, as the the filename
in the content disposition.
"""
-get_raw_docs = lambda msg, parts: (
- {"type": "cnt", # type content they'll be
- "raw": payload if not DEBUG else payload[:100],
- "phash": get_hash(payload),
- "content-disposition": first(headers.get(
- 'content-disposition', '').split(';')),
- "content-type": headers.get(
- 'content-type', ''),
- "content-transfer-encoding": headers.get(
- 'content-transfer-type', '')}
- for payload, headers in get_payloads(msg)
- if not isinstance(payload, list))
+
+def get_raw_docs(msg, parts):
+ return (
+ {
+ "type": "cnt", # type content they'll be
+ "raw": payload if not DEBUG else payload[:100],
+ "phash": get_hash(payload),
+ "content-disposition": first(headers.get(
+ 'content-disposition', '').split(';')),
+ "content-type": headers.get(
+ 'content-type', ''),
+ "content-transfer-encoding": headers.get(
+ 'content-transfer-type', '')
+ } for payload, headers in get_payloads(msg)
+ if not isinstance(payload, list))
+
"""
Groucho Marx: Now pay particular attention to this first clause, because it's
@@ -155,8 +173,12 @@ def walk_msg_tree(parts, body_phash=None):
print
# wrappers vector
- getwv = lambda pv: [True if pv[i] != 1 and pv[i + 1] == 1 else False
- for i in range(len(pv) - 1)]
+ def getwv(pv):
+ return [
+ True if pv[i] != 1 and pv[i + 1] == 1
+ else False
+ for i in range(len(pv) - 1)
+ ]
wv = getwv(pv)
# do until no wrapper document is left
@@ -187,7 +209,7 @@ def walk_msg_tree(parts, body_phash=None):
last_part = max(main_pmap.keys())
main_pmap[last_part][PART_MAP] = {}
for partind in range(len(pv) - 1):
- print partind+1, len(parts)
+ print partind + 1, len(parts)
main_pmap[last_part][PART_MAP][partind] = parts[partind + 1]
outer = parts[0]