-- Rewrap paragraphs that start with a quote char but were not wrapped,
-- i.e. a set of long soft-wrapped paragraphs, where the first line always
-- starts with the quote char.
-- Uses osaxen WrapText (see below) and AkuaSweets.

-- Markus Frischknecht (mailto:mfrischknecht@access.ch) 11/8/99
-- Version history:
-- 1.0 11/8/99 First version.
-- This script is public domain. Use and change at will, but if you release a
-- modified version please include the information above.

(*
WrapText osax by H. Iimori. Can be found at
<http://www.bekkoame.or.jp/~iimori/indexSoftware.html>
The page description and documents are Japanese. However, the entry in
the dictionary of the osax should be enough to start using it:

WrapText: Wrap Text
	WrapText string
		[width small integer] -- Wrap width by bytes. Default is 76.
		[prefix string] -- Add this string to beginning of each lines
		[remove string] -- Remove this string from beginning of each lines
		[onlyLongLines boolean] -- Wrap only long lines
		[scriptCode small integer] -- Script code of text. Use system script when omitted.
	Result: string  -- wrapped text
*)

-- set up double tell mechanism

tell application "Finder"
	try
		-- MacOS 8.0 and 8.1, but also works for Sys 7.5 and 7.6
		set EU to (process 1 whose creator type is "CSOm") as «class psn »
	on error
		-- Eudora is not running, so abort
		beep
	end try
end tell


tell application "Eudora Pro 3.1.3" to tell EU
	
	try
		set currQuote to setting 7009 -- quote string
		
		set selText to selected text
		
		-- Go through each paragraph; if empty, simply insert quote char
		-- else use WrapText on it.
		
		set NBParagraphs to (count selText's paragraphs) - 1
		
		set finalText to ""
		
		repeat with i from 1 to NBParagraphs
			set varLine to paragraph i of selText
			
			if varLine is not currQuote then
				set varLine to WrapText varLine prefix currQuote remove currQuote with onlyLongLines
			end if
			
			set finalText to finalText & varLine & return
		end repeat
		
		
		set selected text to finalText
	on error
		-- in case no selection exist, or no editable window open
		beep
	end try
end tell