This commit is contained in:
temasky
2020-07-31 12:45:56 +00:00
commit 5d419635ed
306 changed files with 26949 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
-- If subject contains emoji, varchar doesn't work well.
ALTER TABLE msgs MODIFY COLUMN subject VARBINARY(255) DEFAULT '';
ALTER TABLE msgs MODIFY COLUMN from_addr VARBINARY(255) DEFAULT '';
-- mail address without address extension: user+abc@domain.com -> user@domain.com
ALTER TABLE maddr ADD COLUMN email_raw varbinary(255) NOT NULL DEFAULT '';
-- index
CREATE INDEX maddr_idx_email_raw ON maddr (email_raw);
-- Create trigger to save email address withou address extension
-- user+abc@domain.com -> user@domain.com
DELIMITER //
CREATE TRIGGER `maddr_email_raw`
BEFORE INSERT
ON `maddr`
FOR EACH ROW
BEGIN
IF (NEW.email LIKE '%+%') THEN
SET NEW.email_raw = CONCAT(SUBSTRING_INDEX(NEW.email, '+', 1), '@', SUBSTRING_INDEX(new.email, '@', -1));
ELSE
SET NEW.email_raw = NEW.email;
END IF;
END;
//
DELIMITER ;
-- Update all existing records.
UPDATE maddr SET email_raw=email WHERE email_raw='';
+39
View File
@@ -0,0 +1,39 @@
-- If subject/from_addr contains emoji, varchar doesn't work well.
ALTER TABLE msgs ALTER COLUMN subject DROP DEFAULT;
ALTER TABLE msgs ALTER COLUMN subject TYPE bytea USING subject::bytea;
ALTER TABLE msgs ALTER COLUMN subject SET DEFAULT '';
ALTER TABLE msgs ALTER COLUMN from_addr DROP DEFAULT;
ALTER TABLE msgs ALTER COLUMN from_addr TYPE bytea USING subject::bytea;
ALTER TABLE msgs ALTER COLUMN from_addr SET DEFAULT '';
-- mail address without address extension: user+abc@domain.com -> user@domain.com
ALTER TABLE maddr ADD COLUMN email_raw VARCHAR(255) NOT NULL DEFAULT '';
-- index
CREATE INDEX maddr_idx_email ON maddr (email);
CREATE INDEX maddr_idx_email_raw ON maddr (email_raw);
CREATE INDEX maddr_idx_domain ON maddr (domain);
-- Create trigger to save email address withou address extension
-- user+abc@domain.com -> user@domain.com
-- CREATE OR REPLACE FUNCTION strip_addr_extension(bytea, varchar, integer) RETURNS TRIGGER AS $$
CREATE OR REPLACE FUNCTION strip_addr_extension()
RETURNS TRIGGER AS $$
BEGIN
IF (NEW.email LIKE '%+%') THEN
NEW.email_raw := split_part(convert_from(NEW.email, 'UTF8'), '+', 1) || '@' || split_part(convert_from(NEW.email, 'UTF8'), '@', 2);
ELSE
NEW.email_raw := convert_from(NEW.email, 'UTF8');
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER maddr_email_raw
BEFORE INSERT ON maddr
FOR EACH ROW
EXECUTE PROCEDURE strip_addr_extension();
-- Update all existing records.
UPDATE maddr SET email_raw=email WHERE email_raw='';
+53
View File
@@ -0,0 +1,53 @@
-- USE vmail;
-- DROP column
ALTER TABLE mailbox DROP COLUMN local_part;
-- New SQL column
ALTER TABLE mailbox ADD COLUMN enableimaptls TINYINT(1) NOT NULL DEFAULT 1;
ALTER TABLE mailbox ADD INDEX (enableimaptls);
ALTER TABLE mailbox ADD COLUMN enablepop3tls TINYINT(1) NOT NULL DEFAULT 1;
ALTER TABLE mailbox ADD INDEX (enablepop3tls);
ALTER TABLE mailbox ADD COLUMN enablesievetls TINYINT(1) NOT NULL DEFAULT 1;
ALTER TABLE mailbox ADD INDEX (enablesievetls);
-- Rename table
RENAME TABLE alias_moderators TO moderators;
-- Column used to limit number of mailing lists a domain admin can create
ALTER TABLE domain ADD COLUMN maillists INT(10) NOT NULL DEFAULT 0;
-- Column used to mark sql record is a mailing list
ALTER TABLE forwardings ADD COLUMN `is_maillist` TINYINT(1) NOT NULL DEFAULT 0;
ALTER TABLE forwardings ADD INDEX (`is_maillist`);
-- Table used to store mailing list accounts
CREATE TABLE IF NOT EXISTS maillists (
id BIGINT(20) UNSIGNED AUTO_INCREMENT,
address VARCHAR(255) NOT NULL DEFAULT '',
domain VARCHAR(255) NOT NULL DEFAULT '',
-- Per mailing list transport. for example: 'mlmmj:example.com/listname'.
transport VARCHAR(255) NOT NULL DEFAULT '',
accesspolicy VARCHAR(30) NOT NULL DEFAULT '',
maxmsgsize BIGINT(20) NOT NULL DEFAULT 0,
-- name of the mailing list
name VARCHAR(255) NOT NULL DEFAULT '',
-- short introduction of the mailing list on subscription page
description TEXT,
-- a server-wide unique id (a 36-characters string) for each mailing list
mlid VARCHAR(36) NOT NULL DEFAULT '',
-- control whether newsletter-style subscription from website is enabled
-- 1 -> enabled, 0 -> disabled
is_newsletter TINYINT(1) NOT NULL DEFAULT 0,
settings TEXT,
created DATETIME NOT NULL DEFAULT '1970-01-01 01:01:01',
modified DATETIME NOT NULL DEFAULT '1970-01-01 01:01:01',
expired DATETIME NOT NULL DEFAULT '9999-12-31 00:00:00',
active TINYINT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (id),
UNIQUE INDEX (address),
UNIQUE INDEX (mlid),
INDEX (is_newsletter),
INDEX (domain),
INDEX (active)
) ENGINE=InnoDB;
+61
View File
@@ -0,0 +1,61 @@
-- \c vmail;
-- DROP column
ALTER TABLE mailbox DROP COLUMN local_part;
-- New SQL column
ALTER TABLE mailbox ADD COLUMN enableimaptls INT2 NOT NULL DEFAULT 1;
CREATE INDEX idx_mailbox_enableimaptls ON mailbox (enableimaptls);
ALTER TABLE mailbox ADD COLUMN enablepop3tls INT2 NOT NULL DEFAULT 1;
CREATE INDEX idx_mailbox_enablepop3tls ON mailbox (enablepop3tls);
ALTER TABLE mailbox ADD COLUMN enablesievetls INT2 NOT NULL DEFAULT 1;
CREATE INDEX idx_mailbox_enablesievetls ON mailbox (enablesievetls);
-- Rename table
ALTER TABLE alias_moderators RENAME TO moderators;
-- Column used to limit number of mailing lists a domain admin can create
ALTER TABLE domain ADD COLUMN maillists INT8 NOT NULL DEFAULT 0;
-- Column used to mark sql record is a mailing list
ALTER TABLE forwardings ADD COLUMN is_maillist INT2 NOT NULL DEFAULT 0;
CREATE INDEX idx_forwardings_is_maillist ON forwardings (is_maillist);
CREATE TABLE maillists (
id SERIAL PRIMARY KEY,
address VARCHAR(255) NOT NULL DEFAULT '',
domain VARCHAR(255) NOT NULL DEFAULT '',
-- Per mailing list transport. for example: 'mlmmj:example.com/listname'.
transport VARCHAR(255) NOT NULL DEFAULT '',
accesspolicy VARCHAR(30) NOT NULL DEFAULT '',
maxmsgsize INT8 NOT NULL DEFAULT 0,
-- name of the mailing list
name VARCHAR(255) NOT NULL DEFAULT '',
-- short introduction of the mailing list on subscription page
description TEXT,
-- a server-wide unique id (a 36-characters string) for each mailing list
mlid VARCHAR(36) NOT NULL DEFAULT '',
-- control whether newsletter-style subscription from website is enabled
-- 1 -> enabled, 0 -> disabled
is_newsletter INT2 NOT NULL DEFAULT 0,
settings TEXT,
created TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '1970-01-01 00:00:00',
modified TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '1970-01-01 00:00:00',
expired TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT '9999-12-31 00:00:00',
active INT2 NOT NULL DEFAULT 1
);
CREATE UNIQUE INDEX idx_maillists_address ON maillists (address);
CREATE INDEX idx_maillists_domain ON maillists (domain);
CREATE UNIQUE INDEX idx_maillists_mlid ON maillists (mlid);
CREATE INDEX idx_maillists_is_newsletter ON maillists (is_newsletter);
CREATE INDEX idx_maillists_active ON maillists (active);
GRANT SELECT ON maillists TO vmail;
GRANT SELECT ON maillists_id_seq TO vmail;
GRANT SELECT ON alias_moderators_id_seq TO vmail;
GRANT SELECT ON forwardings_id_seq TO vmail;
GRANT ALL ON maillists TO vmailadmin;
GRANT ALL ON maillists_id_seq TO vmailadmin;
GRANT ALL ON alias_moderators_id_seq TO vmailadmin;
GRANT ALL ON forwardings_id_seq TO vmailadmin;