Skip to content
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

Add filter tagging mail sent directly to me #169

Merged
merged 1 commit into from
Nov 26, 2017
Merged
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
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