--- /dev/null
+require 'pg'
+
+require 'common/postfixadmin_plugin'
+require 'mv/mv_plugin'
+
+class PostfixadminMv
+
+ include PostfixadminPlugin
+ include MvPlugin
+
+
+ def mv_user(user_from, user_to)
+ raise NonexistentUserError.new(user_from) if not user_exists(user_from)
+
+ user_to_parts = user_to.split('@')
+ localpart_to = user_to_parts[0]
+ domain_to = user_to_parts[1]
+
+ sql_queries = ['UPDATE mailbox SET username=$1,
+ domain=$2,
+ maildir=$2/$3/,
+ local_part=$3
+ WHERE username=$4;']
+
+ sql_queries = ['UPDATE alias SET address=$1,
+ domain=$2,
+ goto=REPLACE(goto, $4, $1);
+ WHERE address=$4;']
+
+ sql_queries = ['UPDATE alias SET goto=REPLACE(GOTO, $4, $1);']
+
+ begin
+ connection = PGconn.connect(@db_host,
+ @db_port,
+ @db_opts,
+ @db_tty,
+ @db_name,
+ @db_user,
+ @db_pass)
+
+ sql_queries.each do |sql_query|
+ connection.query(sql_query, [user_to,
+ domain_to,
+ localpart_to,
+ user_from])
+ end
+
+ connection.close()
+
+ rescue PGError => e
+ # Pretend like we're database-agnostic in case we ever are.
+ raise DatabaseError.new(e)
+ end
+ end
+
+
+ def mv_domain(domain_from, domain_to)
+ raise NotImplementedError
+ end
+
+end