From dbf452e97f63fa8515bfe6e20da6941b115370ea Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 6 Feb 2019 13:07:13 +0000 Subject: [PATCH] Added basic EML viewer --- app/src/main/AndroidManifest.xml | 23 +++++ .../java/eu/faircode/email/ActivityEml.java | 95 +++++++++++++++++++ app/src/main/res/layout/activity_eml.xml | 63 ++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 app/src/main/java/eu/faircode/email/ActivityEml.java create mode 100644 app/src/main/res/layout/activity_eml.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 921890ca7e..20d2bd371f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -123,6 +123,29 @@ + + + + + + + + + + + + + + + + + + + () { + @Override + protected String[] onExecute(Context context, Bundle args) throws Throwable { + Uri uri = args.getParcelable("uri"); + + InputStream is = null; + try { + ContentResolver resolver = context.getContentResolver(); + AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(uri, "*/*", null); + is = new BufferedInputStream(descriptor.createInputStream()); + + Properties props = MessageHelper.getSessionProperties(Helper.AUTH_TYPE_PASSWORD, null, false); + Session isession = Session.getInstance(props, null); + MimeMessage mmessage = new MimeMessage(isession, is); + + String body = null; + try { + MessageHelper helper = new MessageHelper(mmessage); + MessageHelper.MessageParts parts = helper.getMessageParts(); + body = parts.getHtml(context); + } catch (Throwable ex) { + body = ex.toString(); + } + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + mmessage.writeTo(bos); + String eml = new String(bos.toByteArray()); + + return new String[]{eml, body}; + } finally { + if (is != null) + is.close(); + } + } + + @Override + protected void onExecuted(Bundle args, String[] data) { + tvEml.setText(data[0]); + tvBody.setText(Html.fromHtml(data[1])); + grpEml.setVisibility(View.VISIBLE); + pbWait.setVisibility(View.GONE); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(ActivityEml.this, ActivityEml.this, ex); + } + }.execute(this, args, "eml"); + } +} diff --git a/app/src/main/res/layout/activity_eml.xml b/app/src/main/res/layout/activity_eml.xml new file mode 100644 index 0000000000..0cd1ed581a --- /dev/null +++ b/app/src/main/res/layout/activity_eml.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + \ No newline at end of file