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 java.io.ByteArrayInputStream; 023 024 import java.util.ArrayList; 025 import java.util.List; 026 027 import javax.mail.MessagingException; 028 029 /** 030 * This class adds functionality to the basic response by parsing the reply for 031 * LIST command and obtaining specific information about the msgnum and the 032 * size. It could be for one or more msgs depending on wether a msg number was 033 * passed or not into the LIST command 034 * 035 * @see org.apache.geronimo.javamail.store.pop3.POP3Response 036 * @see org.apache.geronimo.javamail.store.pop3.response.DefaultPOP3Response 037 * 038 * @version $Rev: 597135 $ $Date: 2007-11-21 11:26:57 -0500 (Wed, 21 Nov 2007) $ 039 */ 040 041 public class POP3ListResponse extends POP3Response { 042 043 private int msgnum = 0; 044 045 private int size = 0; 046 047 private List multipleMsgs = null; 048 049 POP3ListResponse(POP3Response baseRes) throws MessagingException { 050 super(baseRes.getStatus(), baseRes.getFirstLine(), baseRes.getData()); 051 052 // if ERR not worth proceeding any further 053 if (OK == getStatus()) { 054 055 // if data == null, then it mean it's a single line response 056 if (baseRes.getData() == null) { 057 String[] args = getFirstLine().split(SPACE); 058 try { 059 msgnum = Integer.parseInt(args[0]); 060 } catch (NumberFormatException e) { 061 throw new MessagingException("Invalid response for LIST command", e); 062 } 063 try { 064 size = Integer.parseInt(args[1]); 065 } catch (NumberFormatException e) { 066 throw new MessagingException("Invalid response for LIST command", e); 067 } 068 } else { 069 int totalMsgs = 0; 070 String[] args = getFirstLine().split(SPACE); 071 try { 072 totalMsgs = Integer.parseInt(args[0]); 073 } catch (NumberFormatException e) { 074 throw new MessagingException("Invalid response for LIST command", e); 075 } 076 multipleMsgs = new ArrayList(totalMsgs); 077 // Todo : multi-line response parsing 078 } 079 080 } 081 } 082 083 public int getMessageNumber() { 084 return msgnum; 085 } 086 087 public int getSize() { 088 return size; 089 } 090 091 /** 092 * Messages can be accessed by multipleMsgs.getElementAt(msgnum) 093 * 094 */ 095 public List getMultipleMessageDetails() { 096 return multipleMsgs; 097 } 098 099 }