[Commits] [SCM] claws branch, master, updated. 3.14.0-57-g1b45074

wwp at claws-mail.org wwp at claws-mail.org
Fri Sep 2 00:46:01 CEST 2016


The branch, master has been updated
       via  1b450742d6939bb1bfa76f3b5358bbe520e9fdf6 (commit)
      from  db2ee150ef10f77d1b724a9cdf93df890cafc534 (commit)

Summary of changes:
 src/quote_fmt.c       |    1 +
 src/quote_fmt_lex.l   |    1 +
 src/quote_fmt_parse.y |   31 ++++++++++++++++++++++++++++++-
 3 files changed, 32 insertions(+), 1 deletion(-)


- Log -----------------------------------------------------------------
commit 1b450742d6939bb1bfa76f3b5358bbe520e9fdf6
Author: wwp <wwp at free.fr>
Date:   Fri Sep 2 00:40:27 2016 +0200

    Templates: add a way to attach a file, 'attach_output' or 'A', file whose absolute path+filename
    is the output of a command-line (it s a mix of 'attach' and 'program'). The first line of the
    command-line output is taken into account, trailing newline being stripped down.
    Like 'attach', if the filename is not found or not accessible, CM will raise an error. Like
    'program', if the command-line fails, no error raises but the standard output of CM shows it.

diff --git a/src/quote_fmt.c b/src/quote_fmt.c
index 22fb576..9059290 100644
--- a/src/quote_fmt.c
+++ b/src/quote_fmt.c
@@ -93,6 +93,7 @@ static gchar *quote_desc_strings[] = {
 	"|program{<span style=\"oblique\">sub_expr</span>}\n(|p{<span style=\"oblique\">sub_expr</span>})\n",	N_("insert program output:\n<span style=\"oblique\">sub_expr</span> is evaluated as a command-line to get\nthe output from"), /* insert program output */
 	"|input{<span style=\"oblique\">sub_expr</span>}\n(|i{<span style=\"oblique\">sub_expr</span>})\n",		N_("insert user input:\n<span style=\"oblique\">sub_expr</span> is a variable to be replaced by\nuser-entered text"), /* insert user input */
 	"|attach{<span style=\"oblique\">sub_expr</span>}\n(|a{<span style=\"oblique\">sub_expr</span>})",		N_("attach file:\n<span style=\"oblique\">sub_expr</span> is evaluated as the path of the file to attach"), /* attach file */
+	"|attach_output{<span style=\"oblique\">sub_expr</span>}\n(|A{<span style=\"oblique\">sub_expr</span>})",	N_("attach file:\n<span style=\"oblique\">sub_expr</span> is evaluated as a command-line to get\nthe filename from"), /* attach file whose name's got from program output */
 	"",					NULL,
 	N_("<span weight=\"bold\">definition of terms:</span>"),	NULL,
 	"<span style=\"oblique\">expr</span>\n",			N_("text that can contain any of the symbols or\ncommands above"),
diff --git a/src/quote_fmt_lex.l b/src/quote_fmt_lex.l
index 46c295f..7af7f61 100644
--- a/src/quote_fmt_lex.l
+++ b/src/quote_fmt_lex.l
@@ -152,6 +152,7 @@ int escaped_string = 0;
 ("|p"|"|program") /* insert program output */ return INSERT_PROGRAMOUTPUT;
 ("|i"|"|input") /* insert user input */ return INSERT_USERINPUT;
 ("|a"|"|attach") /* attach file */ return ATTACH_FILE;
+("|A"|"|attach_program") /*  file whose name's got from program output */ return ATTACH_PROGRAMOUTPUT;
 <S_DATE>"{" return OPARENT;
 <S_DATE>"}" { BEGIN S_NORMAL; return CPARENT; }
 <S_NORMAL>"{" return OPARENT;
diff --git a/src/quote_fmt_parse.y b/src/quote_fmt_parse.y
index af7f421..dc330c1 100644
--- a/src/quote_fmt_parse.y
+++ b/src/quote_fmt_parse.y
@@ -560,6 +560,22 @@ static void quote_fmt_attach_file(const gchar *filename)
 	attachments = g_list_append(attachments, g_strdup(filename));
 }
 
+static void quote_fmt_attach_file_program_output(const gchar *progname)
+{
+	FILE *file;
+	char buffer[PATH_MAX];
+
+	if ((file = popen(progname, "r")) != NULL) {
+		/* get first line only */
+		if (fgets(buffer, sizeof(buffer), file)) {
+			/* trim trailing CR/LF */
+			strretchomp(buffer);
+			attachments = g_list_append(attachments, g_strdup(buffer));
+		}
+		pclose(file);
+	}
+}
+
 static gchar *quote_fmt_complete_address(const gchar *addr)
 {
 	gint count;
@@ -641,7 +657,7 @@ static gchar *quote_fmt_complete_address(const gchar *addr)
 %token QUERY_NOT_TO_FOUND_IN_ADDRESSBOOK
 /* other tokens */
 %token INSERT_FILE INSERT_PROGRAMOUTPUT INSERT_USERINPUT
-%token ATTACH_FILE
+%token ATTACH_FILE ATTACH_PROGRAMOUTPUT
 %token OPARENT CPARENT
 %token CHARACTER
 %token SHOW_DATE_EXPR
@@ -1312,4 +1328,17 @@ attach:
 		if (!dry_run) {
 			quote_fmt_attach_file(sub_expr.buffer);
 		}
+	}
+	| ATTACH_PROGRAMOUTPUT
+	{
+		current = &sub_expr;
+		clear_buffer();
+	}
+	OPARENT sub_expr CPARENT
+	{
+		current = &main_expr;
+		if (!dry_run) {
+			quote_fmt_attach_file_program_output(sub_expr.buffer);
+		}
 	};
+;

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list