From: Tristan Chabredier Date: Sat, 30 Sep 2006 09:34:17 +0000 (+0000) Subject: 2006-09-30 [wwp] 2.5.2cvs23 X-Git-Tag: rel_2_6_0~94 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=23170423c38b53fc5adad661b19138e004babc8b 2006-09-30 [wwp] 2.5.2cvs23 * tools/fix_date.sh Fixed a minor bug in date value extraction, added a switch to replace non RFC-compliant Date: value, added a switch to use strict RFC matching patterns for dates. --- diff --git a/ChangeLog b/ChangeLog index f17db233e..09538aff3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-09-30 [wwp] 2.5.2cvs23 + + * tools/fix_date.sh + Fixed a minor bug in date value extraction, added a switch + to replace non RFC-compliant Date: value, added a switch + to use strict RFC matching patterns for dates. + 2006-09-29 [colin] 2.5.2cvs22 * src/matcher_parser.h diff --git a/PATCHSETS b/PATCHSETS index fa4a09bb7..41e68398f 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -1936,3 +1936,4 @@ ( cvs diff -u -r 1.1.4.33 -r 1.1.4.34 src/gtk/gtksctree.c; cvs diff -u -r 1.1.4.9 -r 1.1.4.10 src/gtk/gtksctree.h; ) > 2.5.2cvs20.patchset ( cvs diff -u -r 1.65.2.49 -r 1.65.2.50 src/codeconv.c; cvs diff -u -r 1.96.2.151 -r 1.96.2.152 src/textview.c; ) > 2.5.2cvs21.patchset ( cvs diff -u -r 1.4.2.4 -r 1.4.2.5 src/matcher_parser.h; cvs diff -u -r 1.25.2.17 -r 1.25.2.18 src/matcher_parser_parse.y; cvs diff -u -r 1.59.2.49 -r 1.59.2.50 src/prefs_filtering.c; cvs diff -u -r 1.5.2.10 -r 1.5.2.11 src/statusbar.c; cvs diff -u -r 1.15.2.34 -r 1.15.2.35 src/summary_search.c; cvs diff -u -r 1.395.2.257 -r 1.395.2.258 src/summaryview.c; cvs diff -u -r 1.1.2.45 -r 1.1.2.46 src/gtk/quicksearch.c; cvs diff -u -r 1.1.2.7 -r 1.1.2.8 src/gtk/quicksearch.h; ) > 2.5.2cvs22.patchset +( cvs diff -u -r 1.1.2.2 -r 1.1.2.3 tools/fix_date.sh; ) > 2.5.2cvs23.patchset diff --git a/configure.ac b/configure.ac index 13cec78c2..15abab34c 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=5 MICRO_VERSION=2 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=22 +EXTRA_VERSION=23 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/tools/fix_date.sh b/tools/fix_date.sh index 3611d6723..08997ccbd 100644 --- a/tools/fix_date.sh +++ b/tools/fix_date.sh @@ -7,9 +7,7 @@ # If no X-Original-Date already exist, the former Date value will be set # in such field. -# TODO: add a switch to replace only non RFC-compliant Date: headers - -VERSION="0.0.3" +VERSION="0.0.4" function version() @@ -25,19 +23,36 @@ function usage() 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 " --force always force (re-)writing of Date: header" + echo " --rfc force re-writing of Date: header when it's not RFC-compliant" echo " --debug turn on debug information (be more verbose)" + echo " --strict use RFC-strict matching patterns for dates" echo " -- end of switches (in case a filename starts with a -)" exit $1 } +function date_valid() +{ + test $STRICT -eq 1 && \ + REGEXP="$DATE_REGEXP_STRICT" || \ + REGEXP="$DATE_REGEXP" + + echo "$1" | grep -qEim 1 "$REGEXP" + DATE_VALID=$? +} -# use --force to always write the Date header -# otherwise, the Date header will be written if only it doesn't already -# exist +# use --force to always (re-)write the Date header +# otherwise, the Date header will be written if only it doesn't exist FORCE=0 +# use --rfc to (re-)write the Date header when it's not RFC-compliant +# otherwise, the Date header will be written if only it doesn't exist +RFC=0 # use --debug to display more information about what's performed DEBUG=0 +# use --strict to use strict matching patterns for date validation +STRICT=0 +# 0 = valid, always valid until --strict is used, then date_valid overrides this value +DATE_VALID=0 while [ -n "$1" ] do @@ -46,6 +61,8 @@ do --version) version;; --force) FORCE=1;; --debug) DEBUG=1;; + --rfc) RFC=1;; + --strict) STRICT=1;; --) shift break;; -*) echo "error: unrecognized switch '$1'" @@ -55,11 +72,20 @@ do shift done +if [ $FORCE -eq 1 -a $RFC -eq 1 ] +then + echo "error: use either --force or --rfc, but not both at the same time" + usage 1 +fi + test $# -lt 1 && \ usage 1 TMP="/tmp/${0##*/}.tmp" +DATE_REGEXP="( (Mon|Tue|Wed|Thu|Fri|Sat|Sun),)? [0-9]+ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dev) [0-9]+ [0-9]+:[0-9]+:[0-9}+ [-+][0-9]+" +DATE_REGEXP_STRICT="(Mon|Tue|Wed|Thu|Fri|Sat|Sun), [0-9]+ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dev) [0-9]+ [0-9]+:[0-9]+:[0-9}+ [-+][0-9]+" + while [ -n "$1" ] do # skip if file is empty or doesn't exist @@ -69,11 +95,11 @@ do 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) - RECEIVED_DATE=$(grep -Eim 1 ';( (Mon|Tue|Wed|Thu|Fri|Sat|Sun),)? [0-9]+ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dev) [0-9]+ [0-9]+:[0-9]+:[0-9}+ [-+][0-9]+' "$1" | cut -d ';' -f 2) -# strict, day of week needed -# RECEIVED_DATE=$(grep -Eim 1 '; (Mon|Tue|Wed|Thu|Fri|Sat|Sun), [0-9]+ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dev) [0-9]+ [0-9]+:[0-9]+:[0-9}+ [-+][0-9]+' "$1" | cut -d ';' -f 2) + X_ORIGINAL_DATE=$(grep -Eim 1 '^X-Original-Date: ' "$1" | cut -d ':' -f 2-) + DATE=$(grep -Eim 1 '^Date: ' "$1" | cut -d ':' -f 2-) + test $STRICT -eq 1 && \ + RECEIVED_DATE=$(grep -Eim 1 ";$DATE_REGEXP" "$1" | cut -d ';' -f 2) || \ + RECEIVED_DATE=$(grep -Eim 1 "; $DATE_REGEXP_STRICT" "$1" | cut -d ';' -f 2) FILE_DATE=$(ls -l --time-style="+%a, %d %b %Y %X %z" "$1" | tr -s ' ' ' ' | cut -d ' ' -f 6-11) # we could also use the system date as a possible replacement #SYSTEM_DATE="$(date -R)" @@ -106,6 +132,8 @@ do fi # replace/set the date and write all lines + test $RFC -eq 1 && \ + date_valid "$DATE" if [ -z "$DATE" ] then test $DEBUG -eq 1 && \ @@ -119,9 +147,23 @@ do 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" + if [ $RFC -eq 1 ] + then + if [ $DATE_VALID -ne 0 ] + then + test $DEBUG -eq 1 && \ + echo "$1: date already found but not RFC-compliant, replacing with $REPLACEMENT" + sed "s/^Date: .*/Date:$REPLACEMENT_DATE/" "$1" >> "$TMP" + else + test $DEBUG -eq 1 && \ + echo "$1: date already found and RFC-compliant, skipping" + cat "$1" >> "$TMP" + fi + else + test $DEBUG -eq 1 && \ + echo "$1: date already found, skipping" + cat "$1" >> "$TMP" + fi fi fi