Separating Attachments After Import of mbox File

Here’s an old script importing the attachments of the selected emails. Might require some time though.

-- Import attachments of selected emails

tell application id "DNtp"
	set theSelection to the selection
	set tmpFolder to path to temporary items
	set tmpPath to POSIX path of tmpFolder
	
	repeat with theRecord in theSelection
		if type of theRecord is unknown and path of theRecord ends with ".eml" then
			set theRTF to convert record theRecord to rich
			
			try
				if type of theRTF is rtfd then
					set thePath to path of theRTF
					set theGroup to parent 1 of theRecord
					
					tell application "Finder"
						set filelist to every file in ((POSIX file thePath) as alias)
						repeat with theFile in filelist
							set theAttachment to POSIX path of (theFile as string)
							
							if theAttachment does not end with ".rtf" then
								-- Importing skips files inside the database package,
								-- therefore let's move them to a temporary folder first
								set theAttachment to move ((POSIX file theAttachment) as alias) to tmpFolder with replacing
								set theAttachment to POSIX path of (theAttachment as string)
								tell application id "DNtp" to import theAttachment to theGroup
							end if
						end repeat
					end tell
				end if
			on error msg
				display dialog msg
			end try
			
			delete record theRTF
		end if
	end repeat
end tell