You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2009/05/12 06:12:19 UTC

svn commit: r773775 - in /logging/log4j/trunk/src: changes/changes.xml main/java/org/apache/log4j/net/SMTPAppender.java

Author: carnold
Date: Tue May 12 04:12:18 2009
New Revision: 773775

URL: http://svn.apache.org/viewvc?rev=773775&view=rev
Log:
Bug 47142: Add SMTPAppender.formatBody to simplify extension

Modified:
    logging/log4j/trunk/src/changes/changes.xml
    logging/log4j/trunk/src/main/java/org/apache/log4j/net/SMTPAppender.java

Modified: logging/log4j/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=773775&r1=773774&r2=773775&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Tue May 12 04:12:18 2009
@@ -77,6 +77,7 @@
        <action action="add" issue="44357">Document system properties used by log4j.</action>
        <action action="fix" issue="44038">log4j is susceptible to exceptions in Exception.printStackTrace.</action>
        <action action="fix" issue="46741">Misuse of "it's" in Javadoc for PatternLayout.</action>
+       <action action="add" issue="47142">Add SMTPAppender.formatBody to simplify extension.</action>
     </release>
 
   

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/net/SMTPAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/net/SMTPAppender.java?rev=773775&r1=773774&r2=773775&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/net/SMTPAppender.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/net/SMTPAppender.java Tue May 12 04:12:18 2009
@@ -332,14 +332,14 @@
   }
 
   /**
-     Send the contents of the cyclic buffer as an e-mail message.
+   * Layout body of email message.
+   * @since 1.2.16  
    */
-  protected
-  void sendBuffer() {
-
-    // Note: this code already owns the monitor for this
-    // appender. This frees us from needing to synchronize on 'cb'.
-    try {
+  protected String formatBody() {
+	  
+	  // Note: this code already owns the monitor for this
+	  // appender. This frees us from needing to synchronize on 'cb'.
+	  
       StringBuffer sbuf = new StringBuffer();
       String t = layout.getHeader();
       if(t != null)
@@ -363,8 +363,18 @@
       if(t != null) {
 	    sbuf.append(t);
       }
+      
+      return sbuf.toString();
+  }
+  
+  /**
+     Send the contents of the cyclic buffer as an e-mail message.
+   */
+  protected
+  void sendBuffer() {
 
-      String s = sbuf.toString();
+    try {
+      String s = formatBody();
       boolean allAscii = true;
       for(int i = 0; i < s.length() && allAscii; i++) {
           allAscii = s.charAt(i) <= 0x7F;
@@ -385,6 +395,7 @@
             headers.setHeader("Content-Transfer-Encoding", "quoted-printable");
             part = new MimeBodyPart(headers, os.toByteArray());
           } catch(Exception ex) {
+              StringBuffer sbuf = new StringBuffer(s);
               for (int i = 0; i < sbuf.length(); i++) {
                   if (sbuf.charAt(i) >= 0x80) {
                       sbuf.setCharAt(i, '?');



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org