From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <thomas.monjalon@6wind.com>
Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43])
 by dpdk.org (Postfix) with ESMTP id 400712A5D
 for <ci@dpdk.org>; Thu, 15 Dec 2016 00:05:30 +0100 (CET)
Received: by mail-wm0-f43.google.com with SMTP id a197so136964425wmd.0
 for <ci@dpdk.org>; Wed, 14 Dec 2016 15:05:30 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=6wind-com.20150623.gappssmtp.com; s=20150623;
 h=from:to:subject:date:message-id:in-reply-to:references;
 bh=Ets8I0sSxFMwfKs+03ub8XdSISipA6iiHw4uKcOxodM=;
 b=vZCXQ3UukAkJ1IkghDuACBvE26Xh2XYzo7etjZ5ZxoJkGKCVUUJgGr2yfhjKqqgTiu
 yk+0XAzQWi3CJ0t0N73Qg/2d6pmU5OCdCZzf7kN09TdBztC41g2/4npwBGpeVp8Hh1tO
 DMVL/H+aX7WVvx9Mk1oc7WGFCSczAZABLxVgBDX9NBjdiI3sx7H4Pii97du8JnUxQxmI
 QLdWmmHleKeY1xQqNlf/DP5pqJuA5fgR/G8LhvoYL2ifXPovMCE6ulWtEd5Mk3LWwOpU
 76821CZ9mcnsYQ/jjIqMvta9ohoebhbyH7u5aNVd38YpBLThb5ZEP3S8QQF3/m8jP9RM
 ih5w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
 :references;
 bh=Ets8I0sSxFMwfKs+03ub8XdSISipA6iiHw4uKcOxodM=;
 b=o7w5XwXd7EXvFT7VnYXhBLgJZTH/28+vm5a4jDI3emTL7R8ZVGnTy9C6Xxj/66wYtr
 czMfLJmgA4K27D4ZWToD+YM2WqLqmiR5rdzbr9IAFtIDLb52PcKb7dZV80nD4XPrVE43
 X4/5C0aQZ23F2gn3j8YqTyYR4sglKTt/QzfvYfA8NJjvi6YTzsDsBNf/eEABUYtr98Yo
 3TqF30WhzNjZdsqheXFAiwuEW9A+mTJMJiRXhhqv5h7NPTSBFJodAhuErH6jJvjOq+fN
 Ac6RphCvP8UiFgO9ImQX3w10GaQTj8pSfEh3AuiErO6Ngc0u3kSbCeROvmzZoD098kgv
 F+7g==
X-Gm-Message-State: AKaTC01ko26cnfSI46+nCrPPWHVJQGKOowxc76zxyCYTO14DCqJyK6emm4e+XoPVRYVSgRPC
X-Received: by 10.28.189.69 with SMTP id n66mr9386512wmf.35.1481756729658;
 Wed, 14 Dec 2016 15:05:29 -0800 (PST)
Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184])
 by smtp.gmail.com with ESMTPSA id v2sm69378887wja.41.2016.12.14.15.05.28
 for <ci@dpdk.org>
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Wed, 14 Dec 2016 15:05:29 -0800 (PST)
From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: ci@dpdk.org
Date: Thu, 15 Dec 2016 00:05:15 +0100
Message-Id: <1481756723-4868-2-git-send-email-thomas.monjalon@6wind.com>
X-Mailer: git-send-email 2.7.0
In-Reply-To: <1481756723-4868-1-git-send-email-thomas.monjalon@6wind.com>
References: <1480944373-10233-1-git-send-email-thomas.monjalon@6wind.com>
 <1481756723-4868-1-git-send-email-thomas.monjalon@6wind.com>
Subject: [dpdk-ci] [PATCH v5 1/9] tools: add mail filter
X-BeenThere: ci@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK CI discussions <ci.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/ci>,
 <mailto:ci-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/ci/>
List-Post: <mailto:ci@dpdk.org>
List-Help: <mailto:ci-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/ci>,
 <mailto:ci-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 14 Dec 2016 23:05:30 -0000

This script acts as a pipe which blocks non-patch emails.
It can be used as a first filter before processing a patch.

Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
 README                      |   8 ++++
 tools/filter-patch-email.sh | 111 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+)
 create mode 100755 tools/filter-patch-email.sh

diff --git a/README b/README
index b4bf001..806ce8f 100644
--- a/README
+++ b/README
@@ -44,3 +44,11 @@ The sender must be trusted (whitelisted) by dpdk.org.
 
 If a report has the format of a "per-patch" test,
 it is automatically integrated in patchwork.
+
+
+Scripts help
+------------
+
+Some scripts in this repository (dpdk-ci) may help to build a test.
+
+Their purpose and options are described when using the option -h.
diff --git a/tools/filter-patch-email.sh b/tools/filter-patch-email.sh
new file mode 100755
index 0000000..821786f
--- /dev/null
+++ b/tools/filter-patch-email.sh
@@ -0,0 +1,111 @@
+#! /bin/sh -e
+
+# BSD LICENSE
+#
+# Copyright 2016 6WIND S.A.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+#   * Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#   * Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#   * Neither the name of 6WIND S.A. nor the names of its
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+print_usage () {
+	cat <<- END_OF_HELP
+	usage: $(basename $0) < email
+
+	Filter out email from stdin if does not match patch criterias.
+	END_OF_HELP
+}
+
+while getopts h arg ; do
+	case $arg in
+		h ) print_usage ; exit 0 ;;
+		? ) print_usage ; exit 1 ;;
+	esac
+done
+
+if [ -t 0 ] ; then
+	echo 'nothing to read on stdin' >&2
+	exit 0
+fi
+
+fifo=/tmp/$(basename $0 sh)$$
+mkfifo $fifo
+trap "rm -f $fifo" INT EXIT
+
+parse ()
+{
+	gitsend=false
+	patchsubject=false
+	content=false
+	linenum=0
+	minusline=false
+	plusline=false
+	atline=false
+	binary=false
+	done=false
+	while IFS= read -r line ; do
+		printf '%s\n' "$line"
+		set -- $line
+		if ! $content ; then
+			[ "$1" != 'X-Mailer:' -o "$2" != 'git-send-email' ] || gitsend=true
+			if echo "$line" | grep -qa '^Subject:.*\[PATCH' ; then
+				subject=$(echo "$line" | sed 's,^Subject:[[:space:]]*,,')
+				while [ -n "$subject" ] ; do
+					echo "$subject" | grep -q '^\[' || break
+					if echo "$subject" | grep -q '^\[PATCH' ; then
+						patchsubject=true
+						break
+					fi
+					subject=$(echo "$subject" | sed 's,^[^]]*\][[:space:]]*,,')
+				done
+			fi
+			[ -n "$line" ] || content=true
+		elif ! $done ; then
+			$gitsend || $patchsubject || break
+			[ "$1" != '---' ] || minusline=true
+			[ "$1" != '+++' ] || plusline=true
+			[ "$1" != '@@' ] || atline=true
+			[ "$1 $2 $3" != 'GIT binary patch' ] || binary=true
+			if ($minusline && $plusline && $atline) || $binary ; then
+				echo 1 >$fifo
+				done=true
+				cat
+				break
+			fi
+			linenum=$(($linenum + 1))
+			[ $linenum -lt 999 ] || break
+		fi
+	done
+	$done || echo 0 >$fifo
+	exec >&-
+}
+
+waitparsing ()
+{
+	result=$(cat $fifo)
+	[ "$result" = 0 ] || cat
+}
+
+parse | waitparsing
-- 
2.7.0