source: contrib/MailArchiver/sources/vendor/mime4j/apache-mime4j-0.7-SNAPSHOT-20110327.010440-17/core/src/main/java/org/apache/james/mime4j/parser/ContentHandler.java @ 6785

Revision 6785, 7.1 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.parser;
21
22import org.apache.james.mime4j.MimeException;
23import org.apache.james.mime4j.stream.BodyDescriptor;
24import org.apache.james.mime4j.stream.RawField;
25
26import java.io.IOException;
27import java.io.InputStream;
28
29/**
30 * <p>
31 * Receives notifications of the content of a plain RFC822 or MIME message.
32 * Implement this interface and register an instance of that implementation
33 * with a <code>MimeStreamParser</code> instance using its
34 * {@link org.apache.james.mime4j.stream.MimeStreamParser#setContentHandler(ContentHandler)}
35 * method. The parser uses the <code>ContentHandler</code> instance to report
36 * basic message-related events like the start and end of the body of a
37 * part in a multipart MIME entity.
38 * </p>
39 * <p>
40 * Throwing an exception from an event method will terminate the message
41 * processing, i.e. no new events will be generated for that message.
42 * <p>
43 * Events will be generated in the order the corresponding elements occur in
44 * the message stream parsed by the parser. E.g.:
45 * <pre>
46 *      startMessage()
47 *          startHeader()
48 *              field(...)
49 *              field(...)
50 *              ...
51 *          endHeader()
52 *          startMultipart()
53 *              preamble(...)
54 *              startBodyPart()
55 *                  startHeader()
56 *                      field(...)
57 *                      field(...)
58 *                      ...
59 *                  endHeader()
60 *                  body()
61 *              endBodyPart()
62 *              startBodyPart()
63 *                  startHeader()
64 *                      field(...)
65 *                      field(...)
66 *                      ...
67 *                  endHeader()
68 *                  body()
69 *              endBodyPart()
70 *              epilogue(...)
71 *          endMultipart()
72 *      endMessage()
73 * </pre>
74 * The above shows an example of a MIME message consisting of a multipart
75 * body containing two body parts.
76 * </p>
77 * <p>
78 * See MIME RFCs 2045-2049 for more information on the structure of MIME
79 * messages and RFC 822 and 2822 for the general structure of Internet mail
80 * messages.
81 * </p>
82 */
83public interface ContentHandler {
84
85    /**
86     * Called when a new message starts (a top level message or an embedded
87     * rfc822 message).
88     *
89     * @throws MimeException on processing errors
90     */
91    void startMessage() throws MimeException;
92
93    /**
94     * Called when a message ends.
95     *
96     * @throws MimeException on processing errors
97     */
98    void endMessage() throws MimeException;
99
100    /**
101     * Called when a new body part starts inside a
102     * <code>multipart/*</code> entity.
103     *
104     * @throws MimeException on processing errors
105     */
106    void startBodyPart() throws MimeException;
107
108    /**
109     * Called when a body part ends.
110     *
111     * @throws MimeException on processing errors
112     */
113    void endBodyPart() throws MimeException;
114
115    /**
116     * Called when a header (of a message or body part) is about to be parsed.
117     *
118     * @throws MimeException on processing errors
119     */
120    void startHeader() throws MimeException;
121
122    /**
123     * Called for each field of a header.
124     *
125     * @param rawField the MIME field.
126     * @throws MimeException on processing errors
127     */
128    void field(RawField rawField) throws MimeException;
129
130    /**
131     * Called when there are no more header fields in a message or body part.
132     *
133     * @throws MimeException on processing errors
134     */
135    void endHeader() throws MimeException;
136
137    /**
138     * Called for the preamble (whatever comes before the first body part)
139     * of a <code>multipart/*</code> entity.
140     *
141     * @param is used to get the contents of the preamble.
142     * @throws MimeException on processing errors
143     * @throws IOException should be thrown on I/O errors.
144     */
145    void preamble(InputStream is) throws MimeException, IOException;
146
147    /**
148     * Called for the epilogue (whatever comes after the final body part)
149     * of a <code>multipart/*</code> entity.
150     *
151     * @param is used to get the contents of the epilogue.
152     * @throws MimeException on processing errors
153     * @throws IOException should be thrown on I/O errors.
154     */
155    void epilogue(InputStream is) throws MimeException, IOException;
156
157    /**
158     * Called when the body of a multipart entity is about to be parsed.
159     *
160     * @param bd encapsulates the values (either read from the
161     *        message stream or, if not present, determined implictly
162     *        as described in the
163     *        MIME rfc:s) of the <code>Content-Type</code> and
164     *        <code>Content-Transfer-Encoding</code> header fields.
165     * @throws MimeException on processing errors
166     */
167    void startMultipart(BodyDescriptor bd) throws MimeException;
168
169    /**
170     * Called when the body of an entity has been parsed.
171     *
172     * @throws MimeException on processing errors
173     */
174    void endMultipart() throws MimeException;
175
176    /**
177     * Called when the body of a discrete (non-multipart) entity is about to
178     * be parsed.
179     *
180     * @param bd see {@link #startMultipart(BodyDescriptor)}
181     * @param is the contents of the body. NOTE: this is the raw body contents
182     *           - it will not be decoded if encoded. The <code>bd</code>
183     *           parameter should be used to determine how the stream data
184     *           should be decoded.
185     * @throws MimeException on processing errors
186     * @throws IOException should be thrown on I/O errors.
187     */
188    void body(BodyDescriptor bd, InputStream is)
189        throws MimeException, IOException;
190
191    /**
192     * Called when a new entity (message or body part) starts and the
193     * parser is in <code>raw</code> mode.
194     *
195     * @param is the raw contents of the entity.
196     * @throws MimeException on processing errors
197     * @throws IOException should be thrown on I/O errors.
198     * @see org.apache.james.mime4j.stream.MimeStreamParser#setRaw(boolean)
199     */
200    void raw(InputStream is) throws MimeException, IOException;
201
202}
Note: See TracBrowser for help on using the repository browser.