There's not really much you can do to account for such feck-wittery.
When in traffic on a narrow road where there's oncoming traffic, I tend to ride in primary - there's physically not space for the driver of the car behind to try and pass.
On a wider road, or where there's no oncoming traffic, I tend to ride on the off-side corner of the car in front, far enough back so I've got time to stop/swerve if the driver of the car in front stops suddenly, but not so far back the driver of the car behind is more likely to become impatient thinking they should be in the gap ahead of me. Rarely then will they flank my left, but sometimes they do. How I respond depends on the situation, if it's non-aggressive I'll close the gap between myself and the car in front. If I feel I'm being endangered, I'll drop back allowing the driver to undertake. Then sit on their off-side corner so they have a clear view of me in their mirror and hopefully realise what they had just done was quite fruitless. If the 'undertaking' driver really is going nuts about it, I'll just drop back. It's not worth it.