Last active
August 5, 2021 00:53
-
-
Save av-gantimurov/cccf64e346fc620b2f20eb2ead9596bf to your computer and use it in GitHub Desktop.
Fix munpack UTF-8 names in attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
find . -type f -iname '*X=' | while read name | |
do | |
newname=$(echo "$name" | sed 's/[[:print:]]*\/=Xutf-8XBX//I; s/X=XXX=Xutf-8XBX//gI; s/X=$//' | base64 -d ) | |
dir=$(echo $name | sed 's/\/=Xutf-8XBX[A-Za-z0-9X=/+-]\+//I') | |
mv --verbose "$name" "${dir}/${newname}" | |
done |
no suport space in name
i do this for name with space
find . -type f -iname 'X=' | while read name
do
newname=$(echo "$name" | sed 's/[[:print:]]/=XUTF-8XBX//I; s/X=XXX=XUTF-8XBX//gI; s/X==XUTF-8XBX//gI; s/X=$//' | base64 -d )
newnamenoespace=$(echo "$newname" | sed 's/ /_/g')
dir=$(echo $name | sed 's//=Xutf-8XBX[A-Za-z0-9X=/+-]+//I')
mv --verbose "$name" "${dir}/${newnamenoespace}"
done
Thanks both av-gantimurov and gilles0606 for your contributions. Simple, yet effective solutions, much appreciated even years later!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple script which renames attaches decoded by munpack with UTF-8 encoded names.
Run it in directory with attaches.
Supports names in upper and lower cases.
Supports names with slash in it.