CREATE DATABASE `mail`;
GRANT ALL ON `mail`.* TO "mail"@"localhost" IDENTIFIED BY "mailpassword";
 
FLUSH PRIVILEGES;
USE `mail`;
 
CREATE TABLE IF NOT EXISTS `alias` (
	`source` VARCHAR(255) NOT NULL,
	`destination` VARCHAR(255) NOT NULL DEFAULT "",
	`enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1,
	PRIMARY KEY (`source`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
CREATE TABLE IF NOT EXISTS `domain` (
	`domain` VARCHAR(255) NOT NULL DEFAULT "",
	`transport` VARCHAR(255) NOT NULL DEFAULT "virtual:",
	`enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1,
	PRIMARY KEY (`domain`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
CREATE TABLE IF NOT EXISTS `user` (
	`email` VARCHAR(255) NOT NULL DEFAULT "",
	`password` VARCHAR(255) NOT NULL DEFAULT "",
	`name` VARCHAR(255) DEFAULT NULL,
	`quota` INT UNSIGNED DEFAULT NULL,
	`enabled` TINYINT UNSIGNED NOT NULL DEFAULT 1,
	PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



INSERT INTO `domain`
	(`domain`)
VALUES
	("localhost"),
	("localhost.localdomain"),
	("example.net"),
	("example.org"),
	("example.com");

INSERT INTO `user`
	(`email`, `password`, `name`)
VALUES
	("admin@example.net", ENCRYPT("adminpassword"), "Administrator"),
	("admin@example.org", ENCRYPT("adminpassword"), "Administrator"),
	("admin@example.com", ENCRYPT("adminpassword"), "Administrator");

INSERT INTO `alias`
	(`source`, `destination`)
VALUES
	("@localhost.localdomain", "@localhost"),
	("@localhost", "admin@example.com");
