#!/bin/sh
# Show summary of messages with sender and subject (8-bit chars replaced
# by `.').

gawk '
BEGIN {
  envelope_length = 34
  FORMAT = "x-vm-: %3d %-" envelope_length "s %s\n";
}

/^From / {
  if (count > 0) {
    printf FORMAT, count, envelope, subject;
  }
  count++;
  envelope = substr ($2, 0, envelope_length);
}

/^Subject: / {
  $1 = ""; $2 = ""; # clear header and spam marker
  subject = substr ($0, 0, 33);
  gsub (/[^ -~]/, ".", subject)
}

END {
    # The x-vm-- makes kspam ignore this line.
    printf FORMAT, count, envelope, subject;
}
' "$@"
