SQL template: create VIEW in PostgreSQL database for iRedMail
opened this issue · comments
Deleted user commented
Here's SQL template used to create VIEW in PostgreSQL for iRedMail, tested with Roundcubemail-1.1.0 with PostgreSQL-8.4.20 on CentOS 6 (iRedMail-0.9.0).
-- RHEL/CentOS 6.
-- CREATE LANGUAGE plpgsql;
-- \i /usr/share/pgsql/contrib/dblink.sql;
-- RHEL/CentOS 7
-- CREATE EXTENSION dblink;
CREATE VIEW global_addressbook AS
SELECT * FROM dblink('host=127.0.0.1 port=5432 user=xxx password=xxxx dbname=xxx', 'SELECT extract(epoch FROM created), name, username, domain FROM mailbox WHERE active=1')
AS global_addressbook ("ID" BIGINT, name VARCHAR(255), email VARCHAR(255), domain VARCHAR(255));
ALTER TABLE global_addressbook OWNER TO roundcube;
Notes:
- if you're running RHEL/CentOS 6 or 7, don't forget to uncomment the first lines to create dblink function.
- of course you should replace
xxx
in above sample SQL command by the real SQL username/password/database name. - on iRedMail server, it's better to use SQL user
vmail
which has read-only permission tovmail
database. Don't usevmailadmin
orroot
user.
Known issue on iRedMail server:
- column
mailbox.created
stores timestamp when this account was created, if the timestamp contains timezone info (e.g.2015-02-28 22:31:16.562376
), this plugin cannot display any contact. Change the timestamp to2015-02-28 22:31:16
(without time zone info) works.
Michael Telatynski commented
Mind creating a fork and pull request for this, also any chance of you creating an Alias Compatible one? On the MySQL Side it uses a subquery on the e-mail address.