package Bean;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
public class SolBean
{
Connection con;
Statement stat;
ResultSet rset;
String mailid,key;
String tmid,tkey;
String sql;
public boolean checkAuth(String rmailid, String rkey)
{
int flag=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:smtpdsn");
stat = con.createStatement();
sql = "Select * from smtpkey where mailid='"+rmailid+"' and authkey='"+rkey+"'";
rset = stat.executeQuery(sql);
while(rset.next())
flag = 1;
if(flag != 1)
return false;
else
return true;
}catch(SQLException se)
{
System.out.println(se);
}
catch(ClassNotFoundException ce)
{
System.out.println(ce);
}
return false;
}
public boolean checkVerify(String rmailid)
{
int flag=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:smtpdsn");
stat = con.createStatement();
sql = "Select * from smtpkey where mailid='"+rmailid+"'";
rset = stat.executeQuery(sql);
while(rset.next())
flag = 1;
if(flag == 0)
return false;
else
return true;
}catch(SQLException se)
{
System.out.println(se);
}
catch(ClassNotFoundException ce)
{
System.out.println(ce);
}
return false;
}
public int checkProcess(Vector cmdlist)
{
int i;
String temp;
String tstr=null;
Vector finalcmdlist = new Vector();
Vector finalrlist = new Vector();
String acmdlist[];
acmdlist = new String[cmdlist.size()];
cmdlist.copyInto(acmdlist);
for(i=0;i
if(acmdlist[i].length() <= 4)
continue;
tstr = acmdlist[i].substring(0,4).trim();
tmid = acmdlist[i].substring(5).trim();
System.out.println("Cmd:"+tstr+" id:"+tmid);
if(tstr.equals("VRFY"))
{
System.out.println("inside vrfy");
boolean result = checkVerify(tmid);
System.out.println("Result : 1 "+result);
if(result == true)
{
System.out.println("ID OK");
tstr = acmdlist[++i].substring(0,4).trim();
tkey = acmdlist[i].substring(5).trim();
System.out.println("Cmd :"+tstr);
System.out.println("key:"+tkey);
if(tstr.equals("AUTH"))
{
if(checkAuth(tmid,tkey))
System.out.println("Authentication key Correct");
else
{
System.out.println("Authentication key Not Correct");
return 3; // auth key incorrect
}
}
else
{
System.out.println("Authentication key not available");
return 2; // auth key not submitted
}
}
else
return 1; // verify failure
}
}
finalrlist = rcptFilter(cmdlist);
finalcmdlist = makeCmdlist(cmdlist,finalrlist);
System.out.println("Final command list");
for(i=0;i
temp = (String) finalcmdlist.get(i);
System.out.println(i+"->"+temp);
}
sendMail(finalcmdlist);
return 0;
}
public Vector makeCmdlist(Vector cmdlist,Vector finalrlist)
{
int i,j;
String tstr=null,str=null;
Vector finalcmdlist = new Vector();
String acmdlist[] = new String[cmdlist.size()];
cmdlist.copyInto(acmdlist);
finalcmdlist.addElement(acmdlist[0]);
finalcmdlist.addElement(acmdlist[1]);
for(i=0;i
tstr = (String) finalrlist.get(i);
finalcmdlist.addElement(tstr);
}
System.out.println("loop 1 : "+finalcmdlist.size());
for(i=2;i
str = acmdlist[i];
if(str.equals("DATA"))
break;
}
System.out.println("loop 2 : "+finalcmdlist.size());
finalcmdlist.addElement(str);
for(;i
System.out.println("loop 3 : "+finalcmdlist.size());
return finalcmdlist;
}
public Vector rcptFilter(Vector cmdlist)
{
int i,j;
String temp,prv;
String tstr=null,str=null;
String srlist[];
Vector rlist = new Vector();
Vector finalrlist = new Vector();
String acmdlist[] = new String[cmdlist.size()];
cmdlist.copyInto(acmdlist);
for(i=0;i
str = acmdlist[i];
if(acmdlist[i].length() <= 4)
continue;
tstr = acmdlist[i].substring(0,4).trim();
if(tstr.equals("RCPT"))
rlist.addElement(str);
}
srlist = new String[rlist.size()];
rlist.copyInto(srlist);
for(i=0;i
{
temp = srlist[i];
srlist[i] = srlist[j];
srlist[j] = temp;
}
// System.out.println("Sorted Mail List");
// for(i=0;i
prv = "";
for(i=0;i
if(!prv.equalsIgnoreCase(srlist[i]))
{
prv = srlist[i];
finalrlist.addElement(prv);
}
}
if(!prv.equalsIgnoreCase(srlist[i]))
finalrlist.addElement(srlist[i]);
/* System.out.println("Final Mail List");
for(i=0;i
temp = (String) finalrlist.get(i);
System.out.println(i+"->"+temp);
}*/
return (finalrlist);
}
public void sendMail(Vector finalcmdlist)
{
String cmd=null;
int i;
Socket sock;
try
{
sock = new Socket("127.0.0.1",25);
System.out.println("Conn");
BufferedReader br =
new BufferedReader(new InputStreamReader(sock.getInputStream()));
PrintStream ps = new PrintStream(sock.getOutputStream());
for(i=0;i
cmd = (String) finalcmdlist.get(i);
ps.println(cmd);
// System.out.println("ms : "+cmd);
}
ps.close();
sock.close();
}catch(Exception e)
{
System.out.println("Error : "+e);
}
}
}
//FMsend
No comments:
Post a Comment