From 446a611e5788d42d58d127c7433823e1034da84b Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 16 Aug 2023 10:17:57 +0200 Subject: [PATCH] Added Jsoup helper --- .../eu/faircode/email/AdapterMessage.java | 73 +++++++++++++++++++ app/src/main/res/menu/popup_message_more.xml | 5 ++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 79 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index d8cfa75aba..767c37601e 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -6012,6 +6012,9 @@ public class AdapterMessage extends RecyclerView.Adapter>() { + @Override + protected List onExecute(Context context, Bundle args) throws IOException { + long id = args.getLong("id"); + String selected = args.getString("selected"); + + Map map = new HashMap<>(); + + DB db = DB.getInstance(context); + EntityMessage message = db.message().getMessage(id); + if (message == null || !message.content) + return null; + + Document d = JsoupEx.parse(message.getFile(context)); + + List result = new ArrayList<>(); + for (Element element : d.select(String.format("*:containsOwn(%s)", selected))) { + List path = new ArrayList<>(); + Element e = element; + while (e != null && e.parent() != null /* skip #root */) { + int index = 0; + for (Element p : e.previousElementSiblings()) + if (Objects.equals(e.tagName(), p.tagName())) + index++; + path.add(String.format("%s:eq(%d)", e.tagName(), index)); + e = e.parent(); + } + Collections.reverse(path); + result.add(TextUtils.join(" > ", path)); + } + + return result; + } + + @Override + protected void onExecuted(Bundle args, List jsoup) { + if (jsoup != null && jsoup.size() > 0) { + ClipboardManager clipboard = Helper.getSystemService(context, ClipboardManager.class); + if (clipboard == null) + return; + + ClipData clip = ClipData.newPlainText( + context.getString(R.string.app_name), + jsoup.get(0)); + clipboard.setPrimaryClip(clip); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) + ToastEx.makeText(context, jsoup.get(0), Toast.LENGTH_LONG).show(); + } + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.execute(context, owner, args, "message:jsoup"); + } + private void onMenuResetQuestions(TupleMessageEx message) { Bundle args = new Bundle(); args.putLong("id", message.id); diff --git a/app/src/main/res/menu/popup_message_more.xml b/app/src/main/res/menu/popup_message_more.xml index e52bf6536a..dbd28ba875 100644 --- a/app/src/main/res/menu/popup_message_more.xml +++ b/app/src/main/res/menu/popup_message_more.xml @@ -170,6 +170,11 @@ android:icon="@drawable/baseline_mail_more_24" android:title="@string/title_thread_info" /> + + Encrypt Decrypt Thread info + Jsoup Reset link questions Resync Encoding