Cleanup
This commit is contained in:
parent
2a2e18e8b6
commit
b443af43ae
4 changed files with 39 additions and 32 deletions
|
@ -22,6 +22,9 @@ import java.util.regex.Pattern;
|
|||
import static com.fsck.k9.mail.internet.CharsetSupport.fixupCharset;
|
||||
import static com.fsck.k9.mail.internet.MimeUtility.getHeaderParameter;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Alternative;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Html;
|
||||
import static com.fsck.k9.mail.internet.Viewable.MessageHeader;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Text;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Textual;
|
||||
|
||||
public class MessageExtractor {
|
||||
|
@ -167,7 +170,7 @@ public class MessageExtractor {
|
|||
Message message = (Message) body;
|
||||
|
||||
// We add the Message object so we can extract the filename later.
|
||||
viewables.add(new Viewable.MessageHeader(part, message));
|
||||
viewables.add(new MessageHeader(part, message));
|
||||
|
||||
// Recurse to grab all viewable parts and attachments from that message.
|
||||
viewables.addAll(getViewables(message, attachments));
|
||||
|
@ -177,10 +180,10 @@ public class MessageExtractor {
|
|||
*/
|
||||
String mimeType = part.getMimeType();
|
||||
if (mimeType.equalsIgnoreCase("text/plain")) {
|
||||
Viewable.Text text = new Viewable.Text(part);
|
||||
Text text = new Text(part);
|
||||
viewables.add(text);
|
||||
} else {
|
||||
Viewable.Html html = new Viewable.Html(part);
|
||||
Html html = new Html(part);
|
||||
viewables.add(html);
|
||||
}
|
||||
} else {
|
||||
|
@ -220,7 +223,7 @@ public class MessageExtractor {
|
|||
* @param directChild If {@code true}, this method will return after the first {@code text/plain} was
|
||||
* found.
|
||||
*
|
||||
* @return A list of {@link Viewable.Text} viewables.
|
||||
* @return A list of {@link Text} viewables.
|
||||
*
|
||||
* @throws MessagingException
|
||||
* In case of an error.
|
||||
|
@ -254,7 +257,7 @@ public class MessageExtractor {
|
|||
}
|
||||
}
|
||||
} else if (isPartTextualBody(part) && part.getMimeType().equalsIgnoreCase("text/plain")) {
|
||||
Viewable.Text text = new Viewable.Text(part);
|
||||
Text text = new Text(part);
|
||||
viewables.add(text);
|
||||
if (directChild) {
|
||||
break;
|
||||
|
@ -274,7 +277,7 @@ public class MessageExtractor {
|
|||
* @param directChild If {@code true}, this method will add all {@code text/html} parts except the first
|
||||
* found to 'attachments'.
|
||||
*
|
||||
* @return A list of {@link Viewable.Text} viewables.
|
||||
* @return A list of {@link Text} viewables.
|
||||
*
|
||||
* @throws MessagingException In case of an error.
|
||||
*/
|
||||
|
@ -314,7 +317,7 @@ public class MessageExtractor {
|
|||
}
|
||||
} else if (!(directChild && partFound) && isPartTextualBody(part) &&
|
||||
part.getMimeType().equalsIgnoreCase("text/html")) {
|
||||
Viewable.Html html = new Viewable.Html(part);
|
||||
Html html = new Html(part);
|
||||
viewables.add(html);
|
||||
partFound = true;
|
||||
} else if (!knownTextParts.contains(part)) {
|
||||
|
@ -359,8 +362,8 @@ public class MessageExtractor {
|
|||
*
|
||||
* @return The set of viewable {@code Part}s.
|
||||
*
|
||||
* @see MimeUtility#findHtmlPart(Multipart, Set, List, boolean)
|
||||
* @see MimeUtility#findAttachments(Multipart, Set, List)
|
||||
* @see MessageExtractor#findHtmlPart(Multipart, Set, List, boolean)
|
||||
* @see MessageExtractor#findAttachments(Multipart, Set, List)
|
||||
*/
|
||||
private static Set<Part> getParts(List<Viewable> viewables) {
|
||||
Set<Part> parts = new HashSet<Part>();
|
||||
|
|
|
@ -991,7 +991,7 @@ public class MimeUtility {
|
|||
*/
|
||||
if (contentTransferEncoding != null) {
|
||||
contentTransferEncoding =
|
||||
MimeUtility.getHeaderParameter(contentTransferEncoding, null);
|
||||
getHeaderParameter(contentTransferEncoding, null);
|
||||
if (MimeUtil.ENC_QUOTED_PRINTABLE.equalsIgnoreCase(contentTransferEncoding)) {
|
||||
in = new QuotedPrintableInputStream(in);
|
||||
} else if (MimeUtil.ENC_BASE64.equalsIgnoreCase(contentTransferEncoding)) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Empty marker class interface the class hierarchy used by
|
||||
* {@link com.fsck.k9.mailstore.LocalMessageExtractor#extractTextAndAttachments(android.content.Context, com.fsck.k9.mail.Message)}.
|
||||
* {@link MessageExtractor#getViewables(com.fsck.k9.mail.Part, java.util.List)}
|
||||
*
|
||||
* @see Viewable.Text
|
||||
* @see Viewable.Html
|
||||
|
@ -20,7 +20,7 @@ public interface Viewable {
|
|||
*
|
||||
* @see com.fsck.k9.mail.internet.MessageExtractor#isPartTextualBody(com.fsck.k9.mail.Part)
|
||||
*/
|
||||
static abstract class Textual implements Viewable {
|
||||
abstract class Textual implements Viewable {
|
||||
private Part mPart;
|
||||
|
||||
public Textual(Part part) {
|
||||
|
@ -35,7 +35,7 @@ public interface Viewable {
|
|||
/**
|
||||
* Class representing a {@code text/plain} part of a message.
|
||||
*/
|
||||
static class Text extends Textual {
|
||||
class Text extends Textual {
|
||||
public Text(Part part) {
|
||||
super(part);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public interface Viewable {
|
|||
/**
|
||||
* Class representing a {@code text/html} part of a message.
|
||||
*/
|
||||
static class Html extends Textual {
|
||||
class Html extends Textual {
|
||||
public Html(Part part) {
|
||||
super(part);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public interface Viewable {
|
|||
* inline.
|
||||
* </p>
|
||||
*/
|
||||
static class MessageHeader implements Viewable {
|
||||
class MessageHeader implements Viewable {
|
||||
private Part mContainerPart;
|
||||
private Message mMessage;
|
||||
|
||||
|
@ -84,7 +84,7 @@ public interface Viewable {
|
|||
* class.
|
||||
* </p>
|
||||
*/
|
||||
static class Alternative implements Viewable {
|
||||
class Alternative implements Viewable {
|
||||
private List<Viewable> mText;
|
||||
private List<Viewable> mHtml;
|
||||
|
||||
|
@ -101,5 +101,4 @@ public interface Viewable {
|
|||
return mHtml;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import static com.fsck.k9.mail.internet.MimeUtility.getHeaderParameter;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Alternative;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Html;
|
||||
import static com.fsck.k9.mail.internet.Viewable.MessageHeader;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Text;
|
||||
import static com.fsck.k9.mail.internet.Viewable.Textual;
|
||||
|
||||
class LocalMessageExtractor {
|
||||
private static final String TEXT_DIVIDER =
|
||||
|
@ -58,14 +63,14 @@ class LocalMessageExtractor {
|
|||
StringBuilder html = new StringBuilder();
|
||||
|
||||
for (Viewable viewable : viewables) {
|
||||
if (viewable instanceof Viewable.Textual) {
|
||||
if (viewable instanceof Textual) {
|
||||
// This is either a text/plain or text/html part. Fill the variables 'text' and
|
||||
// 'html', converting between plain text and HTML as necessary.
|
||||
text.append(buildText(viewable, !hideDivider));
|
||||
html.append(buildHtml(viewable, !hideDivider));
|
||||
hideDivider = false;
|
||||
} else if (viewable instanceof Viewable.MessageHeader) {
|
||||
Viewable.MessageHeader header = (Viewable.MessageHeader) viewable;
|
||||
} else if (viewable instanceof MessageHeader) {
|
||||
MessageHeader header = (MessageHeader) viewable;
|
||||
Part containerPart = header.getContainerPart();
|
||||
Message innerMessage = header.getMessage();
|
||||
|
||||
|
@ -76,9 +81,9 @@ class LocalMessageExtractor {
|
|||
addMessageHeaderHtml(context, html, innerMessage);
|
||||
|
||||
hideDivider = true;
|
||||
} else if (viewable instanceof Viewable.Alternative) {
|
||||
} else if (viewable instanceof Alternative) {
|
||||
// Handle multipart/alternative contents
|
||||
Viewable.Alternative alternative = (Viewable.Alternative) viewable;
|
||||
Alternative alternative = (Alternative) viewable;
|
||||
|
||||
/*
|
||||
* We made sure at least one of text/plain or text/html is present when
|
||||
|
@ -161,21 +166,21 @@ class LocalMessageExtractor {
|
|||
private static StringBuilder buildHtml(Viewable viewable, boolean prependDivider)
|
||||
{
|
||||
StringBuilder html = new StringBuilder();
|
||||
if (viewable instanceof Viewable.Textual) {
|
||||
Part part = ((Viewable.Textual)viewable).getPart();
|
||||
if (viewable instanceof Textual) {
|
||||
Part part = ((Textual)viewable).getPart();
|
||||
addHtmlDivider(html, part, prependDivider);
|
||||
|
||||
String t = part.getText();
|
||||
if (t == null) {
|
||||
t = "";
|
||||
} else if (viewable instanceof Viewable.Text) {
|
||||
} else if (viewable instanceof Text) {
|
||||
t = HtmlConverter.textToHtml(t);
|
||||
}
|
||||
html.append(t);
|
||||
} else if (viewable instanceof Viewable.Alternative) {
|
||||
} else if (viewable instanceof Alternative) {
|
||||
// That's odd - an Alternative as child of an Alternative; go ahead and try to use the
|
||||
// text/html child; fall-back to the text/plain part.
|
||||
Viewable.Alternative alternative = (Viewable.Alternative) viewable;
|
||||
Alternative alternative = (Alternative) viewable;
|
||||
|
||||
List<Viewable> htmlAlternative = alternative.getHtml().isEmpty() ?
|
||||
alternative.getText() : alternative.getHtml();
|
||||
|
@ -193,21 +198,21 @@ class LocalMessageExtractor {
|
|||
private static StringBuilder buildText(Viewable viewable, boolean prependDivider)
|
||||
{
|
||||
StringBuilder text = new StringBuilder();
|
||||
if (viewable instanceof Viewable.Textual) {
|
||||
Part part = ((Viewable.Textual)viewable).getPart();
|
||||
if (viewable instanceof Textual) {
|
||||
Part part = ((Textual)viewable).getPart();
|
||||
addTextDivider(text, part, prependDivider);
|
||||
|
||||
String t = part.getText();
|
||||
if (t == null) {
|
||||
t = "";
|
||||
} else if (viewable instanceof Viewable.Html) {
|
||||
} else if (viewable instanceof Html) {
|
||||
t = HtmlConverter.htmlToText(t);
|
||||
}
|
||||
text.append(t);
|
||||
} else if (viewable instanceof Viewable.Alternative) {
|
||||
} else if (viewable instanceof Alternative) {
|
||||
// That's odd - an Alternative as child of an Alternative; go ahead and try to use the
|
||||
// text/plain child; fall-back to the text/html part.
|
||||
Viewable.Alternative alternative = (Viewable.Alternative) viewable;
|
||||
Alternative alternative = (Alternative) viewable;
|
||||
|
||||
List<Viewable> textAlternative = alternative.getText().isEmpty() ?
|
||||
alternative.getHtml() : alternative.getText();
|
||||
|
|
Loading…
Reference in a new issue