/* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is the Netscape Messaging Access SDK Version 3.5 code, * released on or about June 15, 1998. * * The Initial Developer of the Original Code is Netscape Communications * Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): ______________________________________. */ import netscape.messaging.imap4.*; import java.io.*; import java.net.*; import java.util.*; /** * ServerSink is the data sink for all IMAP4 commands * @author alterego@netscape.com * @version 0.1 */ public class ServerSink extends IMAP4Sink { /** Creates an ServerSink object */ public ServerSink() { m_uidNumbers = new Vector(); } /** * Indicates the end of response(s) for successful commands * @param in_tag The tag associated with the command * @param in_status "OK" * @param in_reason The reason for in_status */ public void taggedLine( StringBuffer in_tag, StringBuffer in_status, StringBuffer in_reason) { System.out.println("TAG: " + in_tag); System.out.println("STATUS: " + in_status); System.out.println("REASON: " + in_reason); } /** * Indicates the response for unsuccessful commands (error responses) * @param in_tag The tag associated with the command * @param in_status "NO" or "BAD" * @param in_reason The reason for in_status */ public void error( StringBuffer in_tag, StringBuffer in_status, StringBuffer in_reason) throws IMAP4ServerException { System.out.println("----------ERROR---------"); System.out.println("TAG: " + in_tag); System.out.println("STATUS: " + in_status); System.out.println("REASON: " + in_reason); System.out.println("----------ERROR---------"); throw new IMAP4ServerException(in_tag + " " + in_reason); } /** * An unsolicited ok response * @param in_responseCode The response code (optional) * @param in_information An information message in the form of human-readable text */ public void ok(StringBuffer in_responseCode, StringBuffer in_information) { System.out.println("CODE: " + in_responseCode); System.out.println("Info: " + in_information); } /** * Raw (unparsed) data is pushed into here. Note: Matches up with sendCommand * and will also be used as a default method to push information that doesn't * belong anywhere else * @param in_tag The tag associated with the command * @param in_data The raw data */ public void rawResponse(StringBuffer in_data) { System.out.println("rawResponse: " + in_data); } //Fetch Response ////////////////////////////////////////////////////////////////////// /** * Indicates the beginning of a fetch response * @param in_msg The message number or uid * @return Object A reference object that will be used to associate all data * items for a given response */ public Object fetchStart(int in_msg) { System.out.println("Fetch Start.................. " + in_msg); StringBuffer l_buffer = new StringBuffer(); l_buffer.append("Msg Num: " + in_msg); return l_buffer; } /** * The data for the particular message has been completely fetched * @param in_reference A reference object that will be used to associate all data * items for a given response */ public void fetchEnd(Object in_reference) { System.out.println("Fetch End.................. "); } /** * The size of the message * Data item(s): RFC822.SIZE * @param in_reference A reference object that will be used to associate all data * items for a given response * @param in_size The size of the data * */ public void fetchSize(Object in_reference, int in_size) { String l_data = "Size: " + in_size; System.out.println(l_data); ((StringBuffer)in_reference).append(l_data); } /** * The data associated with the data items listed below * Data item(s): BODY[, BODY.PEEK[, RFC822.HEADER, RFC822, RFC822.TEXT * @param in_reference A reference object that will be used to associate all data * items for a given response * @param in_data A chunk of message data * @param in_bytesRead The number of bytes read so far * @param in_totalBytes The total size of the body segment */ public void fetchData(Object in_reference, byte[] in_data, int in_bytesRead, int in_totalBytes) { String l_data = new String(in_data); // System.out.println("Data: " + l_data); ((StringBuffer)in_reference).append(l_data); } /** * The value of the flags * Data item(s): FLAGS * @param in_reference A reference object that will be used to associate all data * items for a given response * @param in_flags The flags */ public void fetchFlags(Object in_reference, StringBuffer in_flags) { System.out.println("Flags: " + in_flags); ((StringBuffer)in_reference).append("Flags: " + in_flags); } /** * The value of the body structure * Data item(s): BODY, BODYSTRUCTURE * @param in_reference A reference object that will be used to associate all data * items for a given response * @param in_bodyStructure The body structure */ public void fetchBodyStructure(Object in_reference, StringBuffer in_bodyStructure) { System.out.println("BodyStructure: " + in_bodyStructure); ((StringBuffer)in_reference).append("BodyStructure: " + in_bodyStructure); } /** * The value of the envelope Note: Use ENVELOPE_* values for quick access * Data item(s): ENVELOPE * @param in_reference A reference object that will be used to associate all data * items for a given response * @param in_fieldValue The value of the field */ public void fetchEnvelope(Object in_reference, StringBuffer[] in_fieldValue) { for(int i=0; i