nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] proposed patch for shell metacharacter failure in nmh-1.7

2018-01-20 11:13:55
So it seems as if your method of storing David's patch, and of quoting
his email to reply to it, have both turned «'\''» into «'''».

That's right.


Hopefully, this is some home-brew script rather than core nmh, but if
it's the latter then we'd like to know.  :-)

It's nothing to do with nmh, and coincidentally I discovered the problem
myself about three days ago during an email discussion of mounting CIFS
shares on Linux.

The culprit was the appended shell script, shown here in its fixed version.
Specifically, the read statements weren't using the -r option.

My signature quotes are chosen at random from a collection, including the
one on this message.  But sometimes the random choice throws up something
appropriate. :-)

     - Steven


8<-----------------------------   cut here   ---------------------------->8
#!/bin/sh
#
#  fixdate -- fix the time zone on a Date: header in an email message
#
#  Steven Winikoff 2012/12/12
#
#  it's annoying to view Date: headers marked in a different time zone;
#  that annoyance wasn't important in a world where invalid time zones were
#  infrequent, but EVERY SINGLE MESSAGE from Concordia's new Exchange
#  servers is stamped in UTC :-(
#
#  usage:  fixdate < message
#
#    where standard input is the mail message to be fixed; the (possibly
#    modified) message will be echoed to standard output
#
#  exit status:  0 if the date was modified, or 1 otherwise
#
#--------------------------------------------------------------------------
#  helper function:  when are two date strings equal? :-)
#
#     normally this would be just a simple text comparison, but some
#     systems present date stamps such as this one:
#
#        Mon, 4 Jun 2012 14:24:06 -0400
#
#     this gets canonicalized by /bin/date as follows:
#
#        Mon, 04 Jun 2012 14:24:06 -0400
#
#     ...and we don't want to bother rewriting the date in this case, so
#     detect and eliminate it:

function samedate()
{
   #-- dispose of the simplest case first :-)

   [ "${1}" = "${2}" ] && return 0


   #-- the next simplest case occurs when the original date has a suffix;
   #   for example, "Tue, 26 Jun 2012 01:13:26 -0400 (EDT)", which should
   #   be treated as equal to "Tue, 26 Jun 2012 01:13:26 -0400"

   truncated="`echo \"${1}\" | cut -c1-31`"

   [ "${truncated}" = "${2}" ] && return 0


   #-- if the day number has no leading zero, these dates are definitely
   #   different:

   possible_zero="`echo \"${2}\" | cut -c6`"
   [ "${possible_zero}" = "0" ] || return 1


   #-- if we're still here, these dates may be identical except for the
   #   leading zero:

   rest="`echo \"${2}\" | cut -c1-5,7-`"
   test "${1}" = "${rest}"
}


#--------------------------------------------------------------------------
#  process message headers, one line at a time:

IFS='
'
while read -r line
do
   #-- have we reached the end of the headers yet?

   if [ -z "${line}" ]
   then
      echo
      break
   fi


   #-- if we're here, this line is a header:

   start="`echo \"${line}\" | cut -c1-6`"
   if [ "${start}" != "Date: " ]
   then
      #-- not a Date: header, so just blat to standard output:

      echo "${line}"
   else
      #-- convert to our time zone:

      old="`echo \"${line}\" | unqp | sed 's/^Date: //'`"
      new="`date -d \"${old}\" -R`"

      if samedate "${old}" "${new}"
      then
         #-- already correct:

         echo "${line}"
      else
         #-- use the new date, but keep the old one also:

         echo "Date: ${new}"
         echo "X-Original-Date: ${old}"
      fi
   fi
done


#--------------------------------------------------------------------------
#  now read and emit the body:

while read -r line
do
   echo "${line}"
done

exit 0
8<-----------------------------   cut here   ---------------------------->8
-- 
___________________________________________________________________________
Steven Winikoff                | "I really hate this dumb machine; I wish
Concordia University           |  that they would sell it.  It never does
Montreal, QC, Canada           |  quite what I mean, but only what I tell
Steven.Winikoff@concordia.ca   |  it!"
                               |                            - fortune(6)

-- 
Nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>