我如何才能为 mutt 中的唯一特定收件人进行 GPG 加密?

Spa*_*awk 5 mutt

我正在尝试设置一个发送挂钩,以便在发送给特定收件人时启用 gpg 加密,但如果它也发送给其他收件人,则禁用加密。但是,当特定收件人在收件人列表中的任何位置时,发送挂钩似乎会触发,而不管其他人是否在场。

理想情况下,如果转到 ,我会加密foo@bar.com,但如果转到 ,则不会加密foo@bar.com, not@this.com, or@whatever.com。笨蛋手册

当发生多个匹配时,[send-hook] 命令按照它们在 muttrc 中指定的顺序执行。

因此,我将以下内容放入我的 muttrc.conf 文件中。如果邮件发送到foo@bar.com,则启用自动加密。但是,如果收件人不是foo@bar.com,则取消设置自动加密。

send-hook . unset crypt_autoencrypt
send-hook "!~l ~t ^foo@bar\\.com$" "set crypt_autoencrypt"
send-hook "!~l !~t ^foo@bar\\.com$" "unset crypt_autoencrypt"
Run Code Online (Sandbox Code Playgroud)

但是,它似乎不起作用。似乎发送钩子似乎并没有分别解析每个单独的收件人。即使我将邮件发送到foo@bar.com, not@this.com,mutt也会尝试对其进行加密。

解决方法

我可以通过一个非常丑陋的黑客来解决这个问题。

send-hook . unset crypt_autoencrypt
send-hook "!~l ~t ^foo@bar\\.com$" "set crypt_autoencrypt"
send-hook "!~l ~t [^r]\\.com$" "unset crypt_autoencrypt"
Run Code Online (Sandbox Code Playgroud)

如果我将电子邮件发送到前面.com有非r字符的地址,则它不会加密。显然有很多…r.com地址不是foo@bar.com,所以我必须按如下方式扩展第三行。

send-hook "!~l ~t '([^r]\\.com|[^a]r\\.com)$" "unset crypt_autoencrypt"
Run Code Online (Sandbox Code Playgroud)

这也排除…r.coma前面带有非字符的地址。我只是再重复几次这个序列。

这样做的主要问题是发送钩子似乎不会为 cc: 地址触发,如果电子邮件是 cc:ed to ,则整个第三行都没有实际意义not@this.com

Spa*_*awk 1

在 muttrc 中,使用

set crypt_opportunistic_encrypt = yes
Run Code Online (Sandbox Code Playgroud)

$ man 5 muttrc

crypt_opportunistic_encrypt
      Type: boolean
      Default: no

      Setting this variable will cause Mutt to automatically enable
      and disable encryption, based on whether all message recipient
      keys can be located by mutt.

      When this option is enabled, mutt will determine the encryption
      setting each time the TO, CC, and BCC lists are edited.  If
      $edit_headers is set, mutt will also do so each time the
      message is edited.

      While this is set, encryption settings can't be manually
      changed.  The pgp or smime menus provide an option to disable
      the option for a particular message.

      If $crypt_autoencrypt or $crypt_replyencrypt enable encryption
      for a message, this option will be disabled for the message.  It
      can be manually re-enabled in the pgp or smime menus.  (Crypto
      only)
Run Code Online (Sandbox Code Playgroud)

这还会检查 cc:ed 地址的有效性。不幸的是,根据倒数第二段,这会覆盖许多有用的设置。例如,我有set pgp_autoinline = yes,它已被弃用,但对于发送到不支持 PGP/MIME 的旧客户端1是必需的。

1例如Android的K-9 + APG。据我所知,这是唯一一款可以读取 PGP 加密电子邮件的 FOSS Android 电子邮件客户端,但只能以有限的方式读取。(编辑:K-9 + openkeychain 现在支持 PGP/MIME。)