(IMAPProtocol p, String u, String pw)
| 761 | } |
| 762 | |
| 763 | private void login(IMAPProtocol p, String u, String pw) |
| 764 | throws ProtocolException { |
| 765 | // turn on TLS if it's been enabled or required and is supported |
| 766 | // and we're not already using SSL |
| 767 | if ((enableStartTLS || requireStartTLS) && !p.isSSL()) { |
| 768 | if (p.hasCapability("STARTTLS")) { |
| 769 | p.startTLS(); |
| 770 | // if startTLS succeeds, refresh capabilities |
| 771 | p.capability(); |
| 772 | } else if (requireStartTLS) { |
| 773 | logger.fine("STARTTLS required but not supported by server"); |
| 774 | throw new ProtocolException( |
| 775 | "STARTTLS required but not supported by server"); |
| 776 | } |
| 777 | } |
| 778 | if (p.isAuthenticated()) |
| 779 | return; // no need to login |
| 780 | |
| 781 | // allow subclasses to issue commands before login |
| 782 | preLogin(p); |
| 783 | |
| 784 | // issue special ID command to Yahoo! Mail IMAP server |
| 785 | // http://en.wikipedia.org/wiki/Yahoo%21_Mail#Free_IMAP_and_SMTPs_access |
| 786 | if (guid != null) { |
| 787 | Map<String,String> gmap = new HashMap<>(); |
| 788 | gmap.put("GUID", guid); |
| 789 | p.id(gmap); |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * Put a special "marker" in the capabilities list so we can |
| 794 | * detect if the server refreshed the capabilities in the OK |
| 795 | * response. |
| 796 | */ |
| 797 | p.getCapabilities().put("__PRELOGIN__", ""); |
| 798 | String authzid; |
| 799 | if (authorizationID != null) |
| 800 | authzid = authorizationID; |
| 801 | else if (proxyAuthUser != null) |
| 802 | authzid = proxyAuthUser; |
| 803 | else |
| 804 | authzid = null; |
| 805 | |
| 806 | if (enableSASL) { |
| 807 | try { |
| 808 | p.sasllogin(saslMechanisms, saslRealm, authzid, u, pw); |
| 809 | if (!p.isAuthenticated()) |
| 810 | throw new CommandFailedException( |
| 811 | "SASL authentication failed"); |
| 812 | } catch (UnsupportedOperationException ex) { |
| 813 | // continue to try other authentication methods below |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | if (!p.isAuthenticated()) |
| 818 | authenticate(p, authzid, u, pw); |
| 819 | |
| 820 | if (proxyAuthUser != null) |
no test coverage detected