Problem with routine detaching folder action

G’day scripters

I’m using the following routine (lifted from these pages) to seperate out attachments embedded in rft formatted mail.

Trouble is, we received a lonnnnng email, full of ‘/’, that causes an ‘out of memory error’ on the ‘set mySource to source of thisMessage’. The error causes the script to become detached from the folder before the error trapping kicks in.

Is there any fix, please

Regards

Santa


repeat with thisMessage in the_messages
								if (id of thisMessage & ".emlx" as string) is equal to thePrintName then
									set selected messages of mess_viewer to (thisMessage as list)
									display dialog (id of thisMessage & ".emlx" as string) & return & thePrintName
									
									-- *** PRINTING ***
									
									-- Routine to correct text when attachments embedded in rtf
									try
										set mySource to ""
										try
											set mySource to source of thisMessage
										end try
										if mySource contains "Content-Type" then
											set myContentType to content of header "Content-Type" of thisMessage
										else
											set myContentType to ""
										end if
										
										if (myContentType contains "multipart/mixed;" or myContentType contains "multipart/alternative;") and (mySource contains "Content-Type: text/plain;") then
											set myBoundary to item -1 of my textToList(myContentType, "boundary=")
											if character 1 of myBoundary contains "\"" then set myBoundary to (characters 2 thru -2 of myBoundary) as Unicode text
											set myParts to my textToList(mySource, myBoundary)
											set myContent to ""
											repeat with myPart in myParts
												if myPart contains "Content-Type: text/plain;" then
													set myContent to myContent & (my listToText(items 2 thru -2 of my textToList(myPart, ((ASCII character 10) & (ASCII character 10))), ((ASCII character 10) & (ASCII character 10))))
												end if
											end repeat
										else
											tell application "Mail" to set myContent to content of thisMessage
										end if
									on error TheError number errNum
										set myContent to "Content preparation error"
										set PrintError to "There is a problem with the routine preparing the Content: " & return & return & TheError & return & return
										if WriteTheErrors then my WriteErrors(PrintError, errNum)
									end try