title: Extracting only the body of email using Python
body: <p>I am using Python to read the Enron email dataset. I have the emails in text files. I would like to read the text files and extract only the "Body" section of each email. I am not concerned about any other <code>FROM</code>, <code>TO</code>, <code>BCC</code>, <code>attachments</code>, <code>DATE</code>, etc. I only want the <code>BODY</code> section and would like to store it in a list. I tried to use the <code>get_payload()</code> function, but it still prints everything. How do I skip the other content and use only the Body section?</p>
  
  <pre><code>import email.parser
  from email.parser import Parser
  
  # Code to extract a particular section from raw emails.
  
  parser = Parser()
  text1 = open("path of the file", "r").read()
  msg = email.message_from_string(text1)
  email = parser.parsestr(text1)
  
  if msg.is_multipart():
      for payload in msg.get_payload():
         print payload.get_payload()
  else:
      print msg.get_payload()
  </code></pre>
  
  <p>One file may contain multiple emails. Sample emails.</p>
  
  <pre><code>docID:  1
  segmentNumber:  0
  Body:   I just checked with Carolyn on your invoicing for the conference.  She 
  verified the 85K was processed.
  
  ##########################################################
  docID:  2
  segmentNumber:  0
  Body:   null
  ##########################################################
  docID:  3
  segmentNumber:  0
  Body:   In regard to the costs for the GAM conference, Karen told me the $ 6,695.97 
  figure was inclusive of all the items for the conference.  However, after 
  speaking with Shweta, I found out this is not the case.  The CDs are not 
  included in this figure.  
  
  The CD cost will be $2,011.50 + the cost of postage/handling (which is 
  currently being tabulated).
  
  
  ##########################################################
  docID:  3
  segmentNumber:  1
  Body:   
  This is the original quote for this project and it did not include the 
  postage. As soon as I have the details from the vendor, I'll forward those to 
  you.
  Please call me if you have any questions.
  </code></pre>