1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

gpg-mail-tube: Support templates.

* tools/gpg-mail-tube.c: Include i18n.h.
(main): Call i18n.h
(only_ascii): New.
(mail_tube_encrypt): Use a template or fallback to the old version.

* doc/mail-tube.txt, doc/mail-tube.de.txt: Two standard templates.
* doc/Makefile.am (helpfiles): Add them.
--

GnuPG-bug-id: 7381
This commit is contained in:
Werner Koch 2025-05-30 14:55:12 +02:00
parent 61514f7cd8
commit 982f45c8c7
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
5 changed files with 128 additions and 5 deletions

View file

@ -33,7 +33,8 @@ helpfiles = help.txt help.be.txt help.ca.txt help.cs.txt \
help.gl.txt help.hu.txt help.id.txt help.it.txt \
help.ja.txt help.nb.txt help.pl.txt help.pt.txt \
help.pt_BR.txt help.ro.txt help.ru.txt help.sk.txt \
help.sv.txt help.tr.txt help.zh_CN.txt help.zh_TW.txt
help.sv.txt help.tr.txt help.zh_CN.txt help.zh_TW.txt \
mail-tube.txt mail-tube.de.txt
EXTRA_DIST = samplekeys.asc mksamplekeys com-certs.pem \
gnupg-logo.pdf gnupg-logo.png gnupg-logo-tr.png \

38
doc/mail-tube.de.txt Normal file
View file

@ -0,0 +1,38 @@
# mail-tube.txt - gpg-mail-tube strings (de) -*- default-generic -*-
# Written in 2025 by g10 Code GmbH
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this text to the
# public domain worldwide. This text is distributed without any
# warranty. You should have received a copy of the CC0 Public Domain
# Dedication along with this software. If not, see
# <https://creativecommons.org/publicdomain/zero/1.0/>.
# SPDX-License-Identifier: CC0-1.0
#
# Note that this template file needs to be UTF-8 encoded. When looking
# for a template item, GnuPG scans the help files in the following order
# (assuming a standard Unix layout):
#
# /etc/gnupg/TEMPLATE.LL_TT.txt
# /etc/gnupg/TEMPLATE.LL.txt
# /etc/gnupg/TEMPLATE.txt
# /usr/share/gnupg/TEMPLATE.LL_TT.txt
# /usr/share/gnupg/TEMPLATE.LL.txt
# /usr/share/gnupg/TEMPLATE.txt
#
# Here TEMPLATE denotes the name of the template (e.g. "mail-tube"),
# LL_TT denotes the full name of the current locale with the territory
# (.e.g. "de_DE"), LL denotes just the locale name (e.g. "de"). The
# first matching item is returned. To put a dot or a hash mark at the
# beginning of a text line, it needs to be prefixed with a dot and a
# space. A single dot may be used to terminated an entry. Depending
# on the template type certain variables (${NAME}) are expanded.
# Check the man page of the respective tool.
.encrypted-file-attached
Anbei erhalten Sie eine verschlüsselte Datei.
.
.encrypted-mail-attached
Anbei erhalten Sie eine verschlüsselte Mail.
.

38
doc/mail-tube.txt Normal file
View file

@ -0,0 +1,38 @@
# mail-tube.txt - gpg-mail-tube strings (en) -*- default-generic -*-
# Written in 2025 by g10 Code GmbH
#
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this text to the
# public domain worldwide. This text is distributed without any
# warranty. You should have received a copy of the CC0 Public Domain
# Dedication along with this software. If not, see
# <https://creativecommons.org/publicdomain/zero/1.0/>.
# SPDX-License-Identifier: CC0-1.0
#
# Note that this template file needs to be UTF-8 encoded. When looking
# for a template item, GnuPG scans the help files in the following order
# (assuming a standard Unix layout):
#
# /etc/gnupg/TEMPLATE.LL_TT.txt
# /etc/gnupg/TEMPLATE.LL.txt
# /etc/gnupg/TEMPLATE.txt
# /usr/share/gnupg/TEMPLATE.LL_TT.txt
# /usr/share/gnupg/TEMPLATE.LL.txt
# /usr/share/gnupg/TEMPLATE.txt
#
# Here TEMPLATE denotes the name of the template (e.g. "mail-tube"),
# LL_TT denotes the full name of the current locale with the territory
# (.e.g. "de_DE"), LL denotes just the locale name (e.g. "de"). The
# first matching item is returned. To put a dot or a hash mark at the
# beginning of a text line, it needs to be prefixed with a dot and a
# space. A single dot may be used to terminated an entry. Depending
# on the template type certain variables (${NAME}) are expanded.
# Check the man page of the respective tool.
.encrypted-file-attached
Please find attached an encrypted file.
.
.encrypted-mail-attached
Please find attached an encrypted mail.
.

View file

@ -2194,6 +2194,12 @@ The recipients must be plain mail addresses
(e.g. @code{foo@@example.org}) and should in general list the To and
Cc addresses contained in the mail.
The tool needs to insert strings into the mails which can be
configured using a plain text file. The installed default files for
English (@file{mail-tube.txt}) and German (@file{mail-tube.de.txt})
can be copied to the system configuration directory and changed to
local needs. Environment variables in these texts are expanded.
@mansect options
@noindent
@command{gpg-mail-tube} understands these options:

View file

@ -37,6 +37,7 @@
#include "../common/ccparray.h"
#include "../common/mbox-util.h"
#include "../common/zb32.h"
#include "../common/i18n.h"
#include "rfc822parse.h"
#include "mime-maker.h"
@ -256,6 +257,7 @@ main (int argc, char **argv)
log_set_prefix ("gpg-mail-tube", GPGRT_LOG_WITH_PREFIX);
/* Make sure that our subsystems are ready. */
i18n_init(); /* Required for gnupg_get_template. */
init_common_subsystems (&argc, &argv);
/* Parse the command line. */
@ -369,6 +371,18 @@ main (int argc, char **argv)
}
/* Return true if TSRING has only ascii chacrterst or is NULL. */
static int
only_ascii (const char *string)
{
if (string)
for ( ; *string; string++)
if ((*string & 0x80))
return 0;
return 1;
}
/* This function is called by the mail parser to communicate events.
* This callback communicates with the main function using a structure
* passed in OPAQUE. Should return 0 or set errno and return -1. */
@ -549,20 +563,46 @@ mail_tube_encrypt (estream_t fpin, strlist_t recipients)
/* Output the plain or PGP/MIME boilerplate. */
if (opt.as_attach)
{
/* FIXME: Need to have a configurable message here. */
char *templ, *tmpstr;
const char *charset = "us-ascii";
const char *ctencode = "";
templ = gnupg_get_template ("mail-tube",
ct_is_text? "encrypted-file-attached"
: "encrypted-mail-attached",
(GET_TEMPLATE_SUBST_ENVVARS
| GET_TEMPLATE_CRLF));
if (templ && !only_ascii (templ))
{
charset = "utf-8";
ctencode = "Content-Transfer-Encoding: quoted-printable\r\n";
tmpstr = mime_maker_qp_encode (templ);
if (!tmpstr)
{
log_error ("QP encoding failed: %s\n",
gpg_strerror (gpg_error_from_syserror ()));
exit (1);
}
xfree (templ);
templ = tmpstr;
}
es_fprintf (es_stdout,
"\r\n"
"\r\n"
"--=-=mt-%s=-=\r\n"
"Content-Type: text/plain; charset=us-ascii\r\n"
"Content-Type: text/plain; charset=%s\r\n"
"%s"
"Content-Disposition: inline\r\n"
"\r\n"
"Please find attached an encrypted %s.\r\n"
"%s"
"\r\n"
"--=-=mt-%s=-=\r\n",
boundary,
ct_is_text? "file":"message",
charset, ctencode,
templ? templ
: "Please find attached an encrypted file/mail.\r\n",
boundary);
xfree (templ);
if (ct_is_text)
es_fprintf (es_stdout,
"Content-Type: text/plain; charset=us-ascii\r\n"