Fix for KB926521 (broken Sent Items from iPhone or other mobiledevice)

J

Jon Connell

I think I have a workaround for this problem:

http://support.microsoft.com/kb/926521

Basically, rewriting the sent item in AppleScript. I am almost there,
but I can't get the "make new recipient" bit of this script work.
Anyone have any ideas?

Jon

tell application "Microsoft Entourage"
set selectedMessages to current messages
if selectedMessages is {} then
display dialog "Please select a message first and then run this
script." with icon 1
return
end if
repeat with theMessage in selectedMessages
set theHeaders to headers of theMessage
set lineOne to paragraph 1 of theHeaders
set lineTwo to paragraph 2 of theHeaders
if lineOne begins with "MAIL FROM: " and lineTwo begins with "RCPT
TO: " then
set theBody to the content of theMessage
set paragraphList to every paragraph of theBody
set newHeaders to ""
set newBody to ""
set myState to "header"
set ccString to ""
set toString to ""
set theSubject to ""
set theDate to ""
repeat with i from 1 to the count of paragraphs of theBody
set thisParagraph to item i of the paragraphList
if thisParagraph = "" then
set myState to "body"
else
if (myState = "cc" or myState = "to") and thisParagraph contains
":" then
set myState to "header"
set AppleScript's text item delimiters to tid
end if

if myState = "header" then
if thisParagraph begins with "Subject: " then
set theSubject to thisParagraph
else if thisParagraph begins with "From: " then
set theSender to thisParagraph
else if thisParagraph begins with "To: " then
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "To: "
set theToString to text item 2 of thisParagraph
set myState to "to"
else if thisParagraph begins with "Cc: " then
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "Cc: "
set theCcString to text item 2 of thisParagraph
set myState to "cc"
else if thisParagraph begins with "Date: " then
set theDate to thisParagraph
end if
set newHeaders to newHeaders & thisParagraph & (ASCII character
13)
else if myState = "cc" then
set theCcString to theCcString & thisParagraph
else if myState = "to" then
set theToString to theToString & thisParagraph
else if myState = "body" then
set newBody to newBody & thisParagraph & (ASCII character 13)
end if
end if
end repeat
set recipientList to {}
if theCcString $B!b(B "" then
set AppleScript's text item delimiters to ","
set theRecipients to every text item of theCcString
repeat with thisRecipient in theRecipients
if thisRecipient contains "<" and thisRecipient contains ">" then
set AppleScript's text item delimiters to "<"
set displayName to text item 1 of thisRecipient
set recipientAddress to text item 2 of thisRecipient
set AppleScript's text item delimiters to ">"
set recipientAddress to text item 1 of recipientAddress
else
set displayName to thisRecipient
set recipientAddress to thisRecipient
end if
if displayName contains "\"" then
set AppleScript's text item delimiters to "\""
set displayName to text item 2 of displayName
end if
make new recipient at end of recipientList with properties
{recipient type:cc recipient, address:{display name:displayName,
address:recipientAddress}}
end repeat
end if
if theToString $B!b(B "" then
set AppleScript's text item delimiters to ","
set theRecipients to every text item of theToString
repeat with thisRecipient in theRecipients
if thisRecipient contains "<" and thisRecipient contains ">" then
set AppleScript's text item delimiters to "<"
set displayName to text item 1 of thisRecipient
set recipientAddress to text item 2 of thisRecipient
set AppleScript's text item delimiters to ">"
set recipientAddress to text item 1 of recipientAddress
else
set displayName to thisRecipient
set recipientAddress to thisRecipient
end if
if displayName contains "\"" then
set AppleScript's text item delimiters to "\""
set displayName to text item 2 of displayName
end if
make new recipient at end of recipientList with properties
{recipient type:to recipient, address:{display name:displayName,
address:recipientAddress}}
end repeat
end if
set recipients of theMessage to theRecipients
set sender of theMessage to theSender
set subject of theMessage to theSubject
set time sent of theMessage to date theDate
set content of theMessage to newBody
end if

end repeat
end tell
 
W

William Smith [MVP]

Jon said:
I think I have a workaround for this problem:

http://support.microsoft.com/kb/926521

Basically, rewriting the sent item in AppleScript. I am almost there,
but I can't get the "make new recipient" bit of this script work.
Anyone have any ideas?

Hi Jon!

I think you're on the right track for using AppleScript but from a
little testing I think you're using a sledgehammer instead of a
ball-peen hammer.

View the source of any of your messages. Notice the message source is
practically identical to any other regular message source with the
exception of the first 2-3 (more or less) lines at the top separated by
a blank space. Here's an example:

MAIL FROM: <[email protected]>
RCPT TO: <[email protected]>
RCPT TO: <[email protected]>

X-MimeOLE: Produced By Microsoft Exchange V6.5
Received: from 10.0.0.1 ([10.0.0.1]) by
...

If you drag the "corrupt" message to the Desktop (creating a Message.eml
file), open it in a text editor and remove the first lines and the blank
space, save and drag back into Entourage then your message reads correctly.

So, how do you script changing the *source* of the message? Sadly,
that's read only.

I've created the following rough script to allow me to read these
"corrupted" sent messages. I place it in the Entourage Script menu,
select a message (only works with one at a time) and then select the
script from the Script menu:



-- test that this is a corrupt ActiveSync message
-- and get its source

tell application "Microsoft Entourage"
set theMessage to the selection
set theSource to source of item 1 of theMessage
if headers of item 1 of theMessage contains "Subject" then
return -- do not continue if properly formatted
end if
end tell

-- parse the source until you come to a blank blank line

set lineCount to 1
set aParagraph to "not empty"

repeat until aParagraph is ""
set aParagraph to paragraph lineCount of theSource
set lineCount to lineCount + 1
end repeat

-- copy the correct source of the message
-- to a new file in the temporary items folder

set newSource to ""

repeat with i from lineCount to count of paragraphs of theSource
set newSource to newSource & paragraph i of theSource & return
end repeat

set fileName to (path to temporary items) & "Message.eml" as string
set newFile to open for access file fileName with write permission
write newSource to newFile
close access newFile

-- set the new file's type and creator code
-- so that Entourage will open it natively
-- and open the message

tell application "Finder"
set file type of file fileName to "M822"
set creator type of file fileName to "OPIM"
open file fileName
end tell



My script doesn't handle very well the encoded portions of replies that
may be contained at the bottom of the message. But at least I can read
my own part of the message.

If you can devise a method to get the message back into Entourage then
we'll have made good progress.

--

bill

Entourage Help Page <http://entourage.mvps.org/>
Entourage Help Blog <http://blog.entourage.mvps.org/>
YouTalk <http://nine.pairlist.net/mailman/listinfo/youtalk>
Twitter: follow <http://twitter.com/meck>
 
W

William Smith [MVP]

William said:
I think you're on the right track for using AppleScript but from a
little testing I think you're using a sledgehammer instead of a
ball-peen hammer.

I've worked out all the bugs I can for the script and it's working very
well for me. I'll be making a blog post on it this weekend along with
the script for download.

--

bill

Entourage Help Page <http://entourage.mvps.org/>
Entourage Help Blog <http://blog.entourage.mvps.org/>
YouTalk <http://nine.pairlist.net/mailman/listinfo/youtalk>
Twitter: follow <http://twitter.com/meck>
 
J

Jon Connell

I've worked out all the bugs I can for the script and it's working very
well for me. I'll be making a blog post on it this weekend along with
the script for download.

Great, thanks. I'll take a look.

Jon
 

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