diff --git a/fix-duplicate-mail-ids b/fix-duplicate-mail-ids old mode 100644 new mode 100755 diff --git a/fix-maildir-mbsync-duplicate-uid b/fix-maildir-mbsync-duplicate-uid new file mode 100755 index 0000000..c5dc935 --- /dev/null +++ b/fix-maildir-mbsync-duplicate-uid @@ -0,0 +1,27 @@ +#!/bin/sh +# Nico Schottelius, 2024-05-08 +# Can also be run in a loop with: +# for uid in $(find . | grep -o 'U=.*:' | sort | uniq -d | sed -e 's/U=//' -e 's/:$//') ; do fix-maildir-mbsync-duplicate-uid $uid; done + +if [ $# -ne 1 ]; then + echo $0 UID + echo "Remove the UID from the newer message" +fi + +MAIL_UID=$1 + +i=0 + +for mail in $(ls *U=${MAIL_UID}:*); do + i=$((i+1)) + # Do not rename the first one + if [ $i = 1 ]; then + continue + fi + + # Rename all others + new_name=$(echo $mail | sed 's/,U=.*//') + + echo "Renaming $mail to $new_name" + mv $mail $new_name +done