summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alot/commands/thread.py4
-rw-r--r--alot/db/envelope.py12
-rw-r--r--alot/db/message.py68
-rw-r--r--alot/widgets.py7
-rw-r--r--docs/source/api/database.rst4
5 files changed, 15 insertions, 80 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 89a48fb4..b8cfd4e4 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -19,7 +19,7 @@ from alot.db.message import encode_header
from alot.db.message import extract_headers
from alot.db.message import extract_body
from alot.db.envelope import Envelope
-from alot.db.message import Attachment
+from alot.db.attachment import Attachment
from alot.db.errors import DatabaseROError
from alot.settings import settings
@@ -652,7 +652,7 @@ class OpenAttachmentCommand(Command):
def __init__(self, attachment, **kwargs):
"""
:param attachment: attachment to open
- :type attachment: :class:`~alot.message.Attachment`
+ :type attachment: :class:`~alot.db.attachment.Attachment`
"""
Command.__init__(self, **kwargs)
self.attachment = attachment
diff --git a/alot/db/envelope.py b/alot/db/envelope.py
index 4af1a05b..6572b507 100644
--- a/alot/db/envelope.py
+++ b/alot/db/envelope.py
@@ -11,7 +11,7 @@ import logging
import alot.helper as helper
from alot.settings import settings
-from message import Attachment
+from attachment import Attachment
from message import encode_header
@@ -29,7 +29,7 @@ class Envelope(object):
:param headers: unencoded header values
:type headers: dict (str -> unicode)
:param attachments: file attachments to include
- :type attachments: list of :class:`Attachment`
+ :type attachments: list of :class:`~alot.db.attachment.Attachment`
"""
assert isinstance(bodytext, unicode)
self.headers = {}
@@ -107,11 +107,11 @@ class Envelope(object):
"""
attach a file
- :param attachment: File to attach, given as :class:`Attachment` object
- or path to a file.
- :type attachment: :class:`Attachment` or str
+ :param attachment: File to attach, given as
+ :class:`~alot.db.attachment.Attachment` object or path to a file.
+ :type attachment: :class:`~alot.db.attachment.Attachment` or str
:param filename: filename to use in content-disposition.
- Will be ignored if `path` matches multiple files
+ Will be ignored if `path` matches multiple files
:param ctype: force content-type to be used for this attachment
:type ctype: str
"""
diff --git a/alot/db/message.py b/alot/db/message.py
index 08162379..54b72241 100644
--- a/alot/db/message.py
+++ b/alot/db/message.py
@@ -19,6 +19,7 @@ from alot.settings import settings
from alot.helper import string_sanitize
from alot.helper import string_decode
+from attachment import Attachment
class Message(object):
"""
@@ -400,70 +401,3 @@ def encode_header(key, value):
else:
value = Header(value)
return value
-
-
-class Attachment(object):
- """represents a mail attachment"""
-
- def __init__(self, emailpart):
- """
- :param emailpart: a non-multipart email that is the attachment
- :type emailpart: :class:`email.message.Message`
- """
- self.part = emailpart
-
- def __str__(self):
- desc = '%s:%s (%s)' % (self.get_content_type(),
- self.get_filename(),
- helper.humanize_size(self.get_size()))
- return string_decode(desc)
-
- def get_filename(self):
- """
- return name of attached file.
- If the content-disposition header contains no file name,
- this returns `None`
- """
- extracted_name = decode_header(self.part.get_filename())
- if extracted_name:
- return os.path.basename(extracted_name)
- return None
-
- def get_content_type(self):
- """mime type of the attachment part"""
- ctype = self.part.get_content_type()
- # replace underspecified mime description by a better guess
- if ctype in ['octet/stream', 'application/octet-stream']:
- ctype = helper.guess_mimetype(self.get_data())
- return ctype
-
- def get_size(self):
- """returns attachments size in bytes"""
- return len(self.part.get_payload())
-
- def save(self, path):
- """
- save the attachment to disk. Uses :meth:`get_filename` in case path
- is a directory
- """
- filename = self.get_filename()
- path = os.path.expanduser(path)
- if os.path.isdir(path):
- if filename:
- basename = os.path.basename(filename)
- FILE = open(os.path.join(path, basename), "w")
- else:
- FILE = tempfile.NamedTemporaryFile(delete=False, dir=path)
- else:
- FILE = open(path, "w") # this throws IOErrors for invalid path
- FILE.write(self.get_data())
- FILE.close()
- return FILE.name
-
- def get_data(self):
- """return data blob from wrapped file"""
- return self.part.get_payload(decode=True)
-
- def get_mime_representation(self):
- """returns mime part that constitutes this attachment"""
- return self.part
diff --git a/alot/widgets.py b/alot/widgets.py
index b07ae5f7..c81f685c 100644
--- a/alot/widgets.py
+++ b/alot/widgets.py
@@ -7,6 +7,7 @@ from alot.helper import pretty_datetime
from alot.helper import tag_cmp
from alot.helper import string_decode
import alot.db.message as message
+from alot.db.attachment import Attachment
import time
@@ -670,7 +671,7 @@ class MessageBodyWidget(urwid.AttrMap):
class AttachmentWidget(urwid.WidgetWrap):
"""
- one-line summary of an :class:`~alot.message.Attachment`.
+ one-line summary of an :class:`~alot.db.attachment.Attachment`.
Theme settings:
* `thread_attachment`
@@ -679,8 +680,8 @@ class AttachmentWidget(urwid.WidgetWrap):
def __init__(self, attachment, selectable=True):
self._selectable = selectable
self.attachment = attachment
- if not isinstance(attachment, message.Attachment):
- self.attachment = message.Attachment(self.attachment)
+ if not isinstance(attachment, Attachment):
+ self.attachment = Attachment(self.attachment)
att = settings.get_theming_attribute('thread', 'attachment')
focus_att = settings.get_theming_attribute('thread',
'attachment_focus')
diff --git a/docs/source/api/database.rst b/docs/source/api/database.rst
index 53fe803b..456ca31e 100644
--- a/docs/source/api/database.rst
+++ b/docs/source/api/database.rst
@@ -10,7 +10,7 @@ use an :class:`DBManager` instance to transparently provide persistent objects.
:class:`~alot.db.message.Message` moreover contains convenience methods
to extract information about the message like reformated header values, a summary,
-decoded and interpreted body text and a list of :class:`Attachments <alot.message.Attachment>`.
+decoded and interpreted body text and a list of :class:`Attachments <alot.db.attachment.Attachment>`.
The central :class:`~alot.ui.UI` instance carries around a :class:`DBManager` object that
is used for any lookups or modifications of the email base. :class:`DBManager` can
@@ -52,7 +52,7 @@ Wrapper
Other Structures
---------------------------
-.. autoclass:: Attachment
+.. autoclass:: alot.db.attachment.Attachment
:members:
.. autoclass:: alot.db.envelope.Envelope