using terms from application "Mail" on perform mail action with messages theMessages for rule theRule tell application "Mail" repeat with eachMessage in theMessages set theSubject to subject of eachMessage repeat with eachAttachment in every mail attachment of eachMessage set thePath to (path to home folder) as string -- "Macintosh HD:Users:username:" set thePath to thePath & "Dropbox:" set thePath to thePath & theSubject if theSubject's length > 0 then set thePath to thePath & " - " end if set thePath to thePath & ((random number from 10000 to 99999) as string) -- avoids collisions set thePath to thePath & " - " set thePath to thePath & (name of eachAttachment) save eachAttachment in file thePath end repeat set read status of eachMessage to true end repeat end tell end perform mail action with messages end using terms from