(Part part, Part attachment)
| 2318 | } |
| 2319 | |
| 2320 | static boolean deletePart(Part part, Part attachment) throws MessagingException, IOException { |
| 2321 | boolean deleted = false; |
| 2322 | if (part.isMimeType("multipart/*")) { |
| 2323 | Multipart multipart = (Multipart) part.getContent(); |
| 2324 | for (int i = 0; i < multipart.getCount(); i++) { |
| 2325 | Part child = multipart.getBodyPart(i); |
| 2326 | if (child == attachment) { |
| 2327 | String fileName = child.getFileName(); |
| 2328 | String contentType = child.getContentType(); |
| 2329 | String disposition = child.getDisposition(); |
| 2330 | |
| 2331 | if (fileName != null && !fileName.startsWith("deleted")) |
| 2332 | fileName = "deleted" + (TextUtils.isEmpty(fileName) ? "" : "_" + fileName); |
| 2333 | if (TextUtils.isEmpty(contentType)) |
| 2334 | contentType = "application/octet-stream"; |
| 2335 | if (TextUtils.isEmpty(disposition)) |
| 2336 | disposition = Part.ATTACHMENT; |
| 2337 | |
| 2338 | multipart.removeBodyPart(i); |
| 2339 | |
| 2340 | try { |
| 2341 | // Can't upload empty message/rfc822 |
| 2342 | ContentType ct = new ContentType(contentType); |
| 2343 | if ("message/rfc822".equalsIgnoreCase(ct.getBaseType())) |
| 2344 | contentType = "application/octet-stream"; |
| 2345 | } catch (Throwable ex) { |
| 2346 | Log.w(ex); |
| 2347 | } |
| 2348 | |
| 2349 | BodyPart placeholderPart = new MimeBodyPart(); |
| 2350 | placeholderPart.setContent("", contentType); |
| 2351 | placeholderPart.setFileName(fileName); |
| 2352 | placeholderPart.setDisposition(disposition); |
| 2353 | multipart.addBodyPart(placeholderPart); |
| 2354 | |
| 2355 | deleted = true; |
| 2356 | } else { |
| 2357 | if (deletePart(child, attachment)) |
| 2358 | deleted = true; |
| 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | if (part instanceof MimeMessage) |
| 2364 | ((MimeMessage) part).saveChanges(); |
| 2365 | else if (part instanceof Multipart) |
| 2366 | part.setDataHandler(part.getDataHandler()); |
| 2367 | |
| 2368 | return deleted; |
| 2369 | } |
| 2370 | |
| 2371 | private static void onBody(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder, POP3Store istore) throws MessagingException, IOException { |
| 2372 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
no test coverage detected