]>
gitweb.michael.orlitzky.com - mailshears.git/blob - plugins/postfixadmin.rb
3 require 'common/postfixadmin_plugin'
8 include PostfixadminPlugin
12 # It's obviously an error if the source user does not exist.
13 raise NonexistentUserError
.new(src
.to_s()) if not user_exists(src
)
15 # And if the destination domain does not exist.
16 if not domain_exists(dst
.domain())
17 raise NonexistentDomainError
.new(dst
.domain
.to_s())
20 # But the destination *user* should *not* exist.
21 # And it's an error if the destination user exists already.
22 raise UserAlreadyExistsError
.new(dst
.to_s()) if user_exists(dst
)
24 mailbox_query
= 'UPDATE mailbox SET '
25 mailbox_query +
= ' username=$1,'
26 mailbox_query +
= ' domain=$2,'
27 mailbox_query +
= " maildir=CONCAT($2, '/', $3, '/'),"
28 mailbox_query +
= ' local_part=$3 '
29 mailbox_query +
= 'WHERE username=$4;'
31 alias_query1
= 'UPDATE alias SET '
32 alias_query1 +
= ' address=$1,'
33 alias_query1 +
= ' domain=$2,'
34 alias_query1 +
= ' goto=REPLACE(goto, $4, $1) '
35 alias_query1 +
= 'WHERE address=$4;'
37 alias_query2
= 'UPDATE alias SET '
38 alias_query2 +
= 'goto=REPLACE(goto, $4, $1);'
40 sql_queries
= [mailbox_query
, alias_query1
, alias_query2
]
43 connection
= PGconn
.connect(@db_host,
51 sql_queries
.each
do |sql_query
|
52 varchar
= 1043 # from pg_type.h
53 params
= [{:value => dst
.to_s(), :type => varchar
},
54 {:value => dst
.domainpart(), :type => varchar
},
55 {:value => dst
.localpart(), :type => varchar
},
56 {:value => src
.to_s(), :type => varchar
}]
57 connection
.query(sql_query
, params
)
63 # Pretend like we're database-agnostic in case we ever are.
64 raise DatabaseError
.new(e
)