I want to read mails from a mbox file and do some action based on that. I don't want to write/modify the mbox file but it will be modified by another process (Mostly adding new mails).
I am reading this documentation. http://docs.python.org/library/mailbox.html#mailbox.mbox
But I don't understand the following
PS: I am not allowed to install any plugins of thunderbird:(
No need to call Mailbox.lock()
when you don't modify the mbox. A quote from the documentation of Mailbox.lock()
(emphasis my own):
You should always lock the mailbox before making any modifications to its contents.
Notification on file changes is out of the scope of the mailbox module. On Linux systems you can use pyinotify to get this functionality.
This is also answered in the documentation:
The default Mailbox iterator iterates over message representations, not keys as the default dictionary iterator does. Moreover, modification of a mailbox during iteration is safe and well-defined. Messages added to the mailbox after an iterator is created will not be seen by the iterator. Messages removed from the mailbox before the iterator yields them will be silently skipped, though using a key from an iterator may result in > a KeyError exception if the corresponding message is subsequently removed.
In short, you need to create a new Mailbox
instance, after the mbox file has changed.