Issue7359
Created on 2009-11-19 16:15 by doko, last changed 2012-06-18 18:35 by petri.lehtinen. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg95486 - (view) | Author: Matthias Klose (doko) * ![]() |
Date: 2009-11-19 16:15 | |
no change in behaviour in 2.6
the mailbox module in python 2.5 cannot modify mboxes in read-only
directories, e.g. the system mail spool. This is because
mailbox._singlefileMailbox.flush() tries to write the modified mailbox
to a temporary file and then rename it. See:
penelope[tmp]$ python2.5
Python 2.5 (release25-maint, Dec 9 2006, 14:35:53)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mailbox
>>> mbox = mailbox.mbox("/var/mail/nikolaus")
>>> mbox.clear()
>>> mbox.close()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/mailbox.py", line 623, in close
self.flush()
File "/usr/lib/python2.5/mailbox.py", line 570, in flush
new_file = _create_temporary(self._path)
File "/usr/lib/python2.5/mailbox.py", line 1885, in _create_temporary
os.getpid()))
File "/usr/lib/python2.5/mailbox.py", line 1875, in _create_carefully
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR)
OSError: [Errno 13] Permission denied:
'/tmp/mail/nikolaus.1195061622.penelope.4241'
>>>
|
|||
| msg95522 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2009-11-20 01:34 | |
The same remark as in issue7360, that is it is not robust at all to overwrite the file rather than doing an atomic rename from a temporary file. The only possible exception would be if you only /append/ to the mbox file (and that's assuming all mailbox-reading software you use be able to deal with a partially written message at the end of an mbox file). |
|||
| msg122994 - (view) | Author: Ole Laursen (olau) | Date: 2010-12-01 13:40 | |
Just got bitten by this too. Renaming is good and all, but as far as I can tell, it will never work with the system spool. It's not just that you can't create a temporary file in the directory, you can't rename files into it either. If I create an empty file somewhere and try to rename it to overwrite my mailbox, I get a permission denied. Sad. :( So I think you have to bite the bullet and write directly to the file. Either that or define that the module can't be used to work with system spool mailboxes, at least on Debian. But that would be even more sad. |
|||
| msg135240 - (view) | Author: Steffen Daode Nurpmeso (sdaoden) | Date: 2011-05-05 20:37 | |
Issue #11935 becomes gigantic and may even swamp this one over! |
|||
| msg163112 - (view) | Author: Petri Lehtinen (petri.lehtinen) * ![]() |
Date: 2012-06-18 18:35 | |
Every program that accesses mailboxes in the system-wide mail spool directory needs to have write access to it. This is because dot-locking is achieved by creating additional files to that directory, and it must be used (in addition to fcntl() locking) to avoid messing up the mailboxes because of concurrent access.
In Debian, /var/mail is owned by root:mail with mode 2755, and every MUA is setgid mail. See the Debian Policy Manual section 11.6 for more information:
http://www.debian.org/doc/debian-policy/ch-customized-programs.html#s-mail-transport-agents
If you write a MUA or MTA using Python's mailbox module, your program needs to have write access to /var/mail. That's the only way to do it correctly. It also makes the mailbox module's renaming behavior possible.
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2012-06-18 18:35:41 | petri.lehtinen | set | status: open -> closed nosy: + petri.lehtinen messages: + msg163112 resolution: invalid stage: committed/rejected |
| 2011-05-05 20:37:07 | sdaoden | set | nosy:
+ sdaoden messages: + msg135240 |
| 2010-12-01 13:40:40 | olau | set | nosy:
+ olau messages: + msg122994 |
| 2009-11-20 01:34:37 | pitrou | set | priority: normal versions: + Python 2.7, Python 3.2 nosy: + akuchling, pitrou messages: + msg95522 |
| 2009-11-19 16:15:24 | doko | create | |
