/usr/share/doc/nmh/examples/rmmproc.messageid is in nmh 1.7.1~RC3-1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #! /bin/sh
##
# rmmproc.messageid -- tries to back up each message/file to a file
# that's named based on Message ID
#
# This code is Copyright (c) 2013, by the authors of nmh.
# See the COPYRIGHT file in the root directory of the nmh
# distribution for complete copyright information.
#
# If called on messages, the current directory is the message folder
# and the script arguments are the message filenames. If called on
# files, the arguments are the full paths to the files.
#
# The backup directory will be:
# 1) If input is messages, the folder of the messages.
# 2) If input is files, the directories of the files.
# 3) If input is standard input (-), the user's MHPATH directory.
#
# Each backup filename will be:
# 1) Message-ID with all / and \ converted to periods.
# Message-IDs should not contain \, but some filesystems can't
# handle them. Message-IDs should be unique, so there should be
# no need to backup a file with the same name, especially if the
# result of malicious action. If the backup file already
# exists, use 2).
# NOTE: conversion of some characters in the filename could
# result in an unintended name collision. If that is a concern,
# a program that uses mkstemp(3) to create a temporary file might
# be the basis for a remedy.
# 2) Concatenation of BACKUP_PREFIX and input filename.
# NOTE: if a file of that name already exists in the destination
# directory, it will be overwritten by the mv below.
##
for i in "$@"; do
if [ "$i" = - ]; then
#### Input is stdin; put backup in user's MHPATH directory.
dir=`mhparam path`
#### If Path is relative, prepend home directory.
[ `dirname "$dir"` = . ] && dir="$HOME/$dir"
else
dir=`dirname "$i"`
fi
#### Extract first Message-Id, remove <>, substitute / and \.
messageid=`sed -n '
/^$/q; /^[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:/!d
s/>.*//; s/.*<//; y#/\\\#..#; p
' "$i"`
if [ "$messageid" -a ! -f "$dir/$messageid" ]; then
filename="$dir/$messageid"
else
#### `mhparam sbackup` is usually ',' but depends on configuration.
filename="$dir"/`mhparam sbackup``basename "$i"`
fi
mv "$i" "$filename" || status=1
done
exit $status
|