View Javadoc

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.mail.BodyPart;
21  import javax.mail.MessagingException;
22  import javax.mail.MultipartDataSource;
23  
24  import javax.mail.internet.MimePart;
25  import javax.mail.internet.MimePartDataSource;
26  
27  import org.apache.geronimo.javamail.store.imap.connection.IMAPBodyStructure;
28  
29  public class IMAPMultipartDataSource extends MimePartDataSource implements MultipartDataSource {
30      // the list of parts
31      protected BodyPart[] parts;
32  
33      IMAPMultipartDataSource(IMAPMessage message, MimePart parent, String section, IMAPBodyStructure bodyStructure) {
34          super(parent);
35  
36          parts = new BodyPart[bodyStructure.parts.length];
37          
38          // We're either created from the parent message, in which case we're the top level 
39          // of the hierarchy, or we're created from a nested message, so we need to apply the 
40          // parent numbering prefix. 
41          String sectionBase = section == null ? "" : section + "."; 
42  
43          for (int i = 0; i < parts.length; i++) {
44              // create a section id.  This is either the count (origin zero) or a subpart of the previous section.
45              parts[i] = new IMAPMimeBodyPart(message, (IMAPBodyStructure)bodyStructure.parts[i], sectionBase + (i + 1));
46          }
47      }
48  
49      public int getCount() {
50          return parts.length;
51      }
52  
53      public BodyPart getBodyPart(int index) throws MessagingException {
54          return parts[index];
55      }
56  }