subjecttop
Show the 25 most common email subjects in the Postfix mail log, or list every subject
- Command:
/go/subjecttop - Category: Mail
- Required arguments: None
- Optional argument: Any value, which switches to listing every subject
- Output: Lines of the form
<count> <subject>, or one subject per line - Last updated: 2026-11-19
On this page: Overview · Quick start · Requirements · Syntax · Output · Examples · Troubleshooting · Details · See also
Overview
/go/subjecttop helps you spot bulk or spam mail by showing which email subjects appear most often in the Postfix mail log. It reads /var/log/maillog, pulls out the subject of each logged message, and counts them.
Typical uses:
- finding a spam campaign that is being sent from the server
- checking which messages a hacked website or mailbox is sending
The command only reads the log. It doesn't change anything.
[!NOTE] Subjects can contain private information. Use the command only for administration, and treat its output as confidential.
Quick start
/go/subjecttop
Requirements
- The command needs
rootorsudorights to read the log. - The mail log must be
/var/log/maillog. The path is fixed. If your system writes the log somewhere else, for example/var/log/mail.logon Debian, the report is empty. - Postfix has to log the subjects. Postfix does that only for some configurations, for example when header checks log the headers they see. If your configuration doesn't, the report is empty.
Syntax
/go/subjecttop
/go/subjecttop <any value>
| Form | Behavior |
|---|---|
/go/subjecttop |
Shows the 25 most common subjects with their counts. |
/go/subjecttop <any value> |
Prints every subject in the log, one per line, in log order, without counts. The value itself is ignored. |
The command has no other options.
Output
Without an argument, each line shows how many times a subject was logged, then the subject:
842 Make Money Fast
120 Invoice 12345
63 Your order has shipped
| Detail | Behavior |
|---|---|
| Number of lines | At most 25, the most common first. |
| Subject length | Cut to the first 75 characters. |
| Case | Counted without regard to case, but see Troubleshooting. |
| Period covered | Everything in the current /var/log/maillog, which is what has been logged since the last log rotation. |
With an argument the output has no counts and can be very long.
Logging
Every run is appended to /var/log/go/subjecttop.log.
Examples
# The 25 most common subjects
/go/subjecttop
# Every subject, searched for a word
/go/subjecttop all | grep -i invoice
# Check that the log contains any subjects at all
grep -c "Subject:" /var/log/maillog
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No output | The log has no subjects, because Postfix isn't set to log them. | Check with grep -c "Subject:" /var/log/maillog. |
cat: /var/log/maillog: No such file or directory |
The mail log is in another place on this system. | Find the real log file. The script has the path fixed. |
| A subject is cut off in the middle | The command removes everything from the first from in the line, so a subject that contains the word from is shortened. |
Expected. See Notes for maintainers. |
| Subjects that differ only in case appear as separate lines | The list is sorted with case sensitivity before the case-insensitive count. | Expected. Add up the lines by hand. |
| Old mail is missing | Only the current log file is read, not the rotated ones. | Run it on the rotated files by hand. |
| The command is slow | It reads the whole log each time. | Run it at a quiet time on very large logs. |
| An enormous amount of output | An argument was given. | Run it without an argument, or pipe the output to less or grep. |
Permission denied |
The command wasn't run as root, or without sudo rights. |
Run it as root. |
Details
What it does
- Logs the call to
/var/log/go/subjecttop.log. - Reads
/var/log/maillogand keeps, for every line that containsSubject:, the text fromSubject:to the end of the line. - Removes the
Subject:label. - Without an argument:
- Removes everything from the first
fromto the end of the line. In Postfix's header warnings this is the part that comes after the subject, with the client address and the sender. - Cuts each subject to 75 characters.
- Sorts the subjects, counts the repeats ignoring case, and sorts by count.
- Shows the top 25.
- Removes everything from the first
- With an argument: prints the subjects without any further processing.
flowchart TD
A["subjecttop"] --> B["Read /var/log/maillog, keep Subject: text"]
B --> C{"Any argument?"}
C -- "No" --> D["Cut at ' from ' and at 75 characters"]
D --> E["Count repeats, sort, show top 25"]
C -- "Yes" --> F["Print every subject"]
Notes for maintainers
| Issue | Why it matters | Suggested fix |
|---|---|---|
from is removed from the first occurrence to the end of the line |
A subject such as Message from John becomes Message, and different subjects merge into one. |
Remove only Postfix's trailer, for example with sed -E 's/ from [^ ]+\[[^]]+\]; .*//'. |
sort is case-sensitive, but uniq -ci ignores case |
Repeats that differ in case are only joined when they happen to be next to each other. | Use sort -f | uniq -ci. |
The path /var/log/maillog is fixed |
Empty output on systems that log to /var/log/mail.log or the journal. |
Detect the log file, or read journalctl -u postfix. |
| Any argument switches to dump mode | A typo prints the whole log's subjects, and there is no way to choose the number of lines or the file. | Add real options, such as --all and --top N. |
The pattern Subject:.* matches any log line that contains the word |
Lines from other programs and bounce texts are mixed in. | Match only header Subject: lines. |
| Only the current log is read, and always in full | Rotated logs are ignored, and big logs are slow. | Add a date range, and read rotated files when asked. |
| The output shows the subject of everyone's mail | Private data. | Restrict who can run the command. |
| The limits (25 lines, 75 characters) are fixed | Not adjustable. | Make them options. |
See also
| Command | Description |
|---|---|
mailtop |
Check the most active email accounts in GoAdmio |
spam |
Track spam email accounts in GoAdmio |
incoming |
Report today's inbound mail sessions |
outgoing |
Report today's outbound mail sessions |
filter |
Reset the server-wide email filter list to the built-in spam and virus keyword rules |
deletemailqueue |
Delete all emails in the Postfix mail queue |
postfwd |
Build the Postfwd rate-limiting rules |