+ if domain_to.nil?
+ # There was no "@" in the destination user.
+ msg = "the destination user #{user_to} is not valid"
+ raise InvalidUserError.new(msg)
+ end
+
+ if not domain_exists(domain_to)
+ msg = "destination domain #{domain_to} does not exist"
+ raise NonexistentDomainError.new(msg)
+ end
+
+ mailbox_query = 'UPDATE mailbox SET '
+ mailbox_query += ' username=$1,'
+ mailbox_query += ' domain=$2,'
+ mailbox_query += " maildir=CONCAT($2, '/', $3, '/'),"
+ mailbox_query += ' local_part=$3 '
+ mailbox_query += 'WHERE username=$4;'
+
+ alias_query1 = 'UPDATE alias SET '
+ alias_query1 += ' address=$1,'
+ alias_query1 += ' domain=$2,'
+ alias_query1 += ' goto=REPLACE(goto, $4, $1) '
+ alias_query1 += 'WHERE address=$4;'