如何使用python重命名和排序.eml文件中的头文件?

如何使用python重命名和排序.eml文件中的头文件?,python,python-3.x,list,python-requests,Python,Python 3.x,List,Python Requests,首先,我想用以下方法替换标题的值: file = open('abc.eml', 'r+') headers = Parser().parse(file) headers.replace_header('Delivered-To','cad@gmail.com') 但现在我想根据我的愿望订购标题,就像我想在收到后放置X-Received标题一样: 另外,如果我想将X-Google-Smtp-Source重命名为X-Google-Ftp-Source,该怎么做? 我引用了一些类

首先,我想用以下方法替换标题的值:

   file = open('abc.eml', 'r+')
   headers = Parser().parse(file)
   headers.replace_header('Delivered-To','cad@gmail.com')
但现在我想根据我的愿望订购标题,就像我想在收到后放置X-Received标题一样: 另外,如果我想将X-Google-Smtp-Source重命名为X-Google-Ftp-Source,该怎么做? 我引用了一些类似git的资源。堆栈,但我没有得到解决方案。 有人能帮忙吗? 此外,如果您知道如何在.eml文件中添加类似pdf的附件,请提供帮助

Delivered-To: abc@gmail.com
Received: by 2002:ac9:7f0f:0:0:0:0:0 with SMTP id h15p34174o;
        Fri, 05 Apr 2021 08:15:23 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJzHfuzlMENyQ5wL1O1nlqhaZb+uLeH/U9UE7t8ZeswmA6cdrfddr2I/ISa5m3h
X-Received: by 2002:a17:906:564f:: with SMTP id v15mr4909636ejr.96.1619795723139;
        Fri, 30 Apr 2021 08:15:23 -0700 (PDT)