Capturing relevant information from the body of emails sent to a process model

I'm trying to create a feature to allow users to communicate by email and have their communication tracked by Appian and stored in a database. However, I'm having a hard time capturing the meaningful information from the body of the email message. Email signatures and the content of emails earlier in the chain are also captured. Has anyone implemented a solution that does what I'm trying to accomplish?

For example, I tried sending an email with just the word "Testing" in the body, but striphtml(msg!body) returns all of this garbage, including my email signature:

Testing________________________________[cid:image001.jpg@01CC47C6.5B839AF0]John StrettonEDP Renewables North AmericaCorporate InitiativesAddress here, Houston, TX 77002Direct xxx.xxx.xxxxwww.edpr.comTake action. Use energy efficient products.This e-mail is for the use of the intended recipient(s) only. If y...

OriginalPostID-257049

  Discussion posts and replies are publicly visible

  • Here's my approach. You'll need to install the Email Reply Parser plugin first and you will also need the Appian Regular Expression Functions plugin. You can replace the hard-coded search strings with whatever makes sense for your organization's email signatures. I've found the "16 underscores" approach to be pretty effective.

    =a!localVariables(
      /* Email body extraction. Pretty good at excluding signatures, but not 100% effective. */
      local!body: index(
        parseemailreply(ri!msg),
        "visibleText",
        null
      ),
      /* Anything after 16 consecutive underscores is assumed to be from an earlier email message */
      local!restOfChain: regexfirstmatch("________________.*",local!body),
      /* Text strings that should be deleted from the extracted email body */
      local!stringsToDelete: {
        local!restOfChain,
        "This e-mail is for the use of the intended recipient(s) only. If you are not the intended recipient(s), or the employee or agent responsible for delivery of this message to the intended recipient(s), you are hereby notified that any distribution, dissemination, or copying of this e-mail is strictly prohibited.  If you have received this e-mail in error, please immediately notify the sender and delete this e-mail message from your computer. Thank you.",
        "This message and the attached files may contain confidential and/or privileged information, which should not be disclosed, copied, saved or distributed, under the terms of current legislation. If you have received this message in error, we ask that you do not disclose or use this information. Please notify the sender of this error, by email, and delete this message from your device."
      },
      /* Remove all instances of the strings marked for deletion and return the result*/
      reduce(
        fn!substitute(_,_,""),
        local!body,
        local!stringsToDelete
      )
    )