BrightSide Workbench Full Report + Source Code
org.turro.elephant.james.JamesRemoteManager Class Reference

Public Member Functions

 JamesRemoteManager (String mailHost, int port, String user, String password)
 
String execute (JamesCommand command)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 35 of file JamesRemoteManager.java.

Constructor & Destructor Documentation

◆ JamesRemoteManager()

org.turro.elephant.james.JamesRemoteManager.JamesRemoteManager ( String  mailHost,
int  port,
String  user,
String  password 
)

Definition at line 40 of file JamesRemoteManager.java.

40  {
41  this.mailHost = mailHost;
42  this.port = port;
43  this.user = user;
44  this.password = password;
45  }

Member Function Documentation

◆ execute()

String org.turro.elephant.james.JamesRemoteManager.execute ( JamesCommand  command)

Definition at line 47 of file JamesRemoteManager.java.

47  {
48  String returnString = "An unknown error has occurred.";
49  try {
50  Socket socket = new Socket(mailHost, port);
51  InputStream is = socket.getInputStream();
52  InputStreamReader isr = new InputStreamReader(is);
53  BufferedReader br = new BufferedReader(isr);
54  OutputStream os = socket.getOutputStream();
55  OutputStreamWriter osw = new OutputStreamWriter(os);
56  BufferedWriter bw = new BufferedWriter(osw);
57 
58  String total = "";
59  String line = "";
60  String infoString = "OK: \r\n\r\n";
61 
62  while ((line = br.readLine()) != null) {
63  total += line;
64 
65  if (line.indexOf("id") != -1) {
66  //It wants a username.
67  bw.write(user);
68  bw.newLine();//Put in a new line.
69  bw.flush();
70  } else if (line.indexOf("Password") != -1) {
71  //It wants a password.
72  bw.write(password);
73  bw.newLine();//Put in a new line.
74  bw.flush();
75  }
76  if (line.indexOf("Welcome") != -1) {
77  //It wants the command.
78  bw.write(command.getCommand());
79  bw.newLine();//Put in a new line.
80  bw.flush();
81 
82  //Give James a head start.
83  //If James is slow in returning data, br.ready (below) won't be able to collect the status information
84  //from the command. 1.5 seconds should be enough of a delay to let James get a head start in sending back
85  //data. If necessary, increase this value.
86  Thread.sleep(3000);
87 
88  //Acquire resulting data.
89  while (br.ready()) {
90  infoString += br.readLine() + "\r\n";
91  }
92 
93  //And quit neatly.
94  bw.write("quit");
95  bw.newLine();//Put in a new line.
96  bw.flush();
97  }//end if Welcome
98 
99  }//end while
100 
101  returnString = (String) infoString;
102 
103  socket.close();
104 
105  Logger.getLogger(JamesRemoteManager.class.getName()).log(Level.INFO, returnString);
106 
107  }//end try
108  catch (Exception e) {
109  if (command.getCommand().equals("shutdown")) {
110  returnString = "OK: Shutdown";
111  } else {
112  Logger.getLogger(JamesRemoteManager.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(returnString), e);
113  }
114  }
115 
116  return returnString;
117 
118  }
JamesRemoteManager(String mailHost, int port, String user, String password)
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: