title: Parsing email with Python
body: <p>I'm writing a Python script to process emails returned from <a href="http://www.procmail.org" rel="nofollow noreferrer">Procmail</a>. As suggested in this <a href="https://stackoverflow.com/questions/1225586/checking-email-with-python">question</a>, I'm using the following Procmail config:</p>
  
  <pre><code>:0:
  |$HOME/process_mail.py
  </code></pre>
  
  <p>My process_mail.py script is receiving an email via stdin like this:</p>
  
  <pre><code>From hostname Tue Jun 15 21:43:30 2010
  Received: (qmail 8580 invoked from network); 15 Jun 2010 21:43:22 -0400
  Received: from mail-fx0-f44.google.com (209.85.161.44)
  by ip-73-187-35-131.ip.secureserver.net with SMTP; 15 Jun 2010 21:43:22 -0400
  Received: by fxm19 with SMTP id 19so170709fxm.3
  for &lt;username@domain.com&gt;; Tue, 15 Jun 2010 18:47:33 -0700 (PDT)
  MIME-Version: 1.0
  Received: by 10.103.84.1 with SMTP id m1mr2774225mul.26.1276652853684; Tue, 15
  Jun 2010 18:47:33 -0700 (PDT)
  Received: by 10.123.143.4 with HTTP; Tue, 15 Jun 2010 18:47:33 -0700 (PDT)
  Date: Tue, 15 Jun 2010 20:47:33 -0500
  Message-ID: &lt;AANLkTikFsIjJ3KYW1HJWcAqQlGXNiXE2YMzrj39I0tdB@mail.gmail.com&gt;
  Subject: TEST 12
  From: Full Name &lt;username@sender.com&gt;
  To: username@domain.com
  Content-Type: text/plain; charset=ISO-8859-1
  
  ONE
  TWO
  THREE
  </code></pre>
  
  <p>I'm trying to parse the message in this way:</p>
  
  <pre><code>&gt;&gt;&gt; import email
  &gt;&gt;&gt; msg = email.message_from_string(full_message)
  </code></pre>
  
  <p>I want to get message fields like 'From', 'To' and 'Subject'. However, the message object does not contain any of these fields. </p>
  
  <p>What am I doing wrong?</p>