Problem with mail rule

I want to use a mail rule with the applescript “Mail Rule - Add attachments to DEVONThink” to automate the import of every mail attachment.

This works properly when only one new mail is received. But as soon as two or more mails are received at once, it imports the attachment of the first mail and the same attachment for the second mail. So I’m getting duplicates and the attachment from the second mail isn’t there.

This only happens when the rule is triggered at the reception. When you select two or more mails and then “Apply Rules” it works.

I think this is maybe a bug inside apple mail. When i modify the applescript to show a dialog with the subject of the mail. Then it repeats the same subject when two or more mails are received at once.

Or is it maybe a problem with the “repeat” loop within the applescript?

Hi Sebastian and welcome to the forum :slight_smile:

I believe this is a bug in Apple Mail. I have numerous rules which fail in a similar fashion, invariably when several mails arrive at the same time. This regularly includes Apple Mail applying the rule to a different mail than the one which actually triggered the rule. I have found no solution to this behaviour; as a fallback I have included checks within my scripts to at least determine whether the mail which the script is acting on fulfils the rule criteria. That at least precludes Mail causing damage, but leaves me having to intervene manually. Not exactly the point of automation…

What kind of email account do you use? E.g. iCloud, IMAP, Exchange or POP3? As far as I remember it’s only reliable in case of POP3 due to Mail’s bugs.

Hi Christian, i´m using IMAP.

I will give POP3 a try…

Please remember that POP3 might remove the messages from your mail server depending on the settings, afterwards they’re only available on the machine which imported the messages using POP3.

With POP3 it won’t even import a single mail attachment via mail rule. Only when I select the mails and start “Apply Rules”… :pensive:

I suspect that the attachments aren’t being downloaded until you perform that manual step. Apple Mail is not very good at automation. For me it works happily when I’m at my Mac, and almost universally fails when I’m not.

I used to use Postbox; I think I only stopped because there was no obvious advantage to using Mail. That was in the days before I was playing with automation. Perhaps I’ll go back to trying that. No plugin, of course - but assuming drag and drop to DT works, that should be ok. If I do go back, I’ll post here how the experience was.

So, I have just tried Postbox; on the positive side, my 6 year old license still works. On the negative side, support for AppleScript is so rudimentary that it is not obviously possible to handle mails selected by a filter (rule) using AS (so the equivalent of perform mail action with messages is unavailable). It also doesn’t seem to be possible to use a filter (rule) to save a mail to a Finder folder from where DT could help itself to the mail. So all in all whilst the interface is nice, fast things are easy to set up, Postbox isn’t going to solve this problem, unfortunately. I anybody comes across a reliable, scriptable mail client, do let me know…

I too am playing with Postbox once again. It does have many nice features. I’m looking at DevonThink integration as well. You do know you can access Postbox mailboxes directly in DevonThink, correct?

I’m not sure - I’m aware that I can import an mbox file; I’m not aware that I can access my mailboxes directly (as with Mail, where I am aware how to do so). Could you elaborate?