#!/bin/sh
# @(#) mutt_expires_editor $Revision: 1.4 $
# mutt_expires_editor - edit messages to add or modify the Expires: header
#
# Written by Gary Johnson (2003-12-20)
# This script is intended to be invoked from a mutt macro such as the
# following. (Thanks to Tom Eliaz for suggesting the pager version that
# marks the newly-edited message as read.)
#
# macro index ,E ':set editor=mutt_expires_editor:set editor=vim' "set Expires: header"
# macro pager ,E ':set editor=mutt_expires_editor:set editor=vimN' "set Expires: header"
#
# It prompts the user for a date which it then includes in an "Expires:"
# header which it inserts into the header of the message whose file name
# was given as the argument to the script. The date may be given in any
# of several forms, including short forms such as "Tuesday" for next
# Tuesday and relative forms such as "today" and "next month". The
# special date "never" will remove the "Expires:" header from the
# message, and hitting without entering a date will use a
# default date.
#
# Mutt's ~E flag can then be used in patterns to limit, color, or
# otherwise identify or manipulate messages that have expired.
#
# The script requires the GNU version of the date(1) program, and
# formail, distributed with procmail.
# Adapted from the mutt-expires-editor script written by Oman Wild to
# accompany his patch-1.5.0.ow.edit-expires.4 which was posted to the
# mutt-dev list on 5 February 2002. The default date and "never"
# features were contributed by Tom Eliaz.
default_date="today + 20 days"
file=$1
tmp_file=$file.$$
echo "Expiry date [$default_date, \"never\" to remove]: \c" # For HP-UX and SunOS.
#echo -n "Expiry date [$default_date, \"never\" to remove]: " # For GNU/Linux.
read date
# Typing (usually ^D) will exit.
if [ $? -ne 0 ]
then
exit 2
fi
# Typing with no date will use the default date.
if [ "$date" = "" ]
then
date="$default_date"
fi
# The special date "never" will remove the Expires: header.
if [ "$date" = "never" ]
then
formail -i "Expires:" < $file > $tmp_file
mv $tmp_file $file
else
rfc822_date=$(date -R -d "$date")
# Only edit the message if the date is valid.
if [ "$rfc822_date" != "" ]
then
formail -i "Expires: $rfc822_date" < $file > $tmp_file
mv $tmp_file $file
fi
fi