• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one   *
3  * or more contributor license agreements.  See the NOTICE file *
4  * distributed with this work for additional information        *
5  * regarding copyright ownership.  The ASF licenses this file   *
6  * to you under the Apache License, Version 2.0 (the            *
7  * "License"); you may not use this file except in compliance   *
8  * with the License.  You may obtain a copy of the License at   *
9  *                                                              *
10  *   http://www.apache.org/licenses/LICENSE-2.0                 *
11  *                                                              *
12  * Unless required by applicable law or agreed to in writing,   *
13  * software distributed under the License is distributed on an  *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15  * KIND, either express or implied.  See the License for the    *
16  * specific language governing permissions and limitations      *
17  * under the License.                                           *
18  ****************************************************************/
19 
20 package org.apache.james.mime4j.field;
21 
22 //BEGIN android-changed: Stubbing out logging
23 import org.apache.james.mime4j.Log;
24 import org.apache.james.mime4j.LogFactory;
25 //END android-changed
26 import org.apache.james.mime4j.field.datetime.DateTime;
27 import org.apache.james.mime4j.field.datetime.parser.ParseException;
28 
29 import java.util.Date;
30 
31 public class DateTimeField extends Field {
32     private Date date;
33     private ParseException parseException;
34 
DateTimeField(String name, String body, String raw, Date date, ParseException parseException)35     protected DateTimeField(String name, String body, String raw, Date date, ParseException parseException) {
36         super(name, body, raw);
37         this.date = date;
38         this.parseException = parseException;
39     }
40 
getDate()41     public Date getDate() {
42         return date;
43     }
44 
getParseException()45     public ParseException getParseException() {
46         return parseException;
47     }
48 
49     public static class Parser implements FieldParser {
50         private static Log log = LogFactory.getLog(Parser.class);
51 
parse(final String name, String body, final String raw)52         public Field parse(final String name, String body, final String raw) {
53             Date date = null;
54             ParseException parseException = null;
55             //BEGIN android-changed
56             body = com.android.email.Utility.cleanUpMimeDate(body);
57             //END android-changed
58             try {
59                 date = DateTime.parse(body).getDate();
60             }
61             catch (ParseException e) {
62                 if (log.isDebugEnabled()) {
63                     log.debug("Parsing value '" + body + "': "+ e.getMessage());
64                 }
65                 parseException = e;
66             }
67             return new DateTimeField(name, body, raw, date, parseException);
68         }
69     }
70 }
71