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

Method sanitize

app/src/main/java/eu/faircode/email/UriHelper.java:283–507  ·  view source on GitHub ↗
(Context context, Uri uri)

Source from the content-addressed store, hash-verified

281 }
282
283 static Uri sanitize(Context context, Uri uri) {
284 if (uri.isOpaque())
285 return uri;
286
287 Uri url;
288 boolean changed = false;
289 if (uri.getHost() != null &&
290 uri.getHost().endsWith("safelinks.protection.outlook.com") &&
291 !TextUtils.isEmpty(uri.getQueryParameter("url"))) {
292 Uri result = Uri.parse(uri.getQueryParameter("url"));
293 changed = (result != null && isHyperLink(result));
294 url = (changed ? result : uri);
295 } else if ("https".equals(uri.getScheme()) &&
296 "smex-ctp.trendmicro.com".equals(uri.getHost()) &&
297 "/wis/clicktime/v1/query".equals(uri.getPath()) &&
298 !TextUtils.isEmpty(uri.getQueryParameter("url"))) {
299 Uri result = Uri.parse(uri.getQueryParameter("url"));
300 changed = (result != null && isHyperLink(result));
301 url = (changed ? result : uri);
302 } else if ("https".equals(uri.getScheme()) &&
303 "www.google.com".equals(uri.getHost()) &&
304 uri.getPath() != null &&
305 uri.getPath().startsWith("/amp/")) {
306 // https://blog.amp.dev/2017/02/06/whats-in-an-amp-url/
307 Uri result = null;
308
309 String u = uri.toString();
310 u = u.replace("https://www.google.com/amp/", "");
311
312 int p = u.indexOf("/");
313 while (p > 0) {
314 String segment = u.substring(0, p);
315 if (segment.contains(".")) {
316 result = Uri.parse("https://" + u);
317 break;
318 }
319
320 u = u.substring(p + 1);
321 p = u.indexOf("/");
322 }
323
324 changed = (result != null && isHyperLink(result));
325 url = (changed ? result : uri);
326 } else if ("https".equals(uri.getScheme()) &&
327 uri.getHost() != null &&
328 uri.getHost().startsWith("www.google.") &&
329 uri.getQueryParameter("url") != null) {
330 // Google non-com redirects
331 Uri result = Uri.parse(uri.getQueryParameter("url"));
332 changed = (result != null && isHyperLink(result));
333 url = (changed ? result : uri);
334 } else if (uri.getPath() != null &&
335 uri.getPath().startsWith("/track/click") &&
336 uri.getQueryParameter("p") != null) {
337 Uri result = null;
338 try {
339 // Mandrill
340 String p = new String(Base64.decode(uri.getQueryParameter("p"), Base64.URL_SAFE));

Callers 2

onCreateDialogMethod · 0.95
onOpenLinkMethod · 0.95

Calls 15

isHyperLinkMethod · 0.95
iMethod · 0.95
getBraveDebounceMethod · 0.95
filterMethod · 0.95
indexOfMethod · 0.80
getBooleanMethod · 0.80
sizeMethod · 0.65
getHostMethod · 0.45
isEmptyMethod · 0.45
parseMethod · 0.45
equalsMethod · 0.45
getPathMethod · 0.45

Tested by

no test coverage detected