// 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: smtpMail.java
import java.io.*;
import java.net.Socket;
import java.util.*;
public class smtpMail
{
public smtpMail()
{
DELIMETER = "";
SEPARATOR = "";
so = null;
recv = null;
send = null;
from = "";
to = "";
domain = "";
x_set = new Vector();
body = new Vector();
attach = new Vector();
DELIMETER = getId();
SEPARATOR = System.getProperty("file.separator");
}
private String getId()
{
String s = "";
long l = System.currentTimeMillis();
Random random = new Random();
s = String.valueOf(l);
for(int i = 1; i <= 6; i++)
s = s + (int)(1.0D + 6D * random.nextDouble());
return s;
}
public int open(String s, int i)
{
try
{
so = new Socket(s, i);
send = new PrintWriter(so.getOutputStream(), true);
recv = new BufferedReader(new InputStreamReader(so.getInputStream()));
String s1 = recv.readLine();
char c = s1.charAt(0);
if((c == '4') | (c == '5'))
return 0;
}
catch(Exception _ex)
{
return 0;
}
return 1;
}
private int sendString(String s)
{
String s1 = "";
try
{
send.println(s);
s1 = recv.readLine();
}
catch(Exception _ex)
{
return 0;
}
if(s1.length() == 0)
return 0;
char c = s1.charAt(0);
return !((c == '4') | (c == '5')) ? 1 : 0;
}
public void setDomain(String s)
{
domain = s;
}
public void addHeader(String s, String s1)
{
x_set.addElement(s);
x_set.addElement(s1);
}
public void removeHeader(String s)
{
int i = x_set.indexOf(s);
if(i >= 0)
{
x_set.removeElementAt(i + 1);
x_set.removeElementAt(i);
}
}
public void clearHeaders()
{
x_set.removeAllElements();
}
public void setFrom(String s)
{
from = s;
x_set.addElement("From");
x_set.addElement(s);
}
public void setTo(String s)
{
to = s;
x_set.addElement("To");
x_set.addElement(s);
}
public void clearData()
{
body.removeAllElements();
}
public void clearAttachment()
{
attach.removeAllElements();
}
public void addData(String s)
{
body.addElement("1");
body.addElement(s);
}
public void addTextFile(String s)
{
body.addElement("2");
body.addElement(s);
}
public void addAttachment(String s)
{
attach.addElement(s);
}
public int transmit()
{
boolean flag = true;
if(domain.length() != 0)
{
int i = sendString("HELO " + domain);
if(i != 1)
return 0;
}
if(from.length() != 0)
{
int j = sendString("MAIL FROM:" + from);
if(j != 1)
return 0;
}
if(to.length() != 0)
{
int k = sendString("RCPT TO:" + to);
if(k != 1)
return 0;
}
if(sendString("DATA") != 1)
return 0;
for(int l = 0; l < x_set.size(); l += 2)
{
String s = (String)x_set.elementAt(l);
send.println(s + ": " + x_set.elementAt(l + 1));
}
if(x_set.indexOf("Date") < 0)
send.println("Date: " + (new Date()).toString());
if(x_set.indexOf("Mime-Version") < 0)
send.println("Mime-Version: 1.0");
send.println("X-Mailer: ColdJava 1999 ver 1.2");
if(attach.size() > 0)
send.println("Content-Type: MULTIPART/mixed; BOUNDARY=" + DELIMETER);
try
{
send.print("\n\n");
int i1 = 0;
if(attach.size() > 0)
{
send.println("--" + DELIMETER);
send.println("Content-Type: TEXT/plain;");
send.print("\n");
}
for(; i1 < body.size(); i1 += 2)
{
String s1 = (String)body.elementAt(i1);
if(s1.compareTo("1") == 0)
send.println((String)body.elementAt(i1 + 1));
else
if(s1.compareTo("2") == 0)
sendTextFile((String)body.elementAt(i1 + 1));
}
for(int j1 = 0; j1 < attach.size(); j1++)
sendBinaryFile((String)attach.elementAt(j1));
if(attach.size() > 0)
send.println("--" + DELIMETER + "--");
return sendString("\n.\n");
}
catch(Exception _ex)
{
return 0;
}
}
private void sendTextFile(String s)
{
try
{
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(new FileInputStream(s)));
String s1;
while((s1 = bufferedreader.readLine()) != null)
send.println(s1);
bufferedreader.close();
return;
}
catch(Exception _ex)
{
return;
}
}
private void sendBinaryFile(String s)
{
byte abyte0[] = new byte[48];
boolean flag = true;
String s1 = s;
try
{
DataInputStream datainputstream = new DataInputStream(new FileInputStream(s));
int i = s.lastIndexOf(SEPARATOR);
if(i >= 0)
s1 = s1.substring(i + 1);
send.println("--" + DELIMETER);
send.println("Content-Type: APPLICATION/octet-stream; name=\"" + s1 + "\";");
send.println("Content-Transfer-Encoding: BASE64");
send.println("Content-Description: " + s1);
send.print("\n");
while(flag)
{
int j = datainputstream.available();
int k;
if(j >= abyte0.length)
{
k = datainputstream.read(abyte0, 0, abyte0.length);
}
else
{
k = j;
datainputstream.readFully(abyte0, 0, k);
flag = false;
}
send.println(encode(abyte0, k));
}
datainputstream.close();
return;
}
catch(Exception _ex)
{
return;
}
}
private String toBinaryString(byte byte0)
{
byte byte1 = byte0;
String s = Integer.toBinaryString(byte1);
if(byte1 < 0)
s = s.substring(s.length() - 8);
for(; s.length() < 8; s = "0" + s);
return s;
}
private String encode(byte abyte0[], int i)
{
StringBuffer stringbuffer = new StringBuffer();
for(int j = 0; j < i; j += 3)
if(j + 2 < i)
{
String s = toBinaryString(abyte0[j]) + toBinaryString(abyte0[j + 1]) + toBinaryString(abyte0[j + 2]);
stringbuffer.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(Integer.parseInt("00" + s.substring(0, 6), 2)));
stringbuffer.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(Integer.parse