]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/dovecot.rb
3 require 'common/filesystem'
4 require 'common/dovecot_plugin'
12 def mv_user(user_from
, user_to
)
13 # Move the user's mail directory from one domain (that should
14 # exist) to another domain (that should exist).
16 # This is actually a little subtle, because none of the
17 # directories in question have to exist. If I create two new
18 # domains in postfixadmin and one mailbox but never deliver any
19 # mail, it should be possible to move the mailbox to the other
20 # domain. No directories will exist until mail is delivered,
23 # get_user_path() will fail if there's no mailbox to move. It will
24 # also fail on an invalid user -- oh well!
26 from_path
= self.get_user_path(user_from
)
27 rescue NonexistentUserError
28 # Do nothing, there's no source mailbox...
32 # We may need to create the target domain directory, even if the
33 # domain exists in the database.
34 domain_to
= user_to
.split('@')[1]
35 domain_dir
= self.get_domain_path(domain_to
)
36 FileUtils
.mkdir_p(domain_dir
)
38 # The from_path exists or else we would have returned earlier. The
39 # parent of to_path exists because we just created it.
40 to_path
= self.get_user_path(user_to
, false)
41 FileUtils
.mv(from_path
, to_path
)