title: Parsing email message headers in Go
body: <p>How I can read some headers from an email message in Go?</p>
  
  <p>Usually I would use <a href="https://golang.org/src/net/textproto/reader.go?s=12179:12232#L458" rel="nofollow">ReadMIMEHeader()</a>, but sadly not everybody has read all the relevant RFCs and for some messages I get output like:</p>
  
  <blockquote>
    <p>malformed MIME header line: name="7DDA4_foo_9E5D72.zip"</p>
  </blockquote>
  
  <p>I narrowed the culprit to be </p>
  
  <pre><code>Content-Type: application/x-zip-compressed; x-unix-mode=0600;
  name="7DDA4_foo_9E5D72.zip"
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>Content-Type: application/x-zip-compressed; x-unix-mode=0600; 
    name="7DDA4_foo_9E5D72.zip"
  </code></pre>
  
  <p>in the source of the message.</p>
  
  <p><a href="http://play.golang.org/p/y4OS532H1J" rel="nofollow">Go Playground example</a></p>
  
  <p><strong>What is the correct way of parsing the headers correctly, regardless if indented or not?</strong></p>