You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2002/09/18 00:44:10 UTC

cvs commit: jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/template TemplateEmail.java

jmcnally    2002/09/17 15:44:10

  Modified:    src/java/org/apache/fulcrum/template TemplateEmail.java
  Log:
  added the ability to set the encoding for the email and to set headers.
  
  Revision  Changes    Path
  1.4       +55 -24    jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/template/TemplateEmail.java
  
  Index: TemplateEmail.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/template/TemplateEmail.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TemplateEmail.java	26 Jul 2002 20:30:46 -0000	1.3
  +++ TemplateEmail.java	17 Sep 2002 22:44:10 -0000	1.4
  @@ -57,6 +57,7 @@
   import java.util.ArrayList;
   import java.util.List;
   import java.util.Iterator;
  +import java.io.StringWriter;
   import javax.mail.internet.InternetAddress;
   import org.apache.commons.mail.SimpleEmail;
   import org.apache.commons.lang.StringUtils;
  @@ -178,6 +179,11 @@
       private TemplateContext context = null;
   
       /**
  +     * The charset
  +     */
  +    private String charset = null;
  +
  +    /**
        * Constructor
        */
       public TemplateEmail()
  @@ -250,6 +256,18 @@
           }
       }
   
  +
  +    /**
  +     * The given Unicode string will be charset-encoded using the specified 
  +     * charset. The charset is also used to set the "charset" parameter.
  +     *
  +     * @param charset a <code>String</code> value
  +     */
  +    public void setCharset(String charset)
  +    {
  +        this.charset = charset;
  +    }
  +
       /**
        * To: name, email
        *
  @@ -317,6 +335,19 @@
           return this;
       }
   
  +    private List headersList;
  +    public TemplateEmail addHeader(String name, String value)
  +    {
  +        String[] pair = new String[2];
  +        pair[0] = name;
  +        pair[1] = value;
  +        if (headersList == null) 
  +        {
  +            headersList = new ArrayList(3);
  +        }        
  +        headersList.add(pair);
  +        return this;
  +    }
   
       /**
        * Subject.
  @@ -403,28 +434,11 @@
               throw new Exception ("Must set a To:");
           }
   
  -        // Process the template.
  -        String body = TurbineTemplate.handleRequest(context,template);
  -
  -        // If the caller desires word-wrapping, do it here
  -        if (wordWrap > 0)
  -        {
  -            body = WordWrapper.wrapText (body,
  -                                     System.getProperty("line.separator"),
  -                                     wordWrap);
  -        }
  -
  -        SimpleEmail se = new SimpleEmail();
  -        se.setFrom(fromEmail, fromName);
  -        se.addTo(toEmail, toName);
  -        if (ccEmail != null && ccName != null)
  -        {
  -            se.addCc(ccEmail, ccName);
  -        }
  -        addReplyTo(se);
  -        se.setSubject(subject);
  -        se.setMsg(body);
  -        se.send();
  +        // this method is only supposed to send to one user (additional cc:
  +        // users are ok.)
  +        toList = null;
  +        addTo(toEmail, toName);
  +        sendMultiple();
       }
   
       /**
  @@ -439,7 +453,9 @@
           }
   
           // Process the template.
  -        String body = TurbineTemplate.handleRequest(context,template);
  +        StringWriter sw = new StringWriter();
  +        TurbineTemplate.handleRequest(context,template, sw);
  +        String body = sw.toString();
   
           // If the caller desires word-wrapping, do it here
           if (wordWrap > 0)
  @@ -457,8 +473,23 @@
               se.setCc(ccList);
           }
           addReplyTo(se);
  +        if (charset != null) 
  +        {
  +            se.setCharset(charset);            
  +        }
           se.setSubject(subject);
           se.setMsg(body);
  +
  +        if (headersList != null) 
  +        {
  +            Iterator i = headersList.iterator();
  +            while (i.hasNext()) 
  +            {
  +                String[] pair = (String[])i.next();
  +                se.addHeader(pair[0], pair[1]);
  +            }
  +        }
  +        
           se.send();
       }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-turbine-fulcrum/src/java/org/apache/fulcrum/template TemplateEmail.java

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
jmcnally@apache.org writes:

>  +    private List headersList;
>  +    public TemplateEmail addHeader(String name, String value)
>  +    {
>  +        String[] pair = new String[2];
>  +        pair[0] = name;
>  +        pair[1] = value;
>  +        if (headersList == null) 
>  +        {
>  +            headersList = new ArrayList(3);
>  +        }        
>  +        headersList.add(pair);
>  +        return this;
>  +    }

How I _hate_ things like this. Jon S. Stevens, where is the style police?

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>