home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / net / smtp / SmtpClient.class (.txt) next >
Encoding:
Java Class File  |  1998-04-23  |  2.7 KB  |  137 lines

  1. package sun.net.smtp;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintStream;
  5. import java.net.InetAddress;
  6. import sun.net.NetworkClient;
  7. import sun.net.TransferProtocolClient;
  8.  
  9. public class SmtpClient extends TransferProtocolClient {
  10.    SmtpPrintStream message;
  11.  
  12.    public void closeServer() throws IOException {
  13.       if (((NetworkClient)this).serverIsOpen()) {
  14.          this.closeMessage();
  15.          this.issueCommand("QUIT\r\n", 221);
  16.          super.closeServer();
  17.       }
  18.  
  19.    }
  20.  
  21.    void issueCommand(String var1, int var2) throws IOException {
  22.       ((TransferProtocolClient)this).sendServer(var1);
  23.  
  24.       int var3;
  25.       while((var3 = ((TransferProtocolClient)this).readServerResponse()) != var2) {
  26.          if (var3 != 220) {
  27.             throw new SmtpProtocolException(((TransferProtocolClient)this).getResponseString());
  28.          }
  29.       }
  30.  
  31.    }
  32.  
  33.    private void toCanonical(String var1) throws IOException {
  34.       this.issueCommand("rcpt to: " + var1 + "\r\n", 250);
  35.    }
  36.  
  37.    // $FF: renamed from: to (java.lang.String) void
  38.    public void method_0(String var1) throws IOException {
  39.       int var2 = 0;
  40.       int var3 = var1.length();
  41.       int var4 = 0;
  42.       int var5 = 0;
  43.       int var6 = 0;
  44.  
  45.       for(boolean var7 = false; var4 < var3; ++var4) {
  46.          char var8 = var1.charAt(var4);
  47.          if (var6 > 0) {
  48.             if (var8 == '(') {
  49.                ++var6;
  50.             } else if (var8 == ')') {
  51.                --var6;
  52.             }
  53.  
  54.             if (var6 == 0) {
  55.                if (var5 > var2) {
  56.                   var7 = true;
  57.                } else {
  58.                   var2 = var4 + 1;
  59.                }
  60.             }
  61.          } else if (var8 == '(') {
  62.             ++var6;
  63.          } else if (var8 == '<') {
  64.             var2 = var5 = var4 + 1;
  65.          } else if (var8 == '>') {
  66.             var7 = true;
  67.          } else if (var8 == ',') {
  68.             if (var5 > var2) {
  69.                this.toCanonical(var1.substring(var2, var5));
  70.             }
  71.  
  72.             var2 = var4 + 1;
  73.             var7 = false;
  74.          } else if (var8 > ' ' && !var7) {
  75.             var5 = var4 + 1;
  76.          } else if (var2 == var4) {
  77.             ++var2;
  78.          }
  79.       }
  80.  
  81.       if (var5 > var2) {
  82.          this.toCanonical(var1.substring(var2, var5));
  83.       }
  84.  
  85.    }
  86.  
  87.    public void from(String var1) throws IOException {
  88.       this.issueCommand("mail from: " + var1 + "\r\n", 250);
  89.    }
  90.  
  91.    private void openServer(String var1) throws IOException {
  92.       ((NetworkClient)this).openServer(var1, 25);
  93.       this.issueCommand("helo " + InetAddress.getLocalHost().getHostName() + "\r\n", 250);
  94.    }
  95.  
  96.    public PrintStream startMessage() throws IOException {
  97.       this.issueCommand("data\r\n", 354);
  98.       return this.message = new SmtpPrintStream(super.serverOutput, this);
  99.    }
  100.  
  101.    void closeMessage() throws IOException {
  102.       if (this.message != null) {
  103.          this.message.close();
  104.       }
  105.  
  106.    }
  107.  
  108.    public SmtpClient(String var1) throws IOException {
  109.       if (var1 != null) {
  110.          try {
  111.             this.openServer(var1);
  112.             return;
  113.          } catch (Exception var5) {
  114.          }
  115.       }
  116.  
  117.       try {
  118.          String var2 = System.getProperty("mail.host");
  119.          if (var2 != null) {
  120.             this.openServer(var2);
  121.             return;
  122.          }
  123.       } catch (Exception var4) {
  124.       }
  125.  
  126.       try {
  127.          this.openServer("localhost");
  128.       } catch (Exception var3) {
  129.          this.openServer("mailhost");
  130.       }
  131.    }
  132.  
  133.    public SmtpClient() throws IOException {
  134.       this((String)null);
  135.    }
  136. }
  137.