title: Convert eml to markdown with python
body: <p>I have downloaded eml files from gmail and wanted to convert the mail content to markdown.
  The code I have used is this:</p>
  <pre><code>import os
  import email
  from markdownify import markdownify as md
  from email import message_from_file
  from email import policy
  from email.parser import BytesParser
  import glob
  
      files = glob.glob(&quot;file_gmail.eml&quot;) # returns list of files
  with open(files[0], &quot;rb&quot;) as fp:
      msg = BytesParser(policy=policy.default).parse(fp)
      asunto = msg['subject']
      msgmkd = md(msg.get_body(preferencelist=(&quot;html&quot;)).get_content())
      file = open(asunto + '.md', 'w')
      file.write(msgmkd)
      file.close()
  </code></pre>
  <p>The downside is that it leaves me the CSS and some other things and I am not able to remove it. The code that leaves at the beginning of the text is this:</p>
  <pre><code>html [if !mso]&gt;&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;&lt;!--&lt;![endif] .ExternalClass { width: 100%; background: inherit; background-color: inherit; } .ExternalClass p, .ExternalClass ul, .ExternalClass ol { Margin: 0; } .undoreset div p, .undoreset p { margin-bottom: 20px; } div[class^=&quot;aolmail\_divbody&quot;] { overflow: auto; } [owa] #ac-footer { padding: 20px 0px !important; background: inherit; background-color: inherit; }  @media only screen and (max-width: 600px) { /*----------------
  ...
  </code></pre>
  <p>Is there a better way to do it?</p>