From a6ec9a807df68978bf3b85314a4c54c60ecc2b7a Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 7 Mar 2026 17:59:31 +0530 Subject: feat: implement SMTP server with authentication, port validation, and email storage --- models/alias.go | 10 ++++++++++ models/attachment.go | 14 ++++++++++++++ models/email.go | 25 +++++++++++++++++++++++++ models/mailbox.go | 12 ++++++++++++ models/tag.go | 9 +++++++++ models/user.go | 10 ++++++++++ 6 files changed, 80 insertions(+) create mode 100644 models/alias.go create mode 100644 models/attachment.go create mode 100644 models/email.go create mode 100644 models/mailbox.go create mode 100644 models/tag.go create mode 100644 models/user.go (limited to 'models') diff --git a/models/alias.go b/models/alias.go new file mode 100644 index 0000000..5b0dcb3 --- /dev/null +++ b/models/alias.go @@ -0,0 +1,10 @@ +package models + +import "gorm.io/gorm" + +type Alias struct { + gorm.Model + SourceAddress string `gorm:"uniqueIndex;not null" json:"source_address"` + MailboxID uint `gorm:"not null" json:"mailbox_id"` + Mailbox Mailbox `gorm:"foreignKey:MailboxID" json:"mailbox"` +} diff --git a/models/attachment.go b/models/attachment.go new file mode 100644 index 0000000..cd1a741 --- /dev/null +++ b/models/attachment.go @@ -0,0 +1,14 @@ +package models + +import "gorm.io/gorm" + +type Attachment struct { + gorm.Model + EmailID uint `gorm:"not null;index" json:"email_id"` + Email Email `gorm:"foreignKey:EmailID" json:"email"` + Filename string `gorm:"not null" json:"filename"` + ContentType string `gorm:"not null" json:"content_type"` + ContentID string `json:"content_id"` + Size int64 `json:"size"` + IsInline bool `gorm:"default:false" json:"is_inline"` +} diff --git a/models/email.go b/models/email.go new file mode 100644 index 0000000..12b3ad1 --- /dev/null +++ b/models/email.go @@ -0,0 +1,25 @@ +package models + +import "gorm.io/gorm" + +type Email struct { + gorm.Model + MailboxID uint `gorm:"not null;index" json:"mailbox_id"` + Mailbox Mailbox `gorm:"foreignKey:MailboxID" json:"mailbox"` + MessageID string `gorm:"index" json:"message_id"` + Filename string `gorm:"uniqueIndex;not null" json:"filename"` + FromAddress string `gorm:"not null" json:"from_address"` + FromName string `json:"from_name"` + ToAddresses string `gorm:"not null" json:"to_addresses"` + CcAddresses string `json:"cc_addresses"` + BccAddresses string `json:"bcc_addresses"` + ReplyToAddress string `json:"reply_to_address"` + ReturnPath string `json:"return_path"` + Subject string `json:"subject"` + Snippet string `json:"snippet"` + Size int64 `json:"size"` + IsRead bool `gorm:"default:false;index" json:"is_read"` + AttachmentCount int `gorm:"default:0" json:"attachment_count"` + InlineCount int `gorm:"default:0" json:"inline_count"` + Tags []Tag `gorm:"many2many:email_tags" json:"tags"` +} diff --git a/models/mailbox.go b/models/mailbox.go new file mode 100644 index 0000000..da4114f --- /dev/null +++ b/models/mailbox.go @@ -0,0 +1,12 @@ +package models + +import "gorm.io/gorm" + +type Mailbox struct { + gorm.Model + Address string `gorm:"uniqueIndex;not null" json:"address"` + UserID uint `gorm:"not null" json:"user_id"` + User User `gorm:"foreignKey:UserID" json:"user"` + Aliases []Alias `gorm:"foreignKey:MailboxID" json:"aliases"` + Emails []Email `gorm:"foreignKey:MailboxID" json:"emails"` +} diff --git a/models/tag.go b/models/tag.go new file mode 100644 index 0000000..79fa65f --- /dev/null +++ b/models/tag.go @@ -0,0 +1,9 @@ +package models + +import "gorm.io/gorm" + +type Tag struct { + gorm.Model + Name string `gorm:"uniqueIndex;not null" json:"name"` + Emails []Email `gorm:"many2many:email_tags" json:"emails"` +} diff --git a/models/user.go b/models/user.go new file mode 100644 index 0000000..6bb6edf --- /dev/null +++ b/models/user.go @@ -0,0 +1,10 @@ +package models + +import "gorm.io/gorm" + +type User struct { + gorm.Model + Username string `gorm:"uniqueIndex;not null" json:"username"` + DisplayName string `json:"display_name"` + Mailboxes []Mailbox `gorm:"foreignKey:UserID" json:"mailboxes"` +} -- cgit v1.2.3