• 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
Re: Delete Mail Script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delete Mail Script


  • Subject: Re: Delete Mail Script
  • From: Brian Christmas <email@hidden>
  • Date: Wed, 07 Aug 2013 14:01:20 +1000

Robert, I've again amended the script to how I'd do it, if there were any problems in deleting the mail. Note that I've shifted the try statements to treat each individual message separately. Also, why are you setting the message background to red, I think it's wasting time.

Regards

Santa

tell application "Mail"
set fetches automatically to false
set selectedMessages to (messages of mailbox "Spam Virus Mail" of mailbox "Personal" whose date received is less than (current date) - (2 * days))
set messcount to (count of selectedMessages)
if (count of selectedMessages) is equal to 0 then
tell application "Finder"
activate
display alert "No mail in the Spam Virus Mail mailbox is older than 2 days" message "Try running this script later on. Rob." giving up after 2
end tell
else
set deleteMessageFlag to my deleteMessages(0, 0)
if deleteMessageFlag > 0 then display dialog "Some messages could not be deleted" giving up after 5
end if
end tell

on delateMessages(loopCounter, errorMessage)
tell application "Mail"
set selectedMessages to (messages of mailbox "Spam Virus Mail" of mailbox "Personal" whose date received is less than (current date) - (2 * days))
repeat with i from messcount to 1 by -1
try
set theSource to item i of selectedMessages
set background color of theSource to red # What's the point of this???
delete theSource
on error Errmsg
set errorMessage to errorMessage + 1
end try
end repeat
set selectedMessages to (messages of mailbox "Spam Virus Mail" of mailbox "Personal" whose date received is less than (current date) - (2 * days))
end tell
set loopCounter to loopCounter + 1
if (count of selectedMessages) > 0 and loopCounter < 20 then my deleteMessages(loopCounter, errorMessage)
return errorMessage
end delateMessages
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Delete Mail Script
      • From: Robert <email@hidden>
References: 
 >Delete Mail Script (From: Robert <email@hidden>)

  • Prev by Date: Re: Delete Mail Script
  • Next by Date: Re: Delete Mail Script
  • Previous by thread: Re: Delete Mail Script
  • Next by thread: Re: Delete Mail Script
  • Index(es):
    • Date
    • Thread