Skip to content

Improve MeFilter #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions afew/filters/MeFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class MeFilter(Filter):
message = 'Tagging all mails sent directly to myself'
_bare_email_re = re.compile(r"[^<]*<(?P<email>[^@<>]+@[^@<>]+)>")

def __init__(self, database, me_tag='to-me', tags_blacklist=[]):
super().__init__(database, tags_blacklist=tags_blacklist)
def __init__(self, database, me_tag=None, **kwargs):
super().__init__(database, **kwargs)

my_addresses = set()
my_addresses.add(notmuch_settings.get('user', 'primary_email'))
Expand All @@ -23,8 +23,10 @@ def __init__(self, database, me_tag='to-me', tags_blacklist=[]):
self.query = ' OR '.join('to:"%s"' % address
for address in my_addresses)

self.me_tag = me_tag

def handle_message(self, message):
if not self._tag_blacklist.intersection(message.get_tags()):
self.add_tags(message, self.me_tag)
# The me_tag option does nothing that couldn't be done with the
# "normal" tags option. If the me_tag is explicitly configured or there
# is no tags option make use of it.
if not me_tag is None or (not self._tags_to_add and not self._tags_to_remove):
if me_tag is None:
me_tag = 'to-me'
self._tags_to_add.append(me_tag)
6 changes: 5 additions & 1 deletion docs/filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ MeFilter

Add filter tagging mail sent directly to any of addresses defined in
Notmuch config file: `primary_email` or `other_email`.
Default tag is `to-me` and can be customized with `me_tag` option.
Default tag action is `+to-me`.

(In the past there used to be advertised a `me_tag` option to overwrite the tag
to apply. The current code still handles it as it used to work, but usage is
discouraged.)

SentMailsFilter
---------------
Expand Down