[Pythonmac-SIG] Setting metadata (creator, type, or uti)

FZiegler zarf at klacto.net
Sun Apr 8 16:20:01 CEST 2012


I've been using a dovecot IMAP server on localhost as my local mail 
store (to have it in standard Maildir format and accessible by any 
client). I also want to make it searchable in Spotlight.

Ideally this could be done by appending '.eml' to every mail file so 
that they get picked up by Apple's mail importer; unfortunately this is 
ruled out by dovecot's existing scheme to name emails. The workaround I 
found is the Mew importer (http://www.mew.org/en/feature/spotlight.html) 
which can work based on Mac file type. For this I periodically set all 
messages' HFS file type with this script:


   import os, fnmatch

   for root, dirs, files in os.walk('/Volumes/Home/FZ/Mail'):
       for filename in files:
           if not fnmatch.fnmatch(filename, 'dovecot*'):
               filepath = os.path.join(root, filename)
               os.system('/usr/bin/SetFile -t MewX \"' + filepath + '\"')


This works, but is very slow with 20,000+ system calls per run. Hence my 
questions:

1) Is there a more efficient way to set file type? I tried using library 
functions in Carbon.File.FSSpec instead, but found that they no longer 
work (http://bugs.python.org/issue7807).

2) Or is something else (the 'uti'?) I could set so that the mails 
actually get indexed by Apple's mail importer? Following is some 
possibly relevant output of `locate lsregister` -dump.

Thanks,
Francois Z.

--------------------------------------------------------
type	id:            20368
	uti:           com.apple.mail.email
	description:   Email Message
	flags:         exported  active  apple-internal  trusted
	icon:          Contents/Resources/document.icns
	conforms to:   public.data, public.email-message
	tags:          .eml, message/rfc822
--------------------------------------------------------
--------------------------------------------------------
type	id:            21916
	uti:           org.mew.mew
	description:   Mew message text
	flags:         exported  active  trusted
	icon:
	delegate:      Spotlight/MewImporter.mdimporter/
	conforms to:   public.message, public.data, public.content
	tags:          .mew, 'MewX'
--------------------------------------------------------


More information about the Pythonmac-SIG mailing list