mirror of https://github.com/M66B/FairEmail.git
parent
00180c2840
commit
dbf452e97f
@ -0,0 +1,95 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.AssetFileDescriptor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.method.ScrollingMovementMethod;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.mail.Session;
|
||||||
|
import javax.mail.internet.MimeMessage;
|
||||||
|
|
||||||
|
import androidx.constraintlayout.widget.Group;
|
||||||
|
|
||||||
|
public class ActivityEml extends ActivityBase {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getSupportActionBar().setSubtitle("EML");
|
||||||
|
setContentView(R.layout.activity_eml);
|
||||||
|
|
||||||
|
final TextView tvEml = findViewById(R.id.tvEml);
|
||||||
|
final TextView tvBody = findViewById(R.id.tvBody);
|
||||||
|
final ContentLoadingProgressBar pbWait = findViewById(R.id.pbWait);
|
||||||
|
final Group grpEml = findViewById(R.id.grpEml);
|
||||||
|
tvEml.setMovementMethod(new ScrollingMovementMethod());
|
||||||
|
tvBody.setMovementMethod(new ScrollingMovementMethod());
|
||||||
|
grpEml.setVisibility(View.GONE);
|
||||||
|
pbWait.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
Log.logExtras(getIntent());
|
||||||
|
Log.i("EML uri=" + getIntent().getData());
|
||||||
|
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable("uri", getIntent().getData());
|
||||||
|
|
||||||
|
new SimpleTask<String[]>() {
|
||||||
|
@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");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ActivityEml">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvEml"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:fontFamily="monospace"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:text="EML"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/vSeparator"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_weight="2" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/vSeparator"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:background="?attr/colorSeparator"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/tvBody"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvEml" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBody"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:fontFamily="monospace"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:text="Body"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/vSeparator"
|
||||||
|
app:layout_constraintVertical_weight="1" />
|
||||||
|
|
||||||
|
<eu.faircode.email.ContentLoadingProgressBar
|
||||||
|
android:id="@+id/pbWait"
|
||||||
|
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Group
|
||||||
|
android:id="@+id/grpEml"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:constraint_referenced_ids="tvEml,vSeparator,tvBody" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in new issue