mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-13 07:06:29 +03:00
Add types.Mail
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/neilalexander/yggmail/internal/storage/types"
|
||||
)
|
||||
|
||||
type TableMails struct {
|
||||
@@ -35,7 +37,6 @@ const mailsSchema = `
|
||||
FOREIGN KEY (mailbox) REFERENCES mailboxes(mailbox) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
DROP VIEW IF EXISTS inboxes;
|
||||
CREATE VIEW IF NOT EXISTS inboxes AS SELECT * FROM (
|
||||
SELECT ROW_NUMBER() OVER (PARTITION BY mailbox) AS seq, * FROM mails
|
||||
)
|
||||
@@ -160,13 +161,14 @@ func (t *TableMails) MailCreate(mailbox string, data []byte) (int, error) {
|
||||
return id, err
|
||||
}
|
||||
|
||||
func (t *TableMails) MailSelect(mailbox string, id int) (int, int, []byte, bool, bool, bool, bool, time.Time, error) {
|
||||
var data []byte
|
||||
var seen, answered, flagged, deleted bool
|
||||
var ts int64
|
||||
var seq, pid int
|
||||
err := t.selectMail.QueryRow(mailbox, id).Scan(&seq, &pid, &data, &ts, &seen, &answered, &flagged, &deleted)
|
||||
return seq, pid, data, seen, answered, flagged, deleted, time.Unix(ts, 0), err
|
||||
func (t *TableMails) MailSelect(mailbox string, id int) (int, *types.Mail, error) {
|
||||
var seq int
|
||||
mail := &types.Mail{}
|
||||
err := t.selectMail.QueryRow(mailbox, id).Scan(
|
||||
&seq, &mail.ID, &mail.Mail, &mail.Date,
|
||||
&mail.Seen, &mail.Answered, &mail.Flagged, &mail.Deleted,
|
||||
)
|
||||
return seq, mail, err
|
||||
}
|
||||
|
||||
func (t *TableMails) MailSearch(mailbox string) ([]uint32, error) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package storage
|
||||
|
||||
import "time"
|
||||
import "github.com/neilalexander/yggmail/internal/storage/types"
|
||||
|
||||
type Storage interface {
|
||||
ConfigGet(key string) (string, error)
|
||||
@@ -19,7 +19,7 @@ type Storage interface {
|
||||
MailboxSubscribe(name string, subscribed bool) error
|
||||
|
||||
MailCreate(mailbox string, data []byte) (int, error)
|
||||
MailSelect(mailbox string, id int) (int, int, []byte, bool, bool, bool, bool, time.Time, error)
|
||||
MailSelect(mailbox string, id int) (int, *types.Mail, error)
|
||||
MailSearch(mailbox string) ([]uint32, error)
|
||||
MailUpdateFlags(mailbox string, id int, seen, answered, flagged, deleted bool) error
|
||||
MailDelete(mailbox, id string) error
|
||||
|
||||
14
internal/storage/types/types.go
Normal file
14
internal/storage/types/types.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
type Mail struct {
|
||||
Mailbox string
|
||||
ID int
|
||||
Mail []byte
|
||||
Date time.Time
|
||||
Seen bool
|
||||
Answered bool
|
||||
Flagged bool
|
||||
Deleted bool
|
||||
}
|
||||
Reference in New Issue
Block a user