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 org.apache.geronimo.javamail.store.pop3.POP3Constants;
025
026 import org.apache.geronimo.mail.util.Base64;
027
028 /**
029 * This class provides the basic implementation for the POP3Response.
030 *
031 * @see org.apache.geronimo.javamail.store.pop3.POP3Response
032 * @version $Rev: 597135 $ $Date: 2007-11-21 11:26:57 -0500 (Wed, 21 Nov 2007) $
033 */
034
035 public class POP3Response implements POP3Constants {
036
037 private int status = ERR;
038
039 private String firstLine;
040
041 private byte[] data;
042
043 POP3Response(int status, String firstLine, byte []data) {
044 this.status = status;
045 this.firstLine = firstLine;
046 this.data = data;
047 }
048
049 public int getStatus() {
050 return status;
051 }
052
053 public byte[] getData() {
054 return data;
055 }
056
057 public ByteArrayInputStream getContentStream() {
058 return new ByteArrayInputStream(data);
059 }
060
061 public String getFirstLine() {
062 return firstLine;
063 }
064
065 public boolean isError() {
066 return status == ERR;
067 }
068
069 public boolean isChallenge() {
070 return status == CHALLENGE;
071 }
072
073 /**
074 * Decode the message portion of a continuation challenge response.
075 *
076 * @return The byte array containing the decoded data.
077 */
078 public byte[] decodeChallengeResponse()
079 {
080 // the challenge response is a base64 encoded string...
081 return Base64.decode(firstLine.trim());
082 }
083
084 }
085