include PostfixadminPlugin
include MvPlugin
- def mv_user(user_from, user_to)
- if not user_exists(user_from)
- raise NonexistentUserError.new("source user #{user_from} does not exist")
- end
-
- user_to_parts = user_to.split('@')
- localpart_to = user_to_parts[0]
- domain_to = user_to_parts[1]
+ def mv_user(src, dst)
+ # It's obviously an error if the source user does not exist.
+ raise NonexistentUserError.new(src.to_s()) if not user_exists(src)
- if not domain_exists(domain_to)
- msg = "destination domain #{domain_to} does not exist"
- raise NonexistentDomainError.new(msg)
+ # And if the destination domain does not exist.
+ if not domain_exists(dst.domain())
+ raise NonexistentDomainError.new(dst.domain.to_s())
end
+ # But the destination *user* should *not* exist.
+ # And it's an error if the destination user exists already.
+ raise UserAlreadyExistsError.new(dst.to_s()) if user_exists(dst)
+
mailbox_query = 'UPDATE mailbox SET '
mailbox_query += ' username=$1,'
mailbox_query += ' domain=$2,'
sql_queries.each do |sql_query|
varchar = 1043 # from pg_type.h
- params = [{:value => user_to, :type => varchar},
- {:value => domain_to, :type => varchar},
- {:value => localpart_to, :type => varchar},
- {:value => user_from, :type => varchar}]
+ params = [{:value => dst.to_s(), :type => varchar},
+ {:value => dst.domainpart(), :type => varchar},
+ {:value => dst.localpart(), :type => varchar},
+ {:value => src.to_s(), :type => varchar}]
connection.query(sql_query, params)
end