Ability to Delete Sent Mail After a Week/Month Removed in Sierra

Discussion in 'macOS Sierra (10.12)' started by bedouin, Dec 11, 2016.

  1. bedouin macrumors member

    Joined:
    Mar 3, 2011
    #1
    In every version of OS X that I can remember until Sierra, there was an option in Mail to remove sent messages after a week, month, and maybe even a year.

    A couple days ago I noticed that my sent mail folders were filled with messages from a couple months ago. I looked in the Mail preferences and saw that the option to delete sent messages after a certain period of time has been removed. Is there a way to get this back, perhaps through some plist wizardry? This is highly annoying.
     
  2. sguser macrumors regular

    Joined:
    Aug 12, 2010
  3. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
  4. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #4
    I just checked after seeing your post and I have the same issue. I'm pretty sure there was an option on this screen to keep 30 days. Since updating to Sierra on Sept. 20 none of my sent items have been purged.

    Screen Shot 2016-12-12 at 8.24.42 AM.png
     
  5. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
    #5
    There definitely was. I've been using OS X since 10.1, and that option has existed until Sierra.
     
  6. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #6
    I'm going to play around with the plist some today and I'll let you know if I figure anything out.
     
  7. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
    #7
    Thanks! I'm hoping you find something.

    Here is a screenshot from Mail in Yosemite by the way, for anyone who may think we are crazy :)

    Screen Shot 2016-12-12 at 6.40.30 PM.png
     
  8. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #8
    Well, after a couple hours messing about I am nowhere. :mad:

    From looking around in the Mail plist it looks like this command should fix it (to 60 days), but it does not.

    Code:
    defaults write com.apple.mail NumberOfDaysToKeepSentMessages 60
    I can see the 60 change applied in the plist, but Mail does not seem to recognize it. Before the plist change that value was set to -1, which seems to be "never".

    I even rebooted after updating the plist because since Mavericks plist files get cached, so you need to logout after any changes. I don't see any other values in the plist that look like they would do anything with sent message storage.
     
  9. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
    #9
    Aside from switching to a new mail client (which I'm seriously considering because of this), are there any other solutions to accomplish the same thing?

    By the way, have you tried switching it to 30 days? Maybe 60 is above the threshold, since there was only ever an option for one week, a month, or on exit.

    EDIT: Another curiosity . . . this setting was done on a per-account basis (i.e., a separate value could be used for each account). Perhaps the setting is hidden in with preferences for the individual accounts?
     
  10. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #10
    Yep... I tried all that. I even converted the plist to an XML file using plutil so I could read and edit it in Textedit. There is a setting for each account and I changed both on mine then used plutil to convert back to a binary plist.

    I tried every method and variation I could find or think of and nothing seems to work. The setting does take in the plist, but it seems as if Mail is just ignoring it.
     
  11. adrianlondon macrumors 6502a

    adrianlondon

    Joined:
    Nov 28, 2013
    Location:
    Switzerland
    #11
    I wonder whether they removed the functionality to stop the conversation view from becoming disjointed.

    You could write an Applescript to do it, but I agree that it would be much better to have it as an option in the account settings.
     
  12. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
    #12
    Shrug. I disabled the conversation view then I minute it was first introduced to Mail. Not a fan.
     
  13. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
    #13
    I created an Automator workflow to identify the messages I want to delete (those older than 30 days in the sent boxes of certain accounts), but there is no action to actually delete them once you've identified them — unless I'm missing something. Passing the filtered messages onto the "Move to Trash" Finder action does not work, since they're not actually files. Any ideas?
     
  14. adrianlondon macrumors 6502a

    adrianlondon

    Joined:
    Nov 28, 2013
    Location:
    Switzerland
    #14
    In Applescript:

    set theAccount to account of mailbox of this_message
    set mailbox of this_message to mailbox "Trash" of theAccount

    or maybe
    move this_message to mailbox "Trash" of theAccount

    I've not tried either, but I suspect it would work. You need to move it to the Trash mailbox within Mail not to the finder Trash.
     
  15. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #15
    I was able to get this Smart Mailbox to pretty easily ID them all for a quick delete.

    Screen Shot 2016-12-14 at 8.49.59 AM.png
     
  16. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
    #16
    I do not know anything about Applescript. Is there some simple code I could insert into this workflow?

    https://imgur.com/a/DFYfK

    I thought of going that route, but would prefer it to be automated and run every day automatically.
     
  17. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #17
    Oh me too.... but I am stuck right where you are with Automator. Please let me know if you come up with something. :)

    For now, I figure I can just use the Smart Mailbox once a month or so and be all set.
     
  18. High Desert macrumors regular

    Joined:
    Nov 26, 2015
    Location:
    Powell Butte, Or.
    #18
    Sounds like there are all kinds of landmines people are tripping over with Sierra that do not seem to have a fix. Guess I'll stay with El Capitan until these are fixed.
     
  19. bedouin thread starter macrumors member

    Joined:
    Mar 3, 2011
    #19
    I implemented your smart mailbox approach. I had to do things a bit differently though, because I have two accounts where I actually do want the sent messages to be saved. I had to create a smart mailbox identifying sent messages for the four accounts I want to purge messages from, and then make another smart mailbox to identify messages older than 30 days in that particular smart mailbox. Not a very "smart" way of having to deal with this.
     
  20. adrianlondon macrumors 6502a

    adrianlondon

    Joined:
    Nov 28, 2013
    Location:
    Switzerland
    #20
    I'm very new to Applescript and know very little about Automator :). I could probably write the entire thing in Applescript, but I believe you need a way to schedule it, and that requires a repeating calendar event and assumes you have a laptop running at that time. Or maybe it could be triggered by any mail being received? But again, that's only on the laptop.

    A smart mailbox does seem the easiest way. Do you use an email provider that's not Apple/iCloud? Maybe a rule can be set there (via any web interface) to delete mails in the sent mailbox after 30 days? If I do get around to writing an Applescriot (just for fun, I don't need it myself as I use the smart mailbox method to clear out stuff only once a year!) I'll post it up here.
     
  21. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #21
  22. KALLT macrumors 601

    Joined:
    Sep 23, 2008
    #22
  23. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #23
    It is in the mail plist in this folder on Sierra. If you read this plist you can see changes applied to it from that Mail pref pane. If you look in that plist you can see where NumberOfDaysToKeepSentMessages has been changed from 30 to -1 on Sierra. It would be interesting to see what you show for that setting on El Capitan.

    Code:
    ~/Library/Containers/com.apple.mail/Data/Library/Preferences/
     
  24. KALLT macrumors 601

    Joined:
    Sep 23, 2008
    #24
    Just checked again, it is not there. There are few account-specific settings in there at all and this particular setting applies to the account, not the application as a whole. I did find ‘NumberOfDaysToKeepSentMessages’ in ~/Library/Mail/V2/MailData/Accounts.plist, but that plist has not been updated in months. There is no equivalent of Accounts.plist in V3, so it must be stored somewhere else now. I am wondering if it is in one of the databases instead in the MailData directory instead.
     
  25. adrianlondon macrumors 6502a

    adrianlondon

    Joined:
    Nov 28, 2013
    Location:
    Switzerland
    #25
    This will go through your email accounts (as defined in MailAccounts) and move any message in the Sent folder over 30 days old to the Trash folder. I'm a newbie at Applescript, but I've tested it and it does work.

    Code:
    set delDate to (current date) - (30 * days)
    set MailAccounts to {"Account1", "Account2"}
    set totalDeleted to 0
    set MailRunning to 0
    
    set choice to display alert "Deleting old sent emails" message "Will delete items earlier than " & date string of delDate buttons {"cancel", "Run"} default button "cancel" giving up after 10
    
    if gave up of choice is true or button returned of choice = "cancel" then
        error number -128
    end if
    
    -- If Mail isn't running before this script executes, then kill it when the script ends
    tell application "System Events"
        set ProcessList to name of every process
    end tell
    if "Mail" is in ProcessList then set MailRunning to 1
    
    tell application "Mail"
       
        repeat with theAccount in MailAccounts
            set myMailbox to mailbox "Sent" of account theAccount
            set TrashBox to mailbox "Trash" of account theAccount
    --     debug
    --     display dialog (theAccount as rich text) & (name of myMailbox as rich text) & (name of TrashBox as rich text)
           
            set messagesToDelete to (messages of myMailbox whose date received is less than delDate)
            set totalDeleted to totalDeleted + (count of messagesToDelete)
            repeat with messageToDelete in messagesToDelete
                move messageToDelete to TrashBox
            end repeat
        end repeat
       
        display alert "Done!" message "Deleted " & (totalDeleted as rich text) & " emails" buttons {"OK"} giving up after 5
        if MailRunning = 0 then quit
    end tell
     

Share This Page