Created
November 20, 2018 03:15
-
-
Save grahamc/2887c2f5a4b5a3abcdc440aaee9dc254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notmuch search --format=text0 --output=files listunsubscribe:mailto | xargs -n1 -0 awk -F: ' ~ | |
# Set "unsub" to 0 indicating we have not hit an unsubscribe header | |
# As soon as we reach one, we set it to 1 to indicate the next line | |
# might be a header-folded unsubscribe line continuation | |
begin { unsub=0 } | |
# Abort if we find a line with no content, indicating going from | |
# headers to body | |
$0 == "" { exit } | |
# If unsub=1 it means the previous line was a list-unsubscribe | |
# header line. If the current line starts with a space, it is a | |
# header continuation, so print it. | |
$0 ~ /^\s+/ && unsub==1 { print $0 } | |
# If unsub=1 it means the previous line was a list-unsubscribe | |
# header line. Since the current line does not start with a space, | |
# it is not a header continuation, so weve finished finding the | |
# unsubscribe header. | |
$0 !~ /^\s+/ && unsub==1 { exit } | |
# We have reached a list-unsubscribe header, so set unsub=1 to | |
# handle a header-folded line continuation and print the header | |
tolower($1) == "list-unsubscribe" { unsub=1; print $0; } | |
' | sed -e 's/^List-Unsubscribe://' \ | |
| tr ',' $'\n' \ | |
| sed -e 's/^\s*//' -e 's/\s*$//' -e 's/^<//' -e 's/>$//' \ | |
| grep -e "^mailto:" \ | |
| sed -e "s/^mailto://" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment