PS: hier eine Alternative…
Show Plain Text
- set desktopPath to POSIX path of (path to desktop)
- tell application "Mail" to set theMessages to selection
- repeat with theMessage in theMessages
- tell application "Mail"
- set messageID to id of theMessage as string
- set theMailbox to mailbox of theMessage
- set receivedDate to date received of theMessage
- set theAccount to account of theMailbox
- set accountDirectoryPath to account directory of theAccount
- end tell
- set {dy, mt, yr} to {day, its month, year} of receivedDate
- set theDate to (yr as text) & mt & dy
- set messagePath to POSIX path of accountDirectoryPath & name of theMailbox & ".mbox"
- try
- set theFile to paragraph 1 of (do shell script "/usr/bin/find " & quoted form of messagePath & " -name " & messageID & "*.emlx")
- set newFile to desktopPath & messageID & "_" & theDate & ".eml"
- set pythonText to "emlx = open(\"" & theFile & "\", 'r'); elen = int(emlx.readline().rstrip()); email = emlx.read(elen); emlx.close(); neweml = open(\"" & newFile & "\", 'w'); neweml.write(email); neweml.close()"
- do shell script "python -c " & quoted form of pythonText
- end try
- end repeat
als script innerhalb von Mail musst du es in einen "rule-wrapper" packen, das sieht dann so aus
Show Plain Text
- using terms from application "Mail"
- on perform mail action with messages theMessages for rule theRule
- repeat with theMessage in theMessages
- set messageID to id of theMessage as string
- set theMailbox to mailbox of theMessage
- set receivedDate to date received of theMessage
- set theAccount to account of theMailbox
- set accountDirectoryPath to account directory of theAccount
- set {dy, mt, yr} to {day, its month, year} of receivedDate
- set theDate to (yr as rich text) & mt & dy
- set messagePath to POSIX path of accountDirectoryPath & name of theMailbox & ".mbox"
- try
- set theFile to paragraph 1 of (do shell script "/usr/bin/find " & quoted form of messagePath & " -name " & messageID & "*.emlx")
- set newFile to desktopPath & messageID & "_" & theDate & ".eml"
- set pythonText to "emlx = open(\"" & theFile & "\", 'r'); elen = int(emlx.readline().rstrip()); email = emlx.read(elen); emlx.close(); neweml = open(\"" & newFile & "\", 'w'); neweml.write(email); neweml.close()"
- do shell script "python -c " & quoted form of pythonText
- end try
- end repeat
- end perform mail action with messages
- end using terms from
und das script muss im Ordner ~/Library/Application Scripts/com.apple.mail/ liegen (~ ist dein Benutzerordner)