mail filters


is it possible to apply “filters” to a selection of archived mails, so that mails are distributed to existing folders (within the same database) according to the conditions defined? That would be really a great, time-saving help!

I think of a script that runs down a list of rules for example:

if “from” is "" move mail to folder ""

I would like to search for the criteria in the columns

  • from
  • to
  • author
  • name

and would like to define the match for the criteria as

  • is (complete match)
  • matches/contains (matches partly)

I do not necessarily need or want to combine conditions, for example that “name contains …” but “from is not …”, but of course if this would also be possible, would like to learn about it.

Any kind soul willing to help me: Be warned, I would need a syntax for the script containing two different rules in order to understand how to add other rules on my own. I am absolutely bad at Apple Script.

Kind regards,

Here’s a simple example moving all selected messages whose sender’s address ends with to a group named like that.

property pDomain : ""

tell application id "com.devon-technologies.thinkpro2"
	set theSelection to the selection
	set theDestinationGroup to create location pDomain
	repeat with theRecord in theSelection
			set theMetadata to meta data of theRecord
			set theSender to kMDItemAuthorEmailAddresses of theMetadata
			if theSender ends with pDomain then move record theRecord to theDestinationGroup
		end try
	end repeat
end tell


thank you very much! And of course this works.

The “problems” for me with this solution are:

  • that my folders are not named according to the the property. Ok I could rename them, but given you would help me with similiar scripts for the columns to/author/name and I would rename other folders according to the properties the other scripts would need to work, I guess that I could not build a reasonable folder structure anymore.

  • that the script creates a folder (group) on the root level of my database. I had created a folder in my structure of folders with the matching name before I ran the script, but the script creates a folder on it’s own outside and above the mail-group.
    I have a database for my business containing also business mails. With this solution the complete structure would be cluttered with mail folders. Even if I would keep my business mails in a mail-only database my structure would be predetermined by the script properties. Or I would have to move them manually into my group-structure which would contradict the time-saving aspect I want to achieve by filtering.

If there is no alternative solution, that let’s me distribute mails to existent folders with names I can decide on in an already given structure, I guess I would rather “filter” them every time by hand.

Thanks for listening!

Kind regards,

PS: If no other option than filtering this way is available, could please tell me, what I must insert instead of “theSender” for filtering the columns name/author/to.
And can I create a script, that executes different properties one after another (instead of having to run a single script for every property?

PPS: I want to explain: I moved from PowerMail to Apple Mail with the idea, that I can change my organisation and workflow thanks to the fact, that I trust a DevonThink database more than other databases.
So my new way is that my mail client is not my archive anymore, it has become an uncluttred to-do-list. Everything that is in the inbox is a to-do, every to-do is in one place (the inbox). Is it done, I move it to a folder called “archive” which goes into DtPO soon also in order to have one place to search for content if needed. Filtering would be great help for me.

By the way: Did you have a look at smart groups and whether they could “file” messages the way you want?

Hallo Christian,

no, not for this purpose until I read your hint. Good to have someone thinking of a complete different solution when your own brain is fixed on another.

I have set up a smart group, listing all mails with “from matches devonthink” in my transfer folder. (The folder the newly archived mails go in first to be sorted then.) Fine, they show and I can file them to the group “DT”.

Now I added “to matches devonthink” and either none are listed or any mail from anyone, because “if following is true” is either “all” or “any”. I would need “or” there.
Imagine I would want to filter mails “from and to” for only 10 contacts. This would result in 20 smart groups. And everytime I have archived recent mails I would have to go through these 20 smart groups to move the mails in my structure. Even if I gave up my current groups and use smart groups I still would have two folders for every client, not counting the fact that some of my contacts use more than one email adress and not counting other contacts.

I will think about it again on another day and will surely take more benefit from smart groups for many purposes, but still the most efficient way would be one script that runs down different criterias and moves the messages to dedicated folders like I asked in the beginning.
Second best option I can think of would be your script given I could create one big script that executes many single scripts like yours. I would even accept folders with names matching script properties created on the root level of the database, if option no. 1 is not possible.

Third option would be that I keep my folder structure in Apple Mail, set up filters in Apple Mail that I apply before archiving and let DtPO do the achiving. (Don’t like the idea to keep all these folders in Mail.)

I still dream of one script and - boom - it’s all sorted, well most of. Any chance?

Thank you for your time and help!

Kind regards,

Any is actually OR. Could you please post a screenshot of the smart group? Thanks!

Actually I wanted to suggest to use smart groups instead of groups so that you don’t have to update the groups at all (no matter whether on your own or by using a script).

Setting up rules/filters in Apple Mail or setting up smart groups in DEVONthink should be basically the same work.

It’s definitely possible, see my simple example, but requires a highly customized script and definitely much more work. Maybe it’s the right time to learn AppleScript? :slight_smile:

I beg your pardon, you are right. I must have made a mistake at last.
I set up a new smart group some minutes ago (had deleted the old one) and “OR/ANY” works, I can list matches e.g. regarding “from” and “to” (and other) in one smart group.

Hahaha, could it be I am a bit old-fashioned? It took me quiet a while to get the concept. I was so much focussed on my existent groups, that I maintained so much for years, and never used smart groups (in any program), that I never thought about using smart groups instead. Great idea, thank you!

I had a look at smart groups the last hour. I guess I can do it all with them and maybe will come back with questions once I have explored that a bit more. But one thing for now, that I would appreciate your input on:

I found that items listed in a smart group are not tagged with the name of the smart group nor with the name of the folder (non-smart group) in which I have organized this smart group. (Other items not listed in a smart group are tagged as expected.) Can I change this or do I have to tag the mails manually. Or can I label them automatically?

The idea behind this is that my business email basically splits in only a few main groups and most of my contacts have constant and known email addresses, but all my customers don’t. Each customer is basically one individual email-address.
Now given I have a few main groups that list all my non-customer-mails, I want to list all mails that have not been listed in any of those given groups before. What would be the best, automated way to smart-group list the customer’s mails?

Kind regards,

Not yet, this would require “smart rules” (smart groups plus actions) which will be probably available in a future release.

The easiest approach might be to assign emails from your contacts a dedicated label and to use a smart group like…

Kind is Email
Label is not …

…to retrieve the messages from your customers. But that’s not really automatic without smart rules.

That would be great now that I’ve gone smart. :smiley:

Yes, auto-applying a label or tag is exactly what I thought of to retrieve all emails untagged or unlabeled. But applying a label or tag is a done in a few seconds and I will happily do so. And as you mention labels, yes, labels are best for that for me.

Christian, thank you so much again for your input, really helps a lot!

Kind regards,