diff --git a/sympa/recipe/sympa_fix_personalization.recipe b/sympa/recipe/sympa_fix_personalization.recipe index f74f1ea..6e3f7ec 100644 --- a/sympa/recipe/sympa_fix_personalization.recipe +++ b/sympa/recipe/sympa_fix_personalization.recipe @@ -27,39 +27,23 @@ function patch_message_pm { /opt/miaou-bash/tools/append_or_replace '^.*qw/subject x-originating-ip message-id date x-original-to.*$' ' qw/subject x-originating-ip message-id date x-original-to x-original-from from to thread-topic content-type/' "$MESSAGE_PM" FOUND=true else - echo 'already patched!' + echo 'x-original-from already patched!' fi - message=$(prepend_2lines_of_text_before_existing_line "$MESSAGE_PM" '$data->{sender} = $self->{sender};' '$data->{gecos} = $self->{gecos};' '$data->{subject} = $self->{decoded_subject};') - echo $message - if [[ $message =~ 'do prepend' ]]; then - echo 'prepending sender and gecos in message pm' + + if [[ $(grep -n '$data->{sender} = $self->{sender};' /usr/share/sympa/lib/Sympa/Message.pm | cut -d: -f1) -ne 1540 ]]; then + patch /usr/share/sympa/lib/Sympa/Message.pm << EOF +1539a1540,1541 +> \$data->{sender} = \$self->{sender}; +> \$data->{gecos} = \$self->{gecos}; +EOF FOUND=true + else - echo 'sender and gecos already prepended!' + echo 'sender + gecos already patched!' fi - else - echo "file: $MESSAGE_PM not found!" && exit 11 - fi -} - -## arg1=file, arg2=text, arg3='existing_line' -function prepend_2lines_of_text_before_existing_line { - local file="$1" - local line1="$2" - local line2="$3" - local existing="$4" - [[ ! -f $file ]] && echo "file: $file not found!" && exit 20 - - if ! (grep "^$existing$" $file -B2 | grep -qz "$line1.*$line2.*$existing"); then - echo 'do prepend' - >&2 echo "line1=$line1" - >&2 echo "line2=$line2" - >&2 echo "existing=$existing" - echo sed -i "/^$existing$/s/^/$line1\n$line2\n/" $file - sed -i "/^$existing$/s/^/$line1\n$line2\n/" $file else - echo 'already done!' + echo "file: $MESSAGE_PM not found!" && exit 11 fi }