#! /usr/bin/gawk -f # lsmbox, inna wersja BEGIN{ "tput cols" | getline cols; # sprawdzic czy zwrocilo cos sensownego! close("tput cols"); cols -= 17; subjw = int(0.6 * cols); sendw = cols - subjw; fmt = sprintf("%%-3d %%-%d.%ds %%4d/%%-6d %%-%d.%ds\n", sendw, sendw, subjw, subjw); ARGC == 1 && ("MAIL" in ENVIRON && (ARGV[1] = ENVIRON["MAIL"]) || "USER" in ENVIRON && (ARGV[1] = "/var/mail/" ENVIRON["USER"])) && (ARGC = 2); } function print_line() { printf fmt, nmail, sender, nlines, nbytes, subject; } /^From /{ nbytes--; nlines--; nmail && print_line(); nmail++; sender = subject = ""; nbytes = nlines = 0; in_headers = 1; next; } END{ nbytes--; nlines--; nmail && print_line(); } !/^From /{ nbytes += length() + 1; nlines++; } in_headers && /^[ \t]+[^ \t\r]+/{ sub(/^[ \t]*/, ""); hkey == "sender" && (sender = sender " " $0); hkey == "subject" && (subject = subject " " $0); } in_headers && /^From: /{ sub(/^From:[ \t]+/, ""); sender = $0; hkey = "sender"; next; } in_headers && /^Subject: /{ sub(/^Subject:[ \t]+/, ""); subject = $0; hkey = "subject"; next; } in_headers && /^[A-Z]/{ hkey = ""; next; } in_headers && /^[ \t]*$/{ in_headers = 0; hkey = "" }