]>
gitweb.michael.orlitzky.com - mailshears.git/blob - postfixadmin.rb
82ddf055c4b1bd747fb6f1319e344ad8b26c3055
3 require 'common/postfixadmin_plugin'
8 include PostfixadminPlugin
11 def mv_user(user_from
, user_to
)
12 if not user_exists(user_from
)
13 raise NonexistentUserError
.new("source user #{user_from} does not exist")
16 user_to_parts
= user_to
.split('@')
17 localpart_to
= user_to_parts
[0]
18 domain_to
= user_to_parts
[1]
21 # There was no "@" in the destination user.
22 msg
= "the destination user #{user_to} is not valid"
23 raise InvalidUserError
.new(msg
)
26 if not domain_exists(domain_to
)
27 msg
= "destination domain #{domain_to} does not exist"
28 raise NonexistentDomainError
.new(msg
)
31 mailbox_query
= 'UPDATE mailbox SET '
32 mailbox_query +
= ' username=$1,'
33 mailbox_query +
= ' domain=$2,'
34 mailbox_query +
= " maildir=CONCAT($2, '/', $3, '/'),"
35 mailbox_query +
= ' local_part=$3 '
36 mailbox_query +
= 'WHERE username=$4;'
38 alias_query1
= 'UPDATE alias SET '
39 alias_query1 +
= ' address=$1,'
40 alias_query1 +
= ' domain=$2,'
41 alias_query1 +
= ' goto=REPLACE(goto, $4, $1) '
42 alias_query1 +
= 'WHERE address=$4;'
44 alias_query2
= 'UPDATE alias SET '
45 alias_query2 +
= 'goto=REPLACE(goto, $4, $1);'
47 sql_queries
= [mailbox_query
, alias_query1
, alias_query2
]
50 connection
= PGconn
.connect(@db_host,
58 sql_queries
.each
do |sql_query
|
59 varchar
= 1043 # from pg_type.h
60 params
= [{:value => user_to
, :type => varchar
},
61 {:value => domain_to
, :type => varchar
},
62 {:value => localpart_to
, :type => varchar
},
63 {:value => user_from
, :type => varchar
}]
64 connection
.query(sql_query
, params
)
70 # Pretend like we're database-agnostic in case we ever are.
71 raise DatabaseError
.new(e
)