Possible to set default imported mbox names?

I recently started telecommuting full time, which is resulting in a large volume of email. I’ve been using just Mail.app + MailTags, but Mail.app’s searching is abysmally slow for full content searches, and it doesn’t let me stack things (for instance I can’t easily search for a string within a specific tag). If possible, I’d like to start using EagleFiler to store everything but immediately pending email (I dislike having to use two programs, but EF’s speedy searches are a must-have).

I’m thinking about a workflow where I archive my inbox to EagleFiler daily and do basically all my email searching/browsing in EF. Since I’ll be mainly browsing the messages via tags, having a large quantity of mailboxes in the library doesn’t really matter to me. However, I would like to change the default name for imported mailboxes (INBOX-# just really doesn’t cut it), ideally to the date I imported it. Is this possible (any hidden preferences)?

My reason for asking is that if I’m going to be using multiple programs to manage my email, I need the process to be as stream-lined as possible or else I won’t use it and will end up playing catch-up constantly.

If it’s not possible, consider this a feature request.

Also, I haven’t used EF for much email archiving up until now (been mainly throwing text documents at it). Does anyone have advice on using it to keep your inbox clean? Workflows that work for them? Other software that works better (I’d like to use EagleFiler since I own it and really enjoy it, but if there’s a more perfect option out there I’d like to know)?

Text email backup suggestion
If you process a lot of email on a daily basis, why not give “Mailsteward” a try. When I tried it, it can only handle text info (it transfer all email into text) but that is probably the reason why it is ultra fast in searching info.

New version seems to have the ability to view html, I haven’t tried it lately though.

The downside is, you will need to use 3 programs instead of 2. Mail.app, EagleFiler (for all non-email archive) and Mailsteward (since it only handles email).

Also note that Mailsteward stores its data in SQL format.

That’s what I do.

The default name is the name of the mailbox, so it would only be “INBOX” if you imported your inbox from Apple Mail. However, yes, if you import the same mailbox multiple times you’ll end up with multiple mailboxes in EagleFiler with the same base name. I’ve written a script that you can use to add the date to the filename. Another option would be to use the Merge Mailboxes command to combine identically named mailboxes into a single mailbox.

As I see it, it would be better to use EagleFiler because:

  1. Your mail wouldn’t be separate from your other files.
  2. EagleFiler has a friendlier, more mail-client-like, interface.
  3. The searching is faster.
  4. It preserves the actual data that was received from the mail server, and stores it in an open format (mbox) that other programs can import.
  5. It checksums the mailboxes so that you can verify that they aren’t damaged.

Interesting. Is it possible to import a specific mailbox from Mail.app (either by calling the script once the mailbox is selected, or automatically)? If I could do that, then I could combine your date/filename script with the Mail.app import script and live a nicely automated life. (I checked your “Import examples” but none of them dealt with Mail, and a quick glance through the EF AppleScript dictionary didn’t reveal anything, either.)

Another cool thing would be if I could use a Mail import Applescript that would turn off auto-checking, grab the selected messages (without asking if I wanted the mailbox), rename the mailbox in EF (sounds like I can already do this), and then set my auto-checking preferences again. I’m not sure how feasible this would be, of course, but if it’s possible I’d love to do it!

I’m also leaning toward EagleFiler over Mailsteward at the moment, although not because I’ve had a chance to compare speed. My main beef with MailSteward before I’ve even launched it is the interface (looks like extra steps to get to a search, which is not good).

Would you mind briefly describing your email/EagleFiler workflow, Michael? I’d be interested to see how the program’s creator makes use of it. :slight_smile:

To do that, I’d recommend running a special script that knows which mailbox to import and that also adds the date. Something like:

set _path to "/Users/mjt/Library/Mail/IMAP-mjt@c-command.com@postal.mail.dreamhost.com/INBOX.imapmbox"
set _path to my copyWithDateName(_path)
tell application "Mail"
    set _fetchesAutomatically to fetches automatically
    set fetches automatically to false
end tell
tell application "EagleFiler"
    tell library document 1
        import files {POSIX file _path}
    end tell
end tell
tell application "Mail"
    set fetches automatically to _fetchesAutomatically
end tell

on copyWithDateName(_mailbox)
    set {_name, _extension} to my rpartition(my nameOf(_mailbox), ".")
    set _newName to _name & " " & my currentDateString()
    
    set _tempFolder to do shell script "mktemp -d -t 'EFMailImport'"
    set _renamedMailbox to _tempFolder & "/" & _newName & "." & _extension
    
    my copyFile(_mailbox, _renamedMailbox)
    return _renamedMailbox
end copyWithDateName

on copyFile(_source, _dest)
    do shell script "cp -R -P -f -p " & _source's quoted form & " " & _dest's quoted form
end copyFile

on currentDateString()
    return do shell script "date +%Y-%m-%d"
end currentDateString

on nameOf(_path)
    return do shell script "basename " & _path's quoted form
end nameOf

on split(_string, _sep)
    set _temp to AppleScript's text item delimiters
    set AppleScript's text item delimiters to _sep
    set _result to text items of _string
    set AppleScript's text item delimiters to _temp
    return _result
end split

on rpartition(_string, _sep)
    set _list to my split(_string, _sep)
    set _head to my join(items 1 thru -2 of _list, "")
    set _tail to item -1 of _list
    return {_head, _tail}
end rpartition

on join(_list, _sep)
    set _temp to AppleScript's text item delimiters
    set AppleScript's text item delimiters to _sep
    set _result to _list as string
    set AppleScript's text item delimiters to _temp
    return _result
end join

It’s a bit more complicated than you’d expect due to the fact that it’s currently not easy for a script to get at the record that was just imported in order to rename it. So, instead, the script creates a copy of the mailbox, renames it, and then imports it. You’ll need to edit the first line to have the proper path for the mailbox that you want to import.

I organize my messages into folders and mailboxes both in Mail and in EagleFiler. The folder structure is somewhat different, since one is for processing new mail, while the other is for organizing archived mail. That is, a given message stays in a mailbox with the same name, but that mailbox may be in a different place in the hierarchy in EagleFiler than it was in Mail.

When I notice that my mailboxes are getting too large in Mail (say, more than 500 messages in a mailbox), I import a bunch of them into EagleFiler (using the capture key) and delete the original messages. Now, in EagleFiler, I have the older, organized mailboxes, and the newer ones, which are all at the top level (in Unfiled). I want to get the mail from the newer mailboxes into the archive hierarchy. So I click on the Library source and sort by name. I find the pairs of old and new mailboxes with the same name and use the Merge Mailboxes command to combine them. Of course, if you use tags rather than folders, there’s no immediate reason to do any merging.

Michael, you are the awesome. When I asked if it was possible, I didn’t expect you to write the script! :smiley:

I’m in the middle of work right now, but I will customize and test that tonight. Thank you!

Woot! That script works exactly like I wanted. Thank you!

I’ve actually modified it so that it not only imports my work email inbox into EagleFiler, but also archives all the messages in my inbox to a preset archive folder within Mail (modifications based off the MailArchiveByDate scripts).

Figured I’d post it here in case anyone else wants to try this. I have to warn you, though, that the code I added is not very flexible. It’s scripted based on my needs right now (very simple immediate archiving of a single account) without any attempt to make it more generalizable.

To use it you’ll need a root level folder for archives with a folder inside it that has the same name as the email account you’re working with. If you want anything different, you’ll need to modify the script.


-- UNIX path to your mbox file
set _path to "/Users/username/Library/Mail/POP-account@something.com/INBOX.mbox"
-- Name of account you are archiving from the accounts list
-- also used as the name of your archive folder
set _mailAccount to "Work"
-- Name of archive root folder (must be a root-level folder!)
set _mailArchiveRoot to "Archives"

set _path to my copyWithDateName(_path)
tell application "Mail"
    set _fetchesAutomatically to fetches automatically
    set fetches automatically to false
end tell
tell application "EagleFiler"
    tell library document 1
        set theFolder to library record "Email" of root folder
        import files {POSIX file _path} container theFolder
    end tell
end tell
tell application "Mail"
    set theMailbox to (mailbox "INBOX" of account _mailAccount)
    set theMessages to (every message of theMailbox)
    set theArchive to (mailbox _mailAccount of mailbox _mailArchiveRoot)
    repeat with currentMessage in theMessages
        move currentMessage to theArchive
    end repeat
    set fetches automatically to _fetchesAutomatically
end tell

on copyWithDateName(_mailbox)
    set {_name, _extension} to my rpartition(my nameOf(_mailbox), ".")
    set _newName to _name & " " & my currentDateString()
    
    set _tempFolder to do shell script "mktemp -d -t 'EFMailImport'"
    set _renamedMailbox to _tempFolder & "/" & _newName & "." & _extension
    
    my copyFile(_mailbox, _renamedMailbox)
    return _renamedMailbox
end copyWithDateName

on copyFile(_source, _dest)
    do shell script "cp -R -P -f -p " & _source's quoted form & " " & _dest's quoted form
end copyFile

on currentDateString()
    return do shell script "date +%Y-%m-%d"
end currentDateString

on nameOf(_path)
    return do shell script "basename " & _path's quoted form
end nameOf

on split(_string, _sep)
    set _temp to AppleScript's text item delimiters
    set AppleScript's text item delimiters to _sep
    set _result to text items of _string
    set AppleScript's text item delimiters to _temp
    return _result
end split

on rpartition(_string, _sep)
    set _list to my split(_string, _sep)
    set _head to my join(items 1 thru -2 of _list, "")
    set _tail to item -1 of _list
    return {_head, _tail}
end rpartition

on join(_list, _sep)
    set _temp to AppleScript's text item delimiters
    set AppleScript's text item delimiters to _sep
    set _result to _list as string
    set AppleScript's text item delimiters to _temp
    return _result
end join

Out of curiosity Michael, what do the _variables signify? Is that a certain scope of variable, personal coding preference, or what? I couldn’t find any information online about it. I mimicked it on the off-chance that it’s something based on functionality.

It’s personal coding preference. It’s tricky to pick variable names in AppleScript because you have to be careful not to use a name that’s in use by a scripting addition, the application itself, the name of a class, or a property of one of the AppleScript objects that’s in scope. Even if you pick something safe today, a future version of the operating system or the application may introduce new terminology that conflicts. I used to use “the” as a prefix to indicate my own variables, but recently I saw someone else use “_” and I decided that I like that because it’s shorter, to read and to pronounce in my head.