fork(1) download
  1. import re
  2.  
  3. data="""
  4. Message-ID: <1608636066635.7f830.79689714@crcvmail15.nm>
  5. Received: from 125.209.x.x (net58.219.x-x.host.lt-nn.net [91.219.x.x])
  6. by crcvmail15.google.com with ESMTP id +844Q-zuS122aEqk5CZDZg
  7. for <test@google.com>;
  8. Received: from 125.209.x.x (net58.219.x-18.host.lt-nn.net [91.219.x.x])
  9. by crcvmail15.google.com with ESMTP id +844Q-zuS122aEqk5CZDZg
  10. for <test@google.com>;
  11. Tue, 22 Dec 2020 11:20:58 -0000
  12. From: "test"<from@google.com>
  13. To: test@google.com
  14. Subject:example email
  15. Content-Type: text/html; charset="utf-8"
  16. Content-Transfer-Encoding: quoted-printable
  17. """
  18.  
  19. fields = ['From','To','Cc','Subject','Message-ID','Date','Return-Path', 'Reply-To']
  20. pat = fr'^({"|".join(map(re.escape, fields))})\W+(.*)'
  21. result = dict(re.findall(pat,data, re.M))
  22. print(result)
Success #stdin #stdout 0.02s 9276KB
stdin
Standard input is empty
stdout
{'Message-ID': '1608636066635.7f830.79689714@crcvmail15.nm>', 'From': 'test"<from@google.com>', 'To': 'test@google.com', 'Subject': 'example email'}