From 6a04afb7586431e3d8310940ae1959cf9efda8d0 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 28 Dec 2010 09:07:59 +0000 Subject: [PATCH] extract "does it have html images" out of MessageView. really, it should end up in LocalMessage somewhere --- src/com/fsck/k9/activity/MessageView.java | 31 +++-------------------- src/com/fsck/k9/helper/Utility.java | 30 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 6441d3e58..ce9e5ebf2 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -12,10 +12,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import com.fsck.k9.mail.store.LocalStore; import org.apache.commons.io.IOUtils; import android.app.AlertDialog; import android.app.Dialog; @@ -80,12 +77,13 @@ import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.store.StorageManager; import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBodyPart; import com.fsck.k9.mail.store.LocalStore.LocalMessage; -import com.fsck.k9.mail.store.LocalStore.LocalTextBody; import com.fsck.k9.provider.AttachmentProvider; import com.fsck.k9.view.AccessibleWebView; import com.fsck.k9.view.MessageWebView; import com.fsck.k9.view.ToggleScrollView; +import static com.fsck.k9.helper.Utility.*; + public class MessageView extends K9Activity implements OnClickListener { private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference"; @@ -2040,7 +2038,7 @@ public class MessageView extends K9Activity implements OnClickListener // If the message contains external pictures and the "Show pictures" // button wasn't already pressed, see if the user's preferences has us // showing them anyway. - if (hasExternalImages(text) && !mShowPictures) + if (Utility.hasExternalImages(text) && !mShowPictures) { if ((account.getShowPictures() == Account.ShowPictures.ALWAYS) || ((account.getShowPictures() == Account.ShowPictures.ONLY_FROM_CONTACTS) && @@ -2076,28 +2074,7 @@ public class MessageView extends K9Activity implements OnClickListener } }//loadMessageForViewBodyAvailable - private static final String IMG_SRC_REGEX = "(?is:]+src\\s*=\\s*['\"]?([a-z]+)\\:)"; - private final Pattern mImgPattern = Pattern.compile(IMG_SRC_REGEX); - private boolean hasExternalImages(final String message) - { - Matcher imgMatches = mImgPattern.matcher(message); - while (imgMatches.find()) - { - if (!imgMatches.group(1).equals("content")) - { - if (K9.DEBUG) - { - Log.d(K9.LOG_TAG, "External images found"); - } - return true; - } - } - if (K9.DEBUG) - { - Log.d(K9.LOG_TAG, "No external images."); - } - return false; - } + @Override public void loadMessageForViewFailed(Account account, String folder, String uid, diff --git a/src/com/fsck/k9/helper/Utility.java b/src/com/fsck/k9/helper/Utility.java index 02d6caaf6..c3fc00dc5 100644 --- a/src/com/fsck/k9/helper/Utility.java +++ b/src/com/fsck/k9/helper/Utility.java @@ -664,5 +664,35 @@ public class Utility Log.w(K9.LOG_TAG, "cannot delete " + fromDir.getAbsolutePath()); } } + /** + * Figure out if this part hsa images. + * TODO: should only return true if we're an html part + */ + + + private static final String IMG_SRC_REGEX = "(?is:]+src\\s*=\\s*['\"]?([a-z]+)\\:)"; + private static final Pattern mImgPattern = Pattern.compile(IMG_SRC_REGEX); + public static boolean hasExternalImages(final String message) + { + Matcher imgMatches = mImgPattern.matcher(message); + while (imgMatches.find()) + { + if (!imgMatches.group(1).equals("content")) + { + if (K9.DEBUG) + { + Log.d(K9.LOG_TAG, "External images found"); + } + return true; + } + } + if (K9.DEBUG) + { + Log.d(K9.LOG_TAG, "No external images."); + } + return false; + } + + }