diff options
author | Ben Sima <ben@bensima.com> | 2025-04-18 12:52:41 -0400 |
---|---|---|
committer | Ben Sima <ben@bensima.com> | 2025-04-18 12:52:41 -0400 |
commit | a6d62663e20fb5d1359845017787c85c4b10746f (patch) | |
tree | 3d949ed83abacb80c2ac0c50a6f52ef5087febb8 /find-mail-duplicates.sh | |
parent | 7cf00fd9819f663cd411f1079cbbd22127ec7941 (diff) |
mail duplicates one-off script
Diffstat (limited to 'find-mail-duplicates.sh')
-rwxr-xr-x | find-mail-duplicates.sh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/find-mail-duplicates.sh b/find-mail-duplicates.sh new file mode 100755 index 0000000..c8ae097 --- /dev/null +++ b/find-mail-duplicates.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# find-mail-duplicates.sh +# Usage: find-mail-duplicates.sh /path/to/maildir + +set -e + +# Check if a maildir path was provided +if [ $# -lt 1 ]; then + echo "Usage: $0 /path/to/maildir" + echo "Example: $0 ~/Mail/ben@bensima.com/Trash" + exit 1 +fi + +MAILDIR="$1" + +# Validate the maildir +if [ ! -d "$MAILDIR" ]; then + echo "Error: Maildir '$MAILDIR' does not exist or is not a directory" + exit 1 +fi + + +# Find all UIDs in the maildir +TMP_UID_FILE=$(mktemp) +find "$MAILDIR" -type f -name "*,U=*" | sed -E 's/.*,U=([0-9]+)[,:].*/\1/' | sort > "$TMP_UID_FILE" + +# Find duplicated UIDs +DUPLICATE_UIDS=$(uniq -d "$TMP_UID_FILE") + +# Count duplicates +DUPLICATE_COUNT=$(echo "$DUPLICATE_UIDS" | wc -l) +if [ -z "$DUPLICATE_UIDS" ]; then + echo "No duplicate UIDs found in $MAILDIR" + rm "$TMP_UID_FILE" + exit 0 +fi + + +# Process each duplicate UID +for UID_NUM in $DUPLICATE_UIDS; do + echo "$MAILDIR $UID_NUM" + # echo "--------------------------------------------" + # echo "Duplicate UID: $UID_NUM" + + # # Find messages with this UID + # DUPLICATE_FILES=$(find "$MAILDIR" -type f -name "*,U=$UID_NUM[,:]*") + # FILE_COUNT=$(echo "$DUPLICATE_FILES" | wc -l) + + # echo "Found $FILE_COUNT messages with UID $UID_NUM" + + # # List the duplicates + # for f in $DUPLICATE_FILES; do + # echo " $f" + # done + + # echo "To fix these duplicates, run:" + # echo " fix-mail-duplicates.sh \"$MAILDIR\" $UID_NUM" +done + +rm "$TMP_UID_FILE" |