def __init__(self, dirname, factory=None, create=True, access=0o700,
uid=None, gid=None):
"""Like the parent but allows specification of permission, uid, and
gid if creating."""
# pylint: disable=W0233, W0231
mailbox.Mailbox.__init__(self, dirname, factory, create)
self._paths = {
'tmp': os.path.join(self._path, 'tmp'),
'new': os.path.join(self._path, 'new'),
'cur': os.path.join(self._path, 'cur'),
}
exists = os.path.exists(self._path)
is_mailbox = (os.path.exists(self._paths["tmp"]) and
os.path.exists(self._paths["new"]) and
os.path.exists(self._paths["cur"]))
if not is_mailbox:
if create:
mask = os.umask(0o000)
if not exists:
try:
os.mkdir(self._path, access)
except OSError as e:
# If another process has simultaneously created
# this mailbox, that's fine.
if e.errno != 17:
raise
os.chmod(self._path, stat.S_IRWXU | stat.S_IRWXG |
stat.S_IRWXG | stat.S_ISGID)
if uid and gid:
os.chown(self._path, uid, gid)
elif uid:
os.chown(self._path, uid, -1)
elif gid:
os.chown(self._path, -1, gid)
for path in self._paths.values():
if not os.path.exists(path):
try:
os.mkdir(path, access)
except OSError as e:
# If another process has simultaneously created
# this mailbox, that's fine.
if e.errno != 17:
raise
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXG |
stat.S_ISGID)
if uid and gid:
os.chown(path, uid, gid)
elif uid:
os.chown(path, uid, -1)
elif gid:
os.chown(path, -1, gid)
os.umask(mask)
else:
raise mailbox.NoSuchMailboxError(self._path)
self._toc = {}
self._toc_mtimes = {'cur': 0, 'new': 0}
self._last_read = 0 # Records last time we read cur/new
self._skewfactor = 0.1 # Adjust if os/fs clocks are skewing
评论列表
文章目录