From a03e011345413a9b3749deb9da895bb4e8ec9974 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 3 Dec 2016 02:02:16 +1300 Subject: Rewrite unf(1df) in awk Also update manual page references to it, and improve it by making it ignore body content --- bin/unf.awk | 34 ++++++++++++++++++++++++++++++++++ bin/unf.sed | 17 ----------------- 2 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 bin/unf.awk delete mode 100644 bin/unf.sed (limited to 'bin') diff --git a/bin/unf.awk b/bin/unf.awk new file mode 100644 index 00000000..22a10aa8 --- /dev/null +++ b/bin/unf.awk @@ -0,0 +1,34 @@ +# Unfold header lines in an internet message, don't touch the body + +# Function to write and empty the buffer +function wrbuf() { + if (length(buf)) + print buf + buf = "" +} + +# Flag to stop processing once we hit the first blank line +!length { + wrbuf() + body = 1 +} +body { + print + next +} + +# Write any buffer contents once we hit a line not starting with a space +/^[^ \t]/ { + wrbuf() +} + +# Append the current line to the buffer +{ + sub(/^[ \t]+/, " ") + buf = buf $0 +} + +# Write the buffer out again when we hit the end +END { + wrbuf() +} diff --git a/bin/unf.sed b/bin/unf.sed deleted file mode 100644 index 23270fc6..00000000 --- a/bin/unf.sed +++ /dev/null @@ -1,17 +0,0 @@ -# Unfold lines with leading spaces (e.g. RFC 822 headers) -/^[ \t]/!{ - 1!{ - x - p - x - } - h -} -/^[ \t]/{ - H - x - s/[\r\n]//g - x -} -$!d -x -- cgit v1.2.3