Highlighted

Delete everything to the right of matching phrase

New Here ,
Sep 13, 2019

Copy link to clipboard

Copied

I'm using sendgrid's email parser to return the body of an email to my application. The problem is, if the message is a reply it also returns the original message with the reply message. What I'm trying to do is parse out the reply from the original message. To do this I think I need to find the text/characters that each major email client uses between the reply and the original message and remove the original message.

 

What I'm trying to do is use coldfusion to look at the following example text and delete out everything to the right of and including the 'On Fri, Sep 13, 2019' in the following text.

 

This is an example of a gmail reply.
"here's a test reply with multiple line breaks On Fri, Sep 13, 2019 at 5:56 PM <matt@email.com> wrote: > ---*PLEASE REPLY ABOVE THIS LINE*--- > > This is your confirmation text > I wonder how to keep the line breaks? > > > Thank you!"

 

How would this be possible in CF? If you know of any better way to accomplish this, that would be great as well.

So what I'd like to end up returning would be: "here's a test reply with multiple line breaks"

TOPICS
Advanced techniques

Views

75

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Delete everything to the right of matching phrase

New Here ,
Sep 13, 2019

Copy link to clipboard

Copied

I'm using sendgrid's email parser to return the body of an email to my application. The problem is, if the message is a reply it also returns the original message with the reply message. What I'm trying to do is parse out the reply from the original message. To do this I think I need to find the text/characters that each major email client uses between the reply and the original message and remove the original message.

 

What I'm trying to do is use coldfusion to look at the following example text and delete out everything to the right of and including the 'On Fri, Sep 13, 2019' in the following text.

 

This is an example of a gmail reply.
"here's a test reply with multiple line breaks On Fri, Sep 13, 2019 at 5:56 PM <matt@email.com> wrote: > ---*PLEASE REPLY ABOVE THIS LINE*--- > > This is your confirmation text > I wonder how to keep the line breaks? > > > Thank you!"

 

How would this be possible in CF? If you know of any better way to accomplish this, that would be great as well.

So what I'd like to end up returning would be: "here's a test reply with multiple line breaks"

TOPICS
Advanced techniques

Views

76

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 13, 2019 0
BKBK LATEST
Adobe Community Professional ,
Sep 14, 2019

Copy link to clipboard

Copied

Two points:

 

1. Don't worry about line breaks. ColdFusion will consider them to be characters in a string. 

 

2. You could just solve this by writing a function. Something like this:

<cfscript>

testString="here's a test reply with multiple line breaks On Fri, Sep 13, 2019 at 5:56 PM <matt@email.com> wrote: > ---*PLEASE REPLY ABOVE THIS LINE*--- > > This is your confirmation text > I wonder how to keep the line breaks? > > > Thank you!";


delimitingString="On Fri, Sep 13, 2019";

 

result=findSubstring(testString, delimitingString);
writeoutput(result);

 

/* Function to extract a substring from an input string, given a sring delimiter */
string function findSubstring (required string stringToSearch, required string delimiterString) {

    if(arguments.delimiterString is "") {
        return arguments.stringToSearch;
    }
    var searchIndex=findNoCase(arguments.delimiterString, arguments.stringToSearch);

    return left(arguments.stringToSearch,searchIndex-1);
}

</cfscript>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 14, 2019 0