Meine Schwester hat 1 GB Mailspace und muss in regelmäßigen Abständen die Emails aus der Inbox oder dem gesendet-Ordner in einen lokalen Mail-Ordner verschieben, damit das Postfach nicht überläuft.
Dieses Skript hier fragt den Quell-Account und das Quell-Postfach ab, im Anschluss das Zielpostfach und dann wie alt die Mails sein müssen, damit sie verschoben werden sollen.
Neben dem reinen Nutzen ein schönes Beispiel, wie man eine Mailbox via AppleScript-Dialog auswählen kann. ;-)
Viel Spaß damit!
## MoveMail oder than... ©hubionmac.com 23.09.2014
## This script moves all Emails older than x days from a source mailbox to a destination mailbox
## source and destination mailbox may be located on differenc accounts or may be local mailboxes
tell application "Mail"
set theaccounts to name of every account whose enabled is true
set sourceAccount to (choose from list theaccounts & {"• Local •"} with prompt "Set Source-Mailbox:" & return & "Select Account") as string
if sourceAccount is "false" then
error number -128
end if
set sourceMailbox to (choose from list my return_mailboxes(sourceAccount) with prompt "Set Source-Mailbox:" & return & "Select Mailbox") as string
if sourceMailbox is "false" then
error number -128
end if
if sourceAccount is "• Local •" then
set sourceMailbox to mailbox sourceMailbox
else
set sourceMailbox to mailbox sourceMailbox of account sourceAccount
end if
set destiAccount to (choose from list theaccounts & {"• Local •"} with prompt "Set destination-Mailbox:" & return & "Select Account" default items {sourceAccount}) as string
if destiAccount is "false" then
error number -128
end if
set destiMailbox to (choose from list my return_mailboxes(destiAccount) with prompt "Set destination-Mailbox:" & return & "Select Mailbox") as string
if destiMailbox is "false" then
error number -128
end if
if destiAccount is "• Local •" then
set sourceMailbox to mailbox destiMailbox
else
set destiMailbox to mailbox destiMailbox of account destiAccount
end if
repeat until 1 = 0
try
set daycount to text returned of (display dialog "Only move mail older than x days" default answer "30") as integer
if daycount > 0 then
exit repeat
end if
end try
end repeat
set deadline to current date
set deadline to deadline - 60 * 60 * 24 * daycount
display dialog "Really move " & (count of (every message of sourceMailbox whose date sent < deadline)) & " messages?"
move (every message of sourceMailbox whose date sent < deadline) to destiMailbox
end tell
on return_mailboxes(accountname)
tell application "Mail"
set l to {}
if accountname is "• Local •" then
repeat with thebox in every mailbox
set tmp to name of thebox
repeat until 1 is 0
if name of container of thebox is not missing value then
set tmp to name of container of thebox & "/" & tmp
set thebox to container of thebox
else
exit repeat
end if
end repeat
set l to l & {tmp as rich text}
end repeat
else
repeat with thebox in every mailbox of account accountname
set tmp to name of thebox
repeat until 1 is 0
if name of container of thebox is not missing value then
set tmp to name of container of thebox & "/" & tmp
set thebox to container of thebox
else
exit repeat
end if
end repeat
set l to l & {tmp as rich text}
end repeat
end if
end tell
return l
end return_mailboxes