Stages of thermally induced gas-exchange in the high-temperature superconductor YBa2Cu3O7−δ