001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.geronimo.javamail.store.pop3.connection;
021
022 import javax.mail.MessagingException;
023
024 /**
025 * This class adds functionality to the basic response by parsing the status
026 * line and obtaining specific information about num of msgs and the size
027 *
028 * @see org.apache.geronimo.javamail.store.pop3.POP3Response
029 * @see org.apache.geronimo.javamail.store.pop3.response.DefaultPOP3Response
030 *
031 * @version $Rev: 597135 $ $Date: 2007-11-21 11:26:57 -0500 (Wed, 21 Nov 2007) $
032 */
033
034 public class POP3StatusResponse extends POP3Response {
035
036 private int numMessages = 0;
037
038 private int size = 0;
039
040 POP3StatusResponse(POP3Response baseRes) throws MessagingException {
041 super(baseRes.getStatus(), baseRes.getFirstLine(), baseRes.getData());
042
043 // if ERR not worth proceeding any further
044 if (OK == getStatus()) {
045 String[] args = getFirstLine().split(SPACE);
046 try {
047 numMessages = Integer.parseInt(args[0]);
048 } catch (NumberFormatException e) {
049 throw new MessagingException("Invalid response for STAT command", e);
050 }
051 try {
052 size = Integer.parseInt(args[1]);
053 } catch (NumberFormatException e) {
054 throw new MessagingException("Invalid response for STAT command", e);
055 }
056 }
057 }
058
059 public int getNumMessages() {
060 return numMessages;
061 }
062
063 public int getSize() {
064 return size;
065 }
066
067 }