private void setupStoreAndSmtpTransport(String serverType, String schemePrefix) throws URISyntaxException { String domainPart = EmailHelper.getDomainFromEmailAddress(mAccount.getEmail()); String suggestedStoreServerName = serverNameSuggester.suggestServerName(serverType, domainPart); URI storeUriForDecode = new URI(mAccount.getStoreUri()); URI storeUri = new URI(schemePrefix, storeUriForDecode.getUserInfo(), suggestedStoreServerName, storeUriForDecode.getPort(), null, null, null); mAccount.setStoreUri(storeUri.toString()); String suggestedTransportServerName = serverNameSuggester.suggestServerName(Protocols.SMTP, domainPart); URI transportUriForDecode = new URI(mAccount.getTransportUri()); URI transportUri = new URI("smtp+tls+", transportUriForDecode.getUserInfo(), suggestedTransportServerName, transportUriForDecode.getPort(), null, null, null); mAccount.setTransportUri(transportUri.toString()); }
private void setupDav() throws URISyntaxException { URI uriForDecode = new URI(mAccount.getStoreUri()); /* * The user info we have been given from * AccountSetupBasics.onManualSetup() is encoded as an IMAP store * URI: AuthType:UserName:Password (no fields should be empty). * However, AuthType is not applicable to WebDAV nor to its store * URI. Re-encode without it, using just the UserName and Password. */ String userPass = ""; String[] userInfo = uriForDecode.getUserInfo().split(":"); if (userInfo.length > 1) { userPass = userInfo[1]; } if (userInfo.length > 2) { userPass = userPass + ":" + userInfo[2]; } String domainPart = EmailHelper.getDomainFromEmailAddress(mAccount.getEmail()); String suggestedServerName = serverNameSuggester.suggestServerName(Protocols.WEBDAV, domainPart); URI uri = new URI("webdav+ssl+", userPass, suggestedServerName, uriForDecode.getPort(), null, null, null); mAccount.setStoreUri(uri.toString()); }
@Test public void getDomainFromEmailAddress_withInvalidEmail_shouldReturnNull() { String result = EmailHelper.getDomainFromEmailAddress("user"); assertNull(result); }
@Test public void getDomainFromEmailAddress_withTLD_shouldReturnDomain() { String result = EmailHelper.getDomainFromEmailAddress("user@domain"); assertEquals("domain", result); } }
@Test public void getDomainFromEmailAddress_withRegularEmail_shouldReturnsDomain() { String result = EmailHelper.getDomainFromEmailAddress("user@domain.com"); assertEquals("domain.com", result); }