Support Article
Mail replies to Pega pulse post raw data in Pulse messages
SA-61858
Summary
When replying to the Pega Pulse email message, the reply message is posted with the mail's HTML data instead of only the replied message.
Error Messages
Not Applicable
Steps to Reproduce
- Create an email listener
- Configure an Email account with the MS Exchange Office 365 account details in the Receiver, Service package/class, and method to read the Pulse replies.
- Create a work object and send a Pulse notification to any operator.
- Reply to the Pulse notification from Outlook.
Root Cause
The HTML data displayed due to the Outlook account which attempted to load the HTML content where the Text portion did not exist.
Resolution
Perform the following local-change:
- Create a new PostPulseReplyWrapper activity (wrapper) in the PegaSocial-Message in the application ruleset.
- In Step 2 of the activity, add the below Java code,
// "Strips" text from Body of HTML document
// Relies on Third Party Library "Tag Soup" (org.ccil.cowan.tagsoup), which is included in Pega7.3
java.io.InputStream is = new org.apache.commons.io.input.ReaderInputStream(new java.io.StringReader( pyBody ), java.nio.charset.StandardCharsets.UTF_8);
bodyTextSB=new StringBuffer();
class myHandler extends org.xml.sax.helpers.DefaultHandler {
final String NL="\r\n";
String[] tags= { "body", "script" , "style" };
java.util.Map<String, Boolean> tagsOfInterest=new java.util.HashMap<>();
{
for (String tag: tags) {
tagsOfInterest.put(tag, false);
}
}
@Override
public void characters(char ch[], int start, int length) {
if ( tagsOfInterest.get( "body" ) ) {
boolean dontWrite=false;
StringBuilder debugTags=new StringBuilder();
for (String tag: tagsOfInterest.keySet() ) {
if (!tag.equals("body")) {
dontWrite=dontWrite | tagsOfInterest.get(tag);
}
if (oLog.isDebugEnabled()) {
debugTags.append( tag+"="+tagsOfInterest.get(tag)+" " );
}
}
oLog.debug( debugTags );
if (oLog.isDebugEnabled()) {
oLog.debug("dontwrite="+dontWrite);
}
if (dontWrite) {
return;
}
else {
String tempString = new String(ch, start, length);
bodyTextSB.append( tempString );
}
}
}
@Override
public void startElement(String uri, String localName,
String name, org.xml.sax.Attributes a) {
String lc=localName.toLowerCase();
if (tagsOfInterest.containsKey( lc )) {
tagsOfInterest.put(lc, true);
if (oLog.isDebugEnabled()) {
oLog.debug("Start Tag Detected for:"+lc);
}
}
if (lc.equals("p") || lc.equals("br") || lc.equals("div") ) { bodyTextSB.append(NL); } // Not strictly necessarily (and might be wrong sometimes):attempt to preserve newlines.
}
@Override
public void endElement(String namespaceURI, String localName, String qName) {
String lc=localName.toLowerCase();
if (tagsOfInterest.containsKey( lc )) {
tagsOfInterest.put(lc, false);
if (oLog.isDebugEnabled()) {
oLog.debug("End Tag Detected for:"+lc);
}
}
}
}
try {
org.ccil.cowan.tagsoup.jaxp.SAXParserImpl.newInstance(null).parse( is , new myHandler() );
String tempString=bodyTextSB.toString();
if (oLog.isDebugEnabled()) {
oLog.debug("Original .pyBody: "+ pyBody);
oLog.debug("Modified .pyBody:" + tempString);
}
if (tempString.length() > 0) {
pyBody=tempString;
}
else { oLog.info("Zero Length String returned when parsing input; returning original .pyBody"); }
}
catch(Exception e) { if (oLog.isDebugEnabled()) { oLog.error(e);}
oLog.info("Error Parsing Input: pyBody is unaltered.");
}
- Declare pyBody (String type) and bodyTextSB (StringBuffer type) local variables in the activity's Parameters tab.
- Change the activity in the Service Email rule from pzPostReplyFromMail to PostReplyPulseWrapper.
Published August 15, 2019 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.