git » chasquid » commit 9388b39

aliases: Normalize right-hand side addresses

author Alberto Bertogli
2017-07-13 23:54:55 UTC
committer Alberto Bertogli
2017-07-14 00:06:09 UTC
parent a016d785151fbd5bc21158c60cb6f4b38e315678

aliases: Normalize right-hand side addresses

The right-hand side addresses of an alias should be normalized, to
maintain the internal invariant that we always deal with normalized
addresses.

Otherwise, strange situations may arise, such as the same domain having
two different domaininfo structures depending on case.

internal/aliases/aliases.go +1 -0
internal/aliases/aliases_test.go +5 -0

diff --git a/internal/aliases/aliases.go b/internal/aliases/aliases.go
index 160987a..31ef18b 100644
--- a/internal/aliases/aliases.go
+++ b/internal/aliases/aliases.go
@@ -299,6 +299,7 @@ func parseFile(domain, path string) (map[string][]Recipient, error) {
 				if !strings.Contains(a, "@") {
 					a = a + "@" + domain
 				}
+				a, _ = normalize.Addr(a)
 				rs = append(rs, Recipient{a, EMAIL})
 			}
 			aliases[addr] = rs
diff --git a/internal/aliases/aliases_test.go b/internal/aliases/aliases_test.go
index a18f92a..b25b9cc 100644
--- a/internal/aliases/aliases_test.go
+++ b/internal/aliases/aliases_test.go
@@ -237,6 +237,9 @@ a@dom: x@dom
 o1: a
 o1: b
 
+# Check that we normalize the right hand side.
+aA: bB@dom-B
+
 # Finally one to make the file NOT end in \n:
 y: z`
 
@@ -255,6 +258,8 @@ func TestRichFile(t *testing.T) {
 		{"c@dom", []Recipient{{"d@e", EMAIL}, {"f@dom", EMAIL}}},
 		{"x@dom", []Recipient{{"command", PIPE}}},
 		{"o1@dom", []Recipient{{"b@dom", EMAIL}}},
+		{"aA@dom", []Recipient{{"bb@dom-b", EMAIL}}},
+		{"aa@dom", []Recipient{{"bb@dom-b", EMAIL}}},
 		{"y@dom", []Recipient{{"z@dom", EMAIL}}},
 	}
 	cases.check(t, resolver)