Merge "services/identityd: Bugfix"
diff --git a/services/identity/auditor/blessing_auditor.go b/services/identity/auditor/blessing_auditor.go
index cd540e9..d6858ae 100644
--- a/services/identity/auditor/blessing_auditor.go
+++ b/services/identity/auditor/blessing_auditor.go
@@ -78,7 +78,18 @@
 	if !ok {
 		return d, fmt.Errorf("failed to extract extension")
 	}
-	d.email = strings.Split(extension, "/")[0]
+	// Find the first email component
+	for _, n := range strings.Split(extension, security.ChainSeparator) {
+		// HACK ALERT: An email is the first entry to end up with
+		// a single "@" in it
+		if strings.Count(n, "@") == 1 {
+			d.email = n
+			break
+		}
+	}
+	if len(d.email) == 0 {
+		return d, fmt.Errorf("failed to extract email address from extension %q", extension)
+	}
 	var caveats []security.Caveat
 	for _, arg := range entry.Arguments[3:] {
 		if cav, ok := arg.(security.Caveat); !ok {
diff --git a/services/identity/auditor/blessing_auditor_test.go b/services/identity/auditor/blessing_auditor_test.go
index c592699..5b1f50b 100644
--- a/services/identity/auditor/blessing_auditor_test.go
+++ b/services/identity/auditor/blessing_auditor_test.go
@@ -28,24 +28,24 @@
 		Blessings          security.Blessings
 	}{
 		{
-			Extension:          "email/nocaveats",
-			Email:              "email",
+			Extension:          "foo@bar.com/nocaveats/bar@baz.com",
+			Email:              "foo@bar.com",
 			RevocationCaveatID: "",
-			Blessings:          newBlessing(t, p, "test/email/nocaveats"),
+			Blessings:          newBlessing(t, p, "test/foo@bar.com/nocaveats/bar@baz.com"),
 		},
 		{
-			Extension:          "email/caveat",
-			Email:              "email",
+			Extension:          "users/foo@bar.com/caveat",
+			Email:              "foo@bar.com",
 			Caveats:            []security.Caveat{expiryCaveat},
 			RevocationCaveatID: "",
-			Blessings:          newBlessing(t, p, "test/email/caveat"),
+			Blessings:          newBlessing(t, p, "test/foo@bar.com/caveat"),
 		},
 		{
-			Extension:          "email/caveatAndRevocation",
-			Email:              "email",
+			Extension:          "special/guests/foo@bar.com/caveatAndRevocation",
+			Email:              "foo@bar.com",
 			Caveats:            []security.Caveat{expiryCaveat, newCaveat(security.NewCaveat(revocationCaveat))},
 			RevocationCaveatID: revocationCaveat.ID(),
-			Blessings:          newBlessing(t, p, "test/email/caveatAndRevocation"),
+			Blessings:          newBlessing(t, p, "test/foo@bar.com/caveatAndRevocation"),
 		},
 	}