title: How to accurately parse smtp message status code (DSN)?
body: <p>RFC1893 claims that status codes will come in the format below you can read more <a href="http://www.faqs.org/rfcs/rfc1893.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>But our bounce management system is having a hard time parsing error status code from bounce messages.  We are able to get the raw message, but depending on the email server the code will come in different places.  Is there any rule on how to parse this type of messages to obtain better results.  We are not looking for the 100% solution but at least 80%.  </p>
  
  <blockquote>
    <p>This document defines a new set of status codes to report mail system
       conditions.  These status codes are intended to be used for media and
       language independent status reporting.  They are not intended for
       system specific diagnostics.</p>
    
    <p>The syntax of the new status codes
    is defined as:</p>
  
  <pre><code>      status-code = class "." subject "." detail
        class = "2"/"4"/"5"
        subject = 1*3digit
        detail = 1*3digit
  </code></pre>
    
    <p>White-space characters and comments
    are NOT allowed within a status-<br>
    code.  Each numeric sub-code within
    the status-code MUST be expressed<br>
    without leading zero digits.</p>
  </blockquote>
  
  <p>The quote above from the RFC tells one thing but then the text below from a leading tool on bounce management says something different, where I can get a good source of standard status codes:</p>
  
  <blockquote>
    <p>Return Code   Description<br>
    0 UNDETERMINED - (ie. Recipient Reply)<br>
    10    HARD BOUNCE - (ie. User Unknown)<br>
    20    SOFT BOUNCE - General<br>
    21    SOFT BOUNCE - Dns Failure<br>
    22    SOFT BOUNCE - Mailbox Full<br>
    23    SOFT BOUNCE - Message Too Large<br>
    30    BOUNCE - NO EMAIL ADDRESS. VERY RARE!<br>
    40    GENERAL BOUNCE<br>
    50    MAIL BLOCK - General<br>
    51    MAIL BLOCK - Known Spammer<br>
    52    MAIL BLOCK - Spam Detected<br>
    53    MAIL BLOCK - Attachment Detected<br>
    54    MAIL BLOCK - Relay Denied<br>
    60    AUTO REPLY - (ie. Out Of Office)<br>
    70    TRANSIENT BOUNCE<br>
    80    SUBSCRIBE Request<br>
    90    UNSUBSCRIBE/REMOVE Request<br>
    100   CHALLENGE-RESPONSE  </p>
  </blockquote>