class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailDetector {

    @Override
    public boolean isAutoSubmitted(Mail mail) throws MessagingException {
        String[] headers = mail.getMessage().getHeader(AUTO_SUBMITTED_HEADER);
        if (headers != null) {
            return Arrays.stream(headers)
                .anyMatch(this::isAutoSubmitted);
        }
        return false;
    }

}