]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/dovecot.rb
3 require 'common/filesystem'
4 require 'common/dovecot_plugin'
8 # Handle moving (renaming) Dovecot users on the filesystem.
16 # Move the Dovecot user *src* to *dst*. This relocates the user's
17 # directory within the Dovecot mailstore (on the filesystem).
19 # This fails if the source user does not exist, or if the
20 # destination user already exists before the move.
22 # But is it an error if the target domain does not exist? That's a
23 # bit subtle... The domain may exist in the database, but if it
24 # has not received any mail yet, then its directory won't exist
27 # There are two possible "oops" scenarios resulting from the fact
28 # that we may run either the Postfixadmin move first or the
29 # Dovecot move first. If we move the user in the database, we
30 # definitely want to move him on disk (that is, we should create
31 # the directory here). But if we move him on disk first, then we
32 # don't know if the database move will fail! We don't want to move
33 # his mail files if he won't get moved in the database.
35 # Faced with two equally-bad (but easy-to-fix) options, we do the
36 # simplest thing and fail if the destination domain directory
37 # doesn't exist. If nothing else, this is at least consistent.
39 # @param src [User] the source user to be moved.
41 # @param dst [User] the destination user being moved to.
44 raise NonexistentUserError
.new(src
.to_s()) if not user_exists(src
)
45 raise UserAlreadyExistsError
.new(dst
.to_s()) if user_exists(dst
)
47 # See the docstring...
48 if not self.domain_exists(dst
.domain()) then
49 raise NonexistentDomainError
.new(dst
.domainpart())
52 # We may need to create the target domain directory, even if the
53 # domain exists in the database.
54 FileUtils
.mkdir_p(self.get_domain_path(dst
.domain()))
56 # The parent of dst_path exists because we just created it.The
57 # source path should exist too, because the "source user" does,
58 # and, well, how did we determine that?
59 src_path
= self.get_user_path(src
)
60 dst_path
= self.get_user_path(dst
)
61 FileUtils
.mv(src_path
, dst_path
)