Text : how to delete return character ? (a script for Eudora)

Hello,

I made a script to notify me when new mails arrive in Eudora.
It works well.

But I would like to delete the return characters in the message notification to display (in growl) the maximum of the body message.

Here’s the part of the code to get the content of the new mails :

tell application "Eudora"
				
				set NewMail to 0
				
				set MyDisplaySenders to {}
				set myDisplaySubjects to {}
				set myDisplayBodies to {}
				
				set DisplayMess to {}
				set DisplaySub to {}
				set DisplayBody to {}
				
				repeat with MessNo from 1 to NbrMessNotification
					
					set messStatus to the status of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
					if messStatus is unread then
						set mySender to sender of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
						set mySubject to subject of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
						set myBody to (body) of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
						set DisplayMess to {mySender}
						set DisplaySub to {mySubject}
						set DisplayBody to {myBody}
						set NewMail to (NewMail + 1)

					end if
					set MyDisplaySenders to MyDisplaySenders & DisplayMess
					set myDisplaySubjects to myDisplaySubjects & DisplaySub
					set myDisplayBodies to myDisplayBodies & DisplayBody
					
				end repeat

So myDisplayBodies is a list of string.
And this list contain each body of new mails.

I made also some functions to remplace return character by space character :

on ReplaceReturnList(myList)
	repeat with itemIndex from 1 to length of myList
		set the item itemIndex of myList to ReplaceReturn(the item itemIndex of myList)
	end repeat
	return myList
end ReplaceReturnList


on ReplaceReturn(myString)
	set myString to ReplaceString(myString, "

", " ")
	set myString to ReplaceString(myString, "
", " ")
	return myString
end ReplaceReturn


on ReplaceString(myString, OldCharacter, NewCharacter)
	set text item delimiters of AppleScript to OldCharacter
	set myTextList to text items of myString
	set text item delimiters of AppleScript to NewCharacter
	return myTextList as text
end ReplaceString

These functions work when I test them in script editor.
For example with :

return ReplaceReturnList({"go go go
go



go

go"})

But It doesn’t work in the full script.
Maybe because of some text format ?
If you have some idea …

Thanks

Christophe.


Full Script :

-- 	Required :
-- 		Eudora > 	Creation of a Notification mailbox
--					Creation of a "Copy to" filter to Notification mailbox for "any header" incoming mail
--		Growl > 		Optimized for Growl "Music Video" display

on run
	tell application "System Events" to set ListProcesses to name of processes whose visible is true
	if "Eudora" is not in ListProcesses then
		set x to display dialog "Do you want to activate Eudora ?" buttons {"Yes", "No"} default button "Yes"
		if button returned of x is "Yes" then
			tell application "Eudora" to activate
		end if
	end if
end run

on idle
	set Delay0 to 300 -- Check if Eudora is active with this delay
	
	tell application "System Events" to set ListProcesses to name of processes whose visible is true
	if "Eudora" is in ListProcesses then
		
		set MailboxNotification to "Notification"
		set MailboxFolder to ""
		set Delay1 to 40 -- Check the mailbox with this delay
		
		set IntervalDelay to Delay1
		
		tell application "System Events" to set frontApp to (name of every process whose frontmost is true) as Unicode text
		if frontApp is "Eudora" then
			Notification2Trash()
		end if
		
		tell application "Eudora"
			set NbrMessNotification to number of messages in mailbox MailboxNotification of mail folder MailboxFolder
		end tell
		
		if (NbrMessNotification > 0) then
			
			tell application "Eudora"
				
				set NewMail to 0
				
				set MyDisplaySenders to {}
				set myDisplaySubjects to {}
				set myDisplayBodies to {}
				
				set DisplayMess to {}
				set DisplaySub to {}
				set DisplayBody to {}
				
				repeat with MessNo from 1 to NbrMessNotification
					
					set messStatus to the status of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
					if messStatus is unread then
						set mySender to sender of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
						set mySubject to subject of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
						set myBody to (body) of message MessNo in mailbox MailboxNotification of mail folder MailboxFolder
						set DisplayMess to {mySender}
						set DisplaySub to {mySubject}
						set DisplayBody to {myBody}
						set NewMail to (NewMail + 1)
					end if
					set MyDisplaySenders to MyDisplaySenders & DisplayMess
					set myDisplaySubjects to myDisplaySubjects & DisplaySub
					set myDisplayBodies to myDisplayBodies & DisplayBody
					
				end repeat
			end tell
			
			
			set myDisplayBodies to ReplaceReturnList(myDisplayBodies)
			
			
			if (NewMail = 1) then
				set NotificationMessage to ("You have " & NewMail & " new message")
			else
				set NotificationMessage to ("You have " & NewMail & " new messages")
			end if
			
			
			if (NewMail ≥ 1) then
				tell application "GrowlHelperApp"
					-- Make a list of all the notification types 
					-- that this script will ever send:
					set the allNotificationsList to ¬
						{"Eudora Notification", "Eudora Message"}
					
					-- Make a list of the notifications 
					-- that will be enabled by default.      
					-- Those not enabled by default can be enabled later 
					-- in the 'Applications' tab of the growl prefpane.
					set the enabledNotificationsList to ¬
						{"Eudora Notification", "Eudora Message"}
					
					-- Register our script with growl.
					-- You can optionally (as here) set a default icon 
					-- for this script's notifications.
					register as application ¬
						"Eudora" all notifications allNotificationsList ¬
						default notifications enabledNotificationsList ¬
						icon of application "Eudora"
					
					--       Send a Notification...
					set NotificationBody to ""
					repeat with itemIndex from 1 to NewMail
						set messSubject to the item itemIndex of myDisplaySubjects
						set messSender to the item itemIndex of MyDisplaySenders
						set NotificationBody to NotificationBody & messSender & "  -  " & messSubject & return
					end repeat
					notify title ¬
						"Eudora  -  " & NotificationMessage description ¬
						NotificationBody with name ¬
						"Eudora Notification" application name "Eudora"
					
					repeat with itemIndex from 1 to NewMail
						set messSubject to the item itemIndex of myDisplaySubjects
						set messSender to the item itemIndex of MyDisplaySenders
						set messBody to the item itemIndex of myDisplayBodies
						notify title ¬
							(messSender & "  -  " & messSubject) description ¬
							messBody with name ¬
							"Eudora Message" application name "Eudora"
					end repeat
				end tell
			end if
			
		end if
		
	else
		set IntervalDelay to Delay0
	end if
	return IntervalDelay
end idle

on reopen
	set MessageExec to Notification2Trash()
end reopen

-- Notification2Trash : Delete all message in MailBox Notification

on Notification2Trash()
	tell application "Eudora"
		set MailboxNotification to "Notification"
		set MailboxFolder to ""
		if ((number of messages in mailbox MailboxNotification of mail folder MailboxFolder) > 0) then
			repeat with MessNo from 1 to (number of messages in mailbox MailboxNotification of mail folder MailboxFolder)
				set status of message 1 in mailbox MailboxNotification of mail folder MailboxFolder to "2"
				set priority of message 1 in mailbox MailboxNotification of mail folder MailboxFolder to "180"
				move message 1 in mailbox MailboxNotification of mail folder MailboxFolder to end of mailbox "Trash"
			end repeat
		end if
	end tell
end Notification2Trash


on ReplaceReturnList(myList)
	repeat with itemIndex from 1 to length of myList
		set the item itemIndex of myList to ReplaceReturn(the item itemIndex of myList)
	end repeat
	return myList
end ReplaceReturnList


on ReplaceReturn(myString)
	set myString to ReplaceString(myString, "

", " ")
	set myString to ReplaceString(myString, "
", " ")
	return myString
end ReplaceReturn


on ReplaceString(myString, OldCharacter, NewCharacter)
	set text item delimiters of AppleScript to OldCharacter
	set myTextList to text items of myString
	set text item delimiters of AppleScript to NewCharacter
	return myTextList as text
end ReplaceString

AppleScript: AppleScript 1.10.6
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

The most likely possibility is that the text item delimiters in your script haven’t been properly restored. Be very careful to check that. Without deciphering yours, here’s how I would do it:

set myTxt to "go go go
go



go

go"

set CR to ASCII character 13
set LF to ASCII character 10

set tid to AppleScript's text item delimiters
if myTxt contains CR then
	set AppleScript's text item delimiters to CR
else if myTxt contains LF then
	set AppleScript's text item delimiters to LF
else
	set AppleScript's text item delimiters to tid
	display dialog "No returns or line feeds"
end if
set TI to text items of myTxt
set text item delimiters to space
set txt to TI as string
set text item delimiters to tid
txt  --> "go go go go    go  go"

Having said that, I use SmartWrap to do it for me.

Thank you.

With ASCII character 13 and 10 instead of “\r”, it’s now much better.
And I will be careful with the text item delimiters.

Thanks again.

And Thanks for SmartWrap… it looks very useful.

Christophe.

I was interested in your problem because you are one of the few posters I have seen on this bbs who use Eudora. Perhaps I should share with so rare a user the script that I use to accomplish basically the same things. This is one of the first scripts I ever wrote.

-- This script will count the new mail found in all your mailboxes, display a Fastscripts notification, and then open all the mailboxes that have new mail. FastScripts notification could also be a dialog box or Growl

-- Eudora keeps your mailboxes in a folder called "Mail Folder" found in¬("Your_HD:Users:Your_Username:Documents:Eudora Folder:)

-- To get the proper address in the following statement, run another script with the statement set myChoice to (choose folder), navigate to your Eudora Mail folder and copy the result into the "set mF..." statement below.

-- tell application "Eudora" to connect

set mF to ((path to documents folder as text) & "Eudora Folder:Mail Folder:") as alias

tell application "Finder" to set boxes to mF's entire contents
set mbCount to count of boxes
set BoxesWithMail to {}
set CountInBoxes to {}
set Apl to ((ASCII character 240) & space & space)

repeat with j from 1 to mbCount
	set mbName to last word of (item j of boxes as text)
	set newMail to checkNewMail(mbName)
	if newMail > 0 then
		set end of BoxesWithMail to mbName
		set end of CountInBoxes to newMail
	end if
end repeat

if length of BoxesWithMail = 0 then
	tell application "FastScripts" to display message Apl & "No mail" at screen position top center dismissing after delay 1.5
	
else
	set mailNotice to TellMe(BoxesWithMail, CountInBoxes)
	tell application "FastScripts" to display message mailNotice at screen position top center dismissing after delay (count of BoxesWithMail)
	
	tell application "Eudora"
		repeat with k from 1 to count of BoxesWithMail
			if item k of BoxesWithMail = "Inbox" then
				open mailbox "In"
			else
				open mailbox (item k of BoxesWithMail)
			end if
		end repeat
		activate
	end tell
end if

on checkNewMail(mail_box)
	tell application "Eudora"
		if (name of mailbox mail_box = "Trash") then
			set MailWaiting to 0
		else
			set MailWaiting to recent unread in mailbox mail_box
		end if
		return MailWaiting
	end tell
end checkNewMail

on TellMe(boxList, MailCount)
	set msg to ""
	set boxCount to count of boxList
	repeat with n from 1 to boxCount
		if item n of boxList = "In" then set item n of boxList to "Inbox"
		set msg to msg & my Apl & (item (n) of MailCount as text) & " waiting in " & (item n of boxList) & return
	end repeat
	return msg
end TellMe

Yes, we’re not so much to still use Eudora…

I saw your script - I guess - a few weeks ago when I tried to find some documentation about Eudora and Applescript.
But I didn’t undestand anything to Applescript…

The other problem : I have a lot of mailboxes, too much maybe.
So I didn’t want to scan all of them. (I don’t know if it’s a good reason… )

So I use a different way :
a filter copy the new mails in a Notification mailbox.
(I can put the filter at the right place in the filter settings to adjust the notification)
And I just have to scan the Notification mailbox. Then I delete these messages …

It’s almost my first script so It looks like a draft…

Christophe