Livecode Enhancements pack - error after update

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Enhancements pack - error after update

Post by Klaus » Fri Feb 23, 2024 5:30 pm

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!

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Livecode Enhancements pack - error after update

Post by mbossiere » Sat Feb 24, 2024 7:18 am

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
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Enhancements pack - error after update

Post by Klaus » Sat Feb 24, 2024 5:25 pm

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.

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Livecode Enhancements pack - error after update

Post by mbossiere » Sat Feb 24, 2024 6:04 pm

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
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Enhancements pack - error after update

Post by Klaus » Sat Feb 24, 2024 6:46 pm

Avec plaisir, mon ami! :)
Feel free to ask if you get stuck.

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Livecode Enhancements pack - error after update

Post by mbossiere » Sun Feb 25, 2024 3:13 pm

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
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Enhancements pack - error after update

Post by Klaus » Sun Feb 25, 2024 7:20 pm

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!
Attachments
Bildschirmfoto 2024-02-25 um 19.16.30.png

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Livecode Enhancements pack - error after update

Post by mbossiere » Mon Feb 26, 2024 6:04 am

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?
Screen Shot 2024-02-25 at 10.00.14 PM.jpg
Marc
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Enhancements pack - error after update

Post by Klaus » Mon Feb 26, 2024 11:26 am

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.

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Livecode Enhancements pack - error after update

Post by mbossiere » Mon Feb 26, 2024 5:58 pm

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.
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Enhancements pack - error after update

Post by Klaus » 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
...

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Livecode Enhancements pack - error after update

Post by mbossiere » Tue Feb 27, 2024 7:12 am

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.
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Livecode Enhancements pack - error after update

Post by Klaus » Tue Feb 27, 2024 10:25 am

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.

mbossiere
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 44
Joined: Wed Aug 01, 2007 2:15 am
Location: Tucson Arizona US

Re: Livecode Enhancements pack - error after update

Post by mbossiere » Tue Feb 27, 2024 5:34 pm

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
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”