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
20package org.apache.james.mime4j.field;
21
22//BEGIN android-changed: Stubbing out logging
23import org.apache.james.mime4j.Log;
24import org.apache.james.mime4j.LogFactory;
25//END android-changed
26import org.apache.james.mime4j.field.address.AddressList;
27import org.apache.james.mime4j.field.address.parser.ParseException;
28
29public class AddressListField extends Field {
30    private AddressList addressList;
31    private ParseException parseException;
32
33    protected AddressListField(String name, String body, String raw, AddressList addressList, ParseException parseException) {
34        super(name, body, raw);
35        this.addressList = addressList;
36        this.parseException = parseException;
37    }
38
39    public AddressList getAddressList() {
40        return addressList;
41    }
42
43    public ParseException getParseException() {
44        return parseException;
45    }
46
47    public static class Parser implements FieldParser {
48        private static Log log = LogFactory.getLog(Parser.class);
49
50        public Field parse(final String name, final String body, final String raw) {
51            AddressList addressList = null;
52            ParseException parseException = null;
53            try {
54                addressList = AddressList.parse(body);
55            }
56            catch (ParseException e) {
57                if (log.isDebugEnabled()) {
58                    log.debug("Parsing value '" + body + "': "+ e.getMessage());
59                }
60                parseException = e;
61            }
62            return new AddressListField(name, body, raw, addressList, parseException);
63        }
64    }
65}
66