diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2022-02-16 11:22:25 -0800 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2022-02-16 20:53:40 +0100 |
commit | d6afac3da2792b7ec7ff210ca21821c6f3129879 (patch) | |
tree | ecb6c37bbc3e337766e270d8b761ef6a832bd0ed | |
parent | ce139f9887e5f5403cf2ff367722ac12aa050fea (diff) | |
download | pw-d6afac3da2792b7ec7ff210ca21821c6f3129879.tar.gz |
pw-apply: Fix two issues with author name parsing
Fix few issues with how we extract author name.
1. Handling full name properly regardless whether it consists of two
space-separated words or more (e.g., currently for "Kumar Kartikeya
Dwivedi" we'd extract only "Kumar Kartikeya").
2. Fix extracting *only* author name and not their email regardless if
X-Patchwork-Submitter: tag is single-lined or wrapped. Normally it
would be wrapped for base64-encoded variants so email would end up on
second line and we'd never extract it. Which is good because base64
regexes assume only name and no emails. But in some cases, especially
with quote-printable encoding, like this one:
X-Patchwork-Submitter: =?utf-8?q?Mauricio_V=C3=A1squez?= <mauricio@kinvolk.io>
we'll capture email as part of author name, which is wrong.
Both these problems are fixed now with more elaborate combination of
cutting by spaces and <, and then trimming trailing whitespaces with
awk.
Then also add support for quote-printable encoding which starts with
=?utf-8?q? prefix (as opposed to =?utf-8?b? for base64-encoding). Use
perl single-liner to decode (haven't found other way, qprint cli tool
isn't installed everywhere).
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rwxr-xr-x | pw-apply | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -177,10 +177,13 @@ git checkout master if [ ! -z "$merge" ]; then git merge --stat --log --no-edit --no-ff $branch if [ ! -z "$cover" ]; then - author=`grep 'X-Patchwork-Submitter:' cover.i|cut -f2,3 -d' '` + author=$(grep 'X-Patchwork-Submitter:' cover.i | cut -d' ' -f2- | cut -d'<' -f1 | awk '{$1=$1;print}') if [[ "$author" =~ ^=\?utf-8\?b\?(.*)\?=$ ]]; then # strip away "=?utf-8?b?" prefix and "?=" suffix and base64-decode author=$(echo "${BASH_REMATCH[1]}" | base64 -d) + elif [[ "$author" =~ ^=\?utf-8\?q\?(.*)\?=$ ]]; then + # strip away "=?utf-8?q?" prefix and "?=" suffix and quoted-printable-decode + author=$(echo "${BASH_REMATCH[1]}" | tr '_' ' ' | perl -MMIME::QuotedPrint -0777 -nle 'print decode_qp($_)') fi # Extract cover letter subject, potentially split into two lines branch_name=$(awk '/^\w+: / { subj=0 } /^Subject: / { subj = 1 } subj { print $0 }' cover.i | tr -d '\n' | cut -d']' -f2 | cut -c 2-) |