View Javadoc

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