~sircmpwn/aerc

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH] Add archive command

Details
Message ID
<20190604193652.6172-1-r@gnzler.io>
Sender timestamp
1559677012
DKIM signature
missing
Download raw message
Patch: +62 -0
Adds an archive command that moves the current message into the folder
specified in the account config entry.

Supports three layouts at this point:

- flat: puts all messages next to each other
- year: creates a folder per year
- month: same as above, plus folders per month
---
 commands/account/archive.go | 58 +++++++++++++++++++++++++++++++++++++
 config/binds.conf           |  1 +
 config/config.go            |  3 ++
 3 files changed, 62 insertions(+)
 create mode 100644 commands/account/archive.go

diff --git a/commands/account/archive.go b/commands/account/archive.go
new file mode 100644
index 0000000..7aa6384
--- /dev/null
+++ b/commands/account/archive.go
@@ -0,0 +1,58 @@
package account

import (
	"errors"
	"fmt"
	"path"
	"time"

	"github.com/gdamore/tcell"

	"git.sr.ht/~sircmpwn/aerc/widgets"
	"git.sr.ht/~sircmpwn/aerc/worker/types"
)

const (
	ARCHIVE_FLAT  = "flat"
	ARCHIVE_YEAR  = "year"
	ARCHIVE_MONTH = "month"
)

func init() {
	register("archive", Archive)
}

func Archive(aerc *widgets.Aerc, args []string) error {
	if len(args) != 2 {
		return errors.New("Usage: archive <flat|year|month>")
	}
	acct := aerc.SelectedAccount()
	if acct == nil {
		return errors.New("No account selected")
	}
	msg := acct.Messages().Selected()
	store := acct.Messages().Store()
	archiveDir := acct.AccountConfig().Archive
	acct.Messages().Next()

	switch args[1] {
	case ARCHIVE_MONTH:
		archiveDir = path.Join(archiveDir,
			fmt.Sprintf("%d", msg.Envelope.Date.Year()),
			fmt.Sprintf("%02d", msg.Envelope.Date.Month()))
	case ARCHIVE_YEAR:
		archiveDir = path.Join(archiveDir, fmt.Sprintf("%v", msg.Envelope.Date.Year()))
	case ARCHIVE_FLAT:
	}

	store.Move([]uint32{msg.Uid}, archiveDir, func(msg types.WorkerMessage) {
		switch msg := msg.(type) {
		case *types.Done:
			aerc.PushStatus("Messages archived.", 10*time.Second)
		case *types.Error:
			aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second).
				Color(tcell.ColorDefault, tcell.ColorRed)
		}
	})
	return nil
}
diff --git a/config/binds.conf b/config/binds.conf
index f758b17..2b27454 100644
--- a/config/binds.conf
+++ b/config/binds.conf
@@ -28,6 +28,7 @@ K = :prev-folder<Enter>
<Enter> = :view<Enter>
d = :confirm 'Really delete this message?' ':delete-message<Enter>'<Enter>
D = :delete<Enter>
a = :archive year<Enter>

C = :compose<Enter>

diff --git a/config/config.go b/config/config.go
index 1fb764b..1c419c2 100644
--- a/config/config.go
+++ b/config/config.go
@@ -33,6 +33,7 @@ const (
)

type AccountConfig struct {
	Archive         string
	CopyTo          string
	Default         string
	From            string
@@ -133,6 +134,8 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
				account.From = val
			} else if key == "copy-to" {
				account.CopyTo = val
			} else if key == "archive" {
				account.Archive = val
			} else if key != "name" {
				account.Params[key] = val
			}
-- 
2.21.0
Details
Message ID
<BUL8TPCYPE1E.2D37TI1K0S8C6@homura>
In-Reply-To
<20190604193652.6172-1-r@gnzler.io> (view parent)
Sender timestamp
1559681151
DKIM signature
missing
Download raw message
Nice! I think we're going to need to make sure the target folder exists
before we try to move the message into it, though.
Details
Message ID
<BUL91LYHXB7D.16DDFWUTXGJTE@hibiki>
In-Reply-To
<BUL8TPCYPE1E.2D37TI1K0S8C6@homura> (view parent)
Sender timestamp
1559681770
DKIM signature
missing
Download raw message
On Tue Jun 4, 2019 at 4:45 PM Drew DeVault wrote:
> Nice! I think we're going to need to make sure the target folder exists
> before we try to move the message into it, though.

Yes, I saw a note I made to myself about that just after I sent off the
patch :facepalm:

And then I was trying to figure out how to get around
https://todo.sr.ht/~sircmpwn/aerc2/143#comment-2502
to respond to the thread here via aerc^^

I will update this with the code that creates them!

*I responded to your personal email only at first :P still
getting the hang of the email based flow...*
Reply to thread Export thread (mbox)