You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Procmail转发邮件插入文本遇问题:日志报错与位置异常求助

Fixing Your Procmail Script: "Missing Action" Error & Text Injection Position

Let's break down the issues with your script and fix them step by step:

1. The "procmail: Missing action" Error

Your original script has two syntax missteps triggering this error:

  • You had a standalone :0 * ^Subject:.*weather rule with no associated action. Procmail requires every :0 rule block to have a clear action (like filtering, saving, or forwarding).
  • Your pipe command wasn't wrapped in shell braces, so Procmail misinterpreted the separate echo and cat commands as invalid, unassociated actions.

2. Text Injection in the Wrong Position

Since your incoming email is a multipart MIME message, using the bfw flag filters the entire raw email content—including MIME headers. That’s why your injected text ended up above the MIME body instead of the actual message content. We need to target only the text/plain body part to insert your text properly.

Corrected Procmail Script

Here's the fixed version that resolves both issues:

SHELL=/bin/bash
VERBOSE=off
LOGFILE=/home/test/.procmail.log
LOGDATE_=`/bin/date +%Y-%m-%d`

:0
* ^Subject:.*weather
{
    # Inject text at the start of the text/plain body part
    :0 fhw
    | sed '/^Content-Type: text\/plain;/,/^$/ {
        /^$/!b
        i\
This is injected text\
    }'

    # Forward the modified email (keep a copy with the 'c' flag)
    :0 c
    ! mymail@somedomain.com
}

What Each Part Does:

  • Branch Block {}: Wraps all actions for the subject-matching rule, eliminating the "Missing action" error by ensuring every :0 has a defined purpose.
  • Sed Filter: The sed command locates the text/plain MIME part header, waits until the end of the header (blank line), then inserts your text right before the actual message content.
  • Forward Rule: The :0 c rule forwards the modified email to your target address, with c preserving a copy of the modified email in your inbox (remove c if you don't want a local copy).

Verification

After updating your script, send a test email with "weather" in the subject. Check your .procmail.log for errors, and verify the forwarded email has your injected text at the top of the message body, not above the MIME headers.

内容的提问来源于stack exchange,提问作者Marek MW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:34:33