You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by pa...@apache.org on 2020/01/25 10:25:06 UTC

[ofbiz-framework] branch trunk updated: Fixed: Potensial bug under CommunicationEventServices#updateCommEventAfterEmail for CommunicationEvent.subject field (OFBIZ-10879)

This is an automated email from the ASF dual-hosted git repository.

pawan pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 832076c  Fixed: Potensial bug under CommunicationEventServices#updateCommEventAfterEmail for CommunicationEvent.subject field (OFBIZ-10879)
832076c is described below

commit 832076ce91dbca182ffab38d27ea72ca5e2cb0be
Author: Pawan Verma <pa...@hotwaxsystems.com>
AuthorDate: Sat Jan 25 15:54:37 2020 +0530

    Fixed: Potensial bug under CommunicationEventServices#updateCommEventAfterEmail for CommunicationEvent.subject field
    (OFBIZ-10879)
    
    CommunicationEventServices#updateCommEventAfterEmail could generate wrong result. If general.properties value 'mail.notifications.redirectTo' is used, it is possible that the subject string has more than 255 character.
    
    Thanks, Ulrich Heidfeld for your contribution.
---
 .../communication/CommunicationEventServices.java  | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
index 85f1134..dfb6012 100644
--- a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
+++ b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
@@ -43,6 +43,7 @@ import javax.mail.internet.InternetAddress;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
@@ -823,6 +824,7 @@ public class CommunicationEventServices {
      */
     public static Map<String, Object> updateCommEventAfterEmail(DispatchContext dctx, Map<String, ? extends Object> context) {
         LocalDispatcher dispatcher = dctx.getDispatcher();
+        Delegator delegator = dctx.getDelegator();
 
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         String communicationEventId = (String) context.get("communicationEventId");
@@ -838,6 +840,27 @@ public class CommunicationEventServices {
         commEventMap.put("userLogin", userLogin);
         commEventMap.put("content", wrapper.getMessageBody());
 
+        String subject = wrapper.getSubject();
+        String redirectAddress = EntityUtilProperties.getPropertyValue("general",
+                "mail.notifications.redirectTo", delegator);
+        if (UtilValidate.isNotEmpty(redirectAddress) && subject.endsWith("]") && subject.contains(" [To: ")) {
+            // Format of subject for redirected mail from sendMail service:
+            // "Original subject [To: <sendTo>, Cc: <sendCc>, Bcc: <sendBcc>]"
+            String origSendTo = StringUtils.substringBetween(subject, "[To: ", ", Cc:");
+            String origSendCc = StringUtils.substringBetween(subject, ", Cc: ", ", Bcc:");
+            String origSendBcc = StringUtils.substringBetween(subject, ", Bcc: ", "]");
+
+            // ignore "null" Strings in subject
+            if (origSendTo != "null") commEventMap.put("toString", origSendTo);
+            if (origSendCc != "null") commEventMap.put("ccString", origSendCc);
+            if (origSendBcc != "null") commEventMap.put("bccString", origSendBcc);
+
+            // Format of subject in commEvent: "Original subject [RedirectedTo: recipient@example.com]" 
+            subject = StringUtils.substringBefore(subject, "[To: ")
+                    + "[RedirectedTo: " + commEventMap.get("fromString") + "]";
+            commEventMap.put("subject", StringUtils.abbreviate(subject, 255));
+        }
+
         // populate the address (to/from/cc/bcc) data
         populateAddressesFromMessage(wrapper, commEventMap);
 


Re: [ofbiz-framework] branch trunk updated: Fixed: Potensial bug under CommunicationEventServices#updateCommEventAfterEmail for CommunicationEvent.subject field (OFBIZ-10879)

Posted by Deepak Dixit <de...@hotwax.co>.
I think this is not the right fix for reported problems.
As we are updating so we don't need to pass the to,cc and bcc. And
redirectTo will be used in dev mode only.
We can fix the subject length only.

IMO we should revert this.

Kind Regards,
Deepak Dixit
DIRECTOR OF PRODUCT ENGINEERING
mobile: +91 9826754548
email: deepak.dixit@hotwax.co
*www.hotwax.co <http://www.hotwax.co/>*


On Sat, Jan 25, 2020 at 3:55 PM <pa...@apache.org> wrote:

> This is an automated email from the ASF dual-hosted git repository.
>
> pawan pushed a commit to branch trunk
> in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
>
>
> The following commit(s) were added to refs/heads/trunk by this push:
>      new 832076c  Fixed: Potensial bug under
> CommunicationEventServices#updateCommEventAfterEmail for
> CommunicationEvent.subject field (OFBIZ-10879)
> 832076c is described below
>
> commit 832076ce91dbca182ffab38d27ea72ca5e2cb0be
> Author: Pawan Verma <pa...@hotwaxsystems.com>
> AuthorDate: Sat Jan 25 15:54:37 2020 +0530
>
>     Fixed: Potensial bug under
> CommunicationEventServices#updateCommEventAfterEmail for
> CommunicationEvent.subject field
>     (OFBIZ-10879)
>
>     CommunicationEventServices#updateCommEventAfterEmail could generate
> wrong result. If general.properties value 'mail.notifications.redirectTo'
> is used, it is possible that the subject string has more than 255 character.
>
>     Thanks, Ulrich Heidfeld for your contribution.
> ---
>  .../communication/CommunicationEventServices.java  | 23
> ++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git
> a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
> b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
> index 85f1134..dfb6012 100644
> ---
> a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
> +++
> b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
> @@ -43,6 +43,7 @@ import javax.mail.internet.InternetAddress;
>  import javax.servlet.http.HttpServletRequest;
>  import javax.servlet.http.HttpServletResponse;
>
> +import org.apache.commons.lang.StringUtils;
>  import org.apache.ofbiz.base.location.FlexibleLocation;
>  import org.apache.ofbiz.base.util.Debug;
>  import org.apache.ofbiz.base.util.GeneralException;
> @@ -823,6 +824,7 @@ public class CommunicationEventServices {
>       */
>      public static Map<String, Object>
> updateCommEventAfterEmail(DispatchContext dctx, Map<String, ? extends
> Object> context) {
>          LocalDispatcher dispatcher = dctx.getDispatcher();
> +        Delegator delegator = dctx.getDelegator();
>
>          GenericValue userLogin = (GenericValue) context.get("userLogin");
>          String communicationEventId = (String)
> context.get("communicationEventId");
> @@ -838,6 +840,27 @@ public class CommunicationEventServices {
>          commEventMap.put("userLogin", userLogin);
>          commEventMap.put("content", wrapper.getMessageBody());
>
> +        String subject = wrapper.getSubject();
> +        String redirectAddress =
> EntityUtilProperties.getPropertyValue("general",
> +                "mail.notifications.redirectTo", delegator);
> +        if (UtilValidate.isNotEmpty(redirectAddress) &&
> subject.endsWith("]") && subject.contains(" [To: ")) {
> +            // Format of subject for redirected mail from sendMail
> service:
> +            // "Original subject [To: <sendTo>, Cc: <sendCc>, Bcc:
> <sendBcc>]"
> +            String origSendTo = StringUtils.substringBetween(subject,
> "[To: ", ", Cc:");
> +            String origSendCc = StringUtils.substringBetween(subject, ",
> Cc: ", ", Bcc:");
> +            String origSendBcc = StringUtils.substringBetween(subject, ",
> Bcc: ", "]");
> +
> +            // ignore "null" Strings in subject
> +            if (origSendTo != "null") commEventMap.put("toString",
> origSendTo);
> +            if (origSendCc != "null") commEventMap.put("ccString",
> origSendCc);
> +            if (origSendBcc != "null") commEventMap.put("bccString",
> origSendBcc);
> +
> +            // Format of subject in commEvent: "Original subject
> [RedirectedTo: recipient@example.com]"
> +            subject = StringUtils.substringBefore(subject, "[To: ")
> +                    + "[RedirectedTo: " + commEventMap.get("fromString")
> + "]";
> +            commEventMap.put("subject", StringUtils.abbreviate(subject,
> 255));
> +        }
> +
>          // populate the address (to/from/cc/bcc) data
>          populateAddressesFromMessage(wrapper, commEventMap);
>
>
>