How can you use Applescript to process several emails for content?

S

sedgington

Hi,
I have a script that will process a selected email and pull out its
content:
----------------------
tell application "Microsoft Entourage"


set theMail to selection
set mySrc to content of (item 1 of theMail)

end tell
-------------------------
What I would like to do is select several emails and pull the content
out of all of them.

When I try and do this with a list, the script hangs on the first email
and tells me that it can't get the content from the others.

Could anyone point me in the right direction on what is probably a
trivial thing to do for the initiated?

Thanks in Advance!
 
B

Barry Wainwright [MVP]

Hi,
I have a script that will process a selected email and pull out its
content:
----------------------
tell application "Microsoft Entourage"


set theMail to selection
set mySrc to content of (item 1 of theMail)

end tell
-------------------------
What I would like to do is select several emails and pull the content
out of all of them.

When I try and do this with a list, the script hangs on the first email
and tells me that it can't get the content from the others.

Could anyone point me in the right direction on what is probably a
trivial thing to do for the initiated?

Thanks in Advance!

First, we need to know what yu want to do with the content!

However, this loop should process each mail in turn (assuming you don't want
to concatenate all the content into one block:

Tell app "microsoft entourage"
Set theMessages to current messages
Repeat with aMessage in theMessages
Set mySrc to content of aMessage
-- do your stuff with mysrc
End repeat
End tell
 
S

sedgington

Barry said:
First, we need to know what yu want to do with the content!

However, this loop should process each mail in turn (assuming you don't want
to concatenate all the content into one block:

Tell app "microsoft entourage"
Set theMessages to current messages
Repeat with aMessage in theMessages
Set mySrc to content of aMessage
-- do your stuff with mysrc
End repeat
End tell


--
Barry Wainwright
Microsoft MVP (see http://mvp.support.microsoft.com for details)
Check out the Entourage User's WebLog for hints, tips and troubleshooting
<http://homepage.mac.com/barryw/weblog/weblog.html>


Thank you very much Barry.

I guess that I should have explained that I want the content in one
block so that it can then be processed by an external program. When I
run the script you graciously provided above, it only delivers the
content of one message, I'm looking to get the content of all the
messages that I have selected. I guess what I am having a problem with
is how to walk through the structure of entourage to get to the content
of each item (message). I'll look on your website, but if you could
give me any more hints it would be greatly appreciated.

Thanks again,

Stephen
 
B

Barry Wainwright [MVP]

Thank you very much Barry.

I guess that I should have explained that I want the content in one
block so that it can then be processed by an external program. When I
run the script you graciously provided above, it only delivers the
content of one message, I'm looking to get the content of all the
messages that I have selected. I guess what I am having a problem with
is how to walk through the structure of entourage to get to the content
of each item (message). I'll look on your website, but if you could
give me any more hints it would be greatly appreciated.

Thanks again,

Stephen

Simply concatenate the data into a single variable:

Set myData to ""
Tell app "microsoft entourage"
Set theMessages to current messages
Repeat with aMessage in theMessages
Set mySrc to content of aMessage
Set myData to myData & Return & mySrc
End repeat
End tell
Return mydata
 
S

sedgington

Barry said:
Simply concatenate the data into a single variable:

Set myData to ""
Tell app "microsoft entourage"
Set theMessages to current messages
Repeat with aMessage in theMessages
Set mySrc to content of aMessage
Set myData to myData & Return & mySrc
End repeat
End tell
Return mydata


--
Barry Wainwright
Microsoft MVP (see http://mvp.support.microsoft.com for details)
Check out the Entourage User's WebLog for hints, tips and troubleshooting
<http://homepage.mac.com/barryw/weblog/weblog.html>

Wow, you are fast! This does exactly what I need. If I am understanding
it correctly, you are setting an empty myData container first and then
telling Entourage to go through each message and extract the content to
the container separated by a return. Once that is done, you ask it to
present the the information in the myData container. Simple and
elegant. The solution I was working on was to
set theList {}
set theList & mySrc

which gave me theList with all the items as an array but did not give
me a report the way myData does even when I
return theList
This is a tremendously helpful insight into how applescript works.
Again, many thanks!
Stephen
 
B

Barry Wainwright [MVP]

Wow, you are fast! This does exactly what I need. If I am understanding
it correctly, you are setting an empty myData container first and then
telling Entourage to go through each message and extract the content to
the container separated by a return. Once that is done, you ask it to
present the the information in the myData container. Simple and
elegant. The solution I was working on was to
set theList {}
set theList & mySrc

which gave me theList with all the items as an array but did not give
me a report the way myData does even when I
return theList
This is a tremendously helpful insight into how applescript works.
Again, many thanks!
Stephen

That approach works as well, but you just need to convert the list into a
text string at the end:

Set AppleScript's text item delimiters to {return}
Return theList as text
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top