convert meta files to new format when read
This commit is contained in:
@@ -142,10 +142,10 @@ def list_quarantine_emails(quarantines, args):
|
|||||||
for storage_id, metadata in emails.items():
|
for storage_id, metadata in emails.items():
|
||||||
row = emails[storage_id]
|
row = emails[storage_id]
|
||||||
row["storage_id"] = storage_id
|
row["storage_id"] = storage_id
|
||||||
row["date"] = time.strftime(
|
row["timestamp"] = time.strftime(
|
||||||
'%Y-%m-%d %H:%M:%S',
|
'%Y-%m-%d %H:%M:%S',
|
||||||
time.localtime(
|
time.localtime(
|
||||||
metadata["date"]))
|
metadata["timestamp"]))
|
||||||
row["mailfrom"] = metadata["mailfrom"]
|
row["mailfrom"] = metadata["mailfrom"]
|
||||||
row["recipient"] = metadata["recipients"].pop(0)
|
row["recipient"] = metadata["recipients"].pop(0)
|
||||||
if "subject" not in emails[storage_id]:
|
if "subject" not in emails[storage_id]:
|
||||||
@@ -156,7 +156,7 @@ def list_quarantine_emails(quarantines, args):
|
|||||||
if metadata["recipients"]:
|
if metadata["recipients"]:
|
||||||
row = {
|
row = {
|
||||||
"storage_id": "",
|
"storage_id": "",
|
||||||
"date": "",
|
"timestamp": "",
|
||||||
"mailfrom": "",
|
"mailfrom": "",
|
||||||
"recipient": metadata["recipients"].pop(0),
|
"recipient": metadata["recipients"].pop(0),
|
||||||
"subject": ""
|
"subject": ""
|
||||||
@@ -171,7 +171,7 @@ def list_quarantine_emails(quarantines, args):
|
|||||||
if not emails:
|
if not emails:
|
||||||
logger.info(f"quarantine '{args.quarantine}' is empty")
|
logger.info(f"quarantine '{args.quarantine}' is empty")
|
||||||
print_table(
|
print_table(
|
||||||
[("Quarantine-ID", "storage_id"), ("Date", "date"),
|
[("Quarantine-ID", "storage_id"), ("When", "timestamp"),
|
||||||
("From", "mailfrom"), ("Recipient(s)", "recipient"),
|
("From", "mailfrom"), ("Recipient(s)", "recipient"),
|
||||||
("Subject", "subject")],
|
("Subject", "subject")],
|
||||||
rows
|
rows
|
||||||
|
|||||||
@@ -187,7 +187,6 @@ class FileMailStorage(BaseMailStorage):
|
|||||||
metadata = {
|
metadata = {
|
||||||
"mailfrom": mailfrom,
|
"mailfrom": mailfrom,
|
||||||
"recipients": recipients,
|
"recipients": recipients,
|
||||||
"date": timegm(gmtime()),
|
|
||||||
"subject": subject,
|
"subject": subject,
|
||||||
"timestamp": timegm(gmtime()),
|
"timestamp": timegm(gmtime()),
|
||||||
"queue_id": qid,
|
"queue_id": qid,
|
||||||
@@ -210,7 +209,7 @@ class FileMailStorage(BaseMailStorage):
|
|||||||
# parsing of the message, catch all exceptions here
|
# parsing of the message, catch all exceptions here
|
||||||
try:
|
try:
|
||||||
subject = milter.msg["subject"] or ""
|
subject = milter.msg["subject"] or ""
|
||||||
except Exception as e:
|
except Exception:
|
||||||
subject = ""
|
subject = ""
|
||||||
else:
|
else:
|
||||||
data = milter.msg.as_bytes
|
data = milter.msg.as_bytes
|
||||||
@@ -242,6 +241,41 @@ class FileMailStorage(BaseMailStorage):
|
|||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"invalid metafile '{metafile}': {e}")
|
f"invalid metafile '{metafile}': {e}")
|
||||||
|
|
||||||
|
# convert metafile structure, this can be removed in the future
|
||||||
|
converted = False
|
||||||
|
if "subject" not in metadata:
|
||||||
|
try:
|
||||||
|
metadata["subject"] = metadata["headers"]["subject"]
|
||||||
|
except KeyError:
|
||||||
|
metadata["subject"] = ""
|
||||||
|
converted = True
|
||||||
|
if "timestamp" not in metadata:
|
||||||
|
try:
|
||||||
|
metadata["timestamp"] = metadata["date"]
|
||||||
|
except KeyError:
|
||||||
|
metadata["timestamp"] = 0
|
||||||
|
converted = True
|
||||||
|
if "vars" not in metadata:
|
||||||
|
try:
|
||||||
|
metadata["vars"] = metadata["named_subgroups"]
|
||||||
|
except KeyError:
|
||||||
|
metadata["vars"] = {}
|
||||||
|
converted = True
|
||||||
|
if "headers" in metadata:
|
||||||
|
del metadata["headers"]
|
||||||
|
converted = True
|
||||||
|
if "date" in metadata:
|
||||||
|
del metadata["date"]
|
||||||
|
converted = True
|
||||||
|
if "named_subgroups" in metadata:
|
||||||
|
del metadata["named_subgroups"]
|
||||||
|
converted = True
|
||||||
|
if "subgroups" in metadata:
|
||||||
|
del metadata["subgroups"]
|
||||||
|
converted = True
|
||||||
|
if converted:
|
||||||
|
self._save_metafile(metafile, metadata)
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
def find(self, mailfrom=None, recipients=None, older_than=None):
|
def find(self, mailfrom=None, recipients=None, older_than=None):
|
||||||
@@ -266,7 +300,8 @@ class FileMailStorage(BaseMailStorage):
|
|||||||
metafile[:-len(self._metadata_suffix)])
|
metafile[:-len(self._metadata_suffix)])
|
||||||
metadata = self.get_metadata(storage_id)
|
metadata = self.get_metadata(storage_id)
|
||||||
if older_than is not None:
|
if older_than is not None:
|
||||||
if timegm(gmtime()) - metadata["date"] < (older_than * 86400):
|
age = timegm(gmtime()) - metadata["timestamp"]
|
||||||
|
if age < (older_than * 86400):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if mailfrom is not None:
|
if mailfrom is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user