Download Apple Mail Messages

Summary: Fully download the selected messages from Apple Mail so that they can be imported.
Requires: Apple Mail
Install Location: ~/Library/Scripts/Applications/Mail/
Last Modified: 2020-11-21

Description

When importing from Apple Mail, EagleFiler may report a Missing Apple Mail Messages or Missing Apple Mail Attachment error. This indicates that the message had not been fully downloaded to your Mac. The Importing Attachments instructions explain ways to prevent this from happening or to efficiently bulk-download whole mailboxes so that you can import successfully. This script is a good option when there are more than a few messages that need to be downloaded.

To see an accurate message count, and to make sure that you are downloading all of the intended messages, it’s best to uncheck View ‣ Organize by Conversation in Mail before selecting the messages.

Installation Instructions · Download in Compiled Format · Download in Text Format

Script

tell application "Mail"
    
with timeout of 60 * 60 seconds
        
set _messages to the selection as list
    
end timeout
    
set _total to count of _messages
    
set _secondsBetweenReports to 3
    
set _secondsUntilFirstReport to 0
    
set _atLeastOneReport to false
    
set _lastReportDate to (my currentDate()) - _secondsBetweenReports + _secondsUntilFirstReport
    
set _i to 1
    
repeat with _message in _messages
        
try
            
get _message's source -- download
        
end try
        
if (((my currentDate()) - _lastReportDate) > _secondsBetweenReports) or (_i is _total and _atLeastOneReport) then
            
my notify(_i, _total)
            
set _lastReportDate to my currentDate()
            
set _atLeastOneReport to true
        
end if
        
set _i to _i + 1
    
end repeat
end tell

on notify(_i, _n)
    
set _title to "Mail Download Progress"
    
set _description to "Messages: " & _i & " of " & _n
    
tell application "EagleFiler"
        
notify with name _title title _title description _description
    
end tell
end notify

on currentDate()
    
--errAEPrivilegeError -10004 if call this from inside of "tell app 'Mail'"
    
return current date
end currentDate