mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 23:56:07 +02:00
Improved EML viewer
This commit is contained in:
@@ -6,7 +6,7 @@ import android.content.res.AssetFileDescriptor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.text.Spanned;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -28,12 +28,17 @@ public class ActivityEml extends ActivityBase {
|
||||
getSupportActionBar().setSubtitle("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 tvEml = findViewById(R.id.tvEml);
|
||||
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);
|
||||
|
||||
@@ -43,11 +48,13 @@ public class ActivityEml extends ActivityBase {
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable("uri", getIntent().getData());
|
||||
|
||||
new SimpleTask<String[]>() {
|
||||
new SimpleTask<Result>() {
|
||||
@Override
|
||||
protected String[] onExecute(Context context, Bundle args) throws Throwable {
|
||||
protected Result onExecute(Context context, Bundle args) throws Throwable {
|
||||
Uri uri = args.getParcelable("uri");
|
||||
|
||||
Result result = new Result();
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
@@ -58,20 +65,35 @@ public class ActivityEml extends ActivityBase {
|
||||
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();
|
||||
MessageHelper helper = new MessageHelper(mmessage);
|
||||
|
||||
result.from = MessageHelper.formatAddresses(helper.getFrom());
|
||||
result.to = MessageHelper.formatAddresses(helper.getTo());
|
||||
result.replyto = MessageHelper.formatAddresses(helper.getReply());
|
||||
result.cc = MessageHelper.formatAddresses(helper.getCc());
|
||||
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();
|
||||
mmessage.writeTo(bos);
|
||||
String eml = new String(bos.toByteArray());
|
||||
result.eml = new String(bos.toByteArray());
|
||||
|
||||
return new String[]{eml, body};
|
||||
return result;
|
||||
} finally {
|
||||
if (is != null)
|
||||
is.close();
|
||||
@@ -79,9 +101,16 @@ public class ActivityEml extends ActivityBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, String[] data) {
|
||||
tvEml.setText(data[0]);
|
||||
tvBody.setText(Html.fromHtml(data[1]));
|
||||
protected void onExecuted(Bundle args, Result result) {
|
||||
tvFrom.setText(result.from);
|
||||
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);
|
||||
pbWait.setVisibility(View.GONE);
|
||||
}
|
||||
@@ -92,4 +121,16 @@ public class ActivityEml extends ActivityBase {
|
||||
}
|
||||
}.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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user