Mail script "import" as rtfd (not eml) and perform smart rule trigger

Two-part question concerning Mail Rule scripts:

First, is it possible to “import” an email from Mail into DevonThink directly as an rtfd? I.e., the Mail Rule script would “create record with {name:theSubject & “.rtfd”, type:rtfd, …”. I nearly always convert my imported emails to rtfd (and then delete the eml records) so I can add text without needing an annotation file. Can I eliminate the convert and delete steps by “importing” already converted?

Second, the various Mail scripts follow the creation of the .eml record by the command: “perform smart rule trigger import event record theRecord”. Since no smart rule name is specified, this means “All smart rules are used” according to the DTP AppleScript dictionary. I’m uncertain about what the “trigger import event” clause means in conjunction with “all smart rules.” Is this supposed to trigger any and all smart rules that have “On Import” as a trigger?

Here’s what I want to do:

  1. Have a Mail Rule run an “Add messages to DevonThink” script to import new email into my database Inbox.
  2. The import event should then trigger a smart rule that will convert the .eml record into .rtfd (if necessary), then carry out further actions on the rtfd depending on the smart rule criteria. I can’t specify a smart rule by name in the Mail script because there will be several with different criteria dependent on the sender of the email and/or text in the subject line.

I nearly always convert my imported emails to rtfd

You have just created an exception by saying “nearly always”. This tells me you should just import the emails, filter them with a smart rule, and process those that match, not try to modify the mail rule script.

The import event should then trigger a smart rule that will convert the .eml record into .rtfd (if necessary)

Again, “if necessary”. So you need to define when it’s necessary and build that into the criteria of the smart rule.

By the way, move the imported email into the database’s Trash, do the Convert & Continue from there, then file the resulting RTF(D) document. That way, the unwanted email is already in the Trash, ready to be emptied.

1 Like

I nearly always convert my imported emails to rtfd

You have just created an exception by saying “nearly always”. This tells me you should just import the emails, filter them with a smart rule, and process those that match, not try to modify the mail rule script.

Perhaps I should have been clearer about my mail workflow. I don’t use DT to “manage” my emails, only to save a relatively small number as documents, mostly relevant to financial matters.

In a typical month I receive around 800 emails. About 400 I can trash without opening based on the subject line alone, Another 350 I will read before trashing, filing in a local mailbox, or leaving temporarily in my Mail inbox as a reminder of an upcoming event. Only the remaining ~50 will I import into DT.

Of those, about 30-35 are recurring bills, payment confirmations, Amazon purchases, and the like. These I can easily direct to DT using Mail rules, and they will always be converted to rtfd.

The rest are infrequent or one-off orders/bills/payments that aren’t feasible to use a Mail rule for, and the occasional informational email that needs to be kept (notices and confirmations of changes to an account, terms of service, etc.). This group I send manually to DT using a Script menu script, and this is what I was referring to when I said I “nearly always” convert to rtfd: the expense-related stuff I convert to rtfd so I can edit it, while the informational stuff I leave as eml. The “nearly always” has nothing to do with the Mail rule scripts.

... a smart rule that will convert the .eml record into .rtfd (if necessary)

Again, “if necessary”. So you need to define when it’s necessary and build that into the criteria of the smart rule.

By “if necessary” I meant “only if I can’t create the rtfd directly from the Mail rule script.” (Not “if this already imported eml needs to be converted” – if I import an eml from the Mail rule, conversion will be necessary; if I can import an rtfd from the Mail rule, it won’t be necessary.)

With all that clarified (I hope), back to my questions:

  1. Can a Mail rule script create an rtfd instead of an eml record in DT? Is there any reason this will not work or pitfalls I should be aware of?
  2. What exactly does “perform smart rule trigger import event …” do once the file gets into DT?
  1. Can a Mail rule script create an rtfd instead of an eml record in DT? Is there any reason this will not work or pitfalls I should be aware of?

Directly, no. You could generate an RTF file from the mail’s contents but (1) there will be no attachments, and (2) there will be no formatting. Converting via a smart rule would be a better option.

  1. What exactly does “perform smart rule trigger import event …” do once the file gets into DT?

Exactly what it says in the dictionary. Runs smart rules that pertain to the location and criteria. However, as is also known, if you have multiple smart rules targeting the same location and file types, the first rule runs. Subsequent ones may be ignored or affected by the actions of the previous rules.

For example, both rules run in this contrived example…

This is something you’d need to think about in your situation.

OK, thanks. I’ll have to rethink things.