(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder)
| 2230 | } |
| 2231 | |
| 2232 | private static void onAttachment(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws JSONException, MessagingException, IOException { |
| 2233 | // Download attachment |
| 2234 | DB db = DB.getInstance(context); |
| 2235 | |
| 2236 | long id = jargs.getLong(0); |
| 2237 | |
| 2238 | // Get attachment |
| 2239 | EntityAttachment attachment = db.attachment().getAttachment(id); |
| 2240 | if (attachment == null) |
| 2241 | attachment = db.attachment().getAttachment(message.id, (int) id); // legacy |
| 2242 | if (attachment == null) |
| 2243 | throw new IllegalArgumentException("Local attachment not found"); |
| 2244 | if (attachment.subsequence != null) |
| 2245 | throw new IllegalArgumentException("Download of sub attachment"); |
| 2246 | if (attachment.available) |
| 2247 | return; |
| 2248 | if (message.uid == null) |
| 2249 | throw new IllegalArgumentException("Attachment/message uid missing"); |
| 2250 | |
| 2251 | // Get message |
| 2252 | Message imessage = ifolder.getMessageByUID(message.uid); |
| 2253 | if (imessage == null) |
| 2254 | throw new MessageRemovedException(); |
| 2255 | |
| 2256 | // Get message parts |
| 2257 | MessageHelper helper = new MessageHelper((MimeMessage) imessage, context); |
| 2258 | MessageHelper.MessageParts parts = helper.getMessageParts(); |
| 2259 | |
| 2260 | // Download attachment |
| 2261 | parts.downloadAttachment(context, attachment, folder); |
| 2262 | |
| 2263 | if (attachment.size != null) |
| 2264 | EntityLog.log(context, "Operation attachment size=" + attachment.size); |
| 2265 | } |
| 2266 | |
| 2267 | private static void onDetach(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException { |
| 2268 | DB db = DB.getInstance(context); |
no test coverage detected