Treat a known Message-ID as a duplicate in the mail importer
Outlook for Mac rewrites headers on every export, so a re-exported message never hashes the same twice. Hash-only matching stored each re-export as a variant beside the original.
This commit is contained in:
1 parent
011bdc2947
commit
7c8db7999a
2 files changed
+13
-13
No files matched your search
+9
-11
@@ -150,7 +150,7 @@ def main():
|
||||
parser.error(f"could not scan source directory: {error}")
|
||||
messages = [path for path in files if path.suffix.lower() == ".eml"]
|
||||
unsupported = [path for path in files if path.suffix.lower() != ".eml"]
|
||||
imported = duplicates = variants = failures = 0
|
||||
imported = duplicates = failures = 0
|
||||
|
||||
for path in sorted(messages):
|
||||
try:
|
||||
@@ -161,12 +161,13 @@ def main():
|
||||
continue
|
||||
|
||||
headers = read_headers(path)
|
||||
if headers["message_id"] and headers["message_id"] in message_ids:
|
||||
print(f"DUPLICATE {path.relative_to(source)}")
|
||||
duplicates += 1
|
||||
continue
|
||||
|
||||
target = destination(archive, headers, digest)
|
||||
is_variant = bool(
|
||||
headers["message_id"] and headers["message_id"] in message_ids
|
||||
)
|
||||
label = "VARIANT" if is_variant else "IMPORT"
|
||||
print(f"{label} {path.relative_to(source)} -> {target.relative_to(archive)}")
|
||||
print(f"IMPORT {path.relative_to(source)} -> {target.relative_to(archive)}")
|
||||
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
temporary = target.with_name(f".{target.name}.{os.getpid()}.tmp")
|
||||
@@ -191,10 +192,7 @@ def main():
|
||||
hashes.add(digest)
|
||||
if headers["message_id"]:
|
||||
message_ids.add(headers["message_id"])
|
||||
if is_variant:
|
||||
variants += 1
|
||||
else:
|
||||
imported += 1
|
||||
imported += 1
|
||||
except (OSError, ValueError) as error:
|
||||
print(f"FAILED {path.relative_to(source)}: {error}")
|
||||
failures += 1
|
||||
@@ -205,7 +203,7 @@ def main():
|
||||
write_index(archive, rows)
|
||||
|
||||
print(
|
||||
f"{imported} imported, {variants} variants, {duplicates} duplicates, "
|
||||
f"{imported} imported, {duplicates} duplicates, "
|
||||
f"{len(unsupported)} unsupported, {failures} failures"
|
||||
)
|
||||
return 1 if failures or unsupported else 0
|
||||
|
||||
Reference in new issue
Block a user