summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-02-06 14:40:05 +0100
committerAnton Khirnov <anton@khirnov.net>2020-02-06 17:11:05 +0100
commit72ed7d40ac68d7e91f41e94fbcf6cb7a3e28433a (patch)
tree08395b57acf97a9aa83bb545645241259b9b28fb /alot
parent8b787ec521849cb854154857196734b7a298611e (diff)
db: drop useless getters
Diffstat (limited to 'alot')
-rw-r--r--alot/buffers/thread.py6
-rw-r--r--alot/commands/search.py3
-rw-r--r--alot/commands/thread.py12
-rw-r--r--alot/db/message.py43
-rw-r--r--alot/db/thread.py35
-rw-r--r--alot/widgets/search.py4
-rw-r--r--alot/widgets/thread.py10
7 files changed, 50 insertions, 63 deletions
diff --git a/alot/buffers/thread.py b/alot/buffers/thread.py
index 41766852..6434bb04 100644
--- a/alot/buffers/thread.py
+++ b/alot/buffers/thread.py
@@ -34,7 +34,7 @@ class ThreadBuffer(Buffer):
Buffer.__init__(self, ui, self.body)
def __str__(self):
- return '[thread] %s (%d message%s)' % (self.thread.get_subject(),
+ return '[thread] %s (%d message%s)' % (self.thread.subject,
self.message_count,
's' * (self.message_count > 1))
@@ -46,9 +46,9 @@ class ThreadBuffer(Buffer):
def get_info(self):
info = {}
- info['subject'] = self.thread.get_subject()
+ info['subject'] = self.thread.subject
info['authors'] = self.thread.get_authors_string()
- info['tid'] = self.thread.get_thread_id()
+ info['tid'] = self.thread.id
info['message_count'] = self.message_count
info['thread_tags'] = self.translated_tags_str()
info['intersection_tags'] = self.translated_tags_str(intersection=True)
diff --git a/alot/commands/search.py b/alot/commands/search.py
index 89012011..a2d598df 100644
--- a/alot/commands/search.py
+++ b/alot/commands/search.py
@@ -179,8 +179,7 @@ class TagCommand(Command):
testquery = searchbuffer.querystring
thread = threadline_widget.get_thread()
if not self.allm:
- testquery = "(%s) AND thread:%s" % (testquery,
- thread.get_thread_id())
+ testquery = "(%s) AND thread:%s" % (testquery, thread.id)
logging.debug('all? %s', self.allm)
logging.debug('q: %s', testquery)
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 28edaa84..9c79840f 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -140,7 +140,7 @@ class ReplyCommand(Command):
# set body text
name, address = parseaddr(mail['From'])
- timestamp = self.message.get_date()
+ timestamp = self.message.date
qf = settings.get_hook('reply_prefix')
if qf:
quotestring = qf(name, address, timestamp,
@@ -262,7 +262,7 @@ class ReplyCommand(Command):
envelope.add('Mail-Followup-To', decode_header(followupto))
# set In-Reply-To header
- envelope.add('In-Reply-To', '<%s>' % self.message.get_message_id())
+ envelope.add('In-Reply-To', '<%s>' % self.message.id)
# set References header
old_references = mail.get('References', '')
@@ -271,10 +271,10 @@ class ReplyCommand(Command):
references = old_references[-8:]
if len(old_references) > 8:
references = old_references[:1] + references
- references.append('<%s>' % self.message.get_message_id())
+ references.append('<%s>' % self.message.id)
envelope.add('References', ' '.join(references))
else:
- envelope.add('References', '<%s>' % self.message.get_message_id())
+ envelope.add('References', '<%s>' % self.message.id)
# continue to compose
encrypt = mail.get_content_subtype() == 'encrypted'
@@ -317,7 +317,7 @@ class ForwardCommand(Command):
if self.inline: # inline mode
# set body text
name, address = self.message.get_author()
- timestamp = self.message.get_date()
+ timestamp = self.message.date
qf = settings.get_hook('forward_prefix')
if qf:
quote = qf(name, address, timestamp,
@@ -693,7 +693,7 @@ class PipeCommand(Command):
logging.debug(self.output_format)
if self.output_format == 'id':
- pipestrings = [e.get_message_id() for e in to_print]
+ pipestrings = [e.id for e in to_print]
separator = '\n'
elif self.output_format == 'filepath':
pipestrings = [e.get_filename() for e in to_print]
diff --git a/alot/db/message.py b/alot/db/message.py
index ad9de9f4..0b59090d 100644
--- a/alot/db/message.py
+++ b/alot/db/message.py
@@ -29,6 +29,12 @@ class Message:
"""the :class:`~alot.db.Thread` this Message belongs to"""
thread = None
+ """value of the Date header value as :class:`~datetime.datetime`"""
+ date = None
+
+ """value of the Message-Id header (str)"""
+ id = None
+
def __init__(self, dbman, msg, thread):
"""
:param dbman: db manager that is used for further lookups
@@ -39,13 +45,12 @@ class Message:
:type thread: :class:`~alot.db.Thread`
"""
self._dbman = dbman
- self._id = msg.get_message_id()
- self._thread_id = msg.get_thread_id()
+ self.id = msg.get_message_id()
self.thread = thread
try:
- self._datetime = datetime.fromtimestamp(msg.get_date())
+ self.date = datetime.fromtimestamp(msg.get_date())
except ValueError:
- self._datetime = None
+ self.date = None
self._filename = msg.get_filename()
self._email = None # will be read upon first use
self._attachments = None # will be read upon first use
@@ -79,11 +84,11 @@ class Message:
def __hash__(self):
"""needed for sets of Messages"""
- return hash(self._id)
+ return hash(self.id)
def __eq__(self, other):
if isinstance(other, type(self)):
- return self._id == other.get_message_id()
+ return self.id == other.id
return NotImplemented
def get_email(self):
@@ -101,22 +106,10 @@ class Message:
warning, policy=email.policy.SMTP)
return self._email
- def get_date(self):
- """returns Date header value as :class:`~datetime.datetime`"""
- return self._datetime
-
def get_filename(self):
"""returns absolute path of message files location"""
return self._filename
- def get_message_id(self):
- """returns messages id (str)"""
- return self._id
-
- def get_thread_id(self):
- """returns id (str) of the thread this message belongs to"""
- return self._thread_id
-
def get_message_parts(self):
"""yield all body parts of this message"""
for msg in self.get_email().walk():
@@ -136,11 +129,9 @@ class Message:
:rtype: str
"""
- if self._datetime is None:
- res = None
- else:
- res = settings.represent_datetime(self._datetime)
- return res
+ if self.date is None:
+ return None
+ return settings.represent_datetime(self.date)
def get_author(self):
"""
@@ -176,7 +167,7 @@ class Message:
if callable(afterwards):
afterwards()
- self._dbman.tag('id:' + self._id, tags, afterwards=myafterwards,
+ self._dbman.tag('id:' + self.id, tags, afterwards=myafterwards,
remove_rest=remove_rest)
self._tags = self._tags.union(tags)
@@ -200,7 +191,7 @@ class Message:
if callable(afterwards):
afterwards()
- self._dbman.untag('id:' + self._id, tags, myafterwards)
+ self._dbman.untag('id:' + self.id, tags, myafterwards)
def get_attachments(self):
"""
@@ -245,5 +236,5 @@ class Message:
def matches(self, querystring):
"""tests if this messages is in the resultset for `querystring`"""
- searchfor = '( {} ) AND id:{}'.format(querystring, self._id)
+ searchfor = '( {} ) AND id:{}'.format(querystring, self.id)
return self._dbman.count_messages(searchfor) > 0
diff --git a/alot/db/thread.py b/alot/db/thread.py
index 9284d076..bae48b1a 100644
--- a/alot/db/thread.py
+++ b/alot/db/thread.py
@@ -30,6 +30,12 @@ class Thread:
"""number of contained messages"""
total_messages = None
+ """This thread's ID"""
+ id = None
+
+ """Thread subject"""
+ subject = None
+
def __init__(self, dbman, thread):
"""
:param dbman: db manager that is used for further lookups
@@ -39,7 +45,7 @@ class Thread:
"""
self._dbman = dbman
self._authors = None
- self._id = thread.get_thread_id()
+ self.id = thread.get_thread_id()
self._messages = {}
self._tags = set()
@@ -48,7 +54,7 @@ class Thread:
def refresh(self, thread=None):
"""refresh thread metadata from the index"""
if not thread:
- thread = self._dbman._get_notmuch_thread(self._id)
+ thread = self._dbman._get_notmuch_thread(self.id)
self.total_messages = thread.get_total_messages()
self._notmuch_authors_string = thread.get_authors()
@@ -62,7 +68,7 @@ class Thread:
subject = first_msg.get_header('subject')
except IndexError:
subject = ''
- self._subject = subject
+ self.subject = subject
self._authors = None
ts = thread.get_oldest_date()
@@ -82,11 +88,7 @@ class Thread:
self._toplevel_messages = []
def __str__(self):
- return "thread:%s: %s" % (self._id, self.get_subject())
-
- def get_thread_id(self):
- """returns id of this thread"""
- return self._id
+ return "thread:%s: %s" % (self.id, self.subject)
def get_tags(self, intersection=False):
"""
@@ -130,7 +132,7 @@ class Thread:
if callable(afterwards):
afterwards()
- self._dbman.tag('thread:' + self._id, tags, afterwards=myafterwards,
+ self._dbman.tag('thread:' + self.id, tags, afterwards=myafterwards,
remove_rest=remove_rest)
def remove_tags(self, tags, afterwards=None):
@@ -157,7 +159,7 @@ class Thread:
self._tags = self._tags.difference(tags)
if callable(afterwards):
afterwards()
- self._dbman.untag('thread:' + self._id, tags, myafterwards)
+ self._dbman.untag('thread:' + self.id, tags, myafterwards)
self._tags = self._tags.difference(rmtags)
def get_authors(self):
@@ -171,7 +173,7 @@ class Thread:
# Sort messages with date first (by date ascending), and those
# without a date last.
msgs = sorted(self.get_messages().keys(),
- key=lambda m: m.get_date() or datetime.max)
+ key=lambda m: m.date or datetime.max)
orderby = settings.get('thread_authors_order_by')
self._authors = []
@@ -220,10 +222,6 @@ class Thread:
else:
return self._notmuch_authors_string
- def get_subject(self):
- """returns subject string"""
- return self._subject
-
def get_toplevel_messages(self):
"""
returns all toplevel messages contained in this thread.
@@ -245,7 +243,7 @@ class Thread:
:class:`~alot.db.message.Message`.
"""
if not self._messages: # if not already cached
- query = self._dbman.query('thread:' + self._id)
+ query = self._dbman.query('thread:' + self.id)
thread = next(query.search_threads())
def accumulate(acc, msg):
@@ -270,10 +268,9 @@ class Thread:
:type msg: :class:`~alot.db.message.Message`
:returns: list of :class:`~alot.db.message.Message` or `None`
"""
- mid = msg.get_message_id()
msg_hash = self.get_messages()
for m in msg_hash.keys():
- if m.get_message_id() == mid:
+ if m.id == msg.id:
return msg_hash[m]
return None
@@ -286,7 +283,7 @@ class Thread:
:returns: True if this thread matches the given query, False otherwise
:rtype: bool
"""
- thread_query = 'thread:{tid} AND {subquery}'.format(tid=self._id,
+ thread_query = 'thread:{tid} AND {subquery}'.format(tid=self.id,
subquery=query)
num_matches = self._dbman.count_messages(thread_query)
return num_matches > 0
diff --git a/alot/widgets/search.py b/alot/widgets/search.py
index 51048394..a4d22e82 100644
--- a/alot/widgets/search.py
+++ b/alot/widgets/search.py
@@ -178,12 +178,12 @@ def prepare_authors_string(thread):
def prepare_subject_string(thread):
- return thread.get_subject() or ' '
+ return thread.subject or ' '
def prepare_content_string(thread):
msgs = sorted(thread.get_messages().keys(),
- key=lambda msg: msg.get_date(), reverse=True)
+ key=lambda msg: msg.date, reverse=True)
lastcontent = ' '.join(m.get_body_text() for m in msgs)
lastcontent = lastcontent.replace('^>.*$', '')
return lastcontent
diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py
index d87a881a..47034bfe 100644
--- a/alot/widgets/thread.py
+++ b/alot/widgets/thread.py
@@ -332,7 +332,7 @@ class ThreadTree(Tree):
"""
def __init__(self, thread):
self._thread = thread
- self.root = thread.get_toplevel_messages()[0].get_message_id()
+ self.root = thread.get_toplevel_messages()[0].id
self._parent_of = {}
self._first_child_of = {}
self._last_child_of = {}
@@ -342,13 +342,13 @@ class ThreadTree(Tree):
def accumulate(msg, odd=True):
"""recursively read msg and its replies"""
- mid = msg.get_message_id()
+ mid = msg.id
self._message[mid] = MessageTree(msg, odd)
odd = not odd
last = None
self._first_child_of[mid] = None
for reply in thread.get_replies_to(msg):
- rid = reply.get_message_id()
+ rid = reply.id
if self._first_child_of[mid] is None:
self._first_child_of[mid] = rid
self._parent_of[rid] = mid
@@ -361,7 +361,7 @@ class ThreadTree(Tree):
last = None
for msg in thread.get_toplevel_messages():
- mid = msg.get_message_id()
+ mid = msg.id
self._prev_sibling_of[mid] = last
self._next_sibling_of[last] = mid
accumulate(msg)
@@ -389,4 +389,4 @@ class ThreadTree(Tree):
@staticmethod
def position_of_messagetree(mt):
- return mt._message.get_message_id()
+ return mt._message.id