Please refer to the implementation: pkg.jfrech.com/go/imaptar