1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

. Fixed issue 423:

. HTMLized version of plain text email is not loaded up as a MIME part of the message anymore. We use a custom seperate variable in the text body class.
This commit is contained in:
Bao-Long Nguyen-Trong 2009-05-20 04:36:20 +00:00
parent 435e2c3532
commit 23797b62ee
2 changed files with 68 additions and 38 deletions

View File

@ -9,7 +9,6 @@ import java.io.OutputStream;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -26,11 +25,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Process;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.util.Regex;
import android.util.Config; import android.util.Config;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -56,8 +51,6 @@ import com.android.email.MessagingController;
import com.android.email.MessagingListener; import com.android.email.MessagingListener;
import com.android.email.R; import com.android.email.R;
import com.android.email.Utility; import com.android.email.Utility;
import com.android.email.activity.FolderMessageList.FolderMessageListAdapter.FolderInfoHolder;
import com.android.email.activity.FolderMessageList.FolderMessageListAdapter.MessageInfoHolder;
import com.android.email.mail.Address; import com.android.email.mail.Address;
import com.android.email.mail.Flag; import com.android.email.mail.Flag;
import com.android.email.mail.Message; import com.android.email.mail.Message;
@ -65,11 +58,10 @@ import com.android.email.mail.MessagingException;
import com.android.email.mail.Multipart; import com.android.email.mail.Multipart;
import com.android.email.mail.Part; import com.android.email.mail.Part;
import com.android.email.mail.Message.RecipientType; import com.android.email.mail.Message.RecipientType;
import com.android.email.mail.internet.MimeHeader;
import com.android.email.mail.internet.MimeUtility; import com.android.email.mail.internet.MimeUtility;
import com.android.email.mail.store.LocalStore.LocalAttachmentBody;
import com.android.email.mail.store.LocalStore.LocalAttachmentBodyPart; import com.android.email.mail.store.LocalStore.LocalAttachmentBodyPart;
import com.android.email.mail.store.LocalStore.LocalMessage; import com.android.email.mail.store.LocalStore.LocalMessage;
import com.android.email.mail.store.LocalStore.LocalTextBody;
import com.android.email.provider.AttachmentProvider; import com.android.email.provider.AttachmentProvider;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -1053,34 +1045,51 @@ public class MessageView extends Activity
@Override @Override
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid, public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
Message message) { Message message) {
Spannable markup; Spannable markup;
MessageView.this.mMessage = message; MessageView.this.mMessage = message;
try { try {
Part part = MimeUtility.findFirstPartByMimeType(mMessage, "text/html"); String text;
if (part == null) { Part part = MimeUtility.findFirstPartByMimeType(mMessage, "text/html");
part = MimeUtility.findFirstPartByMimeType(mMessage, "text/plain"); if (part == null) {
} part = MimeUtility.findFirstPartByMimeType(mMessage, "text/plain");
if (part != null) { if (part == null) {
String text = MimeUtility.getTextFromPart(part); text = null;
/* }
* TODO this should be smarter, change to regex for img, but consider how to else {
* get background images and a million other things that HTML allows. LocalTextBody body = (LocalTextBody)part.getBody();
*/ if (body == null) {
mHandler.showShowPictures(text.contains("<img")); text = null;
mMessageContentView.loadDataWithBaseURL("email://", text, "text/html", "utf-8", null); }
} else {
else text = body.getBodyForDisplay();
mMessageContentView.loadUrl("file:///android_asset/empty.html"); }
renderAttachments(mMessage, 0);
}
catch (Exception e) {
if (Config.LOGV) {
Log.v(Email.LOG_TAG, "loadMessageForViewBodyAvailable", e);
} }
} }
else {
text = MimeUtility.getTextFromPart(part);
}
if (text != null) {
/*
* TODO this should be smarter, change to regex for img, but consider how to
* get background images and a million other things that HTML allows.
*/
mHandler.showShowPictures(text.contains("<img"));
mMessageContentView.loadDataWithBaseURL("email://", text, "text/html", "utf-8", null);
}
else {
mMessageContentView.loadUrl("file:///android_asset/empty.html");
}
renderAttachments(mMessage, 0);
} }
catch (Exception e) {
if (Config.LOGV) {
Log.v(Email.LOG_TAG, "loadMessageForViewBodyAvailable", e);
}
}
}//loadMessageForViewBodyAvailable
@Override @Override

View File

@ -802,15 +802,14 @@ public class LocalStore extends Store implements Serializable {
String htmlContent = cursor.getString(0); String htmlContent = cursor.getString(0);
String textContent = cursor.getString(1); String textContent = cursor.getString(1);
if (htmlContent != null) { if (textContent != null) {
TextBody body = new TextBody(htmlContent); LocalTextBody body = new LocalTextBody(textContent, htmlContent);
MimeBodyPart bp = new MimeBodyPart(body, "text/html"); MimeBodyPart bp = new MimeBodyPart(body, "text/plain");
mp.addBodyPart(bp); mp.addBodyPart(bp);
} }
else {
if (textContent != null) { TextBody body = new TextBody(htmlContent);
TextBody body = new TextBody(textContent); MimeBodyPart bp = new MimeBodyPart(body, "text/html");
MimeBodyPart bp = new MimeBodyPart(body, "text/plain");
mp.addBodyPart(bp); mp.addBodyPart(bp);
} }
} }
@ -1509,6 +1508,28 @@ public class LocalStore extends Store implements Serializable {
} }
} }
public class LocalTextBody extends TextBody {
private String mBodyForDisplay;
public LocalTextBody(String body) {
super(body);
}
public LocalTextBody(String body, String bodyForDisplay) throws MessagingException {
super(body);
this.mBodyForDisplay = bodyForDisplay;
}
public String getBodyForDisplay() {
return mBodyForDisplay;
}
public void setBodyForDisplay(String mBodyForDisplay) {
this.mBodyForDisplay = mBodyForDisplay;
}
}//LocalTextBody
public class LocalMessage extends MimeMessage { public class LocalMessage extends MimeMessage {
private long mId; private long mId;
private int mAttachmentCount; private int mAttachmentCount;