mail-1.4.1

16:39:03.323 INFO  jd.cli.Main - Decompiling mail-1.4.1.jar
package com.sun.mail.handlers;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.activation.ActivationDataFlavor;
import javax.activation.DataContentHandler;
import javax.activation.DataSource;

public class image_gif
  implements DataContentHandler
{
  private static ActivationDataFlavor myDF = new ActivationDataFlavor(Image.class, "image/gif", "GIF Image");
  
  protected ActivationDataFlavor getDF()
  {
    return myDF;
  }
  
  public DataFlavor[] getTransferDataFlavors()
  {
    return new DataFlavor[] { getDF() };
  }
  
  public Object getTransferData(DataFlavor df, DataSource ds)
    throws IOException
  {
    if (getDF().equals(df)) {
      return getContent(ds);
    }
    return null;
  }
  
  public Object getContent(DataSource ds)
    throws IOException
  {
    InputStream is = ds.getInputStream();
    int pos = 0;
    
    byte[] buf = new byte['?'];
    int count;
    while ((count = is.read(buf, pos, buf.length - pos)) != -1)
    {
      pos += count;
      if (pos >= buf.length)
      {
        int size = buf.length;
        if (size < 262144) {
          size += size;
        } else {
          size += 262144;
        }
        byte[] tbuf = new byte[size];
        System.arraycopy(buf, 0, tbuf, 0, pos);
        buf = tbuf;
      }
    }
    Toolkit tk = Toolkit.getDefaultToolkit();
    return tk.createImage(buf, 0, pos);
  }
  
  public void writeTo(Object obj, String type, OutputStream os)
    throws IOException
  {
    if (!(obj instanceof Image)) {
      throw new IOException("\"" + getDF().getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString());
    }
    throw new IOException(getDF().getMimeType() + " encoding not supported");
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.handlers.image_gif
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.handlers;

import java.awt.Image;
import javax.activation.ActivationDataFlavor;

public class image_jpeg
  extends image_gif
{
  private static ActivationDataFlavor myDF = new ActivationDataFlavor(Image.class, "image/jpeg", "JPEG Image");
  
  protected ActivationDataFlavor getDF()
  {
    return myDF;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.handlers.image_jpeg
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.handlers;

import java.awt.datatransfer.DataFlavor;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
import javax.activation.ActivationDataFlavor;
import javax.activation.DataContentHandler;
import javax.activation.DataSource;
import javax.mail.Message;
import javax.mail.MessageAware;
import javax.mail.MessageContext;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;

public class message_rfc822
  implements DataContentHandler
{
  ActivationDataFlavor ourDataFlavor = new ActivationDataFlavor(Message.class, "message/rfc822", "Message");
  
  public DataFlavor[] getTransferDataFlavors()
  {
    return new DataFlavor[] { ourDataFlavor };
  }
  
  public Object getTransferData(DataFlavor df, DataSource ds)
    throws IOException
  {
    if (ourDataFlavor.equals(df)) {
      return getContent(ds);
    }
    return null;
  }
  
  public Object getContent(DataSource ds)
    throws IOException
  {
    try
    {
      Session session;
      Session session;
      if ((ds instanceof MessageAware))
      {
        MessageContext mc = ((MessageAware)ds).getMessageContext();
        session = mc.getSession();
      }
      else
      {
        session = Session.getDefaultInstance(new Properties(), null);
      }
      return new MimeMessage(session, ds.getInputStream());
    }
    catch (MessagingException me)
    {
      throw new IOException("Exception creating MimeMessage in message/rfc822 DataContentHandler: " + me.toString());
    }
  }
  
  public void writeTo(Object obj, String mimeType, OutputStream os)
    throws IOException
  {
    if ((obj instanceof Message))
    {
      Message m = (Message)obj;
      try
      {
        m.writeTo(os);
      }
      catch (MessagingException me)
      {
        throw new IOException(me.toString());
      }
    }
    else
    {
      throw new IOException("unsupported object");
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.handlers.message_rfc822
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.handlers;

import java.awt.datatransfer.DataFlavor;
import java.io.IOException;
import java.io.OutputStream;
import javax.activation.ActivationDataFlavor;
import javax.activation.DataContentHandler;
import javax.activation.DataSource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;

public class multipart_mixed
  implements DataContentHandler
{
  private ActivationDataFlavor myDF = new ActivationDataFlavor(MimeMultipart.class, "multipart/mixed", "Multipart");
  
  public DataFlavor[] getTransferDataFlavors()
  {
    return new DataFlavor[] { myDF };
  }
  
  public Object getTransferData(DataFlavor df, DataSource ds)
    throws IOException
  {
    if (myDF.equals(df)) {
      return getContent(ds);
    }
    return null;
  }
  
  public Object getContent(DataSource ds)
    throws IOException
  {
    try
    {
      return new MimeMultipart(ds);
    }
    catch (MessagingException e)
    {
      IOException ioex = new IOException("Exception while constructing MimeMultipart");
      
      ioex.initCause(e);
      throw ioex;
    }
  }
  
  public void writeTo(Object obj, String mimeType, OutputStream os)
    throws IOException
  {
    if ((obj instanceof MimeMultipart)) {
      try
      {
        ((MimeMultipart)obj).writeTo(os);
      }
      catch (MessagingException e)
      {
        throw new IOException(e.toString());
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.handlers.multipart_mixed
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.handlers;

import javax.activation.ActivationDataFlavor;

public class text_html
  extends text_plain
{
  private static ActivationDataFlavor myDF = new ActivationDataFlavor(String.class, "text/html", "HTML String");
  
  protected ActivationDataFlavor getDF()
  {
    return myDF;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.handlers.text_html
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.handlers;

import java.awt.datatransfer.DataFlavor;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import javax.activation.ActivationDataFlavor;
import javax.activation.DataContentHandler;
import javax.activation.DataSource;
import javax.mail.internet.ContentType;
import javax.mail.internet.MimeUtility;

public class text_plain
  implements DataContentHandler
{
  private static ActivationDataFlavor myDF = new ActivationDataFlavor(String.class, "text/plain", "Text String");
  
  protected ActivationDataFlavor getDF()
  {
    return myDF;
  }
  
  public DataFlavor[] getTransferDataFlavors()
  {
    return new DataFlavor[] { getDF() };
  }
  
  public Object getTransferData(DataFlavor df, DataSource ds)
    throws IOException
  {
    if (getDF().equals(df)) {
      return getContent(ds);
    }
    return null;
  }
  
  public Object getContent(DataSource ds)
    throws IOException
  {
    String enc = null;
    InputStreamReader is = null;
    try
    {
      enc = getCharset(ds.getContentType());
      is = new InputStreamReader(ds.getInputStream(), enc);
    }
    catch (IllegalArgumentException iex)
    {
      throw new UnsupportedEncodingException(enc);
    }
    try
    {
      int pos = 0;
      
      char[] buf = new char['?'];
      int count;
      int size;
      while ((count = is.read(buf, pos, buf.length - pos)) != -1)
      {
        pos += count;
        if (pos >= buf.length)
        {
          size = buf.length;
          if (size < 262144) {
            size += size;
          } else {
            size += 262144;
          }
          char[] tbuf = new char[size];
          System.arraycopy(buf, 0, tbuf, 0, pos);
          buf = tbuf;
        }
      }
      return new String(buf, 0, pos);
    }
    finally
    {
      try
      {
        is.close();
      }
      catch (IOException ex) {}
    }
  }
  
  public void writeTo(Object obj, String type, OutputStream os)
    throws IOException
  {
    if (!(obj instanceof String)) {
      throw new IOException("\"" + getDF().getMimeType() + "\" DataContentHandler requires String object, " + "was given object of type " + obj.getClass().toString());
    }
    String enc = null;
    OutputStreamWriter osw = null;
    try
    {
      enc = getCharset(type);
      osw = new OutputStreamWriter(os, enc);
    }
    catch (IllegalArgumentException iex)
    {
      throw new UnsupportedEncodingException(enc);
    }
    String s = (String)obj;
    osw.write(s, 0, s.length());
    osw.flush();
  }
  
  private String getCharset(String type)
  {
    try
    {
      ContentType ct = new ContentType(type);
      String charset = ct.getParameter("charset");
      if (charset == null) {
        charset = "us-ascii";
      }
      return MimeUtility.javaCharset(charset);
    }
    catch (Exception ex) {}
    return null;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.handlers.text_plain
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.handlers;

import javax.activation.ActivationDataFlavor;

public class text_xml
  extends text_plain
{
  private static ActivationDataFlavor myDF = new ActivationDataFlavor(String.class, "text/xml", "XML String");
  
  protected ActivationDataFlavor getDF()
  {
    return myDF;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.handlers.text_xml
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

class AString
{
  byte[] bytes;
  
  AString(byte[] b)
  {
    bytes = b;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.AString
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

import com.sun.mail.util.ASCIIUtility;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Vector;

public class Argument
{
  protected Vector items;
  
  public Argument()
  {
    items = new Vector(1);
  }
  
  public void append(Argument arg)
  {
    items.ensureCapacity(items.size() + items.size());
    for (int i = 0; i < items.size(); i++) {
      items.addElement(items.elementAt(i));
    }
  }
  
  public void writeString(String s)
  {
    items.addElement(new AString(ASCIIUtility.getBytes(s)));
  }
  
  public void writeString(String s, String charset)
    throws UnsupportedEncodingException
  {
    if (charset == null) {
      writeString(s);
    } else {
      items.addElement(new AString(s.getBytes(charset)));
    }
  }
  
  public void writeBytes(byte[] b)
  {
    items.addElement(b);
  }
  
  public void writeBytes(ByteArrayOutputStream b)
  {
    items.addElement(b);
  }
  
  public void writeBytes(Literal b)
  {
    items.addElement(b);
  }
  
  public void writeAtom(String s)
  {
    items.addElement(new Atom(s));
  }
  
  public void writeNumber(int i)
  {
    items.addElement(new Integer(i));
  }
  
  public void writeNumber(long i)
  {
    items.addElement(new Long(i));
  }
  
  public void writeArgument(Argument c)
  {
    items.addElement(c);
  }
  
  public void write(Protocol protocol)
    throws IOException, ProtocolException
  {
    int size = items != null ? items.size() : 0;
    DataOutputStream os = (DataOutputStream)protocol.getOutputStream();
    for (int i = 0; i < size; i++)
    {
      if (i > 0) {
        os.write(32);
      }
      Object o = items.elementAt(i);
      if ((o instanceof Atom))
      {
        os.writeBytes(string);
      }
      else if ((o instanceof Number))
      {
        os.writeBytes(((Number)o).toString());
      }
      else if ((o instanceof AString))
      {
        astring(bytes, protocol);
      }
      else if ((o instanceof byte[]))
      {
        literal((byte[])o, protocol);
      }
      else if ((o instanceof ByteArrayOutputStream))
      {
        literal((ByteArrayOutputStream)o, protocol);
      }
      else if ((o instanceof Literal))
      {
        literal((Literal)o, protocol);
      }
      else if ((o instanceof Argument))
      {
        os.write(40);
        ((Argument)o).write(protocol);
        os.write(41);
      }
    }
  }
  
  private void astring(byte[] bytes, Protocol protocol)
    throws IOException, ProtocolException
  {
    DataOutputStream os = (DataOutputStream)protocol.getOutputStream();
    int len = bytes.length;
    if (len > 1024)
    {
      literal(bytes, protocol);
      return;
    }
    boolean quote = len == 0;
    boolean escape = false;
    for (int i = 0; i < len; i++)
    {
      byte b = bytes[i];
      if ((b == 0) || (b == 13) || (b == 10) || ((b & 0xFF) > Byte.MAX_VALUE))
      {
        literal(bytes, protocol);
        return;
      }
      if ((b == 42) || (b == 37) || (b == 40) || (b == 41) || (b == 123) || (b == 34) || (b == 92) || ((b & 0xFF) <= 32))
      {
        quote = true;
        if ((b == 34) || (b == 92)) {
          escape = true;
        }
      }
    }
    if (quote) {
      os.write(34);
    }
    if (escape) {
      for (int i = 0; i < len; i++)
      {
        byte b = bytes[i];
        if ((b == 34) || (b == 92)) {
          os.write(92);
        }
        os.write(b);
      }
    } else {
      os.write(bytes);
    }
    if (quote) {
      os.write(34);
    }
  }
  
  private void literal(byte[] b, Protocol protocol)
    throws IOException, ProtocolException
  {
    startLiteral(protocol, b.length).write(b);
  }
  
  private void literal(ByteArrayOutputStream b, Protocol protocol)
    throws IOException, ProtocolException
  {
    b.writeTo(startLiteral(protocol, b.size()));
  }
  
  private void literal(Literal b, Protocol protocol)
    throws IOException, ProtocolException
  {
    b.writeTo(startLiteral(protocol, b.size()));
  }
  
  private OutputStream startLiteral(Protocol protocol, int size)
    throws IOException, ProtocolException
  {
    DataOutputStream os = (DataOutputStream)protocol.getOutputStream();
    boolean nonSync = protocol.supportsNonSyncLiterals();
    
    os.write(123);
    os.writeBytes(Integer.toString(size));
    if (nonSync) {
      os.writeBytes("+}\r\n");
    } else {
      os.writeBytes("}\r\n");
    }
    os.flush();
    if (!nonSync) {
      for (;;)
      {
        Response r = protocol.readResponse();
        if (r.isContinuation()) {
          break;
        }
        if (r.isTagged()) {
          throw new LiteralException(r);
        }
      }
    }
    return os;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.Argument
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

class Atom
{
  String string;
  
  Atom(String s)
  {
    string = s;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.Atom
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

public class BadCommandException
  extends ProtocolException
{
  private static final long serialVersionUID = 5769722539397237515L;
  
  public BadCommandException() {}
  
  public BadCommandException(String s)
  {
    super(s);
  }
  
  public BadCommandException(Response r)
  {
    super(r);
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.BadCommandException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

import java.io.ByteArrayInputStream;

public class ByteArray
{
  private byte[] bytes;
  private int start;
  private int count;
  
  public ByteArray(byte[] b, int start, int count)
  {
    bytes = b;
    this.start = start;
    this.count = count;
  }
  
  public ByteArray(int size)
  {
    this(new byte[size], 0, size);
  }
  
  public byte[] getBytes()
  {
    return bytes;
  }
  
  public byte[] getNewBytes()
  {
    byte[] b = new byte[count];
    System.arraycopy(bytes, start, b, 0, count);
    return b;
  }
  
  public int getStart()
  {
    return start;
  }
  
  public int getCount()
  {
    return count;
  }
  
  public void setCount(int count)
  {
    this.count = count;
  }
  
  public ByteArrayInputStream toByteArrayInputStream()
  {
    return new ByteArrayInputStream(bytes, start, count);
  }
  
  public void grow(int incr)
  {
    byte[] nbuf = new byte[bytes.length + incr];
    System.arraycopy(bytes, 0, nbuf, 0, bytes.length);
    bytes = nbuf;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.ByteArray
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

public class CommandFailedException
  extends ProtocolException
{
  private static final long serialVersionUID = 793932807880443631L;
  
  public CommandFailedException() {}
  
  public CommandFailedException(String s)
  {
    super(s);
  }
  
  public CommandFailedException(Response r)
  {
    super(r);
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.CommandFailedException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

public class ConnectionException
  extends ProtocolException
{
  private transient Protocol p;
  private static final long serialVersionUID = 5749739604257464727L;
  
  public ConnectionException() {}
  
  public ConnectionException(String s)
  {
    super(s);
  }
  
  public ConnectionException(Protocol p, Response r)
  {
    super(r);
    this.p = p;
  }
  
  public Protocol getProtocol()
  {
    return p;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.ConnectionException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

import java.io.IOException;
import java.io.OutputStream;

public abstract interface Literal
{
  public abstract int size();
  
  public abstract void writeTo(OutputStream paramOutputStream)
    throws IOException;
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.Literal
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

public class LiteralException
  extends ProtocolException
{
  private static final long serialVersionUID = -6919179828339609913L;
  
  public LiteralException(Response r)
  {
    super(r.toString());
    response = r;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.LiteralException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

public class ParsingException
  extends ProtocolException
{
  private static final long serialVersionUID = 7756119840142724839L;
  
  public ParsingException() {}
  
  public ParsingException(String s)
  {
    super(s);
  }
  
  public ParsingException(Response r)
  {
    super(r);
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.ParsingException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

import com.sun.mail.util.SocketFetcher;
import com.sun.mail.util.TraceInputStream;
import com.sun.mail.util.TraceOutputStream;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Properties;
import java.util.Vector;

public class Protocol
{
  protected String host;
  private Socket socket;
  protected boolean debug;
  protected boolean quote;
  protected PrintStream out;
  protected Properties props;
  protected String prefix;
  private boolean connected = false;
  private TraceInputStream traceInput;
  private volatile ResponseInputStream input;
  private TraceOutputStream traceOutput;
  private volatile DataOutputStream output;
  private int tagCounter = 0;
  private volatile Vector handlers = null;
  private volatile long timestamp;
  private static final byte[] CRLF = { 13, 10 };
  
  public Protocol(String host, int port, boolean debug, PrintStream out, Properties props, String prefix, boolean isSSL)
    throws IOException, ProtocolException
  {
    try
    {
      this.host = host;
      this.debug = debug;
      this.out = out;
      this.props = props;
      this.prefix = prefix;
      
      socket = SocketFetcher.getSocket(host, port, props, prefix, isSSL);
      String s = props.getProperty("mail.debug.quote");
      quote = ((s != null) && (s.equalsIgnoreCase("true")));
      
      initStreams(out);
      
      processGreeting(readResponse());
      
      timestamp = System.currentTimeMillis();
      
      connected = true;
    }
    finally
    {
      if (!connected) {
        disconnect();
      }
    }
  }
  
  private void initStreams(PrintStream out)
    throws IOException
  {
    traceInput = new TraceInputStream(socket.getInputStream(), out);
    traceInput.setTrace(debug);
    traceInput.setQuote(quote);
    input = new ResponseInputStream(traceInput);
    
    traceOutput = new TraceOutputStream(socket.getOutputStream(), out);
    traceOutput.setTrace(debug);
    traceOutput.setQuote(quote);
    output = new DataOutputStream(new BufferedOutputStream(traceOutput));
  }
  
  public Protocol(InputStream in, OutputStream out, boolean debug)
    throws IOException
  {
    host = "localhost";
    this.debug = debug;
    quote = false;
    this.out = System.out;
    
    traceInput = new TraceInputStream(in, System.out);
    traceInput.setTrace(debug);
    traceInput.setQuote(quote);
    input = new ResponseInputStream(traceInput);
    
    traceOutput = new TraceOutputStream(out, System.out);
    traceOutput.setTrace(debug);
    traceOutput.setQuote(quote);
    output = new DataOutputStream(new BufferedOutputStream(traceOutput));
    
    timestamp = System.currentTimeMillis();
  }
  
  public long getTimestamp()
  {
    return timestamp;
  }
  
  public synchronized void addResponseHandler(ResponseHandler h)
  {
    if (handlers == null) {
      handlers = new Vector();
    }
    handlers.addElement(h);
  }
  
  public synchronized void removeResponseHandler(ResponseHandler h)
  {
    if (handlers != null) {
      handlers.removeElement(h);
    }
  }
  
  public void notifyResponseHandlers(Response[] responses)
  {
    if (handlers == null) {
      return;
    }
    for (int i = 0; i < responses.length; i++)
    {
      Response r = responses[i];
      if (r != null)
      {
        int size = handlers.size();
        if (size == 0) {
          return;
        }
        Object[] h = new Object[size];
        handlers.copyInto(h);
        for (int j = 0; j < size; j++) {
          ((ResponseHandler)h[j]).handleResponse(r);
        }
      }
    }
  }
  
  protected void processGreeting(Response r)
    throws ProtocolException
  {
    if (r.isBYE()) {
      throw new ConnectionException(this, r);
    }
  }
  
  protected ResponseInputStream getInputStream()
  {
    return input;
  }
  
  protected OutputStream getOutputStream()
  {
    return output;
  }
  
  protected synchronized boolean supportsNonSyncLiterals()
  {
    return false;
  }
  
  public Response readResponse()
    throws IOException, ProtocolException
  {
    return new Response(this);
  }
  
  protected ByteArray getResponseBuffer()
  {
    return null;
  }
  
  public String writeCommand(String command, Argument args)
    throws IOException, ProtocolException
  {
    String tag = "A" + Integer.toString(tagCounter++, 10);
    
    output.writeBytes(tag + " " + command);
    if (args != null)
    {
      output.write(32);
      args.write(this);
    }
    output.write(CRLF);
    output.flush();
    return tag;
  }
  
  public synchronized Response[] command(String command, Argument args)
  {
    Vector v = new Vector();
    boolean done = false;
    String tag = null;
    Response r = null;
    try
    {
      tag = writeCommand(command, args);
    }
    catch (LiteralException lex)
    {
      v.addElement(lex.getResponse());
      done = true;
    }
    catch (Exception ex)
    {
      v.addElement(Response.byeResponse(ex));
      done = true;
    }
    while (!done)
    {
      try
      {
        r = readResponse();
      }
      catch (IOException ioex)
      {
        r = Response.byeResponse(ioex);
      }
      catch (ProtocolException pex) {}
      continue;
      
      v.addElement(r);
      if (r.isBYE()) {
        done = true;
      }
      if ((r.isTagged()) && (r.getTag().equals(tag))) {
        done = true;
      }
    }
    Response[] responses = new Response[v.size()];
    v.copyInto(responses);
    timestamp = System.currentTimeMillis();
    return responses;
  }
  
  public void handleResult(Response response)
    throws ProtocolException
  {
    if (response.isOK()) {
      return;
    }
    if (response.isNO()) {
      throw new CommandFailedException(response);
    }
    if (response.isBAD()) {
      throw new BadCommandException(response);
    }
    if (response.isBYE())
    {
      disconnect();
      throw new ConnectionException(this, response);
    }
  }
  
  public void simpleCommand(String cmd, Argument args)
    throws ProtocolException
  {
    Response[] r = command(cmd, args);
    
    notifyResponseHandlers(r);
    
    handleResult(r[(r.length - 1)]);
  }
  
  public synchronized void startTLS(String cmd)
    throws IOException, ProtocolException
  {
    simpleCommand(cmd, null);
    socket = SocketFetcher.startTLS(socket, props, prefix);
    initStreams(out);
  }
  
  protected synchronized void disconnect()
  {
    if (socket != null)
    {
      try
      {
        socket.close();
      }
      catch (IOException e) {}
      socket = null;
    }
  }
  
  protected void finalize()
    throws Throwable
  {
    super.finalize();
    disconnect();
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.Protocol
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

public class ProtocolException
  extends Exception
{
  protected transient Response response = null;
  private static final long serialVersionUID = -4360500807971797439L;
  
  public ProtocolException() {}
  
  public ProtocolException(String s)
  {
    super(s);
  }
  
  public ProtocolException(Response r)
  {
    super(r.toString());
    response = r;
  }
  
  public Response getResponse()
  {
    return response;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.ProtocolException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

import com.sun.mail.util.ASCIIUtility;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Vector;

public class Response
{
  protected int index;
  protected int pindex;
  protected int size;
  protected byte[] buffer = null;
  protected int type = 0;
  protected String tag = null;
  private static final int increment = 100;
  public static final int TAG_MASK = 3;
  public static final int CONTINUATION = 1;
  public static final int TAGGED = 2;
  public static final int UNTAGGED = 3;
  public static final int TYPE_MASK = 28;
  public static final int OK = 4;
  public static final int NO = 8;
  public static final int BAD = 12;
  public static final int BYE = 16;
  public static final int SYNTHETIC = 32;
  
  public Response(String s)
  {
    buffer = ASCIIUtility.getBytes(s);
    size = buffer.length;
    parse();
  }
  
  public Response(Protocol p)
    throws IOException, ProtocolException
  {
    ByteArray ba = p.getResponseBuffer();
    ByteArray response = p.getInputStream().readResponse(ba);
    buffer = response.getBytes();
    size = (response.getCount() - 2);
    
    parse();
  }
  
  public Response(Response r)
  {
    index = index;
    size = size;
    buffer = buffer;
    type = type;
    tag = tag;
  }
  
  public static Response byeResponse(Exception ex)
  {
    String err = "* BYE JavaMail Exception: " + ex.toString();
    err = err.replace('\r', ' ').replace('\n', ' ');
    Response r = new Response(err);
    type |= 0x20;
    return r;
  }
  
  private void parse()
  {
    index = 0;
    if (buffer[index] == 43)
    {
      type |= 0x1;
      index += 1;
      return;
    }
    if (buffer[index] == 42)
    {
      type |= 0x3;
      index += 1;
    }
    else
    {
      type |= 0x2;
      tag = readAtom();
    }
    int mark = index;
    String s = readAtom();
    if (s == null) {
      s = "";
    }
    if (s.equalsIgnoreCase("OK")) {
      type |= 0x4;
    } else if (s.equalsIgnoreCase("NO")) {
      type |= 0x8;
    } else if (s.equalsIgnoreCase("BAD")) {
      type |= 0xC;
    } else if (s.equalsIgnoreCase("BYE")) {
      type |= 0x10;
    } else {
      index = mark;
    }
    pindex = index;
  }
  
  public void skipSpaces()
  {
    while ((index < size) && (buffer[index] == 32)) {
      index += 1;
    }
  }
  
  public void skipToken()
  {
    while ((index < size) && (buffer[index] != 32)) {
      index += 1;
    }
  }
  
  public void skip(int count)
  {
    index += count;
  }
  
  public byte peekByte()
  {
    if (index < size) {
      return buffer[index];
    }
    return 0;
  }
  
  public byte readByte()
  {
    if (index < size) {
      return buffer[(index++)];
    }
    return 0;
  }
  
  public String readAtom()
  {
    return readAtom('\000');
  }
  
  public String readAtom(char delim)
  {
    skipSpaces();
    if (index >= size) {
      return null;
    }
    int start = index;
    byte b;
    while ((index < size) && ((b = buffer[index]) > 32) && (b != 40) && (b != 41) && (b != 37) && (b != 42) && (b != 34) && (b != 92) && (b != Byte.MAX_VALUE) && ((delim == 0) || (b != delim))) {
      index += 1;
    }
    return ASCIIUtility.toString(buffer, start, index);
  }
  
  public String readString(char delim)
  {
    skipSpaces();
    if (index >= size) {
      return null;
    }
    int start = index;
    while ((index < size) && (buffer[index] != delim)) {
      index += 1;
    }
    return ASCIIUtility.toString(buffer, start, index);
  }
  
  public String[] readStringList()
  {
    skipSpaces();
    if (buffer[index] != 40) {
      return null;
    }
    index += 1;
    
    Vector v = new Vector();
    do
    {
      v.addElement(readString());
    } while (buffer[(index++)] != 41);
    int size = v.size();
    if (size > 0)
    {
      String[] s = new String[size];
      v.copyInto(s);
      return s;
    }
    return null;
  }
  
  public int readNumber()
  {
    skipSpaces();
    
    int start = index;
    while ((index < size) && (Character.isDigit((char)buffer[index]))) {
      index += 1;
    }
    if (index > start) {
      try
      {
        return ASCIIUtility.parseInt(buffer, start, index);
      }
      catch (NumberFormatException nex) {}
    }
    return -1;
  }
  
  public long readLong()
  {
    skipSpaces();
    
    int start = index;
    while ((index < size) && (Character.isDigit((char)buffer[index]))) {
      index += 1;
    }
    if (index > start) {
      try
      {
        return ASCIIUtility.parseLong(buffer, start, index);
      }
      catch (NumberFormatException nex) {}
    }
    return -1L;
  }
  
  public String readString()
  {
    return (String)parseString(false, true);
  }
  
  public ByteArrayInputStream readBytes()
  {
    ByteArray ba = readByteArray();
    if (ba != null) {
      return ba.toByteArrayInputStream();
    }
    return null;
  }
  
  public ByteArray readByteArray()
  {
    if (isContinuation())
    {
      skipSpaces();
      return new ByteArray(buffer, index, size - index);
    }
    return (ByteArray)parseString(false, false);
  }
  
  public String readAtomString()
  {
    return (String)parseString(true, true);
  }
  
  private Object parseString(boolean parseAtoms, boolean returnString)
  {
    skipSpaces();
    
    byte b = buffer[index];
    if (b == 34)
    {
      index += 1;
      int start = index;
      int copyto = index;
      while ((b = buffer[index]) != 34)
      {
        if (b == 92) {
          index += 1;
        }
        if (index != copyto) {
          buffer[copyto] = buffer[index];
        }
        copyto++;
        index += 1;
      }
      index += 1;
      if (returnString) {
        return ASCIIUtility.toString(buffer, start, copyto);
      }
      return new ByteArray(buffer, start, copyto - start);
    }
    if (b == 123)
    {
      int start = ++index;
      while (buffer[index] != 125) {
        index += 1;
      }
      int count = 0;
      try
      {
        count = ASCIIUtility.parseInt(buffer, start, index);
      }
      catch (NumberFormatException nex)
      {
        return null;
      }
      start = index + 3;
      index = (start + count);
      if (returnString) {
        return ASCIIUtility.toString(buffer, start, start + count);
      }
      return new ByteArray(buffer, start, count);
    }
    if (parseAtoms)
    {
      int start = index;
      
      String s = readAtom();
      if (returnString) {
        return s;
      }
      return new ByteArray(buffer, start, index);
    }
    if ((b == 78) || (b == 110))
    {
      index += 3;
      return null;
    }
    return null;
  }
  
  public int getType()
  {
    return type;
  }
  
  public boolean isContinuation()
  {
    return (type & 0x3) == 1;
  }
  
  public boolean isTagged()
  {
    return (type & 0x3) == 2;
  }
  
  public boolean isUnTagged()
  {
    return (type & 0x3) == 3;
  }
  
  public boolean isOK()
  {
    return (type & 0x1C) == 4;
  }
  
  public boolean isNO()
  {
    return (type & 0x1C) == 8;
  }
  
  public boolean isBAD()
  {
    return (type & 0x1C) == 12;
  }
  
  public boolean isBYE()
  {
    return (type & 0x1C) == 16;
  }
  
  public boolean isSynthetic()
  {
    return (type & 0x20) == 32;
  }
  
  public String getTag()
  {
    return tag;
  }
  
  public String getRest()
  {
    skipSpaces();
    return ASCIIUtility.toString(buffer, index, size);
  }
  
  public void reset()
  {
    index = pindex;
  }
  
  public String toString()
  {
    return ASCIIUtility.toString(buffer, 0, size);
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.Response
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

public abstract interface ResponseHandler
{
  public abstract void handleResponse(Response paramResponse);
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.ResponseHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.iap;

import com.sun.mail.util.ASCIIUtility;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ResponseInputStream
{
  private static final int minIncrement = 256;
  private static final int maxIncrement = 262144;
  private static final int incrementSlop = 16;
  private BufferedInputStream bin;
  
  public ResponseInputStream(InputStream in)
  {
    bin = new BufferedInputStream(in, 2048);
  }
  
  public ByteArray readResponse()
    throws IOException
  {
    return readResponse(null);
  }
  
  public ByteArray readResponse(ByteArray ba)
    throws IOException
  {
    if (ba == null) {
      ba = new ByteArray(new byte['?'], 0, 128);
    }
    byte[] buffer = ba.getBytes();
    int idx = 0;
    for (;;)
    {
      int b = 0;
      boolean gotCRLF = false;
      while ((!gotCRLF) && ((b = bin.read()) != -1))
      {
        switch (b)
        {
        case 10: 
          if ((idx > 0) && (buffer[(idx - 1)] == 13)) {
            gotCRLF = true;
          }
          break;
        }
        if (idx >= buffer.length)
        {
          int incr = buffer.length;
          if (incr > 262144) {
            incr = 262144;
          }
          ba.grow(incr);
          buffer = ba.getBytes();
        }
        buffer[(idx++)] = ((byte)b);
      }
      if (b == -1) {
        throw new IOException();
      }
      if ((idx < 5) || (buffer[(idx - 3)] != 125)) {
        break;
      }
      for (int i = idx - 4; i >= 0; i--) {
        if (buffer[i] == 123) {
          break;
        }
      }
      if (i < 0) {
        break;
      }
      int count = 0;
      try
      {
        count = ASCIIUtility.parseInt(buffer, i + 1, idx - 3);
      }
      catch (NumberFormatException e)
      {
        break;
      }
      if (count > 0)
      {
        int avail = buffer.length - idx;
        if (count + 16 > avail)
        {
          ba.grow(256 > count + 16 - avail ? 256 : count + 16 - avail);
          
          buffer = ba.getBytes();
        }
        while (count > 0)
        {
          int actual = bin.read(buffer, idx, count);
          count -= actual;
          idx += actual;
        }
      }
    }
    ba.setCount(idx);
    return ba;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.iap.ResponseInputStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.imap;

public class ACL
  implements Cloneable
{
  private String name;
  private Rights rights;
  
  public ACL(String name)
  {
    this.name = name;
    rights = new Rights();
  }
  
  public ACL(String name, Rights rights)
  {
    this.name = name;
    this.rights = rights;
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setRights(Rights rights)
  {
    this.rights = rights;
  }
  
  public Rights getRights()
  {
    return rights;
  }
  
  public Object clone()
    throws CloneNotSupportedException
  {
    ACL acl = (ACL)super.clone();
    rights = ((Rights)rights.clone());
    return acl;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.imap.ACL
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.imap;

public class AppendUID
{
  public long uidvalidity = -1L;
  public long uid = -1L;
  
  public AppendUID(long uidvalidity, long uid)
  {
    this.uidvalidity = uidvalidity;
    this.uid = uid;
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.imap.AppendUID
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.imap;

import com.sun.mail.iap.ProtocolException;
import com.sun.mail.imap.protocol.IMAPProtocol;

class DefaultFolder$1
  implements IMAPFolder.ProtocolCommand
{
  private final DefaultFolder this$0;
  
  DefaultFolder$1(DefaultFolder paramDefaultFolder, String paramString)
    throws ProtocolException
  {}
  
  public Object doCommand(IMAPProtocol p)
    throws ProtocolException
  {
    return p.list("", val$pattern);
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.imap.DefaultFolder.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.imap;

import com.sun.mail.iap.ProtocolException;
import com.sun.mail.imap.protocol.IMAPProtocol;

class DefaultFolder$2
  implements IMAPFolder.ProtocolCommand
{
  private final DefaultFolder this$0;
  
  DefaultFolder$2(DefaultFolder paramDefaultFolder, String paramString)
    throws ProtocolException
  {}
  
  public Object doCommand(IMAPProtocol p)
    throws ProtocolException
  {
    return p.lsub("", val$pattern);
  }
}

/* Location:
 * Qualified Name:     com.sun.mail.imap.DefaultFolder.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package com.sun.mail.imap;

import com.sun.mail.iap.ProtocolException;
import com.sun.mail.imap.protocol.IMAPProtocol;
import com.sun.mail.imap.protocol.ListInfo;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.MethodNotSupportedException;

public c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd