Get user name type

pull/147/head
M66B 6 years ago
parent 3d74b93d74
commit ef2172f7fb

@ -222,10 +222,10 @@ public class FragmentSetup extends FragmentEx {
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid)); throw new IllegalArgumentException(context.getString(R.string.title_email_invalid));
String domain = email.split("@")[1]; String[] dparts = email.split("@");
Provider provider = Provider.fromDomain(context, domain); Provider provider = Provider.fromDomain(context, dparts[1]);
String user = email; // TODO String user = (provider.user == Provider.UserType.EMAIL ? email : dparts[0]);
Character separator; Character separator;
long now = new Date().getTime(); long now = new Date().getTime();

@ -56,6 +56,9 @@ public class Provider {
public String smtp_host; public String smtp_host;
public int smtp_port; public int smtp_port;
public boolean smtp_starttls; public boolean smtp_starttls;
public UserType user = UserType.EMAIL;
enum UserType {LOCAL, EMAIL}
private Provider() { private Provider() {
} }
@ -120,19 +123,16 @@ public class Provider {
return result; return result;
} }
static Provider fromDomain(Context context, String domain) throws IOException, XmlPullParserException { static Provider fromDomain(Context context, String domain) throws IOException {
try { try {
return Provider.fromDNS(context, domain); return Provider.fromISPDB(domain);
} catch (TextParseException ex) { } catch (Throwable ex) {
Log.w(ex);
throw new UnknownHostException(domain);
} catch (UnknownHostException ex) {
Log.w(ex); Log.w(ex);
return Provider.fromConfig(context, domain); return Provider.fromDNS(domain);
} }
} }
private static Provider fromConfig(Context context, String domain) throws IOException, XmlPullParserException { private static Provider fromISPDB(String domain) throws IOException, XmlPullParserException {
// https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat // https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
URL url = new URL("https://autoconfig.thunderbird.net/v1.1/" + domain); URL url = new URL("https://autoconfig.thunderbird.net/v1.1/" + domain);
Log.i("Fetching " + url); Log.i("Fetching " + url);
@ -203,11 +203,27 @@ public class Provider {
provider.imap_starttls = true; provider.imap_starttls = true;
else if (smtp) else if (smtp)
provider.smtp_starttls = true; provider.smtp_starttls = true;
} } else
Log.w("Unknown socket type=" + socket);
} }
continue;
} else if ("username".equals(xml.getName())) {
eventType = xml.next();
if (eventType == XmlPullParser.TEXT) {
String username = xml.getText();
Log.i("Username=" + username);
if ("%EMAILADDRESS%".equals(username))
provider.user = UserType.EMAIL;
else if ("%EMAILLOCALPART%".equals(username))
provider.user = UserType.LOCAL;
else
Log.w("Unknown username type=" + username);
}
continue; continue;
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {
if ("incomingServer".equals(xml.getName())) if ("incomingServer".equals(xml.getName()))
imap = false; imap = false;
@ -225,7 +241,7 @@ public class Provider {
return provider; return provider;
} }
private static Provider fromDNS(Context context, String domain) throws TextParseException, UnknownHostException { private static Provider fromDNS(String domain) throws TextParseException, UnknownHostException {
// https://tools.ietf.org/html/rfc6186 // https://tools.ietf.org/html/rfc6186
SRVRecord imap = lookup("_imaps._tcp." + domain); SRVRecord imap = lookup("_imaps._tcp." + domain);
SRVRecord smtp = lookup("_submission._tcp." + domain); SRVRecord smtp = lookup("_submission._tcp." + domain);

Loading…
Cancel
Save