diff --git a/NEWS b/NEWS index 32f3c84d..bb31a50e 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,7 @@ Noteworthy changes in version 1.7.0 (unreleased) [C25/A14/R_] GPGME_STATUS_NOTATION_FLAGS NEW. GPGME_DATA_TYPE_PGP_ENCRYPTED NEW. GPGME_DATA_TYPE_PGP_SIGNATURE NEW. + GPGME_DATA_ENCODING_MIME NEW. Noteworthy changes in version 1.6.0 (2015-08-26) [C25/A14/R0] diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 87322b09..c514ff82 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -2130,6 +2130,9 @@ scheme as used by @acronym{MIME} and other protocols. This specifies that the data is encoded in an armored form as used by OpenPGP and PEM. +@item GPGME_DATA_ENCODING_MIME +This specifies that the data is encoded as a MIME part. + @item GPGME_DATA_ENCODING_URL The data is a list of linefeed delimited URLs. This is only useful with @code{gpgme_op_import}. diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp index af1c479a..64acb47f 100644 --- a/lang/cpp/src/data.cpp +++ b/lang/cpp/src/data.cpp @@ -146,6 +146,7 @@ GpgME::Data::Encoding GpgME::Data::encoding() const case GPGME_DATA_ENCODING_BINARY: return BinaryEncoding; case GPGME_DATA_ENCODING_BASE64: return Base64Encoding; case GPGME_DATA_ENCODING_ARMOR: return ArmorEncoding; + case GPGME_DATA_ENCODING_MIME: return MimeEncoding; } return AutoEncoding; } @@ -158,6 +159,7 @@ GpgME::Error GpgME::Data::setEncoding(Encoding enc) case BinaryEncoding: ge = GPGME_DATA_ENCODING_BINARY; break; case Base64Encoding: ge = GPGME_DATA_ENCODING_BASE64; break; case ArmorEncoding: ge = GPGME_DATA_ENCODING_ARMOR; break; + case MimeEncoding: ge = GPGME_DATA_ENCODING_MIME; break; } return Error(gpgme_data_set_encoding(d->data, ge)); } diff --git a/lang/cpp/src/data.h b/lang/cpp/src/data.h index d5e54aaa..b2f2173f 100644 --- a/lang/cpp/src/data.h +++ b/lang/cpp/src/data.h @@ -77,7 +77,8 @@ public: AutoEncoding, BinaryEncoding, Base64Encoding, - ArmorEncoding + ArmorEncoding, + MimeEncoding }; Encoding encoding() const; Error setEncoding(Encoding encoding); diff --git a/src/data.c b/src/data.c index 7123a82b..87b619e4 100644 --- a/src/data.c +++ b/src/data.c @@ -193,7 +193,7 @@ gpgme_data_set_encoding (gpgme_data_t dh, gpgme_data_encoding_t enc) "encoding=%i", enc); if (!dh) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); - if (enc < 0 || enc > GPGME_DATA_ENCODING_URL0) + if (enc < 0 || enc > GPGME_DATA_ENCODING_MIME) return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); dh->encoding = enc; return TRACE_ERR (0); diff --git a/src/engine-gpg.c b/src/engine-gpg.c index e279f04b..16571a5a 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -294,6 +294,15 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound) return 0; } + +/* Return true if the engine's version is at least VERSION. */ +static int +have_gpg_version (engine_gpg_t gpg, const char *version) +{ + return _gpgme_compare_versions (gpg->version, version); +} + + static char * gpg_get_version (const char *file_name) @@ -1719,6 +1728,10 @@ gpg_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags, if (!err && (flags & GPGME_ENCRYPT_NO_COMPRESS)) err = add_arg (gpg, "--compress-algo=none"); + if (gpgme_data_get_encoding (plain) == GPGME_DATA_ENCODING_MIME + && have_gpg_version (gpg, "2.1.14")) + err = add_arg (gpg, "--mimemode"); + if (!symmetric) { /* If we know that all recipients are valid (full or ultimate trust) @@ -1779,6 +1792,10 @@ gpg_encrypt_sign (void *engine, gpgme_key_t recp[], if (!err && (flags & GPGME_ENCRYPT_NO_COMPRESS)) err = add_arg (gpg, "--compress-algo=none"); + if (gpgme_data_get_encoding (plain) == GPGME_DATA_ENCODING_MIME + && have_gpg_version (gpg, "2.1.14")) + err = add_arg (gpg, "--mimemode"); + if (!symmetric) { /* If we know that all recipients are valid (full or ultimate trust) @@ -2381,8 +2398,14 @@ gpg_sign (void *engine, gpgme_data_t in, gpgme_data_t out, err = add_arg (gpg, "--detach"); if (!err && use_armor) err = add_arg (gpg, "--armor"); - if (!err && use_textmode) - err = add_arg (gpg, "--textmode"); + if (!err) + { + if (gpgme_data_get_encoding (in) == GPGME_DATA_ENCODING_MIME + && have_gpg_version (gpg, "2.1.14")) + err = add_arg (gpg, "--mimemode"); + else if (use_textmode) + err = add_arg (gpg, "--textmode"); + } } if (!err) diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c index ccda9736..080b3061 100644 --- a/src/gpgme-tool.c +++ b/src/gpgme-tool.c @@ -1876,6 +1876,8 @@ server_data_encoding (const char *line) return GPGME_DATA_ENCODING_URLESC; if (strstr (line, "--url0")) return GPGME_DATA_ENCODING_URL0; + if (strstr (line, "--mime")) + return GPGME_DATA_ENCODING_MIME; return GPGME_DATA_ENCODING_NONE; } diff --git a/src/gpgme.h.in b/src/gpgme.h.in index cdb7037d..49d56c37 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -228,7 +228,8 @@ typedef enum GPGME_DATA_ENCODING_ARMOR = 3, /* Either PEM or OpenPGP Armor. */ GPGME_DATA_ENCODING_URL = 4, /* LF delimited URL list. */ GPGME_DATA_ENCODING_URLESC = 5, /* Ditto, but percent escaped. */ - GPGME_DATA_ENCODING_URL0 = 6 /* Nul delimited URL list. */ + GPGME_DATA_ENCODING_URL0 = 6, /* Nul delimited URL list. */ + GPGME_DATA_ENCODING_MIME = 7 /* Data is a MIME part. */ } gpgme_data_encoding_t;