MCPcopy Index your code
hub / github.com/RustPython/RustPython / Maildir

Class Maildir

Lib/mailbox.py:267–626  ·  view source on GitHub ↗

A qmail-style Maildir mailbox.

Source from the content-addressed store, hash-verified

265
266
267class Maildir(Mailbox):
268 """A qmail-style Maildir mailbox."""
269
270 colon = ':'
271
272 def __init__(self, dirname, factory=None, create=True):
273 """Initialize a Maildir instance."""
274 Mailbox.__init__(self, dirname, factory, create)
275 self._paths = {
276 'tmp': os.path.join(self._path, 'tmp'),
277 'new': os.path.join(self._path, 'new'),
278 'cur': os.path.join(self._path, 'cur'),
279 }
280 if not os.path.exists(self._path):
281 if create:
282 os.mkdir(self._path, 0o700)
283 for path in self._paths.values():
284 os.mkdir(path, 0o700)
285 else:
286 raise NoSuchMailboxError(self._path)
287 self._toc = {}
288 self._toc_mtimes = {'cur': 0, 'new': 0}
289 self._last_read = 0 # Records last time we read cur/new
290 self._skewfactor = 0.1 # Adjust if os/fs clocks are skewing
291
292 def add(self, message):
293 """Add message and return assigned key."""
294 tmp_file = self._create_tmp()
295 try:
296 self._dump_message(message, tmp_file)
297 except BaseException:
298 tmp_file.close()
299 os.remove(tmp_file.name)
300 raise
301 _sync_close(tmp_file)
302 if isinstance(message, MaildirMessage):
303 subdir = message.get_subdir()
304 suffix = self.colon + message.get_info()
305 if suffix == self.colon:
306 suffix = ''
307 else:
308 subdir = 'new'
309 suffix = ''
310 uniq = os.path.basename(tmp_file.name).split(self.colon)[0]
311 dest = os.path.join(self._path, subdir, uniq + suffix)
312 if isinstance(message, MaildirMessage):
313 os.utime(tmp_file.name,
314 (os.path.getatime(tmp_file.name), message.get_date()))
315 # No file modification should be done after the file is moved to its
316 # final position in order to prevent race conditions with changes
317 # from other programs
318 try:
319 try:
320 os.link(tmp_file.name, dest)
321 except (AttributeError, PermissionError):
322 os.rename(tmp_file.name, dest)
323 else:
324 os.remove(tmp_file.name)

Callers 2

get_folderMethod · 0.85
add_folderMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected