title: MS Exchange IMAP login returns "BAD Command recieved in Invalid state"
body: <p>I have an IMAP client (Perl, Mail::IMAPClient) connecting to a MS Exchange server which, upon login, receives the error "1 BAD Command received in Invalid state." This same IMAP client works in a number of other environments with no errors, and certainly not errors immediately at login!</p>
  
  <p>I've had trouble determining the source of the error and at this point I'm inclined to think the customer's Exchange server is misconfigured or there's some firewall or packet manipulation shenanigans afoot.</p>
  
  <p>I was able to take a packet capture that really looks normal other than the error. After the TCP handshake this is the whole IMAP conversation, followed by the TCP hangup.</p>
  
  <pre><code>No.     Time           Source                Destination
        4 0.010228000    (server)              (client)   
  Internet Message Access Protocol
      Line: * OK The Microsoft Exchange IMAP4 service is ready.\r\n
  
  No.     Time           Source                Destination
        5 0.012680000    (client)              (server)   
  Internet Message Access Protocol
      Line: 1 LOGIN (username) (password)\r\n
          Request Tag: 1
          Request Command: LOGIN
          Request: LOGIN (username) (password)
  
  No.     Time           Source                Destination
        6 0.017559000    (server)              (client)   
  Internet Message Access Protocol
      Line: 1 BAD Command received in Invalid state.\r\n
          Response Tag: 1
          Response Status: BAD
          Response: BAD Command received in Invalid state.
  </code></pre>
  
  <p>Am I right in assuming the problem is on the IMAP server's end?</p>