MCPcopy Create free account
hub / github.com/M66B/FairEmail / get

Method get

app/src/extra/java/eu/faircode/email/Bimi.java:84–384  ·  view source on GitHub ↗
(
            Context context, String _domain, String selector, int scaleToPixels)

Source from the content-addressed store, hash-verified

82 ));
83
84 static Pair<Bitmap, Boolean> get(
85 Context context, String _domain, String selector, int scaleToPixels)
86 throws IOException {
87 Bitmap bitmap = null;
88 boolean verified = false;
89
90 if (TextUtils.isEmpty(selector))
91 selector = "default";
92
93 // Get DNS record
94 String domain = _domain;
95 DnsHelper.DnsRecord record = lookupBimi(context, selector, domain);
96 if (record == null) {
97 String parent = UriHelper.getParentDomain(context, domain);
98 if (parent == null)
99 return null;
100 domain = parent;
101 record = lookupBimi(context, selector, domain);
102 if (record == null)
103 return null;
104 }
105
106 // Process DNS record
107 Map<String, String> values = MessageHelper.getKeyValues(record.response);
108 List<String> tags = new ArrayList<>(values.keySet());
109 Collections.sort(tags); // process certificate first
110 for (String tag : tags) {
111 switch (tag) {
112 // Version
113 case "v": {
114 String version = values.get(tag);
115 if (!"BIMI1".equalsIgnoreCase(version))
116 Log.w("BIMI unsupported version=" + version);
117 break;
118 }
119
120 // Image link
121 case "l": {
122 if (bitmap != null)
123 continue;
124
125 String l = values.get(tag);
126 if (TextUtils.isEmpty(l))
127 continue;
128
129 try {
130 Uri ul = Uri.parse(l);
131 if (!"https".equals(ul.getScheme()))
132 throw new MalformedURLException(l);
133
134 URL url = new URL(l);
135 Log.i("BIMI favicon " + url);
136
137 HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
138 connection.setRequestMethod("GET");
139 connection.setReadTimeout(READ_TIMEOUT);
140 connection.setConnectTimeout(CONNECT_TIMEOUT);
141 connection.setInstanceFollowRedirects(true);

Callers

nothing calls this directly

Calls 15

lookupBimiMethod · 0.95
getParentDomainMethod · 0.95
getKeyValuesMethod · 0.95
wMethod · 0.95
iMethod · 0.95
setUserAgentMethod · 0.95
renderSvgMethod · 0.95
getRootDomainMethod · 0.95
getDnsNamesMethod · 0.95
getDataUriTypeMethod · 0.95
getDataUriStreamMethod · 0.95
eMethod · 0.95

Tested by

no test coverage detected