]>
diplodocus.org Git - nmh/blob - etc/rmmproc.messageid
3 # rmmproc.messageid -- tries to back up a message/file to a file that's
4 # named based on Message ID
6 # This code is Copyright (c) 2013, by the authors of nmh.
7 # See the COPYRIGHT file in the root directory of the nmh
8 # distribution for complete copyright information.
10 # If called on a message, the current directory is the
11 # message folder and $1 is the message filename.
12 # If called on a file, $1 is the full path to the file.
14 # The backup directory will be:
15 # 1) If input is a message, the folder of the message.
16 # 2) If input is a file, the directory of the file.
17 # 3) If input is standard input (-), the user's MHPATH directory.
19 # The backup filename will be:
20 # 1) Message-ID with all / and \ converted to periods.
21 # Message-IDs should not contain \, but some
22 # filesystems can't handle them. Message-IDs should
23 # be unique, so there should be no need to backup a
24 # file with the same name, especially if the result of
25 # malicious action. If the backup file already
27 # NOTE: conversion of some characters in the filename
28 # could result in an unintended name collision. If
29 # that is a concern, a program that uses mktemp(3) to
30 # create a temporary file might be the basis for a
33 # 2) Concatenation of BACKUP_PREFIX and input filename.
34 # NOTE: if a file of that name already exists in the
35 # destination directory, it will be overwritten by the
41 #### Input is stdin; put backup in user's MHPATH directory.
43 #### If Path is relative, prepend home directory.
44 [ `dirname "$dir"` = .
] && dir
="$HOME/$dir"
49 #### Extract first Message-Id, remove <>, substitute / and \.
51 /^$/q; /^[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:/!d
52 s/>.*//; s/.*<//; y#/\\\#..#; p
55 if [ "$messageid" -a ! -f "$dir/$messageid" ]; then
56 filename
="$dir/$messageid"
58 filename
="$dir"/`mhparam sbackup``basename "$1"`
61 #### If unable to backup the message, exit with status 1.