Home | History | Annotate | Download | only in field
      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.address.AddressList;
     27 import org.apache.james.mime4j.field.address.MailboxList;
     28 import org.apache.james.mime4j.field.address.parser.ParseException;
     29 
     30 public class MailboxListField extends Field {
     31 
     32     private MailboxList mailboxList;
     33     private ParseException parseException;
     34 
     35     protected MailboxListField(final String name, final String body, final String raw, final MailboxList mailboxList, final ParseException parseException) {
     36         super(name, body, raw);
     37         this.mailboxList = mailboxList;
     38         this.parseException = parseException;
     39     }
     40 
     41     public MailboxList getMailboxList() {
     42         return mailboxList;
     43     }
     44 
     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 
     52         public Field parse(final String name, final String body, final String raw) {
     53             MailboxList mailboxList = null;
     54             ParseException parseException = null;
     55             try {
     56                 mailboxList = AddressList.parse(body).flatten();
     57             }
     58             catch (ParseException e) {
     59                 if (log.isDebugEnabled()) {
     60                     log.debug("Parsing value '" + body + "': "+ e.getMessage());
     61                 }
     62                 parseException = e;
     63             }
     64             return new MailboxListField(name, body, raw, mailboxList, parseException);
     65         }
     66     }
     67 }
     68