Re: Unbreaking e-mails
Re: Unbreaking e-mails
- Subject: Re: Unbreaking e-mails
- From: "Christopher C. Stone" <email@hidden>
- Date: Mon, 19 Feb 2001 15:30:22 -0600
At 11:15 -0600 02/19/2001, Erik Ness wrote:
>
What I would like to be able to do is to unbreak the email formatting: remove single line breaks and turn double line breaks into singles. I know I could do this in another program, but is there a way to manipulate the text within AppleScript?
___________________________________________________________________________
Hello Erik,
This would take a little adjusting to suit your needs, but it's fast and flexible.
Osax dependency: RegEx Commands
http://www.lazerware.com/FTP/RECommands.hqx
OPTION-7 and OPTION-8 indicate their keyboard equivalents.
on StripIt(t)
set txtEnd to ""
if t ends with return then
set txtEnd to return
end if
set xcepLst to "Mr|Mrs"
-- Replace any non-breaking spaces with a space
set t to REReplace t with " " pattern " "
-- Strip whitespace from the beginning of lines
set t to REReplace t with "" pattern "^\\s+"
-- Strip whitespace from the end of lines
set t to REReplace t with "" pattern "\\s+$"
-- Strip multiple spaces.
set t to REReplace t with " " pattern "( |\\s)+"
-- Manage the period in exception list items
set t to REReplace t with "\\1OPTION-8|OPTION-8" pattern "(" & xcepLst & ")\\."
-- Replace more then two consecutive returns with two returns.
set t to REReplace t with "\\r\\r" pattern "\\r\\r+" separator "OPTION-7"
-- Give two consecutive returns a placeholder.
set t to REReplace t with "|cr|cr|" pattern "\\r\\r" separator "OPTION-7"
-- Replace single returns with a space.
set t to REReplace t with " " pattern "\\r" separator "OPTION-7"
-- Restore two consecutive returns.
set t to REReplace t with "\\r\\r" pattern "\\|cr\\|cr\\|" separator "OPTION-7"
-- Replace end punctuation with itself and two spaces.
set t to REReplace t with "\\1 " pattern "([\\.?!]\\\"*) +" separator "OPTION-7"
-- Restore periods to exception list items.
set t to REReplace t with "\\." pattern "OPTION-8\\|OPTION-8"
set t to t & txtEnd
return t
end StripIt
Best Regards,
Christopher Stone
______________________________
StoneWorks Computer Consulting
email@hidden