Postfix

smtpd_command_filter 的後綴正則表達式

  • August 20, 2013

我的一些使用者正在使用 Gmail 向我們的域發送郵件(郵件伺服器託管在帶有後綴的 CentOS 5 機器上)。有時,但不是所有時候,當他們這樣做時,他們會得到類似於以下內容的反彈:

---------- Forwarded message ----------
From: Mail Delivery Subsystem <mailer-daemon@googlemail.com>
Date: Mon, Aug 19, 2013 at 9:12 AM
Subject: Delivery Status Notification (Failure)
To: user1@domain.com


Delivery to the following recipient failed permanently:

user2@domain.com

Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the       recipient domain domain.com by mail.domain.com. [xxx.xxx.xxx.xxx].

The error that the other server returned was:
502 5.5.2 Error: command not recognized

----- Original message -----

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
   d=gmail.com; s=;
   h=mime-version:sender:in-reply-to:references:date:message-id:subject
    :from:to:content-type;
   bh=...=;
   b=...==
MIME-Version: 1.0
X-Received: by xxx.xxx.xxx.xxx with SMTP id ...;
Mon, 19 Aug 2013 06:12:55 -0700 (PDT)
Sender: user1@gmail.com
Received: by xxx.xxx.xxx.xxx with HTTP; Mon, 19 Aug 2013 06:12:55 -0700 (PDT)
In-Reply-To: <...@mail.gmail.com>
References: <...@mail.gmail.com>
   <...@domain.com>
   <....gmail.com>
   <....gmail.com>
Date: Mon, 19 Aug 2013 09:12:55 -0400
X-Google-Sender-Auth: ...
Message-ID: <...@mail.gmail.com>
Subject: ...
From: <user1@domain.com>
To: <user2@domain.com>
Content-Type: multipart/alternative; boundary=...  

但奇怪的是,郵件仍然通過……

檢查我的郵件日誌後,我看到類似於以下內容的行:

Aug 19 9:12:36 domain postfix/smtpd[...]: connect from mail.google.com[xxx.xxx.xxx.xxx]
Aug 19 9:12:37 domain postfix/smtpd[...]: XXXX: mail.google.com[xxx.xxx.xxx.xxx]
Aug 19 9:12:37 domain postfix/smtpd[...]: warning: non-SMTP command from mail.google.com[xxx.xxx.xxx.xxx]:         h=mime-version:sender:in-reply-to:references:date:message-id:subject
Aug 19 9:12:37 domain postfix/smtpd[...]: disconnect from mail.google.com[xxx.xxx.xxx.xxx]  

看起來好像我的郵件伺服器正在將“h = mime”行解釋為命令。

經過一番研究,我關注了這個執行緒:

http://serverfault.com/questions/379964/postfix-unknown-command/380248#380248  

我添加了

smtpd_command_filter = pcre:/etc/postfix/bogus_commands  

參數到我的 /etc/postfix/main.cf 文件,然後在 bogus_commands 文件中添加一些正則表達式以嘗試替換任何以開頭的命令

h=mime  

NOOP  

但是,我嘗試過的正則表達式似乎都沒有工作。

我試過了:

/^.*h=mime.*$/\s NOOP  

preg_replace(^.*h=mime.*$, NOOP, )  

/.*h=mime.*/ NOOP  

誰能幫我找到我需要的正則表達式的正確語法才能正常工作?無論如何,我都不是正則表達式專家。我可能只是在做一些簡單的錯誤。非常感謝您提供的任何幫助。

在我的特殊情況下,事實證明我使用了不正確的後綴版本來嘗試實現 smtpd_command_filter 參數。將 postfix 更新到最新版本後,現在一切正常。

引用自:https://serverfault.com/questions/532095