Individual email messages contain all data and info about their attachments. However, Mail also recreates the attachments in an associated Attachments folder and uses this as a cache to speed up any subsequent access to an attachment. These cached Attachment folders can consume quite a bit of space (mine total 1.8G) and old ones in particular could be deleted without any repercussions. Personally, I wouldn't bother just to free up disk space but I did find one Mail client which seemed to have got itself confused and ended up with many unnecessary cached folders. Deleting all the Attachment folders was the easiest way to clean things up. The following Terminal commands can be used to report on existing Attachments folders and delete them if required.
NB. This was carried out using Apple Mail in OS X 10.6 but should apply to 10.5 as well (not tested). All the terminal commands are entered on a single line (just copy and paste into a text doc if you want to see the full length command)
Reporting On Attachments Folder Sizes
To do this, find and copy all attachments into a separate allAttachments folder so you can check the resultant size (using Get Info on the folder). There is probably a way to report on total size without doing a copy but it would need some command output parsing which is beyond my expertise.
To copy all attachments from your own mail accounts...
find ~/Library/Mail/ -type d -name Attachments -print -exec mkdir -p ~/allAttachments/{} \; -exec cp -R {} ~/AllAttachments/{} \;
As above but only for mailboxes not modified in last 90 days…
find ~/Library/Mail/ -type d -name Attachments -mtime +90 -print -exec mkdir -p ~/allAttachments/{} \; -exec cp -R {} ~/AllAttachments/{} \;
As an alternative to the simple Get Info, report on sizes of individual mailboxes and give total…
du -hd6 ~/allAttachments
To get more or less detail, change the "6" to a 5 or 7.
As original search & copy but do it across all users on the computer, and report on individual user's total (requires sudo command so will ask for an admin password)…
for user in `ls /Users` ; do sudo find /Users/$user/Library/Mail/ -type d -name Attachments -print -exec mkdir -p ~/allAttachments/{} \; -exec cp -R {} ~/AllAttachments/{} \; ; done ; du -hd2 ~/allAttachments
Deleting Attachments Folders
To delete the original Attachments folders, add "-exec rm -rf {}" to one of the find commands...
find -d ~/Library/Mail/ -type d -name Attachments -print -exec rm -rf {} \;
OR
find -d ~/Library/Mail/ -type d -name Attachments -mtime +90 -print -exec rm -rf {} \;
OR
for user in `ls /Users` ; do sudo find -d /Users/$user/Library/Mail/ -type d -name Attachments -print -exec rm -rf {} \; ; done
NB. To avoid erroneous "No such file or directory" warnings, these commands have the -d (depth first) option added to the find command.
Note that the Attachments cache folder for a mailbox will be recreated should you actually select a message in that folder which has an attachment. To force a re-creation of all attachments in a mailbox, just select the mailbox in Mail and rebuild via menu command: Mailbox -> Rebuild



Comments