private boolean login() { try { channel.write(". CAPABILITY\r\n"); if (config.getPassword() != null) channel.write(". login " + config.getUsername() + " " + config.getPassword() + "\r\n"); else { // Use xoauth login instead. OAuthConfig oauth = config.getOAuthConfig(); Preconditions.checkArgument( oauth != null, "Must specify a valid oauth config if not using password auth"); //noinspection ConstantConditions String oauthString = new XoauthSasl(config.getUsername(), oauth.clientId, oauth.clientSecret) .build(Protocol.IMAP, oauth.accessToken, oauth.tokenSecret); channel.write(". AUTHENTICATE XOAUTH " + oauthString + "\r\n"); } return mailClientHandler.awaitLogin(); } catch (Exception e) { // Capture the wire trace and log it for some extra context here. StringBuilder trace = new StringBuilder(); for (String line : mailClientHandler.getWireTrace()) { trace.append(line).append("\n"); } log.warn( "Could not oauth or login for {}. Partial trace follows:\n" + "----begin wiretrace----\n{}\n----end wiretrace----", new Object[] {config.getUsername(), trace.toString(), e}); } return false; }
@Override public List<String> getWireTrace() { return mailClientHandler.getWireTrace(); }