bbottema/simple-java-mail

ConcurrentModificationException when importing from MimeMessage

nedashley opened this issue · 3 comments

Hi,

I am experiencing a ConcurrentModificationException when converting from MimeMessage. I have narrowed the cause down to the moveInvalidEmbeddedResourcesToAttachments method in MimeMessageParser.

Here is a fix which I am currently testing:

private static void moveInvalidEmbeddedResourcesToAttachments(ParsedMimeMessageComponents parsedComponents) {
    final String htmlContent = parsedComponents.htmlContent.toString();
    for(Iterator<Map.Entry<String, DataSource>> it = parsedComponents.cidMap.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<String, DataSource> entry = it.next();
        String cid = extractCID(entry.getKey());
        if (!htmlContent.contains("cid:" + cid)) {
            parsedComponents.attachmentList.put(cid, entry.getValue());
            it.remove();
        }
    }
}

Thanks
Ned

Hi,

I can confirm that after making the above change my use case is now working and not experiencing the ConcurrentModificationException.

Thanks
Ned

I think you were checking the develop folder (not released in a version), while the bug is already in the master folder (released in recent versions).

I'm going to backport your change into the master and release it in v5.1.5.

Done, released in 5.1.5! Thanks for the bug report!!