summaryrefslogtreecommitdiffstats
path: root/Lib/mailbox.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-12-26 09:15:14 (GMT)
committerGitHub <noreply@github.com>2023-12-26 09:15:14 (GMT)
commite87cadc1ce194aae2c076e81298d6e8074f1bb45 (patch)
tree3cdba116c8e0f1aa0b93e41270968e932f4846f3 /Lib/mailbox.py
parentb5dc0f83adda0bde1b176c3a84cc31cd94254e73 (diff)
downloadcpython-e87cadc1ce194aae2c076e81298d6e8074f1bb45.zip
cpython-e87cadc1ce194aae2c076e81298d6e8074f1bb45.tar.gz
cpython-e87cadc1ce194aae2c076e81298d6e8074f1bb45.tar.bz2
gh-66515: mailbox.MH now supports folders withou the ".mh_sequences" file (GH-804)
(for example Claws Mail IMAP-cache folders).
Diffstat (limited to 'Lib/mailbox.py')
-rw-r--r--Lib/mailbox.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 574c014..0e1d49b 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -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