From 20f299ed36c7f6c9c29490504a3c7f71df91f901 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Mon, 11 Mar 2019 10:52:20 +0100 Subject: [PATCH] use afew for tagging --- config/afew/config | 29 +++++++++ config/afew/only_contacts.py | 33 ++++++++++ config/afew/spam_filter.py | 118 +++++++++++++++++++++++++++++++++++ config/alot/config | 8 +-- notmuch-config | 7 ++- notmuch-hooks/post-new | 10 +-- 6 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 config/afew/config create mode 100644 config/afew/only_contacts.py create mode 100644 config/afew/spam_filter.py diff --git a/config/afew/config b/config/afew/config new file mode 100644 index 0000000..c5e648d --- /dev/null +++ b/config/afew/config @@ -0,0 +1,29 @@ +[TagOrContact.1] +query = to:felixvdj.*@posteo.be OR to:felix.vanderjeugt.*@posteo.net + +[Filter.1] +message = Tag messages to my UGent account +query = to:felix.vanderjeugt@ugent.be +tags = +ugent + +[Filter.2] +message = Tag messages to my Zeus account +query = to:felixvdj@zeus.ugent.be +tags = +zeus + +[Filter.3] +message = The Dodona alias +query = to:dodona@ugent.be +tags = +dodona + +[Filter.4] +message = The Unipept alias +query = to:unipept@ugent.be +tags = +unipept + +[ListMailsFilter] + +[Filter.0] +message = Add all new messages to the inbox +query = tag:new +tags = +unread;-new diff --git a/config/afew/only_contacts.py b/config/afew/only_contacts.py new file mode 100644 index 0000000..ca08dad --- /dev/null +++ b/config/afew/only_contacts.py @@ -0,0 +1,33 @@ +from afew.filters.BaseFilter import Filter +from afew.FilterRegistry import register_filter + +from khard.config import Config + +import re + +@register_filter +class TagOrContact(Filter): + message = 'Allow only tagged messages from non-contacts' + user = None + domain = None + + def __init__(self, database, **kwargs): + super(TagOrContact, self).__init__(database, **kwargs) + self._extract_tag_re = re.compile(f'[^+]+(\+(?P[^@]+))?@[^@]+') + self._bare_email_re = re.compile(r'[^<]*<(?P[^@<>]+@[^@<>]+)>') + self._contactbook = Config().abook + + def handle_message(self, message): + recipient = message.get_header('Delivered-To') + match = self._extract_tag_re.fullmatch(recipient) + if match is None: return # wrong email + + if match.group('tag'): + self.add_tags(message, match['tag']) + else: + sender = message.get_header('From') + if '<' in sender: sender = self._bare_email_re.fullmatch(sender)['email'] + if self._contactbook.search(sender): + self.add_tags(message, 'contact') + else: + self.add_tags(message, 'killed') diff --git a/config/afew/spam_filter.py b/config/afew/spam_filter.py new file mode 100644 index 0000000..8dcc1b0 --- /dev/null +++ b/config/afew/spam_filter.py @@ -0,0 +1,118 @@ +from afew.filters.BaseFilter import Filter +from afew.FilterRegistry import register_filter + +spammers = """ +hbguirui.net +foodcongress2019.com +congresssummit.com +icmsquare.net +austinpublishinggroup.us +hindawi.com +internationalmeeting.org +openaccessusa.com +journal.aoam.email +mailpanda.com +scientificres.org +scifedconferences.com +insightmeetings.net +wgc-2019.com +intopenaccess.com +walla.co.il +innofine.in +escientificres.com +xceptdom.com +aoam.info +cambridgescholars.com +mra-journal.org +jimsindia.org +service.cyagenbio.com +oatext-alerts.net +2019ibc.com +eclinmed.org +innovationinfo.net +intechopen.com +neurologyspeakerexperts.org +conferencesinternational.org +oap-lifescience.org +synpeptide.com.cn +americaseminars.com +oatextjournals.com +connectcyagen.com +oatjournals.com +meetingsintl.com +scientglobal.org +research101.site +biochemistryjournals.org +functionalfoodcenter.com +bio-congress.com +oatext-news.org +ptzjournals.com +glazovsky.co.ua +wcfnconference2018.com +iacrlrd2019.com +scientificfederation.com +journalres.org +bangng.org +eurosciconmeetings.com +renecon.eu +kebiochem.cn +reg-med2018.com +edelweisspublications.info +ibc-congress.com +sciencescholastic.com +journals.hindawi.com +bioevents.net +clinicalopenaccess.org +easummit.net +networkwithexpert.com +cmcb2019.com +eursciconevent.com +cmedu.org +oatextjournal.info +alliedinternational.org +kingfisherbiotech.com +meettheglobalexpert.com +tonirovany.biz.ua +doveproofreading.com +clinicalcasereports.editor@protonmail.ch +scireslitoa.com +academiapublishing.org +editorialscience.org +pepcon-2019.com +oap-journals.net +klserv.com +keimra.org +oap-cancer.org +cmcb-2019.com +rebuilding-the-raindrops.ovh +gavinconferences.org +iwbbio.org +usp-pl.net +biochemjournals.com +sophia.isabella010@yahoo.com +aimspress6.com +proteinresearch.website +linkinscience.com +esciencemedicine.com +cellmech-bio2018.com +oap-journals.org +sara.wallner78@gmail.com +evajones290@gmail.com +news.caister.com +scientificfederation.info +imrjournal.email +oap-journals.com +frontiermeetings.com +submitresearch.online +editor.factor21@daum.net +""" + +@register_filter +class KnownSpammers(Filter): + + def __init__(self, database, **kwargs): + super(KnownSpammers, self).__init__(database, **kwargs) + self.query = ' or '.join(f'from:{s}' for s in spammers.split('\n') if s) + + def handle_message(self, message): + self.add_tags(message, 'spam') diff --git a/config/alot/config b/config/alot/config index ac124ee..3c9f945 100644 --- a/config/alot/config +++ b/config/alot/config @@ -1,5 +1,5 @@ -initial_command = search NOT tag:killed AND NOT tag:archived +initial_command = search not tag:archived periodic_hook_frequency = 60 attachment_prefix = /data/temporary @@ -11,8 +11,8 @@ editor_cmd = "dvtm 'vis %s'" [[posteo]] realname = Felix Van der Jeugt address = felix.vanderjeugt@posteo.net - aliases = felixvdj@zeus.ugent.be - alias_regexp = felix\.vanderjeugt\+.+@posteo.net + aliases = felixvdj@zeus.ugent.be, ninewise@posteo.be + alias_regexp = (felix\.vanderjeugt\+.+@posteo.net|felixvdj\+.+@posteo\.be) gpg_key = 68FF561137C38F9618E97339AF25A2C2862AA368 sendmail_command = /usr/bin/msmtp --account=posteo -t sent_box = maildir:///data/mail/posteo/Sent @@ -65,7 +65,7 @@ editor_cmd = "dvtm 'vis %s'" t = toggletags selected; move down [[search]] - x = tag killed + x = tag spam a = tag archived A = untag archived diff --git a/notmuch-config b/notmuch-config index 7db4fbd..7fa1175 100644 --- a/notmuch-config +++ b/notmuch-config @@ -48,7 +48,7 @@ other_email=felix.vanderjeugt@ugent.be;felix.vanderjeugt@gmail.com # in the mail store. # [new] -tags=unread;new; +tags=new; ignore= # Search configuration @@ -61,7 +61,7 @@ ignore= # query will override that exclusion. # [search] -exclude_tags=killed;deleted;spam; +exclude_tags=spam; # Maildir compatibility configuration # @@ -86,3 +86,6 @@ exclude_tags=killed;deleted;spam; # [maildir] synchronize_flags=true + +[query] +inbox=not tag:spam and not tag:archived diff --git a/notmuch-hooks/post-new b/notmuch-hooks/post-new index 174cb25..1571135 100755 --- a/notmuch-hooks/post-new +++ b/notmuch-hooks/post-new @@ -1,11 +1,11 @@ #!/bin/sh -# some filtering -notmuch tag +killed -new -unread -- subject:'^[SPAM]' to:ugent +# filtering spam +afew --tag --new -e SpamFilter,KnownSpammers +notmuch tag -new -- tag:spam and tag:new # notify for new messages notmuch search tag:new | cut -d' ' --complement -f1 | xargs -0 --no-run-if-empty notify-send -# processed new messages are no longer new -notmuch tag -new -- tag:new - +# tagging messages +afew --tag --new