This duplicated code is not easy maintainable.
Please, can you create a pull request with your proposal for improving the Dokuwikis mail class?