(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state)
| 1175 | } |
| 1176 | |
| 1177 | private static void onAdd(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException { |
| 1178 | // Add message |
| 1179 | DB db = DB.getInstance(context); |
| 1180 | |
| 1181 | if (folder.local) { |
| 1182 | Log.i(folder.name + " local add"); |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | // Drafts can change accounts |
| 1187 | if (jargs.length() == 0 && !folder.id.equals(message.folder)) |
| 1188 | throw new IllegalArgumentException("Message folder changed"); |
| 1189 | |
| 1190 | // Get arguments |
| 1191 | long target = jargs.optLong(0, folder.id); |
| 1192 | boolean autoread = jargs.optBoolean(1, false); |
| 1193 | boolean copy = jargs.optBoolean(2, false); // Cross account |
| 1194 | |
| 1195 | if (target != folder.id) |
| 1196 | throw new IllegalArgumentException("Invalid folder"); |
| 1197 | |
| 1198 | // External draft might have a uid only |
| 1199 | if (TextUtils.isEmpty(message.msgid)) { |
| 1200 | message.msgid = EntityMessage.generateMessageId(); |
| 1201 | db.message().setMessageMsgId(message.id, message.msgid); |
| 1202 | } |
| 1203 | |
| 1204 | Properties props = MessageHelper.getSessionProperties(account.unicode); |
| 1205 | Session isession = Session.getInstance(props, null); |
| 1206 | Flags flags = ifolder.getPermanentFlags(); |
| 1207 | |
| 1208 | // Get raw message |
| 1209 | MimeMessage imessage; |
| 1210 | File file = message.getRawFile(context); |
| 1211 | if (folder.id.equals(message.folder)) { |
| 1212 | // Pre flight check |
| 1213 | if (!message.content) |
| 1214 | throw new IllegalArgumentException("Message body missing"); |
| 1215 | |
| 1216 | if (!BuildConfig.DEBUG) { |
| 1217 | List<EntityAttachment> attachments = db.attachment().getAttachments(message.id); |
| 1218 | for (EntityAttachment attachment : attachments) |
| 1219 | if (EntityAttachment.SMIME_SIGNATURE.equals(attachment.encryption)) |
| 1220 | for (EntityAttachment content : attachments) |
| 1221 | if (EntityAttachment.SMIME_CONTENT.equals(content.encryption)) { |
| 1222 | boolean afile = attachment.getFile(context).exists(); |
| 1223 | boolean cfile = content.getFile(context).exists(); |
| 1224 | if (!attachment.available || !afile || !content.available || !cfile) { |
| 1225 | Log.e("S/MIME vanished" + |
| 1226 | " available=" + attachment.available + "/" + content.available + |
| 1227 | " file=" + afile + "/" + cfile + |
| 1228 | " error=" + attachment.error + "/" + content.error); |
| 1229 | db.attachment().setAvailable(attachment.id, false); |
| 1230 | db.attachment().setAvailable(content.id, false); |
| 1231 | db.attachment().setEncryption(attachment.id, null); |
| 1232 | db.attachment().setEncryption(content.id, null); |
| 1233 | } |
| 1234 | } |
no test coverage detected