source: contrib/MailArchiver/sources/vendor/mime4j/custom/core/src/main/java/org/apache/james/mime4j/stream/MimeEntityConfig.java @ 6785

Revision 6785, 8.3 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
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.stream;
21
22import org.apache.james.mime4j.MimeException;
23
24/**
25 * MIME entity configuration
26 */
27public final class MimeEntityConfig implements Cloneable {
28
29    private boolean strictParsing;
30    private int maxLineLen;
31    private int maxHeaderCount;
32    private int maxHeaderLen;
33    private long maxContentLen;
34    private boolean countLineNumbers;
35    private String headlessParsing;
36    private boolean malformedHeaderStartsBody;
37   
38        public MimeEntityConfig() {
39        this.strictParsing = false;
40        this.malformedHeaderStartsBody = false;
41        this.maxLineLen = 1000;
42        this.maxHeaderCount = 1000;
43        this.maxHeaderLen = 10000;
44        this.maxContentLen = -1;
45        this.headlessParsing = null;
46    }
47   
48    /**
49     * @see #setMalformedHeaderStartsBody(boolean)
50     *
51     * @return true if malformed header should "end" the headers and be
52     * part of the body
53     */
54    public boolean isMalformedHeaderStartsBody() {
55                return malformedHeaderStartsBody;
56        }
57
58        /**
59         * Define the behaviour for dealing with malformed headers while in lenient
60         * mode
61         *
62         * @param malformedHeaderStartsBody <code>true</code> to make the parser
63         *            interpret a malformed header as end of the headers and
64         *            as part of the body (as if the CRLF separator was missing).
65         *            <code>false</code> to simply ignore malformed headers and
66         *            continue parsing headers from the following line.
67         */
68        public void setMalformedHeaderStartsBody(boolean malformedHeaderStartsBody) {
69                this.malformedHeaderStartsBody = malformedHeaderStartsBody;
70        }
71
72    /**
73     * Returns the value of the strict parsing mode
74     * @see #setStrictParsing(boolean)
75     *
76     * @return value of the strict parsing mode
77     */
78    public boolean isStrictParsing() {
79        return this.strictParsing;
80    }
81
82    /**
83     * Defines whether minor violations of the MIME specification should be
84     * tolerated or should result in a {@link MimeException}. If this parameter
85     * is set to <code>true</code>, a strict interpretation of the MIME
86     * specification will be enforced, If this parameter is set to <code>false</code>
87     * minor violations will result in a warning in the log.
88     * <p>
89     * Default value: <code>false</code>
90     *
91     * @param strictParsing value of the strict parsing mode
92     */
93    public void setStrictParsing(boolean strictParsing) {
94        this.strictParsing = strictParsing;
95    }
96
97    /**
98     * Returns the maximum line length limit
99     * @see #setMaxLineLen(int)
100     *
101     * @return value of the the maximum line length limit
102     */
103    public int getMaxLineLen() {
104        return this.maxLineLen;
105    }
106
107    /**
108     * Sets the maximum line length limit. Parsing of a MIME entity will be terminated
109     * with a {@link MimeException} if a line is encountered that exceeds the maximum
110     * length limit. If this parameter is set to a non positive value the line length
111     * check will be disabled.
112     * <p>
113     * Default value: <code>1000</code>
114     *
115     * @param maxLineLen maximum line length limit
116     */
117    public void setMaxLineLen(int maxLineLen) {
118        this.maxLineLen = maxLineLen;
119    }
120   
121    /**
122     * Returns the maximum header limit
123     * @see #setMaxHeaderCount(int)
124     *
125     * @return value of the the maximum header limit
126     */
127    public int getMaxHeaderCount() {
128        return this.maxHeaderCount;
129    }
130
131    /**
132     * Sets the maximum header limit. Parsing of a MIME entity will be terminated
133     * with a {@link MimeException} if the number of headers exceeds the maximum
134     * limit. If this parameter is set to a non positive value the header limit check
135     * will be disabled.
136     * <p>
137     * Default value: <code>1000</code>
138     *
139     * @param maxHeaderCount maximum header limit
140     */
141    public void setMaxHeaderCount(int maxHeaderCount) {
142        this.maxHeaderCount = maxHeaderCount;
143    }
144
145    /**
146     * Returns the maximum header length limit
147     * @see #setMaxHeaderLen(int)
148     *
149     * @return value of the maximum header length limit
150     */
151    public int getMaxHeaderLen() {
152        return maxHeaderLen;
153    }
154
155    /**
156     * Sets the maximum header length limit. Parsing of a MIME entity will be terminated
157     * with a {@link MimeException} if the total length of a header exceeds this limit.
158     * If this parameter is set to a non positive value the header length check will be
159     * disabled.
160     * <p>
161     * A message header may be folded across multiple lines. This configuration parameter
162     * is used to limit the total length of a header, i.e. the sum of the length of all
163     * lines the header spans across (including line terminators).
164     * <p>
165     * Default value: <code>10000</code>
166     *
167     * @param maxHeaderLen maximum header length limit
168     */
169    public void setMaxHeaderLen(int maxHeaderLen) {
170        this.maxHeaderLen = maxHeaderLen;
171    }
172
173    /**
174     * Returns the maximum content length limit
175     * @see #setMaxContentLen(long)
176     *
177     * @return value of the the maximum content length limit
178     */
179    public long getMaxContentLen() {
180        return maxContentLen;
181    }
182
183    /**
184     * Sets the maximum content length limit. Parsing of a MIME entity will be terminated
185     * with a {@link MimeException} if a content body exceeds the maximum length limit.
186     * If this parameter is set to a non positive value the content length
187     * check will be disabled.
188     * <p>
189     * Default value: <code>-1</code>
190     *
191     * @param maxContentLen maximum content length limit
192     */
193    public void setMaxContentLen(long maxContentLen) {
194        this.maxContentLen = maxContentLen;
195    }
196
197    /**
198     * Returns the value of the default content type.
199     * When not null, indicates that the parsing should be headless.
200     *
201     * @return default content type when parsing headless,
202     * null otherwise
203     * @see org.apache.james.mime4j.parser.MimeStreamParser#parse(java.io.InputStream)
204     */
205    public String getHeadlessParsing() {
206        return headlessParsing;
207    }
208
209    /**
210     * Defines a default content type.
211     * When not null, indicates that the parsing should be headless.
212     * <p>
213     * Default value: <code>null</code>
214     *
215     * @param contentType
216     *            value of the default content type when parsing headless,
217     *            null otherwise
218     * @see org.apache.james.mime4j.parser.MimeStreamParser#parse(java.io.InputStream)
219     */
220    public void setHeadlessParsing(String contentType) {
221        this.headlessParsing = contentType;
222    }
223
224    @Override
225    public MimeEntityConfig clone() {
226        try {
227            return (MimeEntityConfig) super.clone();
228        } catch (CloneNotSupportedException e) {
229            // this shouldn't happen, since we are Cloneable
230            throw new InternalError();
231        }
232    }
233   
234    @Override
235    public String toString() {
236        return "[strict parsing: " + strictParsing + ", max line length: "
237                + maxLineLen + ", max header count: " + maxHeaderCount
238                + ", max content length: " + maxContentLen
239                + ", count line numbers: " + countLineNumbers + "]";
240    }
241   
242
243
244}
Note: See TracBrowser for help on using the repository browser.