mirror of
https://git.code.sf.net/p/archivemail/code
synced 2025-01-02 21:24:40 +00:00
Only use the default archive name suffix when the user specified no affix
Also add more archive name affix testing to the test suite.
This commit is contained in:
parent
b6bc92c34f
commit
67f23e1af4
2 changed files with 41 additions and 12 deletions
|
@ -172,7 +172,8 @@ class StaleFiles:
|
||||||
class Options:
|
class Options:
|
||||||
"""Class to store runtime options, including defaults"""
|
"""Class to store runtime options, including defaults"""
|
||||||
archive_prefix = None
|
archive_prefix = None
|
||||||
archive_suffix = "_archive"
|
archive_suffix = None
|
||||||
|
archive_default_suffix = "_archive"
|
||||||
days_old_max = 180
|
days_old_max = 180
|
||||||
date_old_max = None
|
date_old_max = None
|
||||||
delete_old_mail = False
|
delete_old_mail = False
|
||||||
|
@ -1636,6 +1637,9 @@ def make_archive_name(mailbox_name):
|
||||||
else:
|
else:
|
||||||
tm = time.localtime(options.date_old_max)
|
tm = time.localtime(options.date_old_max)
|
||||||
prefix = suffix = ""
|
prefix = suffix = ""
|
||||||
|
if options.archive_prefix is None and options.archive_suffix is None:
|
||||||
|
suffix = options.archive_default_suffix
|
||||||
|
else:
|
||||||
if options.archive_prefix:
|
if options.archive_prefix:
|
||||||
prefix = time.strftime(options.archive_prefix, tm)
|
prefix = time.strftime(options.archive_prefix, tm)
|
||||||
if options.archive_suffix:
|
if options.archive_suffix:
|
||||||
|
|
|
@ -897,7 +897,6 @@ class TestArchiveMboxPreserveUnread(unittest.TestCase):
|
||||||
class TestArchiveMboxSuffix(unittest.TestCase):
|
class TestArchiveMboxSuffix(unittest.TestCase):
|
||||||
"""make sure the 'suffix' option works"""
|
"""make sure the 'suffix' option works"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_suffix = archivemail.options.archive_suffix
|
|
||||||
archivemail.options.quiet = True
|
archivemail.options.quiet = True
|
||||||
|
|
||||||
def testSuffix(self):
|
def testSuffix(self):
|
||||||
|
@ -915,14 +914,11 @@ class TestArchiveMboxSuffix(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
archivemail.options.quiet = False
|
archivemail.options.quiet = False
|
||||||
archivemail.options.archive_suffix = self.old_suffix
|
archivemail.options.archive_suffix = None
|
||||||
|
|
||||||
class TestArchiveMboxPrefix(unittest.TestCase):
|
class TestArchiveMboxPrefix(unittest.TestCase):
|
||||||
"""make sure the 'prefix' option works"""
|
"""make sure the 'prefix' option works"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_prefix = archivemail.options.archive_prefix
|
|
||||||
self.old_suffix = archivemail.options.archive_suffix
|
|
||||||
archivemail.options.archive_suffix = ""
|
|
||||||
archivemail.options.quiet = True
|
archivemail.options.quiet = True
|
||||||
|
|
||||||
def testPrefix(self):
|
def testPrefix(self):
|
||||||
|
@ -940,8 +936,37 @@ class TestArchiveMboxPrefix(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
archivemail.options.quiet = False
|
archivemail.options.quiet = False
|
||||||
archivemail.options.archive_prefix = self.old_prefix
|
archivemail.options.archive_prefix = None
|
||||||
archivemail.options.archive_suffix = self.old_suffix
|
|
||||||
|
class TestArchiveAffixes(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.mbox = "harbsch"
|
||||||
|
self.archive_prefix = "wurbl+"
|
||||||
|
self.archive_suffix = "+schronk&borsz"
|
||||||
|
archivemail.options.quiet = True
|
||||||
|
|
||||||
|
def testDefaultPrefix(self):
|
||||||
|
"""if no archive name affix is specified, the default archive suffix is appended"""
|
||||||
|
self.assertEqual(archivemail.make_archive_name(self.mbox),
|
||||||
|
self.mbox + archivemail.options.archive_default_suffix)
|
||||||
|
|
||||||
|
def testPrefixKillsDefaultSuffix(self):
|
||||||
|
"""if an archive name prefix is specified, the default archive suffix is not appended"""
|
||||||
|
archivemail.options.archive_prefix = self.archive_prefix
|
||||||
|
self.assertEqual(archivemail.make_archive_name(self.mbox),
|
||||||
|
self.archive_prefix + self.mbox)
|
||||||
|
|
||||||
|
def testPrefixAndSuffix(self):
|
||||||
|
"""specifying both an archive name prefix and suffix works"""
|
||||||
|
archivemail.options.archive_prefix = self.archive_prefix
|
||||||
|
archivemail.options.archive_suffix = self.archive_suffix
|
||||||
|
self.assertEqual(archivemail.make_archive_name(self.mbox),
|
||||||
|
self.archive_prefix + self.mbox + self.archive_suffix)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
archivemail.options.archive_prefix = None
|
||||||
|
archivemail.options.archive_suffix = None
|
||||||
|
archivemail.options.quiet = False
|
||||||
|
|
||||||
class TestArchiveDryRun(TestArchive):
|
class TestArchiveDryRun(TestArchive):
|
||||||
"""make sure the 'dry-run' option works"""
|
"""make sure the 'dry-run' option works"""
|
||||||
|
|
Loading…
Reference in a new issue