aboutsummaryrefslogtreecommitdiffstats
path: root/tools/mime-maker.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-09-29 15:38:06 +0000
committerWerner Koch <[email protected]>2016-09-29 15:56:37 +0000
commitf776757ea94542e2f425840dddaf3e65b0ff7757 (patch)
tree91fd42217fe4405291ceeae7f8c8db172437d5a6 /tools/mime-maker.c
parenttools: Change mime-maker to write out CR,LF. (diff)
downloadgnupg-f776757ea94542e2f425840dddaf3e65b0ff7757.tar.gz
gnupg-f776757ea94542e2f425840dddaf3e65b0ff7757.zip
tools: Allow retrieval of signed data from mime-maker.
* tools/mime-maker.c (find_part): New. (mime_maker_get_part): New. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'tools/mime-maker.c')
-rw-r--r--tools/mime-maker.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/mime-maker.c b/tools/mime-maker.c
index 99185cfef..a81bd69c3 100644
--- a/tools/mime-maker.c
+++ b/tools/mime-maker.c
@@ -202,6 +202,22 @@ find_parent (part_t root, part_t needle)
return NULL;
}
+/* Find the part node from the PARTID. */
+static part_t
+find_part (part_t root, unsigned int partid)
+{
+ part_t node, n;
+
+ for (node = root->child; node; node = node->next)
+ {
+ if (node->partid == partid)
+ return root;
+ if ((n = find_part (node, partid)))
+ return n;
+ }
+ return NULL;
+}
+
/* Create a boundary string. Outr codes is aware of the general
* structure of that string (gebins with "=-=") so that
@@ -730,3 +746,54 @@ mime_maker_make (mime_maker_t ctx, estream_t fp)
ctx->outfp = NULL;
return err;
}
+
+
+/* Create a stream object from the MIME part identified by PARTID and
+ * store it at R_STREAM. If PARTID identifies a container the entire
+ * tree is returned. Using that function may read stream objects
+ * which have been added as MIME bodies. The caller must close the
+ * stream object. */
+gpg_error_t
+mime_maker_get_part (mime_maker_t ctx, unsigned int partid, estream_t *r_stream)
+{
+ gpg_error_t err;
+ part_t part;
+ estream_t fp;
+
+ *r_stream = NULL;
+
+ /* When the entire tree is requested, we make sure that all missing
+ * headers are applied. We don't do that if only a part is
+ * requested because the additional headers (like Date:) will only
+ * be added to part 0 headers anyway. */
+ if (!partid)
+ {
+ err = add_missing_headers (ctx);
+ if (err)
+ return err;
+ part = ctx->mail;
+ }
+ else
+ part = find_part (ctx->mail, partid);
+
+ /* For now we use a memory stream object; however it would also be
+ * possible to create an object created on the fly while the caller
+ * is reading the returned stream. */
+ fp = es_fopenmem (0, "w+b");
+ if (!fp)
+ return gpg_error_from_syserror ();
+
+ ctx->outfp = fp;
+ err = write_tree (ctx, NULL, part);
+ ctx->outfp = NULL;
+
+ if (!err)
+ {
+ es_rewind (fp);
+ *r_stream = fp;
+ }
+ else
+ es_fclose (fp);
+
+ return err;
+}