Example usage for javax.mail.internet MailDateFormat parse

List of usage examples for javax.mail.internet MailDateFormat parse

Introduction

In this page you can find the example usage for javax.mail.internet MailDateFormat parse.

Prototype

@Override
public Date parse(String text, ParsePosition pos) 

Source Link

Document

Parses the given date in the format specified by RFC 2822.

Usage

From source file:com.stimulus.archiva.domain.Email.java

public Date getReceivedDate() {
    MailDateFormat mdf = new MailDateFormat();

    try {//  w  w w . ja v a2s  . c o  m

        /*  Enumeration e = getAllHeaders();
          while (e.hasMoreElements()) {
             Header h = (Header)e.nextElement();
             System.out.println(h.getName()+":"+h.getValue());
          }*/
        String[] header = getHeader("Received");
        if (header == null || header.length < 1) {
            return null;
        }
        for (int i = 0; i < header.length; i++) {
            int received = header[i].lastIndexOf(';');
            if (received >= 0) {
                String dateStr = header[i].substring(received + 1).trim();
                Date date = mdf.parse(dateStr, new ParsePosition(0));
                return date;
            }
        }
    } catch (Exception re) {
        logger.debug("getReceivedDate(). unable to parse received date", re);
    }
    return null;
}