Page 2 of 2
Re: Livecode Enhancements pack - error after update
Posted: Fri Feb 23, 2024 5:30 pm
by Klaus
What however worked with the above mentioned email is this:
Code: Select all
...
put getMailText(tEMLArray) into tText
...
Returned the complete body text in tText!
Re: Livecode Enhancements pack - error after update
Posted: Sat Feb 24, 2024 7:18 am
by mbossiere
Klaus,
I'm still mystified about how you are getting the body. Could I ask you to write a commented button (just a minimal number of lines) that collects an .EML file and pulls out it's Body in plain text? Then maybe I'd understand better how an array is structured and how you address the various parts of an array. I know it's a multpart variable, but not how it's laid out or how to "ask" it for it's elements. I notice your screenshot has an element call "content" but you refer to "body" a couple of times and I'm confused about the differences.
Sorry to be such an idiot!!

Marc
Re: Livecode Enhancements pack - error after update
Posted: Sat Feb 24, 2024 5:25 pm
by Klaus
Well, that's all in my last postings, but here a summary:
Code: Select all
on mouseUp
## Let user select a EML file:
answer file "EML"
## User clicked CANCEL so get out of this handler:
if the result = "cancel" then
exit to top
end if
## Put it into a variable:
put url("file:" & it) into tData
## Let LC make the data an array:
put emlToArray(tData) into tEMLArray
## I found that this does obviously not work with ALL emails, see my last postings...
## put tEMLArray["content"] into tText
## But this seems to work in most cases to get the actual BODY of the mail:
put getMailText(tEMLArray) into tText
## Check tText in a field and see if you need to:
## put textdecode(tText,"utf8") into tTextClean
## Now you can continue with your last script from the previous page:
## headers is also an array and NOT a simple string, that is an error in the dictionary!
put getHeaders(tData) into tHeaderArray
put tHeaderArray["From"] into tFrom
put tHeaderArray["To"] into tTo
put tHeaderArray["Subject"] into tSubj
put tHeaderArray["Date"] into tDate
put tHeaderArray["Content-Transfer-Encoding"] into tContent
put tTo & CR & tFrom & CR & tSubj & CR & tDate & CR & CR & tText
end mouseUp
I notice your screenshot has an element call "content" but you refer to "body" a couple of times and I'm confused about the differences.
"content" MAY be a key of the tEMLArray, "body" does not!
I only used it to describe what it is: the actual text or message in the email.
Re: Livecode Enhancements pack - error after update
Posted: Sat Feb 24, 2024 6:04 pm
by mbossiere
Thanks so much Klaus! I wish I had time right now to study this but I quickly put it into my button and it works like magic! I'm sure I will be able to figure it out when I have a moment. Thank you so much for this and for your comments in the code. I really need to get my mind around the nature of arrays

Marc Bossiere
Re: Livecode Enhancements pack - error after update
Posted: Sat Feb 24, 2024 6:46 pm
by Klaus
Avec plaisir, mon ami!
Feel free to ask if you get stuck.
Re: Livecode Enhancements pack - error after update
Posted: Sun Feb 25, 2024 3:13 pm
by mbossiere
Klaus wrote: Sat Feb 24, 2024 6:46 pm
Avec plaisir, mon ami!
Feel free to ask if you get stuck.
Je suis tres reconnaissant, mon ami! This is the key to maybe 30,000+ old email files going back years which I have had very limited ways to manipulate. Very excited about this, and for future applications. When I saw EMLParser I knew I needed the Enhancements Pack (which, sadly I have only just gotten around to exploring). Too bad the documentation is so rudimentary (and even wrong, as you point out). It could use some samples of each step!
One other thing I would like to know, do you happen to know if there is a way to access any attachments that were part of each email? Even if the attached files are gone as I presume, is there a reference one can perhaps extract to the filenames of such attachments? This could prove very valuable in some cases.
Marc
Re: Livecode Enhancements pack - error after update
Posted: Sun Feb 25, 2024 7:20 pm
by Klaus
Hi Marc,
I saved an email with a MP3 file attached.
See in the script, attachments are also returned in an array with
Code: Select all
...
put emlToArray(tData) into tArray
put getAttachments(tArray) into tAt
...
The keys are abviously* the filename of the attached file and the content of that key its base 64 encoded data.
*I only checked with ONE file!
Re: Livecode Enhancements pack - error after update
Posted: Mon Feb 26, 2024 6:04 am
by mbossiere
Hi Klaus
Code: Select all
...
put emlToArray(tData) into tArray
put getAttachments(tArray) into tAt
...
Very exciting... I tried the following and as you can see came very close (to 3 .jpg files), but tAt was empty. I know I need to address one of them, but how?
Marc
Re: Livecode Enhancements pack - error after update
Posted: Mon Feb 26, 2024 11:26 am
by Klaus
tAt is NOT empty, it contains another ARRAY!
You cannot set the htmltext of the browser object to an array.
But you can access its keys, which are the filename of the attached files.
Re: Livecode Enhancements pack - error after update
Posted: Mon Feb 26, 2024 5:58 pm
by mbossiere
Yes, I can see them. I'm so close! What I don't know is how syntactically to address them or to get their names for further manipulation.
Re: Livecode Enhancements pack - error after update
Posted: Mon Feb 26, 2024 6:08 pm
by Klaus
Using my example, e.g. store the images on the desktop
Code: Select all
...
put the keys of tAt into tFilenames
repeat with i = 1 to the num of lines of tFilenames
## tFileName now contains the name of the first KEY of tAt
put line i of tFilenames into tFileName
## Save the images on the desktop:
put base64decode(tAt[tFileName]) into url("binfile:" & specialfolderpath("desktop") "/" & tFileName)
end repeat
...
Re: Livecode Enhancements pack - error after update
Posted: Tue Feb 27, 2024 7:12 am
by mbossiere
Klaus wrote: Mon Feb 26, 2024 6:08 pm
Using my example, e.g. store the images on the desktop
Code: Select all
...
put the keys of tAt into tFilenames
repeat with i = 1 to the num of lines of tFilenames
## tFileName now contains the name of the first KEY of tAt
put line i of tFilenames into tFileName
## Save the images on the desktop:
put base64decode(tAt[tFileName]) into url("binfile:" & specialfolderpath("desktop") "/" & tFileName)
end repeat
...
Now, this is truly magic! The EML file actually contains photo and .pdf and .mp3 files locked away for 15 years!!
Your line of code at the end (saving tFileName to the desktop is brilliant!
-- put base64decode(tAt[tFileName]) into url("binfile:" & specialfolderpath("desktop") "/" & tFileName)
needed to be changed to
-- put base64decode(tAt[tFileName]) into url("binfile:" & specialfolderpath("desktop") & "/" & tFileName)
before it would work for me, but it produced photos I had no idea were lurking inside an .EML file... quite ingenius!
I presume base64 is the method by which these were encoded inside .EML?
Thanks you once again Klaus. This is more than I hoped for.
Re: Livecode Enhancements pack - error after update
Posted: Tue Feb 27, 2024 10:25 am
by Klaus
Glad it works for you and sorry, I forgot a & in my script.
Yes, base64encode is the way to "translate" binary data to a string that can e.g. be sent via email.
Re: Livecode Enhancements pack - error after update
Posted: Tue Feb 27, 2024 5:34 pm
by mbossiere
I have been wanting a key to .EML for at least ten years! This is better than I hoped for. Thanks for all your patience
Marc