Stickybeak Posted June 25, 2019 Posted June 25, 2019 I am trying to write a script to permit me to respond to emails received into fmp. I have successfully written the calculation to extract the email address from the "from" field in which the data is presented "Joes Bloggs <[email protected]>. I cannot work out how to do the same for the CC field. The data is in the same format but there are typically multiple CC recipients and so I need to extract the text between <> sequentially. Any clues?
OlgerDiekstra Posted June 25, 2019 Posted June 25, 2019 (edited) Multiple email addresses in the TO, CC and BCC (RFC) headers are separated with a "," (comma). So to parse any of those headers you'd do a substitute to replace the comma's with a carriage return and make a list. ([email protected],[email protected]) However. If fancy names are used ("john smith" <[email protected]>,"John Doe" <[email protected]>) it's more complicated. I would try replacing ">, " with a carriage return first, then ">," and then only the comma. That should give you a list that you can parse. Edited June 25, 2019 by OlgerDiekstra
Stickybeak Posted June 25, 2019 Author Posted June 25, 2019 Using this calculation: "Middle(Messages::Cc;Position(Messages::Cc;"<";1;1)+1;Position(Messages::Cc;">";1;1)-Position(Messages::Cc;"<";1;1)-1) I get only the first email address in the Cc field. It has "fancy names" so to make it work I have first strip out the "name" - which is what the calc above does. I am trying to avoid creating a new field for the list - I was trying to do it by a variable which why I included recursive as a tag - I hoped I might be able to go through the CC field until I had somehow parsed all the addresses in it.
comment Posted June 25, 2019 Posted June 25, 2019 (edited) You need either a custom function or a looping script for this. Or version 18 with its While() function. If - as it seems - you need to use the result in a script anyway, I would do this within the same script to keep all the required logic on one place. Post an example of the input (with fake data, of course) if you need help with this. . Edited June 25, 2019 by comment
OlgerDiekstra Posted June 25, 2019 Posted June 25, 2019 3 hours ago, Stickybeak said: Using this calculation: "Middle(Messages::Cc;Position(Messages::Cc;"<";1;1)+1;Position(Messages::Cc;">";1;1)-Position(Messages::Cc;"<";1;1)-1) I get only the first email address in the Cc field. It has "fancy names" so to make it work I have first strip out the "name" - which is what the calc above does. I am trying to avoid creating a new field for the list - I was trying to do it by a variable which why I included recursive as a tag - I hoped I might be able to go through the CC field until I had somehow parsed all the addresses in it. You're not creating a list of your CC's. Assuming a CC line of: "Person 1" <[email protected]>, "Person 2" <[email protected]>,[email protected],"Person 4" <[email protected]> First create a value list of the CC line: Substitute( $CC; [ ">, "; "¶" ]; [ ">,"; "¶" ]; [ ","; "¶" ] ) This will give you a list like this: "Person 1" <p.one@here.com>¶ "Person 2" <p.two@here.com>¶ [email protected]¶ "Person 4" <p.four@here.com> Then you can apply your calculation to get just the email addresses: $count=1 $newCC = "" loop $email = middle( GetValue( $CC; $count ) $email = Middle( $email; Position( $email; "<"; 1; 1 ) + 1; Position( $email; ">"; 1; 1 ) - Position( $email; "<" ;1 ;1 )- 1 ) $newCC = $newCC & "¶" & $email $count = $count + 1 exit loop if $count > valuecount( $CC ) end loop $newCC will end up with a list of just emailaddresses. [email protected]¶ [email protected]¶ [email protected]¶ [email protected]
Recommended Posts
This topic is 1989 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now