Here is my code for extracting fields that i want to.
But, I don't think it works effectively because extracting is depends on count of fields.
Surely It's not important in small data however, I want to know better way.
So I want to extract at once or more effectively
Sorry for my stupidity.
import re
data="""
Message-ID: <[email protected]>
Received: from 125.209.x.x (net58.219.x-x.host.lt-nn.net [91.219.x.x])
by crcvmail15.google.com with ESMTP id +844Q-zuS122aEqk5CZDZg
for <[email protected]>;
Received: from 125.209.x.x (net58.219.x-18.host.lt-nn.net [91.219.x.x])
by crcvmail15.google.com with ESMTP id +844Q-zuS122aEqk5CZDZg
for <[email protected]>;
Tue, 22 Dec 2020 11:20:58 -0000
From: "test"<[email protected]>
To: [email protected]
Subject:example email
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
"""
def searchHeader(field):
form = re.search(r'('+field+'W+(.*?)
)',data)
if form:
print(form.group())
fields = ['From','To','Cc','Subject','Message-ID','Date','(Return-Path|Reply-To)']
for field in fields:
res = searchHeader(field)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…