From 3915f133fd04c8e0e8c89146d8dbf02924784cf6 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Sat, 14 Nov 2020 14:36:43 +0100 Subject: [PATCH] Rename inbox to flag to sync it and bogofilter spam --- config/alot/config | 22 +++++++++++----------- config/alot/hooks.py | 8 ++++---- local/bin/spam | 24 +++++++++++------------- notmuch-config | 2 +- notmuch-hooks/post-new | 21 ++++++++++++++------- profile | 1 + 6 files changed, 42 insertions(+), 36 deletions(-) diff --git a/config/alot/config b/config/alot/config index 887c1dc..77bcd99 100644 --- a/config/alot/config +++ b/config/alot/config @@ -1,5 +1,5 @@ -initial_command = search tag:inbox +initial_command = search tag:flagged periodic_hook_frequency = 60 edit_headers_blacklist = Content-Type, MIME-Version attachment_prefix = /data/temporary @@ -21,7 +21,7 @@ theme = "mutt" sendmail_command = /usr/bin/msmtp --account=posteo -t sent_box = maildir:///data/mail/posteo/Sent draft_box = maildir:///data/mail/posteo/Drafts - sent_tags = posteo,inbox + sent_tags = posteo,flagged passed_tags = # none sign_by_default = False @@ -38,7 +38,7 @@ theme = "mutt" sendmail_command = /usr/bin/msmtp --account=gmail -t sent_box = maildir:///data/mail/gmail/Sent draft_box = maildir:///data/mail/gmail/Sent - sent_tags = gmail,inbox + sent_tags = gmail,flagged passed_tags = # none sign_by_default = True @@ -56,7 +56,7 @@ theme = "mutt" sendmail_command = /usr/bin/msmtp --account=ugent -t sent_box = maildir:///data/mail/ugent/Sent draft_box = maildir:///data/mail/ugent/Sent - sent_tags = ugent,inbox + sent_tags = ugent,flagged passed_tags = # none sign_by_default = True @@ -72,7 +72,7 @@ theme = "mutt" sendmail_command = true sent_box = maildir:///data/mail/todo draft_box = maildir:///data/mail/todo - sent_tags = todo,inbox + sent_tags = todo,flagged passed_tags = # none @@ -82,9 +82,8 @@ theme = "mutt" n = compose --sender todo@localhost --to todo [[search]] - x = toggletags spam,inbox - a = toggletags inbox - A = toggletags inbox,muted + a = toggletags flagged + A = toggletags flagged,muted 1 = call hooks.delay(ui,1) 2 = call hooks.delay(ui,2) 3 = call hooks.delay(ui,3) @@ -96,10 +95,11 @@ theme = "mutt" 9 = call hooks.delay(ui,9) 0 = call hooks.delay(ui,0) i = call hooks.spam(ui) + x = call hooks.togglespam(ui) [[thread]] - a = toggletags inbox ; fold - A = toggletags inbox,muted ; fold + a = toggletags flagged ; fold + A = toggletags flagged,muted ; fold n = togglemimepart r = reply --all u = pipeto --background selecturl @@ -117,7 +117,7 @@ theme = "mutt" [tags] - [[inbox]] + [[flagged]] translated = [[encrypted]] diff --git a/config/alot/hooks.py b/config/alot/hooks.py index a7485c2..82fa8fe 100644 --- a/config/alot/hooks.py +++ b/config/alot/hooks.py @@ -15,20 +15,20 @@ async def delay(ui, days): if days != 0: for message in messages: - if 'inbox' in message.get_tags(): + if 'flagged' in message.get_tags(): message.add_tags(['delay', datetag]) - await ui.apply_commandline('untag inbox,unread') + await ui.apply_commandline('untag flagged,unread') else: for message in messages: if 'delay' in message.get_tags(): message.remove_tags([t for t in message.get_tags() if t.startswith('delay')]) - message.add_tags(['inbox']) + message.add_tags(['flagged']) await ui.apply_commandline('untag delay,delay/*') async def spam(ui): message = ui.current_buffer.get_selected_message() message.add_tags(['spam']) - message.remove_tags(['unread', 'inbox']) + message.remove_tags(['unread', 'flagged']) if 'ugent' in message.get_tags(): envelope = Envelope( headers=dict( diff --git a/local/bin/spam b/local/bin/spam index efb0304..ed7d60f 100755 --- a/local/bin/spam +++ b/local/bin/spam @@ -1,15 +1,13 @@ #!/bin/sh +set -e -mid="id:$1" -file="$(notmuch show "$mid" | sed -n '1s/.*filename:\([^ ]*\).*/\1/p')" -temp="$(mktemp)" - -cat > "$temp" < -HERE - -alot compose --sender felix.vanderjeugt@ugent.be \ - --template="$temp" \ - --subject spam \ - --to spam@ugent.be \ - --attach "$file" +for mid in $(notmuch search --output=messages tag:inbox "$@"); do + printf "%s ? " "$(notmuch show "$mid" | sed -n 's/Subject: //p')" + read ans + case "$ans" in + y*) + notmuch show --format=raw "$mid" | bogofilter -Sn + notmuch tag -inbox -unread +spam -- "$mid" + ;; + esac +done diff --git a/notmuch-config b/notmuch-config index 27dff23..012a1a5 100644 --- a/notmuch-config +++ b/notmuch-config @@ -88,4 +88,4 @@ exclude_tags=spam; synchronize_flags=true [query] -inbox=tag:inbox +inbox=tag:flagged diff --git a/notmuch-hooks/post-new b/notmuch-hooks/post-new index 46ea04f..47cba8b 100755 --- a/notmuch-hooks/post-new +++ b/notmuch-hooks/post-new @@ -10,10 +10,6 @@ for maildir in /data/mail/*; do 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" @@ -60,7 +56,7 @@ done # Undelay threads with new messages for delaytag in $(notmuch search --output=tags -- tag:delay and thread:{tag:new} | grep 'delay/'); do - notmuch tag -delay -"$delaytag" +inbox -- tag:"$delaytag" and thread:{tag:new} + notmuch tag -delay -"$delaytag" +flagged -- tag:"$delaytag" and thread:{tag:new} done # Github notifications @@ -78,7 +74,9 @@ archive tag:dodona subject:'status was changed to internal error' 'course_id: 33 archive tag:dodona subject:'status was changed to internal error' 'course_id: 339' # Data Mining 2020-2021 archive tag:dodona subject:'status was changed to internal error' 'course_id: 346' # Programming Basics 2020-2021 archive tag:dodona subject:'status was changed to internal error' 'course_id: 349' # Programmingin Python 2020-2021 +archive tag:dodona subject:'status was changed to internal error' 'course_id: 374' # Statistiek 2020-2021 archive tag:dodona subject:'status was changed to internal error' 'course_id: 375' # Statistiek: introductie tot R 2020-2021 +archive tag:dodona subject:'status was changed to internal error' 'course_id: 376' # Statistiek: Data Exploratie .. 2020-2021 archive tag:dodona subject:'status was changed to internal error' 'course_id: 380' # C# 2020-2021 archive tag:dodona subject:'status was changed to internal error' 'course_id: 384' # E620500A 2020-2021 archive tag:dodona subject:'status was changed to internal error' 'user_id: 3' # Peter @@ -94,8 +92,17 @@ archive tag:ugent subject:'Belnet FileSender: Ontvangstbevestiging' archive thread:{tag:muted} notmuch tag -muted -- tag:muted and date:'..30_days' +# Bogofilter +for mid in $(notmuch search --output=messages tag:new); do + case "$(notmuch show --format=raw "$mid" | bogofilter -eut)" in + H*) true ;; + S*) spam "$mid" ; echo "$mid" >> ~/spamtest;; + U*) true ;; + esac +done + # Inbox remaining not-spam -addtag inbox "not tag:spam" +addtag flagged "not tag:spam" notmuch tag -new -- tag:new # Show threads after their delay @@ -103,6 +110,6 @@ today="$(date +'%s')" for delaytag in $(notmuch search --output=tags tag:delay | grep 'delay/'); do until="$(date -d "${delaytag#*/}" +'%s')" if [ "$today" -gt "$until" ]; then - notmuch tag -delay -"$delaytag" +inbox -- tag:"$delaytag" + notmuch tag -delay -"$delaytag" +flagged -- tag:"$delaytag" fi done \ No newline at end of file diff --git a/profile b/profile index 0b5a4b6..ca4a207 100755 --- a/profile +++ b/profile @@ -24,6 +24,7 @@ export LESSHISTFILE=- export FZF_DEFAULT_COMMAND='(git ls-files -co --exclude-standard || rg --files) 2> /dev/null' export SKIM_DEFAULT_COMMAND='(git ls-files -co --exclude-standard || rg --files) 2> /dev/null' export LC_ALL=en_US.utf8 +export BOGOFILTER_DIR="$XDG_DATA_HOME/bogofilter" # Select Dock sound card if it's there #(it's broken)