]> git.notmuchmail.org Git - notmuch/blobdiff - bindings/python/notmuch/message.py
python: fix docstring of Message.get_header()
[notmuch] / bindings / python / notmuch / message.py
index 435a05db3400225fa143c60b9ab9919c9a0f30ac..4bf90c22f9bb62fbfe3c4bef1c69b7a2cb72da36 100644 (file)
@@ -21,7 +21,7 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
 
 from ctypes import c_char_p, c_void_p, c_long, c_uint, c_int
 from datetime import date
-from notmuch.globals import nmlib, STATUS, NotmuchError, Enum
+from notmuch.globals import nmlib, STATUS, NotmuchError, Enum, _str
 from notmuch.tag import Tags
 from notmuch.filename import Filenames
 import sys
@@ -115,7 +115,7 @@ class Messages(object):
                the Python object.(?)
         """
         if msgs_p is None:
-            NotmuchError(STATUS.NULL_POINTER)
+            raise NotmuchError(STATUS.NULL_POINTER)
 
         self._msgs = msgs_p
         #store parent, so we keep them alive as long as self  is alive
@@ -187,7 +187,7 @@ class Messages(object):
             set_end = "]"
             set_sep = ", "
         else:
-            raise Exception
+            raise TypeError("format must be either 'text' or 'json'")
 
         first_set = True
 
@@ -208,10 +208,8 @@ class Messages(object):
             if (match or entire_thread):
                 if format.lower() == "text":
                     sys.stdout.write(msg.format_message_as_text(indent))
-                elif format.lower() == "json":
-                    sys.stdout.write(msg.format_message_as_json(indent))
                 else:
-                    raise NotmuchError
+                    sys.stdout.write(msg.format_message_as_json(indent))
                 next_indent = indent + 1
 
             # get replies and print them also out (if there are any)
@@ -292,7 +290,7 @@ class Message(object):
               objects are dead.
         """
         if msg_p is None:
-            NotmuchError(STATUS.NULL_POINTER)
+            raise NotmuchError(STATUS.NULL_POINTER)
         self._msg = msg_p
         #keep reference to parent, so we keep it alive
         self._parent = parent
@@ -371,22 +369,23 @@ class Message(object):
         return Message._get_date(self._msg)
 
     def get_header(self, header):
-        """Returns a message header
+        """Get the value of the specified header.
 
-        This returns any message header that is stored in the notmuch database.
-        This is only a selected subset of headers, which is currently:
+        The value will be read from the actual message file, not from
+        the notmuch database. The header name is case insensitive.
 
-          TODO: add stored headers
+        Returns an empty string ("") if the message does not contain a
+        header line matching 'header'.
 
         :param header: The name of the header to be retrieved.
-                       It is not case-sensitive (TODO: confirm).
+                       It is not case-sensitive.
         :type header: str
         :returns: The header value as string
         :exception: :exc:`NotmuchError`
 
                     * STATUS.NOT_INITIALIZED if the message
                       is not initialized.
-                    * STATUS.NULL_POINTER, if no header was found
+                    * STATUS.NULL_POINTER if any error occured.
         """
         if self._msg is None:
             raise NotmuchError(STATUS.NOT_INITIALIZED)
@@ -395,7 +394,7 @@ class Message(object):
         header = Message._get_header(self._msg, header)
         if header == None:
             raise NotmuchError(STATUS.NULL_POINTER)
-        return header
+        return header.decode('UTF-8')
 
     def get_filename(self):
         """Returns the file path of the message file
@@ -505,7 +504,7 @@ class Message(object):
         if self._msg is None:
             raise NotmuchError(STATUS.NOT_INITIALIZED)
 
-        status = nmlib.notmuch_message_add_tag(self._msg, tag)
+        status = nmlib.notmuch_message_add_tag(self._msg, _str(tag))
 
         # bail out on failure
         if status != STATUS.SUCCESS:
@@ -549,7 +548,7 @@ class Message(object):
         if self._msg is None:
             raise NotmuchError(STATUS.NOT_INITIALIZED)
 
-        status = nmlib.notmuch_message_remove_tag(self._msg, tag)
+        status = nmlib.notmuch_message_remove_tag(self._msg, _str(tag))
         # bail out on error
         if status != STATUS.SUCCESS:
             raise NotmuchError(status)
@@ -747,7 +746,7 @@ class Message(object):
         """A message() is represented by a 1-line summary"""
         msg = {}
         msg['from'] = self.get_header('from')
-        msg['tags'] = str(self.get_tags())
+        msg['tags'] = self.get_tags()
         msg['date'] = date.fromtimestamp(self.get_date())
         return "%(from)s (%(date)s) (%(tags)s)" % (msg)