Skip to content

Instantly share code, notes, and snippets.

@pi3ch
Created May 14, 2012 05:59
Show Gist options
  • Select an option

  • Save pi3ch/2692062 to your computer and use it in GitHub Desktop.

Select an option

Save pi3ch/2692062 to your computer and use it in GitHub Desktop.
Access mutt attachment remotely
#!/bin/sh
# muttattch.sh
# This script handle all the attachment type in mutt and forward to
# a netcat on port 8083 to view on the remote/local system
# in mutt open attachment and in remote system open localhost.
TEMP="/tmp/muttattch"
PORT=8083
rm -f $TEMP
mkfifo --mode=600 $TEMP
# netcat is the fun part of this script.
# -l: listen for an incoming connection
# -q 1: wait 1s after EOF and quit
nc -q 1 -l $PORT < $TEMP &> /dev/null &
# send the HTTP headers, followed by a blank line.
echo "HTTP/1.1 200 OK" >> $TEMP
echo "Server: pi3ch/netcat (mutt)" >> $TEMP
echo "Cache-Control: no-cache" >> $TEMP
echo "Pragma: no-cache" >> $TEMP
echo -n "Content-type: " >> $TEMP
file -bni $1 2> /dev/null >> $TEMP
echo -n "Content-Length: " >> $TEMP
wc -c<$1 >> $TEMP
echo >> $TEMP
echo "Pragma: no-cache" >> $TEMP
echo -n "Content-type: " >> $TEMP
file -bni $1 2> /dev/null >> $TEMP
echo -n "Content-Length: " >> $TEMP
wc -c<$1 >> $TEMP
echo >> $TEMP
# Get started sending the file...
cat $1 >> $TEMP &
# Progress bar
# Fire up your browser now!
sleep 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment