<<< Date Index >>>     <<< Thread Index >>>

Re: simulating "Aborted unmodified message" condition



On 2006-09-11, William Yardley <mutt-users@xxxxxxxxxxxxxxxxx> wrote:
> On Mon, Sep 11, 2006 at 03:20:18PM -0700, William Yardley wrote:
> > On Mon, Sep 11, 2006 at 03:06:56PM -0700, Gary Johnson wrote:
> > > On 2006-09-11, William Yardley <mutt-users@xxxxxxxxxxxxxxxxx> wrote:
> > > > On Mon, Sep 11, 2006 at 02:38:31PM -0700, Gary Johnson wrote:
> > > > > On 2006-09-11, William Yardley <mutt-users@xxxxxxxxxxxxxxxxx> wrote:
> 
> > > > > > I was wondering if there's an easy way to simulate the
> > > > > > condition for "Aborted unmodified message" within a shell or
> > > > > > perl script. 
>  
> > > > >     :set editor="true"
> > > > > 
> > > > > Is that what you had in mind?
> 
> > > > No, because I already have to set editor to be my script. I want
> > > > to make it fail after opening the message with my "editor".
>   
> > > I don't really understand what you're trying to do.  If you want
> > > that message, then the modification time of the message file when
> > > your script ends needs to be the same as the modification time when
> > > mutt wrote the file.  So your script needs to either not modify the
> > > file, or to restore the original modification time.
>  
> > Well I'm not modifying the file in this case, though I do have
> > $edit_headers set - maybe that's what I need to change.
> 
> Maybe a better way of explaining...
> 
> I'm trying to do the equivalent of what :q! does in vim within a script.
> 
> So what would be most helpful would be a simple explanation of how
> message editing exactly works in mutt - the editor is invoked with a
> temporary filename passed to it by mutt - how does mutt know when the
> editor has written to the file or quit without writing to it?

Mutt

    1.  creates a temporary file,
    2.  writes the message to that file,
    3.  decrements the mtime of that file by 1 second,
    4.  invokes 'editor' upon that file with a system() call.

Mutt then waits for the call to system() to return, which happens 
when the user quits the editor.  Mutt then

    5.  checks the mtime of the temporary file.
    6.  If the mtime has changed, mutt
            a)  displays the compose menu,
            b)  waits for the next command from the user and 
                processes it accordingly.
        else, mutt
            a)  prints "Aborted unmodified message".
    7.  Mutt deletes the file.
    8.  Mutt waits for the next command from the user.

I've omitted a few details, but I think that adequately explains the 
part you're interested in.  In short:  mutt knows that the editor is 
done when system() returns and knows whether the file has been 
modified by comparing the current modification time to the 
modification time that mutt set.

Regards,
Gary

-- 
Gary Johnson                               | Agilent Technologies
garyjohn@xxxxxxxxxxxxxxx                   | Wireless Division
http://www.spocom.com/users/gjohnson/mutt/ | Spokane, Washington, USA