2

My purpose is to write a script to automate Spamcop Reports. There are some tries in forums, but as mac os changes along the years, scripts lose its functionality. I'm newcomer with Applescript.

Spamcop is an email blacklist. Submit spams has steps, for example, in Gmail junk folder, we should separate true spam, send them as attach-mime (full headers), wait analysis, receive an email with links to confirm each spam report.

This script works:

     tell application "Mail" activate

  end tell

 tell application "System Events"
  tell process "Mail"
    delay 0.5
    keystroke "4" using command down
    delay 0.5
    keystroke "a" using command down
    delay 0.5
    click menu item "Forward as Attachment" of menu "Message" of menu bar 1
    delay 5
    keystroke "Spamcop <submit._______@spam.spamcop.net>"
    keystroke tab
    delay 0.5
    keystroke tab
    keystroke "Spam"
    delay 0.5
    keystroke tab
    keystroke "Spam are here!"
    keystroke "d" using {shift down, command down}
end tell

tell application "Mail" activate
end tell

tell application "System Events"
    tell process "Mail"
        delay 0.5
        keystroke "4" using command down
        delay 0.5
        keystroke "a" using command down
        delay 0.5
        keystroke "j" using {option down, command down}
        delay 1
        key code 36
    end tell
end tell

** where keystroke "4" using command down is the 4th favorite folder, my junk

The next step is receiving the answer of Spamcop with links to confirm reporting. I tried this, but it didn't work: https://www.webveteran.com/blog/mac/mac-os-x/automate-reporting-spam-to-spamcop-net/

So, any suggestions? How to receive an email in a separate Mail folder from Spamcop, read "http://www.spamcop.net/sc?id=" link, open each one in Safari, click at "Send Report(s) Now" button (in fact ""), and close this Tab.

  • I wrote and have been using these scripts to automate Spamcop reporting for years. It uses a combination of perl and AppleScript. – Graham Miln Feb 25 '18 at 18:37
  • You should consider sending Mail AppleScript commands to forward the email attachments or move mail to junk folders. Simulating keystrokes and clicks is a really iffy and inelegant way of doing it. – CJK Feb 26 '18 at 3:22
1

If you have a Spamcop account, you can use this perl script to submit pending reports:

#!/usr/bin/perl

use WWW::Mechanize;

my $spamcop_url = 'http://www.spamcop.net';

my $mech = WWW::Mechanize->new();
$mech->get( $spamcop_url );

$mech->submit_form(
        form_number => 1,
        fields      => {
            username    => 'ENTER YOUR SPAMCOP USER NAME HERE',
            password    => 'ENTER YOUR SPAMCOP PASSWORD HERE',
        }
    ) ."\n";

my $stop = 0;
while(not $stop) {

    $mech->follow_link( text => 'Report Now' ) ."\n";

    my $form = $mech->form_name( 'sendreport' );
    if ($form) {
        print "Send Report form found: ".$mech->value('reports')."\n";
        $mech->click_button( 'value' => 'Send Spam Report(s) Now' ) ."\n";
    } else {
        print "No report form button found.\n";
        $stop = 1;
    }
}

I wrote this script and talk about it at Automating SpamCop.

  • Thanks for your help and your time! I wanted to use Applescript because I could put the code to run in a Mail rule. I installed Perl on Mac and I will take some time to run the code you wrote. I had made a recording in the Katalon plugin for Firefox, much easier but it runs separately from Mail and Safari: open spamcop.net click name=username type name=username type name=password sendKeys name=password ${KEY_ENTER} click link=Report Now click //input[@value='Send Spam Report(s) Now'] click link=Report Now click //input[@value='Send Spam Report(s) Now'] – Julio Takada Feb 25 '18 at 23:49
0

I recently installed Spamcop Deputy and it seems to work quite well. It's two Applescripts, one of which you have to modify slightly, plus a Mail.app Rule. You select the messages, run the AppleScript, and the scripts and rule do all the rest, besides actually submitting the report (which some Spamcop helpers have gotten into trouble for automating in the past).

  • I have tested both SpamcopNotify.scpt and SpamcopIn.scpt. The SpamcopNotify.scpt has the inconvenience of sending Junk messages to Trash and not real delete them. The SpamcopIn.scpt didn't worked in my Rule-Mail.app without the SpamcopNotify. Finally, you have to be careful when testing these scripts, I had sended some wrong reports to Spamcop (after deleting the messages, Mail jump to the next message...). – Julio Takada Mar 4 '18 at 19:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .