The way a dog moves it tail can shed light on its mood – and other dogs can spot and respond to these differences, a study suggests.