Added simple DNS viewer

pull/153/head
M66B 6 years ago
parent ee3ea6e1c7
commit 1d78d7a863

@ -161,6 +161,7 @@ dependencies {
// https://javaee.github.io/javamail/
// https://projects.eclipse.org/projects/ee4j.javamail
// https://mvnrepository.com/artifact/com.sun.mail
implementation "com.sun.mail:android-mail:$javamail_version"
implementation "com.sun.mail:android-activation:$javamail_version"

@ -160,6 +160,24 @@
</intent-filter>
</activity>
<activity
android:name=".ActivityDSN"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:mimeType="message/disposition-notification" />
<data android:host="*" />
</intent-filter>
</activity>
<service android:name=".ServiceSynchronize" />
<service android:name=".ServiceSend" />

@ -0,0 +1,93 @@
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.view.View;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import androidx.constraintlayout.widget.Group;
public class ActivityDSN extends ActivityBase {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setSubtitle("DSN");
setContentView(R.layout.activity_dsn);
final TextView tvHeaders = findViewById(R.id.tvHeaders);
final ContentLoadingProgressBar pbWait = findViewById(R.id.pbWait);
final Group grpReady = findViewById(R.id.grpReady);
grpReady.setVisibility(View.GONE);
Uri uri = getIntent().getData();
if (uri == null) {
pbWait.setVisibility(View.GONE);
return;
} else
pbWait.setVisibility(View.VISIBLE);
Log.i("Disposition uri=" + uri);
Bundle args = new Bundle();
args.putParcelable("uri", uri);
new SimpleTask<Result>() {
@Override
protected void onPostExecute(Bundle args) {
pbWait.setVisibility(View.GONE);
}
@Override
protected Result onExecute(Context context, Bundle args) throws Throwable {
Uri uri = args.getParcelable("uri");
if ("file".equals(uri.getScheme()))
throw new IllegalArgumentException(context.getString(R.string.title_no_stream));
Result result = new Result();
ContentResolver resolver = context.getContentResolver();
AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(uri, "*/*", null);
try (InputStream is = new BufferedInputStream(descriptor.createInputStream())) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) != -1)
bos.write(buffer, 0, length);
result.headers = bos.toString("UTF-8");
}
return result;
}
@Override
protected void onExecuted(Bundle args, Result result) {
tvHeaders.setText(result.headers);
grpReady.setVisibility(View.VISIBLE);
}
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(findViewById(android.R.id.content), ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(ActivityDSN.this, ActivityDSN.this, ex);
}
}.execute(this, args, "disposition:decode");
}
private class Result {
String headers;
}
}

@ -0,0 +1,44 @@
<ScrollView 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"
android:orientation="vertical"
tools:context=".ActivityDSN">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvHeaders"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:fontFamily="monospace"
android:minHeight="60dp"
android:text="Headers"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<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/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvHeaders" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Loading…
Cancel
Save