procmail and mail file locking

Does procmail default lock the local delivery mail file as I have been told postfix and other MTAs do? If I run procmail -f $MAILTO where procmail is getting the mail file from STDIN. Or do I add something like the following to my script: exec 100>/var/spool/mail$USER.lock || exit 1 flock -w 120 100 || exit 1 And do I also need -d $MAILTO on the above procmail call? thanks

On 2020-05-15 04:26, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file
Se also https://linux.die.net/man/5/procmailrc which mentions using lock files. Did you consider using IMAP? -- Ruud

On 5/15/20 8:57 AM, Ruud H.G. van Tol wrote:
On 2020-05-15 04:26, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file
Se also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts. It was that man page that clued me into needing to do something about locking the access to /var/spool/mail/$USER file. But what is the 'common' lock file name? The examples in the above mask the file which is the lock file.
Did you consider using IMAP?
What does IMAP have to do with this? Note I participated in the initial IETF work on IMAP. For this mail, my mailserver is running Dovecot and I am using Thunderbird via IMAP. But here I am talking about a 'simple' MDA of cron output into the local store with no MTA on said system. Why no MTA? Because... And Mutt works just fine, and if I SSH into the box, I can run Mutt in the SSH terminal. Or if I am connected via the serial console.
-- Ruud

Greetings, Robert Moskowitz!
On 5/15/20 8:57 AM, Ruud H.G. van Tol wrote:
On 2020-05-15 04:26, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file
Se also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts.
It was that man page that clued me into needing to do something about locking the access to /var/spool/mail/$USER file.
But what is the 'common' lock file name? The examples in the above mask the file which is the lock file.
Did you consider using IMAP?
What does IMAP have to do with this?
I think he did mean Maildir rather than mbox. -- With best regards, Andrey Repin Saturday, May 16, 2020 21:58:16 Sorry for my terrible english...

On 2020-05-16 20:59, Andrey Repin wrote:
Greetings, Robert Moskowitz!
On 5/15/20 8:57 AM, Ruud H.G. van Tol wrote:
On 2020-05-15 04:26, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file
See also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts.
It was that man page that clued me into needing to do something about locking the access to /var/spool/mail/$USER file.
But what is the 'common' lock file name? The examples in the above mask the file which is the lock file.
Did you consider using IMAP?
What does IMAP have to do with this?
I think he did mean Maildir rather than mbox.
Thanks, indeed, I meant Maildir, oops. The procmailrc(5) is a good read, look for lock. Then https://linux.die.net/man/5/procmailex mentions examples of implicit lockfiles. (set VERBOSE to log more details) Some user experience with procmail and lockfiles: https://www.techrepublic.com/article/all-the-wonders-of-procmail-part-2-lock... -- Ruud

On 5/16/20 4:01 PM, Ruud H.G. van Tol wrote:
On 2020-05-16 20:59, Andrey Repin wrote:
Greetings, Robert Moskowitz!
On 5/15/20 8:57 AM, Ruud H.G. van Tol wrote:
On 2020-05-15 04:26, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file
See also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts.
It was that man page that clued me into needing to do something about locking the access to /var/spool/mail/$USER file.
But what is the 'common' lock file name? The examples in the above mask the file which is the lock file.
Did you consider using IMAP?
What does IMAP have to do with this?
I think he did mean Maildir rather than mbox.
Thanks, indeed, I meant Maildir, oops.
Yes. I was really confused there. But I have made bigger blubbers! I considered maildir, but I cannot be assured that I will catch all local mail deliveries. I set up cron to just my script. That was 'easy'. Then I was looking at logwatch, and I see that in /etc/logwatch/conf/logwatch.conf mailer = "/usr/local/mycron" I did not add that, some process corrected logwatch automagically for me. I am not comfortable if I install some other package that does outputs to mail that it would get the change and perhaps deliver in the 'default' mbox manner. Just a little paranoia here. So I stay with mbox and have to be concerned with file locking....
The procmailrc(5) is a good read, look for lock.
Then https://linux.die.net/man/5/procmailex mentions examples of implicit lockfiles. (set VERBOSE to log more details)
Some user experience with procmail and lockfiles: https://www.techrepublic.com/article/all-the-wonders-of-procmail-part-2-lock...
-- Ruud ____________________________________________________________ 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

Greetings, Robert Moskowitz!
I considered maildir, but I cannot be assured that I will catch all local mail deliveries.
With Maildir, it's actually even harder to miss mails, since it's inherently non-blocking.
I set up cron to just my script. That was 'easy'. Then I was looking at logwatch, and I see that in /etc/logwatch/conf/logwatch.conf
mailer = "/usr/local/mycron"
I did not add that, some process corrected logwatch automagically for me. I am not comfortable if I install some other package that does outputs to mail that it would get the change and perhaps deliver in the 'default' mbox manner.
Just a little paranoia here. So I stay with mbox and have to be concerned with file locking....
…or move to Maildir and forget about locking issues. -- With best regards, Andrey Repin Monday, May 18, 2020 18:39:44 Sorry for my terrible english...

What Ruud posted is certainly good stuff but I got the impression from Robert's postings that this is overkill. On Thu, 14 May 2020, at 22:26, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file as I have been told postfix and other MTAs do?
In case of files, yes.
If I run `procmail -f $MAILTO` where procmail is getting the mail file from STDIN.
That's fine. It does not change the default locking.
Or do I add something like the following to my script:
exec 100>/var/spool/mail$USER.lock || exit 1 flock -w 120 100 || exit 1
Not needed.
And do I also need -d $MAILTO on the above procmail call?
Not as long as $MAILTO is your own address. On Fri, 15 May 2020, at 09:31, Robert Moskowitz wrote:
Se also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts.
Piping formail also doesn't change the fact that procmail has its default locking when delivering to files. But I did not get your remark about receipts.
It was that man page that clued me into needing to do something about locking the access to /var/spool/mail/$USER file.
It should work in most cases. Of course there are pathological cases like spool dirs mounted on network file systems or uncommon mail delivery agents (not that I know any).
But what is the 'common' lock file name? The examples in the above mask the file which is the lock file.
/var/spool/mail/$USER.lock but see the manpages for details or run an strace if you want to be sure. I am actually not sure procmail creates a $LOCKEXT (defaults to .lock) file but I also did not bother to check. In any case quoting from procmail(1) Whenever procmail itself opens a file to deliver to, it consistently uses the following kernel locking strategies: fcntl(2). -- -- Andreas Nothing in life is to be feared, it is only to be understood. Now is the time to understand more, so that we may fear less. --- Glenn T. Seaborg, 1968, quoting Marie Curie; cf. https://todayinsci.com/C/Curie_Marie/CurieMarie-Quotations.htm

On 5/16/20 4:59 PM, Andreas Schamanek wrote:
What Ruud posted is certainly good stuff but I got the impression from Robert's postings that this is overkill.
On Thu, 14 May 2020, at 22:26, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file as I have been told postfix and other MTAs do?
In case of files, yes.
Just to be sure, you are talking about the mbox mail file. Your last comment seems to assure me that you mean writing to an mbox file.
If I run `procmail -f $MAILTO` where procmail is getting the mail file from STDIN.
That's fine. It does not change the default locking.
Or do I add something like the following to my script:
exec 100>/var/spool/mail$USER.lock || exit 1 flock -w 120 100 || exit 1
Not needed.
And do I also need -d $MAILTO on the above procmail call?
Not as long as $MAILTO is your own address.
On Fri, 15 May 2020, at 09:31, Robert Moskowitz wrote:
Se also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts.
Piping formail also doesn't change the fact that procmail has its default locking when delivering to files. But I did not get your remark about receipts.
I am not using receipts where I see the use of lockfile in the examples. I have a 'simple' formail command that is then piped into procmail.
It was that man page that clued me into needing to do something about locking the access to /var/spool/mail/$USER file.
It should work in most cases. Of course there are pathological cases like spool dirs mounted on network file systems or uncommon mail delivery agents (not that I know any).
But what is the 'common' lock file name? The examples in the above mask the file which is the lock file.
/var/spool/mail/$USER.lock but see the manpages for details or run an strace if you want to be sure. I am actually not sure procmail creates a $LOCKEXT (defaults to .lock) file but I also did not bother to check. In any case quoting from procmail(1)
Whenever procmail itself opens a file to deliver to, it consistently uses the following kernel locking strategies: fcntl(2).
thanks!

On Sun, 17 May 2020, at 07:37, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file as I have been told postfix and other MTAs do? In case of files, yes. Just to be sure, you are talking about the mbox mail file. Your last comment seems to assure me that you mean writing to an mbox file.
Procmail has by default locking support for writing to any file as long as it is (at least) a regular file, that includes mbox and maildir, of course.
Se also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts.
Piping formail also doesn't change the fact that procmail has its default locking when delivering to files. But I did not get your remark about receipts.
I am not using receipts where I see the use of lockfile in the examples. I have a 'simple' formail command that is then piped into procmail.
My procmailrc(5) does not mention "receipt". Maybe you mean "recipe"? But then, almost everything in procmailrc is a recipe :) -- -- Andreas Nothing in life is to be feared, it is only to be understood. Now is the time to understand more, so that we may fear less. --- Glenn T. Seaborg, 1968, quoting Marie Curie; cf. https://todayinsci.com/C/Curie_Marie/CurieMarie-Quotations.htm

On 5/17/20 8:00 AM, Andreas Schamanek wrote:
On Sun, 17 May 2020, at 07:37, Robert Moskowitz wrote:
Does procmail default lock the local delivery mail file as I have been told postfix and other MTAs do? In case of files, yes. Just to be sure, you are talking about the mbox mail file. Your last comment seems to assure me that you mean writing to an mbox file.
Procmail has by default locking support for writing to any file as long as it is (at least) a regular file, that includes mbox and maildir, of course.
Se also https://linux.die.net/man/5/procmailrc which mentions using lock files.
I am piping the output of a formail command into procmail. No receipts.
Piping formail also doesn't change the fact that procmail has its default locking when delivering to files. But I did not get your remark about receipts.
I am not using receipts where I see the use of lockfile in the examples. I have a 'simple' formail command that is then piped into procmail.
My procmailrc(5) does not mention "receipt". Maybe you mean "recipe"? But then, almost everything in procmailrc is a recipe :)
ARGH!!! Mr. Malaprop strikes again. Rudd has nothing over me in using the wrong word. Yes, at some point it would be nice to work out how recipes work, outside of the kitchen. But for now I am doing this all in the command line.
participants (4)
-
Andreas Schamanek
-
Andrey Repin
-
Robert Moskowitz
-
Ruud H.G. van Tol