I would like to test client connections with IMAP over SSL, HTTPS, and other secure text-based Internet protocols over SSL/TLS, the same way I would using Telnet or Netcat if they were not tunneled over a secure protocol. Is there a way to get Telnet or Netcat to go through SSL/TLS such as with a pipe or alternate program?
First, there is no Telnet/Netcat client – they are two separate programs. Second, there is no "the" – there exist at least 10 different Telnet clients and at least 6 different Netcat versions.
In case you do not trust your SSL implementation (heartbleed), you can use GnuPG for encryption in combination with the traditional netcat.
On the receiving side, execute
and on the sending side, execute
Parameters for netcat depend on which implementation you use. For GnuPG, arguments -c and -d are used for symmetric encryption/decryption and you have to enter the same password on both sides to pipe data through gpg.
Pro tip: pipe your data through a stream compressor like gzip/gunzip or xz/unxz (compress before encryption, decompress after decryption) if you have "more" CPU power than bandwidth.