CREATE DATABASE amavis; GRANT CREATE, DROP, ALTER, SELECT, INSERT, UPDATE, DELETE ON amavis.* TO amavis@localhost IDENTIFIED BY 'password'; FLUSH PRIVILEGES; USE amavis; CREATE TABLE users ( id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, -- unique id priority integer NOT NULL DEFAULT '7', -- sort field, 0 is low prior. policy_id integer unsigned NOT NULL DEFAULT '1', -- JOINs with policy.id email varchar(255) NOT NULL UNIQUE, fullname varchar(255) DEFAULT NULL, -- not used by amavisd-new digest char(2) default 'WD', username varchar(255) default NULL, retention smallint(6) default '14' ) ENGINE=InnoDB; CREATE TABLE users_id_seq ( id int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (id) ) ENGINE=InnoDB; CREATE TABLE mailaddr ( id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, priority integer NOT NULL DEFAULT '7', -- 0 is low priority email varchar(255) NOT NULL UNIQUE ) ENGINE=InnoDB; CREATE TABLE wblist ( rid integer unsigned NOT NULL, -- recipient: users.id sid integer unsigned NOT NULL, -- sender: mailaddr.id priority smallint(6) NOT NULL default '7', email varchar(255) NOT NULL default '', wb varchar(10) NOT NULL, -- W or Y / B or N / space=neutral / score PRIMARY KEY (rid,email) -- amavisnewsql specific, normally it's (rid,sid) ) ENGINE=InnoDB; CREATE TABLE policy ( id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, policy_name varchar(35), -- not used by amavisd-new, a comment virus_lover char(1) default NULL, -- Y/N spam_lover char(1) default NULL, -- Y/N banned_files_lover char(1) default NULL, -- Y/N bad_header_lover char(1) default NULL, -- Y/N bypass_virus_checks char(1) default NULL, -- Y/N bypass_spam_checks char(1) default NULL, -- Y/N bypass_banned_checks char(1) default NULL, -- Y/N bypass_header_checks char(1) default NULL, -- Y/N spam_modifies_subj char(1) default NULL, -- Y/N virus_quarantine_to varchar(64) default NULL, spam_quarantine_to varchar(64) default NULL, banned_quarantine_to varchar(64) default NULL, bad_header_quarantine_to varchar(64) default NULL, clean_quarantine_to varchar(64) default NULL, other_quarantine_to varchar(64) default NULL, spam_tag_level float default NULL, -- higher score inserts spam info headers spam_tag2_level float default NULL, -- inserts 'declared spam' header fields spam_kill_level float default NULL, -- higher score triggers evasive actions spam_dsn_cutoff_level float default NULL, spam_quarantine_cutoff_level float default NULL, addr_extension_virus varchar(64) default NULL, addr_extension_spam varchar(64) default NULL, addr_extension_banned varchar(64) default NULL, addr_extension_bad_header varchar(64) default NULL, warnvirusrecip char(1) default NULL, -- Y/N warnbannedrecip char(1) default NULL, -- Y/N warnbadhrecip char(1) default NULL, -- Y/N newvirus_admin varchar(64) default NULL, virus_admin varchar(64) default NULL, banned_admin varchar(64) default NULL, bad_header_admin varchar(64) default NULL, spam_admin varchar(64) default NULL, spam_subject_tag varchar(64) default NULL, spam_subject_tag2 varchar(64) default NULL, message_size_limit integer default NULL, -- max size in bytes, 0 disable banned_rulenames varchar(64) default NULL -- comma-separated list of ... ) ENGINE=InnoDB; CREATE TABLE policy_id_seq ( id int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (id) ) ENGINE=InnoDB; CREATE TABLE maddr ( id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, email varchar(255) NOT NULL UNIQUE, -- full mail address domain varchar(255) NOT NULL -- only domain part of the email address ) ENGINE=InnoDB; CREATE TABLE msg ( id int(10) unsigned NOT NULL auto_increment, stype varchar(8) default 'spam', sender varchar(255) default NULL, subject varchar(255) default NULL, body mediumtext, storetime int(11) default NULL, score float default NULL, UNIQUE KEY id (id) ) ENGINE=InnoDB; CREATE TABLE msg_id_seq ( id bigint(20) unsigned NOT NULL default '0', PRIMARY KEY (id) ) ENGINE=InnoDB; CREATE TABLE msgowner ( msgid int(10) unsigned NOT NULL default '0', rid int(11) NOT NULL default '0' ) ENGINE=InnoDB; CREATE TABLE msgs ( mail_id varchar(12) NOT NULL PRIMARY KEY, -- long-term unique mail id secret_id varchar(12) DEFAULT '', -- authorizes release of mail_id am_id varchar(20) NOT NULL, -- id used in the log time_num integer unsigned NOT NULL, -- rx_time: seconds since Unix epoch time_iso TIMESTAMP NOT NULL, -- rx_time: ISO8601 UTC ascii time sid integer unsigned NOT NULL, -- sender: maddr.id policy varchar(255) DEFAULT '', -- policy bank path (like macro %p) client_addr varchar(255) DEFAULT '', -- SMTP client IP address (IPv4 or v6) size integer unsigned NOT NULL, -- message size in bytes content char(1), -- content type: V/B/S/s/M/H/O/C: quar_type char(1), -- quarantined as: ' '/F/Z/B/Q/M/L quar_loc varchar(255) DEFAULT '', -- quarantine location (e.g. file) dsn_sent char(1), -- was DSN sent? Y/N/q (q=quenched) spam_level float, -- SA spam level (no boosts) message_id varchar(255) DEFAULT '', -- mail Message-ID header field from_addr varchar(255) DEFAULT '', -- mail From header field, UTF8 subject varchar(255) DEFAULT '', -- mail Subject header field, UTF8 host varchar(255) NOT NULL, -- hostname where amavisd is running FOREIGN KEY (sid) REFERENCES maddr(id) ON DELETE RESTRICT ) ENGINE=InnoDB; CREATE INDEX msgs_idx_sid ON msgs (sid); CREATE INDEX msgs_idx_mess_id ON msgs (message_id); -- useful with pen pals CREATE INDEX msgs_idx_time_iso ON msgs (time_iso); CREATE TABLE msgrcpt ( mail_id varchar(12) NOT NULL, -- (must allow duplicates) rid integer unsigned NOT NULL, -- recipient: maddr.id (dupl. allowed) ds char(1) NOT NULL, -- delivery status: P/R/B/D/T rs char(1) NOT NULL, -- release status: initialized to ' ' bl char(1) DEFAULT ' ', -- sender blacklisted by this recip wl char(1) DEFAULT ' ', -- sender whitelisted by this recip bspam_level float, -- spam level + per-recip boost smtp_resp varchar(255) DEFAULT '', -- SMTP response given to MTA FOREIGN KEY (rid) REFERENCES maddr(id) ON DELETE RESTRICT, FOREIGN KEY (mail_id) REFERENCES msgs(mail_id) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE INDEX msgrcpt_idx_mail_id ON msgrcpt (mail_id); CREATE INDEX msgrcpt_idx_rid ON msgrcpt (rid); CREATE TABLE quarantine ( mail_id varchar(12) NOT NULL, -- long-term unique mail id chunk_ind integer unsigned NOT NULL, -- chunk number, starting with 1 mail_text blob NOT NULL, -- store mail as chunks of octets PRIMARY KEY (mail_id,chunk_ind), FOREIGN KEY (mail_id) REFERENCES msgs(mail_id) ON DELETE CASCADE ) ENGINE=InnoDB; INSERT INTO msg_id_seq (id) VALUES (1); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level) VALUES (1, 'Default - all spam to spam folder', '6.5', '9999'); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level, spam_quarantine_cutoff_level) VALUES (2, 'Quarantine, discard high score spam', '5', '8', '14'); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level, spam_quarantine_cutoff_level) VALUES (3, 'Nothing goes to spam folder', '15', '15', '15'); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level, spam_quarantine_cutoff_level) VALUES (4, 'No spam goes to quarantine', '6', '14', '14'); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level, spam_quarantine_cutoff_level) VALUES (5, 'Permissive, no spam quarantine','9', '20', '20'); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level, spam_quarantine_cutoff_level) VALUES (6, 'Permissive, with spam quarantine','10', '10', '25'); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level) VALUES (7, 'Do not tag or block spam', '9999', '9999'); INSERT INTO policy (id, policy_name, spam_tag2_level, spam_kill_level) VALUES (8, 'All spam to quarantine', '8', '8'); INSERT INTO policy_id_seq (id) VALUES (9); INSERT INTO users_id_seq (id) VALUES (1);