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 10, 2021 8:37 PM in response to Lester2k1

Maybe this can get you part way, at least give it a try with a few of the emails to see what it will do:


  1. In the Apple Mail app, select all the emails you wish to move into Numbers
  2. Print (Command P), but choose "Open in Preview" not actually printing to a printer
  3. In Preview, click on a page then Command A to select all the text in the entire PDF (along with any images or whatever else is there)
  4. Copy (Command C)
  5. In Numbers in a new table select a cell then Paste (Command V)


I don't know what your data looks like but hopefully this will create enough of a structure that you can do something with it. I noticed some oddities, though, as I was playing around with it. For instance, in one email was the word "attached" but it came out as "a#ached". It also removed space characters in some places.


It should put each "From:" into its own cell, which will have the name and email address of the sender. Maybe IF can be used to point them out and REGEX.EXTRACT can be used separate out the name and the email address. In the next cell down should be the date and time, but with all the spaces removed. It might be hard to put the spaces back in to turn it back into a date and time but is probably doable. The answers to your questions will probably follow some pattern but I don't know what it will be.


I cannot guarantee it won't mangle a name or email address like it mangled the word "attached"



Aug 13, 2021 4:31 PM in response to Lester2k1

I think you will be able to go from a Mailbox directly into a Numbers table using Applescript. I have never scripted Mail before but there is individual access to name, address, date, etc and message content which could be turned into columns of a Numbers Spreadsheet. I just don't know how to do something "for every message of the selected mailbox". The problem is finding someone who knows how to do it, which is almost the same as your original question of "does anyone know of a way..."


There is a $10 MBox to CSV converter in the app store. Might be a bargain.

Aug 18, 2021 3:13 AM in response to Badunit

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 repeat
end 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 tell
end 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 8
end 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

Aug 10, 2021 7:09 PM in response to Lester2k1

That you expect to get a ,csv file implies that the email content is organized in a way that it is possible to place the data in a .csv file—which is why I asked if you could copy the data (as opposed to copying an image of the data) directly from the email.


If it is already comma separated, or tab-depatated, you may be able to copy the data, then paste it into a Numbers table by selecting (single click) the top left cell in which the data is to start, then pasting.


Regards,

Barry

Aug 10, 2021 3:14 PM in response to Barry

Oh….I understand what you mean now…lol.


People will be sending me emails with answers for a game I am conducting.


it’s a structured format in that the contestants complete a form online. This for automatically send me an email with the information.


I need to be able to collect their name, email address, time and date of the email, and the answer for the question.


they don’t have free will to just send an email as the address is not public.


I will then want to export the emails from that inbox and insert them into a spreadsheet so that the data can be filtered in order to find the winner.


this is why I need the .csv file

Aug 10, 2021 7:54 PM in response to Barry

Maybe a little more clarification is needed.


I will be receiving thousands of emails weekly. There is no way for me to go through them all, which is why o want to be able to import the data (all at once) into Numbers.


This action is done natively in the windows environment by exporting from Outlook (directly to .csv) then importing into Excel.


can this be done in the Apple Environment?

is there a way to convert .mbox to .csv so that I can do this?

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.