Cannot return the Content of some emails

I am having trouble with a script I am working on to transfer email messages and attachments to text files. There are instances (not all) where I cannot return the content of the message. To try and establish what the problem is I redirected one of the offending messages with the attachment changed and the message itself replace with “Original Text Replaced”. I then wrote a simple scrip (below) to return the subject, senders name and the content. Please accept the message did have content.

tell application “Mail”

set the_message to item 1 of (get selection as list)
display dialog subject of the_message as string
display dialog (extract name from sender of the_message as string)
display dialog content of the_message as string

end tell

I logged the scrip as it ran and the results are below as can be seen the subject and senders name were correctly returned but not the content.

tell application “Mail”
get selection
{message id 23888 of mailbox “Test/Test10”}
get subject of message id 23888 of mailbox “Test/Test10”
“5 New Text & Doc”
display dialog “5 New Text & Doc”
{button returned:“OK”}
get sender of message id 23888 of mailbox “Test/Test10”
“"MCCARTHY, Dorothy" dorothy.mccarthy@oup.com
extract name from “"MCCARTHY, Dorothy" dorothy.mccarthy@oup.com
“MCCARTHY, Dorothy”
display dialog “MCCARTHY, Dorothy”
{button returned:“OK”}
get content of message id 23888 of mailbox “Test/Test10”
“???”
display dialog “???”
{button returned:“OK”}
end tell

I then saved the message by selecting Save As from mail as a text file that I copied as is shown below and it can be seen it does have text which should have been captured as the content.

Resent-From: peter mitchell mitch@surfbvi.com
From: “MCCARTHY, Dorothy” dorothy.mccarthy@oup.com
Date: February 1, 2006 5:58:07 AM GMT-04:00
Resent-To: Mitchell UK Peter & Gloria mitch@vail.net
To: mitch@surfvi.com, mitchbvi@btinternet.com, mitch@vail.net
Subject: 5 New Text & Doc

Original Text Replaced

I feel it must be something embedded in the email message but I cannot work out what or how to find out. I have backspaced to delete the text and attachment from the original email message then added new text and attachment. It still refuses to return the content of the email. If I use mail to remove the attachment and run the scrip above it returns the notification that the attachment has been removed but still does not show the original content as can be seen from this log.

tell application “Mail”
get selection
{message id 23901 of mailbox “Sent Messages” of account “Surfbvi”}
get subject of message id 23901 of mailbox “Sent Messages” of account “Surfbvi”
“5 New Text & Doc”
display dialog “5 New Text & Doc”
{button returned:“OK”}
get sender of message id 23901 of mailbox “Sent Messages” of account “Surfbvi”
“"MCCARTHY, Dorothy" dorothy.mccarthy@oup.com
extract name from “"MCCARTHY, Dorothy" dorothy.mccarthy@oup.com
“MCCARTHY, Dorothy”
display dialog “MCCARTHY, Dorothy”
{button returned:“OK”}
get content of message id 23901 of mailbox “Sent Messages” of account “Surfbvi”
"?

[The attachment Test for email attachments.doc has been manually removed]

?"
display dialog "?

[The attachment Test for email attachments.doc has been manually removed]

?"
{button returned:“OK”}
end tell

I would greatly appreciate any help or suggestions.

Thanks

peter

Try getting the source property instead of content. If it is an HTML formatted email (or something besides plain text) I believe it is returned as "source’ instead of “content”.

It should be easy enough to find out. If you look in the “view” menu at “show” for the message in question, see if it has “plain text alternative” or just “raw source” enabled (not grayed out).

Kevin

Thank you very much for the suggestion, I had in fact tried returning source rather than content, which did of course include the message. Unfortunately as you know source is a lot more than just the content, in fact on one test file a ten line message saved as source to a text file covered 28 pages. Obviously I need to parse everything but the message out, but as a real newcomer to applescript I don’t know how to do that. You are correct it is not just HTML that causes the problem in fact with some documents html is not a problem (or at least does not appear to be).

Any further thoughts or instructions on how to parse would be very much appreciated.

thanks you

Peter