Fix up various off-by-one errors when syncing flags in nnimap.