On 02Jan2015 09:07, Cameron Simpson <c...@zip.com.au> wrote:
Finally, the matching procmailrc recipe (untested) to use in your own
procmail recipes:
:0whf
* from:.*<sed-us...@yahoogroups.com>
| fix-dkim-from

On 31Dec2014 17:09, Eliana <elianasema...@gmail.com> wrote:
I see you said the above is untested, but I am thinking: Why can't the above be as follows, so all yahoogroups lists would qualify for the recipe?

:0whf
* from:.*<.*@yahoogroups.com>
| fix-dkim-from

As Eliana points out, the guard on the rule should be as wide as is suitable. But a guard is needed because the script itself presumes it is being given a header needing unmangling, so it may mangle other messages if you let it.

Eliana also provided me some headers from other lists with the same issue but different From: and other headers.

In particular, some of those lists do not keep enough in the From: header but _do_ provide another header with the original premangling From: content. In those examples, that ewas named "X-Original-From:".

Therefore I have done the following:

 - made "fix-dkim-from" a little more flexible to cope with some
   of the examples from other non-yahoo lists

 - made a different script named "fix-dkim-from-swap" which swaps out the
   "From:" header for the "X-Original-From:" header to handle the
   other examples; this script will optionally accept an argument
   naming the other header if it is not "X-Original-From:".

Therefore, the example procmailrc recipes not look like this:

 # DKIM messages which can be drectly unmangled
 :0whf
 * ^from:.*<.*@yahoogroups.com>
 | fix-dkim-from

 # DKIM messages which provide the old From: header in another header
 :0whf
 * ^from:.*<otherl...@otherdomain.example.com>
 | fix-dkim-from-swap

I've attached the updated and new scripts to this message, but in case they get stripped they can be fetched here:

 https://bitbucket.org/cameron_simpson/css/src/tip/bin/fix-dkim-from
 https://bitbucket.org/cameron_simpson/css/src/tip/bin/fix-dkim-from-swap

The "Raw" link towards the top right should get you the raw source. Note that there are some bare TAB characters in the sed script regexps.

Cheers,
Cameron Simpson <c...@zip.com.au>

I couldn't think of anything else to do with it, so I put it on the web.
#!/usr/bin/sed -nf
#
# Fix up the From: lines of messages which have passed through a
# DKIM verifying mailing list such as (gah!) all of Yahoo's ones.
#
# They unilaterally decided to introduce this and as fallout they
# could not leave the From: lines alone like any sane mailing list.
# Fortunately, the mangled lines look like this:
#
#  From: "full name local@domain [sed-users]" <sed-us...@yahoogroups.com>
# or:
#  From: "local@domain [sed-users]" <sed-us...@yahoogroups.com>
#
# This can readily be undone and converted into:
#
#  From: "full name" <local@domain>
# or:
#  From: <local@domain>
#
# leaving the message ready for use.
#
# In my mailfiler tool I have these rules:
#
#   
from:s/"(?P<fullname>.*\S)\s+(?P<coreaddr>\S+@\S+)\s+\[sed-users\]".*<sed-us...@yahoogroups.com>/"$fullname"
 <$coreaddr>/
#                           sender:sed-us...@yahoogroups.com
#                           from:/<sed-us...@yahoogroups.com>
#   
from:s/"(?P<coreaddr>\S+@\S+)\s+\[sed-users\]".*<sed-us...@yahoogroups.com>/<$coreaddr>/
#                           sender:sed-us...@yahoogroups.com
#                           from:/<sed-us...@yahoogroups.com>
#   sh      SedUsers        
to,cc,sender,x-apparently-to:sed-us...@yahoogroups.com
#
# Gory, but it rewrites the From: lines on the sed-users list and
# then files the message in my "sh" folder. There are two s/this/that/
# rules there, one for "full name local@domain" and one for just
# "local@domain".
#
# The sed script below does the same as an external tool for use
# with systems like procmail. Note that you need know that the
# message is suitable to be unmangled, so you will need to phrase the
# procmail rule along these lines:
#
#  :0whf
#  * from:.*<sed-us...@yahoogroups.com>
#  | fix-dkim-from
#
# Hoping this helps,
#   - Cameron Simpson <c...@zip.com.au> 31dec2014
#

:top

# save the first line to the hold space
1{
  h
  d
}

# append continuation lines to the hold space
/^[     ]/{
  H
  d
}

# save current line to hold space, pull back saved line
x

# rewrite the From: line to undo the from-mangling
/^[Ff][Rr][Oo][Mm]:/{

  y/    / /
  y/\n/ /

  # trim list name from @yahoogroups.com messages
  s/  *\[[^\]*]*\]" \(<[^@>]*@yahoogroups\.com>\)/" \1/

  # replace "full name local@domain" <listname@blah>
  s/"\(.*[^ ]\)  *\([^ ][^ ]*@[^ ][^ ]*\)" *<[^@>]*@[^@>]*>/"\1" <\2>/
  t done
  # replace "local@domain" <listname@blah>
  s/"\([^ ][^ ]*@[^ ][^ ]*\)" *<[^@>]*@[^@>]*>/<\1>/
  :done
}

p

# last line; retrieve saved line and print it
${
  x
  p
}
#!/bin/sh
#
# A different DKIM fixup from fix-dkim-from.
#
# fix-dkim-from works for lists where the original From: information
# is preserved in a quotes string in the mangled From: header.
#
# fix-dkim-from-swap is for lists where (arguably more sensibly)
# the original from header has been renamed to (by default)
# X-Original-From:. We just swap them around.
#   - Cameron Simpson <c...@zip.com.au> 02jan2015
#

set -ue

# a basic regular expression matching the former From: header name
otherfrom_re=X-Original-From

cmd=$(basename "$0")
usage="Usage: $cmd [orig-hdr-name-re] <dkim-headers >fixed-headers
  Default orig-hdr-name-re: $otherfrom_re"

badopts=

while [ $# -gt 0 ]
do
  case "$1" in
    -*) echo "$cmd: unrecognised option: $1" >&2
        badopts=1
        ;;
    *)  break ;;
  esac
  shift
done

if [ $# -gt 0 ]
then
  otherfrom_re=$1
  shift
  case "$otherfrom_re" in
    */*)
      echo "$cmd: slash (/) characters forbidden in orig-hdr-name-re: 
$otherfrom_re" >&2
      badopts=1
      ;;
  esac
  if [ $# -gt 0 ]
  then
    echo "$cmd: extra arguments after orig-hdr-name-re: $*" >&2
    badopts=1
  fi
fi

[ $badopts ] && { echo "$usage" >&2; exit 2; }

sed -e "s/^[Ff][Rr][Oo][Mm]:/X-Old-&/
        t done
        s/^$otherfrom_re:/From:/
        :done"

Reply via email to