mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-04 11:54:10 +01:00
Improved EML viewer
This commit is contained in:
@@ -6,7 +6,7 @@ import android.content.res.AssetFileDescriptor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.Spanned;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -28,12 +28,17 @@ public class ActivityEml extends ActivityBase {
|
|||||||
getSupportActionBar().setSubtitle("EML");
|
getSupportActionBar().setSubtitle("EML");
|
||||||
setContentView(R.layout.activity_eml);
|
setContentView(R.layout.activity_eml);
|
||||||
|
|
||||||
final TextView tvEml = findViewById(R.id.tvEml);
|
final TextView tvTo = findViewById(R.id.tvTo);
|
||||||
|
final TextView tvFrom = findViewById(R.id.tvFrom);
|
||||||
|
final TextView tvReplyTo = findViewById(R.id.tvReplyTo);
|
||||||
|
final TextView tvCc = findViewById(R.id.tvCc);
|
||||||
|
final TextView tvBcc = findViewById(R.id.tvBcc);
|
||||||
|
final TextView tvSubject = findViewById(R.id.tvSubject);
|
||||||
|
final TextView tvParts = findViewById(R.id.tvParts);
|
||||||
final TextView tvBody = findViewById(R.id.tvBody);
|
final TextView tvBody = findViewById(R.id.tvBody);
|
||||||
|
final TextView tvEml = findViewById(R.id.tvEml);
|
||||||
final ContentLoadingProgressBar pbWait = findViewById(R.id.pbWait);
|
final ContentLoadingProgressBar pbWait = findViewById(R.id.pbWait);
|
||||||
final Group grpEml = findViewById(R.id.grpEml);
|
final Group grpEml = findViewById(R.id.grpEml);
|
||||||
tvEml.setMovementMethod(new ScrollingMovementMethod());
|
|
||||||
tvBody.setMovementMethod(new ScrollingMovementMethod());
|
|
||||||
grpEml.setVisibility(View.GONE);
|
grpEml.setVisibility(View.GONE);
|
||||||
pbWait.setVisibility(View.VISIBLE);
|
pbWait.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
@@ -43,11 +48,13 @@ public class ActivityEml extends ActivityBase {
|
|||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putParcelable("uri", getIntent().getData());
|
args.putParcelable("uri", getIntent().getData());
|
||||||
|
|
||||||
new SimpleTask<String[]>() {
|
new SimpleTask<Result>() {
|
||||||
@Override
|
@Override
|
||||||
protected String[] onExecute(Context context, Bundle args) throws Throwable {
|
protected Result onExecute(Context context, Bundle args) throws Throwable {
|
||||||
Uri uri = args.getParcelable("uri");
|
Uri uri = args.getParcelable("uri");
|
||||||
|
|
||||||
|
Result result = new Result();
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
ContentResolver resolver = context.getContentResolver();
|
ContentResolver resolver = context.getContentResolver();
|
||||||
@@ -58,20 +65,35 @@ public class ActivityEml extends ActivityBase {
|
|||||||
Session isession = Session.getInstance(props, null);
|
Session isession = Session.getInstance(props, null);
|
||||||
MimeMessage mmessage = new MimeMessage(isession, is);
|
MimeMessage mmessage = new MimeMessage(isession, is);
|
||||||
|
|
||||||
String body = null;
|
MessageHelper helper = new MessageHelper(mmessage);
|
||||||
try {
|
|
||||||
MessageHelper helper = new MessageHelper(mmessage);
|
result.from = MessageHelper.formatAddresses(helper.getFrom());
|
||||||
MessageHelper.MessageParts parts = helper.getMessageParts();
|
result.to = MessageHelper.formatAddresses(helper.getTo());
|
||||||
body = parts.getHtml(context);
|
result.replyto = MessageHelper.formatAddresses(helper.getReply());
|
||||||
} catch (Throwable ex) {
|
result.cc = MessageHelper.formatAddresses(helper.getCc());
|
||||||
body = ex.toString();
|
result.bcc = MessageHelper.formatAddresses(helper.getBcc());
|
||||||
|
result.subject = helper.getSubject();
|
||||||
|
|
||||||
|
MessageHelper.MessageParts parts = helper.getMessageParts();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (MessageHelper.AttachmentPart apart : parts.getRawAttachments()) {
|
||||||
|
if (sb.length() > 0)
|
||||||
|
sb.append("<br />");
|
||||||
|
sb.append(
|
||||||
|
apart.part.getContentType()).append(' ')
|
||||||
|
.append(apart.disposition).append(' ')
|
||||||
|
.append(apart.filename);
|
||||||
}
|
}
|
||||||
|
result.parts = Html.fromHtml(sb.toString());
|
||||||
|
|
||||||
|
result.body = Html.fromHtml(parts.getHtml(context));
|
||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
mmessage.writeTo(bos);
|
mmessage.writeTo(bos);
|
||||||
String eml = new String(bos.toByteArray());
|
result.eml = new String(bos.toByteArray());
|
||||||
|
|
||||||
return new String[]{eml, body};
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
if (is != null)
|
if (is != null)
|
||||||
is.close();
|
is.close();
|
||||||
@@ -79,9 +101,16 @@ public class ActivityEml extends ActivityBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onExecuted(Bundle args, String[] data) {
|
protected void onExecuted(Bundle args, Result result) {
|
||||||
tvEml.setText(data[0]);
|
tvFrom.setText(result.from);
|
||||||
tvBody.setText(Html.fromHtml(data[1]));
|
tvTo.setText(result.to);
|
||||||
|
tvReplyTo.setText(result.replyto);
|
||||||
|
tvCc.setText(result.cc);
|
||||||
|
tvBcc.setText(result.bcc);
|
||||||
|
tvSubject.setText(result.subject);
|
||||||
|
tvParts.setText(result.parts);
|
||||||
|
tvBody.setText(result.body);
|
||||||
|
tvEml.setText(result.eml);
|
||||||
grpEml.setVisibility(View.VISIBLE);
|
grpEml.setVisibility(View.VISIBLE);
|
||||||
pbWait.setVisibility(View.GONE);
|
pbWait.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
@@ -92,4 +121,16 @@ public class ActivityEml extends ActivityBase {
|
|||||||
}
|
}
|
||||||
}.execute(this, args, "eml");
|
}.execute(this, args, "eml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Result {
|
||||||
|
String from;
|
||||||
|
String to;
|
||||||
|
String replyto;
|
||||||
|
String cc;
|
||||||
|
String bcc;
|
||||||
|
String subject;
|
||||||
|
Spanned parts;
|
||||||
|
Spanned body;
|
||||||
|
String eml;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -626,6 +626,10 @@ public class MessageHelper {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<AttachmentPart> getRawAttachments() {
|
||||||
|
return attachments;
|
||||||
|
}
|
||||||
|
|
||||||
List<EntityAttachment> getAttachments() throws MessagingException {
|
List<EntityAttachment> getAttachments() throws MessagingException {
|
||||||
List<EntityAttachment> result = new ArrayList<>();
|
List<EntityAttachment> result = new ArrayList<>();
|
||||||
|
|
||||||
@@ -734,7 +738,7 @@ public class MessageHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AttachmentPart {
|
class AttachmentPart {
|
||||||
String disposition;
|
String disposition;
|
||||||
String filename;
|
String filename;
|
||||||
boolean pgp;
|
boolean pgp;
|
||||||
|
|||||||
@@ -1,63 +1,221 @@
|
|||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
tools:context=".ActivityEml">
|
tools:context=".ActivityEml">
|
||||||
|
|
||||||
<TextView
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
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_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="match_parent">
|
||||||
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
|
<TextView
|
||||||
android:id="@+id/pbWait"
|
android:id="@+id/tvFromTitle"
|
||||||
style="@style/Base.Widget.AppCompat.ProgressBar"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:text="@string/title_from"
|
||||||
android:indeterminate="true"
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Group
|
<TextView
|
||||||
android:id="@+id/grpEml"
|
android:id="@+id/tvFrom"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
app:constraint_referenced_ids="tvEml,vSeparator,tvBody" />
|
android:layout_marginStart="6dp"
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
android:text="From"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/tvFromTitle"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvToTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/title_to"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvFrom" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvTo"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:text="To"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/tvToTitle"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvFrom" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvReplyToTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/title_reply_to"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvTo" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvReplyTo"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:text="Reply to"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/tvReplyToTitle"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvTo" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvCcTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/title_cc"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvReplyTo" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvCc"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:text="Cc"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/tvCcTitle"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvReplyTo" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBccTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/title_bcc"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvCc" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBcc"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:text="Bcc"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/tvBccTitle"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvCc" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvSubject"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Subject"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvBcc" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/vSeparatorParts"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:background="?attr/colorSeparator"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvSubject" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvParts"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:text="Parts"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/vSeparatorParts" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/vSeparatorBody"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:background="?attr/colorSeparator"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvParts" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBody"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:fontFamily="monospace"
|
||||||
|
android:text="Body"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/vSeparatorBody" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/vSeparatorEml"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:background="?attr/colorSeparator"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvBody" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvEml"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
|
android:fontFamily="monospace"
|
||||||
|
android:text="EML"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/vSeparatorEml" />
|
||||||
|
|
||||||
|
<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="
|
||||||
|
tvFromTitle,tvFrom,
|
||||||
|
tvToTitle,tvTo,
|
||||||
|
tvReplyToTitle,tvReplyTo,
|
||||||
|
tvCcTitle,tvCc,
|
||||||
|
tvBccTitle,tvBcc,
|
||||||
|
tvSubject,
|
||||||
|
vSeparatorParts,tvParts,
|
||||||
|
vSeparatorBody,tvBody,
|
||||||
|
vSeparatorEml,tvEml" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</ScrollView>
|
||||||
Reference in New Issue
Block a user