12 Replies - 527 Views - Last Post: 29 May 2020 - 07:06 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 705
  • View blog
  • Posts: 4,524
  • Joined: 12-January 10

How do you extract tokens from an email body?

Posted 22 May 2020 - 05:41 AM

so i have an email body that is rendered and in the body there can be tokens:

Hi,
You are receiving this message because {Student} has submitted an issue for course:
{Course}
on: {Date}

Comment:
{Issue}

Thank you.



the above is an example but it could be any wording.
those tokens or even the email body can be anything and placed anywhere depending on who wrote the email. does anyone have a link or a suggestion on how to pull those tokens out of an email body? I cant seem to find any info of people doing anything like that

Is This A Good Question/Topic? 0
  • +

Replies To: How do you extract tokens from an email body?

#2 andrewsw   User is offline

  • palpable absurdity
  • member icon

Reputation: 6901
  • View blog
  • Posts: 28,559
  • Joined: 12-December 12

Re: How do you extract tokens from an email body?

Posted 22 May 2020 - 06:09 AM

If you know that you are looking for {Student} in the string then you could just search and/or replace this string, so presumably there is a bit more that you are trying to achieve?

You could also replace {Course}, etc..

Or are you trying to find whatever is delimited by braces {whatevs} ? Regex could do it, although, perhaps there is something else to your process that would be it more easily "parsable".
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 705
  • View blog
  • Posts: 4,524
  • Joined: 12-January 10

Re: How do you extract tokens from an email body?

Posted 22 May 2020 - 06:27 AM

so the thing is that the professors make the mails and they can use any type of token anywhere in the body and the email can say anything and be any length.
so i cant just do a replace on {student} because that can actually be anything that the professor chooses .
they can put {kid} for all we know and anywhere in the body. that's the dilemma---
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • palpable absurdity
  • member icon

Reputation: 6901
  • View blog
  • Posts: 28,559
  • Joined: 12-December 12

Re: How do you extract tokens from an email body?

Posted 22 May 2020 - 06:36 AM

I would go to regex then. Unless, that is, you interpret that the task might be to write with basic string processing? That is, might he be expecting students to process the string to find the first "{" and continue to find its closing "}"? Would he/she be shocked if you used regex?

Quote

I cant seem to find any info of people doing anything like that

With basic string processing one would think that you could tackle it without needing to find something similar from the net :)
Was This Post Helpful? 1
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15743
  • View blog
  • Posts: 63,065
  • Joined: 12-June 08

Re: How do you extract tokens from an email body?

Posted 22 May 2020 - 06:46 AM

I would recommend regex'n that shit up, yo!

. is 'any character but new line'
* is 0 or more of previous expressoin

http://regexlib.com/...CookieSupport=1

            string derp = @"Hi,
You are receiving this message because {Student}
            has submitted an issue for course:
{Course}
        on: {Date}

        Comment:
            {Issue}

            Thank you.";
            
            string[] temp = System.Text.RegularExp ressions.Regex.Split(derp, "{.*} ");
            MatchCollection m;

            m = Regex.Matches(derp, "{.*}");

            if(m != null)
            {
                foreach (Match item in m)
                {

                    Console.WriteLine($"{item.Value}");
                }
            }


{Student}
{Course}
{Date}
{Issue}


Was This Post Helpful? 1
  • +
  • -

#6 DarenR   User is offline

  • D.I.C Lover

Reputation: 705
  • View blog
  • Posts: 4,524
  • Joined: 12-January 10

Re: How do you extract tokens from an email body?

Posted 22 May 2020 - 06:47 AM

View Postandrewsw, on 22 May 2020 - 09:36 AM, said:

I would go to regex then. Unless, that is, you interpret that the task might be to write with basic string processing? That is, might he be expecting students to process the string to find the first "{" and continue to find its closing "}"? Would he/she be shocked if you used regex?


this isnt for students --- this is actually for professors.
we have a thing called emailer where the professor can write emails that get sent to students and for some reason we allow them to enter as many tokens as they want with any id they want. I was actually thinking of making a token list that they have to pick from and be done with it.... that way the professors dont have to do extra thinking work ha
Was This Post Helpful? 0
  • +
  • -

#7 DarenR   User is offline

  • D.I.C Lover

Reputation: 705
  • View blog
  • Posts: 4,524
  • Joined: 12-January 10

Re: How do you extract tokens from an email body?

Posted 22 May 2020 - 07:08 AM

View Postmodi123_1, on 22 May 2020 - 09:46 AM, said:

I would recommend regex'n that shit up, yo!



so apparently who ever made this emailer decided to not finish the mailer--- their token thing doesnt actually do anything
so on the designer for the emailer they have a thing called show tokens where the tokens should show up-- however there is no code associated with that button.
and then they have a tab where you can add new tokens for use -- but guess what -- no code associated with the tab
and then the ones i made in the db show up as not active in a list that they have on another tab which in fact the db has them as active..


this is going to take me a bit of work to get this emailer to work--- and this entire time i was just supposed to be working on an issue submitter -- ha
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15743
  • View blog
  • Posts: 63,065
  • Joined: 12-June 08

Re: How do you extract tokens from an email body?

Posted 22 May 2020 - 07:09 AM

Classic bullshit. STubbed out but never done.


Posted Image
Was This Post Helpful? 1
  • +
  • -

#9 DarenR   User is offline

  • D.I.C Lover

Reputation: 705
  • View blog
  • Posts: 4,524
  • Joined: 12-January 10

Re: How do you extract tokens from an email body?

Posted 29 May 2020 - 05:23 AM

hey modi on this line
string[] temp = System.Text.RegularExp<b></b>ressions.Regex.Split(derp, "{.*} ");



section RegularExp<b></b>ressions. is not known and errors out--- is this a new vs coding style? -- they have me using 2013
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15743
  • View blog
  • Posts: 63,065
  • Joined: 12-June 08

Re: How do you extract tokens from an email body?

Posted 29 May 2020 - 05:26 AM

Ya removed the dumb bold tags the forum injected, right?
Was This Post Helpful? 0
  • +
  • -

#11 DarenR   User is offline

  • D.I.C Lover

Reputation: 705
  • View blog
  • Posts: 4,524
  • Joined: 12-January 10

Re: How do you extract tokens from an email body?

Posted 29 May 2020 - 05:32 AM

yeah -- it didnt understand ressions so i shortened it to
 System.Text.RegularExpressions.Regex.


havent tried it yet ha
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15743
  • View blog
  • Posts: 63,065
  • Joined: 12-June 08

Re: How do you extract tokens from an email body?

Posted 29 May 2020 - 07:01 AM

Seems it's been in .NET Framework since 1.1

https://docs.microso...iker-applies-to
Was This Post Helpful? 0
  • +
  • -

#13 DarenR   User is offline

  • D.I.C Lover

Reputation: 705
  • View blog
  • Posts: 4,524
  • Joined: 12-January 10

Re: How do you extract tokens from an email body?

Posted 29 May 2020 - 07:06 AM

it worked after i removed that section -- now to try to figure out how to find the token values -- since they arent stored anywhere---- and one of the values comes from an api ugh
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1