aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg/pipe.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-10-23 16:01:21 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-25 22:24:31 +0200
commita381630604066cde5b791bfadb92de8c35e1cd1c (patch)
treee90bf4000c5b79971438630edb7da4e955952391 /commands/msg/pipe.go
parenta820e12d0f471e6768b0b198ed93fe5c244d2000 (diff)
downloadaerc-a381630604066cde5b791bfadb92de8c35e1cd1c.tar.gz
pipe: reorder patches based on email subjects
The Message-Id header cannot be relied upon as users can tweak it before sending. The subject seems a more reliable basis to reorder patches. Change the logic of sorting. Previously, all messages were required to look like patches to be sorted. Now if at least one message looks like a patch, all messages will be sorted by Subject before piping them. Since `git am` ignores non-patch messages, it should allow piping series of emails including reviews and comments without getting confusing errors. I have tested that this works on multiple series that appeared out of order in my INBOX with the following command (after marking the messages): :pipe -m sed -n 's/^Subject: //p' Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'commands/msg/pipe.go')
-rw-r--r--commands/msg/pipe.go32
1 files changed, 7 insertions, 25 deletions
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index 89dbc47c..d0101675 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -7,7 +7,6 @@ import (
"os/exec"
"regexp"
"sort"
- "strconv"
"time"
"git.sr.ht/~rjarry/aerc/commands"
@@ -169,11 +168,11 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
}
}
- is_git_patches := true
+ is_git_patches := false
for _, msg := range messages {
info := store.Messages[msg.Content.Uid]
- if info == nil || !gitMessageIdRe.MatchString(info.Envelope.MessageId) {
- is_git_patches = false
+ if info != nil && patchSeriesRe.MatchString(info.Envelope.Subject) {
+ is_git_patches = true
break
}
}
@@ -186,9 +185,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
if infoi == nil || infoj == nil {
return false
}
- msgidi := padGitMessageId(infoi.Envelope.MessageId)
- msgidj := padGitMessageId(infoj.Envelope.MessageId)
- return msgidi < msgidj
+ return infoi.Envelope.Subject < infoj.Envelope.Subject
})
}
@@ -241,21 +238,6 @@ func newMessagesReader(messages []*types.FullMessage, useMbox bool) io.Reader {
return pr
}
-var gitMessageIdRe = regexp.MustCompile(`^(\d+\.\d+)-(\d+)-(.+)$`)
-
-// Git send-email Message-Id headers have the following format:
-//
-// DATETIME.PID-NUM-COMMITTER
-//
-// Return a copy of the message id with NUM zero-padded to three characters.
-func padGitMessageId(msgId string) string {
- matches := gitMessageIdRe.FindStringSubmatch(msgId)
- if matches == nil {
- return msgId
- }
- number, err := strconv.Atoi(matches[2])
- if err != nil {
- return msgId
- }
- return fmt.Sprintf("%s-%03d-%s", matches[1], number, matches[3])
-}
+var patchSeriesRe = regexp.MustCompile(
+ `^.*\[(RFC )?PATCH( [^\]]+)? \d+/\d+] .+$`,
+)