I may be missing something here, but I don't see anywhere you have taken steps to secure the authentication credentials. Near as I can tell they would be stored in plain text.
Other than that, this is some great work Imapi! Thanks for contributing to the community.