Topic: PHP save mail attachements to folder

I'm looking for ways to save mailattachements from imap emailaccounts by getting the emaillist from INBOX, decoding the attachments defined via parameter or wildcard of some sort, and place the attachements to a speciel folder.
And then optionally move the procecced mail into INBOX/parsed imap-folder.

Ideally it should be able to save the attachement into a defined folder based on what rule the attachement catches under.

I've searched a bit but not found much if examplecode how this could be done.

The things i've looked at is php.net/imap and the mime-classes in PEAR.

Example-code, scripts, docs, functions, tips n hints etc is welcome.

//Rikard