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

Method onExecute

app/src/main/java/eu/faircode/email/ActivityAMP.java:224–282  ·  view source on GitHub ↗
(Context context, Bundle args)

Source from the content-addressed store, hash-verified

222 }
223
224 @Override
225 protected String onExecute(Context context, Bundle args) throws Throwable {
226 Uri uri = args.getParcelable("uri");
227 long id = args.getLong("id");
228
229 NoStreamException.check(uri, context);
230
231 DB db = DB.getInstance(context);
232 EntityMessage message = db.message().getMessage(id);
233
234 args.putString("subject",
235 message == null || message.subject == null ? "AMP" : message.subject);
236
237 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
238 boolean overview_mode = prefs.getBoolean("overview_mode", false);
239
240 String html;
241 ContentResolver resolver = context.getContentResolver();
242 try (InputStream is = resolver.openInputStream(uri)) {
243 if (is == null)
244 throw new FileNotFoundException(uri.toString());
245 html = Helper.readStream(is);
246 }
247
248 Document d = JsoupEx.parse(html);
249 HtmlHelper.setViewport(d, overview_mode);
250 if (message != null)
251 HtmlHelper.embedInlineImages(context, message.id, d, true);
252
253 for (Element elm : d.select("*")) {
254 if ("script".equals(elm.tagName())) {
255 String src = elm.attr("src");
256
257 if (src.isEmpty()) {
258 elm.remove();
259 continue;
260 }
261
262 Uri u = Uri.parse(src);
263 String host = (u.isHierarchical() ? u.getHost() : null);
264 if (host == null || !ALLOWED_SCRIPT_HOSTS.contains(host.toLowerCase(Locale.ROOT))) {
265 elm.remove();
266 continue;
267 }
268 }
269
270 List<String> toRemove = new ArrayList<>();
271 for (Attribute attr : elm.attributes()) {
272 String key = attr.getKey().toLowerCase(Locale.ROOT);
273 String val = attr.getValue().trim().toLowerCase();
274 if (val.startsWith("javascript:") || key.startsWith("on"))
275 toRemove.add(attr.getKey());
276 }
277
278 toRemove.forEach(elm::removeAttr);
279 }
280
281 return d.html();

Callers

nothing calls this directly

Calls 15

checkMethod · 0.95
getInstanceMethod · 0.95
messageMethod · 0.95
readStreamMethod · 0.95
parseMethod · 0.95
setViewportMethod · 0.95
embedInlineImagesMethod · 0.95
getLongMethod · 0.80
getBooleanMethod · 0.80
trimMethod · 0.80
htmlMethod · 0.80
getMessageMethod · 0.65

Tested by

no test coverage detected