Java Design Antivirus Email program

Source: Internet
Author: User
Tags command line mail socket mail account webmail server

The operations of both programs are simple. These two programs are called VIRPRO01A and virpro01b, respectively, and correspond to program A and program B in the hypothetical scenario discussed above.

Program VIRPRO01A

The VIRPRO01A program is designed to take the POP3 e-mail server as a public email server (a secret e-mail account server can be of any type, for example, it can be a typical webmail server). This program uses the SDK 1.4.2 test to pass under WinXP.

Instance variables

The beginning of the VIRPRO01A class defines a list of instance variables:

class VirPro01a extends Frame{
String dataPath = "./Messages/";
int numberMsgs = 0;
int msgCounter = 0;
int msgNumber;
String uidl = "";//唯一的POP3消息ID
BufferedReader inputStream;
PrintWriter outputStream;
Socket socket;
String pathFileName;

The datapath variable contains a pointer to a local working folder that stores messages waiting for the virus to be scanned and forwarded to a secret e-mail account.

You may want to use another different folder. If you need to do this, simply provide the path and folder name (as a string). As you can see, my working folder is called messages, which is specified with the relative path of the folder that contains the program's class files. You can also use absolute paths.

The remaining instance variables are simple work variables that the program uses for different purposes.

Main method

The following main method confirms the correct number of command-line arguments and uses these parameters to instantiate an object of the virpro01a class.

public static void main(String[] args){
 if(args.length != 3){
  System.out.println("Usage: java VirPro01a "+ "pubServer userName password");
  System.exit(0);
 }// if结束
 new VirPro01a(args[0],args[1],args[2]);
}// main结束

Constructors

Its constructor is as follows:

virpro01a (String server,string userName, string password) {
int port = $//POP3 Mail Port
try{
//Get socket, even A specific port to a specific server
Socket = new socket (server,port);
//Get input stream from socket
InputStream = new BufferedReader (new InputStreamReader (Socket.getinputstream ()));
//Get output stream from socket
OutputStream = new PrintWriter (New OutputStreamWriter (Socket.getoutputstream ()), true);
// Displays the message received from the server on the command line screen after the connection
String connectmsg = Validateoneline ();
System.out.println ("Connected to Server" + connectmsg);
//The communication process is now in a authorization state. Send the user name and password to the server. The
//command is sent in plaintext, uppercase. The command is followed by a parameter. Send a command.
Outputstream.println ("USER" + userName);
//Gets the response and confirms that the response is +ok rather than-err.
String userresponse = Validateoneline ();
//Display response on command line screen
System.out.println ("USER" + userresponse);
Send the password to the server
Outputstream.println ("pass" + password);
Verify that the server's response is +ok. Displays the response in the procedure.
System.out.println ("Pass" + validateoneline ());
}catch (Exception e) {e.printstacktrace ();}

The code above establishes a communication path with the public e-mail server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.