X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=bindings%2Fpython%2Fnotmuch%2Fmessage.py;h=245e814806a55f002b9fe49b96583de5e531b863;hb=83b256b12be25b29f915587342b5ccb139864268;hp=6ee5ec95e0bae524ba54f453f87335dad64da5eb;hpb=ecf8da35e26a899286797a65ce1e36f9600af250;p=notmuch diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py index 6ee5ec95..245e8148 100644 --- a/bindings/python/notmuch/message.py +++ b/bindings/python/notmuch/message.py @@ -21,7 +21,8 @@ Copyright 2010 Sebastian Spaeth ' 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, +from notmuch.globals import ( + nmlib, STATUS, NotmuchError, Enum, _str, Python3StringMixIn, NotmuchTagsP, NotmuchMessagesP, NotmuchMessageP, NotmuchFilenamesP) from notmuch.tag import Tags from notmuch.filename import Filenames @@ -158,7 +159,7 @@ class Messages(object): _move_to_next.argtypes = [NotmuchMessagesP] _move_to_next.restype = None - def next(self): + def __next__(self): if self._msgs is None: raise NotmuchError(STATUS.NOT_INITIALIZED) @@ -169,6 +170,7 @@ class Messages(object): msg = Message(Messages._get(self._msgs), self) self._move_to_next(self._msgs) return msg + next = __next__ # python2.x iterator protocol compatibility def __nonzero__(self): """ @@ -238,7 +240,7 @@ class Messages(object): sys.stdout.write(set_end) -class Message(object): +class Message(Python3StringMixIn): """Represents a single Email message Technically, this wraps the underlying *notmuch_message_t* @@ -336,7 +338,7 @@ class Message(object): """ if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) - return Message._get_message_id(self._msg) + return Message._get_message_id(self._msg).decode('utf-8', errors='ignore') def get_thread_id(self): """Returns the thread ID @@ -354,7 +356,7 @@ class Message(object): if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) - return Message._get_thread_id(self._msg) + return Message._get_thread_id(self._msg).decode('utf-8', errors='ignore') def get_replies(self): """Gets all direct replies to this message as :class:`Messages` @@ -424,10 +426,10 @@ class Message(object): raise NotmuchError(STATUS.NOT_INITIALIZED) #Returns NULL if any error occurs. - header = Message._get_header(self._msg, header) + header = Message._get_header(self._msg, _str(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 @@ -438,7 +440,7 @@ class Message(object): """ if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) - return Message._get_filename(self._msg) + return Message._get_filename(self._msg).decode('utf-8', errors='ignore') def get_filenames(self): """Get all filenames for the email corresponding to 'message' @@ -795,13 +797,12 @@ class Message(object): """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) + def __unicode__(self): + format = "%s (%s) (%s)" + return format % (self.get_header('from'), + self.get_tags(), + date.fromtimestamp(self.get_date()), + ) def get_message_parts(self): """Output like notmuch show"""