Mailsmith Hierarchical Export Script
If you’ve been following the conversation here (or over on HawkWings), you’ll note that one of my biggest concerns with having all my mail *in* Mailsmith was that I couldn’t easily get it all *out*, especially not while preserving the hierarchy of messages. That’s no longer a concern, thanks to a little bit of AppleScript mojo, a few hours of “free” time, and the seeds planted by BareBones flat-export script. With great fanfare, but clearly no guarantees, representations, or warrantees by the author or anyone else, I present to you my Mailsmith Hierarchical Export Script (I’ve pasted it here “in the open” so folks searching will have a better chance of finding it, though WordPress doesn’t make this easy. Any advice is welcomed).
-- This script is an enhancement of the BareBones-published -- Mailsmith Export script. BareBones' script leaves all the mbox files in -- one directory, whereas this now creates a folder hierarchy -- that matches the hierarchy within Mailsmith. -- Note that the author of the modifications makes no guarantees that -- this won't completely corrupt your mail store and render it more -- useless than a leftover chicken. global export_folder on doTask(mbox) tell application "Mailsmith" set pathadd to "" set unix_folder to "" set mboxpath to path of mbox set pathlength to length of mboxpath -- Check to see if we're down one or more levels. -- If so, fill 'pathadd' with the appropriate hierarchy. -- Since Mailsmith uses the colon ':' to separate folder names, -- we'll convert slashes to colons in the process. if pathlength > 0 then repeat with i from 2 to (pathlength) if (item i of mboxpath = "/") then set pathadd to pathadd & ":" else set pathadd to pathadd & item i of mboxpath end if end repeat set pathadd to pathadd & ":" end if set full_folder to (export_folder as string) & pathadd -- Now we'll use the Finder to see if the destination folder exists. -- If it does, do nothing. If not, we gotta create it. tell application "Finder" if folder full_folder exists then else -- Now we need to convert *all* of the colons back to -- slashes since we'll be using unix's 'mkdir -p' command -- to create the subdirectory repeat with l from 1 to length of full_folder if (item l of full_folder = ":") then set unix_folder to unix_folder & "/" else set unix_folder to unix_folder & item l of full_folder end if end repeat set mkdirStr to "mkdir -p '/Volumes/" & unix_folder & "'" -- Of course, since Mailsmith lets us store both messages AND -- folders within the same mailbox, it's entirely possible that -- we'll have a mailbox with both. When exporting as mbox files, -- that situation is impossible, and the creation of the folder -- will fail since the mbox file of the same name will be created first. -- However, since everything else will want to be in that folder, the folder 'wins' -- rights to the name. In that case, rename the mbox to '{name} - mailbox' -- and then create the folder try do shell script mkdirStr on error errText if (errText contains "File exists") then set unix_filename to "" -- Strip the trailing slash from the folder name. -- Yes, I'm sure there's a more efficient way to do this. repeat with g from 1 to ((length of unix_folder) - 1) set unix_filename to unix_filename & item g of unix_folder end repeat -- rename the file set mvStr to "mv '/Volumes/" & unix_filename & "' '/Volumes/" & unix_filename & " - mailbox'" do shell script mvStr end if -- Now create the subdirectory. If it doesn't work this time, let the script die. do shell script mkdirStr end try end if end tell -- increase the timeout while exporting since 180 seconds isn't nearly enough for larger mailboxes with timeout of 3600 seconds export mbox to full_folder as alias end timeout end tell end doTask on run tell application "Mailsmith" set export_folder to choose folder with prompt ¬ "Choose a folder to export mailboxes into." set ct to count mailboxes repeat with i from 1 to ct set obj to mailbox i my process_mailbox(obj) end repeat end tell end run on process_mailbox(mbox) tell application "Mailsmith" -- Skip creating an empty mailbox for each folder (but, of course -- still export if mailbox contains both messages and mailboxes) if not (((count mailboxes of mbox) > 0) and ((count messages of mbox) = 0)) then my doTask(mbox) end if set ct to count mailboxes of mbox repeat with i from 1 to ct set obj to mailbox i of mbox my process_mailbox(obj) end repeat end tell end process_mailbox
But the question remains… where (if anywhere) do I put it? Mail.app *also* seems to limit ones ability to export (to anything!)… if that’s the case, well, I ain’t going there! Oh this is a joy.
Technorati Tags: export, mail.app, mailsmith, applescript
August 23rd, 2006 at 6:16 pm
Dave:
You are able to get your mail out of Mail.app AND keep your mailbox hierarchy. There is a wonderful set of tools by Andreas Amann called ‘Mail Scripts’.
One of the tools in Mail Scripts is the ability to archive your messages into MBX format with the option of maintaining your mailbox hierarchy.
You can find Mail Scripts at http://homepage.mac.com/aamann/Mail_Scripts.html although his site has been down because he just released a new version and he’s maxing out his .Mac bandwidth allotment.
You can get a copy via VersionTracker at http://www.versiontracker.com/dyn/moreinfo/macosx/16217. You can also read more about Mail Scripts at the Hawkwings website: http://www.hawkwings.net/2006/08/22/mail-scripts-2711-an-outstanding-resource-gets-better/
Good luck and please let us know which direction you go with your email client. This is a very interesting topic.
August 23rd, 2006 at 11:16 pm
Dave:
You are able to get your mail out of Mail.app AND keep your mailbox hierarchy. There is a wonderful set of tools by Andreas Amann called ‘Mail Scripts’.
One of the tools in Mail Scripts is the ability to archive your messages into MBX format with the option of maintaining your mailbox hierarchy.
You can find Mail Scripts at http://homepage.mac.com/aamann/Mail_Scripts.html although his site has been down because he just released a new version and he’s maxing out his .Mac bandwidth allotment.
You can get a copy via VersionTracker at http://www.versiontracker.com/dyn/moreinfo/macosx/16217. You can also read more about Mail Scripts at the Hawkwings website: http://www.hawkwings.net/2006/08/22/mail-scripts-2711-an-outstanding-resource-gets-better/
Good luck and please let us know which direction you go with your email client. This is a very interesting topic.
August 23rd, 2006 at 7:59 pm
Dave:
Another email client that you might look at trying is GyazMail (http://gyazsquare.com/gyazmail/), I’ve only used it in a very limited capacity so I don’t know how it will handle a load but it stores messages as single files (RFC 822 format) so it would be easily exportable.
August 24th, 2006 at 12:59 am
Dave:
Another email client that you might look at trying is GyazMail (http://gyazsquare.com/gyazmail/), I’ve only used it in a very limited capacity so I don’t know how it will handle a load but it stores messages as single files (RFC 822 format) so it would be easily exportable.
August 23rd, 2006 at 10:48 pm
[…] « Man… time really flies Mailsmith Hierarchical Export Script » […]
August 24th, 2006 at 3:48 am
[…] « Man… time really flies Mailsmith Hierarchical Export Script » […]
August 23rd, 2006 at 10:53 pm
Thanks for the tip, bronson. I still can’t download it, but I’ll try again tomorrow. Is there an alternate link?
August 24th, 2006 at 3:53 am
Thanks for the tip, bronson. I still can’t download it, but I’ll try again tomorrow. Is there an alternate link?
August 24th, 2006 at 6:24 am
You download it from MacUpdate – http://macupdate.com/info.php/id/9178
I just tried it and it works.
August 24th, 2006 at 11:24 am
You download it from MacUpdate – http://macupdate.com/info.php/id/9178
I just tried it and it works.
August 24th, 2006 at 6:27 am
I also found it at ScriptBuilders – http://files.macscripter.net/ScriptBuilders/E-Mail/mailscripts.dmg
Good luck
August 24th, 2006 at 11:27 am
I also found it at ScriptBuilders – http://files.macscripter.net/ScriptBuilders/E-Mail/mailscripts.dmg
Good luck
October 3rd, 2006 at 12:09 am
[…] If you are using and thinking about a move to Mail.app (or anywhere else), David Hamilton has written a script that exports emails from Mailsmith in a smarter way than the default that comes with Mailsmith itself. […]
October 3rd, 2006 at 7:09 am
[…] If you are using and thinking about a move to Mail.app (or anywhere else), David Hamilton has written a script that exports emails from Mailsmith in a smarter way than the default that comes with Mailsmith itself. […]
January 15th, 2007 at 5:31 pm
It would be the best if somebody would make an export which simulates a POP3 server. That you could export mails to anything you want.
January 15th, 2007 at 10:31 pm
It would be the best if somebody would make an export which simulates a POP3 server. That you could export mails to anything you want.
January 28th, 2007 at 8:36 am
Did any of you consider Mailsteward. I’m using it for some months now. First in combination with Mailsmith, but now with Mail.app. One can schedule mailsteward (Cronjobs) to backup mail from Mail.app. Up until now it’s rock solid and does just what it needs to do: http://www.mailsteward.com/
January 28th, 2007 at 1:36 pm
Did any of you consider Mailsteward. I’m using it for some months now. First in combination with Mailsmith, but now with Mail.app. One can schedule mailsteward (Cronjobs) to backup mail from Mail.app. Up until now it’s rock solid and does just what it needs to do: http://www.mailsteward.com/
February 9th, 2012 at 6:14 pm
This could use an update.
Syntax Error
Expected end of line but found identifer.
Then mbox in
export mbox to full_folder as alias
is highlighted.
February 9th, 2012 at 11:14 pm
This could use an update.
Syntax Error
Expected end of line but found identifer.
Then mbox in
export mbox to full_folder as alias
is highlighted.
February 10th, 2012 at 11:21 am
I just checked with Rich Siegel, Mailsmith’s author and programmer extraordinaire, and he said he just tried the script today and it worked as is. Is it possible you’ve pasted something wrong? I don’t have Mailsmith around to test, but I do trust Rich. 😉
February 10th, 2012 at 4:21 pm
I just checked with Rich Siegel, Mailsmith’s author and programmer extraordinaire, and he said he just tried the script today and it worked as is. Is it possible you’ve pasted something wrong? I don’t have Mailsmith around to test, but I do trust Rich. 😉