Revert adding methods to Message and Part
This commit is contained in:
parent
d24998d584
commit
946565347a
11 changed files with 78 additions and 100 deletions
|
@ -101,6 +101,7 @@ import com.fsck.k9.mail.Message.RecipientType;
|
|||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Multipart;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeBodyPart;
|
||||
import com.fsck.k9.mail.internet.MimeHeader;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
|
@ -2955,10 +2956,10 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
|
||||
|
||||
if (messageFormat == MessageFormat.HTML) {
|
||||
Part part = message.findFirstPartByMimeType("text/html");
|
||||
Part part = MimeUtility.findFirstPartByMimeType(message, "text/html");
|
||||
if (part != null) { // Shouldn't happen if we were the one who saved it.
|
||||
mQuotedTextFormat = SimpleMessageFormat.HTML;
|
||||
String text = part.getText();
|
||||
String text = MessageExtractor.getTextFromPart(part);
|
||||
if (K9.DEBUG) {
|
||||
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
|
||||
}
|
||||
|
@ -3021,9 +3022,9 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
*/
|
||||
private void processSourceMessageText(Message message, Integer bodyOffset, Integer bodyLength,
|
||||
boolean viewMessageContent) throws MessagingException {
|
||||
Part textPart = message.findFirstPartByMimeType("text/plain");
|
||||
Part textPart = MimeUtility.findFirstPartByMimeType(message, "text/plain");
|
||||
if (textPart != null) {
|
||||
String text = textPart.getText();
|
||||
String text = MessageExtractor.getTextFromPart(textPart);
|
||||
if (K9.DEBUG) {
|
||||
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
|
||||
}
|
||||
|
@ -3091,7 +3092,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
// Figure out which message format to use for the quoted text by looking if the source
|
||||
// message contains a text/html part. If it does, we use that.
|
||||
mQuotedTextFormat =
|
||||
(mSourceMessage.findFirstPartByMimeType("text/html") == null) ?
|
||||
(MimeUtility.findFirstPartByMimeType(mSourceMessage, "text/html") == null) ?
|
||||
SimpleMessageFormat.TEXT : SimpleMessageFormat.HTML;
|
||||
} else {
|
||||
mQuotedTextFormat = SimpleMessageFormat.HTML;
|
||||
|
@ -3221,37 +3222,39 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
|||
Part part;
|
||||
if (format == SimpleMessageFormat.HTML) {
|
||||
// HTML takes precedence, then text.
|
||||
part = message.findFirstPartByMimeType("text/html");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
|
||||
if (part != null) {
|
||||
if (K9.DEBUG) {
|
||||
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, HTML found.");
|
||||
}
|
||||
return part.getText();
|
||||
return MessageExtractor.getTextFromPart(part);
|
||||
}
|
||||
|
||||
part = message.findFirstPartByMimeType("text/plain");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
|
||||
if (part != null) {
|
||||
if (K9.DEBUG) {
|
||||
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, text found.");
|
||||
}
|
||||
return HtmlConverter.textToHtml(part.getText());
|
||||
String text = MessageExtractor.getTextFromPart(part);
|
||||
return HtmlConverter.textToHtml(text);
|
||||
}
|
||||
} else if (format == SimpleMessageFormat.TEXT) {
|
||||
// Text takes precedence, then html.
|
||||
part = message.findFirstPartByMimeType("text/plain");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
|
||||
if (part != null) {
|
||||
if (K9.DEBUG) {
|
||||
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: Text requested, text found.");
|
||||
}
|
||||
return part.getText();
|
||||
return MessageExtractor.getTextFromPart(part);
|
||||
}
|
||||
|
||||
part = message.findFirstPartByMimeType("text/html");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
|
||||
if (part != null) {
|
||||
if (K9.DEBUG) {
|
||||
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: Text requested, HTML found.");
|
||||
}
|
||||
return HtmlConverter.htmlToText(part.getText());
|
||||
String text = MessageExtractor.getTextFromPart(part);
|
||||
return HtmlConverter.htmlToText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ import com.fsck.k9.mail.PushReceiver;
|
|||
import com.fsck.k9.mail.Pusher;
|
||||
import com.fsck.k9.mail.Store;
|
||||
import com.fsck.k9.mail.Transport;
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
import com.fsck.k9.mail.internet.TextBody;
|
||||
|
@ -1744,7 +1745,7 @@ public class MessagingController implements Runnable {
|
|||
* right now, attachments will be left for later.
|
||||
*/
|
||||
|
||||
Set<Part> viewables = message.collectTextParts();
|
||||
Set<Part> viewables = MessageExtractor.collectTextParts(message);
|
||||
|
||||
/*
|
||||
* Now download the parts we're interested in storing.
|
||||
|
@ -3197,7 +3198,7 @@ public class MessagingController implements Runnable {
|
|||
try {
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
|
||||
List<Part> attachments = message.collectAttachments();
|
||||
List<Part> attachments = MessageExtractor.collectAttachments(message);
|
||||
for (Part attachment : attachments) {
|
||||
attachment.setBody(null);
|
||||
}
|
||||
|
@ -4244,12 +4245,12 @@ public class MessagingController implements Runnable {
|
|||
try {
|
||||
Intent msg = new Intent(Intent.ACTION_SEND);
|
||||
String quotedText = null;
|
||||
Part part = message.findFirstPartByMimeType("text/plain");
|
||||
Part part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
|
||||
if (part == null) {
|
||||
part = message.findFirstPartByMimeType("text/html");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
|
||||
}
|
||||
if (part != null) {
|
||||
quotedText = part.getText();
|
||||
quotedText = MessageExtractor.getTextFromPart(part);
|
||||
}
|
||||
if (quotedText != null) {
|
||||
msg.putExtra(Intent.EXTRA_TEXT, quotedText);
|
||||
|
|
|
@ -7,6 +7,9 @@ import java.util.regex.Pattern;
|
|||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
|
||||
|
||||
public class CryptoHelper {
|
||||
|
||||
|
@ -31,12 +34,12 @@ public class CryptoHelper {
|
|||
public boolean isEncrypted(Message message) {
|
||||
String data = null;
|
||||
try {
|
||||
Part part = message.findFirstPartByMimeType("text/plain");
|
||||
Part part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
|
||||
if (part == null) {
|
||||
part = message.findFirstPartByMimeType("text/html");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
|
||||
}
|
||||
if (part != null) {
|
||||
data = part.getText();
|
||||
data = MessageExtractor.getTextFromPart(part);
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
// guess not...
|
||||
|
@ -54,12 +57,12 @@ public class CryptoHelper {
|
|||
public boolean isSigned(Message message) {
|
||||
String data = null;
|
||||
try {
|
||||
Part part = message.findFirstPartByMimeType("text/plain");
|
||||
Part part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
|
||||
if (part == null) {
|
||||
part = message.findFirstPartByMimeType("text/html");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
|
||||
}
|
||||
if (part != null) {
|
||||
data = part.getText();
|
||||
data = MessageExtractor.getTextFromPart(part);
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
// guess not...
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
package com.fsck.k9.mail;
|
||||
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
|
||||
public abstract class BodyPart implements Part {
|
||||
private Multipart mParent;
|
||||
|
@ -16,14 +13,4 @@ public abstract class BodyPart implements Part {
|
|||
}
|
||||
|
||||
public abstract void setEncoding(String encoding) throws MessagingException;
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return MessageExtractor.getTextFromPart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Part findFirstPartByMimeType(String mimeType) throws MessagingException {
|
||||
return MimeUtility.findFirstPartByMimeType(this, mimeType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
package com.fsck.k9.mail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import android.util.Log;
|
||||
|
@ -14,8 +12,6 @@ import android.util.Log;
|
|||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.mail.filter.CountingOutputStream;
|
||||
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
|
||||
|
||||
public abstract class Message implements Part, CompositeBody {
|
||||
|
@ -270,41 +266,4 @@ public abstract class Message implements Part, CompositeBody {
|
|||
@Override
|
||||
public abstract Message clone();
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return MessageExtractor.getTextFromPart(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Part findFirstPartByMimeType(String mimeType) throws MessagingException {
|
||||
return MimeUtility.findFirstPartByMimeType(this, mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect attachment parts of a message.
|
||||
* @return A list of parts regarded as attachments.
|
||||
* @throws MessagingException In case of an error.
|
||||
*/
|
||||
public List<Part> collectAttachments() throws MessagingException {
|
||||
try {
|
||||
List<Part> attachments = new ArrayList<Part>();
|
||||
MessageExtractor.getViewables(this, attachments);
|
||||
return attachments;
|
||||
} catch (Exception e) {
|
||||
throw new MessagingException("Couldn't collect attachment parts", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the viewable textual parts of a message.
|
||||
* @return A set of viewable parts of the message.
|
||||
* @throws MessagingException In case of an error.
|
||||
*/
|
||||
public Set<Part> collectTextParts() throws MessagingException {
|
||||
try {
|
||||
return MessageExtractor.getTextParts(this);
|
||||
} catch (Exception e) {
|
||||
throw new MessagingException("Couldn't extract viewable parts", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,16 +29,6 @@ public interface Part {
|
|||
|
||||
void writeTo(OutputStream out) throws IOException, MessagingException;
|
||||
|
||||
/**
|
||||
* Reads the Part's body and returns a String based on any charset conversion that needed
|
||||
* to be done. Note, this <b>does not</b> return a text representation of HTML.
|
||||
* @return a String containing the converted text in the body, or null if there was no text
|
||||
* or an error during conversion.
|
||||
*/
|
||||
String getText();
|
||||
|
||||
Part findFirstPartByMimeType(String mimeType) throws MessagingException;
|
||||
|
||||
/**
|
||||
* Called just prior to transmission, once the type of transport is known to
|
||||
* be 7bit.
|
||||
|
|
|
@ -199,6 +199,34 @@ public class MessageExtractor {
|
|||
return getParts(getViewables(part, attachments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect attachment parts of a message.
|
||||
* @return A list of parts regarded as attachments.
|
||||
* @throws MessagingException In case of an error.
|
||||
*/
|
||||
public static List<Part> collectAttachments(Message message) throws MessagingException {
|
||||
try {
|
||||
List<Part> attachments = new ArrayList<Part>();
|
||||
getViewables(message, attachments);
|
||||
return attachments;
|
||||
} catch (Exception e) {
|
||||
throw new MessagingException("Couldn't collect attachment parts", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the viewable textual parts of a message.
|
||||
* @return A set of viewable parts of the message.
|
||||
* @throws MessagingException In case of an error.
|
||||
*/
|
||||
public static Set<Part> collectTextParts(Message message) throws MessagingException {
|
||||
try {
|
||||
return getTextParts(message);
|
||||
} catch (Exception e) {
|
||||
throw new MessagingException("Couldn't extract viewable parts", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Message getMessageFromPart(Part part) {
|
||||
while (part != null) {
|
||||
if (part instanceof Message)
|
||||
|
|
|
@ -16,7 +16,10 @@ import org.apache.james.mime4j.util.MimeUtil;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
|
@ -952,7 +955,7 @@ public class MimeUtility {
|
|||
if (part.getBody() instanceof Multipart) {
|
||||
Multipart multipart = (Multipart)part.getBody();
|
||||
for (BodyPart bodyPart : multipart.getBodyParts()) {
|
||||
Part ret = bodyPart.findFirstPartByMimeType(mimeType);
|
||||
Part ret = MimeUtility.findFirstPartByMimeType(bodyPart, mimeType);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ import com.fsck.k9.mail.Flag;
|
|||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
import com.fsck.k9.mailstore.LockableDatabase.DbCallback;
|
||||
import com.fsck.k9.mailstore.LockableDatabase.WrappedException;
|
||||
|
||||
|
@ -119,16 +121,16 @@ public class LocalMessage extends MimeMessage {
|
|||
*/
|
||||
public String getTextForDisplay() throws MessagingException {
|
||||
String text = null; // First try and fetch an HTML part.
|
||||
Part part = findFirstPartByMimeType("text/html");
|
||||
Part part = MimeUtility.findFirstPartByMimeType(this, "text/html");
|
||||
if (part == null) {
|
||||
// If that fails, try and get a text part.
|
||||
part = findFirstPartByMimeType("text/plain");
|
||||
part = MimeUtility.findFirstPartByMimeType(this, "text/plain");
|
||||
if (part != null && part.getBody() instanceof LocalTextBody) {
|
||||
text = ((LocalTextBody) part.getBody()).getBodyForDisplay();
|
||||
}
|
||||
} else {
|
||||
// We successfully found an HTML part; do the necessary character set decoding.
|
||||
text = part.getText();
|
||||
text = MessageExtractor.getTextFromPart(this);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ class LocalMessageExtractor {
|
|||
Part part = ((Textual)viewable).getPart();
|
||||
addHtmlDivider(html, part, prependDivider);
|
||||
|
||||
String t = part.getText();
|
||||
String t = MessageExtractor.getTextFromPart(part);
|
||||
if (t == null) {
|
||||
t = "";
|
||||
} else if (viewable instanceof Text) {
|
||||
|
@ -202,7 +202,7 @@ class LocalMessageExtractor {
|
|||
Part part = ((Textual)viewable).getPart();
|
||||
addTextDivider(text, part, prependDivider);
|
||||
|
||||
String t = part.getText();
|
||||
String t = MessageExtractor.getTextFromPart(part);
|
||||
if (t == null) {
|
||||
t = "";
|
||||
} else if (viewable instanceof Html) {
|
||||
|
@ -446,7 +446,7 @@ class LocalMessageExtractor {
|
|||
|
||||
Body firstBody = part.getBody();
|
||||
if (part.isMimeType("text/plain")) {
|
||||
String bodyText = part.getText();
|
||||
String bodyText = MessageExtractor.getTextFromPart(part);
|
||||
if (bodyText != null) {
|
||||
text = bodyText;
|
||||
html = HtmlConverter.textToHtml(text);
|
||||
|
@ -455,7 +455,7 @@ class LocalMessageExtractor {
|
|||
firstBody instanceof MimeMultipart) {
|
||||
MimeMultipart multipart = (MimeMultipart) firstBody;
|
||||
for (BodyPart bodyPart : multipart.getBodyParts()) {
|
||||
String bodyText = bodyPart.getText();
|
||||
String bodyText = MessageExtractor.getTextFromPart(bodyPart);
|
||||
if (bodyText != null) {
|
||||
if (text.isEmpty() && bodyPart.isMimeType("text/plain")) {
|
||||
text = bodyText;
|
||||
|
|
|
@ -36,6 +36,8 @@ import com.fsck.k9.mail.Message;
|
|||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Part;
|
||||
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.internet.MimeUtility;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
|
@ -214,7 +216,7 @@ public class MessageOpenPgpView extends LinearLayout {
|
|||
} else {
|
||||
try {
|
||||
// check for PGP/MIME encryption
|
||||
Part pgp = message.findFirstPartByMimeType("application/pgp-encrypted");
|
||||
Part pgp = MimeUtility.findFirstPartByMimeType(message, "application/pgp-encrypted");
|
||||
if (pgp != null) {
|
||||
Toast.makeText(mContext, R.string.pgp_mime_unsupported, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
|
@ -239,12 +241,12 @@ public class MessageOpenPgpView extends LinearLayout {
|
|||
public void run() {
|
||||
try {
|
||||
// get data String
|
||||
Part part = message.findFirstPartByMimeType("text/plain");
|
||||
Part part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
|
||||
if (part == null) {
|
||||
part = message.findFirstPartByMimeType("text/html");
|
||||
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
|
||||
}
|
||||
if (part != null) {
|
||||
mData = part.getText();
|
||||
mData = MessageExtractor.getTextFromPart(part);
|
||||
}
|
||||
|
||||
// wait for service to be bound
|
||||
|
|
Loading…
Reference in a new issue