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.
Avatar
Ming Su
Associate Professor of Environmental Engneering

My research interest is water quality problems in drinking water bodies, with a focus on harmful algal blooms and associated taste & odor problems.

Related

Next
Previous
comments powered by Disqus