diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Account.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Account.java index 868a6f5e..9d211fde 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Account.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Account.java @@ -303,6 +303,21 @@ public class Account extends AcmeJsonResource { return this; } + /** + * Adds a new Contact email to the account. + *

+ * This is a convenience call for {@link #addContact(String)} hat doesn't + * require from you attach "mailto" scheme before email address. + * + * @param email + * Contact email without "mailto" scheme (e.g. test@gmail.com) + * @return itself + */ + public EditableAccount addEmail(String email) { + addContact("mailto:" + email); + return this; + } + /** * Commits the changes and updates the account. */ diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/AccountBuilder.java b/acme4j-client/src/main/java/org/shredzone/acme4j/AccountBuilder.java index fbcd9688..47e329e6 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/AccountBuilder.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/AccountBuilder.java @@ -84,6 +84,23 @@ public class AccountBuilder { return this; } + /** + * Add a email address to the list of contacts. + *

+ * This is a convenience call for {@link #addContact(String)} that doesn't + * require from you attach "mailto" scheme before email address. + * + * @param email + * Contact email without "mailto" scheme (e.g. test@gmail.com) + * @throws IllegalArgumentException + * if there is a syntax error in the URI string + * @return itself + */ + public AccountBuilder addEmail(String email) { + addContact("mailto:" + email); + return this; + } + /** * Signals that the user agrees to the terms of service. * diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java index c3645ae4..3e4cee9d 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/AccountBuilderTest.java @@ -28,6 +28,7 @@ import org.jose4j.jws.JsonWebSignature; import org.jose4j.jwx.CompactSerializer; import org.jose4j.lang.JoseException; import org.junit.Test; +import org.mockito.Mockito; import org.shredzone.acme4j.connector.Resource; import org.shredzone.acme4j.provider.TestableConnectionProvider; import org.shredzone.acme4j.toolbox.AcmeUtils; @@ -220,4 +221,10 @@ public class AccountBuilderTest { provider.close(); } + @Test + public void testEmailAddresses() { + AccountBuilder builder = Mockito.spy(AccountBuilder.class); + builder.addEmail("foo@example.com"); + Mockito.verify(builder).addContact(Mockito.eq("mailto:foo@example.com")); + } }