Use JID class instead of strings

Uses a JID class with IDN support instead of strings.

Still fairly buggy, and has next to no proper error handling. Fixes #631 and provides a good baseline for #436 (IDN support still needs some work though).

Since there are a lot of non-descriptive commits, this should probably be squashed when merging.