1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.javamail.store.imap;
19
20 import javax.activation.DataHandler;
21
22 import javax.mail.Flags;
23 import javax.mail.MessagingException;
24 import javax.mail.MethodNotSupportedException;
25
26 import org.apache.geronimo.javamail.store.imap.connection.IMAPEnvelope;
27 import org.apache.geronimo.javamail.store.imap.connection.IMAPBodyStructure;
28
29 /**
30 * A nested message attachement inside of another
31 * IMAP message. This is a less-functional version
32 * of the top-level message.
33 */
34 public class IMAPAttachedMessage extends IMAPMessage {
35 // the parent enclosing message.
36 protected IMAPMessage parent;
37
38 /**
39 * Constructor for an attached message part.
40 *
41 * @param parent The parent message (outer-most message).
42 * @param section The section identifier for this embedded part
43 * in IMAP section format. This will identify
44 * the part hierarchy used to locate this part within
45 * the message.
46 * @param envelope The Envelope that describes this part.
47 * @param bodyStructure
48 * The Body structure element that describes this part.
49 */
50 public IMAPAttachedMessage(IMAPMessage parent, String section, IMAPEnvelope envelope, IMAPBodyStructure bodyStructure) {
51 super((IMAPFolder)parent.getFolder(), parent.store, parent.getMessageNumber(), parent.sequenceNumber);
52 this.parent = parent;
53 // sets the subset we're looking for
54 this.section = section;
55 // the envelope and body structure are loaded from the server by the parent
56 this.envelope = envelope;
57 this.bodyStructure = bodyStructure;
58 }
59
60 /**
61 * Check if this message is still valid. This is
62 * delegated to the outer-most message.
63 *
64 * @exception MessagingException
65 */
66 protected void checkValidity() throws MessagingException {
67 parent.checkValidity();
68 }
69
70 /**
71 * Check if the outer-most message has been expunged.
72 *
73 * @return true if the message has been expunged.
74 */
75 public boolean isExpunged() {
76 return parent.isExpunged();
77 }
78
79 /**
80 * Get the size of this message part.
81 *
82 * @return The estimate size of this message part, in bytes.
83 */
84 public int getSize() {
85 return bodyStructure.bodySize;
86 }
87
88
89 /**
90 * Return a copy the flags associated with this message.
91 *
92 * @return a copy of the flags for this message
93 * @throws MessagingException if there was a problem accessing the Store
94 */
95 public Flags getFlags() throws MessagingException {
96 return parent.getFlags();
97 }
98
99
100 /**
101 * Check whether the supplied flag is set.
102 * The default implementation checks the flags returned by {@link #getFlags()}.
103 *
104 * @param flag the flags to check for
105 * @return true if the flags is set
106 * @throws MessagingException if there was a problem accessing the Store
107 */
108 public boolean isSet(Flags.Flag flag) throws MessagingException {
109 // load the flags, if needed
110 return parent.isSet(flag);
111 }
112
113 /**
114 * Set or clear a flag value.
115 *
116 * @param flags The set of flags to effect.
117 * @param set The value to set the flag to (true or false).
118 *
119 * @exception MessagingException
120 */
121 public void setFlags(Flags flag, boolean set) throws MessagingException {
122 throw new MethodNotSupportedException("Flags cannot be set on message attachements");
123 }
124 }
125