summaryrefslogtreecommitdiff
path: root/alot/db
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2013-07-01 10:51:04 -0500
committerPatrick Totzke <patricktotzke@gmail.com>2013-07-07 18:14:28 +0100
commitd6806671c1ae96227acfb8504e98cf2278da5f90 (patch)
treef453d5cc8146852e7a1a9194f9ad60eadf644498 /alot/db
parent949c5b17b48ed8e45d315ba9c55d3ace1b511cb3 (diff)
pep8&pyflakes fixes
mostly automatically fixed
Diffstat (limited to 'alot/db')
-rw-r--r--alot/db/attachment.py7
-rw-r--r--alot/db/envelope.py5
-rw-r--r--alot/db/errors.py3
-rw-r--r--alot/db/message.py18
-rw-r--r--alot/db/utils.py31
5 files changed, 37 insertions, 27 deletions
diff --git a/alot/db/attachment.py b/alot/db/attachment.py
index 2f8b37dc..ad996d2e 100644
--- a/alot/db/attachment.py
+++ b/alot/db/attachment.py
@@ -14,6 +14,7 @@ from alot.db.utils import decode_header
class Attachment(object):
+
"""represents a mail attachment"""
def __init__(self, emailpart):
@@ -25,8 +26,8 @@ class Attachment(object):
def __str__(self):
desc = '%s:%s (%s)' % (self.get_content_type(),
- self.get_filename(),
- helper.humanize_size(self.get_size()))
+ self.get_filename(),
+ helper.humanize_size(self.get_size()))
return string_decode(desc)
def get_filename(self):
@@ -87,5 +88,5 @@ class Attachment(object):
cd = self.part['Content-Disposition']
del part['Content-Disposition']
part['Content-Disposition'] = Header(cd, maxlinelen=78,
- header_name='Content-Disposition')
+ header_name='Content-Disposition')
return part
diff --git a/alot/db/envelope.py b/alot/db/envelope.py
index f6787705..0c0d3150 100644
--- a/alot/db/envelope.py
+++ b/alot/db/envelope.py
@@ -20,11 +20,12 @@ import gpgme
from alot.settings import settings
from alot.errors import GPGProblem, GPGCode
-from attachment import Attachment
-from utils import encode_header
+from .attachment import Attachment
+from .utils import encode_header
class Envelope(object):
+
"""a message that is not yet sent and still editable.
It holds references to unencoded! body text and mail headers among other
things. Envelope implements the python container API for easy access of
diff --git a/alot/db/errors.py b/alot/db/errors.py
index 55eb05ef..668ab34e 100644
--- a/alot/db/errors.py
+++ b/alot/db/errors.py
@@ -8,15 +8,18 @@ class DatabaseError(Exception):
class DatabaseROError(DatabaseError):
+
"""cannot write to read-only database"""
pass
class DatabaseLockedError(DatabaseError):
+
"""cannot write to locked index"""
pass
class NonexistantObjectError(DatabaseError):
+
"""requested thread or message does not exist in the index"""
pass
diff --git a/alot/db/message.py b/alot/db/message.py
index 002f7cf9..4249f8c8 100644
--- a/alot/db/message.py
+++ b/alot/db/message.py
@@ -10,12 +10,13 @@ from notmuch import NullPointerError
import alot.helper as helper
from alot.settings import settings
-from utils import extract_headers, extract_body, message_from_file
+from .utils import extract_headers, extract_body, message_from_file
from alot.db.utils import decode_header
-from attachment import Attachment
+from .attachment import Attachment
class Message(object):
+
"""
a persistent notmuch message object.
It it uses a :class:`~alot.db.DBManager` for cached manipulation
@@ -36,10 +37,10 @@ class Message(object):
self._thread = thread
casts_date = lambda: datetime.fromtimestamp(msg.get_date())
self._datetime = helper.safely_get(casts_date,
- ValueError, None)
+ ValueError, None)
self._filename = msg.get_filename()
author = helper.safely_get(lambda: msg.get_header('From'),
- NullPointerError)
+ NullPointerError)
self._from = decode_header(author)
self._email = None # will be read upon first use
self._attachments = None # will be read upon first use
@@ -102,8 +103,7 @@ class Message(object):
def get_tags(self):
"""returns tags attached to this message as list of strings"""
- l = list(self._tags)
- l.sort()
+ l = sorted(self._tags)
return l
def get_thread(self):
@@ -130,7 +130,7 @@ class Message(object):
:rtype: str
"""
- if self._datetime == None:
+ if self._datetime is None:
res = None
else:
res = settings.represent_datetime(self._datetime)
@@ -235,7 +235,7 @@ class Message(object):
'application/pgp-signature']:
self._attachments.append(Attachment(part))
elif cd.startswith('inline'):
- if filename != None and ct != 'application/pgp':
+ if filename is not None and ct != 'application/pgp':
self._attachments.append(Attachment(part))
return self._attachments
@@ -243,7 +243,7 @@ class Message(object):
"""
returns bodystring extracted from this mail
"""
- #TODO: allow toggle commands to decide which part is considered body
+ # TODO: allow toggle commands to decide which part is considered body
return extract_body(self.get_email())
def get_text_content(self):
diff --git a/alot/db/utils.py b/alot/db/utils.py
index db8de0de..ba6d466e 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -69,7 +69,7 @@ def get_params(mail, failobj=list(), header='content-type', unquote=True):
:param unquote: unquote the values
:returns: a `dict` containing the parameters
'''
- return {k.lower():v for k, v in mail.get_params(failobj, header, unquote)}
+ return {k.lower(): v for k, v in mail.get_params(failobj, header, unquote)}
def message_from_file(handle):
@@ -80,7 +80,8 @@ def message_from_file(handle):
message are added to the returned message object.
:param handle: a file-like object
- :returns: :class:`email.message.Message` possibly augmented with decrypted data
+ :returns: :class:`email.message.Message` possibly augmented with
+ decrypted data
'''
m = email.message_from_file(handle)
@@ -95,7 +96,7 @@ def message_from_file(handle):
# handle OpenPGP signed data
if (m.is_multipart() and
m.get_content_subtype() == 'signed' and
- p.get('protocol', None) == app_pgp_sig):
+ p.get('protocol', None) == app_pgp_sig):
# RFC 3156 is quite strict:
# * exactly two messages
# * the second is of type 'application/pgp-signature'
@@ -132,7 +133,7 @@ def message_from_file(handle):
elif (m.is_multipart() and
m.get_content_subtype() == 'encrypted' and
p.get('protocol', None) == app_pgp_enc and
- 'Version: 1' in m.get_payload(0).get_payload()):
+ 'Version: 1' in m.get_payload(0).get_payload()):
# RFC 3156 is quite strict:
# * exactly two messages
# * the first is of type 'application/pgp-encrypted'
@@ -143,7 +144,8 @@ def message_from_file(handle):
ct = m.get_payload(0).get_content_type()
if ct != app_pgp_enc:
- malformed = 'expected Content-Type: {0}, got: {1}'.format(app_pgp_enc, ct)
+ malformed = 'expected Content-Type: {0}, got: {1}'.format(
+ app_pgp_enc, ct)
want = 'application/octet-stream'
ct = m.get_payload(1).get_content_type()
@@ -228,7 +230,7 @@ def extract_headers(mail, headers=None):
:type headers: list of str
"""
headertext = u''
- if headers == None:
+ if headers is None:
headers = mail.keys()
for key in headers:
value = u''
@@ -251,12 +253,14 @@ def extract_body(mail, types=None):
:type types: list of str
"""
- preferred = 'text/plain' if settings.get('prefer_plaintext') else 'text/html'
+ preferred = 'text/plain' if settings.get(
+ 'prefer_plaintext') else 'text/html'
has_preferred = False
# see if the mail has our preferred type
- if types == None:
- has_preferred = list(typed_subpart_iterator(mail, *preferred.split('/')))
+ if types is None:
+ has_preferred = list(typed_subpart_iterator(
+ mail, *preferred.split('/')))
body_parts = []
for part in mail.walk():
@@ -279,7 +283,7 @@ def extract_body(mail, types=None):
raw_payload = string_decode(raw_payload, enc)
body_parts.append(string_sanitize(raw_payload))
else:
- #get mime handler
+ # get mime handler
key = 'copiousoutput'
handler, entry = settings.mailcap_find_match(ctype, key=key)
tempfile_name = None
@@ -294,8 +298,8 @@ def extract_body(mail, types=None):
nametemplate = entry.get('nametemplate', '%s')
prefix, suffix = parse_mailcap_nametemplate(nametemplate)
tmpfile = tempfile.NamedTemporaryFile(delete=False,
- prefix=prefix,
- suffix=suffix)
+ prefix=prefix,
+ suffix=suffix)
# write payload to tmpfile
tmpfile.write(raw_payload)
tmpfile.close()
@@ -313,7 +317,8 @@ def extract_body(mail, types=None):
logging.debug('parms: %s' % str(parms))
cmdlist = split_commandstring(cmd)
# call handler
- rendered_payload, errmsg, retval = helper.call_cmd(cmdlist, stdin=stdin)
+ rendered_payload, errmsg, retval = helper.call_cmd(
+ cmdlist, stdin=stdin)
# remove tempfile
if tempfile_name: