But what if we assume that our custom header must be added only to outgoing messages and only if there is no one already? Unfortunately you cannot do this with bare metal MTA.
The best and easiest solution is to use MSH Traffic Policy milter.
Our first condition is to check if there is already a header in the message. Message Header condition will scan message for our X-Header. It have four options for matching headers - we need not have Header condition type.
Second conditions is to match only outgoing messages. If your domain is local.net then insert *@local.net value into Message Sender condition. This will filter only messages with internal sender.
We have defined conditions, now it is time for actions. Add message header is what we looking for.