Mark sent messages as "seen" in maildir
- Add maildir flags to complement a messages imap flags - Set the "seen" flag on sent messages when using the maildir backend - Cleanup AppendMessage interface to use models.Flag for both IMAP and maildir
This commit is contained in:
parent
68f179021d
commit
6ff3c7a1ba
|
@ -10,7 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/go-imap"
|
|
||||||
"github.com/emersion/go-sasl"
|
"github.com/emersion/go-sasl"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
@ -18,6 +17,7 @@ import (
|
||||||
"github.com/miolini/datacounter"
|
"github.com/miolini/datacounter"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"git.sr.ht/~sircmpwn/aerc/models"
|
||||||
"git.sr.ht/~sircmpwn/aerc/widgets"
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
||||||
"git.sr.ht/~sircmpwn/aerc/worker/types"
|
"git.sr.ht/~sircmpwn/aerc/worker/types"
|
||||||
)
|
)
|
||||||
|
@ -235,7 +235,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
worker.PostAction(&types.AppendMessage{
|
worker.PostAction(&types.AppendMessage{
|
||||||
Destination: config.CopyTo,
|
Destination: config.CopyTo,
|
||||||
Flags: []string{imap.SeenFlag},
|
Flags: []models.Flag{models.SeenFlag},
|
||||||
Date: time.Now(),
|
Date: time.Now(),
|
||||||
Reader: r,
|
Reader: r,
|
||||||
Length: nbytes,
|
Length: nbytes,
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -9,7 +9,7 @@ require (
|
||||||
github.com/ddevault/go-libvterm v0.0.0-20190526194226-b7d861da3810
|
github.com/ddevault/go-libvterm v0.0.0-20190526194226-b7d861da3810
|
||||||
github.com/emersion/go-imap v1.0.0
|
github.com/emersion/go-imap v1.0.0
|
||||||
github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e
|
github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e
|
||||||
github.com/emersion/go-maildir v0.0.0-20191218233049-14e25d3ea720
|
github.com/emersion/go-maildir v0.2.0
|
||||||
github.com/emersion/go-message v0.10.7
|
github.com/emersion/go-message v0.10.7
|
||||||
github.com/emersion/go-sasl v0.0.0-20190817083125-240c8404624e
|
github.com/emersion/go-sasl v0.0.0-20190817083125-240c8404624e
|
||||||
github.com/emersion/go-smtp v0.11.2
|
github.com/emersion/go-smtp v0.11.2
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -23,6 +23,12 @@ github.com/emersion/go-maildir v0.0.0-20190727102040-941194b0ac70 h1:aUiPu6/iCjc
|
||||||
github.com/emersion/go-maildir v0.0.0-20190727102040-941194b0ac70/go.mod h1:I2j27lND/SRLgxROe50Vam81MSaqPFvJ0OHNnDZ7n84=
|
github.com/emersion/go-maildir v0.0.0-20190727102040-941194b0ac70/go.mod h1:I2j27lND/SRLgxROe50Vam81MSaqPFvJ0OHNnDZ7n84=
|
||||||
github.com/emersion/go-maildir v0.0.0-20191218233049-14e25d3ea720 h1:0Hj2cVnV1NunzYK6Y9fjTdpeqHClF+QNTyiCyhIJ/0E=
|
github.com/emersion/go-maildir v0.0.0-20191218233049-14e25d3ea720 h1:0Hj2cVnV1NunzYK6Y9fjTdpeqHClF+QNTyiCyhIJ/0E=
|
||||||
github.com/emersion/go-maildir v0.0.0-20191218233049-14e25d3ea720/go.mod h1:I2j27lND/SRLgxROe50Vam81MSaqPFvJ0OHNnDZ7n84=
|
github.com/emersion/go-maildir v0.0.0-20191218233049-14e25d3ea720/go.mod h1:I2j27lND/SRLgxROe50Vam81MSaqPFvJ0OHNnDZ7n84=
|
||||||
|
github.com/emersion/go-maildir v0.1.0 h1:GwaZOjulI/6XJInH+ChOeAgXv3BuVFIBg5RtMTFwURA=
|
||||||
|
github.com/emersion/go-maildir v0.1.0/go.mod h1:I2j27lND/SRLgxROe50Vam81MSaqPFvJ0OHNnDZ7n84=
|
||||||
|
github.com/emersion/go-maildir v0.1.1-0.20200301104031-a05813beeb4a h1:3XddcpC7A4HR6iZ+xXZj3wgIk0WhrHGwZGVqffWN7Js=
|
||||||
|
github.com/emersion/go-maildir v0.1.1-0.20200301104031-a05813beeb4a/go.mod h1:I2j27lND/SRLgxROe50Vam81MSaqPFvJ0OHNnDZ7n84=
|
||||||
|
github.com/emersion/go-maildir v0.2.0 h1:fC4+UVGl8GcQGbFF7AWab2JMf4VbKz+bMNv07xxhzs8=
|
||||||
|
github.com/emersion/go-maildir v0.2.0/go.mod h1:I2j27lND/SRLgxROe50Vam81MSaqPFvJ0OHNnDZ7n84=
|
||||||
github.com/emersion/go-message v0.10.4-0.20190609165112-592ace5bc1ca/go.mod h1:3h+HsGTCFHmk4ngJ2IV/YPhdlaOcR6hcgqM3yca9v7c=
|
github.com/emersion/go-message v0.10.4-0.20190609165112-592ace5bc1ca/go.mod h1:3h+HsGTCFHmk4ngJ2IV/YPhdlaOcR6hcgqM3yca9v7c=
|
||||||
github.com/emersion/go-message v0.10.7 h1:wVC8P985qmmL9PGV/VlkBikVqFirxTeYv9xi+YyCprU=
|
github.com/emersion/go-message v0.10.7 h1:wVC8P985qmmL9PGV/VlkBikVqFirxTeYv9xi+YyCprU=
|
||||||
github.com/emersion/go-message v0.10.7/go.mod h1:C4jnca5HOTo4bGN9YdqNQM9sITuT3Y0K6bSUw9RklvY=
|
github.com/emersion/go-message v0.10.7/go.mod h1:C4jnca5HOTo4bGN9YdqNQM9sITuT3Y0K6bSUw9RklvY=
|
||||||
|
|
|
@ -91,7 +91,7 @@ func (imapw *IMAPWorker) handleFetchMessages(
|
||||||
Info: &models.MessageInfo{
|
Info: &models.MessageInfo{
|
||||||
BodyStructure: translateBodyStructure(_msg.BodyStructure),
|
BodyStructure: translateBodyStructure(_msg.BodyStructure),
|
||||||
Envelope: translateEnvelope(_msg.Envelope),
|
Envelope: translateEnvelope(_msg.Envelope),
|
||||||
Flags: translateFlags(_msg.Flags),
|
Flags: translateImapFlags(_msg.Flags),
|
||||||
InternalDate: _msg.InternalDate,
|
InternalDate: _msg.InternalDate,
|
||||||
RFC822Headers: header,
|
RFC822Headers: header,
|
||||||
Uid: _msg.Uid,
|
Uid: _msg.Uid,
|
||||||
|
@ -115,7 +115,7 @@ func (imapw *IMAPWorker) handleFetchMessages(
|
||||||
imapw.worker.PostMessage(&types.MessageInfo{
|
imapw.worker.PostMessage(&types.MessageInfo{
|
||||||
Message: types.RespondTo(msg),
|
Message: types.RespondTo(msg),
|
||||||
Info: &models.MessageInfo{
|
Info: &models.MessageInfo{
|
||||||
Flags: translateFlags(_msg.Flags),
|
Flags: translateImapFlags(_msg.Flags),
|
||||||
Uid: _msg.Uid,
|
Uid: _msg.Uid,
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
@ -136,7 +136,7 @@ func (imapw *IMAPWorker) handleFetchMessages(
|
||||||
imapw.worker.PostMessage(&types.MessageInfo{
|
imapw.worker.PostMessage(&types.MessageInfo{
|
||||||
Message: types.RespondTo(msg),
|
Message: types.RespondTo(msg),
|
||||||
Info: &models.MessageInfo{
|
Info: &models.MessageInfo{
|
||||||
Flags: translateFlags(_msg.Flags),
|
Flags: translateImapFlags(_msg.Flags),
|
||||||
Uid: _msg.Uid,
|
Uid: _msg.Uid,
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
|
@ -89,7 +89,7 @@ func translateAddresses(addrs []*imap.Address) []*models.Address {
|
||||||
return converted
|
return converted
|
||||||
}
|
}
|
||||||
|
|
||||||
var flagMap = map[string]models.Flag{
|
var imapToFlag = map[string]models.Flag{
|
||||||
imap.SeenFlag: models.SeenFlag,
|
imap.SeenFlag: models.SeenFlag,
|
||||||
imap.RecentFlag: models.RecentFlag,
|
imap.RecentFlag: models.RecentFlag,
|
||||||
imap.AnsweredFlag: models.AnsweredFlag,
|
imap.AnsweredFlag: models.AnsweredFlag,
|
||||||
|
@ -97,12 +97,30 @@ var flagMap = map[string]models.Flag{
|
||||||
imap.FlaggedFlag: models.FlaggedFlag,
|
imap.FlaggedFlag: models.FlaggedFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
func translateFlags(imapFlags []string) []models.Flag {
|
var flagToImap = map[models.Flag]string{
|
||||||
|
models.SeenFlag: imap.SeenFlag,
|
||||||
|
models.RecentFlag: imap.RecentFlag,
|
||||||
|
models.AnsweredFlag: imap.AnsweredFlag,
|
||||||
|
models.DeletedFlag: imap.DeletedFlag,
|
||||||
|
models.FlaggedFlag: imap.FlaggedFlag,
|
||||||
|
}
|
||||||
|
|
||||||
|
func translateImapFlags(imapFlags []string) []models.Flag {
|
||||||
var flags []models.Flag
|
var flags []models.Flag
|
||||||
for _, imapFlag := range imapFlags {
|
for _, imapFlag := range imapFlags {
|
||||||
if flag, ok := flagMap[imapFlag]; ok {
|
if flag, ok := imapToFlag[imapFlag]; ok {
|
||||||
flags = append(flags, flag)
|
flags = append(flags, flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func translateFlags(flags []models.Flag) []string {
|
||||||
|
var imapFlags []string
|
||||||
|
for _, flag := range flags {
|
||||||
|
if imapFlag, ok := flagToImap[flag]; ok {
|
||||||
|
imapFlags = append(imapFlags, imapFlag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return imapFlags
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (m appendLiteral) Len() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (imapw *IMAPWorker) handleAppendMessage(msg *types.AppendMessage) {
|
func (imapw *IMAPWorker) handleAppendMessage(msg *types.AppendMessage) {
|
||||||
if err := imapw.client.Append(msg.Destination, msg.Flags, msg.Date,
|
if err := imapw.client.Append(msg.Destination, translateFlags(msg.Flags), msg.Date,
|
||||||
&appendLiteral{
|
&appendLiteral{
|
||||||
Reader: msg.Reader,
|
Reader: msg.Reader,
|
||||||
Length: msg.Length,
|
Length: msg.Length,
|
||||||
|
|
|
@ -222,7 +222,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) {
|
||||||
Info: &models.MessageInfo{
|
Info: &models.MessageInfo{
|
||||||
BodyStructure: translateBodyStructure(msg.BodyStructure),
|
BodyStructure: translateBodyStructure(msg.BodyStructure),
|
||||||
Envelope: translateEnvelope(msg.Envelope),
|
Envelope: translateEnvelope(msg.Envelope),
|
||||||
Flags: translateFlags(msg.Flags),
|
Flags: translateImapFlags(msg.Flags),
|
||||||
InternalDate: msg.InternalDate,
|
InternalDate: msg.InternalDate,
|
||||||
Uid: msg.Uid,
|
Uid: msg.Uid,
|
||||||
},
|
},
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (m Message) ModelFlags() ([]models.Flag, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return translateFlags(flags), nil
|
return translateMaildirFlags(flags), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFlags replaces the message's flags with a new set.
|
// SetFlags replaces the message's flags with a new set.
|
||||||
|
@ -97,7 +97,7 @@ func (m Message) NewBodyPartReader(requestedParts []int) (io.Reader, error) {
|
||||||
return lib.FetchEntityPartReader(msg, requestedParts)
|
return lib.FetchEntityPartReader(msg, requestedParts)
|
||||||
}
|
}
|
||||||
|
|
||||||
var flagMap = map[maildir.Flag]models.Flag{
|
var maildirToFlag = map[maildir.Flag]models.Flag{
|
||||||
maildir.FlagReplied: models.AnsweredFlag,
|
maildir.FlagReplied: models.AnsweredFlag,
|
||||||
maildir.FlagSeen: models.SeenFlag,
|
maildir.FlagSeen: models.SeenFlag,
|
||||||
maildir.FlagTrashed: models.DeletedFlag,
|
maildir.FlagTrashed: models.DeletedFlag,
|
||||||
|
@ -106,16 +106,35 @@ var flagMap = map[maildir.Flag]models.Flag{
|
||||||
// maildir.FlagPassed Flag = 'P'
|
// maildir.FlagPassed Flag = 'P'
|
||||||
}
|
}
|
||||||
|
|
||||||
func translateFlags(maildirFlags []maildir.Flag) []models.Flag {
|
var flagToMaildir = map[models.Flag]maildir.Flag{
|
||||||
|
models.AnsweredFlag: maildir.FlagReplied,
|
||||||
|
models.SeenFlag: maildir.FlagSeen,
|
||||||
|
models.DeletedFlag: maildir.FlagTrashed,
|
||||||
|
models.FlaggedFlag: maildir.FlagFlagged,
|
||||||
|
// maildir.FlagDraft Flag = 'D'
|
||||||
|
// maildir.FlagPassed Flag = 'P'
|
||||||
|
}
|
||||||
|
|
||||||
|
func translateMaildirFlags(maildirFlags []maildir.Flag) []models.Flag {
|
||||||
var flags []models.Flag
|
var flags []models.Flag
|
||||||
for _, maildirFlag := range maildirFlags {
|
for _, maildirFlag := range maildirFlags {
|
||||||
if flag, ok := flagMap[maildirFlag]; ok {
|
if flag, ok := maildirToFlag[maildirFlag]; ok {
|
||||||
flags = append(flags, flag)
|
flags = append(flags, flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func translateFlags(flags []models.Flag) []maildir.Flag {
|
||||||
|
var maildirFlags []maildir.Flag
|
||||||
|
for _, flag := range flags {
|
||||||
|
if maildirFlag, ok := flagToMaildir[flag]; ok {
|
||||||
|
maildirFlags = append(maildirFlags, maildirFlag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maildirFlags
|
||||||
|
}
|
||||||
|
|
||||||
func (m Message) UID() uint32 {
|
func (m Message) UID() uint32 {
|
||||||
return m.uid
|
return m.uid
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,7 +337,7 @@ func (w *Worker) sort(uids []uint32, criteria []*types.SortCriterion) ([]uint32,
|
||||||
|
|
||||||
func (w *Worker) handleCreateDirectory(msg *types.CreateDirectory) error {
|
func (w *Worker) handleCreateDirectory(msg *types.CreateDirectory) error {
|
||||||
dir := w.c.Dir(msg.Directory)
|
dir := w.c.Dir(msg.Directory)
|
||||||
if err := dir.Create(); err != nil {
|
if err := dir.Init(); err != nil {
|
||||||
w.worker.Logger.Printf("could not create directory %s: %v",
|
w.worker.Logger.Printf("could not create directory %s: %v",
|
||||||
msg.Directory, err)
|
msg.Directory, err)
|
||||||
return err
|
return err
|
||||||
|
@ -510,15 +510,16 @@ func (w *Worker) handleCopyMessages(msg *types.CopyMessages) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Worker) handleAppendMessage(msg *types.AppendMessage) error {
|
func (w *Worker) handleAppendMessage(msg *types.AppendMessage) error {
|
||||||
|
// since we are the "master" maildir process, we can modify the maildir directly
|
||||||
dest := w.c.Dir(msg.Destination)
|
dest := w.c.Dir(msg.Destination)
|
||||||
delivery, err := dest.NewDelivery()
|
_, writer, err := dest.Create(translateFlags(msg.Flags))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.worker.Logger.Printf("could not deliver message to %s: %v",
|
w.worker.Logger.Printf("could not create message at %s: %v",
|
||||||
msg.Destination, err)
|
msg.Destination, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer delivery.Close()
|
defer writer.Close()
|
||||||
if _, err := io.Copy(delivery, msg.Reader); err != nil {
|
if _, err := io.Copy(writer, msg.Reader); err != nil {
|
||||||
w.worker.Logger.Printf("could not write message to destination: %v", err)
|
w.worker.Logger.Printf("could not write message to destination: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ type CopyMessages struct {
|
||||||
type AppendMessage struct {
|
type AppendMessage struct {
|
||||||
Message
|
Message
|
||||||
Destination string
|
Destination string
|
||||||
Flags []string
|
Flags []models.Flag
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Reader io.Reader
|
Reader io.Reader
|
||||||
Length int
|
Length int
|
||||||
|
|
Loading…
Reference in New Issue