Source:
<code>protected void getAttachmentParts(Part part, String defaultFilename, MimetypeRegistry mimeService, ExecutionContext context) throws MessagingException, IOException { String filename = getFilename(part, defaultFilename); List<Blob> blobs = (List<Blob>) context.get(ATTACHMENTS_KEY); Map<String, String> contentKeys = (Map<String, String>) context.get(CONTENT_KEY); if (part.isMimeType("multipart/alternative")) { bodyContent += getText(part, defaultFilename, mimeService, context); } else { if (!part.isMimeType("multipart/*")) { String disp = part.getDisposition(); if (disp == null && part.getContentType().toLowerCase().startsWith("text/")) { bodyContent += decodeMailBody(part); } else { Blob blob; try (InputStream in = part.getInputStream()) { blob = Blobs.createBlob(in); } String mime = DEFAULT_BINARY_MIMETYPE; try { if (mimeService != null) { ContentType contentType = new ContentType(part.getContentType()); mime = mimeService.getMimetypeFromFilenameAndBlobWithDefault(filename, blob, contentType.getBaseType()); } } catch (MessagingException | MimetypeDetectionException e) { log.error(e); } blob.setMimeType(mime); blob.setFilename(filename); if (part instanceof MimePart) { String contentId = ((MimePart) part).getContentID(); if (contentId != null) { <START> contentKeys.put(contentId.replaceAll("<", "").replaceAll(">", ""), filename); <END> } } blobs.add(blob); } } if (part.isMimeType("multipart/*")) { Multipart mp = (Multipart) part.getContent(); int count = mp.getCount(); for (int i = 0; i < count; i++) { getAttachmentParts(mp.getBodyPart(i), defaultFilename, mimeService, context); } } else if (part.isMimeType(MESSAGE_RFC822_MIMETYPE)) { getAttachmentParts((Part) part.getContent(), defaultFilename, mimeService, context); } } }</code><technical_language>replaceAll is for regexps. replace</technical_language>

Target:
protected void getAttachmentParts(Part part, String defaultFilename, MimetypeRegistry mimeService, ExecutionContext context) throws MessagingException, IOException { String filename = getFilename(part, defaultFilename); List<Blob> blobs = (List<Blob>) context.get(ATTACHMENTS_KEY); Map<String, String> contentKeys = (Map<String, String>) context.get(CONTENT_KEY); if (part.isMimeType("multipart/alternative")) { bodyContent += getText(part, defaultFilename, mimeService, context); } else { if (!part.isMimeType("multipart/*")) { String disp = part.getDisposition(); if (disp == null && part.getContentType().toLowerCase().startsWith("text/")) { bodyContent += decodeMailBody(part); } else { Blob blob; try (InputStream in = part.getInputStream()) { blob = Blobs.createBlob(in); } String mime = DEFAULT_BINARY_MIMETYPE; try { if (mimeService != null) { ContentType contentType = new ContentType(part.getContentType()); mime = mimeService.getMimetypeFromFilenameAndBlobWithDefault(filename, blob, contentType.getBaseType()); } } catch (MessagingException | MimetypeDetectionException e) { log.error(e); } blob.setMimeType(mime); blob.setFilename(filename); if (part instanceof MimePart) { String contentId = ((MimePart) part).getContentID(); if (contentId != null) { contentKeys.put(filename, contentId.replace("<", "").replace(">", "")); } } blobs.add(blob); } } if (part.isMimeType("multipart/*")) { Multipart mp = (Multipart) part.getContent(); int count = mp.getCount(); for (int i = 0; i < count; i++) { getAttachmentParts(mp.getBodyPart(i), defaultFilename, mimeService, context); } } else if (part.isMimeType(MESSAGE_RFC822_MIMETYPE)) { getAttachmentParts((Part) part.getContent(), defaultFilename, mimeService, context); } } }