Applescript just to ‘Report Now’ Spamcop

applescriptemail

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.

Best Answer

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.