开发者

How to pipe mailx Headers to external File. Always getting truncated

开发者 https://www.devze.com 2023-03-09 06:33 出处:网络
if the subject of a mail is a little longer then it is not possible to pipe it to any command or external file without getting truncated. Why? And how do you do it correctly?

if the subject of a mail is a little longer then it is not possible to pipe it to any command or external file without getting truncated. Why? And how do you do it correctly?

Example:

mail -H -f mbox

shows several mails. Everything looks OK.

O 3 user@linux.sit Tue May 31 13:39 22/596 This is a very long long long Subject

But as soon as one tries to do ANYTHING with a pipe it will break

mail -H -f mbox | tee
 O  3 user@linux.sit Tue May 31 13:39   22/596   This is a ver

It will only display 78 characters in a row and nothing more.

The same if I do

mail -H -f mbox >> into_a_file

mail -H -f mbox | grep -----
mail -f mbox | less

And it is not working in xterm, in gnome-terminal etc... No matter if I set开发者_Go百科 the COLUMNS or the TERMWIDTH (outside of mailx or with the -S option...)

Why is that?


From what I can see, mailx is behaving differently in giving output versus redirecting it.

Reading the manual shows that the standard output of message headers is possible with

$ mail -H

This is the equivalent of giving output with a specific format (like printf in C)

$ mail -H -S headline="%>%a%m %20f  %16d %3l/%-5o %i%S"

Looks like this is getting truncated for the %S field when piping the output. To preserve the subject header, change the %S to something like %150S (field width 150).

$ mail -H -S headline="%>%a%m %20f  %16d %3l/%-5o %i%150S"
0

精彩评论

暂无评论...
验证码 换一张
取 消