POP3: load alt / charset

pull/215/head
M66B 6 months ago
parent 5cbfebeabc
commit d71fd3d2ec

@ -6416,14 +6416,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
.setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP || .setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP ||
EntityFolder.INBOX.equals(message.folderType)); EntityFolder.INBOX.equals(message.folderType));
popupMenu.getMenu().findItem(R.id.menu_charset) popupMenu.getMenu().findItem(R.id.menu_charset)
.setEnabled(message.uid != null) .setEnabled(message.uid != null ||
.setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP); message.accountProtocol == EntityAccount.TYPE_POP)
.setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP ||
EntityFolder.INBOX.equals(message.folderType));
popupMenu.getMenu().findItem(R.id.menu_alternative) popupMenu.getMenu().findItem(R.id.menu_alternative)
.setTitle(message.isPlainOnly() .setTitle(message.isPlainOnly()
? R.string.title_alternative_html : R.string.title_alternative_text) ? R.string.title_alternative_html : R.string.title_alternative_text)
.setEnabled(message.uid != null && message.hasAlt() && !message.isEncrypted()) .setEnabled(message.hasAlt() && !message.isEncrypted() &&
.setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP); (message.uid != null || message.accountProtocol == EntityAccount.TYPE_POP))
.setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP ||
EntityFolder.INBOX.equals(message.folderType));
popupMenu.insertIcons(context); popupMenu.insertIcons(context);

@ -2234,31 +2234,40 @@ class Core {
} }
private static void onBody(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder, POP3Store istore) throws MessagingException, IOException { private static void onBody(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder, POP3Store istore) throws MessagingException, IOException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean download_plain = prefs.getBoolean("download_plain", false);
boolean plain_text = jargs.optBoolean(0, download_plain);
String charset = (jargs.isNull(1) ? null : jargs.optString(1, null));
if (!EntityFolder.INBOX.equals(folder.type)) if (!EntityFolder.INBOX.equals(folder.type))
throw new IllegalArgumentException("Not INBOX"); throw new IllegalArgumentException("Not INBOX");
if (message.content && message.isPlainOnly() == plain_text && charset == null)
return;
Map<EntityMessage, Message> map = findMessages(context, folder, Arrays.asList(message), istore, ifolder); Map<EntityMessage, Message> map = findMessages(context, folder, Arrays.asList(message), istore, ifolder);
if (map.get(message) == null) if (map.get(message) == null)
throw new IllegalArgumentException("Message not found msgid=" + message.msgid); throw new IllegalArgumentException("Message not found msgid=" + message.msgid);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean download_plain = prefs.getBoolean("download_plain", false);
MessageHelper helper = new MessageHelper((MimeMessage) map.entrySet().iterator().next().getValue(), context); MessageHelper helper = new MessageHelper((MimeMessage) map.entrySet().iterator().next().getValue(), context);
MessageHelper.MessageParts parts = helper.getMessageParts(); MessageHelper.MessageParts parts = helper.getMessageParts();
String body = parts.getHtml(context, download_plain); String body = parts.getHtml(context, plain_text, charset);
File file = message.getFile(context); File file = message.getFile(context);
Helper.writeText(file, body); Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body, true); String text = HtmlHelper.getFullText(body, true);
message.preview = HtmlHelper.getPreview(text); message.preview = HtmlHelper.getPreview(text);
message.language = HtmlHelper.getLanguage(context, message.subject, text); message.language = HtmlHelper.getLanguage(context, message.subject, text);
Integer plain_only = parts.isPlainOnly();
if (plain_text)
plain_only = 1 | (plain_only == null ? 0 : plain_only & 0x80);
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.message().setMessageContent(message.id, db.message().setMessageContent(message.id,
true, true,
message.language, message.language,
parts.isPlainOnly(download_plain), plain_only,
message.preview, message.preview,
parts.getWarnings(message.warning)); parts.getWarnings(message.warning));
} }

Loading…
Cancel
Save