简体   繁体   English

在procmail处理之后/之前清洁文本邮件,以便打印该邮件

[英]Cleaning a text-mail after/before a procmail process in order to have a print of that mail

I've to clean some mails in order to print only their body with procmail : 我必须清理一些邮件,以便仅使用procmail打印它们的正文:

:0: # printing mail with bb in the subject to bbprinter
* ^Subject:.*bb
| lpr -Pbbprinter

How should I make that ? 我该怎么做?

Any idea-help welcome 任何想法-帮助欢迎

Your question is ill-defined in a number of ways. 您的问题在很多方面都不清楚。 What do you mean by "clean"? “干净”是什么意思? What do you mean by "body"? “身体”是什么意思?

If you mean, how can I send just the RFC5322 body, not the headers, to the printer, that's easy: 如果您是说,如何将RFC5322正文而不是标题发送到打印机,这很容易:

:0b
* ^Subject:.*bb
| lpr -Pbbprinter

Notice the b flag there after the :0 , which restricts the scope of the action to just the body. 注意:0后面的b标志,它将动作的范围限制为仅主体。

But with MIME, you frequently don't actually want the RFC5322 body (that is, everything after the last header line) but rather only one part out of a MIME multipart message. 但是,对于MIME,您通常实际上实际上并不想要RFC5322正文(即,最后一个标头行之后的所有内容),而实际上只是想要MIME多部分消息中的一部分。 You would need to come up with some analysis of which part to extract, but if you have that, it's still easy: 您需要对要提取的部分进行一些分析,但是如果有的话,这仍然很容易:

:0
* ^Subject:.*bb
| parse-out-preferred-mime-body-part | lpr -Pbbprinter

(We don't use :0b here because a proper MIME parser needs access to the top-level RFC5322 headers, too.) (我们在这里不使用:0b ,因为正确的MIME解析器也需要访问顶级RFC5322标头。)

If by "clean" you mean something else, or in addition, you will have to clarify your question, but the general idea is something like 如果“干净”是指其他意思,或者另外,您必须澄清您的问题,但总体思路是:

:0
* ^Subject:.*bb
| cleanupbody | lpr -Pbbprinter

where cleanupbody could perform whatever you mean by "cleanup" (blot out curse words? Fix common typos? More or less the same thing?) 在这里cleanupbody可以执行您cleanupbody的“ cleanup”(清除诅咒字词?解决常见的错字?或多或少是同一件事?)。

Finally, just to wrap up, you can basically pipe to a shell script of any complexity (although by the time it spans more than a few lines, you are probably better off moving all or parts of it to a separate script, perhaps with a test suite of its own). 最后,作为总结,您基本上可以通过管道传递到任何复杂的shell脚本(尽管当它跨越多行时,最好将其全部或部分移至单独的脚本中,也许使用测试套件)。

:0
* ^Subject:.*bb
| parse-out-preferred-mime-body-part | \
  sed -e 's/grammer/grammar/g' -e 's/seperate/separate/g' \
      -e 's/definately/definitely/g' | \
  lpr -Pbbprinter

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

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