简体   繁体   English

基于Procmail变量的条件

[英]Procmail variable based if condition

I am running procmail recipe that would trigger some of my applications the moment I receive a specific email. 我正在运行procmail食谱,当我收到一封特定的电子邮件时,该食谱将触发我的一些应用程序。 I have the whole thing working but now I need to build conditions into the recipe as to not make it run again and again as to avoid multiple instances of the same program since I have procmail trigger every 10minutes. 我已经完成了所有工作,但是现在我需要在配方中建立条件,以免使其一次又一次地运行,以避免同一程序的多个实例,因为我每隔10分钟就会触发一次procmail。 Problem is i'm not exactly sure how 'if' sentences are made in procmail. 问题是我不确定在procmail中如何制作“如果”句子。

Here is the recipe I have so far: 这是我到目前为止的食谱:

:0
* ^Subject: .*Email Subject!
| export DISPLAY=:0.0; 
  xrandr --size 1360x768;\
  firefox "link"; \
  timeout 10s recordmydesktop --fps 30; \
  xrandr --size 1366x768

The easy and idiomatic way to have a critical section in Procmail is to use a lock file. 在Procmail中具有关键部分的简单且惯用的方法是使用锁定文件。

# Notice the second colon and the name of the lock file to use
:0:firefox.lock
* ^Subject: .*Email Subject!
| export DISPLAY=:0.0; 
  xrandr --size 1360x768;\
  firefox "link"; \
  timeout 10s recordmydesktop --fps 30; \
  xrandr --size 1366x768

This will create $MAILDIR/firefox.lock when the recipe is evaluated, and remove it when the recipe finishes. 在评估配方时,这将创建$MAILDIR/firefox.lock ,并在配方完成时将其删除。 If the file already exists, Procmail will wait until it disappears, or eventually time out (which could cause the incoming message to bounce). 如果文件已经存在,Procmail将等待,直到其消失或最终超时(这可能导致传入的邮件反弹)。

If you need a critical section spanning multiple recipes, you can assign to the "magical" variable LOCKFILE and set it to an empty value when you are done. 如果需要跨越多个配方的关键部分,则可以将其分配给“魔术”变量LOCKFILE并在完成LOCKFILE其设置为空值。

LOCKFILE=firefox.lock

# ... Your recipes here ...

LOCKFILE=

(Obscurely, the equals sign on the last line of this example is optional; but I recommend against that usage.) (显然,此示例最后一行的等号是可选的;但我建议您不要使用该用法。)

See man 5 procmailrc for (much) more, including LOCKSLEEP and LOCKTIMEOUT . 有关更多信息,请参见man 5 procmailrc ,包括LOCKSLEEPLOCKTIMEOUT

The trivial answer to "how to say 'if' in Procmail" is to use a condition. 对于“如何在Procmail中说'if'”的简单回答是使用条件。 You already have one; 您已经有一个; the action will only trigger if the message's headers match the regular expression ^Subject:.*Email Subject! 邮件标题与正则表达式^Subject:.*Email Subject!匹配时,该操作才会触发^Subject:.*Email Subject! . You can nest these conditions, test variables, external commands, etc. Here's a silly made-up example to demonstrate them all. 您可以嵌套这些条件,测试变量,外部命令等。这是一个愚蠢的示例,以演示所有内容。

# If $FOO is set and non-empty
:0
* FOO ?? .
{
    # ... then enter this nested block
    # Does $HOME/bar exist?
    :0
    * ? test -e $HOME/bar
    barista

    # Otherwise, unconditionally deliver to foolish
    :0
    foolish
}

The block is entered if the variable FOO is set. 如果设置了变量FOO则输入该块。 Procmail uses your environment variables, so you can set it before invoking Procmail (depending on Procmail's options; it will only inherit a sanitized copy of your environment by default) or on its command line as well as in your recipe file. Procmail使用您的环境变量,因此您可以在调用Procmail之前进行设置(取决于Procmail的选项;默认情况下,它将仅继承环境的已清理副本)或在其命令行以及配方文件中进行设置。

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

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