I don;t get it
I know this is the syntx and i added to the code but it doesn;t work
my script is…()
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with thisMessage in theMessages
set msgSource to source of thisMessage
try
do shell script "echo " & quoted form of msgSource & "| /usr/local/clamXav/bin/clamscan --quiet --stdout -"
on error errMsg number exitCode
if (exitCode = 1) then
tell thisMessage
set (background color) to red
end tell
set newMessage to make new outgoing message at end of outgoing messages
tell newMessage
--This line below does not add attachment from thisMessage to newMessage
tell content to make new attachment with properties {file name:theAttachment} at after the last paragraph
-- end adding attachment from newmessage to thismessage
set subject to "SCAN"
make new to recipient with properties {address:"scan@virustotal.com"}
end tell
send newMessage
else
display dialog "Something unexpected has happened to clamAV scan: Exit Code = " & exitCode
display dialog "Error Message:" & errMsg
end if
end try
end repeat
end tell
end perform mail action with messages
end using terms from
the problem is, to extract the attachment from a received message.
I just tried to get the reference of an received message’s attachment and insert it into a new message
but this doesn’t work either.
Maybe someone knows how to parse the source extracting the attachment,
I unfortunately don’t
Edit: I found out a (probably the only) way to save the attachment on disk with
set attachmentList to {}
repeat with i in mail attachments of thisMessage
save i in ((path to desktop) as string) & (name of i) -- save on desktop for example
set end of attachmentList to (((path to desktop) as string) & (name of i) as alias)
end repeat
and then later you can make the attachment(s) with this
tell content
repeat with i in attachmentList
make new attachment with properties {file name: i} at after the last paragraph
end repeat
end tell
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with thisMessage in theMessages
set msgSource to source of thisMessage
try
do shell script "echo " & quoted form of msgSource & "| /usr/local/clamXav/bin/clamscan --quiet --stdout -"
on error errMsg number exitCode
if (exitCode = 1) then
tell thisMessage
set (background color) to red
end tell
set attachmentList to {}
repeat with i in mail attachments of thisMessage
save i in ((path to desktop) as string) & (name of i) -- save on desktop for example
set end of attachmentList to (((path to desktop) as string) & (name of i) as alias)
end repeat
set newMessage to make new outgoing message at end of outgoing messages
tell newMessage
tell content
repeat with i in attachmentList
make new attachment with properties {file name:i} at after the last paragraph
end repeat
end tell
set subject to "SCAN"
make new to recipient with properties {address:"scan@virustotal.com"}
end tell
send newMessage
tell application "Finder"
move i to trash
end tell
else
display dialog "I Don't Know...NO SERIOUSLY :): Exit Code = " & exitCode
display dialog "Error Message:" & errMsg
end if
end try
end repeat
end tell
end perform mail action with messages
end using terms from
two suggestions:
¢ I would prefer to save the attachment(s) in the temporary items folder
...
set attachmentList to {}
set tempFolder to (path to temporary items) as Unicode text
repeat with i in mail attachments of thisMessage
save i in (tempFolder & name of i)
set end of attachmentList to ((tempFolder & name of i) as alias)
end repeat
...
¢ If you use a shell script to delete the attachment files after sending,
they don’t appear in the trash
...
send newMessage
repeat with i in attachmentList
do shell script "rm " & quoted form of POSIX path of i
end repeat
...