I can't say the issue cannot be the fuel rail, it's replaceable for a reason. Limp mode issues are often the result of a dirty or faulty SCV (a replaceable part of the fuel pump) but it could equally be the rail, injectors or the pump itself. Sometimes it's just a loose water sensor on the filter. I would have to trust that the mechanic would have thought of these things first and still hasn't found the problem.
Bad fuel - or an algae bloom or waxing in the fuel - can cause problems. The filter may not trap it all (bacteria may pass through the filter), or the waxing may occur beyond the filter. Winterised diesel is available for alpine regions in Australia, some countries use winterised diesel most of the year (Norway/Sweden/Iceland/Greenland/Alaska etc, although Norway is quickly turning electric).
If the fuel rail replacement doesn't work, ask the mechanic if he's replaced the SCV which is a more common failure point in the D40.