DEF_COMPONENTNAME
Smtp
DEF_SUPERCLASS
Object
DEF_SUPERCOMPONENT

DEF_PACKAGE
plugins
internet
DEF_ENDLIST
DEF_SUBCOMPONENTLIST
DEF_ENDLIST
DEF_SUBCOMPONENTCLASSLIST
DEF_ENDLIST
DEF_BITMAP

DEF_THUMBNAIL_UP

DEF_THUMBNAIL_DOWN

DEF_IMPORTS
java.util.*
java.net.*
DEF_ENDLIST
DEF_REQUIRES
DEF_ENDLIST
DEF_IMPLEMENTS
DEF_ENDLIST
DEF_DECLARATION
// A class that lays the groundwork for a SMTP component.
//  Variable Declarations
    static final int DEFAULT_PORT = 25;
    static final boolean DEBUG = false;

    protected DataInputStream reply = null;
    protected PrintStream send = null;
    protected Socket sock = null;
DEF_ENDLIST
DEF_METHOD
    public static void main( String[] args) {
    }
DEF_ENDLIST
DEF_METHOD
    public Smtp( String hostid) throws UnknownHostException, IOException {
        this(hostid, DEFAULT_PORT);
    }
DEF_ENDLIST
DEF_METHOD
    public Smtp( String hostid, int port) throws UnknownHostException, IOException {
        sock = new Socket( hostid, port );
        reply = new DataInputStream( sock.getInputStream() );
        send = new PrintStream( sock.getOutputStream() );
        String rstr = reply.readLine();
        if (DEBUG == true) System.out.println(rstr);
        if (!rstr.startsWith("220")) throw new ProtocolException(rstr);
        while (rstr.indexOf('-') == 3) {
            rstr = reply.readLine();
            if (DEBUG) System.out.println(rstr);
            if (!rstr.startsWith("220")) throw new ProtocolException(rstr);
        }
    }
DEF_ENDLIST
DEF_METHOD
    public Smtp( String hostid, int port, String to_address, String from_address, String message ) throws UnknownHostException, IOException {
    }
DEF_ENDLIST
DEF_METHOD
    public Smtp( InetAddress address ) throws IOException {
        this(address, DEFAULT_PORT);
    }
DEF_ENDLIST
DEF_METHOD
    public Smtp( InetAddress address, int port ) throws IOException {
        sock = new Socket( address, port );
        reply = new DataInputStream( sock.getInputStream() );
        send = new PrintStream( sock.getOutputStream() );
        String rstr = reply.readLine();
        if (DEBUG) System.out.println(rstr);
        if (!rstr.startsWith("220")) throw new ProtocolException(rstr);
        while (rstr.indexOf('-') == 3) {
            rstr = reply.readLine();
            if (DEBUG) System.out.println(rstr);
            if (!rstr.startsWith("220")) throw new ProtocolException(rstr);
        }
    }
DEF_ENDLIST
DEF_METHOD
    public void sendmsg( String from_address, String to_address, String subject, String message ) throws IOException, ProtocolException {

        String rstr;
        String sstr;

        InetAddress local = null;
        local = local.getLocalHost();
        String host = local.getHostName();
        send.println("HELO " + host);
//        send.println("HELO smtp");
        if (DEBUG) System.out.println("HELO " + host);
        rstr = reply.readLine();
        if (DEBUG) System.out.println(rstr);
        if (!rstr.startsWith("250")) throw new ProtocolException(rstr);
        sstr = "MAIL FROM: " + from_address ;
        send.println(sstr);
        if (DEBUG) System.out.println(sstr);
        rstr = reply.readLine();
        if (DEBUG) System.out.println(rstr);
        if (!rstr.startsWith("250")) throw new ProtocolException(rstr);
        sstr = "RCPT TO: " + to_address;
        send.println(sstr);
        if (DEBUG) System.out.println(sstr);
        rstr = reply.readLine();
        if (DEBUG) System.out.println(rstr);
        if (!rstr.startsWith("250")) throw new ProtocolException(rstr);
        send.println("DATA");
        if (DEBUG) System.out.println("DATA");
        rstr = reply.readLine();
        if (DEBUG) System.out.println(rstr);
        if (!rstr.startsWith("354")) throw new ProtocolException(rstr);
        send.println("From: " + from_address);
        if (DEBUG) System.out.println("From: " + from_address);
        send.println("To: " + to_address);
        if (DEBUG) System.out.println("To: " + to_address);
        send.println("Subject: " + subject);
        if (DEBUG) System.out.println("Subject: " + subject);

        // Create Date - we'll cheat by assuming that local clock is right
        // and that GMT String is formatted correctly.

        Date today_date = new Date();
//        send.println("Date: " + today_date.toGMTString());
        send.println("Date: " + msgDateFormat(today_date));
        if (DEBUG) System.out.println("Date: " + msgDateFormat(today_date));

        // Warn the world that we are on the loose - with the comments header:
        send.println("Comment: Unauthenticated sender");
        send.println("X-Mailer: JNet Smtp");

        // Sending a blank line ends the header part.
        send.println("");
        if (DEBUG) System.out.println("");
        // Now send the message proper
        send.println(message);
        if (DEBUG) System.out.println(message);
        send.println(".");
        if (DEBUG) System.out.println(".");
        rstr = reply.readLine();
        if (DEBUG) System.out.println(rstr);
        if (!rstr.startsWith("250")) throw new ProtocolException(rstr);
    }
DEF_ENDLIST
DEF_METHOD
    protected void finalize() throws Throwable {
        send.println("QUIT");
        sock.close();
        super.finalize();
    }
DEF_ENDLIST
DEF_METHOD
    private String msgDateFormat( Date senddate) {
        String formatted = "hold";

        String Day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
        String Month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

        formatted = Day[senddate.getDay()] + ", ";
        formatted = formatted + String.valueOf(senddate.getDate()) + " ";
        formatted = formatted + Month[senddate.getMonth()] + " ";
        if (senddate.getYear() > 99)
            formatted = formatted + String.valueOf(senddate.getYear() + 1900) + " ";
        else
            formatted = formatted + String.valueOf(senddate.getYear()) + " ";
        if (senddate.getHours() < 10) formatted = formatted + "0";
        formatted = formatted + String.valueOf(senddate.getHours()) + ":";
        if (senddate.getMinutes() < 10) formatted = formatted + "0";
        formatted = formatted + String.valueOf(senddate.getMinutes()) + ":";
        if (senddate.getSeconds() < 10) formatted = formatted + "0";
        formatted = formatted + String.valueOf(senddate.getSeconds()) + " ";
        if (senddate.getTimezoneOffset() < 0)
            formatted = formatted + "+";
        else
            formatted = formatted + "-";
        if (senddate.getTimezoneOffset()/60 < 10) formatted = formatted + "0";
        formatted = formatted + String.valueOf(senddate.getTimezoneOffset()/60);
        if (senddate.getTimezoneOffset()%60 < 10) formatted = formatted + "0";
        formatted = formatted + String.valueOf(senddate.getTimezoneOffset()%60);

        return formatted;
    }
DEF_ENDLIST
DEF_ENDCOMPONENT
DEF_COMPONENTNAME
SmtpWrapper
DEF_SUPERCLASS
Panel
DEF_SUPERCOMPONENT

DEF_PACKAGE
plugins
internet
DEF_ENDLIST
DEF_SUBCOMPONENTLIST
DEF_ENDLIST
DEF_SUBCOMPONENTCLASSLIST
DEF_ENDLIST
DEF_CATEGORY
Internet
DEF_BITMAP

DEF_THUMBNAIL_UP
but1.bmp
DEF_THUMBNAIL_DOWN
d-but1.bmp
DEF_VISUAL
DEF_PANEL
DEF_IMPORTS
java.io.IOException
java.net.ProtocolException
java.net.UnknownHostException
DEF_ENDLIST
DEF_REQUIRES
DEF_ENDLIST
DEF_IMPLEMENTS
DEF_ENDLIST
DEF_DECLARATION
// A class that is a wrapper for the smtp class.
//  Variable Declarations
    private String from;
    private String to;
    private String subject = "Uninitialized";
    private String message = "Uninitialized";
    private String mailhost = "unknown";
    private boolean editTo;
    private boolean editFrom;
//    Button sendit;
//    Label fromLabel;
//    Label toLabel;
//    TextField fromText, toText;
//    TextField subjText;
//    TextArea mesgText;
DEF_ENDLIST
DEF_EVENT
    public boolean action(Event e, Object o) {
        if (e.target instanceof Button)  {
            if ("Send".equals( (String) o ) ) {
                try {
/*  Nice idea - but for some reason it is locking up... I'll fix it for v1.1 :-)
//                  showStatus("Getting Mailhost");
                    String mailhost = getCodeBase().getHost();
*/
//                  showStatus("Connecting to mailhost ");
                    Smtp connect = new Smtp(mailhost);
//                    showStatus("Connected to mailhost... sending...");

//      temporarily commented...
//                    subject = subjText.getText();
//                    message = mesgText.getText();

                    connect.sendmsg(from,to,subject,message);
//                    showStatus("Message sent");

//   temporarily commented...
//                    if (fromText.isEditable())
//                        fromText.setText(from);
//                    if (toText.isEditable())
//                        toText.setText(to);
//
//                    subjText.setText("Send from Applet");
//                    mesgText.setText("Sample Message");
                }
                catch (UnknownHostException x1) {
//                    showStatus("Failed to find host - " + mailhost);
                    System.out.println(x1.getMessage());
                }
                catch (ProtocolException x2) {
//                    showStatus("Some sort of protocol exception");
                    System.out.println(x2.getMessage());
                }
                catch (IOException x3) {
//                    showStatus("Error reading/writing to socket on " + mailhost);
                    System.out.println(x3.getMessage());
                }
                finally {
                }
                return true;
            }
        }
        if (e.target instanceof TextField) {
        return true;
        }
        return super.action(e,o);
    }
DEF_ENDLIST
DEF_METHOD
void initialize()
{
 //        resize(300, 200);
//        from = getParameter("From");
//        to = getParameter("To");
//        mailhost = getParameter("Mailhost");
//        fromLabel = new Label("From: ");
//        toLabel = new Label("To: ");
//        fromText = new TextField(from,10);
//        toText = new TextField(to,10);

//        System.out.println("mark1");
//        if (getParameter("EditTo") != null && getParameter("EditTo").equals("false"))
//            toText.setEditable(false);
//        else
//            toText.setEditable(true);

//   temporarily commented...
//        if (editTo == false)
//          toText.setEditable(false);
//        else
//          toText.setEditable(true);


//        if (getParameter("EditFrom") != null && getParameter("EditFrom").equals("true"))
//            fromText.setEditable(true);
//        else
//            fromText.setEditable(false);

//   temporarily commented...
//        if (editFrom == true)
//            fromText.setEditable(true);
//        else
//            fromText.setEditable(false);

//        add(fromLabel);
//        add(fromText);
//        add(toLabel);
//        add(toText);
//        subjText = new TextField("Send from Applet", 40);
//        add(subjText);
//        mesgText = new TextArea("Sample Message",5,40);
//        add(mesgText);
//        sendit = new Button("Send");
//        add(sendit);
}
DEF_ENDLIST
DEF_METHOD
    public void paint(Graphics g) {
    }
DEF_ENDLIST
DEF_METHOD
public void setSmtpTo(String aParam)
{
  to = aParam;
}
DEF_ENDLIST
DEF_METHOD
public String getSmtpTo()
{
  return to;
}
DEF_ENDLIST
DEF_METHOD
public void setSmtpFrom(String aParam)
{
  from = aParam;
}
DEF_ENDLIST
DEF_METHOD
public String getSmtpFrom()
{
  return from;
}
DEF_ENDLIST
DEF_METHOD
public void setSmtpMailHost(String aParam)
{
  mailhost = aParam;
}
DEF_ENDLIST
DEF_METHOD
public String getSmtpMailHost()
{
  return mailhost;
}
DEF_ENDLIST
DEF_METHOD
public void setSmtpEditTo(boolean aParam)
{
  editTo = aParam;  
}
DEF_ENDLIST
DEF_METHOD
public boolean getSmtpEditTo()
{
  return editTo;
}
DEF_ENDLIST
DEF_METHOD
public void setSmtpEditFrom(boolean aParam)
{
  editFrom = aParam;
}
DEF_ENDLIST
DEF_METHOD
public boolean getSmtpEditFrom()
{
  return editFrom;  
}
DEF_ENDLIST
DEF_PROPERTY
To:
String
setSmtpTo(AVALUE);
AVALUE=getSmtpTo();

DEF_ENDLIST
DEF_PROPERTY
From:
String
setSmtpFrom(AVALUE);
AVALUE=getSmtpFrom();

DEF_ENDLIST
DEF_PROPERTY
MailHost
String
setSmtpMailHost(AVALUE);
AVALUE=getSmtpMailHost();

DEF_ENDLIST
DEF_PROPERTY
Edit To
boolean
setSmtpEditTo(AVALUE);
AVALUE=getSmtpEditTo();
true
DEF_ENDLIST
DEF_PROPERTY
Edit From
boolean
setSmtpEditFrom(AVALUE);
AVALUE=getSmtpEditFrom();
true
DEF_ENDLIST
DEF_PROPERTY
Top
int
move(bounds().x, AVALUE);
AVALUE = bounds().y;
0
DEF_ENDLIST
DEF_PROPERTY
Left
int
move(AVALUE, bounds().y);
AVALUE = bounds().x;
0
DEF_ENDLIST
DEF_PROPERTY
Height
int
resize(bounds().width, AVALUE);
AVALUE = bounds().height;
150
DEF_ENDLIST
DEF_PROPERTY
Width
int
resize(AVALUE, bounds().height);
AVALUE = bounds().width;
150
DEF_ENDLIST
DEF_ENDCOMPONENT
