gh-66515: mailbox.MH now supports folders withou the ".mh_sequences" file (GH-804)

(for example Claws Mail IMAP-cache folders).
This commit is contained in:
Serhiy Storchaka 2023-12-26 11:15:14 +02:00 committed by GitHub
parent b5dc0f83ad
commit e87cadc1ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View file

@ -1198,7 +1198,11 @@ class MH(Mailbox):
def get_sequences(self):
"""Return a name-to-key-list dictionary to define each sequence."""
results = {}
with open(os.path.join(self._path, '.mh_sequences'), 'r', encoding='ASCII') as f:
try:
f = open(os.path.join(self._path, '.mh_sequences'), 'r', encoding='ASCII')
except FileNotFoundError:
return results
with f:
all_keys = set(self.keys())
for line in f:
try:
@ -1221,9 +1225,8 @@ class MH(Mailbox):
def set_sequences(self, sequences):
"""Set sequences using the given name-to-key-list dictionary."""
f = open(os.path.join(self._path, '.mh_sequences'), 'r+', encoding='ASCII')
f = open(os.path.join(self._path, '.mh_sequences'), 'w', encoding='ASCII')
try:
os.close(os.open(f.name, os.O_WRONLY | os.O_TRUNC))
for name, keys in sequences.items():
if len(keys) == 0:
continue