对于初学者,您可以使用这样的宏来自动跳转到新消息:
macro index .n "<next-unread-mailbox><enter><next-new-then-unread><enter>" "Go to new mail"
但是请注意,如果没有新消息,则仅Enter
按键,然后将打开当前消息。
作为替代方案,如果Maildir
使用,我们可以使用一个~/bin/mutt-new.sh
脚本来检查是否有新邮件:
#!/usr/bin/env sh
if [ "$(find "$HOME"/.muttmail/box1/new -type f -printf '\n' | wc -l)" -eq 0 ]
then
printf "I think there's no new mail\n" >&2
printf "Press [ENTER] to continue\n" >&2
read -r _
exit 1
fi
echo 'push <next-unread-mailbox><enter><next-new-then-unread><enter>'
将此添加到~/.muttrc
:
macro index .n "!~/bin/mutt-new.sh" "Go to new"
编辑:
怎么做:以下脚本将首先检查当前邮箱中是否有新邮件:
#!/usr/bin/env sh
cur_mbox=${1/=/}
echo "$1" >> /tmp/PAR
echo "$cur_mbox" >> /tmp/PAR
if [ ! "$(find "$HOME"/.muttmail/"$cur_mbox"/new -type f -printf '\n' | wc -l)" -eq 0 ]
then
printf "There is new mail in this mailbox\n" >&2
printf "Press [ENTER] to continue\n" >&2
read -r _
echo 'push <next-new-then-unread><enter>'
elif [ ! "$(find "$HOME"/.muttmail/ -type d -name new -exec ls {} \; | wc -l)" -eq 0 ]
then
printf "There is new mail in other mailboxes\n" >&2
printf "Press [ENTER] to continue\n" >&2
read -r _
echo 'push <next-unread-mailbox><enter><next-new-then-unread><enter>'
else
printf "I think there's no new mail\n" >&2
printf "Press [ENTER] to continue\n" >&2
read -r _
exit 1
fi
将此添加到~/.muttrc
:
folder-hook . 'set my_oldrecord=$record; set record=^; set my_folder=$record; set record=$my_oldrecord'
folder-hook . 'macro index .n "<enter-command>source \"~/bin/mutt-new.sh $my_folder |\"<return>" "Go to new"'
编辑:
你说:
无论如何,这不是最佳选择,因为如果我有新消息,请退出mutt,然后再次打开mutt,这不会使我进入包含“新”消息的邮箱。(假定邮箱不再未读。)
可以通过以下方法解决此问题:
set mark_old=no
<next-unread-mailbox>
不管当前邮箱中是否有未读邮件,它都将运行。在这种情况下,它将切换到另一个邮箱,而不打开当前邮箱中的下一条未读邮件。另一个问题(按照我的问题)是<next-unread-mailbox>
不查找未读/新邮件,而是查找未读邮箱。