General solution to the E-B mixing problem