#!/usr/pkg/bin/ruby18 # move_old_mailboxes.rb - Archive virtual mailboxes no longer is use # Copyright 2007 Eric Shane Radman # # This is free software; you may redistribute, modify, and use it under the # terms of the Modified BSD License. require "dbi" require "find" def move_boxes() dbh = DBI.connect('DBI:Pg:system') dir = '/var/mail' sql = %{ SELECT email FROM users WHERE email=? AND mail='t' } conn = dbh.prepare("SELECT domain FROM transport") conn.execute() domains = conn.fetch_all for domain in domains do conn = dbh.prepare(sql) Find.find(dir + '/' + domain[0]) do |path| if FileTest.directory?(path) parts = path.split('/') if parts.length == 5 then conn.execute(parts[4] + '@' + parts[3]) users = conn.fetch if not users then print parts[4] + '@' + parts[3] sleep(0.5) print " ... copying" print `cp -r #{path} /archive` print " ... removing" print `rm -r #{path}` puts else puts 'Skipping ' + parts[4] + '@' + parts[3] + ' ' end end end end end end if $0 == __FILE__ move_boxes() end