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

Ronald Oussoren ronaldoussoren at mac.com
Mon Apr 9 11:51:44 CEST 2012


On 8 Apr, 2012, at 16:20, FZiegler wrote:

> 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).

MacOS.SetCreatorAndType(filename, creator, type) works both in 32-bit and 64-bit versions of python (I've tested this with 2.7).   FSSpec is not available in 64-bit builds because those APIs don't exist in the 64-bit version of Carbon.framework.

BTW. Neither version is available in python 3 because we dropped the Carbon bindings in python 3.0. That was done because those bindings were unmaintained and were generated from the MacOS 9 header files.


> 
> 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.

As far as I know there is no extended attribute for storing the UTI, otherwise you could have used that. That means you can only use Apple's importer when you use the ".eml" filename extension.

Ronald

> 
> 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'
> --------------------------------------------------------
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
> unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4788 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20120409/904a9cf4/attachment.bin>


More information about the Pythonmac-SIG mailing list