Lua: 从邮件中删除字段 header

Lua: Remove field from mail header

我想从 lua 的邮件 header 中删除一些字段。假设我有一个名为 "header" 的字符串,我想删除所有以 "Re".

开头的 header 字段

我该怎么做?

我试过这样的事情:

string.gsub(header ,"\nRe.-\n[^%s]", "")

但是没用....

例如输入

Received: by a;
        Tue, 14 Mar 2012 19:43:29 -0700 (PDT)
X-Received: by b;
        Tue, 14 Mar 2012 19:43:29 -0700 (PDT)
Return-Path: <x@example.com>
Received: from ex.com 
        by mx..com 
        for x
Received-SPF: pas5a;
Authentication-Results:;
       dkim=pass header.i=@;
Return-Path: <bounce-paypal.de>
MIME-Version: 1.0
Reply-To: a
Subject: b
From: c
To: xxx
Date: Tue, 14 Mar 2012 19:43:29 -0700 (PDT)
Content-Type: multipart/alternative;

应该变成

X-Received: by b;
        Tue, 14 Mar 2012 19:43:29 -0700 (PDT)
Authentication-Results:;
       dkim=pass header.i=@;
MIME-Version: 1.0
Subject: b
From: c
To: xxx
Date: Tue, 14 Mar 2012 19:43:29 -0700 (PDT)
Content-Type: multipart/alternative;

删除以 "Re" 开头的字段时。主要问题是 multi-line 个字段。

如果问题是 multi-line 个字段,首先将它们合并到 single-line 个字段

header = string.gsub(header ,"\n( +)", "%1")

进行您想要的编辑。完成后,根据需要恢复 multi-line 个字段:

header = string.gsub(header ,"", "\n")

只是一个占位符。您可以使用邮件中未使用的任何字符 headers.

尝试

string.gsub(header ,"%f[^\n%z]Re.-\n%f[%S]", "")