- Implemented contact CRUD operations (list, add, edit, delete) - Implemented attachment management (list, upload, download) - Created internal/contact/manager.go for contact persistence - Created internal/attachment/manager.go for attachment storage - Added CLI commands in cmd/contacts.go and cmd/attachments.go - Integrated contact and attachment commands into root CLI Files: - internal/contact/types.go - Contact data models - internal/contact/manager.go - Contact CRUD operations - internal/attachment/manager.go - Attachment file operations - cmd/contacts.go - Contact CLI commands - cmd/attachments.go - Attachment CLI commands Contacts stored in ~/.config/pop/contacts.json Attachments stored in ~/.config/pop/attachments/
138 lines
3.6 KiB
Go
138 lines
3.6 KiB
Go
package mail
|
|
|
|
import "time"
|
|
|
|
type Folder int
|
|
|
|
const (
|
|
FolderInbox Folder = 0
|
|
FolderSent Folder = 3
|
|
FolderDraft Folder = 2
|
|
FolderTrash Folder = 4
|
|
FolderSpam Folder = 5
|
|
)
|
|
|
|
func (f Folder) Name() string {
|
|
names := map[Folder]string{
|
|
FolderInbox: "Inbox",
|
|
FolderSent: "Sent",
|
|
FolderDraft: "Drafts",
|
|
FolderTrash: "Trash",
|
|
FolderSpam: "Spam",
|
|
}
|
|
if name, ok := names[f]; ok {
|
|
return name
|
|
}
|
|
return "Unknown"
|
|
}
|
|
|
|
type Message struct {
|
|
MessageID string `json:"MessageID"`
|
|
ConversationID string `json:"ConversationID"`
|
|
CreatedAt time.Time `json:"-"`
|
|
Created int64 `json:"Created"`
|
|
UpdatedAt time.Time `json:"-"`
|
|
Updated int64 `json:"Updated"`
|
|
Type int `json:"Type"`
|
|
Starred bool `json:"Starred"`
|
|
Read bool `json:"Read"`
|
|
Category int `json:"Category"`
|
|
Sender Recipient `json:"Sender"`
|
|
Recipients []Recipient `json:"Recipients"`
|
|
Subject string `json:"Subject"`
|
|
Body string `json:"Body"`
|
|
BodyEnc string `json:"BodyEnc,omitempty"`
|
|
Attachments []Attachment `json:"Attachments,omitempty"`
|
|
MimeMessageID string `json:"MimeMessageID,omitempty"`
|
|
InReplyTo string `json:"InReplyTo,omitempty"`
|
|
}
|
|
|
|
func (m *Message) Folder() Folder {
|
|
if m.Type == 2 {
|
|
return FolderDraft
|
|
}
|
|
if m.Type == 3 {
|
|
return FolderSent
|
|
}
|
|
return FolderInbox
|
|
}
|
|
|
|
type Recipient struct {
|
|
Name string `json:"Name"`
|
|
Address string `json:"Address"`
|
|
Label int `json:"Label"`
|
|
AddressID string `json:"AddressID,omitempty"`
|
|
KeyID string `json:"KeyID,omitempty"`
|
|
Fingerprint string `json:"Fingerprint,omitempty"`
|
|
}
|
|
|
|
func (r Recipient) DisplayName() string {
|
|
if r.Name != "" {
|
|
return r.Name + " <" + r.Address + ">"
|
|
}
|
|
return r.Address
|
|
}
|
|
|
|
type Attachment struct {
|
|
AttachmentID string `json:"AttachmentID"`
|
|
Name string `json:"Name"`
|
|
ContentType string `json:"ContentType"`
|
|
Size int `json:"Size"`
|
|
DataEnc string `json:"DataEnc,omitempty"`
|
|
Keys []AttachmentKey `json:"Keys,omitempty"`
|
|
}
|
|
|
|
type AttachmentKey struct {
|
|
DataEnc string `json:"DataEnc"`
|
|
}
|
|
|
|
type Draft struct {
|
|
MessageID string `json:"MessageID"`
|
|
To []Recipient `json:"To"`
|
|
CC []Recipient `json:"CC,omitempty"`
|
|
BCC []Recipient `json:"BCC,omitempty"`
|
|
Subject string `json:"Subject"`
|
|
Body string `json:"Body"`
|
|
BodyEnc string `json:"BodyEnc,omitempty"`
|
|
Attachments []Attachment `json:"Attachments,omitempty"`
|
|
}
|
|
|
|
type ListMessagesRequest struct {
|
|
Folder Folder `json:"-"`
|
|
Page int `json:"Page"`
|
|
PageSize int `json:"PageSize"`
|
|
Passphrase string `json:"Passphrase"`
|
|
Starred *bool `json:"Starred,omitempty"`
|
|
Read *bool `json:"Read,omitempty"`
|
|
Since int64 `json:"Since,omitempty"`
|
|
}
|
|
|
|
type ListMessagesResponse struct {
|
|
Total int `json:"Total"`
|
|
Messages []Message `json:"Messages"`
|
|
}
|
|
|
|
type SendRequest struct {
|
|
To []Recipient `json:"To"`
|
|
CC []Recipient `json:"CC,omitempty"`
|
|
BCC []Recipient `json:"BCC,omitempty"`
|
|
Subject string `json:"Subject"`
|
|
Body string `json:"Body"`
|
|
HTML bool `json:"HTML,omitempty"`
|
|
ReplyTo []Recipient `json:"ReplyTo,omitempty"`
|
|
Attachments []Attachment `json:"Attachments,omitempty"`
|
|
Passphrase string `json:"Passphrase"`
|
|
}
|
|
|
|
type SearchRequest struct {
|
|
Query string `json:"Query"`
|
|
Page int `json:"Page"`
|
|
PageSize int `json:"PageSize"`
|
|
Passphrase string `json:"Passphrase"`
|
|
}
|
|
|
|
type SearchResponse struct {
|
|
Total int `json:"Total"`
|
|
Messages []Message `json:"Messages"`
|
|
}
|