public static Date parseDateLenient(String text) {
        if (text == null) {
            return null;
        }
        String normalized = normalize(text);
        for (DateTimeFormatter dateTimeFormatter : DATE_TIME_FORMATTERS) {
            try {
                ZonedDateTime zonedDateTime = ZonedDateTime.parse(normalized, dateTimeFormatter);
                return Date.from(Instant.from(zonedDateTime));
            } catch (SecurityException e) {
                throw e;
            } catch (DateTimeParseException e) {

                //There's a bug in java 8 that if we include .withZone in the DateTimeFormatter,
                //that will override the offset/timezone id even if it included
                // in the original string.  This is fixed in later versions of Java.
                // Once we move to Java 11, we can get rid of this. Can't make this up...
                try {
                    LocalDateTime localDateTime = LocalDateTime.parse(normalized, dateTimeFormatter);
                    return Date.from(Instant.from(localDateTime.atOffset(UTC)));
                } catch (SecurityException e2) {
                    throw e2;
                } catch (Exception e2) {
                    //swallow
                }
            } catch (Exception e) {
                //can get StringIndexOutOfBoundsException because of a bug in java 8
                //ignore
            }
        }

        for (DateTimeFormatter dateFormatter : DATE_FORMATTERS) {
            try {
                TemporalAccessor temporalAccessor = dateFormatter.parse(normalized);
                ZonedDateTime localDate = LocalDate.from(temporalAccessor)
                        .atStartOfDay()
                        .atZone(MIDDAY.toZoneId());
                return Date.from(Instant.from(localDate));
            } catch (SecurityException e) {
                throw e;
            } catch (Exception e) {
                //ignore
            }
        }
        return null;
    }
@Test// for dev purposes
    public void oneOff() throws Exception {
  /*      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss z");
        System.out.println(simpleDateFormat.format(new Date()));
        DateTimeFormatter formatter = DateTimeFormatter
                .ofPattern("yyyy-MM-dd'T'HH:mm:ss.S OOOO")
                .withLocale(Locale.US);
        String date = formatter.format(ZonedDateTime.now(ZoneOffset.UTC));
        System.out.println("String: " + date);
        System.out.println("parsed: " + formatter.parse(date) + " from " + date);
*/
        String s = "Mon, 6 Sep 2010 05:25:34 -0400 (EDT)";
        s = "Tue, 9 Jun 2009 23:58:45 -0400";

        //System.out.println(RFC)
        try {
            System.out.println("mime4j: " + DateTimeFieldLenientImpl.RFC_5322.parse(s));
        } catch (Exception e) {
            System.out.println("mime4j: null");
        }
        try {
            Date d = MailDateParser.parseDateLenient(s);
            DateFormat df =
                    new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", new DateFormatSymbols(Locale.US));
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            String dateString = df.format(d);
            System.out.println("dev parser lenient: " + dateString);
        } catch (Exception e) {
            System.out.println("dev parser lenient: null");
        }
    }