convert mbox to csv

I have an email address that people send to that I am in need of exporting and viewing the messages in Apple Numbers.


When I export the emails, they are placed in a .mbox file that I cannot seem to find a way to get the email data for view in a spreadsheet.


Does anyone know of a way to convert the .mbox file into a .csv file so that I can gain access to the emailed data so that it can be viewed in Apple Numbers>

MacBook Pro 16″, macOS 10.15

Posted on Aug 10, 2021 9:51 AM

Reply
24 replies

Aug 17, 2021 6:55 PM in response to Lester2k1

SGIII just posted a script in another thread that exports selected emails to a Numbers table. You might try it on one of your emails to see if the content ends up in a cell in a format that you can use. If so, maybe you can make some adjustments to the script for your needs.


set dataLst to {{"SenderAddress", "SenderName", "Date", "Time", "Content"}}

tell application "Mail"
	repeat with aMsg in items of (get selection)
		tell aMsg
			set senderNameAddr to my splitEmail(sender)
			set senderAddr to item 2 of senderNameAddr
			set senderName to item 1 of senderNameAddr
			set msgSubj to subject
			set msgDate to date received
			set msgTime to time string of msgDate
			set msgDate to my dateFormat(date string of msgDate)
			set msgContent to content
			set msgLst to {senderAddr, senderName, msgDate, msgTime, msgContent}
			copy msgLst to dataLst's end
		end tell
	end repeatend tell

tell application "Numbers"
	set newDoc to make new document
	tell table 1 of active sheet of newDoc
		delete column "A" -- remove default Header Column
		set column count to length of item 1 of dataLst
		set row count to (length of dataLst)
		repeat with i from 1 to length of dataLst
			repeat with j from 1 to length of item 1 of dataLst
				set value of cell j of row i to item j of item i of dataLst
			end repeat
		end repeat
	end tellend tell

to dateFormat(aDateString) --> yyyy-mm-dd
	set {year:y, month:m, day:d} to date aDateString
	tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8end dateFormat

to splitEmail(nameAddress)
	set text item delimiters to "<"
	tell nameAddress
		set theName to text item 1
		set theAddress to text 1 thru -2 of text item 2
	end tell	return {theName, theAddress}
end splitEmail



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

convert mbox to csv

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.