[gmime] Updated g_mime_part_get_openpgp_data to scan the decoded content
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Updated g_mime_part_get_openpgp_data to scan the decoded content
- Date: Wed, 20 Dec 2017 17:09:26 +0000 (UTC)
commit 3dec7fd867c1589582bad3d03233116b24a4f945
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Wed Dec 13 06:41:33 2017 -0500
Updated g_mime_part_get_openpgp_data to scan the decoded content
If the OpenPGP data is unknown, scan the decoded content for OpenPGP markers.
gmime/gmime-filter-openpgp.c | 8 ++++++++
gmime/gmime-filter-openpgp.h | 18 ++++++++++++++++++
gmime/gmime-part.c | 24 ++++++++++++++++++++++++
3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/gmime/gmime-filter-openpgp.c b/gmime/gmime-filter-openpgp.c
index f9833cb..2feaba8 100644
--- a/gmime/gmime-filter-openpgp.c
+++ b/gmime/gmime-filter-openpgp.c
@@ -344,6 +344,8 @@ filter_reset (GMimeFilter *filter)
* Creates a new #GMimeFilterOpenPGP filter.
*
* Returns: a new #GMimeFilterOpenPGP filter.
+ *
+ * Since: 3.2
**/
GMimeFilter *
g_mime_filter_openpgp_new (void)
@@ -359,6 +361,8 @@ g_mime_filter_openpgp_new (void)
* Gets the type of OpenPGP data that has been detected.
*
* Returns: a #GMimeOpenPGPData value.
+ *
+ * Since: 3.2
**/
GMimeOpenPGPData
g_mime_filter_openpgp_get_data_type (GMimeFilterOpenPGP *openpgp)
@@ -382,6 +386,8 @@ g_mime_filter_openpgp_get_data_type (GMimeFilterOpenPGP *openpgp)
* Gets the stream offset of the beginning of the OpenPGP data block, if any have been found.
*
* Returns: The stream offset or %-1 if no OpenPGP block was found.
+ *
+ * Since: 3.2
**/
gint64
g_mime_filter_openpgp_get_begin_offset (GMimeFilterOpenPGP *openpgp)
@@ -399,6 +405,8 @@ g_mime_filter_openpgp_get_begin_offset (GMimeFilterOpenPGP *openpgp)
* Gets the stream offset of the end of the OpenPGP data block, if any have been found.
*
* Returns: The stream offset or %-1 if no OpenPGP block was found.
+ *
+ * Since: 3.2
**/
gint64
g_mime_filter_openpgp_get_end_offset (GMimeFilterOpenPGP *openpgp)
diff --git a/gmime/gmime-filter-openpgp.h b/gmime/gmime-filter-openpgp.h
index accdac2..f023f0d 100644
--- a/gmime/gmime-filter-openpgp.h
+++ b/gmime/gmime-filter-openpgp.h
@@ -70,6 +70,8 @@ typedef enum {
* @GMIME_OPENPGP_END_PGP_PRIVATE_KEY_BLOCK: The "-----END PGP PRIVATE KEY BLOCK-----" marker has been found.
*
* The current state of the #GMimeFilterOpenPGP filter.
+ *
+ * Since: 3.2
**/
typedef enum {
GMIME_OPENPGP_NONE = 0,
@@ -84,6 +86,19 @@ typedef enum {
GMIME_OPENPGP_END_PGP_PRIVATE_KEY_BLOCK = (1 << 8) | (1 << 7)
} GMimeOpenPGPState;
+
+/**
+ * GMimeOpenPGPMarker:
+ * @marker: The OpenPGP marker.
+ * @len: The length of the OpenPGP marker.
+ * @before: The #GMimeOpenPGPState that the state machine must be in before encountering this marker.
+ * @after: The #GMimeOpenPGPState that the state machine will transition into once this marker is found.
+ * @is_end_marker: %TRUE if the marker is an end marker; otherwise, %FALSE.
+ *
+ * An OpenPGP marker for use with GMime's internal state machines used for detecting OpenPGP blocks.
+ *
+ * Since: 3.2
+ **/
typedef struct {
const char *marker;
size_t len;
@@ -92,11 +107,14 @@ typedef struct {
gboolean is_end_marker;
} GMimeOpenPGPMarker;
+
/**
* GMimeFilterOpenPGP:
* @parent_object: parent #GMimeFilter
*
* A filter to detect OpenPGP markers.
+ *
+ * Since: 3.2
**/
struct _GMimeFilterOpenPGP {
GMimeFilter parent_object;
diff --git a/gmime/gmime-part.c b/gmime/gmime-part.c
index 2177edb..057dc4f 100644
--- a/gmime/gmime-part.c
+++ b/gmime/gmime-part.c
@@ -130,6 +130,7 @@ g_mime_part_init (GMimePart *mime_part, GMimePartClass *klass)
mime_part->content_location = NULL;
mime_part->content_md5 = NULL;
mime_part->content = NULL;
+ mime_part->openpgp = (GMimeOpenPGPData) -1;
}
static void
@@ -938,6 +939,8 @@ set_content (GMimePart *mime_part, GMimeDataWrapper *content)
if (mime_part->content)
g_object_unref (mime_part->content);
+ mime_part->openpgp = (GMimeOpenPGPData) -1;
+
mime_part->content = content;
g_object_ref (content);
}
@@ -1012,6 +1015,27 @@ g_mime_part_get_openpgp_data (GMimePart *mime_part)
{
g_return_val_if_fail (GMIME_IS_PART (mime_part), GMIME_OPENPGP_DATA_NONE);
+ if (mime_part->content == NULL)
+ return GMIME_OPENPGP_DATA_NONE;
+
+ if (mime_part->openpgp == (GMimeOpenPGPData) -1) {
+ GMimeStream *filtered, *stream;
+ GMimeFilterOpenPGP *openpgp;
+
+ stream = g_mime_stream_null_new ();
+ filtered = g_mime_stream_filter_new (stream);
+ g_object_unref (stream);
+
+ openpgp = (GMimeFilterOpenPGP *) g_mime_filter_openpgp_new ();
+ g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, (GMimeFilter *) openpgp);
+ g_mime_data_wrapper_write_to_stream (mime_part->content, filtered);
+ g_mime_stream_flush (filtered);
+ g_object_unref (filtered);
+
+ mime_part->openpgp = g_mime_filter_openpgp_get_data_type (openpgp);
+ g_object_unref (openpgp);
+ }
+
return mime_part->openpgp;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]