diff options
author | Werner Koch <[email protected]> | 2025-05-30 12:55:12 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2025-05-30 12:55:12 +0000 |
commit | 982f45c8c7c64b914b3737ddb864076ff51d1b2f (patch) | |
tree | 1c47722c1f542b12cac5483336885dda58e2a5b5 | |
parent | tools: Add a quoted-printable encoding function. (diff) | |
download | gnupg-982f45c8c7c64b914b3737ddb864076ff51d1b2f.tar.gz gnupg-982f45c8c7c64b914b3737ddb864076ff51d1b2f.zip |
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
-rw-r--r-- | doc/Makefile.am | 3 | ||||
-rw-r--r-- | doc/mail-tube.de.txt | 38 | ||||
-rw-r--r-- | doc/mail-tube.txt | 38 | ||||
-rw-r--r-- | doc/tools.texi | 6 | ||||
-rw-r--r-- | tools/gpg-mail-tube.c | 48 |
5 files changed, 128 insertions, 5 deletions
diff --git a/doc/Makefile.am b/doc/Makefile.am index 35ea94b1d..6d52de830 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -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 \ diff --git a/doc/mail-tube.de.txt b/doc/mail-tube.de.txt new file mode 100644 index 000000000..f5931ac22 --- /dev/null +++ b/doc/mail-tube.de.txt @@ -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. +. diff --git a/doc/mail-tube.txt b/doc/mail-tube.txt new file mode 100644 index 000000000..49fe29223 --- /dev/null +++ b/doc/mail-tube.txt @@ -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. +. diff --git a/doc/tools.texi b/doc/tools.texi index 7186c362a..45f3e897d 100644 --- a/doc/tools.texi +++ b/doc/tools.texi @@ -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: diff --git a/tools/gpg-mail-tube.c b/tools/gpg-mail-tube.c index 0133e9d81..7c3c6d0e3 100644 --- a/tools/gpg-mail-tube.c +++ b/tools/gpg-mail-tube.c @@ -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" |