简体   繁体   English

procmail配方删除页脚

[英]procmail recipe to remove footer

I've encountered some problem when doing the procmail recipe. 我在做procmail配方时遇到了一些问题。

Here what I have get so far : 这是到目前为止我得到的:

  :0
     * ^X-Loop: myemail@gmail\.com
     /dev/null

     :0

    # filtering email by number 60
     * ^Subject:.*(60)
    {
      :0c:
      ${DEFAULT}

      #trying to take out input from the body
      :0fb
      | head -10

      #Forward it to the other folder
      :0
      mytest/
      }

The problem occur when procmail reading the body of the email.It will show output like this : procmail读取电子邮件正文时会发生此问题,它将显示如下输出:

   +96szV6aBDlD/F7vuiK8fUYVknMQPfPmPNikB+fdYLvbwsv9duz6HQaDuwhGn6dh9w2U
   1sABcykpdyfWqWhLt5RzCqppYr5I4yCmB1CNOKwhlzI/w8Sx1QTzGT32G/ERTlbr91BM VmNQ==
   MIME-Version: 1.0
   Received: by 10.52.97.41 with SMTP id dx9mr14500007vdb.89.1337845760664; Thu,
   24 May 2012 00:49:20 -0700 (PDT)
   Received: by 10.52.34.75 with HTTP; Thu, 24 May 2012 00:49:20 -0700 (PDT)
   Date: Thu, 24 May 2012 15:49:20 +0800
   Message-ID: <CAE1Fe-r4Lid+YSgFTQdpsniE_wzeGjETWLLJJxat+HK94u1=AQ@mail.gmail.com>
   Subject: 60136379500
   From: my email <my email@gmail.com>
   To: your email <your email@gmail.com>
   Content-Type: multipart/alternative; boundary=20cf307f380654240604c0c37d07

   --20cf307f380654240604c0c37d07
   Content-Type: text/plain; charset=ISO-8859-1

   hi
   there
   how
   are
   you

   --20cf307f380654240604c0c37d07
   +96szV6aBDlD/F7vuiK8fUYVknMQPfPmPNikB+fdYLvbwsv9duz6HQaDuwhGn6dh9w2U
   1sABcykpdyfWqWhLt5RzCqppYr5I4yCmB1CNOKwhlzI/w8Sx1QTzGT32G/ERTlbr91BM VmNQ==

I have manage to get the output but it is not working if the sender send fewer than 3 lines as the output will print out the footer of the email as well (because it is between the range of head -10). 我已经设法获得了输出,但是如果发件人发送的行数少于3行,则它将无法正常工作,因为输出也将打印出电子邮件的页脚(因为它位于标题-10的范围内)。

I only want the body of the email to be filter (print out in text file) in the procmail. 我只希望在procmail中过滤电子邮件的正文(以文本文件形式打印出来)。 Is it possible?Can anyone show me the way?I'm in my wits ends.Thanks 有可能吗?有人可以给我指路吗?我机智结束了。

Attempting to treat a MIME multipart as just a lump of text is fraught with peril. 尝试将MIME内容视为一小段文本充满了危险。 In order to properly process the body, you should use a MIME-aware tool. 为了正确处理正文,您应该使用支持MIME的工具。 But if you just want to assume that the first part is a text part and drop all other parts, you can create something fairly simple and robust. 但是,如果只想假设第一部分是文本部分并删除所有其他部分,则可以创建相当简单且健壮的内容。

# Truncate everything after first body part:
# Change second occurrence of --$MATCH to --$MATCH--
# and trim anything after it
:0fb
* ^Content-type: multipart/[a-z]+; boundary="\/[^"]+
| sed -e "1,/^--$MATCH$/b" -e "/^--$MATCH$/!b" -e 's//&--/' -eq

For elegance points, you might be able to develop the script to implement your 10-line body truncation action at the same time, but at least, this should hopefully get you started. 对于优雅点,您可以开发脚本以同时执行10行身体截断动作,但是至少,这有望使您入门。 (I would switch to awk or Perl at this point.) (此时我将切换到awk或Perl。)

:0fb
* ^Content-type: multipart/[a-z]+; boundary="\/[^"]+
| awk -v "b=--$MATCH" ' \
    ($0 == b || $0 == b "--") && seen++ { printf "%s--\n", $0; exit } \
    !seen || p++ < 10'

Properly, the MIME part's headers should not count towards the line count. 正确地,MIME部分的标头不应计入行数。

This is slightly speculative; 这有点投机; I assume by "footer" you mean the ugly base64-encoded attachment after the first body part, and of course, this recipe will do nothing at all for single-part messages. 我以“页脚”为基础,假设您的意思是在正文的第一部分之后加上丑陋的base64编码的附件,当然,对于单部分消息,此配方完全不起作用。 Maybe you want to fall back to your original recipe for those. 也许您想退回原来的食谱。

Recently had a similar issue and solved it with this (adapted to OP)... 最近有一个类似的问题,并对此进行了解决(适用于OP)...

#trying to take out input from the body
:0fb
| sed -n '/^Content-Type/,/^--/ { /^Content-Type/b; /^--/b; p }'

Explanations: in general form.... 说明:一般形式。

sed -n '/begin/,/end/ { /begin/b; /end/b; p }'

-n:         --> turn printing off
/begin/     --> begin of pattern range (remainder commands only apply inside range)
,/end/      --> , end of sed pattern range
{ /begin/b; --> /b branch causes lines with pattern /begin/ to skip remaining commands
/end/b;     --> (same as above), these lines will skip the upcoming (p)rint command
p }'        --> prints lines that in pattern that made it to this command

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM