Index: Lib/mailbox.py =================================================================== --- Lib/mailbox.py (revision 53019) +++ Lib/mailbox.py (working copy) @@ -237,6 +237,8 @@ else: raise NoSuchMailboxError(self._path) self._toc = {} + self._cur_mtime = None # Records mtime of 'cur' directory + self._new_mtime = None # Records mtime of 'cur' directory def add(self, message): """Add message and return assigned key.""" @@ -457,12 +459,24 @@ def _refresh(self): """Update table of contents mapping.""" + new_mtime = os.path.getmtime(os.path.join(self._path, 'new')) + cur_mtime = os.path.getmtime(os.path.join(self._path, 'cur')) + + if new_mtime == self._new_mtime and cur_mtime == self._cur_mtime: + return + self._toc = {} - for subdir in ('new', 'cur'): - for entry in os.listdir(os.path.join(self._path, subdir)): + def update_dir (subdir): + path = os.path.join(self._path, subdir) + for entry in os.listdir(path): uniq = entry.split(self.colon)[0] self._toc[uniq] = os.path.join(subdir, entry) - + + update_dir('new') + update_dir('cur') + self._new_mtime = new_mtime + self._cur_mtime = cur_mtime + def _lookup(self, key): """Use TOC to return subpath for given key, or raise a KeyError.""" try: