summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/account/compose.go2
-rw-r--r--commands/compose/postpone.go119
-rw-r--r--commands/msg/forward.go1
-rw-r--r--commands/msg/reply.go2
-rw-r--r--commands/msg/unsubscribe.go1
5 files changed, 122 insertions, 3 deletions
diff --git a/commands/account/compose.go b/commands/account/compose.go
index 8115faa..42d51d5 100644
--- a/commands/account/compose.go
+++ b/commands/account/compose.go
@@ -31,7 +31,7 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error {
 	}
 	acct := aerc.SelectedAccount()
 
-	composer, err := widgets.NewComposer(aerc,
+	composer, err := widgets.NewComposer(aerc, acct
 		aerc.Config(), acct.AccountConfig(), acct.Worker(),
 		template, nil, models.OriginalMail{})
 	if err != nil {
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
new file mode 100644
index 0000000..44aa411
--- /dev/null
+++ b/commands/compose/postpone.go
@@ -0,0 +1,119 @@
+package compose
+
+import (
+	"io"
+	"io/ioutil"
+	"time"
+
+	"github.com/emersion/go-imap"
+	"github.com/miolini/datacounter"
+	"github.com/pkg/errors"
+
+	"git.sr.ht/~sircmpwn/aerc/widgets"
+	"git.sr.ht/~sircmpwn/aerc/worker/types"
+)
+
+type Postpone struct{}
+
+func init() {
+	register(Postpone{})
+}
+
+func (Postpone) Aliases() []string {
+	return []string{"postpone"}
+}
+
+func (Postpone) Complete(aerc *widgets.Aerc, args []string) []string {
+	return nil
+}
+
+func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
+	if len(args) != 1 {
+		return errors.New("Usage: postpone")
+	}
+	composer, _ := aerc.SelectedTab().(*widgets.Composer)
+	config := composer.Config()
+
+	if config.Postpone == "" {
+		return errors.New("No Postpone location configured")
+	}
+
+	aerc.Logger().Println("Postponing mail")
+
+	header, _, err := composer.PrepareHeader()
+	if err != nil {
+		return errors.Wrap(err, "PrepareHeader")
+	}
+	header.SetContentType("text/plain", map[string]string{"charset": "UTF-8"})
+	header.Set("Content-Transfer-Encoding", "quoted-printable")
+	worker := composer.Worker()
+	dirs := aerc.SelectedAccount().Directories().List()
+	alreadyCreated := false
+	for _, dir := range dirs {
+		if dir == config.Postpone {
+			alreadyCreated = true
+			break
+		}
+	}
+
+	errChan := make(chan string)
+
+	// run this as a goroutine so we can make other progress. The message
+	// will be saved once the directory is created.
+	go func() {
+		errStr := <-errChan
+		if errStr != "" {
+			aerc.PushError(" " + errStr)
+			return
+		}
+
+		aerc.RemoveTab(composer)
+		ctr := datacounter.NewWriterCounter(ioutil.Discard)
+		err = composer.WriteMessage(header, ctr)
+		if err != nil {
+			aerc.PushError(errors.Wrap(err, "WriteMessage").Error())
+			composer.Close()
+			return
+		}
+		nbytes := int(ctr.Count())
+		r, w := io.Pipe()
+		worker.PostAction(&types.AppendMessage{
+			Destination: config.Postpone,
+			Flags:       []string{imap.SeenFlag},
+			Date:        time.Now(),
+			Reader:      r,
+			Length:      int(nbytes),
+		}, func(msg types.WorkerMessage) {
+			switch msg := msg.(type) {
+			case *types.Done:
+				aerc.PushStatus("Message postponed.", 10*time.Second)
+				r.Close()
+				composer.Close()
+			case *types.Error:
+				aerc.PushError(" " + msg.Error.Error())
+				r.Close()
+				composer.Close()
+			}
+		})
+		composer.WriteMessage(header, w)
+		w.Close()
+	}()
+
+	if !alreadyCreated {
+		// to synchronise the creating of the directory
+		worker.PostAction(&types.CreateDirectory{
+			Directory: config.Postpone,
+		}, func(msg types.WorkerMessage) {
+			switch msg := msg.(type) {
+			case *types.Done:
+				errChan <- ""
+			case *types.Error:
+				errChan <- msg.Error.Error()
+			}
+		})
+	} else {
+		errChan <- ""
+	}
+
+	return nil
+}
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index c51949e..833eb9f 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -70,7 +70,6 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
 		"To":      to,
 		"Subject": subject,
 	}
-
 	original := models.OriginalMail{}
 
 	addTab := func() (*widgets.Composer, error) {
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index c5ae1b6..291fc4b 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -124,7 +124,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
 			original.Date = msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM")
 		}
 
-		composer, err := widgets.NewComposer(aerc, aerc.Config(),
+		composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
 			acct.AccountConfig(), acct.Worker(), template, defaults, original)
 		if err != nil {
 			aerc.PushError("Error: " + err.Error())
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index 1bf3a83..1a2dd37 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -90,6 +90,7 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
 	}
 	composer, err := widgets.NewComposer(
 		aerc,
+		acct,
 		aerc.Config(),
 		acct.AccountConfig(),
 		acct.Worker(),
' href='#n405'>405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473