OSDN Git Service

Mail Destination Confirm Program(Beta) start
authortakuya-o <takuya-o>
Sun, 20 Feb 2005 23:44:04 +0000 (23:44 +0000)
committertakuya-o <takuya-o>
Sun, 20 Feb 2005 23:44:04 +0000 (23:44 +0000)
31 files changed:
BetaProject.jpr [new file with mode: 0644]
classes/BetaProject.cdi [new file with mode: 0644]
classes/DaemonProject.cdi [new file with mode: 0644]
classes/org/jent/checksmtp/Application$1.class [new file with mode: 0644]
classes/org/jent/checksmtp/Application.class [new file with mode: 0644]
classes/org/jent/checksmtp/ApplicationProperties.class [new file with mode: 0644]
classes/org/jent/checksmtp/LDAPSearch.class [new file with mode: 0644]
classes/org/jent/checksmtp/Processer.class [new file with mode: 0644]
classes/org/jent/checksmtp/SMTPclient.class [new file with mode: 0644]
classes/org/jent/checksmtp/SetupFrame.class [new file with mode: 0644]
classes/org/jent/checksmtp/SetupFrame_AboutBoxPanel1.class [new file with mode: 0644]
classes/org/jent/checksmtp/SmtpBufferedWriter.class [new file with mode: 0644]
classes/org/jent/checksmtp/SocketProxy.class [new file with mode: 0644]
classes/org/jent/checksmtp/ToListDialog$1.class [new file with mode: 0644]
classes/org/jent/checksmtp/ToListDialog$2.class [new file with mode: 0644]
classes/org/jent/checksmtp/ToListDialog$3.class [new file with mode: 0644]
classes/org/jent/checksmtp/ToListDialog.class [new file with mode: 0644]
deploy/CheckSMTP-0.1.jar [new file with mode: 0644]
deploy/CheckSMTP.jar [new file with mode: 0644]
deploy/mdc.jar [new file with mode: 0644]
src/mdc.deploy [new file with mode: 0644]
src/org/jent/checksmtp/Application.java [new file with mode: 0644]
src/org/jent/checksmtp/ApplicationProperties.java [new file with mode: 0644]
src/org/jent/checksmtp/LDAPSearch.java [new file with mode: 0644]
src/org/jent/checksmtp/Processer.java [new file with mode: 0644]
src/org/jent/checksmtp/SMTPclient.java [new file with mode: 0644]
src/org/jent/checksmtp/SetupFrame.java [new file with mode: 0644]
src/org/jent/checksmtp/SetupFrame_AboutBoxPanel1.java [new file with mode: 0644]
src/org/jent/checksmtp/SmtpBufferedWriter.java [new file with mode: 0644]
src/org/jent/checksmtp/SocketProxy.java [new file with mode: 0644]
src/org/jent/checksmtp/ToListDialog.java [new file with mode: 0644]

diff --git a/BetaProject.jpr b/BetaProject.jpr
new file mode 100644 (file)
index 0000000..1ce45b7
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version = '1.0' encoding = 'UTF-8'?>
+<jpr:project xmlns:jpr="http://xmlns.oracle.com/ide/project">
+   <hash n="component-versions">
+      <value n="oracle.adfdt.controller.struts.addin.StrutsProjectMigrator" v="10.1.3.0.2"/>
+      <value n="oracle.ide.model.Project" v="10.1.3.0.2"/>
+      <value n="oracle.jdeveloper.offlinedb.migration.OfflineDBProjectMigrator" v="10.1.3.0.2"/>
+      <value n="oracle.jdevimpl.jsp.JspMigrator" v="10.1.3.0.2"/>
+      <value n="oracle.jdevimpl.webservices.WebServicesMigratorHelper" v="10.1.3.0.2"/>
+   </hash>
+   <list n="contentSets">
+      <string v="oracle.jdeveloper.model.PathsConfiguration/javaContentSet"/>
+      <string v="oracle.jdeveloper.resources.ResourcePaths/resourcesContentSet"/>
+      <string v="oracle.jdeveloper.model.J2eeSettings/webContentSet"/>
+      <string v="oracle.jdeveloper.offlinedb.OfflineDBProjectSettings/offlineDBContentSet"/>
+      <string v="oracle.bm.commonIde.data.project.ModelerProjectSettings/modelersContentSet"/>
+   </list>
+   <hash n="oracle.bm.commonIde.data.project.ModelerProjectSettings">
+      <hash n="modelersContentSet">
+         <list n="url-path">
+            <url path="model/"/>
+         </list>
+      </hash>
+      <value n="modelersVersion" v="10.13"/>
+   </hash>
+   <hash n="oracle.jdeveloper.model.J2eeSettings">
+      <hash n="webContentSet">
+         <list n="url-path">
+            <url path="public_html/"/>
+         </list>
+      </hash>
+   </hash>
+   <hash n="oracle.jdeveloper.model.PathsConfiguration">
+      <hash n="javaContentSet">
+         <list n="pattern-filters">
+            <string v="+**"/>
+         </list>
+         <list n="url-path">
+            <url path="src/"/>
+         </list>
+      </hash>
+   </hash>
+   <hash n="oracle.jdeveloper.offlinedb.OfflineDBProjectSettings">
+      <hash n="offlineDBContentSet">
+         <list n="pattern-filters">
+            <string v="+**"/>
+         </list>
+         <list n="url-path">
+            <url path="database/"/>
+         </list>
+      </hash>
+   </hash>
+   <hash n="oracle.jdeveloper.resources.ResourcePaths">
+      <hash n="resourcesContentSet">
+         <list n="pattern-filters">
+            <string v="+*"/>
+         </list>
+         <list n="url-path">
+            <url path="."/>
+         </list>
+      </hash>
+   </hash>
+   <hash n="oracle.jdeveloper.runner.RunConfiguration">
+      <url n="targetURL" path="src/org/jent/checksmtp/Application.java"/>
+      <value n="VMName" v="client"/>
+   </hash>
+   <hash n="oracle.jdevimpl.config.JProjectPaths">
+      <url n="outputDirectory" path="classes/"/>
+   </hash>
+</jpr:project>
diff --git a/classes/BetaProject.cdi b/classes/BetaProject.cdi
new file mode 100644 (file)
index 0000000..ad4adbc
Binary files /dev/null and b/classes/BetaProject.cdi differ
diff --git a/classes/DaemonProject.cdi b/classes/DaemonProject.cdi
new file mode 100644 (file)
index 0000000..370feb1
Binary files /dev/null and b/classes/DaemonProject.cdi differ
diff --git a/classes/org/jent/checksmtp/Application$1.class b/classes/org/jent/checksmtp/Application$1.class
new file mode 100644 (file)
index 0000000..9974c40
Binary files /dev/null and b/classes/org/jent/checksmtp/Application$1.class differ
diff --git a/classes/org/jent/checksmtp/Application.class b/classes/org/jent/checksmtp/Application.class
new file mode 100644 (file)
index 0000000..d362921
Binary files /dev/null and b/classes/org/jent/checksmtp/Application.class differ
diff --git a/classes/org/jent/checksmtp/ApplicationProperties.class b/classes/org/jent/checksmtp/ApplicationProperties.class
new file mode 100644 (file)
index 0000000..4613907
Binary files /dev/null and b/classes/org/jent/checksmtp/ApplicationProperties.class differ
diff --git a/classes/org/jent/checksmtp/LDAPSearch.class b/classes/org/jent/checksmtp/LDAPSearch.class
new file mode 100644 (file)
index 0000000..e577fc0
Binary files /dev/null and b/classes/org/jent/checksmtp/LDAPSearch.class differ
diff --git a/classes/org/jent/checksmtp/Processer.class b/classes/org/jent/checksmtp/Processer.class
new file mode 100644 (file)
index 0000000..1bd6efb
Binary files /dev/null and b/classes/org/jent/checksmtp/Processer.class differ
diff --git a/classes/org/jent/checksmtp/SMTPclient.class b/classes/org/jent/checksmtp/SMTPclient.class
new file mode 100644 (file)
index 0000000..9f58ec2
Binary files /dev/null and b/classes/org/jent/checksmtp/SMTPclient.class differ
diff --git a/classes/org/jent/checksmtp/SetupFrame.class b/classes/org/jent/checksmtp/SetupFrame.class
new file mode 100644 (file)
index 0000000..365774d
Binary files /dev/null and b/classes/org/jent/checksmtp/SetupFrame.class differ
diff --git a/classes/org/jent/checksmtp/SetupFrame_AboutBoxPanel1.class b/classes/org/jent/checksmtp/SetupFrame_AboutBoxPanel1.class
new file mode 100644 (file)
index 0000000..196b0ac
Binary files /dev/null and b/classes/org/jent/checksmtp/SetupFrame_AboutBoxPanel1.class differ
diff --git a/classes/org/jent/checksmtp/SmtpBufferedWriter.class b/classes/org/jent/checksmtp/SmtpBufferedWriter.class
new file mode 100644 (file)
index 0000000..61fd4b4
Binary files /dev/null and b/classes/org/jent/checksmtp/SmtpBufferedWriter.class differ
diff --git a/classes/org/jent/checksmtp/SocketProxy.class b/classes/org/jent/checksmtp/SocketProxy.class
new file mode 100644 (file)
index 0000000..fea22bb
Binary files /dev/null and b/classes/org/jent/checksmtp/SocketProxy.class differ
diff --git a/classes/org/jent/checksmtp/ToListDialog$1.class b/classes/org/jent/checksmtp/ToListDialog$1.class
new file mode 100644 (file)
index 0000000..7901ca1
Binary files /dev/null and b/classes/org/jent/checksmtp/ToListDialog$1.class differ
diff --git a/classes/org/jent/checksmtp/ToListDialog$2.class b/classes/org/jent/checksmtp/ToListDialog$2.class
new file mode 100644 (file)
index 0000000..36d4990
Binary files /dev/null and b/classes/org/jent/checksmtp/ToListDialog$2.class differ
diff --git a/classes/org/jent/checksmtp/ToListDialog$3.class b/classes/org/jent/checksmtp/ToListDialog$3.class
new file mode 100644 (file)
index 0000000..c0f2924
Binary files /dev/null and b/classes/org/jent/checksmtp/ToListDialog$3.class differ
diff --git a/classes/org/jent/checksmtp/ToListDialog.class b/classes/org/jent/checksmtp/ToListDialog.class
new file mode 100644 (file)
index 0000000..54c783c
Binary files /dev/null and b/classes/org/jent/checksmtp/ToListDialog.class differ
diff --git a/deploy/CheckSMTP-0.1.jar b/deploy/CheckSMTP-0.1.jar
new file mode 100644 (file)
index 0000000..37df1e7
Binary files /dev/null and b/deploy/CheckSMTP-0.1.jar differ
diff --git a/deploy/CheckSMTP.jar b/deploy/CheckSMTP.jar
new file mode 100644 (file)
index 0000000..37df1e7
Binary files /dev/null and b/deploy/CheckSMTP.jar differ
diff --git a/deploy/mdc.jar b/deploy/mdc.jar
new file mode 100644 (file)
index 0000000..f2796e0
Binary files /dev/null and b/deploy/mdc.jar differ
diff --git a/src/mdc.deploy b/src/mdc.deploy
new file mode 100644 (file)
index 0000000..7adb3ee
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version = '1.0' encoding = 'UTF-8'?>
+<simple-archive-deployment nselem="simple-archive-deployment" class="oracle.jdeveloper.deploy.jar.ArchiveProfile" xmlns="http://xmlns.oracle.com/jdeveloper/10130/deploy/jar">
+   <archiveOptions>
+      <additionalManifests/>
+      <compressed>true</compressed>
+      <hasManifest>true</hasManifest>
+      <mainClass>org.jent.checksmtp.Application</mainClass>
+   </archiveOptions>
+   <fileGroups>
+      <groups>
+         <Item class="oracle.jdeveloper.deploy.common.PackagingFileGroup" internalName="project-output">
+            <contributors>
+               <Item type="2"/>
+               <Item type="7"/>
+            </contributors>
+            <displayName>Project Output</displayName>
+            <filters>
+               <rules>
+                  <Item type="1" pattern="**/CVS/"/>
+                  <Item type="1" pattern="**.cdi"/>
+                  <Item type="1" pattern="**.contrib"/>
+                  <Item type="1" pattern="**.keep"/>
+                  <Item type="1" pattern="**.rvi"/>
+                  <Item type="1" pattern=".jsps/"/>
+                  <Item type="1" pattern=".tags/"/>
+                  <Item type="1" pattern=".dtags/"/>
+                  <Item type="0" pattern="**"/>
+               </rules>
+            </filters>
+            <targetWithinJar/>
+         </Item>
+      </groups>
+   </fileGroups>
+   <jarURL path="../deploy/mdc.jar"/>
+   <profileDeps/>
+</simple-archive-deployment>
diff --git a/src/org/jent/checksmtp/Application.java b/src/org/jent/checksmtp/Application.java
new file mode 100644 (file)
index 0000000..972c836
--- /dev/null
@@ -0,0 +1,47 @@
+package org.jent.checksmtp;
+
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Toolkit;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.UIManager;
+
+
+public class Application {
+    public Application() {
+        Frame frame = new SetupFrame();
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        Dimension frameSize = frame.getSize();
+
+        if (frameSize.height > screenSize.height) {
+            frameSize.height = screenSize.height;
+        }
+
+        if (frameSize.width > screenSize.width) {
+            frameSize.width = screenSize.width;
+        }
+
+        frame.setLocation((screenSize.width - frameSize.width) / 2,
+            (screenSize.height - frameSize.height) / 2);
+        frame.addWindowListener(new WindowAdapter() {
+                public void windowClosing(WindowEvent e) {
+                    System.exit(0);
+                }
+            });
+        frame.setVisible(true);
+    }
+
+    public static void main(String[] args) {
+        try {
+            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        new SMTPclient();
+
+        //new Application();
+    }
+}
diff --git a/src/org/jent/checksmtp/ApplicationProperties.java b/src/org/jent/checksmtp/ApplicationProperties.java
new file mode 100644 (file)
index 0000000..522e33f
--- /dev/null
@@ -0,0 +1,165 @@
+package org.jent.checksmtp;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import java.util.Properties;
+
+
+/**
+ * <P>This class hold application properties.</P>
+ * <P>"$user.home/.checksmtp.properties" was used to stored data file.</P>
+ * <H3>Properties</H3>
+ * <DL>
+ * <DT> -.port       <DD>Service port number.       (Default:8725)
+ * <DT> -.serverHost <DD>STMP Server host name.     (Default:mail)
+ * <DT> -.serverPort <DD>STMP Server port.          (Default:25)
+ * <DT> -.ladp       <DD>If "true" use LDAP search. (Default:false)
+ * <DT> -.ldap.providerUrl <DD>LDAP Provider URL    (Default:ldap://localhost:389
+ * <DT> -.ldap.root  <DD>LDAP Search root           (Default:C=JP)
+ * <DT> -.ldap.isSjis<DD>Addhoc patch: When LDAP Server use SJIS, this propertiy set "true" (Default:false)
+ * <DT> -.ldap.attribues<DD>LDAP Search attribues separate by space (Defaut:cn)
+ * </DL>
+ */
+public class ApplicationProperties
+{
+  private static final String PREFIX = "org.jent.checksmtp";
+  private static final String SMTP_SERVER_HOST = PREFIX + ".serverHost";
+  private static final String SMTP_SERVER_PORT = PREFIX + ".serverPort";
+  private static final String SMTP_PORT = PREFIX + ".port";
+  private static final String LDAP_PREFIX = PREFIX + ".ldap";
+  private static final String LDAP_PROVIDER_URL = LDAP_PREFIX + ".providerUrl";
+  private static final String LDAP_ROOT = LDAP_PREFIX + ".root";
+  private static final String LDAP_IS_SJIS = LDAP_PREFIX + ".isSjis";
+  private static final String LDAP_IS_ATTRIBUTES = LDAP_PREFIX + ".attributes";
+
+  private static final String PROPERTIES_FILENAME = ".checksmtp.properties";
+
+  private static Properties applicationProperties = new Properties();
+
+  private static String fileName = PROPERTIES_FILENAME;
+
+  static {
+    try
+    {
+      //InputStream is = ApplicationProperties.class.getClassLoader().getResourceAsStream("checksmtp.properties");
+      fileName = System.getProperty("user.home") + File.separator + PROPERTIES_FILENAME;
+      FileInputStream is = new FileInputStream(fileName);
+      applicationProperties.load(is);
+      is.close();
+    }
+    catch (IOException e)
+    {
+      System.err.println("No checksmtp.properties in " + fileName);
+    }
+  }
+
+  private ApplicationProperties()
+  {
+  }
+
+  /**
+     * Application Properties Save
+     */
+  public static void save()
+  {
+    FileOutputStream fos;
+    try
+    {
+      fos = new FileOutputStream(fileName);
+      applicationProperties.store(fos, "Appliction Properties");
+      fos.close();
+    }
+    catch (IOException e)
+    {
+      System.err.println(fileName + "was occrred save error.");
+      e.printStackTrace();
+    }
+  }
+
+  public static String getSmtpServerHost()
+  {
+    return applicationProperties.getProperty(SMTP_SERVER_HOST, "mail");
+  }
+
+  public static void setSmtpServerHost(String obj)
+  {
+    applicationProperties.setProperty(SMTP_SERVER_HOST, obj);
+  }
+
+  public static int getSmtpServerPort()
+  {
+    return Integer.parseInt(applicationProperties.getProperty(SMTP_SERVER_PORT, "25"));
+  }
+
+  public static void setSmtpServerPort(int port)
+  {
+    applicationProperties.setProperty(SMTP_SERVER_PORT, new Integer(port).toString());
+  }
+
+  public static int getSmtpPort()
+  {
+    return Integer.parseInt(applicationProperties.getProperty(SMTP_PORT, "8725"));
+  }
+
+  public static void setSmtpPort(int port)
+  {
+    applicationProperties.setProperty(SMTP_PORT, new Integer(port).toString());
+  }
+
+  public static String getLdapProviderURL()
+  {
+    return applicationProperties.getProperty(LDAP_PROVIDER_URL, "ldap://localhost:389");
+  }
+
+  public static void setLdapProviderURL(String obj)
+  {
+    applicationProperties.setProperty(LDAP_PROVIDER_URL, obj);
+  }
+
+  public static String getLdapRoot()
+  {
+    return applicationProperties.getProperty(LDAP_ROOT, "C=JP");
+  }
+
+  public static void setLdapRoot(String obj)
+  {
+    applicationProperties.setProperty(LDAP_ROOT, obj);
+  }
+
+  public static boolean getLdapIsSjis()
+  {
+    return new Boolean(applicationProperties.getProperty(LDAP_IS_SJIS)).booleanValue();
+  }
+
+  public static void setLdapRoot(boolean obj)
+  {
+    applicationProperties.setProperty(LDAP_IS_SJIS, Boolean.toString(obj));
+  }
+
+  public static boolean getLdap()
+  {
+    String str = applicationProperties.getProperty(LDAP_PREFIX);
+    Boolean flg = new Boolean(str);
+    return flg.booleanValue();
+  }
+
+  public static void setLdap(boolean obj)
+  {
+    applicationProperties.setProperty(LDAP_PREFIX, Boolean.toString(obj));
+  }
+
+  public static String getLdapAttributes()
+  {
+    return applicationProperties.getProperty(LDAP_IS_ATTRIBUTES, "cn");
+  }
+
+  public static void setLdapAttributes(String obj)
+  {
+    applicationProperties.setProperty(LDAP_IS_ATTRIBUTES, obj);
+  }
+
+}
diff --git a/src/org/jent/checksmtp/LDAPSearch.java b/src/org/jent/checksmtp/LDAPSearch.java
new file mode 100644 (file)
index 0000000..0a7a3ab
--- /dev/null
@@ -0,0 +1,106 @@
+package org.jent.checksmtp;
+
+import java.io.UnsupportedEncodingException;
+
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+
+public class LDAPSearch {
+  static private InitialDirContext ctx = null;
+  static private String lastProviderUrl = null;
+
+  private LDAPSearch() {
+  }
+
+  static private void init() {
+    if ( !ApplicationProperties.getLdap() ) {
+      //InitialDirContext
+      lastProviderUrl = ApplicationProperties.getLdapProviderURL();
+      Properties env = new Properties();
+      env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+                      "com.sun.jndi.ldap.LdapCtxFactory");
+      env.put(Context.PROVIDER_URL, lastProviderUrl);
+  
+      try {
+        ctx = new InitialDirContext(env);
+      } catch (NamingException e) {
+        System.err.println("LDAPSearch init error.");
+        e.printStackTrace();
+      }
+    }
+  }
+  
+  public static String search(String mail) {
+    String ans = "";
+
+    if (!ApplicationProperties.getLdap()) {
+        return ans;
+    }
+    synchronized (LDAPSearch.class ) {
+      //not initialized ctx or LDAP Provider URL was changed.
+      if ( ctx==null 
+      || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) {
+        init();
+      }
+    }
+    
+    Pattern pattern = Pattern.compile("[ \t]+"); //Attributes separate by space.
+    String[] attrNames = pattern.split(ApplicationProperties.getLdapAttributes());
+
+    System.err.println("LDAP Serarch= " + mail + " " + attrNames[0]);
+
+    SearchControls ctrl = new SearchControls();
+    ctrl.setSearchScope(ctrl.SUBTREE_SCOPE);
+    ctrl.setTimeLimit(5000); //5sec
+    ctrl.setCountLimit(3);  //I want to get only 1 recodes.
+    ctrl.setReturningAttributes(attrNames);
+
+    try {
+      NamingEnumeration enum = ctx.search(ApplicationProperties.getLdapRoot(),
+                                          "(mail=" + mail + ")", ctrl);
+
+      while ( enum.hasMore() ) {
+        SearchResult sr = (SearchResult) enum.next();
+
+        //System.out.println("SearchResult=" + sr);
+        for (int i = 0; i < attrNames.length; i++) {
+          Attribute attr = sr.getAttributes().get(attrNames[i]);
+          String str;
+
+          if (attr == null) {
+              str = "";
+          } else {
+              str = (String) attr.get();
+          }
+          if (str == null) { str = "";  }
+
+          if (ApplicationProperties.getLdapIsSjis()) {
+              str = new String(str.getBytes("ISO-8859-1"), "UTF-8");
+          }
+          if (i != 0) { ans += " "; }
+          ans += str;
+        }
+        System.err.println("ANS=" + ans);
+      }
+      enum.close();
+    } catch (NamingException e) {
+      System.err.println("LDAP Search Error.");
+      e.printStackTrace();
+    } catch (UnsupportedEncodingException ueEx) {
+      UnsupportedEncodingException e = ueEx;
+      System.err.println("LDAP SJIS Error.");
+      e.printStackTrace();
+    }
+
+    return ans;
+  }
+}
diff --git a/src/org/jent/checksmtp/Processer.java b/src/org/jent/checksmtp/Processer.java
new file mode 100644 (file)
index 0000000..a86b0de
--- /dev/null
@@ -0,0 +1,262 @@
+package org.jent.checksmtp;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+/*
+ * Socket accept proceed
+ */
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+
+import java.net.Socket;
+
+import java.util.ArrayList;
+import java.util.ListIterator;
+import java.util.regex.Pattern;
+
+
+public class Processer implements Runnable {
+  private Socket client;
+
+  //Conform status.
+  private final int RESULT_UNKNOWN = 0;
+  private final int RESULT_OK = 1;
+  private final int RESULT_NG = 2;
+  private int result = RESULT_UNKNOWN;
+
+  //SMTP result code
+  private final int R354StartInput = 354;
+  private final int R221ServiceClosing = 221;
+  private final int R451RequestedActionAbort = 451;
+  private final int R502CommandNotImplemented = 502;
+
+  //SMTP command
+  private final String COMMAND_RCPT_TO = "RCPT TO:";
+  private final String COMMAND_DATA = "DATA";
+  private final String COMMAND_RESET = "RSET";
+  private final String COMMAND_TURN = "TURN";
+
+  //private final String COMMAND_NOOP = "NOOP";
+  //private final String COMAMND_QUIT = "QUIT";
+  public Processer(Socket client) {
+      this.client = client;
+  }
+
+  public void run() {
+    InputStream serverInput;
+    OutputStream serverOutput;
+    InputStream clientInput;
+    OutputStream clientOutput;
+
+    BufferedReader serverReader;
+    PrintWriter serverWriter;
+    BufferedReader clientReader;
+    PrintWriter clientWriter;
+
+    try {
+      //Connect to SMTP Server host 
+      String servername = ApplicationProperties.getSmtpServerHost();
+
+      //SMTP Server port 
+      int serverport = ApplicationProperties.getSmtpServerPort();
+
+      //Connection to true SMTP server.
+      Socket server = new Socket(servername, serverport);
+      serverInput = server.getInputStream();
+      serverOutput = server.getOutputStream();
+      clientInput = client.getInputStream();
+      clientOutput = client.getOutputStream();
+
+      serverReader = new BufferedReader(new InputStreamReader(
+                  server.getInputStream()));
+      serverWriter = new PrintWriter(new SmtpBufferedWriter(
+                  new OutputStreamWriter(server.getOutputStream(),
+                      "ISO-8859-1")), true);
+      clientReader = new BufferedReader(new InputStreamReader(
+                  client.getInputStream()));
+      clientWriter = new PrintWriter(new SmtpBufferedWriter(
+                  new OutputStreamWriter(client.getOutputStream(),
+                      "ISO-8859-1")), true);
+
+      smtpStart(serverReader, clientWriter, clientReader, serverWriter);
+
+      //for SMTP Server connection test
+      //SocketProxy forServer = new SocketProxy(clientInput, serverOutput, 0);
+      //SocketProxy forClient = new SocketProxy(serverInput, clientOutput, 1);
+      //Thread forServerThread = new Thread(forServer);
+      //Thread forClientThread = new Thread(forClient);
+      //forServerThread.start();
+      ////Use this ThreadforClientThread.run();
+      server.close();
+      client.close();
+    } catch (IOException e) {
+      System.err.println("Execption occurred in Processer.");
+      e.printStackTrace();
+    }
+  }
+
+  private int getCode(String s) {
+      return Integer.parseInt(s.substring(0, 3));
+  }
+
+  private boolean isContinue(String s) {
+      if ('-' == s.charAt(3)) {
+          return true;
+      }
+
+      return false;
+  }
+
+  private boolean isRcptTo(String s) {
+      if (s.startsWith(COMMAND_RCPT_TO)) {
+          return true;
+      }
+
+      return false;
+  }
+
+  private boolean isData(String s) {
+      if (s.startsWith(COMMAND_DATA)) {
+          return true;
+      }
+
+      return false;
+  }
+
+  private boolean isTurn(String s) {
+      if (s.startsWith(COMMAND_TURN)) {
+          return true;
+      }
+
+      return false;
+  }
+
+  public void sayOK() {
+      result = RESULT_OK;
+      notifyResult();
+  }
+
+  public void sayNG() {
+      result = RESULT_NG;
+      notifyResult();
+  }
+
+  private synchronized void notifyResult() {
+      notify();
+  }
+
+  private void smtpStart(BufferedReader serverReader,
+    PrintWriter clientWriter, BufferedReader clientReader,
+    PrintWriter serverWriter) {
+    String line;
+
+    try {
+      ArrayList toList = new ArrayList();
+
+      while (true) {
+        //Server responce
+        line = serverReader.readLine();
+        clientWriter.println(line);
+        System.out.println(line);
+
+        if (isContinue(line)) {
+          continue; //Server responce continue
+        }
+
+        //Client request
+        if (R221ServiceClosing == getCode(line)) {
+          break; //end of session.
+        } else if (R354StartInput == getCode(line)) {
+          System.out.println("Send mail data.");
+
+          while (true) {
+            line = clientReader.readLine();
+            serverWriter.println(line);
+
+            if (line.equals(".")) {
+              break; //end of mail dara.
+            }
+          }
+        } else {
+          while (true) {
+            line = clientReader.readLine();
+
+            if (isRcptTo(line)) {
+              //stored To: address.
+              toList.add(formatToAddress(line));
+            } else if (isTurn(line)) {
+              System.err.println("'TURN' is unsupported command.");
+              clientWriter.println(R502CommandNotImplemented);
+
+              continue; //read next client request.
+            } else if (isData(line)) {
+              //Client want to send data. Check out toList.
+              ListIterator iterater = toList.listIterator();
+
+              while (iterater.hasNext()) {
+                System.out.println("ADDRESS CHECK:" + iterater.next());
+              }
+
+              //checkout toList
+              new ToListDialog(this, toList);
+
+              while (result == RESULT_UNKNOWN) {
+                try {
+                    synchronized (this) {
+                        wait();
+                    }
+                } catch (InterruptedException e) {
+                    System.err.println("Dialg wait interrupted");
+                    e.printStackTrace();
+                }
+              }
+
+              if (result == RESULT_NG) {
+                System.out.println("CANCEL sending mail.");
+                serverWriter.println(COMMAND_RESET);
+                line = serverReader.readLine(); //Server MUST retrun "250 OK"
+                System.out.println(COMMAND_RESET + ":ANSER is " + line);
+                clientWriter.println(R451RequestedActionAbort);
+
+                continue; //I think Client QUIT or Retry. 
+              }
+            }
+
+            break; // client read while(true);
+          }
+
+          serverWriter.println(line);
+          System.out.println(line);
+        }
+      }
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+
+    System.out.println("End of Session.");
+  }
+
+  private String formatToAddress(String line) {
+    System.out.println("FIND To: " + line);
+
+    //Splitting Mail address.
+    String str = line.substring(COMMAND_RCPT_TO.length() + 1);
+    Pattern pattern = Pattern.compile("[< >]+");
+    String[] address = pattern.split(str); // 0<1>2 3
+    int i;
+
+    for (i = 0; i < address.length; i++) {
+      if (!address[i].equals("")) {
+        break;
+      }
+    }
+
+    //Search LDAP
+    str = address[i] + " " + LDAPSearch.search(address[i]);
+    return str;
+  }
+}
diff --git a/src/org/jent/checksmtp/SMTPclient.java b/src/org/jent/checksmtp/SMTPclient.java
new file mode 100644 (file)
index 0000000..9fd92b8
--- /dev/null
@@ -0,0 +1,54 @@
+package org.jent.checksmtp;
+
+import java.io.IOException;
+
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+
+public class SMTPclient implements Runnable {
+    public SMTPclient() {
+        Thread thread = new Thread(this);
+        thread.start();
+    }
+
+    public void run() {
+        while (true) {
+            ServerSocket server = null;
+
+            try {
+                //  Server Port
+                int serverport = ApplicationProperties.getSmtpPort();
+                System.err.println("Open SMTP waiting port. " + serverport);
+
+                try {
+                    server = new ServerSocket(serverport, 10,
+                            InetAddress.getByAddress(
+                                new byte[] { 127, 0, 0, 1 }));
+                } catch (IOException e) {
+                    e.printStackTrace(); //Unexpected!!
+                }
+
+                while (true) {
+                    // Wait connect from mail client
+                    Socket client = server.accept();
+                    System.err.println("Accept new STMP socket.");
+
+                    Processer processer = new Processer(client);
+                    Thread clientThread = new Thread(processer);
+                    clientThread.start();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+                System.err.println("Continure waiting SMTP client.");
+
+                try {
+                    server.close();
+                } catch (IOException ioe) {
+                    //IGNORE close Exception
+                }
+            }
+        }
+    }
+}
diff --git a/src/org/jent/checksmtp/SetupFrame.java b/src/org/jent/checksmtp/SetupFrame.java
new file mode 100644 (file)
index 0000000..4ce4a10
--- /dev/null
@@ -0,0 +1,36 @@
+package org.jent.checksmtp;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+
+public class SetupFrame extends JFrame {
+    private JLabel statusBar = new JLabel();
+    private JPanel panelCenter = new JPanel();
+    private BorderLayout layoutMain = new BorderLayout();
+
+    public SetupFrame() {
+        try {
+            jbInit();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void jbInit() throws Exception {
+        this.getContentPane().setLayout(layoutMain);
+        panelCenter.setLayout(null);
+        this.setSize(new Dimension(400, 300));
+        this.setTitle("Setup");
+        statusBar.setText("");
+        this.getContentPane().add(statusBar, BorderLayout.SOUTH);
+        this.getContentPane().add(panelCenter, BorderLayout.CENTER);
+    }
+}
diff --git a/src/org/jent/checksmtp/SetupFrame_AboutBoxPanel1.java b/src/org/jent/checksmtp/SetupFrame_AboutBoxPanel1.java
new file mode 100644 (file)
index 0000000..5d0f504
--- /dev/null
@@ -0,0 +1,53 @@
+package org.jent.checksmtp;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.border.Border;
+
+
+public class SetupFrame_AboutBoxPanel1 extends JPanel {
+    private Border border = BorderFactory.createEtchedBorder();
+    private GridBagLayout layoutMain = new GridBagLayout();
+    private JLabel labelCompany = new JLabel();
+    private JLabel labelCopyright = new JLabel();
+    private JLabel labelAuthor = new JLabel();
+    private JLabel labelTitle = new JLabel();
+
+    public SetupFrame_AboutBoxPanel1() {
+        try {
+            jbInit();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void jbInit() throws Exception {
+        this.setLayout(layoutMain);
+        this.setBorder(border);
+        labelTitle.setText("Title");
+        labelAuthor.setText("Author");
+        labelCopyright.setText("Copyright");
+        labelCompany.setText("Company");
+        this.add(labelTitle,
+            new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
+                GridBagConstraints.WEST, GridBagConstraints.NONE,
+                new Insets(5, 15, 0, 15), 0, 0));
+        this.add(labelAuthor,
+            new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
+                GridBagConstraints.WEST, GridBagConstraints.NONE,
+                new Insets(0, 15, 0, 15), 0, 0));
+        this.add(labelCopyright,
+            new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
+                GridBagConstraints.WEST, GridBagConstraints.NONE,
+                new Insets(0, 15, 0, 15), 0, 0));
+        this.add(labelCompany,
+            new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
+                GridBagConstraints.WEST, GridBagConstraints.NONE,
+                new Insets(0, 15, 5, 15), 0, 0));
+    }
+}
diff --git a/src/org/jent/checksmtp/SmtpBufferedWriter.java b/src/org/jent/checksmtp/SmtpBufferedWriter.java
new file mode 100644 (file)
index 0000000..3720c9e
--- /dev/null
@@ -0,0 +1,42 @@
+package org.jent.checksmtp;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+
+/**
+ * BufferedWriter for SMTP.
+ * BufferedWriter is use line.separator properties.
+ * SMTP connection use CRLF in end of line.
+ */
+public class SmtpBufferedWriter extends BufferedWriter {
+  private final String CRLF = "\r\n";
+  private final String LF = "\n";
+  private Writer out;
+
+  public SmtpBufferedWriter(Writer out) {
+    super(out);
+    this.out = out;
+  }
+
+  public SmtpBufferedWriter(Writer out, int sz) {
+    super(out, sz);
+    this.out = out;
+  }
+
+  public void newLine() throws IOException {
+    out.write(CRLF);
+  }
+
+  /**
+   * @param str
+   * @throws IOException
+   */
+  public void write(String str) throws IOException {
+    if (str.equals(LF)) {
+      str = CRLF;
+    }
+    write(str, 0, str.length());
+  }
+}
diff --git a/src/org/jent/checksmtp/SocketProxy.java b/src/org/jent/checksmtp/SocketProxy.java
new file mode 100644 (file)
index 0000000..dc9fc1a
--- /dev/null
@@ -0,0 +1,39 @@
+package org.jent.checksmtp;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+
+/**
+ * Socket data proxy
+ */
+public class SocketProxy implements Runnable {
+    InputStream is;
+    OutputStream os;
+    int mode = 0;
+
+    public SocketProxy(InputStream is, OutputStream os, int mode) {
+        this.is = is;
+        this.os = os;
+        this.mode = mode;
+    }
+
+    public void run() {
+        System.err.println("Start SocketProxy mode=" + mode + ":" + this);
+
+        int ch;
+
+        try {
+            while ((ch = is.read()) > 0) {
+                os.write(ch);
+                System.out.write(ch);
+            }
+        } catch (IOException e) {
+            System.err.println("Exception occured in SocketProxy mode=" + mode);
+            e.printStackTrace();
+        }
+
+        System.err.println("End  SocketProxy mode=" + mode + ":" + this);
+    }
+}
diff --git a/src/org/jent/checksmtp/ToListDialog.java b/src/org/jent/checksmtp/ToListDialog.java
new file mode 100644 (file)
index 0000000..50fdbf2
--- /dev/null
@@ -0,0 +1,105 @@
+package org.jent.checksmtp;
+
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowEvent;
+
+import java.util.ArrayList;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JList;
+import javax.swing.JScrollPane;
+
+
+public class ToListDialog extends JDialog {
+  private JButton jButton1 = new JButton();
+  private JButton jButton2 = new JButton();
+  private JList jList1 = new JList();
+  private JScrollPane scrollPane = new JScrollPane(); //add
+  private ArrayList toList = null;
+  private Processer processer = null;
+
+  public ToListDialog() {
+      this(null, "", false);
+  }
+
+  public ToListDialog(Frame parent, String title, boolean modal) {
+      super(parent, title, modal);
+
+      try {
+          jbInit();
+      } catch (Exception e) {
+          e.printStackTrace();
+      }
+  }
+
+  public ToListDialog(Processer processer, ArrayList toList) {
+      this(null, "TO Check", false);
+      this.toList = toList;
+      this.processer = processer;
+
+      if (toList != null) {
+          jList1.setListData(toList.toArray());
+
+          //jList1.update();
+          jList1.setVisible(true);
+      }
+
+      this.show();
+  }
+
+  private void jbInit() throws Exception {
+    jButton2.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        jButton2_actionPerformed(e);
+      }
+    });
+    this.setSize(new Dimension(584, 300));
+    this.getContentPane().setLayout(null);
+    this.setTitle("Conform Mail Destination");
+    this.addWindowListener(new java.awt.event.WindowAdapter() {
+      public void windowClosing(WindowEvent e) {
+        this_windowClosing(e);
+      }
+    });
+    jButton1.setText("OK");
+    jButton1.setBounds(new Rectangle(100, 240, 140, 25));
+    jButton1.addActionListener(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        jButton1_actionPerformed(e);
+      }
+    });
+    jButton2.setText("CANCEL");
+    jButton2.setBounds(new Rectangle(325, 240, 145, 25));
+    jList1.setBounds(new Rectangle(25, 25, 455, 200));
+    jList1.setSize(new Dimension(500, 200));
+    jList1.setToolTipText("null");
+    jList1.setValueIsAdjusting(true);
+    scrollPane.setBounds(new Rectangle(10, 5, 555, 225));
+    scrollPane.getViewport().setView(jList1); //add
+
+    //this.getContentPane().add(jList1, null);
+    this.getContentPane().add(scrollPane, null);
+    this.getContentPane().add(jButton2, null);
+    this.getContentPane().add(jButton1, null);
+  }
+
+  private void jButton1_actionPerformed(ActionEvent e) {
+    //push OK
+    processer.sayOK();
+    this.dispose();
+  }
+
+  private void jButton2_actionPerformed(ActionEvent e) {
+    processer.sayNG();
+    this.dispose();
+  }
+
+  private void this_windowClosing(WindowEvent e) {
+    processer.sayNG();
+  }
+}