Formail - problem with -I From:

When I use a -I From: to replace my From: line, formail is putting foo@bar in the first line From. I have a file, t, I saved from cron. It starts with: From: "(Cron Daemon)" <rgm> To: rgm Subject: Cron <rgm@lx140e> rsync -tvz rsync.tools.ietf.org::tools.id/*-hip-*.xml /home/common/ietf/drafts/xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated Precedence: bulk X-Cron-Env: <XDG_SESSION_ID=270> as a simple test I ran the following: formail -I "From: (Cron Daemon) <$USER@$HOSTNAME>" >> m$USER < t The headers in my m$USER are: From foo@bar Tue May 12 16:47:30 2020 To: rgm Subject: Cron <rgm@lx140e> rsync -tvz rsync.tools.ietf.org::tools.id/*-hip-*.xml /home/common/ietf/drafts/xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated Precedence: bulk X-Cron-Env: <XDG_SESSION_ID=270> . . . Status: RO Content-Length: 101 Lines: 3 From: (Cron Daemon) <rgm@lx140e.htt-consult.com> How do I get formail to at least put From rgm Tue May 12 16:47:30 2020 If not the final rgm@lx140e.htt-consult.com ?? thanks

That initial "From " line (or is it " From "?) is not part of the email-header, but is rather a 'system solution' to represent part of the envelope details. -- Ruud On 2020-05-12 22:52, Robert Moskowitz wrote:
When I use a -I From: to replace my From: line, formail is putting foo@bar in the first line From.

I am struggling a bit with terminology here. There is the "regular" RFC822 email From: header. I will call that From-header. Then there is the mbox start-of-message From line. I will call that From-mbox. If I use formail to change various email headers other than the From-Header, formail creates a From-mbox line that shows the sender as what is in the existing From-Header. If I user formail to -I replace the From-Header, formail creates a From-mbox line where the sender is foo@bar. Strange behavior. Now I have not tested all possible combinations of formail options, but -I From: ... causes this odd behavior. I has become a mute point, as when I pipe the output of formail into procmail -d .... , procmail 'fixes' the From-mbox line. But formail should not be getting it wrong in the first place to need procmail to correct it. On 5/13/20 2:16 AM, Ruud H.G. van Tol wrote:
That initial "From " line (or is it " From "?) is not part of the email-header, but is rather a 'system solution' to represent part of the envelope details.
-- Ruud
On 2020-05-12 22:52, Robert Moskowitz wrote:
When I use a -I From: to replace my From: line, formail is putting foo@bar in the first line From.
procmail mailing list -- procmail@lists.rwth-aachen.de Procmail homepage: http://www.procmail.org/ To unsubscribe send an email to procmail-leave@lists.rwth-aachen.de https://lists.rwth-aachen.de/postorius/lists/procmail.lists.rwth-aachen.de

In article <9049a7aa-73be-bb47-de4c-5e1a4d9768c0@htt-consult.com> you write:
I am struggling a bit with terminology here. There is the "regular" RFC822 email From: header. I will call that From-header. Then there is the mbox start-of-message From line. I will call that From-mbox.
If I use formail to change various email headers other than the From-Header, formail creates a From-mbox line that shows the sender as what is in the existing From-Header.
Right, that's what it does. Or you can use a -f flag to omit the mbox From altogether
If I user formail to -I replace the From-Header, formail creates a From-mbox line where the sender is foo@bar.
That's the default if there's no valid From: in the incoming message.
But formail should not be getting it wrong in the first place to need procmail to correct it.
It's not wrong even if it's not what you expect. Letting procmail generate the mbox From is a better idea anyway. R's, John

On 5/13/20 2:36 PM, John Levine wrote:
I am struggling a bit with terminology here. There is the "regular" RFC822 email From: header. I will call that From-header. Then there is the mbox start-of-message From line. I will call that From-mbox.
If I use formail to change various email headers other than the From-Header, formail creates a From-mbox line that shows the sender as what is in the existing From-Header. Right, that's what it does. Or you can use a -f flag to omit
In article <9049a7aa-73be-bb47-de4c-5e1a4d9768c0@htt-consult.com> you write: the mbox From altogether
But it did not use the From: header content. I am including the message file at the end.
If I user formail to -I replace the From-Header, formail creates a From-mbox line where the sender is foo@bar. That's the default if there's no valid From: in the incoming message.
There IS a From: in the original message: From: "(Cron Daemon)" <rgm> Now this IS the first line in the message. I am replacing this via: -I "From: (Cron Daemon) <$USER@$HOSTNAME>" Which gets inserted after all the remaining headers.
But formail should not be getting it wrong in the first place to need procmail to correct it. It's not wrong even if it's not what you expect.
Well the message HAS a From: header. Yes, I would expect formail to use it in creating the mbox From header, and not have to resort to foo@bar.
Letting procmail generate the mbox From is a better idea anyway.
Yes. But it had me confused and delayed me, trying to get formail creating a From mbox line, to finally give up and start on the procmail step to see it get fixed... From: "(Cron Daemon)" <rgm> To: rgm Subject: Cron <rgm@lx140e> rsync -tvz rsync.tools.ietf.org::tools.id/*-hip-*.xml /home/common/ietf/drafts/xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated Precedence: bulk X-Cron-Env: <XDG_SESSION_ID=270> X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/1000> X-Cron-Env: <DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus> X-Cron-Env: <XDG_SESSION_TYPE=unspecified> X-Cron-Env: <XDG_SESSION_CLASS=background> X-Cron-Env: <LANG=en_US.UTF-8> X-Cron-Env: <SHELL=/bin/bash> X-Cron-Env: <PATH=/sbin:/bin:/usr/sbin:/usr/bin> X-Cron-Env: <MAILTO=rgm> X-Cron-Env: <HOME=/home/rgm> X-Cron-Env: <LOGNAME=rgm> X-Cron-Env: <USER=rgm> Status: RO Content-Length: 101 Lines: 3 sent 30 bytes received 5,001 bytes 402.48 bytes/sec total size is 10,561,702 speedup is 2,099.32

In article <104eaa3a-1276-5531-f6a1-be8ac804e500@htt-consult.com> you write:
If I user formail to -I replace the From-Header, formail creates a From-mbox line where the sender is foo@bar. That's the default if there's no valid From: in the incoming message.
There IS a From: in the original message:
From: "(Cron Daemon)" <rgm>
That's not a valid From: address since it doesn't have a domain name.

On 5/13/20 3:56 PM, John Levine wrote:
In article <104eaa3a-1276-5531-f6a1-be8ac804e500@htt-consult.com> you write:
If I user formail to -I replace the From-Header, formail creates a From-mbox line where the sender is foo@bar. That's the default if there's no valid From: in the incoming message. There IS a From: in the original message:
From: "(Cron Daemon)" <rgm> That's not a valid From: address since it doesn't have a domain name.
Ah, I will take your word for it. I could never grok 822. It is what cron is doing, though. Why put something in broken? It could have done rgm@localhost. One more thing to include in my cron bug report. Already going to complain no Date: as to when the cron task started. All you can do is stick in a Date: header of when the task finished.

In article <e287b896-b6a4-3d88-77de-20164cfcd014@htt-consult.com> you write:
It is what cron is doing, though. Why put something in broken? It could have done rgm@localhost.
On systems with regular mail software, the cron output goes through a submission server which cleans up the address headers and adds Date and Message-ID and so forth. I'll be intrigued whether they accept your report or say it's not their problem.
One more thing to include in my cron bug report. Already going to complain no Date: as to when the cron task started. All you can do is stick in a Date: header of when the task finished.
Well, your command can be something like date; do-something; date and the timestamps are in the message. I do that for stuff that runs a long time. R's, John

Greetings, Robert Moskowitz!
If I user formail to -I replace the From-Header, formail creates a From-mbox line where the sender is foo@bar. That's the default if there's no valid From: in the incoming message. There IS a From: in the original message:
From: "(Cron Daemon)" <rgm> That's not a valid From: address since it doesn't have a domain name.
Ah, I will take your word for it. I could never grok 822.
https://tools.ietf.org/html/rfc5322#section-3.4.1
It is what cron is doing, though. Why put something in broken? It could have done rgm@localhost.
Which is about as "useful". I'd rather like <cron@`hostname --fqdn`>
One more thing to include in my cron bug report. Already going to complain no Date: as to when the cron task started. All you can do is stick in a Date: header of when the task finished.
-- With best regards, Andrey Repin Thursday, May 14, 2020 17:45:59 Sorry for my terrible english...

On 5/14/20 11:05 AM, Andrey Repin wrote:
Greetings, Robert Moskowitz!
If I user formail to -I replace the From-Header, formail creates a From-mbox line where the sender is foo@bar. That's the default if there's no valid From: in the incoming message. There IS a From: in the original message:
From: "(Cron Daemon)" <rgm> That's not a valid From: address since it doesn't have a domain name.
Ah, I will take your word for it. I could never grok 822. https://tools.ietf.org/html/rfc5322#section-3.4.1
It is what cron is doing, though. Why put something in broken? It could have done rgm@localhost. Which is about as "useful". I'd rather like <cron@`hostname --fqdn`>
Well I now have some results of my script and some things kind of work and others don't. #!/bin/sh [[ -z $MAILTO ]] && MAILTO=$USER FullName=$(getent passwd $MAILTO | cut -d: -f5) EmailAddr="$MAILTO@$HOSTNAME" [[ -z $FullName ]] || EmailAddr="$FullName <$EmailAddr>" formail -i "Date: $(date +'%a, %e %b %Y %T %z (%Z)')" -a Message-ID: \ -I "From: (Cron Daemon) <$USER@$HOSTNAME>" -I "To: $EmailAddr" \ | procmail -f $MAILTO For output of crontab entries (from my user crontab): From rgm Thu May 14 04:01:11 2020 Subject: Cron <rgm@lx140e> rsync -tvz rsync.tools.ietf.org::tools.id/*.txt /home/common/ietf/drafts MIME-Version: 1.0 . . . X-Cron-Env: <USER=rgm> Message-ID: <AK0hgwC4d1.A.yjE.MrPveB@lx140e.htt-consult.com> Date: Thu, 14 May 2020 04:01:11 -0400 (EDT) From: (Cron Daemon) <rgm@lx140e.htt-consult.com> To: Robert Moskowitz <rgm@lx140e.htt-consult.com> Status: RO The From, Date:, From:, and To: were added by formail. Well actually the From is from procmail, as formail was putting foo@bar in the From line. This is from cron which was putting out: From: "(Cron Daemon)" <rgm> To: rgm That looks OKish. I loose the "" around (Cron Daemon) as how would I put them into that formail command? But it messes things up with the output from logwatch. I "know" that logwatch generates: To: root From: logwatch my script replaces that with: From root Thu May 14 03:48:06 2020 Subject: Logwatch for lx140e.htt-consult.com (Linux) Auto-Submitted: auto-generated Precedence: bulk MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="UTF-8" Message-ID: <Rd8yDiB9CqC.A.pbE.7ePveB@lx140e.htt-consult.com> Date: Thu, 14 May 2020 03:48:06 -0400 (EDT) From: (Cron Daemon) <root@lx140e.htt-consult.com> To: root <root@lx140e.htt-consult.com> Ouch, I loose that the message is from logwatch, not just root! I have played around with formail, and I have not figured out how to pick up that the original From: is not USER Can someone help on this? thanks
participants (4)
-
Andrey Repin
-
John Levine
-
Robert Moskowitz
-
Ruud H.G. van Tol