Buggy code:
public class SmtpTransport extends Transport { public static final String TRANSPORT_TYPE = "SMTP" ; public static ServerSettings decodeUri ( String uri ) { } public static String createUri ( ServerSettings server ) { } String mHost ; int mPort ; String mUsername ; String mPassword ; AuthType mAuthType ; ConnectionSecurity mConnectionSecurity ; Socket mSocket ; PeekableInputStream mIn ; OutputStream mOut ; private boolean m8bitEncodingAllowed ; private int mLargestAcceptableMessage ; public SmtpTransport ( Account account ) throws MessagingException { } @ Override public void open ( ) throws MessagingException { try { boolean secureConnection = false ; InetAddress [ ] addresses = InetAddress . getAllByName ( mHost ) ; for ( int i = 0 ; i < ( addresses . length ) ; i ++ ) { try { SocketAddress socketAddress = new InetSocketAddress ( addresses [ i ] , mPort ) ; if ( ( mConnectionSecurity ) == ( ConnectionSecurity . SSL_TLS_REQUIRED ) ) { SSLContext sslContext = SSLContext . getInstance ( "TLS" ) ; sslContext . init ( null , new TrustManager [ ] { TrustManagerFactory . get ( mHost , mPort ) } , new SecureRandom ( ) ) ; mSocket = TrustedSocketFactory . createSocket ( sslContext ) ; mSocket . connect ( socketAddress , SOCKET_CONNECT_TIMEOUT ) ; secureConnection = true ; } else { mSocket = new Socket ( ) ; mSocket . connect ( socketAddress , SOCKET_CONNECT_TIMEOUT ) ; } } catch ( SocketException e ) { if ( i < ( ( addresses . length ) - 1 ) ) { continue ; } throw new MessagingException ( "Cannot<seq2seq4repair_space>connect<seq2seq4repair_space>to<seq2seq4repair_space>host" , e ) ; } break ; } mSocket . setSoTimeout ( SOCKET_READ_TIMEOUT ) ; mIn = new PeekableInputStream ( new BufferedInputStream ( mSocket . getInputStream ( ) , 1024 ) ) ; mOut = new BufferedOutputStream ( mSocket . getOutputStream ( ) , 1024 ) ; executeSimpleCommand ( null ) ; InetAddress localAddress = mSocket . getLocalAddress ( ) ; String localHost = localAddress . getCanonicalHostName ( ) ; String ipAddr = localAddress . getHostAddress ( ) ; if ( ( ( localHost . equals ( "" ) ) || ( localHost . equals ( ipAddr ) ) ) || ( localHost . contains ( "_" ) ) ) { if ( ! ( ipAddr . equals ( "" ) ) ) { if ( localAddress instanceof Inet6Address ) { <START_BUG> localHost = ( "[IPV6:" + ipAddr ) + "]" ; <END_BUG> } else { localHost = ( "[" + ipAddr ) + "]" ; } } else { localHost = "android" ; } } HashMap < String , String > extensions = sendHello ( localHost ) ; m8bitEncodingAllowed = extensions . containsKey ( "8BITMIME" ) ; if ( ( mConnectionSecurity ) == ( ConnectionSecurity . STARTTLS_REQUIRED ) ) { if ( extensions . containsKey ( "STARTTLS" ) ) { executeSimpleCommand ( "STARTTLS" ) ; SSLContext sslContext = SSLContext . getInstance ( "TLS" ) ; sslContext . init ( null , new TrustManager [ ] { TrustManagerFactory . get ( mHost , mPort ) } , new SecureRandom ( ) ) ; mSocket = TrustedSocketFactory . createSocket ( sslContext , mSocket , mHost , mPort , true ) ; mIn = new PeekableInputStream ( new BufferedInputStream ( mSocket . getInputStream ( ) , 1024 ) ) ; mOut = new BufferedOutputStream ( mSocket . getOutputStream ( ) , 1024 ) ; extensions = sendHello ( localHost ) ; secureConnection = true ; } else { throw new CertificateValidationException ( "STARTTLS<seq2seq4repair_space>connection<seq2seq4repair_space>security<seq2seq4repair_space>not<seq2seq4repair_space>available" , new CertificateException ( ) ) ; } } boolean authLoginSupported = false ; boolean authPlainSupported = false ; boolean authCramMD5Supported = false ; if ( extensions . containsKey ( "AUTH" ) ) { List < String > saslMech = Arrays . asList ( extensions . get ( "AUTH" ) . split ( "<seq2seq4repair_space>" ) ) ; authLoginSupported = saslMech . contains ( "LOGIN" ) ; authPlainSupported = saslMech . contains ( "PLAIN" ) ; authCramMD5Supported = saslMech . contains ( "CRAM-MD5" ) ; } if ( extensions . containsKey ( "SIZE" ) ) { try { mLargestAcceptableMessage = Integer . parseInt ( extensions . get ( "SIZE" ) ) ; } catch ( Exception e ) { if ( ( K9 . DEBUG ) && ( K9 . DEBUG_PROTOCOL_SMTP ) ) { Log . d ( LOG_TAG , ( ( "Tried<seq2seq4repair_space>to<seq2seq4repair_space>parse<seq2seq4repair_space>" + ( extensions . get ( "SIZE" ) ) ) + "<seq2seq4repair_space>and<seq2seq4repair_space>get<seq2seq4repair_space>an<seq2seq4repair_space>int" ) , e ) ; } } } if ( ( ( ( ( mUsername ) != null ) && ( ( mUsername . length ( ) ) > 0 ) ) && ( ( mPassword ) != null ) ) && ( ( mPassword . length ( ) ) > 0 ) ) { switch ( mAuthType ) { case LOGIN : case PLAIN : if ( authPlainSupported ) { saslAuthPlain ( mUsername , mPassword ) ; } else if ( authLoginSupported ) { saslAuthLogin ( mUsername , mPassword ) ; } else { throw new MessagingException ( "Authentication<seq2seq4repair_space>methods<seq2seq4repair_space>SASL<seq2seq4repair_space>PLAIN<seq2seq4repair_space>and<seq2seq4repair_space>LOGIN<seq2seq4repair_space>are<seq2seq4repair_space>unavailable." ) ; } break ; case CRAM_MD5 : if ( authCramMD5Supported ) { saslAuthCramMD5 ( mUsername , mPassword ) ; } else { throw new MessagingException ( "Authentication<seq2seq4repair_space>method<seq2seq4repair_space>CRAM-MD5<seq2seq4repair_space>is<seq2seq4repair_space>unavailable." ) ; } break ; case AUTOMATIC : if ( secureConnection ) { if ( authPlainSupported ) { saslAuthPlain ( mUsername , mPassword ) ; } else if ( authLoginSupported ) { saslAuthLogin ( mUsername , mPassword ) ; } else if ( authCramMD5Supported ) { saslAuthCramMD5 ( mUsername , mPassword ) ; } else { throw new MessagingException ( "No<seq2seq4repair_space>supported<seq2seq4repair_space>authentication<seq2seq4repair_space>methods<seq2seq4repair_space>available." ) ; } } else { if ( authCramMD5Supported ) { saslAuthCramMD5 ( mUsername , mPassword ) ; } else { throw new MessagingException ( "Update<seq2seq4repair_space>your<seq2seq4repair_space>outgoing<seq2seq4repair_space>server<seq2seq4repair_space>authentication<seq2seq4repair_space>setting.<seq2seq4repair_space>AUTOMATIC<seq2seq4repair_space>auth.<seq2seq4repair_space>is<seq2seq4repair_space>unavailable." ) ; } } break ; default : throw new MessagingException ( "Unhandled<seq2seq4repair_space>authentication<seq2seq4repair_space>method<seq2seq4repair_space>found<seq2seq4repair_space>in<seq2seq4repair_space>the<seq2seq4repair_space>server<seq2seq4repair_space>settings<seq2seq4repair_space>(bug)." ) ; } } } catch ( SSLException e ) { throw new CertificateValidationException ( e . getMessage ( ) , e ) ; }

Fix:
localHost = ( "[IPv6:" + ipAddr ) + "]" ;