diff --git a/src/helma/scripting/rhino/MailObject.java b/src/helma/scripting/rhino/MailObject.java new file mode 100644 index 00000000..53daa5fc --- /dev/null +++ b/src/helma/scripting/rhino/MailObject.java @@ -0,0 +1,368 @@ +/* + * Helma License Notice + * + * The contents of this file are subject to the Helma License + * Version 2.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://adele.helma.org/download/helma/license.txt + * + * Copyright 1998-2003 Helma Software. All Rights Reserved. + * + * $RCSfile$ + * $Author$ + * $Revision$ + * $Date$ + */ + +package helma.scripting.rhino; + +import helma.util.*; +import org.mozilla.javascript.*; +import java.io.*; +import java.util.*; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import javax.activation.*; +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.Multipart; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; +import javax.mail.internet.MimeUtility; + +/** + * A JavaScript wrapper around a JavaMail message class to send + * mail via SMTP from Helma + */ +public class MailObject extends ScriptableObject implements Serializable { + + public static final int OK = 0; + public static final int SUBJECT = 10; + public static final int TEXT = 11; + public static final int MIMEPART = 12; + public static final int TO = 20; + public static final int CC = 21; + public static final int BCC = 22; + public static final int FROM = 23; + public static final int REPLYTO = 24; + public static final int SEND = 30; + + MimeMessage message; + Multipart multipart; + StringBuffer buffer; + int status; + + /** + * Creates a new MailObject prototype object. + */ + MailObject() { + } + + + /** + * Creates a new ESMail object. + * + * @param mailx ... + */ + MailObject(Properties mprops) { + this.status = OK; + + // create some properties and get the default Session + Properties props = new Properties(); + + props.put("mail.smtp.host", mprops.getProperty("smtp", "mail")); + + Session session = Session.getDefaultInstance(props, null); + + message = new MimeMessage(session); + } + + /** + * Overrides abstract method in ScriptableObject + */ + public String getClassName() { + return "Mail"; + } + + public static MailObject mailObjCtor(Context cx, Object[] args, + Function ctorObj, boolean inNewExpr) { + Properties props = (Properties) ctorObj.get("props", ctorObj); + if (props == null) { + props = new Properties(); + } + return new MailObject(props); + } + + public static void init(Scriptable scope, Properties props) { + Method[] methods = MailObject.class.getDeclaredMethods(); + ScriptableObject proto = new MailObject(); + proto.setPrototype(getObjectPrototype(scope)); + Member ctorMember = null; + for (int i=0; i