aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2022-06-27 11:51:08 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2022-06-27 11:51:08 -0400
commitead2b92216c135152f28f9847b52479fe279edf8 (patch)
treef600124fa8cf0c21090f8d4363c2b907d20d9a56
parentf057cb93e1094eceeedf86ce906aa90616541674 (diff)
downloadkorg-helpers-ead2b92216c135152f28f9847b52479fe279edf8.tar.gz
Add support to write out as maildir
It is periodically useful to save the archives as maildir instead of mailbox. Add support for -asmaildir. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-xlist-archive-maker.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/list-archive-maker.py b/list-archive-maker.py
index eed4807..9db319e 100755
--- a/list-archive-maker.py
+++ b/list-archive-maker.py
@@ -70,12 +70,17 @@ def formataddr(pair):
# drop the real name then.
return email.utils.formataddr((None, pair[1]))
-def process_archives(sources, outdir, msgids, listids, rejectsfile):
+def process_archives(sources, outdir, msgids, listids, rejectsfile, asmaildir):
outboxes = {}
writecount = {}
seenids = []
knownset = set(msgids)
+ if asmaildir:
+ outbox = mailbox.Maildir(outdir)
+ outboxes[outdir] = outbox
+ writecount[outdir] = 1
+
# convert listids into email addresses by replacing the first '.' to '@'.
# if you're working with a mailing list that has a non-standard list-id, you
# can specify the list email address as part of the listids to satisfy this check.
@@ -258,12 +263,14 @@ def process_archives(sources, outdir, msgids, listids, rejectsfile):
# fine, use the date in the message, even if it's bogus
msgdate = email.utils.parsedate_tz(str(msg['Date']))
- mboxname = '%04d-%02d.mbx' % (msgdate[0], msgdate[1])
+ if asmaildir:
+ mboxname = outdir
+ else:
+ mboxname = '%04d-%02d.mbx' % (msgdate[0], msgdate[1])
# do we have this mbox open already?
if mboxname in outboxes:
outbox = outboxes[mboxname]
- writecount[mboxname] += 1
else:
outbox = mailbox.mbox('%s/%s' % (outdir, mboxname))
outboxes[mboxname] = outbox
@@ -273,6 +280,7 @@ def process_archives(sources, outdir, msgids, listids, rejectsfile):
outbox.add(msg.as_string(policy=EMLPOLICY).encode())
seenids.append(msgid)
knownset.add(msgid)
+ writecount[mboxname] += 1
except:
# Oh well, toss it
pass
@@ -297,7 +305,7 @@ def process_archives(sources, outdir, msgids, listids, rejectsfile):
def main(args):
- if not os.path.isdir(args.exportdir):
+ if not args.asmaildir and not os.path.isdir(args.exportdir):
os.mkdir(args.exportdir)
if args.knownids and os.path.exists(args.knownids):
@@ -317,7 +325,7 @@ def main(args):
# Make list ID matching case insensitive to match more mail
listids = [listid.lower() for listid in args.listids]
- newids = process_archives(args.source, args.exportdir, knownids, listids, args.rejected)
+ newids = process_archives(args.source, args.exportdir, knownids, listids, args.rejected, args.asmaildir)
if newids is None or not args.knownids:
sys.exit(0)
@@ -342,6 +350,8 @@ if __name__ == '__main__':
'Paths with trailing "/" will be treated as maildirs.'))
parser.add_argument('-exportdir', required=True, default='list-archives',
help='Export dir where to put sanitized archives')
+ parser.add_argument('-asmaildir', action='store_true', default=False,
+ help='Export as maildir instead of mailboxes')
parser.add_argument('-knownids',
help='File with known Message-IDs (one per line)')
parser.add_argument('-listids', required=True, nargs='+',