Sign in to follow this  
Followers 0
svv07

Applescript: SendToSpamCop

4 posts in this topic

Below is the code from my first steps in to the applescript world. I was unsatisfied with the results produced by other scripts mentioned on this forum so I tried to make something that suited my needs better. I'm posting it here so you can try my scri_pt, comment on it, or adapt it to your needs.

General description:

SendToSpamCop for Mail.app takes the source-code of the selected mails and places it in a SpamCop-readable files in a folder on the users desktop. It then generates a mail with the forwarding address of the users SpamCop account as recipient. The scri_pt also attaches the generated files to this mail.

I deliberately haven't added functionality to auto send the mail to SpamCop or to delete the generated SpamCop-folder on the desktop. Though this is not that hard to implement, I thought this would be better for both debugging purposes and for users who want to do something else with the generated files.

Though the scri_pt can be run as it is, you may want to change the value of variable SCaccount in the code, before using it. How to do this is described in the first comments of the scripts source-code. If you don't feel like editing this variable the scri_pt would still work but you have to manually type your SpamCop forwarding address in the recipients field of the generated email.

The scri_pt is open source so do with it what you like. But I would really appreciate it if you can leave some credits to the original author (me B) ).

This is my first applescript coding attempt so comments and suggestions are appreciated.

Here is the code:

(* SendToSpamCop V1.0
  written by S.J.L. v/d Velden
  The code below is open source and you may freely  edit and redistribute it.
  Though I would appreciate it if you gave credits to  the original author (me).
  --------------------------------------------------------

   You have to customize a variable to make this scri_pt
   work with your SpamCop-account.

  Below you see the line that begins with "set
  SCaccount..."
  Replace the text YOURACCOUNT with the email address
  you've got from SpamCop.net to forward your spam to.
   *)
--

set SCaccount to "YOURACCOUNT"


(* Below is the rest of the sourcecode of the scri_pt.
   Please be very carefull editing this code *)

-- Create a SpamCop folder on the desktop
set theOutputFolderPath to path to desktop folder
set theNewFolderName to "SpamCop"

tell application "Finder"
	if (exists folder (theOutputFolderPath & theNewFolderName as string)) = false then
		make new folder at desktop with properties {name:theNewFolderName}
	end if
end tell

-- Create a new message in mail addressed to the users SpamCop account. Read the source from the selected messages in mail and save it as SpamCop readable file in the newly created SpamCop folder. Then attach each file to the new message.
tell application "Mail"
	set theMessages to the selection
	set counter to 1
	set theMessage to (make new outgoing message with properties {visible:true, subject:"report spam", content:" "})
	repeat with thisMessage in theMessages
		set sourceFile to ((theOutputFolderPath & theNewFolderName as string) & ":ml" & counter & ".src")
		set thisSource to the source of thisMessage as string
		set f to open for access sourceFile with write permission
		set eof of f to 0
		write thisSource to f
		close access f

		tell "Finder"
			set theAttachment to sourceFile as alias
		end tell

		tell the theMessage
			tell content
				make new attachment with properties {file name:theAttachment} at before the first character
			end tell
		end tell

		set counter to counter + 1
	end repeat
	tell theMessage
		make new to recipient at end of to recipients with properties {address:SCaccount}
	end tell
end tell

Share this post


Link to post
Share on other sites

svv07,

Thanks for your efforts here. I'd been wishing for a solution to make attachments like that.

I'll play around with it some more and offer any suggestions if/when I have something useful.

--

Mike

[Edited to remove an erroneous result I only *thought* I saw. :) ]

Edited by tmneast

Share this post


Link to post
Share on other sites
Below is the code from my first steps in to the applescript world. I was unsatisfied with the results produced by other scripts mentioned on this forum so I tried to make something that suited my needs better. I'm posting it here so you can try my scri_pt, comment on it, or adapt it to your needs.

Helpful Info for Newbies

This scri_pt appears to still work fine as of Mac OS X 10.5.6, with Mail 3.5.

To Install:

1. Copy the code provided.

2. Open "scri_pt Editor.app" on your HD. It should be located 'HD/Applications/Applescript/scri_pt Editor.app'.

3. Paste it into the top half of the window.

4. Make any necessary changes as detailed above (Your Spamcop reporting email, etc.)

5. Hit the "Compile" button.

6. Pull down 'File>Save as', file format should be 'scri_pt', do not 'hide extension' (good practice).

7. Save into 'HD/Library/Scripts/Mail Scripts/' (good practice).

Initial Setup To Use: (my method)

1. Open "ApplescriptUtility.app" on your HD. It should be located 'HD/Applications/Applescript/ApplescriptUtility.app'.

2. 'Check' the box 'show scri_pt menu in menu bar'.

3. Quit

*This should add the 'scri_pt' icon/menu to your menu bar. You will not need to do this again unless you accidentally remove the icon/menu.*

To Use In Mail: (my method)

1. Select spam message(s).

2. Pull down the 'scri_pt' menu/icon in the menubar, and select your scri_pt.

3. Once it's done running, send.

Share this post


Link to post
Share on other sites
Helpful Info for Newbies
Thank you for the dusting-off and the installation notes. I may say that this scri_pt was a huge timesaver for me last year when I was targeted by hundreds of blowback bounces due to my address having been forged by a spammer. I was able to submit all these mails very efficiently for reporting.

-- rick

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0