]> git.notmuchmail.org Git - notmuch/blobdiff - bindings/python/notmuch/message.py
errors='ignore' when decode to unicode
[notmuch] / bindings / python / notmuch / message.py
index e0c7eda2b46d492cd37cc6a8712c6db6e5a88a03..f95e50e284c5124d0a3e6d37bc0d942e684ccf68 100644 (file)
@@ -19,7 +19,7 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
 """
 
 
-from ctypes import c_char_p, c_void_p, c_long, c_uint, c_int
+from ctypes import c_char_p, c_long, c_uint, c_int
 from datetime import date
 from notmuch.globals import (nmlib, STATUS, NotmuchError, Enum, _str,
     NotmuchTagsP, NotmuchMessagesP, NotmuchMessageP, NotmuchFilenamesP)
@@ -27,7 +27,6 @@ from notmuch.tag import Tags
 from notmuch.filename import Filenames
 import sys
 import email
-import types
 try:
     import simplejson as json
 except ImportError:
@@ -128,10 +127,12 @@ class Messages(object):
         """Return the unique :class:`Tags` in the contained messages
 
         :returns: :class:`Tags`
-        :exceptions: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if not inited
+        :exceptions: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if not init'ed
 
-        .. note:: :meth:`collect_tags` will iterate over the messages and
-          therefore will not allow further iterations.
+        .. note::
+
+            :meth:`collect_tags` will iterate over the messages and therefore
+            will not allow further iterations.
         """
         if self._msgs is None:
             raise NotmuchError(STATUS.NOT_INITIALIZED)
@@ -359,14 +360,15 @@ class Message(object):
         """Gets all direct replies to this message as :class:`Messages`
         iterator
 
-        .. note:: This call only makes sense if 'message' was
-          ultimately obtained from a :class:`Thread` object, (such as
-          by coming directly from the result of calling
-          :meth:`Thread.get_toplevel_messages` or by any number of
-          subsequent calls to :meth:`get_replies`). If this message was
-          obtained through some non-thread means, (such as by a call
-          to :meth:`Query.search_messages`), then this function will
-          return `None`.
+        .. note::
+
+            This call only makes sense if 'message' was ultimately obtained from
+            a :class:`Thread` object, (such as by coming directly from the
+            result of calling :meth:`Thread.get_toplevel_messages` or by any
+            number of subsequent calls to :meth:`get_replies`). If this message
+            was obtained through some non-thread means, (such as by a call to
+            :meth:`Query.search_messages`), then this function will return
+            `None`.
 
         :returns: :class:`Messages` or `None` if there are no replies to
             this message.
@@ -425,7 +427,7 @@ class Message(object):
         header = Message._get_header(self._msg, header)
         if header == None:
             raise NotmuchError(STATUS.NULL_POINTER)
-        return header.decode('UTF-8')
+        return header.decode('UTF-8', errors='ignore')
 
     def get_filename(self):
         """Returns the file path of the message file
@@ -647,7 +649,7 @@ class Message(object):
 
         This means that changes to the message state, (via :meth:`add_tag`,
         :meth:`remove_tag`, and :meth:`remove_all_tags`), will not be
-        committed to the database until the message is :meth:`thaw`ed.
+        committed to the database until the message is :meth:`thaw` ed.
 
         Multiple calls to freeze/thaw are valid and these calls will
         "stack". That is there must be as many calls to thaw as to freeze
@@ -756,11 +758,11 @@ class Message(object):
         not work yet, as the modified tags have not been committed yet
         to the database.
 
-        :returns: a :class:`STATUS`. In short, you want to see
+        :returns: a :class:`STATUS` value. In short, you want to see
             notmuch.STATUS.SUCCESS here. See there for details."""
         if self._msg is None:
             raise NotmuchError(STATUS.NOT_INITIALIZED)
-        status = Message._tags_to_maildir_flags(self._msg)
+        return Message._tags_to_maildir_flags(self._msg)
 
     def maildir_flags_to_tags(self):
         """Synchronize file Maildir flags to notmuch tags
@@ -787,19 +789,21 @@ class Message(object):
             notmuch.STATUS.SUCCESS here. See there for details."""
         if self._msg is None:
             raise NotmuchError(STATUS.NOT_INITIALIZED)
-        status = Message._tags_to_maildir_flags(self._msg)
+        return Message._tags_to_maildir_flags(self._msg)
 
     def __repr__(self):
         """Represent a Message() object by str()"""
         return self.__str__()
 
     def __str__(self):
-        """A message() is represented by a 1-line summary"""
-        msg = {}
-        msg['from'] = self.get_header('from')
-        msg['tags'] = self.get_tags()
-        msg['date'] = date.fromtimestamp(self.get_date())
-        return "%(from)s (%(date)s) (%(tags)s)" % (msg)
+        return unicode(self).encode('utf-8')
+
+    def __unicode__(self):
+        format = "%(from)s (%(date)s) (%(tags)s)"
+        return format % (self.get_header('from'),
+                         self.get_tags(),
+                         date.fromtimestamp(self.get_date()),
+                        )
 
     def get_message_parts(self):
         """Output like notmuch show"""