mirror of https://github.com/M66B/FairEmail.git
Improved header highlighting
This commit is contained in:
parent
2c336e0924
commit
b172e217b2
|
@ -87,7 +87,7 @@ public class ActivityDSN extends ActivityBase {
|
|||
Bundle args = new Bundle();
|
||||
args.putParcelable("uri", uri);
|
||||
|
||||
new SimpleTask<Result>() {
|
||||
new SimpleTask<Spanned>() {
|
||||
@Override
|
||||
protected void onPreExecute(Bundle args) {
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
@ -99,35 +99,29 @@ public class ActivityDSN extends ActivityBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Result onExecute(Context context, Bundle args) throws Throwable {
|
||||
protected Spanned onExecute(Context context, Bundle args) throws Throwable {
|
||||
Uri uri = args.getParcelable("uri");
|
||||
|
||||
NoStreamException.check(uri, context);
|
||||
|
||||
Result result = new Result();
|
||||
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
try (InputStream is = resolver.openInputStream(uri)) {
|
||||
if (is == null)
|
||||
throw new FileNotFoundException(uri.toString());
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[Helper.BUFFER_SIZE];
|
||||
int length;
|
||||
while ((length = is.read(buffer)) != -1)
|
||||
bos.write(buffer, 0, length);
|
||||
Helper.copy(is, bos);
|
||||
|
||||
String headers = MessageHelper.decodeMime(bos.toString(StandardCharsets.UTF_8.name()));
|
||||
result.headers = HtmlHelper.highlightHeaders(context,
|
||||
null, null, null, headers, false);
|
||||
String headers = bos.toString(StandardCharsets.UTF_8.name());
|
||||
headers = MessageHelper.decodeMime(headers);
|
||||
return HtmlHelper.highlightHeaders(context,
|
||||
null, null, null, headers, false, false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Result result) {
|
||||
tvHeaders.setText(result.headers);
|
||||
protected void onExecuted(Bundle args, Spanned result) {
|
||||
tvHeaders.setText(result);
|
||||
grpReady.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
@ -140,8 +134,4 @@ public class ActivityDSN extends ActivityBase {
|
|||
}
|
||||
}.execute(this, args, "disposition:decode");
|
||||
}
|
||||
|
||||
private class Result {
|
||||
Spanned headers;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -328,7 +328,11 @@ public class ActivityEML extends ActivityBase {
|
|||
result.structure = ssb;
|
||||
|
||||
result.headers = HtmlHelper.highlightHeaders(context,
|
||||
helper.getFrom(), helper.getTo(), helper.getReceivedHeader(), helper.getHeaders(), false);
|
||||
helper.getFrom(),
|
||||
helper.getTo(),
|
||||
helper.getReceivedHeader(),
|
||||
helper.getHeaders(),
|
||||
false, false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -2768,11 +2768,16 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
|
||||
if (show_headers && message.headers != null) {
|
||||
Spanned headers = HtmlHelper.highlightHeaders(context,
|
||||
SpannableStringBuilder ssb = HtmlHelper.highlightHeaders(context,
|
||||
message.from, message.to, message.received, message.headers,
|
||||
message.blocklist != null && message.blocklist);
|
||||
if (BuildConfig.DEBUG && headers instanceof SpannableStringBuilder) {
|
||||
SpannableStringBuilder ssb = (SpannableStringBuilder) headers;
|
||||
message.blocklist != null && message.blocklist, true);
|
||||
if (BuildConfig.DEBUG) {
|
||||
float stroke = context.getResources().getDisplayMetrics().density;
|
||||
|
||||
ssb.append("\n\uFFFC"); // Object replacement character
|
||||
ssb.setSpan(new LineSpan(colorSeparator, stroke, 0), ssb.length() - 1, ssb.length(), 0);
|
||||
ssb.append('\n');
|
||||
|
||||
ssb.append('\n');
|
||||
ssb.append("TLS=").append(message.tls == null ? "-" : (message.tls ? "✓" : "✗"));
|
||||
ssb.append(" DKIM=").append(message.dkim == null ? "-" : (message.dkim ? "✓" : "✗"));
|
||||
|
@ -2783,7 +2788,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
ssb.append(" BL=").append(message.blocklist == null ? "-" : (message.blocklist ? "✓" : "✗"));
|
||||
ssb.append('\n');
|
||||
}
|
||||
tvHeaders.setText(headers);
|
||||
|
||||
tvHeaders.setText(ssb);
|
||||
ibCopyHeaders.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
tvHeaders.setText(null);
|
||||
|
|
|
@ -2973,7 +2973,8 @@ public class HtmlHelper {
|
|||
return ssb.toString();
|
||||
}
|
||||
|
||||
static Spanned highlightHeaders(Context context, Address[] from, Address[] to, Long time, String headers, boolean blocklist) {
|
||||
static SpannableStringBuilder highlightHeaders(
|
||||
Context context, Address[] from, Address[] to, Long time, String headers, boolean blocklist, boolean withReceived) {
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilderEx(headers.replaceAll("\\t", " "));
|
||||
int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
|
||||
int colorVerified = Helper.resolveColor(context, R.attr.colorVerified);
|
||||
|
@ -2991,6 +2992,7 @@ public class HtmlHelper {
|
|||
index += line.length() + 1;
|
||||
}
|
||||
|
||||
if (withReceived) {
|
||||
ssb.append("\n\uFFFC"); // Object replacement character
|
||||
ssb.setSpan(new LineSpan(colorSeparator, stroke, 0), ssb.length() - 1, ssb.length(), 0);
|
||||
ssb.append('\n');
|
||||
|
@ -3137,10 +3139,7 @@ public class HtmlHelper {
|
|||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
ssb.append("\n\uFFFC"); // Object replacement character
|
||||
ssb.setSpan(new LineSpan(colorSeparator, stroke, 0), ssb.length() - 1, ssb.length(), 0);
|
||||
ssb.append('\n');
|
||||
}
|
||||
|
||||
return ssb;
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@
|
|||
android:id="@+id/vSeparatorBody"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="3dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -249,7 +249,7 @@
|
|||
android:id="@+id/tvBody"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="3dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="Body"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textIsSelectable="true"
|
||||
|
|
Loading…
Reference in New Issue