Last active
July 14, 2022 23:20
-
-
Save nykma/2f6e55f28ae27537de32654e0a1e9e63 to your computer and use it in GitHub Desktop.
Symlink UTF-7 directory name into an UTF-8 version
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
#!/usr/bin/env ruby | |
# Maildir folder: create an UTF-8 symlink to original UTF-7 maildir. | |
# For example, it will create a symlink named '所有邮件' to a directory | |
# named '&YkBnCZCuTvY-' | |
utf7_dirs = Dir.entries(Dir.pwd).select do |dir| | |
dir.start_with?("&") | |
end | |
utf7_dirs.each do |dir| | |
utf7 = dir.gsub('&', '+').gsub(',', '/') | |
utf8 = (`echo '#{utf7}' | iconv -f UTF-7 -t UTF-8`).chomp | |
unless File.exists?(utf8) | |
File.symlink(dir, utf8) | |
puts "#{dir} => #{utf8}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment