2016-09-05 12:17:11 +00:00
|
|
|
#!/usr/bin/awk -f
|
2016-08-02 20:50:45 +00:00
|
|
|
# mcolor - colorize rendered mail
|
|
|
|
|
|
|
|
function co(n, c) { e = ENVIRON["MCOLOR_" n]; return e ? e : c }
|
|
|
|
function fg(c, s) { return sprintf("\033[38;5;%03dm%s\033[0m", c, s) }
|
|
|
|
function so(s) { return sprintf("\033[1m%s\033[0m", s) }
|
2018-01-29 14:34:53 +00:00
|
|
|
BEGIN { hdr = 1; if ("NO_COLOR" in ENVIRON || match(ENVIRON["TERM"], "^(dumb|network|9term)")) no_color = 1 }
|
|
|
|
no_color { print; next }
|
2017-06-13 11:52:41 +00:00
|
|
|
/\r$/ { sub(/\r$/, "") }
|
2016-10-18 13:42:14 +00:00
|
|
|
/^\014$/ { nextmail = 1; next }
|
2016-08-02 20:50:45 +00:00
|
|
|
/^$/ { hdr = 0 }
|
|
|
|
/^-- $/ { ftr = 1 }
|
|
|
|
/^--- .* ---/ { print fg(co("SEP",242), $0); ftr = 0; sig = 0; next }
|
|
|
|
/^-----BEGIN .* SIGNATURE-----/ { sig = 1 }
|
2016-10-18 13:42:14 +00:00
|
|
|
nextmail && /^From:/ { hdr = 1 }
|
2016-08-02 20:50:45 +00:00
|
|
|
hdr && /^From:/ { print so(fg(co("FROM",119), $0)); next }
|
|
|
|
hdr { print fg(co("HEADER",120), $0); next }
|
|
|
|
ftr { print fg(co("FOOTER",244), $0); next }
|
|
|
|
/^-----BEGIN .* MESSAGE-----/ ||
|
|
|
|
/^-----END .* SIGNATURE-----/ { print fg(co("SIG",244), $0); sig = 0; next }
|
|
|
|
sig { print fg(co("SIG",244), $0); next }
|
2017-06-13 16:07:03 +00:00
|
|
|
/^> *> *>/ { print fg(co("QQQUOTE",152), $0); next }
|
|
|
|
/^> *>/ { print fg(co("QQUOTE",149), $0); next }
|
2016-08-02 20:50:45 +00:00
|
|
|
/^>/ { print fg(co("QUOTE",151), $0); next }
|
2016-10-18 13:42:14 +00:00
|
|
|
{ nextmail = 0; print }
|