📄 pop3.jad
字号:
// Decompiled by Jad v1.5.7. Copyright 1997-99 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name: pop3.java
import java.io.*;
import java.net.Socket;
import java.util.*;
import popStatus;
public class pop3
{
protected final int AUTHORIZATION = 1;
protected final int TRANSACTION = 2;
protected final int UPDATE = 3;
protected int _TotalMsgs;
protected int _TotalSize;
protected boolean _StatusOK;
protected int State;
protected String LastCmd;
protected String Host;
protected int Port;
protected String User;
protected String Password;
protected Socket server;
protected BufferedReader serverInputStream;
protected DataOutputStream serverOutputStream;
private boolean debugOn;
public pop3(String s, String s1, String s2)
{
_StatusOK = false;
Port = 110;
debugOn = false;
Host = s;
User = s1;
Password = s2;
}
public pop3()
{
_StatusOK = false;
Port = 110;
debugOn = false;
}
public popStatus connect(String s)
{
Host = s;
return connect();
}
public popStatus connect(String s, int i)
{
Host = s;
Port = i;
return connect();
}
public synchronized popStatus connect()
{
popStatus popstatus = new popStatus();
debug("Connecting to " + Host + " at port " + Port);
if(Host == null)
{
popstatus._Response = "-ERR Host not specified";
popstatus._OK = false;
return popstatus;
}
try
{
server = new Socket(Host, Port);
if(server == null)
{
debug("-ERR Error while connecting to POP3 server");
popstatus._OK = false;
popstatus._Response = "-ERR Error while connecting to POP3 server";
}
else
{
debug("Connected");
serverInputStream = new BufferedReader(new InputStreamReader(server.getInputStream()));
if(serverInputStream == null)
{
debug("Failed to setup an input stream.");
popstatus._OK = false;
popstatus._Response = "-ERR Error setting up input stream";
server = null;
}
serverOutputStream = new DataOutputStream(server.getOutputStream());
if(serverOutputStream == null)
{
debug("Failed to setup an output stream.");
popstatus._OK = false;
popstatus._Response = "-ERR Error setting up output stream";
server = null;
}
}
}
catch(Exception exception)
{
String s = "Exception! " + exception.toString();
debug(s);
popstatus._OK = false;
popstatus._Response = s;
server = null;
}
if(server != null)
{
popstatus._OK = true;
_StatusOK = true;
popstatus._Response = recv();
Parse(popstatus, 2);
debug("Response=" + popstatus._Response);
}
if(popstatus._OK)
State = 1;
return popstatus;
}
public popStatus login(String s, String s1)
{
User = s;
Password = s1;
return login();
}
public synchronized popStatus login()
{
popStatus popstatus = new popStatus();
if(User == null || Password == null)
{
popstatus._Response = "-ERR Userid or Password not specified";
return popstatus;
}
if(server != null)
{
send("USER " + User);
popstatus._Response = recv();
Parse(popstatus, 1);
if(popstatus._OK)
{
send("PASS " + Password);
popstatus._Response = recv();
Parse(popstatus, 1);
if(popstatus._OK)
{
State = 2;
stat();
}
}
}
return popstatus;
}
public synchronized void close()
{
debug("Closing socket");
try
{
server.close();
State = 0;
return;
}
catch(IOException _ex)
{
debug("Failure in server.close()");
}
}
public synchronized popStatus stat()
{
popStatus popstatus = new popStatus();
if(State != 2)
{
popstatus._Response = "-ERR Server not in transaction mode";
return popstatus;
}
send("STAT");
popstatus._Response = recv();
String as[] = Parse(popstatus, 4);
if(popstatus._OK)
{
_TotalMsgs = Convert.toInt(as[1]);
_TotalSize = Convert.toInt(as[2]);
}
return popstatus;
}
public synchronized popStatus quit()
{
popStatus popstatus = new popStatus();
send("QUIT");
State = 3;
popstatus._Response = recv();
Parse(popstatus, 2);
close();
return popstatus;
}
public synchronized popStatus list(int i)
{
popStatus popstatus = new popStatus();
send("LIST " + i);
popstatus._Response = recv();
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus list()
{
popStatus popstatus = new popStatus();
send("LIST");
recvN(popstatus);
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus uidl(int i)
{
popStatus popstatus = new popStatus();
send("UIDL " + i);
popstatus._Response = recv();
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus uidl()
{
popStatus popstatus = new popStatus();
send("UIDL");
recvN(popstatus);
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus retr(int i)
{
popStatus popstatus = new popStatus();
send("RETR " + i);
recvN(popstatus);
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus top(int i, int j)
{
popStatus popstatus = new popStatus();
send("TOP " + i + " " + j);
recvN(popstatus);
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus dele(int i)
{
popStatus popstatus = new popStatus();
send("DELE " + i);
popstatus._Response = recv();
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus rset()
{
popStatus popstatus = new popStatus();
send("RSET");
popstatus._Response = recv();
Parse(popstatus, 2);
return popstatus;
}
public synchronized popStatus noop()
{
popStatus popstatus = new popStatus();
send("NOOP");
popstatus._Response = recv();
Parse(popstatus, 2);
return popstatus;
}
public int get_TotalMsgs()
{
return _TotalMsgs;
}
public int get_TotalSize()
{
return _TotalSize;
}
public synchronized popStatus appendFile(String s, int i)
{
popStatus popstatus = new popStatus();
send("RETR " + i);
recvN(popstatus);
Parse(popstatus, 2);
if(popstatus._OK)
{
RandomAccessFile randomaccessfile;
try
{
randomaccessfile = new RandomAccessFile(s, "rw");
}
catch(IOException _ex)
{
popstatus._OK = false;
popstatus._Response = "-ERR File open failed";
return popstatus;
}
Date date = new Date();
String as[] = popstatus.Responses();
try
{
randomaccessfile.seek(randomaccessfile.length());
randomaccessfile.writeBytes("From - " + date.toString() + "\r\n");
for(int j = 0; j < as.length; j++)
randomaccessfile.writeBytes(as[j] + "\r\n");
randomaccessfile.close();
}
catch(IOException _ex)
{
popstatus._OK = false;
popstatus._Response = "-ERR File write failed";
return popstatus;
}
}
popstatus._OK = true;
return popstatus;
}
String[] Parse(popStatus popstatus, int i)
{
String as[] = null;
popstatus._OK = false;
String s = popstatus._Response;
if(s != null)
{
int j = 0;
if(s.trim().startsWith("+OK"))
popstatus._OK = true;
else
debug(s);
StringTokenizer stringtokenizer = new StringTokenizer(s);
int k;
if(i == -1)
k = stringtokenizer.countTokens();
else
k = i;
as = new String[k + 1];
for(; stringtokenizer.hasMoreTokens() && j < k; j++)
as[j] = new String(stringtokenizer.nextToken());
if(stringtokenizer.hasMoreTokens())
{
StringBuffer stringbuffer = new StringBuffer(stringtokenizer.nextToken());
for(; stringtokenizer.hasMoreTokens(); stringbuffer.append(" " + stringtokenizer.nextToken()));
as[k] = new String(stringbuffer);
}
}
return as;
}
void send(String s)
{
debug(">> " + s);
LastCmd = s;
try
{
serverOutputStream.writeBytes(s + "\r\n");
_StatusOK = true;
return;
}
catch(IOException _ex)
{
System.err.println("Caught exception while sending command to server");
_StatusOK = false;
return;
}
catch(Exception exception)
{
System.err.println("Send: Unexpected exception: " + exception.toString());
}
_StatusOK = false;
}
String recv()
{
String s = "";
if(!_StatusOK)
{
s = "-ERR Failed sending command to server";
return s;
}
try
{
s = serverInputStream.readLine();
debug("<<" + s);
}
catch(IOException _ex)
{
System.err.println("Caught exception while reading");
s = "-ERR Caught IOException while reading from server";
}
catch(Exception exception)
{
System.err.println("Unexpected exception: " + exception.toString());
s = "-ERR Unexpected exception while reading from server";
}
if(s == null)
{
debug("Read a null line from server");
s = "-ERR <NULL>";
}
if(s.trim().startsWith("-ERR"))
{
debug("Result from server has error!");
debug("Sent: '" + LastCmd + "'");
debug("Received: '" + s + "'");
return s;
}
if(s.trim().startsWith("+OK"))
{
return s;
}
else
{
debug("Received strange response");
debug("'" + s + "'");
s = "-ERR Invalid response";
return s;
}
}
void recvN(popStatus popstatus)
{
debug("entered recvN");
Vector vector = new Vector(100, 100);
String s = "";
try
{
boolean flag = false;
int i = 0;
while(!flag)
{
String s1 = serverInputStream.readLine();
i++;
debug("<<" + s1.length() + " '" + s1 + "'");
if(i == 1)
{
if(s1.trim().startsWith("-ERR "))
{
debug("Result from server has error!");
debug("Sent: '" + LastCmd + "'");
debug("Received: '" + s1 + "'");
flag = true;
popstatus._Response = s1;
}
else
if(s1.trim().startsWith("+OK"))
{
popstatus._Response = s1;
}
else
{
debug("Received strange response");
debug("'" + s1 + "'");
flag = true;
popstatus._Response = "-ERR Invalid response";
}
}
else
if(s1.startsWith("."))
{
if(s1.length() == 1)
flag = true;
else
vector.addElement(s1.substring(1));
}
else
{
vector.addElement(s1);
}
}
}
catch(IOException _ex)
{
System.err.println("Caught exception while reading");
popstatus._Response = "-ERR Caught IOException while reading from server";
}
catch(Exception exception)
{
System.err.println("Unexpected exception: " + exception.toString());
popstatus._Response = "-ERR Unexpected exception while reading from server";
}
popstatus._Responses = new String[vector.size()];
vector.copyInto(popstatus._Responses);
}
public void setDebugOn(boolean flag)
{
debugOn = flag;
}
public void debug(String s)
{
if(debugOn)
System.err.println(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -