aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/account/import-mbox.go44
-rw-r--r--commands/compose/postpone.go37
-rw-r--r--commands/compose/send.go48
3 files changed, 71 insertions, 58 deletions
diff --git a/commands/account/import-mbox.go b/commands/account/import-mbox.go
index 774dfa8f..7aa393b6 100644
--- a/commands/account/import-mbox.go
+++ b/commands/account/import-mbox.go
@@ -65,7 +65,6 @@ func (i ImportMbox) Execute(args []string) error {
app.PushError(err.Error())
return
}
- worker := acct.Worker()
var appended uint32
for i, m := range messages {
@@ -79,27 +78,28 @@ func (i ImportMbox) Execute(args []string) error {
break
}
nbytes, _ := io.Copy(&buf, r)
- worker.PostAction(&types.AppendMessage{
- Destination: folder,
- Flags: models.SeenFlag,
- Date: time.Now(),
- Reader: &buf,
- Length: int(nbytes),
- }, func(msg types.WorkerMessage) {
- switch msg := msg.(type) {
- case *types.Unsupported:
- errMsg := fmt.Sprintf("%s: AppendMessage is unsupported", args[0])
- log.Errorf(errMsg)
- app.PushError(errMsg)
- return
- case *types.Error:
- log.Errorf("AppendMessage failed: %v", msg.Error)
- done <- false
- case *types.Done:
- atomic.AddUint32(&appended, 1)
- done <- true
- }
- })
+ store.Append(
+ folder,
+ models.SeenFlag,
+ time.Now(),
+ &buf,
+ int(nbytes),
+ func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Unsupported:
+ errMsg := fmt.Sprintf("%s: AppendMessage is unsupported", args[0])
+ log.Errorf(errMsg)
+ app.PushError(errMsg)
+ return
+ case *types.Error:
+ log.Errorf("AppendMessage failed: %v", msg.Error)
+ done <- false
+ case *types.Done:
+ atomic.AddUint32(&appended, 1)
+ done <- true
+ }
+ },
+ )
select {
case ok := <-done:
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
index 3ce9cc84..098b7039 100644
--- a/commands/compose/postpone.go
+++ b/commands/compose/postpone.go
@@ -34,6 +34,10 @@ func (p Postpone) Execute(args []string) error {
if acct == nil {
return errors.New("No account selected")
}
+ store := acct.Store()
+ if store == nil {
+ return errors.New("No message store selected")
+ }
tab := app.SelectedTab()
if tab == nil {
return errors.New("No tab selected")
@@ -98,22 +102,23 @@ func (p Postpone) Execute(args []string) error {
handleErr(errors.Wrap(err, "WriteMessage"))
return
}
- worker.PostAction(&types.AppendMessage{
- Destination: targetFolder,
- Flags: models.SeenFlag,
- Date: time.Now(),
- Reader: buf,
- Length: buf.Len(),
- }, func(msg types.WorkerMessage) {
- switch msg := msg.(type) {
- case *types.Done:
- app.PushStatus("Message postponed.", 10*time.Second)
- composer.SetPostponed()
- composer.Close()
- case *types.Error:
- handleErr(msg.Error)
- }
- })
+ store.Append(
+ targetFolder,
+ models.SeenFlag,
+ time.Now(),
+ buf,
+ buf.Len(),
+ func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Done:
+ app.PushStatus("Message postponed.", 10*time.Second)
+ composer.SetPostponed()
+ composer.Close()
+ case *types.Error:
+ handleErr(msg.Error)
+ }
+ },
+ )
}()
if !alreadyCreated {
diff --git a/commands/compose/send.go b/commands/compose/send.go
index 1047ebad..91fd42bd 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -228,8 +228,7 @@ func send(composer *app.Composer, ctx sendCtx,
}
if ctx.copyto != "" && ctx.scheme != "jmap" {
app.PushStatus("Copying to "+ctx.copyto, 10*time.Second)
- errch := copyToSent(composer.Worker(), ctx.copyto,
- copyBuf.Len(), &copyBuf)
+ errch := copyToSent(ctx.copyto, copyBuf.Len(), &copyBuf)
err = <-errch
if err != nil {
errmsg := fmt.Sprintf(
@@ -558,23 +557,32 @@ func newJmapSender(
return writer, err
}
-func copyToSent(worker *types.Worker, dest string,
- n int, msg io.Reader,
-) <-chan error {
- errCh := make(chan error)
- worker.PostAction(&types.AppendMessage{
- Destination: dest,
- Flags: models.SeenFlag,
- Date: time.Now(),
- Reader: msg,
- Length: n,
- }, func(msg types.WorkerMessage) {
- switch msg := msg.(type) {
- case *types.Done:
- errCh <- nil
- case *types.Error:
- errCh <- msg.Error
- }
- })
+func copyToSent(dest string, n int, msg io.Reader) <-chan error {
+ errCh := make(chan error, 1)
+ acct := app.SelectedAccount()
+ if acct == nil {
+ errCh <- errors.New("No account selected")
+ return errCh
+ }
+ store := acct.Store()
+ if store == nil {
+ errCh <- errors.New("No message store selected")
+ return errCh
+ }
+ store.Append(
+ dest,
+ models.SeenFlag,
+ time.Now(),
+ msg,
+ n,
+ func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Done:
+ errCh <- nil
+ case *types.Error:
+ errCh <- msg.Error
+ }
+ },
+ )
return errCh
}