title: Writing Emails to CSV Resulting in Only One Column
body: <p>I have this script I'm using that I got online and modified a bit. Basically what I want is to scrape all the emails in my inbox and save them to a CSV with <strong>Email, First Name, Last Name</strong> format. So far it is saving all that info into one column of CSV instead of three..</p>
  
  <pre><code>#!/usr/bin/env python
  #
  # Very basic example of using Python 3 and IMAP to iterate over emails in a
  # gmail folder/label.  This code is released into the public domain.
  #
  # This script is example code from this blog post:
  # http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/
  #
  # This is an updated version of the original -- modified to work with Python 3.4.
  #
  import sys
  import imaplib
  import getpass
  import email
  import email.header
  import datetime
  import csv
  
  
  EMAIL_ACCOUNT = "test@email.com"
  
  # Use 'INBOX' to read inbox.  Note that whatever folder is specified, 
  # after successfully running this script all emails in that folder 
  # will be marked as read.
  EMAIL_FOLDER = "INBOX"
  
  
  def process_mailbox(M):
      """
      Do something with emails messages in the folder.  
      For the sake of this example, print some headers.
      """
  
      rv, data = M.search(None, "ALL")
      if rv != 'OK':
          print("No messages found!")
          return
  
      emailList = []
      out = open('email_list.csv', 'w')
      for num in data[0].split():
          rv, data = M.fetch(num, '(RFC822)')
          if rv != 'OK':
              print("ERROR getting message", num)
              return
  
          msg = email.message_from_bytes(data[0][1]) # Contains all the message info including header and content
          hdr = email.header.make_header(email.header.decode_header(msg['From']))
          sender = str(hdr)
          emailList.append(sender)
          #out.write(sender)
          #out.write('\n')
  
      for c in emailList:
          print (c.split(" "))
          out.write(c)
          out.write('\n')
  
      out.close()
  
  
  ##        print('Raw Date:', msg['Date'])
  ##        # Now convert to local date-time
  ##        date_tuple = email.utils.parsedate_tz(msg['Date'])
  ##        if date_tuple:
  ##            local_date = datetime.datetime.fromtimestamp(
  ##                email.utils.mktime_tz(date_tuple))
  ##            print ("Local Date:", \
  ##                local_date.strftime("%a, %d %b %Y %H:%M:%S"))
  
  
  M = imaplib.IMAP4_SSL('imap.gmail.com')
  
  try:
      rv, data = M.login(EMAIL_ACCOUNT, 'password')
  except imaplib.IMAP4.error:
      print ("LOGIN FAILED!!! ")
      sys.exit(1)
  
  print(rv, data)
  
  rv, mailboxes = M.list()
  if rv == 'OK':
      print("Mailboxes:")
      print(mailboxes)
  
  rv, data = M.select(EMAIL_FOLDER)
  if rv == 'OK':
      print("Processing mailbox...\n")
      process_mailbox(M)
      M.close()
  else:
      print("ERROR: Unable to open mailbox ", rv)
  
  M.logout()
  </code></pre>
  
  <p>Which prints out in such format:</p>
  
  <pre><code>['John', 'Doe', '&lt;mail-noreply@google.com&gt;']
  ['Joe', 'Doe', '&lt;mail-noreply@google.com&gt;']
  ['Jacob', 'Doe', '&lt;mail-noreply@google.com&gt;']
  ['Homer', 'Simpson-Doh!', '&lt;mail-noreply@google.com&gt;']
  </code></pre>
  
  <p>But in CSV it prints all that info into one column like this:</p>
  
  <pre><code>      Column 1
  Row 1 John Doe &lt;mail-noreply@google.com&gt;
  Row 2 Joe Doe &lt;mail-noreply@google.com&gt;
  Row 3 Jacob Doe &lt;mail-noreply@google.com&gt;
  </code></pre>
  
  <p>But I need 3 columns instead..tried doing out.write(c.split(" ")) but that results in an error.</p>