You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by ca...@apache.org on 2001/05/21 20:08:56 UTC

cvs commit: jakarta-taglibs/mailer/src/org/apache/taglibs/mailer MailTag.java

catlett     01/05/21 11:08:55

  Modified:    mailer/src/org/apache/taglibs/mailer MailTag.java
  Log:
  support for mail attachments has been added
  
  Revision  Changes    Path
  1.4       +99 -24    jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MailTag.java
  
  Index: MailTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MailTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MailTag.java	2001/04/23 22:37:53	1.3
  +++ MailTag.java	2001/05/21 18:08:46	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MailTag.java,v 1.3 2001/04/23 22:37:53 catlett Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/04/23 22:37:53 $
  + * $Header: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MailTag.java,v 1.4 2001/05/21 18:08:46 catlett Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/05/21 18:08:46 $
    *
    * ====================================================================
    *
  @@ -70,7 +70,7 @@
   import javax.mail.internet.*;
   
   /**
  - * ToTag - JSP tag <b>Mail</b> is used to construct an email message.
  + * MailTag - JSP tag <b>Mail</b> is used to construct an email message.
    *
    * <tag>
    *      <name>mail</name>
  @@ -119,7 +119,7 @@
    *              <rtexprvalue>false</rtexprvalue>
    *      </attribute>
    *      <attribute>
  - *              <name>type</name>
  + *              <name>authentication</name>
    *              <required>false</required>
    *              <rtexprvalue>false</rtexprvalue>
    *      </attribute>
  @@ -164,7 +164,7 @@
       /**
        * can be "text" or "html" (otherwise text is default)
        */
  -    private String type = "text";
  +    private String type = "text/plain";
       /**
        * jndi name for Session object
        */
  @@ -194,9 +194,23 @@
        */
       private ArrayList value = new ArrayList(10);
       /**
  +     * list of attachments stored as mimebodyparts
  +     */
  +    private ArrayList bodyparts = new ArrayList(10);
  +    /**
  +     * flag that lets the send tag know if attachments are being sent
  +     */
  +    private boolean attachments = false;
  +    /**
        * flag determines if an error has occured
        */
       private boolean error = false;
  +    /**
  +     * flag that determines if the session for sending mail should have an
  +     * authenticator so that user name and password can be entered if it is 
  +     * required for the mail server
  +     */
  +    private boolean authentication = false;
   
       /**
        * implementation of method from the Tag interface that tells the JSP what
  @@ -254,8 +268,18 @@
   	    props.put("mail.smtp.dsn.notify", "FAILURE");
   	    // set amount of message to get returned
   	    props.put("mail.smtp.dsn.ret", "FULL");
  -	    // create new piece of mail for the smtp mail session
  -	    sessionobj = Session.getDefaultInstance(props, null);
  +	    // create new piece of mail for the smtp mail session check if 
  +	    // authentication is required for the mail server
  +
  +
  +	    //the use of authentication is a work in progress
  +
  +	    //if (authentication)
  +		// create the session with an authenticator object
  +		//sessionobj = Session.getDefaultInstance(props, new Authenticator());
  +	    //else
  +		sessionobj = Session.getDefaultInstance(props, null);
  +
   	    message = new MimeMessage(sessionobj);
   	}
   
  @@ -301,6 +325,26 @@
       }
   
       /**
  +     * get the list of attachments
  +     *
  +     * @return - an arraylist of the mimebodyparts for attachments
  +     *
  +     */
  +    public final ArrayList getBodyParts() {
  +	return bodyparts;
  +    }
  +
  +    /**
  +     * get the attachments flat
  +     *
  +     * @return - the flag that lets the message know if there are attachments
  +     *
  +     */
  +    public final boolean getAttachments() {
  +	return attachments;
  +    }
  +
  +    /**
        * get the to address for this email
        *
        * @return - the address to whom this mail is to be sent
  @@ -430,7 +474,7 @@
        *
        */
       public final void setTo(String value) {
  -	to = value.trim();
  +	to = value;
       }
   
       /**
  @@ -440,7 +484,7 @@
        *
        */
       public final void setReplyTo(String value) {
  -	replyto = value.trim();
  +	replyto = value;
       }
   
       /**
  @@ -450,7 +494,7 @@
        *
        */
       public final void setFrom(String value) {
  -	from = value.trim();
  +	from = value;
       }
   
       /**
  @@ -461,7 +505,7 @@
        *
        */
       public final void setCc(String value) {
  -	cc = value.trim();
  +	cc = value;
       }
   
       /**
  @@ -472,7 +516,7 @@
        *
        */
       public final void setBcc(String value) {
  -	bcc = value.trim();
  +	bcc = value;
       }
   
       /**
  @@ -482,7 +526,7 @@
        *
        */
       public final void setSubject(String value) {
  -	subject = value.trim();
  +	subject = value;
       }
   
       /**
  @@ -492,7 +536,7 @@
        *
        */
       public final void setHeaderName(String value) {
  -	name.add(value.trim());
  +	name.add(value);
       }
   
       /**
  @@ -502,7 +546,7 @@
        *
        */
       public final void setHeaderValue(String value) {
  -	this.value.add(value.trim());
  +	this.value.add(value);
       }
   
       /**
  @@ -512,7 +556,23 @@
        *
        */
       public final void setMessage(String value) {
  -	body = value.trim();
  +	body = value;
  +    }
  +
  +    /**
  +     * set attachments into an arraylist
  +     *
  +     * @param mbp  mimebodypart to be attached to the e-mail
  +     *
  +     */
  +    public final void setBodyParts(MimeBodyPart mbp) {
  +	bodyparts.add(mbp);
  +
  +	// set attachments to true since the possibility of multiple attachments
  +	// exists there is no sence in setting attachments to true everytime one
  +	// is set
  +	if (attachments == false)
  +	    attachments = true;
       }
   
       /**
  @@ -546,13 +606,28 @@
       }
   
       /**
  +     * set authentication flag
  +     *
  +     * @param value  boolean value that marks if an authenticator object should
  +     *               be used in the creation of the session so that user
  +     *               authentication can be performed
  +     *
  +     */
  +    public final void setAuthentication(String value) {
  +	authentication = new Boolean(value).booleanValue();
  +    }
  +
  +    /**
        * set the mime type for this email text or html
        *
        * @param value  string that is the mime type for this email
        *
        */
       public final void setType(String value) {
  -	type = value;
  +	if (value.equalsIgnoreCase("html"))
  +	    type = "text/html";
  +	else
  +	    type = "text/plain";
       }
   
       /**
  @@ -563,9 +638,9 @@
        */
       public final void addTo(String value) {
   	if (to == null)
  -	    to = value.trim();
  +	    to = value;
   	else
  -	    to = to.concat("," + value.trim());
  +	    to = to.concat("," + value);
       }
   
       /**
  @@ -577,9 +652,9 @@
        */
       public final void addCc(String value) {
   	if (cc == null)
  -	    cc = value.trim();
  +	    cc = value;
   	else
  -	    cc = cc.concat("," + value.trim());
  +	    cc = cc.concat("," + value);
       }
   
       /**
  @@ -591,9 +666,9 @@
        */
       public final void addBcc(String value) {
   	if (bcc == null)
  -	    bcc = value.trim();
  +	    bcc = value;
   	else
  -	    bcc = bcc.concat("," + value.trim());
  +	    bcc = bcc.concat("," + value);
       }
   }