#!/bin/bash
# Author: Andreas Herrmann <andreas.herrmann3@amd.com>
#
# Look up message-id at MARC (http://marc.info).
#
# The script tries to find the message-id at MARC.
# So on success you'll get an URL that you can refer to
# when mailing with people that aren't subscribed to certain
# mailing lists.
#
# Read http://marc.info/?l=linux-kernel&m=118235886512436 for more info.
#
# Works with mutt(ng) but might be usable for other
# configurable mail clients as well.
#
# Installation and mutt(ng) configuration is as follows:
#
# (1) Install the script such that it is in your command search path.
# (2) Add following key binding to your mutt(ng) config file:
#
#	macro pager M ":set pipe_decode<enter>|show-mail.sh<enter>:unset pipe_decode<enter>"
#
# Pressing "M" within the pager will now call the below script.
#
# Note:	You have to show the Message-ID in the pager. So either show it by
#	default via
#		unignore message-id
#	or do a display-toggle-head with "h" before the script is called.

clear
while read data
  do
  echo $data | grep -i -q "^message-id:"
  if [ $? -eq 0 ]
      then
      mid=`echo $data | awk '{ print $2 }'`
  fi
done

if [ -n "$mid" ]
then
    echo firefox "http://marc.info/?i=$mid"
    firefox "http://marc.info/?i=$mid"
else
    echo "no Message-ID found"
fi
