简体   繁体   English

procmail 如果不存在,则创建一个新文件夹,其中包含收件人地址的名称

[英]procmail create a new folder if not exist with name of recipient address

Can someone explain how to get the send to mail address with procmail and extract all up to @example.com and then create a new folder with the name?有人可以解释如何使用 procmail 获取发送到邮件地址并将所有内容提取到@example.com,然后使用该名称创建一个新文件夹吗?

Example: I collect all mail in one account so the addresses hello@example.com and welcome@example.com and so on are in the same account.示例:我在一个帐户中收集所有邮件,因此地址 hello@example.com 和welcome@example.com 等在同一帐户中。

Now I want to create a subfolder with the recipient name eg hello and welcome as soon as i receive a mail to this address.现在我想创建一个带有收件人名称的子文件夹,例如 hello 和welcome,一旦我收到发送到该地址的邮件。

My problem is that I just get the sender's address... but I like to get the recipient address.我的问题是我只是得到发件人的地址……但我喜欢得到收件人的地址。

In this post Automatic procmail filter based on username someone explains how to get senders address;在这篇基于用户名的自动 procmail 过滤器中,有人解释了如何获取发件人地址; how can I adapt that to my scenario?我该如何适应我的场景?

If your MTA exposes this information in eg the Delivered-To: header, this is easy enough to extract.如果您的 MTA 在例如Delivered-To:标头中公开此信息,则很容易提取。

:0:
* ^Delivered-to:[   ]*<?\/[^ <>@    ]+
$MATCH

As usual in Procmail, the whitespace inside [ ] should consist of one space and one literal tab character.在 Procmail 中, [ ]的空白应该由一个空格和一个文本制表符组成。 The regex [^ <>@ ]+ matches as many characters as possible which are not space, < , > , @ , or tab.正则表达式[^ <>@ ]+匹配尽可能多的非空格、 <>@或制表符的字符。

This extracts text from the Delivered-To: header up to just before @ and stores that in MATCH by way of the special \\/ token;这从Delivered-To:标题中提取文本直到@之前,并通过特殊的\\/标记将其存储在MATCH then the value of this variable is used as the destination folder to save the message to.然后此变量的值用作将消息保存到的目标文件夹。

It's not clear if you intend for "folder" to mean a mailbox (such as a Berkeley mbox file) or a directory.不清楚您打算将“文件夹”表示为邮箱(例如 Berkeley mbox 文件)还是目录。 In the latter case, remove the second colon, and perhaps add a mkdir if you want to create a maildir structure if it doesn't already exist.在后一种情况下,删除第二个冒号,如果您想创建一个不存在的 maildir 结构,可以添加一个mkdir

Be aware that this is extremely brittle.请注意,这是非常脆弱的。 In the general case, there is no reliable, portable way to make sure that the recipient address is exposed like this.在一般情况下,没有可靠的、可移植的方法来确保收件人地址像这样公开。 If an incoming message was Bcc: ed to both welcome and hello , chances are you will get nothing, or two messages, or just one or the other.如果传入的消息是Bcc: ed 到welcomehello ,你很可能什么也得不到,或者两条消息,或者只有一条消息。 This is a common FAQ;这是一个常见的FAQ; see also http://www.iki.fi/era/procmail/mini-faq.html#bcc另见http://www.iki.fi/era/procmail/mini-faq.html#bcc

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

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