I have a script that saves off parts of an email to a text file. Ocassionally the subject headings of the mails are prepended with *** SPAM *** thanks to my webhost. I would like this to be removed so it doesn’t end up in the subject of my exported file.
I am looking for what to do in my script to take my subject string and strip off this spam label.
set Subject to "*** SPAM ***Make millions selling chia-pets!!!"
set spam to "*** SPAM ***" --> The string to look for
if (characters 1 through (count characters of spam) of Subject as string) is equal to spam then
set Subject to ((characters ((count characters of spam) + 1) through -1 of Subject) & spam) as string
end if
That looks like a text item delimiter problem. If the delimiters are set to anything other than the default {“”}, you’ll get the delimiter characters inserted between the characters of Subject when you coerce them back to string. If you quit the program running the script, then relaunch it and try again, you may find that everything’s OK. Alternatively, you could try inserting this at the top of the script:
set applescript's text item delimiters to {""}
Better still, eshew the use of ‘characters … as string’ altogether. It’s very inefficient. Use ‘text’ instead:
set Subject to "***SPAM*** Free Download"
set spam to "***SPAM***" --> The string to look for
if Subject begins with spam then
-- Cut "***SPAM***" and the following space.
set Subject to text ((count spam) + 2) thru -1 of Subject
end if