My grand plan is to have a rule in Apple Mail that automatically adds a custom header to each message. This rule would be last and each of the rules before that last rule would check for the presence of this custom header and therefore no longer work for incoming mail.
So the plan is to have a small AppleScript
that adds this header but I am running into a block which hopefully someone can help we with. I have the following pieces of code:
tell application "Mail"
activate
set myHeader to make new header with properties {name:"X-MySecretHeader", content:"It's been set"}
end
The last statement fails with the following error:
Mail got an error: Can’t make or move that element into that container.
I then changed the code slightly:
tell application "Mail"
activate
set theMessage to get item 1 of (get selection)
set theHeaders to headers of theMessage
set myHeader to duplicate item -1 of theHeaders
end
Mail got an error: Headers can not be copied.
That last error seems to indicate that I'm trying to do something which cannot be done. I have also tried to do this in a tell block to theMessage
but that did not change anything.
Anyone has an idea?