Heat 3 tablespoons of the oil in a large, non-stick saucepan over a medium heat. Add the onions and garlic and fry gently for 4-5 minutes, stirring regularly, until softened and very lightly browned.
Stir in the olives, capers, chilli flakes and salt, then add the tinned tomatoes and red wine (or stock). Bring the mixture to the boil, then reduce the heat until the mixture is simmering. Simmer very gently for 40-45 minutes, stirring regularly, until the sauce has thickened.
Once the sauce has been cooking for 30 minutes, half-fill a large saucepan with boiling water. Add the spaghetti and cook according to the packet instructions, until al dente.
When the pasta is cooked to your liking, reserve 3 tablespoons of the cooking water in a bowl, then drain the pasta in a colander and return it to the saucepan.
Add half of the sauce to the cooked spaghetti, then stir in the reserved cooking water. Continue to stir the mixture carefully until the spaghetti is coated in the sauce. Season, to taste, with freshly ground black pepper.
To serve, transfer the spaghetti and sauce to a warmed serving dish, then pour over the remaining sauce. Drizzle over the remaining tablespoon of oil and garnish with the parsley, if using. Serve immediately.