mailbox.mbox.add() sets access time as well as modification time

Grant Edwards invalid at invalid
Sat Apr 25 13:30:08 EDT 2009


On 2009-04-25, tinnews at isbd.co.uk <tinnews at isbd.co.uk> wrote:
> Grant Edwards <invalid at invalid> wrote:
>> On 2009-04-24, Grant Edwards <invalid at invalid> wrote:
>> 
>> > Anybody writing to an mbox mailbox has to follow the rules if
>> > they expect to interoperate with other mail applications.  If
>> > mailbox.mbox.add() doesn't preserve the atime when writing to
>> > an mbox, then mailbox.mbox.add is broken.
>> 
>> I should qualify that: since the documentation for add()
>> doesn't specify whether or not it's supposed to add a "new"
>> message or an "old" message, one could argue that either
>> behavior is correct.
>> 
>> However, since the maildir add() method adds a "new" message,
>> one would reasonably expect that the mbox add() method do the
>> same.  Or, I suppose one might expect the converse: since mbox
>> add() creates an "old" message, then maildir add() should do
>> the same.
>> 
>> I have my filesystems mouted with the "noatime" option and use
>> maildir...
>
> Whatever, if mailbox.mbox.add() doesn't preserve the atime when adding
> messages to an mbox then it's close to useless.

That's what I said: it's broken.  Nobody is arguing that it
isn't.  The question is who's going to step up and fix it.
Those of us who don't use mbox format are a bit less motivated
than those who do.

> I suppose I could do the following:-
>
>     lock the mbox
>     get the atime
>     add the new message with mailbox.mbox.add()
>     restore the atime
>     unlock the mbox

You could fix mbox.add().  ;)

> All I need to do now is find out how to get and set atime with python.

You use os.utime().

>From http://docs.python.org/library/os.html#module-os:

os.utime(path, times)

    Set the access and modified times of the file specified by
    path. If times is None, then the file's access and
    modified times are set to the current time. (The effect is
    similar to running the Unix program touch on the path.)
    Otherwise, times must be a 2-tuple of numbers, of the form
    (atime, mtime) which is used to set the access and modified
    times, respectively. Whether a directory can be given for
    path depends on whether the operating system implements
    directories as files (for example, Windows does not). Note
    that the exact times you set here may not be returned by a
    subsequent stat() call, depending on the resolution with
    which your operating system records access and modification
    times; see stat().

    Changed in version 2.0: Added support for None for times.

    Availability: Unix, Windows.


-- 
Grant Edwards                   grante             Yow! My vaseline is
                                  at               RUNNING...
                               visi.com            



More information about the Python-list mailing list