fix a bug in mail client, must loop in reverse order here because we
might splice