给定这样的用户帐户表:
CREATE TABLE tbl_accounts(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
email_addr VARCHAR(50) NOT NULL,
passkey BLOB /* AES KEY */
) ENGINE = InnoDB;
您将需要一个邮箱表来根据用户帐户和他们正在检查的文件夹(收件箱|发件箱)查找电子邮件。我们将这张表分开,使数据库保持“规范化”。
CREATE TABLE tbl_email_box(
account_id INT, /* owner|sender of mail */
FOREIGN KEY (account_id) REFERENCES tbl_accounts(id) ON DELETE SET NULL,
email_id INT,
FOREIGN KEY (email_id) REFERENCES tbl_emails(id) ON DELETE SET NULL,
folder TINYINT(1), /* 0=inbox->account=owner; 1=outbox->account=sender; */
status TINYINT(1) DEFAULT 0, /* 0=unread, 1=read */
date TIMESTAMP /* because the query executes when they check/send mail, */
/* then record is created (date=sent|received date) */
) ENGINE = InnoDB;
此表将存储实际的电子邮件数据
CREATE TABLE tbl_emails(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
subject VARCHAR(100),
message BLOB,
created TIMESTAMP
) ENGINE = InnoDB;
希望这可以帮助。