(Context context, JSONArray jargs, EntityFolder folder, IMAPStore istore, IMAPFolder ifolder, State state)
| 1736 | } |
| 1737 | |
| 1738 | private static void onFetch(Context context, JSONArray jargs, EntityFolder folder, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException { |
| 1739 | long uid = jargs.getLong(0); |
| 1740 | boolean invalidate = jargs.optBoolean(1); |
| 1741 | boolean removed = jargs.optBoolean(2); |
| 1742 | |
| 1743 | DB db = DB.getInstance(context); |
| 1744 | EntityAccount account = db.account().getAccount(folder.account); |
| 1745 | if (account == null) |
| 1746 | throw new IllegalArgumentException("account missing"); |
| 1747 | |
| 1748 | try { |
| 1749 | if (uid < 0) |
| 1750 | throw new MessageRemovedException(folder.name + " fetch uid=" + uid); |
| 1751 | if (removed) |
| 1752 | throw new MessageRemovedException("removed uid=" + uid); |
| 1753 | |
| 1754 | MimeMessage imessage = (MimeMessage) ifolder.getMessageByUID(uid); |
| 1755 | if (imessage == null) |
| 1756 | throw new MessageRemovedException(folder.name + " fetch not found uid=" + uid); |
| 1757 | // synchronizeMessage will check expunged/deleted |
| 1758 | |
| 1759 | if (invalidate && imessage instanceof IMAPMessage) |
| 1760 | ((IMAPMessage) imessage).invalidateHeaders(); |
| 1761 | |
| 1762 | SyncStats stats = new SyncStats(); |
| 1763 | boolean download = db.folder().getFolderDownload(folder.id); |
| 1764 | List<EntityRule> rules = db.rule().getEnabledRules(folder.id, false); |
| 1765 | |
| 1766 | FetchProfile fp = new FetchProfile(); |
| 1767 | fp.add(UIDFolder.FetchProfileItem.UID); // To check if message exists |
| 1768 | fp.add(FetchProfile.Item.FLAGS); // To update existing messages |
| 1769 | if (account.isGmail()) |
| 1770 | fp.add(GmailFolder.FetchProfileItem.LABELS); |
| 1771 | ifolder.fetch(new Message[]{imessage}, fp); |
| 1772 | |
| 1773 | EntityMessage message = synchronizeMessage(context, account, folder, istore, ifolder, imessage, false, download, rules, state, stats); |
| 1774 | if (message != null) { |
| 1775 | if (account.isGmail() && EntityFolder.USER.equals(folder.type)) |
| 1776 | try { |
| 1777 | JSONArray jlabel = new JSONArray(); |
| 1778 | jlabel.put(0, folder.name); |
| 1779 | jlabel.put(1, true); |
| 1780 | onLabel(context, jlabel, folder, message, istore, ifolder, state); |
| 1781 | } catch (Throwable ex1) { |
| 1782 | Log.e(ex1); |
| 1783 | } |
| 1784 | |
| 1785 | if (download) { |
| 1786 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 1787 | boolean fast_fetch = prefs.getBoolean("fast_fetch", false); |
| 1788 | |
| 1789 | boolean async = false; |
| 1790 | if (fast_fetch) { |
| 1791 | long maxSize = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE); |
| 1792 | if (maxSize == 0) |
| 1793 | maxSize = Long.MAX_VALUE; |
| 1794 | boolean download_limited = prefs.getBoolean("download_limited", false); |
| 1795 | boolean download_eml = prefs.getBoolean("download_eml", false); |
no test coverage detected