5

We are trying to get a list of unread emails from our Unix server using mailx -L. However, the email subject gets truncated if its length is greater than 25 characters.

How can this be resolved?

2

mailx truncates its output to fit into the number of columns on stdout. To get the number of columns, it will try ioctl(1, TIOCGWINSZ, ...) first - your terminal's window size - and if that fails, it will use the COLUMNS environment variable. So try this:

COLUMNS=999 mailx -L | cat

The |cat is there so that mailx's stdout won't be a terminal, thus forcing the ioctl to fail.

1

Mails usually are just text files (either in mbox or Maildir format), so you can process them with grep, sed, awk, or any scripting language. Common locations for mails are /var/mail, /var/spool/mail or some file/directory inside a users home directory.

To extract mail's subjects, you can use grep like this:

grep -E '^Subject: ' /path/to/mail

To remove the "Subject: " part, pipe it through sed:

... | sed -e 's/^Subject: //'

Filtering for unread message is more complicated, as the read/unread status is stored in a different mail header line. I guess you would need a slightly more complex script written in awk, Perl, Python etc. I have no tested solution ready for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.