X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/8002bbc34d5e87334b7f9811a6829afaebdb9573..f5bfa5864d2feef66948fde764c376b7a9f8b839:/etc/rmmproc.messageid diff --git a/etc/rmmproc.messageid b/etc/rmmproc.messageid index 3bb7cad2..e23882c6 100755 --- a/etc/rmmproc.messageid +++ b/etc/rmmproc.messageid @@ -1,62 +1,61 @@ #! /bin/sh ## - # rmmproc.messageid -- tries to back up a message/file to a file that's - # named based on Message ID + # 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 a message, the current directory is the - # message folder and $1 is the message filename. - # If called on a file, $1 is the full path to the file. + # 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 a message, the folder of the message. - # 2) If input is a file, the directory of the file. + # 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. # - # The backup filename will be: + # 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 + # 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 mktemp(3) to - # create a temporary file might be the basis for a - # remedy. - # + # 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. - # + # NOTE: if a file of that name already exists in the destination + # directory, it will be overwritten by the mv below. ## -if [ "$1" = - ]; 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 "$1"` -fi +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/.*, substitute / and \. -messageid=`sed -n ' - /^$/q; /^[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:/!d - s/>.*//; s/.*