Skip to content

Instantly share code, notes, and snippets.

@av-gantimurov
Last active August 5, 2021 00:53
Show Gist options
  • Save av-gantimurov/cccf64e346fc620b2f20eb2ead9596bf to your computer and use it in GitHub Desktop.
Save av-gantimurov/cccf64e346fc620b2f20eb2ead9596bf to your computer and use it in GitHub Desktop.
Fix munpack UTF-8 names in attachments
#!/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
@av-gantimurov
Copy link
Author

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.

@gilles0606
Copy link

no suport space in name

@gilles0606
Copy link

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

@IsaacN72
Copy link

IsaacN72 commented Aug 5, 2021

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