Ok, I managed to get a diff of the modified files, could someone check them
in please. Or give comments as to changes to be made.
/Colin
Index: ./src/adapter/org/apache/turbine/util/mail/SimpleEmail.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/adapter/org/apache/turbine/util/mail/SimpleEmail.java,v
retrieving revision 1.1
diff -r1.1 SimpleEmail.java
57c57
< import java.util.Hashtable;
---
> //import java.util.Hashtable;
62d61
< import org.apache.turbine.services.db.util.Criteria;
67a67
> * @author <a href="mailto:[EMAIL PROTECTED]">Colin Chalmers</a>
72c72
< * @version $Id: SimpleEmail.java,v 1.1 2001/07/10 00:39:39 jvanzyl Exp $
---
> * @version $Id: SimpleEmail.java,v 1.2 2001/07/10 00:39:39 jvanzyl Exp $
77,79d76
< /** the conentet type for body of the message */
< private String contentType = null;
<
88,136c85
< super.init();
< }
<
< /**
< * Constructor used to initialize attributes. To create a simple
< * email you need to pass a Criteria object into the SimpleEmail
< * constructor which contains:
< *
< * <ul>
< * <li>SENDER_EMAIL</li>
< * <li>SENDER_NAME</li>
< * <li>RECEIVER_EMAIL</li>
< * <li>RECEIVER_NAME</li>
< * <li>EMAIL_SUBJECT</li>
< * <li>EMAIL_BODY</li>
< * </ul>
< *
< * Deprecated, since Criteria is deprecated in mail API.
< *
< * @param criteria A Criteria.
< * @exception MessagingException.
< */
< public SimpleEmail( Criteria criteria )
< throws MessagingException
< {
< super.init();
< this.initCriteria(criteria);
< }
<
< /**
< * Uses the criteria to set the fields.
< *
< * Deprecated, since the Criteria is deprecated.
< *
< * @param criteria A Criteria.
< * @exception MessagingException.
< */
< protected void initCriteria( Criteria criteria )
< throws MessagingException
< {
< super.initCriteria(criteria);
<
< if( criteria.containsKey( CONTENT_TYPE ) )
< contentType = criteria.getString( CONTENT_TYPE );
<
< if( criteria.containsKey( EMAIL_BODY ) )
< setMsg( criteria.getString( EMAIL_BODY ) );
< else
< setMsg("NO MESSAGE");
---
> super();
149,151c98
< if (contentType == null)
< contentType = TEXT_PLAIN;
< message.setContent( msg, contentType );
---
> setContent( msg, TEXT_PLAIN );
The command completed successfully.
Index: ./src/adapter/org/apache/turbine/util/mail/Email.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/adapter/org/apache/turbine/util/mail/Email.java,v
retrieving revision 1.2
diff -r1.2 Email.java
60c60,62
< import java.util.Vector;
---
> import java.util.ArrayList;
> import java.util.Enumeration;
> import java.util.Collection;
70,73c72
<
< //!! these are bad.
< import org.apache.turbine.Turbine;
< import org.apache.turbine.services.db.util.Criteria;
---
> import javax.mail.internet.MimeMultipart;
80a80
> * @author <a href="mailto:[EMAIL PROTECTED]">Colin Chalmers</a>
86c86
< * @version $Id: Email.java,v 1.2 2001/07/14 21:29:32 jvanzyl Exp $
---
> * @version $Id: Email.java,v 1.3 2001/07/14 21:29:32 jvanzyl Exp $
112c112
<
---
>
114c114,117
< protected MimeMessage message;
---
> protected MimeMessage message = null;
>
> /** The Session class represents a mail session */
> private Session session = null;
118a122,142
> /** The Address of the sending party, mandatory */
> private InternetAddress fromAddress = null;
>
> /** The Subject */
> private String subject = null;
>
> /** An attachment */
> private MimeMultipart emailBody = null;
>
> /** The content */
> private Object content = null;
>
> /** The content type */
> private String contentType = null;
>
> /**
> * The hostname of the mail server with which to connect. If null will try to
>get
> * property from system.properties. If still null, quit
> */
> private String hostName = null;
>
120,123c144,167
< private Vector toList;
< private Vector ccList;
< private Vector bccList;
< private Vector replyList;
---
> private ArrayList toList = null;
> private ArrayList ccList = null;
> private ArrayList bccList = null;
> private ArrayList replyList = null;
>
> /**
> * Used to specify the mail headers. Example:
> *
> * X-Mailer: Sendmail, X-Priority: 1(highest)
> * or 2(high) 3(normal) 4(low) and 5(lowest)
> * Disposition-Notification-To: returnR [EMAIL PROTECTED]
> */
> private Hashtable headers = null;
>
>
> /**
> * Setting to true will enable the display of debug information.
> *
> * @param d A boolean.
> */
> public void setDebug(boolean d)
> {
> session.setDebug(d);
> }
129,130d172
< * @return An HtmlEmail.
< * @exception MessagingException.
135a178,212
>
>
> /**
> * Set the emailBody to a MimeMultiPart
> *
> * @param aMimeMultipart
> */
> public void setContent(MimeMultipart aMimeMultipart)
> {
> this.emailBody = aMimeMultipart;
> }
>
>
> /**
> * Set the content & contentType
> *
> * @param aObject
> * @param aContentType
> */
> public void setContent(Object aObject, String aContentType)
> {
> this.content = aObject;
> this.contentType = aContentType;
> }
>
>
> /**
> * Set the hostname
> *
> * @param aHostName
> */
> public void setHostName(String aHostName)
> {
> this.hostName = aHostName;
> }
139c216
< * TODO: Document.
---
> * Initialise a mailsession object
143a221
> throws MessagingException
147,194c225,234
< properties.put ( MAIL_HOST,
< Turbine.getConfiguration().getString( MAIL_SERVER ) );
< String mailSMTPFrom = Turbine.getConfiguration().getString(MAIL_SMTP_FROM);
< if(mailSMTPFrom!=null && !mailSMTPFrom.equals("")) {
< properties.put ( MAIL_SMTP_FROM, mailSMTPFrom );
< }
< return Session.getDefaultInstance(properties, null);
< }
<
< /**
< * Initializes the mail.
< *
< * Deprecated.
< *
< * @param criteria A Criteria.
< * @exception MessagingException.
< * @see #init() init.
< */
< protected void initialize(Criteria criteria)
< throws MessagingException
< {
< init();
< initCriteria(criteria);
< }
<
< /**
< * Initializes the mail.
< *
< * <p>This is the first method that should be called by a subclass
< * in its constructor.
< *
< * @exception MessagingException.
< */
< protected void init()
< throws MessagingException
< {
<
< // Create the message.
< message = new MimeMessage( getMailSession() );
<
< toList = new Vector();
< ccList = new Vector();
< bccList = new Vector();
< replyList = new Vector();
<
< // Set the sent date.
< setSentDate( new Date() );
< }
---
>
> if (hostName == null)
> {
> hostName = properties.getProperty(MAIL_HOST);
> }
> if (hostName == null)
> {
> throw new MessagingException("Cannot find valid hostname to
>mail session");
> }
> properties.put ( MAIL_HOST, hostName );
196,226c236
< /**
< * Initialize the mail according to the Criteria.
< *
< * <p>This method uses the criteria parameter to set the from, to
< * and subject fields of the email.
< *
< * Deprecated; one should use the setFrom, addTo, etc. methods.
< *
< * @param criteria A Criteria.
< * @exception MessagingException.
< */
< protected void initCriteria( Criteria criteria )
< throws MessagingException
< {
< // Set the FROM field.
< if( criteria.containsKey( SENDER_EMAIL) &&
< criteria.containsKey( SENDER_NAME ) )
< setFrom(criteria.getString( SENDER_EMAIL ),
< criteria.getString( SENDER_NAME ));
<
< // Set the TO field.
< if( criteria.containsKey( RECEIVER_EMAIL) &&
< criteria.containsKey( RECEIVER_NAME ) )
< addTo( criteria.getString( RECEIVER_EMAIL ),
< criteria.getString( RECEIVER_NAME ) );
<
< // Set the SUBJECT field.
< if( criteria.containsKey( EMAIL_SUBJECT ) )
< setSubject( criteria.getString( EMAIL_SUBJECT ) );
< else
< setSubject( "no subject available" );
---
> return Session.getDefaultInstance(properties, null);
237,238c247
< public Email setFrom(String email,
< String name )
---
> public Email setFrom(String email, String name )
243c252
< if ( name == null || name.trim().equals("") )
---
> if (( name == null) || (name.trim().equals("")) )
247c256,264
< message.setFrom(new InternetAddress( email, name ) );
---
> if (fromAddress == null)
> {
> fromAddress = new InternetAddress( email, name );
> }
> else
> {
> fromAddress.setAddress(email);
> fromAddress.setPersonal(name);
> }
264,265c281
< public Email addTo(String email,
< String name )
---
> public Email addTo(String email, String name )
270c286
< if ( name == null || name.trim().equals("") )
---
> if (( name == null) || (name.trim().equals("")) )
274c290,296
< toList.addElement( new InternetAddress( email, name ) );
---
>
> if (toList == null)
> {
> toList = new ArrayList();
> }
>
> toList.add( new InternetAddress( email, name ) );
281a304,316
>
>
> /**
> * Set a list of "TO" addresses
> *
> * @param aCollection
> * @return
> */
> public Email setTo(Collection aCollection)
> {
> toList = new ArrayList(aCollection);
> return this;
> }
291,292c326
< public Email addCc(String email,
< String name )
---
> public Email addCc(String email, String name )
298c332
< if ( name == null || name.trim().equals("") )
---
> if (( name == null) || (name.trim().equals("")) )
302c336,342
< ccList.addElement( new InternetAddress( email, name ) );
---
>
> if (ccList == null)
> {
> ccList = new ArrayList();
> }
>
> ccList.add( new InternetAddress( email, name ) );
310a351,363
>
>
> /**
> * Set a list of "CC" addresses
> *
> * @param aCollection
> * @return An Email.
> */
> public Email setCc(Collection aCollection)
> {
> ccList = new ArrayList(aCollection);
> return this;
> }
320,321c373
< public Email addBcc(String email,
< String name )
---
> public Email addBcc(String email, String name )
326c378
< if ( name == null || name.trim().equals("") )
---
> if (( name == null) || (name.trim().equals("")) )
330c382,388
< bccList.addElement( new InternetAddress( email, name ) );
---
>
> if (bccList == null)
> {
> bccList = new ArrayList();
> }
>
> bccList.add( new InternetAddress( email, name ) );
338a397,410
>
>
>
> /**
> * Set a list of "BCC" addresses
> *
> * @param aCollection
> * @return
> */
> public Email setBcc(Collection aCollection)
> {
> bccList = new ArrayList(aCollection);
> return this;
> }
348,349c420
< public Email addReplyTo(String email,
< String name )
---
> public Email addReplyTo(String email, String name )
354c425
< if ( name == null || name.trim().equals("") )
---
> if (( name == null) || (name.trim().equals("")) )
358c429,435
< replyList.addElement( new InternetAddress( email, name ) );
---
>
> if (replyList == null)
> {
> replyList = new ArrayList();
> }
>
> replyList.add( new InternetAddress( email, name ) );
365a443,456
>
> /**
> * Used to specify the mail headers. Example:
> *
> * X-Mailer: Sendmail, X-Priority: 1(highest)
> * or 2(high) 3(normal) 4(low) and 5(lowest)
> * Disposition-Notification-To: returnR [EMAIL PROTECTED]
> *
> * @param h A Hashtable.
> */
> public void setHeaders(Hashtable h)
> {
> headers = h;
> }
368c459
< * Set the email subject.
---
> * Adds a header (name, value) to the headers Hashtable.
370,372c461,462
< * @param subject A String.
< * @return An Email.
< * @exception MessagingException.
---
> * @param name A String with the name.
> * @param value A String with the value.
374,375c464
< public Email setSubject( String subject )
< throws MessagingException
---
> public void addHeader(String name, String value)
377,381c466
< if ( charset != null )
< {
< message.setSubject(subject, charset);
< }
< else
---
> if (headers == null)
383c468
< message.setSubject(subject);
---
> headers = new Hashtable();
385,386c470,471
< return this;
< }
---
> headers.put(name,value);
> }
389c474
< * Set the sent date field.
---
> * Set the email subject.
391c476
< * @param date A Date.
---
> * @param subject A String.
395c480
< public Email setSentDate( Date date )
---
> public Email setSubject( String aSubject )
398c483
< message.setSentDate( date );
---
> subject = aSubject;
402c487
< /**
---
> /**
421,428c506,568
< InternetAddress[] foo = new InternetAddress[0];
< message.setRecipients(Message.RecipientType.TO,
< toInternetAddressArray(toList));
< message.setRecipients(Message.RecipientType.CC,
< toInternetAddressArray(ccList));
< message.setRecipients(Message.RecipientType.BCC,
< toInternetAddressArray(bccList));
< message.setReplyTo(toInternetAddressArray(replyList));
---
> MimeMessage message = new MimeMessage( getMailSession() );
>
> // Set the sent date.
> message.setSentDate( new Date() );
>
> if (subject != null)
> {
> message.setSubject(subject);
> }
>
> if (content != null)
> {
> message.setContent(content, contentType);
> }
> else if (emailBody != null)
> {
> message.setContent(emailBody);
> }
>
> if (fromAddress != null)
> {
> message.setFrom(fromAddress);
> }
> else
> {
> throw new MessagingException("Sender address required");
>
> }
>
> if (toList != null)
> {
> message.setRecipients(Message.RecipientType.TO,
>toInternetAddressArray(toList));
> }
> else
> {
> throw new MessagingException("At least one receiver address
>required");
> }
>
> if (ccList != null)
> {
> message.setRecipients(Message.RecipientType.CC,
>toInternetAddressArray(ccList));
> }
>
> if (bccList != null)
> {
> message.setRecipients(Message.RecipientType.BCC,
>toInternetAddressArray(bccList));
> }
>
> if (replyList != null)
> {
> message.setReplyTo(toInternetAddressArray(replyList));
> }
>
> if (headers != null)
> {
> Enumeration e = headers.keys();
> while (e.hasMoreElements())
> {
> String name = (String)e.nextElement();
> String value = (String)headers.get(name);
> message.addHeader(name, value);
> }
> }
>
433c573
< * Utility to copy Vector of known InternetAddress objects into an
---
> * Utility to copy ArrayList of known InternetAddress objects into an
436c576
< * @param v A Vector.
---
> * @param v A ArrayList.
439c579
< private InternetAddress[] toInternetAddressArray(Vector v)
---
> private InternetAddress[] toInternetAddressArray(ArrayList aList)
441,446c581
< int size = v.size();
< InternetAddress[] ia = new InternetAddress[size];
< for (int i=0; i<size; i++)
< {
< ia[i] = (InternetAddress)v.elementAt(i);
< }
---
> InternetAddress[] ia = (InternetAddress[])aList.toArray(new
>InternetAddress[0]);
The command completed successfully.
Index: ./src/adapter/org/apache/turbine/util/mail/MultiPartEmail.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/adapter/org/apache/turbine/util/mail/MultiPartEmail.java,v
retrieving revision 1.1
diff -r1.1 MultiPartEmail.java
59,60c59,60
< import java.util.Hashtable;
< import java.util.Vector;
---
> //import java.util.Hashtable;
> //import java.util.Vector;
73d72
< import org.apache.turbine.services.db.util.Criteria;
94,95c93,94
< /** Body portion of the email. */
< protected MimeMultipart emailBody;
---
> /** Body portion of the email. */
> protected MimeMultipart emailBody = null;
98c97
< protected MimeBodyPart main;
---
> protected MimeBodyPart main = null;
101c100
< private String fileServer = null;
---
> private String fileServer = "localhost";
114,140d112
< /**
< * Constructor used to initialize attributes.
< *
< * <p>This method uses the criteria object to set the different
< * fields of the e-mail. The expected fields of the Criteria are:
< *
< * <ul>
< * <li>SENDER_EMAIL</li>
< * <li>RECEIVER_EMAIL</li>
< * <li>EMAIL_SUBJECT</li>
< * <li>EMAIL_BODY</li>
< * <li>ATTACHMENTS - A Vector of EmailAttachment.</li>
< * <li>FILE_SERVER - Where the files are located. If not given,
< * they are assumed to be local.</li>
< * </ul>
< *
< * Deprecated, since Criteria is deprecated in mail API.
< *
< * @param criteria A Criteria.
< * @exception MessagingException.
< */
< public MultiPartEmail( Criteria criteria )
< throws MessagingException
< {
< this.init();
< this.initCriteria(criteria);
< }
150,152c122
< super.init();
<
< fileServer = null;
---
> // super.init(aHostName);
156c126
< message.setContent( emailBody );
---
> super.setContent( emailBody );
164,213c134
< /**
< * Uses the criteria to set the fields.
< *
< * <p>This method uses the criteria object to set the different
< * fields of the e-mail. The expected fields of the Criteria are:
< *
< * <ul>
< * <li>SENDER_EMAIL</li>
< * <li>RECEIVER_EMAIL</li>
< * <li>EMAIL_SUBJECT</li>
< * <li>EMAIL_BODY</li>
< * <li>ATTACHMENTS - A Vector of EmailAttachment.</li>
< * <li>FILE_SERVER - Where the files are located. If not given,
< * they are assumed to be local.</li>
< * </ul>
< *
< * Deprecated, since the Criteria is deprecated.
< *
< * @param criteria A Criteria.
< * @exception MessagingException.
< */
< protected void initCriteria( Criteria criteria )
< throws MessagingException
< {
< super.initCriteria(criteria);
<
< if( criteria.containsKey( EMAIL_BODY ) )
< setMsg( criteria.getString( EMAIL_BODY ) );
< else
< setMsg("NO MESSAGE");
<
< Vector attachments;
<
< if( criteria.containsKey(ATTACHMENTS ) )
< attachments = (Vector)criteria.get( ATTACHMENTS );
< else
< attachments = new Vector();
<
< if( criteria.containsKey(FILE_SERVER) )
< fileServer = criteria.getString(FILE_SERVER);
<
< for (int i=0; i<attachments.size(); i++)
< {
< EmailAttachment attachment =
< (EmailAttachment)attachments.elementAt(i);
< attach( attachment );
< }
< }
<
< /**
---
> /**
258,261c179
< return attach(url,
< attachment.getName(),
< attachment.getDescription(),
< attachment.getDisposition() );
---
> return attach(url, attachment.getName(), attachment.getDescription(),
>attachment.getDisposition() );
274,276c192
< public MultiPartEmail attach( URL url,
< String name,
< String description )
---
> public MultiPartEmail attach( URL url, String name, String description )
292,295c208
< public MultiPartEmail attach( URL url,
< String name,
< String description,
< String disposition)
---
> public MultiPartEmail attach( URL url, String name, String description, String
>disposition)
310,312c223
< public MultiPartEmail attach( DataSource ds,
< String name,
< String description)
---
> public MultiPartEmail attach( DataSource ds, String name, String description)
328,331c239
< public MultiPartEmail attach( DataSource ds,
< String name,
< String description,
< String disposition)
---
> public MultiPartEmail attach( DataSource ds, String name, String description,
>String disposition)
The command completed successfully.
Index: ./src/adapter/org/apache/turbine/util/mail/ByteArrayDataSource.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine/src/adapter/org/apache/turbine/util/mail/ByteArrayDataSource.java,v
retrieving revision 1.1
diff -r1.1 ByteArrayDataSource.java
74a75
> * @author <a href="mailto:[EMAIL PROTECTED]">Colin Chalmers</a>
77c78
< * @version $Id: ByteArrayDataSource.java,v 1.1 2001/07/10 00:39:39 jvanzyl Exp $
---
> * @version $Id: ByteArrayDataSource.java,v 1.2 2001/07/23 00:39:39 jvanzyl Exp $
82,84c83,85
< /** Data. */
< private byte[] data;
<
---
> /** Stream containg the Data */
> private ByteArrayOutputStream Bos = null;
>
86,88c87
< private String type;
<
< private ByteArrayOutputStream baos;
---
> private String type = "application/octet-stream";
89a89,95
> /**
> * Default constructor
> *
> */
> public ByteArrayDataSource()
> {
> }
95a102
> * @exception IOException.
97,98c104,105
< public ByteArrayDataSource(byte[] data,
< String type)
---
> public ByteArrayDataSource(byte[] data, String type)
> throws IOException
100,101c107,131
< this.data = data;
< this.type = type;
---
> ByteArrayInputStream Bis = null;
>
> try
> {
> Bis = new ByteArrayInputStream(data);
> this.ByteArrayDataSource(Bis, type);
> }
> catch (IOException ioex)
> {
> throw ioex;
> }
> finally
> {
> try
> {
> if (Bis != null)
> {
> Bis.close();
> }
> }
> catch (IOException ignored)
> {
> // Ignore
> }
> }
108a139,152
> * @exception IOException.
> */
> public ByteArrayDataSource(InputStream aIs, String type)
> throws IOException
> {
> this.ByteArrayDataSource(aIs, type);
> }
>
> /**
> * Create a datasource from an input stream.
> *
> * @param is An InputStream.
> * @param type A String.
> * @exception IOException.
110,111c154,155
< public ByteArrayDataSource(InputStream is,
< String type)
---
> private void ByteArrayDataSource(InputStream aIs, String type)
> throws IOException
113a158,161
>
> BufferedInputStream Bis = null;
> BufferedOutputStream osWriter = null;
>
116,126c164,178
< int ch;
<
< ByteArrayOutputStream os = new ByteArrayOutputStream();
< BufferedInputStream isReader = new BufferedInputStream( is );
< BufferedOutputStream osWriter = new BufferedOutputStream( os );
<
< while ((ch = isReader.read()) != -1)
< {
< osWriter.write(ch);
< }
< data = os.toByteArray();
---
> int length = 0;
> byte[] buffer = new byte[512];
>
> Bis = new BufferedInputStream( aIs );
> Bos = new ByteArrayOutputStream();
> osWriter = new BufferedOutputStream( Bos );
>
> //Write the InputData to OutputStream
>
> while ((length = Bis.read(buffer)) != -1)
> {
> osWriter.write(buffer, 0 , length);
> }
> osWriter.flush();
> osWriter.close();
>
130c182
< // Do something!
---
> throw ioex;
131a184,205
> finally
> {
> try
> {
> if (Bis != null)
> {
> Bis.close();
> }
> if (Bos != null)
> {
> Bos.close();
> }
> if (osWriter != null)
> {
> osWriter.close();
> }
> }
> catch (IOException ignored)
> {
> // Ignore
> }
> }
133c207
<
---
>
138a213
> * @exception IOException.
140,141c215,216
< public ByteArrayDataSource(String data,
< String type)
---
> public ByteArrayDataSource(String data, String type)
> throws IOException
143a219
>
145a222,223
> Bos = new ByteArrayOutputStream();
>
149c227,229
< this.data = data.getBytes("iso-8859-1");
---
> Bos.write(data.getBytes("iso-8859-1"));
> Bos.flush();
> Bos.close();
154a235,252
> catch (IOException ignored)
> {
> // Ignore
> }
> finally
> {
> try
> {
> if (Bos != null)
> {
> Bos.close();
> }
> }
> catch (IOException ignored)
> {
> // Ignore
> }
> }
164,167c262
< if ( type == null )
< return "application/octet-stream";
< else
< return type;
---
> return this.type;
179,181c274
< if (data == null)
< throw new IOException("no data");
< return new ByteArrayInputStream(data);
---
> return new ByteArrayInputStream(Bos.toByteArray());
192a286
>
194,205c288,300
< /**
< * Get the output stream.
< *
< * @return An OutputStream.
< * @exception IOException.
< */
< public OutputStream getOutputStream()
< throws IOException
< {
< baos = new ByteArrayOutputStream();
< return baos;
< }
---
>
>
> /**
> * Get the OutputStream to write to
> *
> * @return An OutputStream
> * @exception IOException
> */
> public OutputStream getOutputStream()
> throws IOException
> {
> return Bos = new ByteArrayOutputStream();
> }
The command completed successfully.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]