A Nekhoroshev-type theorem for Hamiltonian systems with infinitely many degrees of freedom