MCPcopy Create free account
hub / github.com/M66B/FairEmail / deletePart

Method deletePart

app/src/main/java/eu/faircode/email/Core.java:2320–2369  ·  view source on GitHub ↗
(Part part, Part attachment)

Source from the content-addressed store, hash-verified

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);

Callers 1

onDetachMethod · 0.95

Calls 15

getCountMethod · 0.95
getBodyPartMethod · 0.95
getFileNameMethod · 0.95
getContentTypeMethod · 0.95
getDispositionMethod · 0.95
removeBodyPartMethod · 0.95
getBaseTypeMethod · 0.95
wMethod · 0.95
setContentMethod · 0.95
setFileNameMethod · 0.95
setDispositionMethod · 0.95
addBodyPartMethod · 0.95

Tested by

no test coverage detected