(Context context, EntityAccount account, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder)
| 819 | } |
| 820 | |
| 821 | private static void ensureUid(Context context, EntityAccount account, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws MessagingException, IOException { |
| 822 | if (folder.local) |
| 823 | return; |
| 824 | if (message == null || message.uid != null) |
| 825 | return; |
| 826 | |
| 827 | if (EntityOperation.ADD.equals(op.name)) |
| 828 | return; |
| 829 | if (EntityOperation.FETCH.equals(op.name)) |
| 830 | return; |
| 831 | if (EntityOperation.EXISTS.equals(op.name)) |
| 832 | return; |
| 833 | if (EntityOperation.DELETE.equals(op.name) && !TextUtils.isEmpty(message.msgid)) |
| 834 | return; |
| 835 | |
| 836 | Log.i(folder.name + " ensure uid op=" + op.name + " msgid=" + message.msgid); |
| 837 | |
| 838 | if (TextUtils.isEmpty(message.msgid)) |
| 839 | throw new IllegalArgumentException("Message without msgid for " + op.name); |
| 840 | |
| 841 | DB db = DB.getInstance(context); |
| 842 | |
| 843 | Long uid = findUid(context, account, ifolder, message.msgid, null); |
| 844 | if (uid == null) { |
| 845 | if (EntityOperation.MOVE.equals(op.name) && |
| 846 | EntityFolder.DRAFTS.equals(folder.type)) |
| 847 | try { |
| 848 | long fid = new JSONArray(op.args).optLong(0, -1L); |
| 849 | EntityFolder target = db.folder().getFolder(fid); |
| 850 | if (target != null && EntityFolder.TRASH.equals(target.type)) { |
| 851 | Log.w(folder.name + " deleting id=" + message.id); |
| 852 | db.message().deleteMessage(message.id); |
| 853 | } |
| 854 | } catch (JSONException ex) { |
| 855 | Log.e(ex); |
| 856 | } |
| 857 | |
| 858 | throw new IllegalArgumentException("Message not found for " + op.name + " folder=" + folder.name); |
| 859 | } |
| 860 | |
| 861 | db.message().setMessageUid(message.id, message.uid); |
| 862 | message.uid = uid; |
| 863 | } |
| 864 | |
| 865 | private static Long findUid(Context context, EntityAccount account, IMAPFolder ifolder, String msgid, Long from) throws MessagingException, IOException { |
| 866 | String name = ifolder.getFullName(); |
no test coverage detected