Help - Search - Members - Calendar
Full Version: Trouble Using Applescript Method for Mac Mail
hsc message board > Main > hsc Software Support
Chris F
Hi. I'm new to using Purify and trying to make it work.

I am using the Applescript Rules based method in Apple Mail and it works fine in the sense that it will move the offending email to Trash. But by doing so before the email hits the Inbox, my server does not appear to take note that the email has been downloaded to Mail and it keeps downloading the same spam emails over and over -- and putting them in the trash over and over. I've tried a variety of settings inside Mail to try to fix this, but it only returns to working when I uncheck the Purify Rule, let the email land in the Inbox, then move it to trash. If I do that, then Mail doesn't download more copies. So that pretty much localizes the issue to the way the Purify applescript is performing it's functions. I suppose that if Trash were emptied immediately this might solve the problem by notifying the server, but I don't want to do that in case of errors. I'd like to be able to see what's in the trash before it empties.

After some thought, I think that would be great would be to mark the offending email as Junk and let it continue to the Inbox, where Mail's Junk filter can handle it (either leaving it marked as Junk, or moving it to the Junk Mail folder). Or, alternatively, for the applescript to tag the Spam email in some way -- and then use another Mail Rule move the email to trash or Junk. The latter would work, I think, because I have other rules set up that move emails into folders as they come in and the server knows the email is delivered. It seems that by going outside Mail's rules and letting the Applescript do the moving is where the problem lies.

After doing a little research on Google, I thought I found a way to modify the Purify apple script to set status of Spam emails to Junk (see below). Unfortunately, it is not working. What seems to be happening, as far as I can tell, is that validated emails are being announced as validated, while no announcement and no Junk mail status change is happening to the emails identified as Spam by Purify. They just land in my inbox as if Purify had not processed them. I would love to have some help figuring out a solution -- of any kind -- to my problem. It is much appreciated, in advance.

[EDIT: Since posting a short time ago, I blacklisted an email account of my own and sent myself an email and this time Purify said aloud that the email was rated as "Spam, blacklisted:" and name of sender, and then said "Mail Error". I am, however, still getting other emails that are landing in my mailbox without comment by Purify, neither validated nor not validated. They are Spam emails; though I'm not sure if Purify would catch them as such]

Here was my effort at modifying the applescript:

on perform_mail_action(info)
tell application "Mail"
set theMessages to |SelectedMessages| of info
repeat with thisMessage in theMessages
try
set the_mailbox to mailbox of thisMessage
set the_account to account of the_mailbox
set the_email_addresses to email addresses of the_account
set the_full_name to full name of the_account
-- e-mail address
set the_email_address to item 1 of the_email_addresses
set the_rating to my Rate(the_full_name, the_email_address, source of thisMessage)
if the_rating contains "SPAM" then
say the_rating
set junk mail status of thisMessage to true
-- set mailbox of thisMessage to mailbox "Trash" of the_account
else if the_rating contains "IGNORE" then
say the_rating
set junk mail status of thisMessage to true
-- set mailbox of thisMessage to mailbox "Trash" of the_account
else
say "You have received validated email from " & my ExtractName(sender of thisMessage)
end if
on error
say "Mail error!"
end try
end repeat
end tell
end perform_mail_action
...

Thanks again in advance for the help.

Chris
Jeff Hendrickson
Welcome Chris!

If you are using a POP server, then I recommend that you use the "pass-through" filtering method. I have used this in the past with Apple Mail, and it works great.

I would recommend that you change your email account to use IMAP, and use the AppleScript method. I use this now with Apple Mail, and it works great.

You should NOT use both methods of filtering (pass-through, AppleScript) together. HTH.
Chris F
Hi Jeff,

I called the other day, actually, and spoke to someone (you?) when I was having trouble using the pass-through method, which is what I tried first -- and at that point I was advised to use the applescript method. It's a little frustrating to get a whole new set of advice after working hard on getting that to work. I don't remember there being anything in manual regarding not using POP. If POP doesn't work with applescript that aught to be noted.

Frankly, having tried one method unsuccessfully and now having spent a few hours on a second method, I'd rather not try to solve the problem I'm having by opening myself up to new ones by trying yet a third method.

Do you have any advice on how to get it functioning using applescript?

One new development is that I put back in a line that sets the mailbox of the "the_account" but instead of making that mailbox "trash", I made it "Inbox":

set mailbox of thisMessage to mailbox "Inbox" of the_account

After doing that, the blacklisted email that I send from one of my accounts IS labelled as Junk and is dropped into my Inbox with the Junk label. Which is excellent. However, the program goes on to say "MAIL ERROR". I feel that I am getting closer to solving the issue. Do you or anyone else who knows applescript and this particular piece of applescript have any suggestions on how to get it past whatever error it's having? And why the script is not announcing or labeling other pieces of spam email, but rather just dropping them into my inbox "unannounced".

Thanks in advance for sticking with me on this. And if we can solve it, it could be a solution for other clients who are in the same boat as I.

Chris



QUOTE (Jeff Hendrickson @ Jul 9 2010, 03:01 PM) *
Welcome Chris!

If you are using a POP server, then I recommend that you use the "pass-through" filtering method. I have used this in the past with Apple Mail, and it works great.

I would recommend that you change your email account to use IMAP, and use the AppleScript method. I use this now with Apple Mail, and it works great.

You should NOT use both methods of filtering (pass-through, AppleScript) together. HTH.
Jeff Hendrickson
You are brave sir.

The AppleScript that is included for Apple Mail with Purify works perfectly out of the box. I would suggest that you use it, and get some "up time" so that you can become familiar with how Purify works, get your blacklist, whitelist, ignorelist, country filter, etc... set up and then when you're feeling brave, start monkeying around with the AppleScripts.

I hope that you can understand that I can't give away any free programming time. I've attached the Purify AppleScript that I am running with Apple Mail. Works perfectly.
It's cool that you're tinkering with modifying the script. Good luck. If you feel like sharing any cool improvements to it with other users, that's what this forum is all about. One last bit of advice, if you run Purify with logging on, the file log.txt that is produced in your Purify program folder will give you a detail of any complaints that Purify has with your use of the program. You could think of it as a debugging tool.

QUOTE
--
-- Rate Received (Mail)
-- -----------------------------------------
-- AppleScript to feed test PurifyOSX
--
-- by: hendrickson software components
-- copyright 2009, all rights reserved
--
on perform_mail_action(info)
tell application "Mail"
set theMessages to |SelectedMessages| of info
repeat with thisMessage in theMessages
try
set the_mailbox to mailbox of thisMessage
set the_account to account of the_mailbox
set the_email_addresses to email addresses of the_account
set the_full_name to full name of the_account
-- e-mail address
set the_email_address to item 1 of the_email_addresses
set the_rating to my Rate(the_full_name, the_email_address, source of thisMessage)
if the_rating contains "SPAM" then
-- say the_rating
set mailbox of thisMessage to mailbox "Trash" of the_account
else if the_rating contains "IGNORE" then
-- say the_rating
set mailbox of thisMessage to mailbox "Trash" of the_account
else
say "You have received validated email from " & my ExtractName(sender of thisMessage)
end if
on error
say "Mail error!"
end try
end repeat
end tell
end perform_mail_action

to ExtractName(sender_)
if sender_ begins with "<" then
return text 2 thru -2 of sender_
else
set oldTIDs to text item delimiters
try
set text item delimiters to "<"
set name_ to first text item of sender_
set text item delimiters to oldTIDs
on error
set text item delimiters to oldTIDs
end try
return name_
end if
end ExtractName

to Rate(fullname_, emailaddress_, content_)
try
tell application "PurifyOSX"
set my_ret to Accept FullName fullname_ EmailAddress emailaddress_ EmailContent content_
end tell
on error
say "Purify error!"
end try
return my_ret
end Rate
Chris F
Sorry to be such a bother, but if you re-read my first email you'll see that in fact the applescript method has a flaw. To state it again, it drops spam emails into trash before they hit the inbox, and my server continues to think that it hasn't been downloaded -- and so downloads the email over and over and over again. The applescript method doesn't work, at least not with POP.

If you can't help me get Purify working, can I have a refund please?
Jeff Hendrickson
QUOTE (Chris F @ Jul 10 2010, 10:51 AM) *
Sorry to be such a bother, but if you re-read my first email you'll see that in fact the applescript method has a flaw. To state it again, it drops spam emails into trash before they hit the inbox, and my server continues to think that it hasn't been downloaded -- and so downloads the email over and over and over again. The applescript method doesn't work, at least not with POP.

If you can't help me get Purify working, can I have a refund please?


No bother Chris. I think the flaw might be in your understanding of how email works. rolleyes.gif A POP server is dumb. Your email client (Apple Mail) is totally responsible for figureing out which email messages have been downloaded (using the UID of the email message), until they are deleted from the POP server. There is no concept of "folders" on a POP server. The AppleScript method of filtering was never intended to work with POP.

If you want to use the AppleScript method of filtering, switch your email settings to IMAP. An IMAP server is smart enough to know when you've moved a message from one folder to another.

If for whatever reason you want to continue to use POP, use the pass-through method of filtering, and use an Apple Mail rule as described in the Purify manual to dispose of an email message rated as spam, or ignore.

Purify works perfectly using either method, and the email messages are rated the same way regardless of which method is used.

Purify can be tried for 30 days before purchase, as it states on my website, it also states that after a license key has been sent, there are no refunds. There are no exceptions.
Chris F
Okay Jeff -- you inspired me to keep trying and now it's working!

New question for you (hm, should I start a new thread for this? Let me know and I'll do that...):

Is there a way to get Purify to flag as spam an email that meets these two conditions: 1) it has less than a particular number of works and 2) includes a link.

Or is that beyond the scope of what Purify can do?

I find that Purify is getting about 50% of the spam I'm receiving, but my spam is of a particular nature; I advertise on Craigslist and there are bots out there trolling craigslist and firing off emails to posters. One way they get around spam software is by keeping their responses short and including a link. There may be times when I would get a short email, but unlikely I'd get a short email with a link except if it's a client who's already been whitelisted by my writing to him on a prior occasion.

Thanks in advance!

Chris
Jeff Hendrickson
QUOTE
Okay Jeff -- you inspired me to keep trying and now it's working!

smile.gif smile.gif smile.gif
Great!

QUOTE
1) it has less than a particular number of works and 2) includes a link.

Yes, you can do both things with Purify (and much more).

1) Turn on "Email Containing Images Must Be Friend".
2) Use a regular expression in your blacklist to filter content that contains links. There is a Regular Expression errata pinned to the top of the message board. For example, if I want to blacklist ANY email that contains a URL link to a Russian web site (.ru), I could put the Regular Expression http(.*)\.ru\b in my blacklist. You can experiment with these as you see fit.

There are also a bunch of cool Regular Expressions that users have posted on this site that they use to catch spam. Worth a look.

I also have "Mark Mass Mailer As Spam On" which blocks virtually all bot spam.
Chris F
I don't think I was clear in my message. I need a way for the emails to meet two conditions AT ONCE to then label them as Spam. Below a certain number of words AND a link. Both conditions simultaneously, not each separately. Can Purify do that?
Jeff Hendrickson
No, it does each separately, but, I too have wanted the ability to check more than one condition at once during an evaluation. This feature would be very handy during more complicated evaluations.

Stay tuned. smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.