Setting metadata (creator, type, or uti)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting metadata (creator, type, or uti)

FZiegler
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'
--------------------------------------------------------
_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Reply | Threaded
Open this post in threaded view
|

Re: Setting metadata (creator, type, or uti)

Ronald Oussoren

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  -  [hidden email]
> http://mail.python.org/mailman/listinfo/pythonmac-sig
> unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Setting metadata (creator, type, or uti)

FZiegler
Ronald Oussoren wrote:
>
> MacOS.SetCreatorAndType(filename, creator, type) works both in 32-bit and 64-bit versions of python (I've tested this with 2.7).

Thanks! Indeed this works, and does exactly what I wanted -- real fast.
Thanks also to Karsten for your solution, which is already much faster
than mine.

Francois Z.
_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG