title: How to convert mbox into csv format using python?
body: <p>I am writing to convert email Mbox format into CSV using Python 3</p>
  <pre><code>import mailbox
  import csv
  writer = csv.writer(open(r&quot;...\clean_mail.csv&quot;, &quot;w&quot;))
  for message in mailbox.mbox(r'...\Inbox-001.mbox'):
      if message.is_multipart():
          content = ''.join(part.get_payload() for part in message.get_payload())
      else:
          content = message.get_payload()
      writer.writerow([message['subject'],message['from'], message['date'], content])
  </code></pre>
  <p>This is the error I am getting.</p>
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-10-b7e7d65c9723&gt; in &lt;module&gt;
        4 for message in mailbox.mbox(r'C:\Users\nikip\Documents\2021\Interview Preparation\sentiment analysis\Inbox-001.mbox'):
        5     if message.is_multipart():
  ----&gt; 6         content = ''.join(part.get_payload() for part in message.get_payload())
        7     else:
        8         content = message.get_payload()
  </code></pre>
  <p>TypeError: sequence item 0: expected str instance, list found</p>
  <p>I really appreciate any help you can provide.</p>