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

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

我正在尝试设置一个发送挂钩,以便在发送给特定收件人时启用 gpg 加密,但如果也发送给其他收件人,则禁用加密。然而,当特定的收件人被发送时,发送钩子似乎会被触发。任何地方在收件人列表中,无论其他人在场。

理想情况下,如果它转到 ,我会加密[email protected],但如果转到 ,我不会加密。杂种狗[email protected], [email protected], [email protected]手动的

当出现多个匹配时,[send-hook] 命令按照 muttrc 中指定的顺序执行。

因此,我将以下内容放入我的 muttrc 中。如果邮件发送至[email protected],则启用自动加密。但是,如果存在非 收件人[email protected],则取消设置自动加密。

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"

然而,它似乎不起作用。看来发送挂钩似乎没有单独解析每个单独的收件人。即使我将邮件发送至,mutt 也会尝试对其进行加密。[email protected], [email protected]

解决方法

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

send-hook . unset crypt_autoencrypt
send-hook "!~l ~t ^foo@bar\\.com$" "set crypt_autoencrypt"
send-hook "!~l ~t [^r]\\.com$" "unset crypt_autoencrypt"

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

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

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

主要问题是 send-hooks 似乎不会针对 cc: 地址触发,如果电子邮件被 cc:ed to ,则整个第三行就毫无意义了[email protected]

答案1

在 muttrc 中,使用

set crypt_opportunistic_encrypt = yes

$ 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)

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

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

相关内容