Basic EML viewing support.
The base of an implementation is there.
We can view the plaintext right now.
Change-Id: Ib9dd37197c0592221f49b7770efb459484a4e6f0
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 24fa2b2..130700b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -111,6 +111,16 @@
android:label="@string/app_name"
android:theme="@style/PhotoViewTheme" >
</activity>
+ <activity
+ android:name=".browse.EmlViewerActivity"
+ android:label="@string/app_name"
+ android:exported="false">
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:mimeType="message/rfc822" />
+ </intent-filter>
+ </activity>
<provider
android:authorities="com.android.mail.mockprovider"
diff --git a/res/layout/eml_viewer_activity.xml b/res/layout/eml_viewer_activity.xml
new file mode 100644
index 0000000..751a4fa
--- /dev/null
+++ b/res/layout/eml_viewer_activity.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <WebView
+ android:id="@+id/eml_web_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ />
+</LinearLayout>
\ No newline at end of file
diff --git a/src/com/android/mail/browse/EmlViewerActivity.java b/src/com/android/mail/browse/EmlViewerActivity.java
new file mode 100644
index 0000000..a102424
--- /dev/null
+++ b/src/com/android/mail/browse/EmlViewerActivity.java
@@ -0,0 +1,65 @@
+package com.android.mail.browse;
+
+import android.app.Activity;
+import android.content.ContentResolver;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.webkit.WebView;
+import android.widget.TextView;
+
+import com.android.mail.R;
+import com.android.mail.utils.LogTag;
+import com.android.mail.utils.LogUtils;
+import com.android.mail.utils.MimeType;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+public class EmlViewerActivity extends Activity {
+ private static final String LOG_TAG = LogTag.getLogTag();
+
+ private WebView mWebView;
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.eml_viewer_activity);
+ mWebView = (WebView) findViewById(R.id.eml_web_view);
+
+ final Intent intent = getIntent();
+ final String action = intent.getAction();
+ final String type = intent.getType();
+
+ if (Intent.ACTION_VIEW.equals(action) &&
+ MimeType.EML_ATTACHMENT_CONTENT_TYPE.equals(type)) {
+ openEmlFile(intent.getData());
+ } else {
+ LogUtils.wtf(LOG_TAG,
+ "Entered EmlViewerActivity with wrong intent action or type: %s, %s",
+ action, type);
+ finish(); // we should not be here. bail out. bail out.
+ }
+ }
+
+ private void openEmlFile(Uri uri) {
+ final ContentResolver resolver = getContentResolver();
+ try {
+ final InputStream stream = resolver.openInputStream(uri);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+ StringBuilder builder = new StringBuilder(stream.available());
+ String line = reader.readLine();
+ while (line != null) {
+ builder.append(line);
+ line = reader.readLine();
+ }
+ mWebView.loadDataWithBaseURL("", builder.toString(), "text/html", "utf-8", null);
+ } catch (FileNotFoundException e) {
+ // TODO handle exceptions
+ } catch (IOException e) {
+ // TODO handle exception
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/mail/utils/MimeType.java b/src/com/android/mail/utils/MimeType.java
index 8f0ca96..0f6a18c 100644
--- a/src/com/android/mail/utils/MimeType.java
+++ b/src/com/android/mail/utils/MimeType.java
@@ -43,7 +43,7 @@
static final String GENERIC_MIMETYPE = "application/octet-stream";
@VisibleForTesting
- static final String EML_ATTACHMENT_CONTENT_TYPE = "application/eml";
+ public static final String EML_ATTACHMENT_CONTENT_TYPE = "message/rfc822";
private static final String NULL_ATTACHMENT_CONTENT_TYPE = "null";
private static final Set<String> UNACCEPTABLE_ATTACHMENT_TYPES = ImmutableSet.of(
"application/zip", "application/x-gzip", "application/x-bzip2",
@@ -151,7 +151,7 @@
* Returns the mime type of the attachment based on its name and
* original mime type. This is an workaround for bugs where Gmail
* server doesn't set content-type for certain types correctly.
- * 1) EML files -> "application/eml".
+ * 1) EML files -> "message/rfc822".
* @param name name of the attachment.
* @param mimeType original mime type of the attachment.
* @return the inferred mime type of the attachment.
@@ -174,7 +174,7 @@
if (!TextUtils.isEmpty(type)) {
return type;
} if (extension.equals("eml")) {
- // Extension is ".eml", return mime type "application/eml"
+ // Extension is ".eml", return mime type "message/rfc822"
return EML_ATTACHMENT_CONTENT_TYPE;
} else {
// Extension is not ".eml", just return original mime type.