Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created November 20, 2018 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamc/1cac84d11f49cd35e7218ccd825f1aa5 to your computer and use it in GitHub Desktop.
Save grahamc/1cac84d11f49cd35e7218ccd825f1aa5 to your computer and use it in GitHub Desktop.
grahamc@Morbo> ~
awk -F: '...thatscript...' '/home/grahamc/.mail/grahamc/[Gmail]/All Mail/cur/...:2,S'
List-Unsubscribe: <mailto:unsub+...@reply.github.com>,
<https://github.com/notifications/unsubscribe/...>
# 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 we've 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; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment