output asked headers in the order they were asked; avoid header name spoofing by...
[hband-tools.git] / user-tools / fixRFC822filemtime
blob0ed2b97c1b34597cbe2a0820c3fcb814cdfb1dee
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 fixRFC822filemtime - Set a file's last modification time, which contains an email message in RFC-822 format, to the email's Date
10 =cut
12 EOF
15 set -u
16 set -e
18 for file in "$@"
20 if [ -f "$file" ]
21 then
22 if [ "${file:0:1}" != / ]
23 then
24 file=./$file
27 date=`egrep -im1 ^Date: "$file" | cut -f2- -d: | sed -e 's/\r//'`
29 if [ -n "$date" ]
30 then
31 tstamp=`date +%s -d "$date"`
33 if [ -n "$tstamp" ]
34 then
35 touch -t `date +%Y%m%d%H%M.%S -d "@$tstamp"` "$file"
39 done