View Javadoc

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  
20  package org.apache.geronimo.javamail.store.pop3.connection;
21  
22  import java.io.ByteArrayInputStream; 
23  
24  import java.util.ArrayList; 
25  import java.util.List;     
26  
27  import javax.mail.MessagingException;
28  
29  /**
30   * This class adds functionality to the basic response by parsing the reply for
31   * LIST command and obtaining specific information about the msgnum and the
32   * size. It could be for one or more msgs depending on wether a msg number was
33   * passed or not into the LIST command
34   * 
35   * @see org.apache.geronimo.javamail.store.pop3.POP3Response
36   * @see org.apache.geronimo.javamail.store.pop3.response.DefaultPOP3Response
37   * 
38   * @version $Rev: 597135 $ $Date: 2007-11-21 11:26:57 -0500 (Wed, 21 Nov 2007) $
39   */
40  
41  public class POP3ListResponse extends POP3Response {
42  
43      private int msgnum = 0;
44  
45      private int size = 0;
46  
47      private List multipleMsgs = null;
48  
49      POP3ListResponse(POP3Response baseRes) throws MessagingException {
50          super(baseRes.getStatus(), baseRes.getFirstLine(), baseRes.getData());
51  
52          // if ERR not worth proceeding any further
53          if (OK == getStatus()) {
54  
55              // if data == null, then it mean it's a single line response
56              if (baseRes.getData() == null) {
57                  String[] args = getFirstLine().split(SPACE);
58                  try {
59                      msgnum = Integer.parseInt(args[0]);
60                  } catch (NumberFormatException e) {
61                      throw new MessagingException("Invalid response for LIST command", e);
62                  }
63                  try {
64                      size = Integer.parseInt(args[1]);
65                  } catch (NumberFormatException e) {
66                      throw new MessagingException("Invalid response for LIST command", e);
67                  }
68              } else {
69                  int totalMsgs = 0;
70                  String[] args = getFirstLine().split(SPACE);
71                  try {
72                      totalMsgs = Integer.parseInt(args[0]);
73                  } catch (NumberFormatException e) {
74                      throw new MessagingException("Invalid response for LIST command", e);
75                  }
76                  multipleMsgs = new ArrayList(totalMsgs);
77                  // Todo : multi-line response parsing
78              }
79  
80          }
81      }
82  
83      public int getMessageNumber() {
84          return msgnum;
85      }
86  
87      public int getSize() {
88          return size;
89      }
90  
91      /**
92       * Messages can be accessed by multipleMsgs.getElementAt(msgnum)
93       * 
94       */
95      public List getMultipleMessageDetails() {
96          return multipleMsgs;
97      }
98  
99  }