You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ha...@apache.org on 2009/05/23 04:19:22 UTC

svn commit: r777768 - in /ofbiz/trunk/applications/party: script/org/ofbiz/party/communication/CommunicationEventServices.xml src/org/ofbiz/party/communication/CommunicationEventServices.java

Author: hansbak
Date: Sat May 23 02:19:21 2009
New Revision: 777768

URL: http://svn.apache.org/viewvc?rev=777768&view=rev
Log:
do not treat incoming email message as a reply, select plain text part for incoming message  improved error message

Modified:
    ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml
    ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java

Modified: ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml?rev=777768&r1=777767&r2=777768&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml (original)
+++ ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml Sat May 23 02:19:21 2009
@@ -33,19 +33,21 @@
     </simple-method>
 
     <simple-method method-name="createCommunicationEvent" short-description="Create a CommunicationEvent with or w/o permission check">
-        <!-- check for forward -->
-        <if-not-empty field="parameters.origCommEventId">
-            <entity-one entity-name="CommunicationEvent" value-field="newEntity">
-                <field-map field-name="communicationEventId" from-field="parameters.origCommEventId"/>
-            </entity-one>
-            <clear-field field="newEntity.communicationEventId"/>
-            <clear-field field="newEntity.partyIdFrom"/>
-            <clear-field field="newEntity.partyIdTo"/>
-            <set field="newEntity.subject" value="Forw: ${newEntity.subject}"/>
-            <else><!-- if not create empty one -->
-                <make-value value-field="newEntity" entity-name="CommunicationEvent"/>
-            </else>
-        </if-not-empty>
+        <!-- check for forward only if created by a user and not incoming email by system-->
+        <if-compare field="parameters.userLogin.userLoginId" value="system" operator="not-equals">
+            <if-not-empty field="parameters.origCommEventId">
+                <entity-one entity-name="CommunicationEvent" value-field="newEntity">
+                    <field-map field-name="communicationEventId" from-field="parameters.origCommEventId"/>
+                </entity-one>
+                <clear-field field="newEntity.communicationEventId"/>
+                <clear-field field="newEntity.partyIdFrom"/>
+                <clear-field field="newEntity.partyIdTo"/>
+                <set field="newEntity.subject" value="Forw: ${newEntity.subject}"/>
+            </if-not-empty>
+        </if-compare>
+        <if-empty field="newEntity">
+            <make-value value-field="newEntity" entity-name="CommunicationEvent"/>
+        </if-empty>
         
         <set-nonpk-fields map="parameters" value-field="newEntity"/>
         
@@ -58,25 +60,26 @@
         <field-to-result field="newEntity.communicationEventId" result-name="communicationEventId"/>
 
         <!-- check for reply -->
-        <if-not-empty field="parameters.parentCommEventId">
-            <entity-one entity-name="CommunicationEvent" value-field="parentCommEvent">
-                <field-map field-name="communicationEventId" from-field="parameters.parentCommEventId"/>
-            </entity-one>
-            <entity-one entity-name="PartyNameView" value-field="partyNameView">
-                <field-map field-name="partyId" from-field="parentCommEvent.partyIdFrom"/>
-            </entity-one>
-            
-            <if-compare-field field="parentCommEvent.partyIdFrom" operator="equals" to-field="parameters.partyIdTo">
-                <set field="newEntity.partyIdTo" from-field="parentCommEvent.partyIdFrom"/>
-            </if-compare-field>
-            
-            <set field="newEntity.subject" value="RE: ${parentCommEvent.subject}"/>
-
-            <set field="newEntity.content" value="${groovy:
-                def localContent = parentCommEvent.content;
-                if (!localContent) return(&quot;&quot;);
-
-                resultLine = &quot;\n\n\n&quot; 
+        <if-compare field="parameters.userLogin.userLoginId" value="system" operator="not-equals">
+            <if-not-empty field="parameters.parentCommEventId">
+                <entity-one entity-name="CommunicationEvent" value-field="parentCommEvent">
+                    <field-map field-name="communicationEventId" from-field="parameters.parentCommEventId"/>
+                </entity-one>
+                <entity-one entity-name="PartyNameView" value-field="partyNameView">
+                    <field-map field-name="partyId" from-field="parentCommEvent.partyIdFrom"/>
+                </entity-one>
+                
+                <if-compare-field field="parentCommEvent.partyIdFrom" operator="equals" to-field="parameters.partyIdTo">
+                    <set field="newEntity.partyIdTo" from-field="parentCommEvent.partyIdFrom"/>
+                </if-compare-field>
+                
+                <set field="newEntity.subject" value="RE: ${parentCommEvent.subject}"/>
+                
+                <set field="newEntity.content" value="${groovy:
+                    def localContent = parentCommEvent.content;
+                    if (!localContent) return(&quot;&quot;);
+                    
+                    resultLine = &quot;\n\n\n&quot; 
                     + (partyNameView.firstName!=null?partyNameView.firstName:&quot;&quot;) 
                     + &quot; &quot; 
                     + (partyNameView.middleName!=null?partyNameView.middleName+&quot; &quot;:&quot;&quot;) 
@@ -84,27 +87,28 @@
                     + (partyNameView.lastName!=null?partyNameView.lastName:&quot;&quot;) 
                     + (partyNameView.groupName!=null?partyNameView.groupName:&quot;&quot;) 
                     + &quot; wrote:&quot;;
-                resultLine += &quot;\n -------------------------------------------------------------------- &quot;;
-                resultLine += &quot;\n&gt; &quot; + localContent.substring(0, localContent.indexOf(&quot;\n&quot;,0) == -1 ? localContent.length() : localContent.indexOf(&quot;\n&quot;,0));
-                startChar = localContent.indexOf(&quot;\n&quot;,0);
-                while(startChar != -1 &amp;&amp; (startChar = localContent.indexOf(&quot;\n&quot;,startChar) + 1) != 0)
+                    resultLine += &quot;\n -------------------------------------------------------------------- &quot;;
+                    resultLine += &quot;\n&gt; &quot; + localContent.substring(0, localContent.indexOf(&quot;\n&quot;,0) == -1 ? localContent.length() : localContent.indexOf(&quot;\n&quot;,0));
+                    startChar = localContent.indexOf(&quot;\n&quot;,0);
+                    while(startChar != -1 &amp;&amp; (startChar = localContent.indexOf(&quot;\n&quot;,startChar) + 1) != 0)
                     resultLine += &quot;\n&gt; &quot; + localContent.substring(startChar, localContent.indexOf(&quot;\n&quot;,startChar)==-1 ? localContent.length() : localContent.indexOf(&quot;\n&quot;,startChar));
-                return(resultLine);
-                }"/>
-
-            <!-- set rolestatus from original email to completed -->
-            <entity-and list="roles" entity-name="CommunicationEventRole">
-                <field-map field-name="communicationEventId" from-field="parentCommEvent.communicationEventId"/>
-                <field-map field-name="partyId" from-field="parentCommEvent.partyIdTo"/>
-            </entity-and>
-            <if-not-empty field="roles">
-                <first-from-list list="roles" entry="role"/>
-                <set-service-fields service-name="setCommunicationEventRoleStatus" map="role" to-map="newStat"/>
-                <set field="newStat.statusId" value="COM_ROLE_COMPLETED"/>
-                <call-service service-name="setCommunicationEventRoleStatus" in-map-name="newStat"/>
+                    return(resultLine);
+                    }"/>
+                
+                <!-- set rolestatus from original email to completed -->
+                <entity-and list="roles" entity-name="CommunicationEventRole">
+                    <field-map field-name="communicationEventId" from-field="parentCommEvent.communicationEventId"/>
+                    <field-map field-name="partyId" from-field="parentCommEvent.partyIdTo"/>
+                </entity-and>
+                <if-not-empty field="roles">
+                    <first-from-list list="roles" entry="role"/>
+                    <set-service-fields service-name="setCommunicationEventRoleStatus" map="role" to-map="newStat"/>
+                    <set field="newStat.statusId" value="COM_ROLE_COMPLETED"/>
+                    <call-service service-name="setCommunicationEventRoleStatus" in-map-name="newStat"/>
+                </if-not-empty>
             </if-not-empty>
-        </if-not-empty>
-
+        </if-compare>
+        
         <if-empty field="parameters.statusId">
             <set value="COM_ENTERED" field="parameters.statusId"/>
         </if-empty>
@@ -191,6 +195,7 @@
     <simple-method method-name="updateCommunicationEvent"
         short-description="Update a CommunicationEvent">
         <entity-one entity-name="CommunicationEvent" value-field="event"/>
+        <log level="always" message="====Udating communication event: ${communicationEvent.communicationEventId} with subject: ${communicationEvent.subject}"></log>
         <if-compare-field to-field="parameters.statusId" operator="not-equals" field="event.statusId">
             <call-simple-method method-name="setCommunicationEventStatus"/>
         </if-compare-field>

Modified: ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java?rev=777768&r1=777767&r2=777768&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java (original)
+++ ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java Sat May 23 02:19:21 2009
@@ -36,6 +36,7 @@
 import java.util.regex.Pattern;
 
 import javax.mail.Address;
+import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.mail.internet.InternetAddress;
 import javax.servlet.http.HttpServletRequest;
@@ -634,12 +635,9 @@
             }
             if (!commEvents.isEmpty()) {
                 Debug.logInfo("Ignoring Duplicate Email: " + aboutThisEmail, module);
-                return ServiceUtil.returnSuccess(" Message Ignored: deplicate messageId");
-            } else {
-                Debug.logInfo("Persisting New Email: " + aboutThisEmail, module);
+                return ServiceUtil.returnSuccess(" Message Ignored: duplicate messageId");
             }
 
-
             // get the related partId's
             List<Map<String, Object>> toParties = buildListOfPartyInfoFromEmailAddresses(addressesTo, userLogin, dispatcher);
             List<Map<String, Object>> ccParties = buildListOfPartyInfoFromEmailAddresses(addressesCC, userLogin, dispatcher);
@@ -703,7 +701,21 @@
             if (messageBodyContentType.indexOf(";") > -1) {
                 messageBodyContentType = messageBodyContentType.substring(0, messageBodyContentType.indexOf(";"));
             }
-            String messageBody = wrapper.getMessageBody();
+            
+            // select the plain text bodypart
+            String messageBody = null;
+            if (wrapper.getMainPartCount() > 1) {
+            	for (int ind=0; ind < wrapper.getMainPartCount(); ind++) {
+            		BodyPart p = wrapper.getPart(ind + "");
+            		if (p.getContentType().toLowerCase().indexOf("text/plain") > -1) {
+            			messageBody = (String) p.getContent();
+            		}
+            	}
+            }
+            
+            if (messageBody == null ) {
+            	messageBody = wrapper.getMessageBody();
+            }
                         
             commEventMap.put("content", messageBody);
             commEventMap.put("contentMimeTypeId", messageBodyContentType.toLowerCase());            
@@ -777,6 +789,7 @@
 
             result = dispatcher.runSync("createCommunicationEvent", commEventMap);
             communicationEventId = (String)result.get("communicationEventId");
+            Debug.logInfo("Persisting New Email: " + aboutThisEmail + " into CommunicationEventId: " + communicationEventId, module);
 
             // handle the attachments
             createAttachmentContent(dispatcher, wrapper, communicationEventId, userLogin);