Characterization and formation of the Mg i 12.32 μm line in the quiet Sun and sunspot