Save Attachments to Special Folder in Mutt


Problem: How to save attachments in mutt?

No built-in solution for save multiple attachments to special folder in mutt. I spent couple hours to develop a workflow for doing this.

Solution

  • In muttrc:
macro attach s "<shell-escape>~/.config/mutt/bin/saveattach.sh\n:source /tmp/from\ns" "Save attachment to specific folder"
macro attach S "<shell-escape>~/.config/mutt/bin/saveattach.sh\n:source /tmp/from\ns" "Save attachment to specific folder"
  • Shell script in ~/.config/mutt/bin/saveattach.sh
#!/bin/bash

if [[ -e /tmp/from ]]; then
    rm /tmp/from
fi
echo $HOME"//" > /tmp/from
nvim "+normal G$" +startinsert /tmp/from
path=`cat /tmp/from`
echo $path
if [[ !(-d $path) ]]; then
    mkdir -p $path
fi
echo 'macro attach s "<save-entry><bol>'$path'\n"' > /tmp/from

How to Use

  1. in mutt, goto attachment page, save attach by type s;
  2. nvim will show up with file of /tmp/from
  3. Finish the path in nvim, I use nvim here is because of the path auto completetion feature.
  4. Exit nvim, the select attachment will be save to the specified path automatically, and will go to the next attachment item;
  5. Press s again for saving the following attachments.
苏命
苏命
副研究员

我的研究方向:水源地水质安全保障,主要针对水源地由于藻类爆发引起的水体嗅味问题开展研究。