class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailDetector {

    @Override
    public boolean isMdnSentAutomatically(Mail mail) throws MessagingException {
        ResultCollector resultCollector = new ResultCollector(false);
        MimeStreamParser parser = new MimeStreamParser(MimeConfig.custom()
            .setMaxContentLen(100 * 1024 * 1024)
            .setMaxHeaderCount(-1)
            .setMaxHeaderLen(-1)
            .setMaxLineLen(-1)
            .setHeadlessParsing(mail.getMessage().getContentType())
            .build());
        parser.setContentHandler(createMdnContentHandler(resultCollector));
        try {
            parser.parse(new MimeMessageInputStream(mail.getMessage()));
        } catch (MimeException e) {
            throw new MessagingException("Can not parse Mime", e);
        } catch (IOException e) {
            throw new MessagingException("Can not read content", e);
        }
        return resultCollector.getResult();
    }

}