2006-09-21 [wwp] 2.4.0cvs207
authorTristan Chabredier <wwp@claws-mail.org>
Thu, 21 Sep 2006 09:51:40 +0000 (09:51 +0000)
committerTristan Chabredier <wwp@claws-mail.org>
Thu, 21 Sep 2006 09:51:40 +0000 (09:51 +0000)
* tools/fix_date.sh
several fixes and enhancements. A new --force switch has been
added to prevent overriding by default Date: header when
already existing.

ChangeLog
PATCHSETS
configure.ac
tools/fix_date.sh

index 6468efd3465f9b922a0b2912eb608f1ce82c679a..bae80803b0e2bdb586971ccfb06ad6c99aadbf56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-09-21 [wwp]       2.4.0cvs207
+
+       * tools/fix_date.sh
+               several fixes and enhancements. A new --force switch has been
+               added to prevent overriding by default Date: header when
+               already existing.
+
 2006-09-21 [paul]      2.4.0cvs206
 
        * src/common/utils.c
index 2f2b2d2aa1dd5f4316343dc75e625a6321ccf891..0fa0096ce1c071d814c575f08b516a6b67c657b6 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( diff -u /dev/null tools/fix_date.sh;  cvs diff -u -r 1.25.2.10 -r 1.25.2.11 tools/Makefile.am;  ) > 2.4.0cvs204.patchset
 ( cvs diff -u -r 1.25.2.11 -r 1.25.2.12 tools/Makefile.am;  ) > 2.4.0cvs205.patchset
 ( cvs diff -u -r 1.36.2.78 -r 1.36.2.79 src/common/utils.c;  ) > 2.4.0cvs206.patchset
+( cvs diff -u -r 1.1.2.1 -r 1.1.2.2 tools/fix_date.sh;  ) > 2.4.0cvs207.patchset
index 805e92dfa797b5228a1c965e5ff076b0d570b02d..ceaea250ea9ca25422c0202357f6fda73a3f7572 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=4
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=206
+EXTRA_VERSION=207
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 12718415159030243bb29ef0066b30726fa5dbeb..3611d6723d4e7be4ef58edf90324d0d924ea455b 100644 (file)
@@ -7,17 +7,67 @@
 # If no X-Original-Date already exist, the former Date value will be set
 # in such field.
 
-if [ $# -lt 1 ]
-then
-       echo "usage: ${0##*/} <filename> [<filename> ..]"
-       exit 1
-fi
+# TODO: add a switch to replace only non RFC-compliant Date: headers
+
+VERSION="0.0.3"
+
+
+function version()
+{
+       echo "$VERSION"
+       exit 0
+}
+
+function usage()
+{
+       echo "usage:"
+       echo "  ${0##*/} [<switches>] <filename> [<filename> ..]"
+       echo "switches:"
+       echo "  --help     display this help then exit"
+       echo "  --version  display version information then exit"
+       echo "  --force    force writting of Date: header even if it already exists"
+       echo "  --debug    turn on debug information (be more verbose)"
+       echo "  --         end of switches (in case a filename starts with a -)"
+       exit $1
+}
+
+
+# use --force to always write the Date header
+# otherwise, the Date header will be written if only it doesn't already
+# exist
+FORCE=0
+# use --debug to display more information about what's performed
+DEBUG=0
+
+while [ -n "$1" ]
+do
+       case "$1" in
+       --help)         usage 0;;
+       --version)      version;;
+       --force)        FORCE=1;;
+       --debug)        DEBUG=1;;
+       --)                     shift
+                               break;;
+       -*)                     echo "error: unrecognized switch '$1'"
+                               usage 1;;
+       *)                      break;;
+       esac
+       shift
+done
+
+test $# -lt 1 && \
+       usage 1
 
 TMP="/tmp/${0##*/}.tmp"
+
 while [ -n "$1" ]
 do
-       test ! -s "$1" && \
+       # skip if file is empty or doesn't exist
+       if [ ! -s "$1" ]
+       then
+               shift
                continue
+       fi
 
        X_ORIGINAL_DATE=$(grep -Eim 1 '^X-Original-Date: ' "$1" | cut -d ':' -f 2)
        DATE=$(grep -Eim 1 '^Date: ' "$1" | cut -d ':' -f 2)
@@ -31,18 +81,26 @@ do
        # determine which replacement date to use
        if [ -z "$RECEIVED_DATE" ]
        then
-               # don't forget to add the leading whitespace
+               # don't forget the leading whitespace here
                REPLACEMENT_DATE=" $FILE_DATE"
+               REPLACEMENT="file date"
+#              REPLACEMENT_DATE=" $SYSTEM_DATE"
+#              REPLACEMENT="system date"
        else
                REPLACEMENT_DATE="$RECEIVED_DATE"
+               REPLACEMENT="received date"
        fi
 
-       # ensure that a X-Original-Date is set
+       # ensure that a X-Original-Date is set (but don't override it)
        if [ -z "$X_ORIGINAL_DATE" ]
        then
-               test -z "$DATE" && \
-                       echo "X-Original-Date:$REPLACEMENT_DATE" > "$TMP" || \
-                       echo "X-Original-Date:$DATE" > "$TMP"
+               if [ -z "$DATE" ]
+               then
+                       echo "X-Original-Date:$REPLACEMENT_DATE" > "$TMP"
+               else
+                       test $FORCE -eq 1 && \
+                               echo "X-Original-Date:$DATE" > "$TMP"
+               fi
        else
                :> "$TMP"
        fi
@@ -50,10 +108,21 @@ do
        # replace/set the date and write all lines
        if [ -z "$DATE" ]
        then
+               test $DEBUG -eq 1 && \
+                       echo "$1: date not found, using $REPLACEMENT now"
                echo "Date:$REPLACEMENT_DATE" >> "$TMP"
                cat "$1" >> "$TMP"
        else
-               sed "s/^Date: .*/Date:$REPLACEMENT_DATE/" "$1" >> "$TMP"
+               if [ $FORCE -eq 1 ]
+               then
+                       test $DEBUG -eq 1 && \
+                               echo "$1: date already found, replacing with $REPLACEMENT"
+                       sed "s/^Date: .*/Date:$REPLACEMENT_DATE/" "$1" >> "$TMP"
+               else
+                       test $DEBUG -eq 1 && \
+                               echo "$1: date already found, skipping"
+                       cat "$1" >> "$TMP"
+               fi
        fi
 
        # uncomment the following line to backup the original file
@@ -62,7 +131,7 @@ do
        mv -f "$TMP" "$1"
        if [ $? -ne 0 ]
        then
-               echo "error while moving $TMP to $1"
+               echo "error while moving '$TMP' to '$1'"
                exit 1
        fi