public void validateInviteUsers(InviteCommand command, MessageContext context) { if (!StringUtils.hasLength(command.getEmails())) { context.addMessage( new MessageBuilder() .error() .defaultText("Turite nurodyti bent vieną e-pašto adresą") .build()); return; } StringTokenizer t = new StringTokenizer(command.getEmails()); while (t.hasMoreTokens()) { String email = t.nextToken(); EmailAddress a = new EmailAddress(email); logger.debug("validating email " + email); if (!a.isValid()) { context.addMessage( new MessageBuilder() .error() .defaultText( "Nurodytas adresas \"" + email + "\" neatitinka e-pašto adresų standarto. Ištrinkite arba pataisykite jį ir mėginkite dar kartą.") .build()); } } }
public EmailAddress addEmailAddress(EmailAddress sorEmailAddress) { MockEmailAddress ea = new MockEmailAddress(); ea.setAddress(sorEmailAddress.getAddress()); ea.setAddressType(sorEmailAddress.getAddressType()); emailAddresses.add(ea); return ea; }
public UserInfo mapToDefaultUserInfo(NomadResponse response) { DefaultUserInfo defaultUserInfo = null; if (response != null) { defaultUserInfo = new DefaultUserInfo(); ResponseNomadUser nomadUser = response.getResponseNomadUser(); if (nomadUser != null) { defaultUserInfo.setSub(nomadUser.getId()); defaultUserInfo.setName(nomadUser.getNameFirst()); defaultUserInfo.setGivenName(nomadUser.getNameFirst()); defaultUserInfo.setMiddleName(nomadUser.getNameInitial()); defaultUserInfo.setFamilyName(nomadUser.getNameLast()); EmailAddress emailAddress = nomadUser.getEmailAddress(); if (emailAddress != null) { String email = emailAddress.getContactInfo(); defaultUserInfo.setPreferredUsername(email); defaultUserInfo.setEmail(email); } PhoneNumbers phoneNumbers = nomadUser.getPhoneNumbers(); if (phoneNumbers != null) { defaultUserInfo.setPhoneNumber(phoneNumbers.getContactInfo()); } } } return defaultUserInfo; }
@Test public void testEquals() { final EqualsTester tester = new EqualsTester(); for (final String test : VALID_EMAIL_ADDRESSES) { tester.addEqualityGroup(EmailAddress.parse(test), EmailAddress.parse(test)); } tester.testEquals(); }
@Test public void testCreate() { try { EmailAddress.create("", "test.com"); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException expected) { } try { EmailAddress.create("test", ""); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException expected) { } }
@Test public void testParse_withInvalid() { final String[] invalidTests = { "Abc.example.com", // (an @ character must separate the local and domain parts) "*****@*****.**", // (character dot(.) is last in local part) "*****@*****.**", // (character dot(.) is double) "A@b@[email protected]", // (only one @ is allowed outside quotation marks) "a\"b(c)d,e:f;g<h>i[j\\k][email protected]", // (none of the special characters in this local // part is allowed outside quotation marks) "just\"not\"*****@*****.**", // (quoted strings must be dot separated, or the only element // making up the local-part) "this is\"not\\[email protected]", // (spaces, quotes, and backslashes may only exist when // within quoted strings and preceded by a slash) "this\\ still\\\"not\\\\[email protected]", // (even if escaped (preceded by a backslash), // spaces, quotes, and backslashes must still be // contained by quotes) "test@[192.168.1.1" // IP in brackets missing trailing bracket }; for (final String invalidEmail : invalidTests) { try { EmailAddress.parse(invalidEmail); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException expected) { } } }
/** * Set the value. * * @param value to set * @throws SdpException if the value is null */ public void setValue(String value) throws SdpException { if (value == null) throw new SdpException("The value is null"); else { emailAddress.setDisplayName(value); } }
@Test public void testParse_withValidUnsupported() { final String[] validUnsupportedTests = { "\"much.more unusual\"@example.com", "\"[email protected]\"@example.com", "\"very.(),:;<>[]\\\".VERY.\\\"very@\\\\ \\\"very\\\".unusual\\\"@strange.example.com", "\"()<>[]:,;@\\\\\\\"!#$%&'*+-/=?^_`{}| ~ ? ^_`{}|~.a\"@example.org", "\"\"@example.org", }; for (final String invalidEmail : validUnsupportedTests) { try { EmailAddress.parse(invalidEmail); fail("expected IllegalArgumentException"); } catch (final IllegalArgumentException expected) { } } }
@Test public void testParse_withValid() { for (final String test : VALID_EMAIL_ADDRESSES) { assertEquals(test, EmailAddress.parse(test).toString()); } }
public ZimbraAdminAccount(String email) { EmailAddress = email; Password = ZimbraSeleniumProperties.getStringProperty("adminPwd", "test123"); ZimbraMailHost = EmailAddress.split("@")[1]; }
// where only an address is supplied private void expectNameAddress3(EmailAddress e) { assertTrue("Expected null, found <" + e.getName() + ">", e.getName() == null); assertEquals("address", e.getAddress()); }
/** * Adds the email address to the mapping using the {@link EmailAddress#getType()} method for the * key. * * @param emailAddress The email address to add. */ public void addEmailAddress(EmailAddress emailAddress) { emailAddresses.put(emailAddress.getType(), emailAddress); }
/** * Returns the value. * * @throws SdpParseException * @return the value */ public String getValue() throws SdpParseException { if (emailAddress == null) return null; else { return emailAddress.getDisplayName(); } }
/** * Get the string encoded version of this object * * @since v1.0 */ public String encode() { return EMAIL_FIELD + emailAddress.encode() + Separators.NEWLINE; }
@Override public String toString() { return EmailAddress.toString(); }
/** * @param email The user entered email address that you want to check for suggestions with * @return null, if no suggestions, or an EmailAddress object containing the suggestion */ public EmailAddress suggest(String email) { EmailAddress emailParts = new EmailAddress(email); if (!emailParts.isValid()) return null; String closestDomain = this.findClosestString( emailParts.getDomain(), configuration.getDomains(), configuration.getDistanceAlgorithm(), configuration.getThreshold()); if (closestDomain != null) { // we have a suggestion if (!emailParts.hasDomain(closestDomain)) { // if we have a suggestion different to the actual domain, return it return emailParts.emailAddressWithDifferentDomain(closestDomain); } } else { // we don't have a suggestion, check tld String closestTopLevelDomain = this.findClosestString( emailParts.getTLD(), configuration.getTopLevelDomains(), configuration.getDistanceAlgorithm(), configuration.getThreshold()); if (emailParts.getDomain() != null && closestTopLevelDomain != null && !closestTopLevelDomain.equals(emailParts.getTLD())) { // return suggestion based off tld String domain = emailParts.getDomain(); closestDomain = domain.substring(0, domain.lastIndexOf(emailParts.getTLD())) + closestTopLevelDomain; return emailParts.emailAddressWithDifferentDomain(closestDomain); } } // exact match, no match, or invalid email so no suggestion return null; }
// where the name contains <> private void expectNameAddress2(EmailAddress e) { assertEquals("<name>", e.getName()); assertEquals("address", e.getAddress()); }