防止 mutt 发送缺少附件的电子邮件

Prevent mutt sending email with missing attachments

在发送带附件的电子邮件时,我偶尔会忘记附加相关文件。

如何设置 mutt and vim 以提示我附加丢失的文件?

CheckAttach vim plugin by Christian Brabandt 将检查邮件消息中的关键字并要求您附加文件。该插件将不考虑邮件中引用的部分。

该插件将突出显示关键字并提示您输入 保存邮件时要附加的文件。

看起来像这样:

Attach file: (leave empty to abort):

在该提示符下,您可以指定要附加的任何文件。它允许 文件名完成,因此您可以使用 <Tab> 让 vim 完成文件路径。 此外,您可以指定 glob 模式并让 vim 附加所有文件,即 匹配模式。如果您输入一个空值或“n”(没有 引号),则不会附加任何文件。

安装:

获取最近的 plugin package from the vim site.

然后在命令提示符下 运行,

vim CheckAttach-0.17.vmb

并获取 vim 脚本:

:so %

也可以从GitHub中查看代码。

配置:

edit_headers 必须在您的 .muttrc 中设置。这会启用 pseudo-header :Attach。有关详细信息,请参阅 muttrc 手册页。

要指定要搜索的关键字,请将以下内容添加到您的 .vimrc

let g:attach_check_keywords = 'attached,attachment'

替代用法:

该插件还定义了 vim 命令 :AttachFile。这使您可以 使用 glob 模式附加任意数量的文件。

要附加来自 ~/pictures/ 的所有 png 文件:

 :AttachFile ~/pictures/*.png

mutt 和 neomutt 有配置选项 abort_noattach 如果邮件正文与 设置的正则表达式匹配,mutt 和 neomutt 会在发送邮件前询问您缺少附件abort_noattach_regexp。在 neomutt 中,该选项称为 abort_noattach_regex,没有尾随 p。但是 mutt 配置变体也应该起作用,因为它是一个配置同义词 - 请参阅 code.

您可以在 muttrc(5) 或 neomuttrc(5) 联机帮助页中找到更多相关信息。

笨蛋

3.1. abort_noattach
Type: quadoption
Default: no

When the body of the message matches $abort_noattach_regexp and there are no attachments, this quadoption controls whether to abort sending the message.

3.2. abort_noattach_regexp
Type: regular expression
Default: “attach”

Specifies a regular expression to match against the body of the message, to determine if an attachment was mentioned but mistakenly forgotten. If it matches, $abort_noattach will be consulted to determine if message sending will be aborted.

Like other regular expressions in Mutt, the search is case sensitive if the pattern contains at least one upper case letter, and case insensitive otherwise.

Neomutt

3.3. abort_noattach
Type: quadoption
Default: no

If set to yes , when composing messages containing the regular expression specified by $abort_noattach_regex and no attachments are given, composition will be aborted. If set to no , composing messages as such will never be aborted.

Example:

set abort_noattach_regex = "\<attach(|ed|ments?)\>"

3.4. abort_noattach_regex
Type: regular expression
Default: “ <(attach|attached|attachments?)> ”

Specifies a regular expression to match against the body of the message, to determine if an attachment was mentioned but mistakenly forgotten. If it matches, $abort_noattach will be consulted to determine if message sending will be aborted.

Like other regular expressions in NeoMutt, the search is case sensitive if the pattern contains at least one upper case letter, and case insensitive otherwise.