Last active
August 29, 2015 14:04
-
-
Save ik5/97705b52f9d4c072f3e9 to your computer and use it in GitHub Desktop.
moving maildir from disorgenized method to an orginized method.
This file contains hidden or 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 | |
require 'fileutils' | |
SOURCE = '/tmp/mbox/' | |
DESTINATION = '/tmp/maildir/domain.com/' | |
def is_maildir(path) | |
dirs = Dir[File.join(path, '*')] | |
dirs.select {|name| File.directory?(File.join(path, name)) && | |
!(name == '.' or name == '..') } | |
dirs.include?(File.join(path,'new')) && | |
dirs.include?(File.join(path,'Trash')) && | |
dirs.include?(File.join(path,'tmp')) | |
end | |
def lookup(path) | |
valid = [] | |
Dir.foreach(path) do |name| | |
next if name == '.' or name == '..' | |
fpath = File.join(path,name) | |
#print "Going over #{fpath} ... " | |
next unless File.directory?(fpath) | |
if is_maildir(fpath) | |
valid.push(fpath) | |
#puts 'yes' | |
else | |
#puts 'no' | |
valid = valid + lookup(fpath) | |
end | |
end | |
return valid | |
end | |
FileUtils::mkdir_p(DESTINATION) | |
list = lookup(SOURCE) | |
list.each do |dir| | |
print "Copying #{dir} to #{DESTINATION} ... " | |
begin | |
FileUtils::cp_r(dir, DESTINATION) | |
rescue => e | |
puts "Error: #{e.message}" | |
else | |
puts 'done' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
הי,
קצת ארוך... לא יותר פשוט:
find . -type d -exec bash -c "[[ -d {}/new && -d {}/Trash && -d {}/tmp ]] && echo {}" ;