aboutsummaryrefslogtreecommitdiff
path: root/bin/unf.awk
blob: 57f5f0cfd93debe1e83ded58ec67a861a1e579a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Unfold header lines in an internet message, don't touch the body

BEGIN { buf = "" }

# 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($0) {
    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() }