1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

extract "does it have html images" out of MessageView. really, it should

end up in LocalMessage somewhere
This commit is contained in:
Jesse Vincent 2010-12-28 09:07:59 +00:00
parent 7623a02852
commit 6a04afb758
2 changed files with 34 additions and 27 deletions

View File

@ -12,10 +12,7 @@ import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; 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 org.apache.commons.io.IOUtils;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; 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.StorageManager;
import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBodyPart; import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBodyPart;
import com.fsck.k9.mail.store.LocalStore.LocalMessage; 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.provider.AttachmentProvider;
import com.fsck.k9.view.AccessibleWebView; import com.fsck.k9.view.AccessibleWebView;
import com.fsck.k9.view.MessageWebView; import com.fsck.k9.view.MessageWebView;
import com.fsck.k9.view.ToggleScrollView; import com.fsck.k9.view.ToggleScrollView;
import static com.fsck.k9.helper.Utility.*;
public class MessageView extends K9Activity implements OnClickListener public class MessageView extends K9Activity implements OnClickListener
{ {
private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference"; 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" // If the message contains external pictures and the "Show pictures"
// button wasn't already pressed, see if the user's preferences has us // button wasn't already pressed, see if the user's preferences has us
// showing them anyway. // showing them anyway.
if (hasExternalImages(text) && !mShowPictures) if (Utility.hasExternalImages(text) && !mShowPictures)
{ {
if ((account.getShowPictures() == Account.ShowPictures.ALWAYS) || if ((account.getShowPictures() == Account.ShowPictures.ALWAYS) ||
((account.getShowPictures() == Account.ShowPictures.ONLY_FROM_CONTACTS) && ((account.getShowPictures() == Account.ShowPictures.ONLY_FROM_CONTACTS) &&
@ -2076,28 +2074,7 @@ public class MessageView extends K9Activity implements OnClickListener
} }
}//loadMessageForViewBodyAvailable }//loadMessageForViewBodyAvailable
private static final String IMG_SRC_REGEX = "(?is:<img[^>]+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 @Override
public void loadMessageForViewFailed(Account account, String folder, String uid, public void loadMessageForViewFailed(Account account, String folder, String uid,

View File

@ -664,5 +664,35 @@ public class Utility
Log.w(K9.LOG_TAG, "cannot delete " + fromDir.getAbsolutePath()); 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:<img[^>]+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;
}
} }