New Upstream Release - golang-github-emersion-go-maildir

Ready changes

Summary

Merged new upstream version: 0.3.0 (was: 0.2.0).

Resulting package

Built on 2023-06-10T10:29 (took 4m12s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-github-emersion-go-maildir-dev

Lintian Result

Diff

diff --git a/debian/changelog b/debian/changelog
index 0807994..9fbd1f3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+golang-github-emersion-go-maildir (0.3.0-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+  * Drop patch fix-TestDir_Create.diff, present upstream.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Sat, 10 Jun 2023 10:25:35 -0000
+
 golang-github-emersion-go-maildir (0.2.0-2) unstable; urgency=medium
 
   * Team Upload
diff --git a/debian/patches/fix-TestDir_Create.diff b/debian/patches/fix-TestDir_Create.diff
deleted file mode 100644
index ec8a1bd..0000000
--- a/debian/patches/fix-TestDir_Create.diff
+++ /dev/null
@@ -1,19 +0,0 @@
-Fix repositories used for testing
---- a/maildir_test.go
-+++ b/maildir_test.go
-@@ -62,13 +62,13 @@
- func TestInit(t *testing.T) {
- 	t.Parallel()
- 
--	var d Dir = "test_create"
-+	var d Dir = "test_init"
- 	err := d.Init()
- 	if err != nil {
- 		t.Fatal(err)
- 	}
- 
--	f, err := os.Open("test_create")
-+	f, err := os.Open("test_init")
- 	if err != nil {
- 		t.Fatal(err)
- 	}
diff --git a/debian/patches/series b/debian/patches/series
index 50e1b63..e69de29 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +0,0 @@
-fix-TestDir_Create.diff
diff --git a/maildir.go b/maildir.go
index 29f493e..3825259 100644
--- a/maildir.go
+++ b/maildir.go
@@ -9,6 +9,7 @@ package maildir
 import (
 	"crypto/rand"
 	"encoding/hex"
+	"fmt"
 	"io"
 	"os"
 	"path/filepath"
@@ -36,7 +37,7 @@ type KeyError struct {
 }
 
 func (e *KeyError) Error() string {
-	return "maildir: key " + e.Key + " matches " + strconv.Itoa(e.N) + " files."
+	return fmt.Sprintf("maildir: key %v matches %v files, expected exactly one", e.Key, e.N)
 }
 
 // A FlagError occurs when a non-standard info section is encountered.
@@ -123,6 +124,28 @@ func (d Dir) UnseenCount() (int, error) {
 	return c, nil
 }
 
+func parseKey(filename string) (string, error) {
+	split := strings.FieldsFunc(filename, func(r rune) bool {
+		return r == separator
+	})
+
+	if len(split) == 0 {
+		return "", fmt.Errorf("Cannot parse key from filename %s", filename)
+	}
+
+	return split[0], nil
+}
+
+// Key returns the key for the given file path.
+func (d Dir) Key(path string) (string, error) {
+	if filepath.Dir(path) != string(d) {
+		return "", fmt.Errorf("Filepath %s belongs to a different Maildir", path)
+	}
+
+	filename := filepath.Base(path)
+	return parseKey(filename)
+}
+
 // Keys returns a slice of valid keys to access messages by.
 func (d Dir) Keys() ([]string, error) {
 	f, err := os.Open(filepath.Join(string(d), "cur"))
@@ -137,10 +160,11 @@ func (d Dir) Keys() ([]string, error) {
 	var keys []string
 	for _, n := range names {
 		if n[0] != '.' {
-			split := strings.FieldsFunc(n, func(r rune) bool {
-				return r == separator
-			})
-			keys = append(keys, split[0])
+			key, err := parseKey(n)
+			if err != nil {
+				return nil, err
+			}
+			keys = append(keys, key)
 		}
 	}
 	return keys, nil
@@ -355,7 +379,7 @@ func (d Dir) Copy(target Dir, key string) (string, error) {
 		return "", err
 	}
 	tmpfile := filepath.Join(string(target), "tmp", targetKey)
-	curfile := filepath.Join(string(target), "cur", targetKey+"2,")
+	curfile := filepath.Join(string(target), "cur", targetKey+string(separator)+"2,")
 	if err = os.Rename(tmpfile, curfile); err != nil {
 		return "", err
 	}
diff --git a/maildir_test.go b/maildir_test.go
index ac636eb..e8910a7 100644
--- a/maildir_test.go
+++ b/maildir_test.go
@@ -62,13 +62,13 @@ func makeDelivery(tb testing.TB, d Dir, msg string) {
 func TestInit(t *testing.T) {
 	t.Parallel()
 
-	var d Dir = "test_create"
+	var d Dir = "test_init"
 	err := d.Init()
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	f, err := os.Open("test_create")
+	f, err := os.Open("test_init")
 	if err != nil {
 		t.Fatal(err)
 	}

Debdiff

File lists identical (after any substitutions)

No differences were encountered in the control files

More details

Full run details