Subject: Re: Emacs and Locking

From: [email-masked] (Stephen R. van den Berg)
Date: Wed, 29 Jun 1994 21:02:13 +0200

[email-masked] <[email-masked]> wrote:
>I read my mail using rmail mode of Emacs 19.22 on Sun OS 4.1.2.  I
>have procmail (3.02) deliver my mail to $HOME/mbox with lockfile
>$HOME/mbox.lock.  If two messages arrive essentially simultaneously
>(e.g., I mail a message to myself and request a return receipt) and if
>I happen to be issuing the rmail "g" to read $HOME/mbox when they
>arrive, rmail occasionally fails because $HOME/mbox is corrupted --
>often it contains only the first message followed by just the initial
>"F" of the second.  From looking at Emacs' configuration data, it
>appears that it should also be using locking via $HOME/mbox.lock.  Do
>you have any ideas about what is going wrong?  Any ways to avoid the
>problem (and still use Emacs)?

Procmail delivering straight to the emacs folders is a bit problematic
due to emacs' inability to reload the extra mail that arrived at the
end while the file is already in the buffer.

You can make procmail use the same lockfile as emacs (see man procmailex for
an example), but I don't think this is the best solution.

The best solutions I have heard of so far use some kind of duplicate
folder scheme, i.e. one file for every folder that procmail delivers to, and
one corresponding file for emacs.  This way you import mail from the
shadow file at will with the emacs utility to copy over the mail (I forgot
the name) which employs proper locking methods.

However, I'm not by far the authorative answer concerning emacs, so I cc'd
this mail to the procmail list, I'm sure some other emacs users on there
can give you more qualified advice.

-- 
Sincerely,                                  [email-masked]
           Stephen R. van den Berg (AKA BuGless).

To boldly program, where *no* man has programmed before!

---

From: [email-masked]
Date: Wed, 29 Jun 94 14:43:17 CDT

> can give you more qualified advice.

Just a clarification: I am having procmail deliver my mail into
$HOME/mbox instead of /usr/spool/mail/$LOGNAME, so the problem that I
am seeing is with basic mail delivery, not delivery into Emacs
folders.  Locking does not appear to be working between procmail and
movemail, the utility that Emacs uses to move incoming mail from a
user's mailbox into its buffer (RMAIL).

Ed

---

From: [email-masked]
Date: Wed, 29 Jun 94 18:21:35 CDT

I think that I now understand the source of my problem.  GNU Emacs'
rmail mode only uses its auxiliary program movemail to lock a mailbox
if that mailbox is in what rmail thinks is the system mail spool
directory.  In my case, I had told rmail that I had moved the mailbox
(via variable rmail-primary-inbox-list) but had not told it that I had
moved the spool directory (via variable rmail-spool-directory).

Ed

---

From: Roman Czyborra <[email-masked]>
Date: Thu, 30 Jun 1994 01:52:48 +0200

> Locking does not appear to be working between procmail and movemail,
> the utility that Emacs uses to move incoming mail from a user's
> mailbox into its buffer (RMAIL).

Create your own movemail using procmail's lockfile

	#!/bin/sh
	lockfile $1.lock || exit
	cp $1 $2 && ( : ) > $1
	rm -f $1.lock

and instruct Emacs to use it instead of the broken original.  If you
switched from M-x rmail to M-x vm, that'd be as easy as

	(setq vm-movemail-program "~/bin/movemail")

whereas rmail itself would need a small hack:

	(add-hook 'rmail-mode-hook
		  (function (lambda () 
			      (make-local-variable 'exec-directory)
			      (setq exec-directory "~/bin"))))

The above shell script resembles the original movemail's behavior.  If
you plan to move mail from the command line occasionally it should be
enhanced to create $2.lock too and use cat $1 >> $2 instead of the cp
in order to keep earlier messages in file $2.