cgit

commit 786609bd36c07b85dbf905fc8c36eba7132122d7

Author: Jason A. Donenfeld <Jason@zx2c4.com>

filter: add page source to email filter

Since the email filter is called from lots of places, the script might
benefit from knowing the origin. That way it can modify its contents
and/or size depending.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

 cgitrc.5.txt | 15 ++++++++-------
 filter.c | 3 +++
 filters/email-gravatar.lua | 2 +-
 filters/email-gravatar.py | 2 ++
 ui-commit.c | 4 ++--
 ui-log.c | 2 +-
 ui-refs.c | 6 +++---
 ui-tag.c | 2 +-


diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index b7dc5a4ca665e092a7f5f03a9f749fccd02984b1..6a926aa922fe3d556b3933ebc6d663a8ecac7bff 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -121,9 +121,9 @@ email-filter::
 	Specifies a command which will be invoked to format names and email
 	address of committers, authors, and taggers, as represented in various
 	places throughout the cgit interface. This command will receive an
-	email address as its only command line argument, and the text to
-	format on STDIN. It is to write the formatted text back out onto
-	STDOUT. Default value: none. See also: "FILTER API".
+	email address and an origin page string as its command line arguments,
+	and the text to format on STDIN. It is to write the formatted text back
+	out onto STDOUT. Default value: none. See also: "FILTER API".
 
 embedded::
 	Flag which, when set to "1", will make cgit generate a html fragment
@@ -620,10 +620,11 @@ 	be filtered is available on standard input and the filtered text is
 	expected on standard output.
 
 email filter::
-	This filter is given a single parameter: the email address of the
-	relevent user. The filter will then receive the text string to format
-	on standard input and is expected to write to standard output the
-	formatted text to be included in the page.
+	This filter is given two parameters: the email address of the relevent
+	author and a string indicating the originating page. The filter will
+	then receive the text string to format on standard input and is
+	expected to write to standard output the formatted text to be included
+	in the page.
 
 source filter::
 	This filter is given a single parameter: the filename of the source




diff --git a/filter.c b/filter.c
index 08ce7a5a021a598bc304f42d3760ac9eda0bfefa..aa36026a0434d500e5fe33f4e37671833b819e1b 100644
--- a/filter.c
+++ b/filter.c
@@ -406,6 +406,9 @@ 		colon = NULL;
 
 	switch (filtertype) {
 		case EMAIL:
+			argument_count = 2;
+			break;
+
 		case SOURCE:
 		case ABOUT:
 			argument_count = 1;




diff --git a/filters/email-gravatar.lua b/filters/email-gravatar.lua
index 8a5344794ac7a8575b44e1b1d65c8e996f887858..982e03098c9e25421f6366564a7099c4d6f2bcef 100644
--- a/filters/email-gravatar.lua
+++ b/filters/email-gravatar.lua
@@ -9,7 +9,7 @@ --
 
 require("crypto")
 
-function filter_open(email)
+function filter_open(email, page)
 	buffer = ""
 	md5 = crypto.digest("md5", email:sub(2, -2):lower())
 end




diff --git a/filters/email-gravatar.py b/filters/email-gravatar.py
index 44456155fedd7801d5ae85bb1ae282350fcd4e31..f90b87de3183ddb05ed6767c828de59cef03bd0a 100755
--- a/filters/email-gravatar.py
+++ b/filters/email-gravatar.py
@@ -27,6 +27,8 @@         email = email[1:]
 if email[-1] == '>':
         email = email[0:-1]
 
+page = sys.argv[2]
+
 md5 = hashlib.md5(email.encode()).hexdigest()
 text = sys.stdin.read().strip()
 




diff --git a/ui-commit.c b/ui-commit.c
index bd14ef04c7772da30f5f67457da9f457dd3f1c83..c48bfe88fb7966c763e36a37d2a654a776e517d3 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -44,7 +44,7 @@
 	cgit_print_diff_ctrls();
 	html("<table summary='commit info' class='commit-info'>\n");
 	html("<tr><th>author</th><td>");
-	cgit_open_filter(ctx.repo->email_filter, info->author_email);
+	cgit_open_filter(ctx.repo->email_filter, info->author_email, "commit");
 	html_txt(info->author);
 	if (!ctx.cfg.noplainemail) {
 		html(" ");
@@ -55,7 +55,7 @@ 	html("");
 	cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
 	html("</td></tr>\n");
 	html("<tr><th>committer</th><td>");
-	cgit_open_filter(ctx.repo->email_filter, info->committer_email);
+	cgit_open_filter(ctx.repo->email_filter, info->committer_email, "commit");
 	html_txt(info->committer);
 	if (!ctx.cfg.noplainemail) {
 		html(" ");




diff --git a/ui-log.c b/ui-log.c
index 957d887f0c7b5c17fd1b67697baf29ccd6ffc7ca..499534c1a8b359833576392e582aba0d4171986e 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -168,7 +168,7 @@ 	cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
 			 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
 	show_commit_decorations(commit);
 	html("</td><td>");
-	cgit_open_filter(ctx.repo->email_filter, info->author_email);
+	cgit_open_filter(ctx.repo->email_filter, info->author_email, "log");
 	html_txt(info->author);
 	cgit_close_filter(ctx.repo->email_filter);
 




diff --git a/ui-refs.c b/ui-refs.c
index d125459f81264230a6a4422a22321b3375aff518..147b66563382fb8c7140a1243f423610afa25281 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -77,7 +77,7 @@
 	if (ref->object->type == OBJ_COMMIT) {
 		cgit_commit_link(info->subject, NULL, NULL, name, NULL, NULL, 0);
 		html("</td><td>");
-		cgit_open_filter(ctx.repo->email_filter, info->author_email);
+		cgit_open_filter(ctx.repo->email_filter, info->author_email, "refs");
 		html_txt(info->author);
 		cgit_close_filter(ctx.repo->email_filter);
 		html("</td><td colspan='2'>");
@@ -157,12 +157,12 @@ 		cgit_object_link(obj);
 	html("</td><td>");
 	if (info) {
 		if (info->tagger) {
-			cgit_open_filter(ctx.repo->email_filter, info->tagger_email);
+			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "refs");
 			html_txt(info->tagger);
 			cgit_close_filter(ctx.repo->email_filter);
 		}
 	} else if (ref->object->type == OBJ_COMMIT) {
-		cgit_open_filter(ctx.repo->email_filter, ref->commit->author_email);
+		cgit_open_filter(ctx.repo->email_filter, ref->commit->author_email, "refs");
 		html_txt(ref->commit->author);
 		cgit_close_filter(ctx.repo->email_filter);
 	}




diff --git a/ui-tag.c b/ui-tag.c
index adbdb90e3771b566e808b56629bffb78d0334aa3..c1d173836357a017538db1dd7028b265acc04895 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -77,7 +77,7 @@ 			html("\n");
 		}
 		if (info->tagger) {
 			html("<tr><td>tagged by</td><td>");
-			cgit_open_filter(ctx.repo->email_filter, info->tagger_email);
+			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
 			html_txt(info->tagger);
 			if (info->tagger_email && !ctx.cfg.noplainemail) {
 				html(" ");