afew is too complex after all
This commit is contained in:
parent
5952693319
commit
1ce49693dd
@ -1,31 +0,0 @@
|
||||
[FolderNameFilter]
|
||||
folder_blacklist = Inbox Sent Drafts Trash
|
||||
maildir_separator = /
|
||||
|
||||
[SpamFilter]
|
||||
[KnownSpammers]
|
||||
|
||||
[TagOrContact.1]
|
||||
query = tag:posteo
|
||||
|
||||
[Filter.1]
|
||||
message = Tag messages to my Zeus account
|
||||
query = to:felixvdj@zeus.ugent.be
|
||||
tags = +zeus
|
||||
|
||||
[Filter.2]
|
||||
message = The Dodona alias
|
||||
query = to:dodona@ugent.be
|
||||
tags = +dodona
|
||||
|
||||
[Filter.3]
|
||||
message = The Unipept alias
|
||||
query = to:unipept@ugent.be
|
||||
tags = +unipept
|
||||
|
||||
[Filter.4]
|
||||
query = tag:dodona and subject:'Onderwijsinstelling aangemaakt voor .*'
|
||||
tags = -new
|
||||
|
||||
[ListMailsFilter]
|
||||
[InboxFilter]
|
@ -1,33 +0,0 @@
|
||||
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<tag>[^@]+))?@[^@]+')
|
||||
self._bare_email_re = re.compile(r'[^<]*<(?P<email>[^@<>]+@[^@<>]+)>')
|
||||
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')
|
@ -1,7 +1,4 @@
|
||||
from afew.filters.BaseFilter import Filter
|
||||
from afew.FilterRegistry import register_filter
|
||||
|
||||
spammers = """
|
||||
bio-congress.com
|
||||
golbalpublication.online
|
||||
all.bg
|
||||
vodokanal.poltava.ua
|
||||
@ -155,15 +152,3 @@ 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')
|
||||
self.remove_tags(message, 'new')
|
@ -1,4 +1,61 @@
|
||||
#!/bin/sh
|
||||
|
||||
afew --tag --new
|
||||
notmuch search tag:unread | cut -d' ' --complement -f1 | xargs -0 --no-run-if-empty notify-send
|
||||
addtag() { notmuch tag +"$1" -- "tag:new and ($2) and not tag:$1"; }
|
||||
archive() { notmuch tag -new -unread -- "$@" and tag:new; }
|
||||
spam() { notmuch tag -new -unread +spam -- "$@" and '(' tag:new or tag:unread or not tag:spam ')'; }
|
||||
|
||||
# Tag mails by their origin (top-level maildir)
|
||||
for maildir in /data/mail/*; do
|
||||
origin="$(basename "$maildir")"
|
||||
addtag "$origin" "folder:/$origin/"
|
||||
done
|
||||
|
||||
# Spam
|
||||
spam "subject:/^\[SPAM\]/"
|
||||
# TODO: Known spammers
|
||||
|
||||
# Some aliases
|
||||
addtag zeus "to:felixvdj@zeus.ugent.be"
|
||||
addtag dodona "to:dodona@ugent.be"
|
||||
addtag unipept "to:unipept@ugent.be"
|
||||
|
||||
# More complex tagging
|
||||
for mid in $(notmuch search --output=messages tag:new); do
|
||||
|
||||
tag=false
|
||||
|
||||
# +-tags become actual tags
|
||||
for tag in $(notmuch show --format=raw "$mid" | sed -n '/^\tfor/s/.*<[^>]*+\([^@]*\)@.*>.*/\1/p' | sort | uniq); do
|
||||
addtag "$tag" "$mid"
|
||||
tag=true
|
||||
done
|
||||
|
||||
# messages from contacts get a contact tag
|
||||
for sender in $(notmuch address --output=sender --output=address "$mid"); do
|
||||
if khard list "$sender" > /dev/null 2>&1; then
|
||||
addtag contact "$mid"
|
||||
tag=true
|
||||
fi
|
||||
done
|
||||
|
||||
# mails to posteo must have a tag
|
||||
if ! "$tag"; then
|
||||
addtag killed "$mid and tag:posteo"
|
||||
fi
|
||||
|
||||
# list ids
|
||||
for list in $(notmuch show --format=raw "$mid" | sed -n '/^List-Id:/,/^\w/p' | sed '$d' | tr '\n' ' ' | sed 's/[^<]*<// ; s/\..*//'); do
|
||||
addtag "lists" "$mid"
|
||||
addtag "lists/$list" "$mid"
|
||||
done
|
||||
done
|
||||
|
||||
# Uninteresting
|
||||
archive tag:dodona and subject:'Onderwijsinstelling aangemaakt voor .*'
|
||||
|
||||
# Notify about new messages
|
||||
notmuch search tag:new | cut -d' ' --complement -f1 | xargs -0 --no-run-if-empty notify-send
|
||||
|
||||
# Inbox remaining not-spam
|
||||
addtag inbox "not tag:spam"
|
||||
notmuch tag -new -- tag:new
|
||||
|
Loading…
Reference in New Issue
Block a user