Petals BC MAIL

Add content-type parameter

Details

  • Type: New Feature New Feature
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 3.1.2
  • Fix Version/s: 3.2
  • Component/s: None
  • Security Level: Public
  • Description:
    Hide

    Currently, the body content type is always set to text/plain.
    A new parameter in the payload should allow to set this value dynamically, to send HTML emails for instance.
    This parameter should be optional.

    Here is a patch proposal, developed from the svn trunk, adding a "content-type" parameter :

        1. Eclipse Workspace Patch 1.0
          #P petals-bc-mail
          Index: src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptor.java
          ===================================================================
        • src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptor.java (revision 15640)
          +++ src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptor.java (working copy)
          @@ -100,6 +100,11 @@
          */
          private String body;

    + /**
    + * Body content type
    + */
    + private String contentType;
    +
    private String sendMode;

    public String getSendMode() { @@ -114,7 +119,11 @@ return this.body; }

    • public String getFolder() {
      + public String getContentType() { + return contentType; + }
      +
      + public String getFolder() { return this.folder; }

    @@ -166,6 +175,10 @@
    this.body = body;
    }

    + public void setContentType(String contentType) { + this.contentType = contentType; + }
    +
    public void setDelete(boolean delete) { this.delete = delete; }
    Index: src/main/java/org/ow2/petals/bc/mail/listeners/MimeMessageManager.java
    ===================================================================
    — src/main/java/org/ow2/petals/bc/mail/listeners/MimeMessageManager.java (revision 15640)
    +++ src/main/java/org/ow2/petals/bc/mail/listeners/MimeMessageManager.java (working copy)
    @@ -40,6 +40,7 @@
    import javax.mail.internet.MimeMultipart;

    import org.ow2.petals.bc.mail.Constants;
    +import org.ow2.petals.bc.mail.listeners.SessionDescriptor;
    import org.ow2.petals.component.framework.bc.AbstractBindingComponent;
    import org.ow2.petals.component.framework.util.UtilFactory;

    @@ -99,7 +100,7 @@
    final Multipart multipart = new MimeMultipart();
    if (!sendMode.equalsIgnoreCase(Constants.SEND_MODE_ATTACHMENTSONLY)) { // Set MimeMessage body - this.setMimeMessageBody(multipart, in); + this.setMimeMessageBody(multipart, in, descriptor.getContentType()); }
    if (!sendMode.equalsIgnoreCase(Constants.SEND_MODE_CONTENTONLY)) {
    // Set MimeMessage attachements
    @@ -194,13 +195,13 @@

    • @throws JBIException
    • if the {@link Multipart} body setting failed
      */
    • protected void setMimeMessageBody(Multipart multipart, NormalizedMessage in)
      + protected void setMimeMessageBody(Multipart multipart, NormalizedMessage in, String contentType)
      throws JBIException {
      String content = null;
      try
      Unknown macro: { if (in.getContent() != null) { content = UtilFactory.getSourceUtil().createString(in.getContent()); - this.setMimeMessageBody(multipart, content); + this.setMimeMessageBody(multipart, content, contentType); } }
      catch (final Exception e) {
      throw new JBIException(e.getMessage());
      @@ -217,11 +218,11 @@
    • the content
    • @throws MessagingException
      */
    • protected void setMimeMessageBody(Multipart multipart, String content)
      + protected void setMimeMessageBody(Multipart multipart, String content, String contentType)
      throws MessagingException { this.log.finest("set the email body"); final MimeBodyPart messageBodyPart = new MimeBodyPart(); - messageBodyPart.setContent(content, "text/plain"); + messageBodyPart.setContent(content, contentType); multipart.addBodyPart(messageBodyPart); }
      }
      Index: src/main/java/org/ow2/petals/bc/mail/Constants.java
      ===================================================================
        • src/main/java/org/ow2/petals/bc/mail/Constants.java (revision 15640)
          +++ src/main/java/org/ow2/petals/bc/mail/Constants.java (working copy)
          @@ -28,6 +28,8 @@
          public interface Constants {

    public static final String BODY_PATHELEMENT = "body";
    +
    + public static final String CONTENTTYPE_PATHELEMENT = "content-type";

    // If true in CONSUMES mode, assume default mail content is XML
    public static final String IS_XML_CONTENT = "isxmlcontent";
    Index: src/main/java/org/ow2/petals/bc/mail/service/SendMailGenericService.java
    ===================================================================
    — src/main/java/org/ow2/petals/bc/mail/service/SendMailGenericService.java (revision 15640)
    +++ src/main/java/org/ow2/petals/bc/mail/service/SendMailGenericService.java (working copy)
    @@ -112,7 +112,7 @@
    // with the 'body' element of the jbi message
    final Multipart multipart = (Multipart) mimeMessage.getContent();
    final BodyPart messageBodyPart = multipart.getBodyPart(0);

    • messageBodyPart.setContent(sessionDescriptor.getBody(), "text/plain");
      + messageBodyPart.setContent(sessionDescriptor.getBody(), sessionDescriptor.getContentType());

    // Send this mail
    if (this.logger.isLoggable(Level.FINEST)) { Index: src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptorBuilder.java =================================================================== --- src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptorBuilder.java (revision 15640) +++ src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptorBuilder.java (working copy) @@ -267,6 +267,16 @@ } else { throw new MissingElementException(Constants.BODY_PATHELEMENT); }
    +
    + final Node contentTypeNode = XMLUtil.findChild(rootNode, Constants.CONTENTTYPE_PATHELEMENT, null, false);
    + String contentType = null;
    + if (contentTypeNode != null) { + contentType = contentTypeNode.getTextContent(); + } else { + contentType = "text/plain"; + }
    + sessionDescriptor.setContentType(contentType);
    +
    this.checkProperties(sessionDescriptor);
    return sessionDescriptor;
    }

    Show
    Currently, the body content type is always set to text/plain. A new parameter in the payload should allow to set this value dynamically, to send HTML emails for instance. This parameter should be optional. Here is a patch proposal, developed from the svn trunk, adding a "content-type" parameter :
        1. Eclipse Workspace Patch 1.0 #P petals-bc-mail Index: src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptor.java ===================================================================
        • src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptor.java (revision 15640) +++ src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptor.java (working copy) @@ -100,6 +100,11 @@ */ private String body;
    + /** + * Body content type + */ + private String contentType; + private String sendMode; public String getSendMode() { @@ -114,7 +119,11 @@ return this.body; }
    • public String getFolder() { + public String getContentType() { + return contentType; + } + + public String getFolder() { return this.folder; }
    @@ -166,6 +175,10 @@ this.body = body; } + public void setContentType(String contentType) { + this.contentType = contentType; + } + public void setDelete(boolean delete) { this.delete = delete; } Index: src/main/java/org/ow2/petals/bc/mail/listeners/MimeMessageManager.java =================================================================== — src/main/java/org/ow2/petals/bc/mail/listeners/MimeMessageManager.java (revision 15640) +++ src/main/java/org/ow2/petals/bc/mail/listeners/MimeMessageManager.java (working copy) @@ -40,6 +40,7 @@ import javax.mail.internet.MimeMultipart; import org.ow2.petals.bc.mail.Constants; +import org.ow2.petals.bc.mail.listeners.SessionDescriptor; import org.ow2.petals.component.framework.bc.AbstractBindingComponent; import org.ow2.petals.component.framework.util.UtilFactory; @@ -99,7 +100,7 @@ final Multipart multipart = new MimeMultipart(); if (!sendMode.equalsIgnoreCase(Constants.SEND_MODE_ATTACHMENTSONLY)) { // Set MimeMessage body - this.setMimeMessageBody(multipart, in); + this.setMimeMessageBody(multipart, in, descriptor.getContentType()); } if (!sendMode.equalsIgnoreCase(Constants.SEND_MODE_CONTENTONLY)) { // Set MimeMessage attachements @@ -194,13 +195,13 @@
    • @throws JBIException
    • if the {@link Multipart} body setting failed */
    • protected void setMimeMessageBody(Multipart multipart, NormalizedMessage in) + protected void setMimeMessageBody(Multipart multipart, NormalizedMessage in, String contentType) throws JBIException { String content = null; try
      Unknown macro: { if (in.getContent() != null) { content = UtilFactory.getSourceUtil().createString(in.getContent()); - this.setMimeMessageBody(multipart, content); + this.setMimeMessageBody(multipart, content, contentType); } }
      catch (final Exception e) { throw new JBIException(e.getMessage()); @@ -217,11 +218,11 @@
    • the content
    • @throws MessagingException */
    • protected void setMimeMessageBody(Multipart multipart, String content) + protected void setMimeMessageBody(Multipart multipart, String content, String contentType) throws MessagingException { this.log.finest("set the email body"); final MimeBodyPart messageBodyPart = new MimeBodyPart(); - messageBodyPart.setContent(content, "text/plain"); + messageBodyPart.setContent(content, contentType); multipart.addBodyPart(messageBodyPart); } } Index: src/main/java/org/ow2/petals/bc/mail/Constants.java ===================================================================
        • src/main/java/org/ow2/petals/bc/mail/Constants.java (revision 15640) +++ src/main/java/org/ow2/petals/bc/mail/Constants.java (working copy) @@ -28,6 +28,8 @@ public interface Constants {
    public static final String BODY_PATHELEMENT = "body"; + + public static final String CONTENTTYPE_PATHELEMENT = "content-type"; // If true in CONSUMES mode, assume default mail content is XML public static final String IS_XML_CONTENT = "isxmlcontent"; Index: src/main/java/org/ow2/petals/bc/mail/service/SendMailGenericService.java =================================================================== — src/main/java/org/ow2/petals/bc/mail/service/SendMailGenericService.java (revision 15640) +++ src/main/java/org/ow2/petals/bc/mail/service/SendMailGenericService.java (working copy) @@ -112,7 +112,7 @@ // with the 'body' element of the jbi message final Multipart multipart = (Multipart) mimeMessage.getContent(); final BodyPart messageBodyPart = multipart.getBodyPart(0);
    • messageBodyPart.setContent(sessionDescriptor.getBody(), "text/plain"); + messageBodyPart.setContent(sessionDescriptor.getBody(), sessionDescriptor.getContentType());
    // Send this mail if (this.logger.isLoggable(Level.FINEST)) { Index: src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptorBuilder.java =================================================================== --- src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptorBuilder.java (revision 15640) +++ src/main/java/org/ow2/petals/bc/mail/listeners/SessionDescriptorBuilder.java (working copy) @@ -267,6 +267,16 @@ } else { throw new MissingElementException(Constants.BODY_PATHELEMENT); } + + final Node contentTypeNode = XMLUtil.findChild(rootNode, Constants.CONTENTTYPE_PATHELEMENT, null, false); + String contentType = null; + if (contentTypeNode != null) { + contentType = contentTypeNode.getTextContent(); + } else { + contentType = "text/plain"; + } + sessionDescriptor.setContentType(contentType); + this.checkProperties(sessionDescriptor); return sessionDescriptor; }
  • Environment:
    petals-bc-mail 3.1.2, petals-platform 3.0.5, Windows and RHEL 5.5
  1. patch bc-mail.txt
    (6 kB)
    Logica DGME
    Mon, 30 Aug 2010 - 18:02:12 +0200

Activity

Hide
Logica DGME added a comment - Mon, 30 Aug 2010 - 18:02:12 +0200

proposed patch

Show
Logica DGME added a comment - Mon, 30 Aug 2010 - 18:02:12 +0200 proposed patch
Logica DGME made changes - Mon, 30 Aug 2010 - 18:02:12 +0200
Field Original Value New Value
Attachment patch bc-mail.txt [ 10246 ]
Mathieu Carrolle made changes - Fri, 7 Jan 2011 - 17:16:03 +0100
Original Estimate 0 minutes [ 0 ]
Remaining Estimate 0 minutes [ 0 ]
Fix Version/s 3.2 [ 10055 ]
Mathieu Carrolle made changes - Fri, 7 Jan 2011 - 17:16:25 +0100
Status New [ 10000 ] Open [ 10002 ]
Priority Major [ 3 ]
Mathieu Carrolle made changes - Fri, 7 Jan 2011 - 17:16:32 +0100
Status Open [ 10002 ] In Progress [ 10003 ]
Mathieu Carrolle made changes - Fri, 7 Jan 2011 - 17:38:10 +0100
Status In Progress [ 10003 ] Resolved [ 10004 ]
Resolution Fixed [ 1 ]
Transition Status Change Time Execution Times Last Executer Last Execution Date
New New Open Open
130d 15m
1
Mathieu Carrolle
Fri, 7 Jan 2011 - 17:16:25 +0100
Open Open In Progress In Progress
7s
1
Mathieu Carrolle
Fri, 7 Jan 2011 - 17:16:32 +0100
In Progress In Progress Resolved Resolved
21m 38s
1
Mathieu Carrolle
Fri, 7 Jan 2011 - 17:38:10 +0100



People

Dates

  • Created:
    Mon, 30 Aug 2010 - 18:00:54 +0200
    Updated:
    Fri, 7 Jan 2011 - 17:38:10 +0100
    Resolved:
    Fri, 7 Jan 2011 - 17:38:10 +0100