• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[SOLUTION] help with mail.app please
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLUTION] help with mail.app please


  • Subject: [SOLUTION] help with mail.app please
  • From: Warren Pollans <email@hidden>
  • Date: Wed, 22 Sep 2004 22:16:08 -0400

Hello again. After a little more RTFM I have come up with the following script which is run as a mail.app rule. It works and I'd appreciate any suggestions for improvement. I haven't tested moving infected messages to the "Quarantine" mailbox. Thanks, Warren

QUESTION:  how does 'save' work in the context of this example?

on perform_mail_action(info)
tell application "Mail"
set selectedMessages to |SelectedMessages| of info
set theRule to |Rule| of info
repeat with eachMessage in selectedMessages
try
-- create mac file path
set macMailPath to (((path to startup disk) as Unicode text) & "tmp:tmpmailfile")
set unixMailPath to (POSIX path of macMailPath)
-- display dialog "macMAILFILE:" & macMailPath
-- display dialog "unixMAILFILE:" & unixMailPath
-- set theContent to (content of eachMessage) as Unicode text
-- display dialog theContent

-- THIS DOES NOT WORK
-- save theContent in macMailPath

set theSource to the source of eachMessage as text
try
set theFile to open for access file macMailPath with write permission
write theSource to theFile starting at 0
close access macMailPath as file specification
on error errText
display dialog "open-file ERROR: " & errText
end try

-- OK, works from here down
set theCommand to "/usr/local/bin/clamscan --quiet " & unixMailPath & "; echo $?"
-- display dialog theCommand
set spamStatus to do shell script theCommand
set theStatus to "STATUS:" & spamStatus & ":"
display dialog theStatus
on error errText
display dialog "ERROR: " & errText
end try

-- if (spamStatus > 0) then
-- set mailbox of eachMessage to mailbox "Quarantine"
-- end if
end repeat
end tell
end perform_mail_action



On Wednesday, Sep 22, 2004, at 11:09 US/Eastern, Warren Pollans wrote:

Hello,

I'm using 10.2.8 and would like some help/direction with what should be basic mail.app scripting. I want a rule to send each incoming mail message through a shell script that runs clanscan (virus checker) and returns status - If the status is not zero, I want the mesg moved to mailbox "Quarantine".

I'm trying to save each mail to a file and pass the file to clamscan. My first problem is that "theMailFile" is not being written. I know I'm getting each mesg because I can "display dialog theContent" but I'm not sure if the "content" is what I want - I would like to be able to get the contents, including attachments, of the mesg. My attempt at doing this is below - I don't know what I'm doing here - obvious yes? :-)

Could someone please direct me to some "applescripting mail.app" info.

Thanks,

Warren

+++++++++++++++++++++++++++++++

on perform_mail_action(info)
	tell application "Mail"
		set selectedMessages to |SelectedMessages| of info
		set theMailFile to "/tmp/thismailmsg"
		repeat with eachMessage in selectedMessages
			set theContent to content of eachMessage
			save theContent in theMailFile
			set theCommand to "/usr/local/bin/clamscan --quiet " & theMailFile
			set spamStatus to do shell script theCommand
			if (spamStatus > 0) then
				set mailbox of eachMessage to mailbox "Quarantine"
			end if
		end repeat
	end tell
end perform_mail_action

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >help with mail.app please (From: Warren Pollans <email@hidden>)

  • Prev by Date: Re: Scripting Console
  • Next by Date: Script from Book
  • Previous by thread: help with mail.app please
  • Next by thread: Re: IS: Debugging Techniques -- WAS: Re: cure for NSArgumentEvaluationScriptError?
  • Index(es):
    • Date
    • Thread