Skip to content

Commit

Permalink
Merge pull request #169 from aidecoe/me-filter
Browse files Browse the repository at this point in the history
Add filter tagging mail sent directly to me
  • Loading branch information
GuillaumeSeren authored Nov 26, 2017
2 parents 27237fd + bd27830 commit 355eaca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions afew/filters/MeFilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# coding=utf-8
from __future__ import print_function, absolute_import, unicode_literals

#
# Copyright (c) Amadeusz Zolnowski <aidecoe@aidecoe.name>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

import re

from ..utils import filter_compat
from .BaseFilter import Filter
from ..NotmuchSettings import notmuch_settings


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'):
super(MeFilter, self).__init__(database)

my_addresses = set()
my_addresses.add(notmuch_settings.get('user', 'primary_email'))
if notmuch_settings.has_option('user', 'other_email'):
other_emails = notmuch_settings.get('user', 'other_email').split(';')
my_addresses.update(filter_compat(None, other_emails))

self.query = ' OR '.join('to:"%s"' % address
for address in my_addresses)

self.me_tag = me_tag

def handle_message(self, message):
self.add_tags(message, self.me_tag)
1 change: 1 addition & 0 deletions afew/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_all_builtin_FilterRegistrys_exist(self):
'SpamFilter',
'Filter',
'KillThreadsFilter',
'MeFilter',
'SentMailsFilter',
'HeaderMatchingFilter',
'ListMailsFilter']),
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_requires():
'InboxFilter = afew.filters.InboxFilter:InboxFilter',
'KillThreadsFilter = afew.filters.KillThreadsFilter:KillThreadsFilter',
'ListMailsFilter = afew.filters.ListMailsFilter:ListMailsFilter',
'MeFilter = afew.filters.MeFilter:MeFilter',
'SentMailsFilter = afew.filters.SentMailsFilter:SentMailsFilter',
'SpamFilter = afew.filters.SpamFilter:SpamFilter',
],
Expand Down

0 comments on commit 355eaca

Please sign in to comment.