Fix gpg decryption (#186)
After a multipart/encrypted part gets decrypted the result is usually a `multipart/mixed` part (see enigmail). Before this commit mime multiparts where handled only by `g_mime_message_foreach`. As a result the decrypted mime multiparts where not processed. This patch handles mime multiparts explicitly by removing the `g_mime_message_foreach` invocations. This might come at the cost of reduced maintainability, in the case of radical gmime changes. However, gmime is pretty stable and that scenario is highly unlikely. TODO: After decryption make any attachments available
This commit is contained in:
@ -30,10 +30,6 @@
|
|||||||
#include "mu-msg-priv.h"
|
#include "mu-msg-priv.h"
|
||||||
#include "mu-msg-part.h"
|
#include "mu-msg-part.h"
|
||||||
|
|
||||||
static gboolean handle_children (MuMsg *msg,
|
|
||||||
GMimeMessage *mime_msg, MuMsgOptions opts,
|
|
||||||
unsigned index, MuMsgPartForeachFunc func,
|
|
||||||
gpointer user_data);
|
|
||||||
struct _DoData {
|
struct _DoData {
|
||||||
GMimeObject *mime_obj;
|
GMimeObject *mime_obj;
|
||||||
unsigned index;
|
unsigned index;
|
||||||
@ -151,6 +147,13 @@ accumulate_text (MuMsg *msg, MuMsgPart *part, GString **gstrp)
|
|||||||
accumulate_text_part (msg, part, gstrp);
|
accumulate_text_part (msg, part, gstrp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* declaration, so we can use it earlier */
|
||||||
|
static gboolean handle_mime_object (MuMsg *msg,
|
||||||
|
GMimeObject *mobj, GMimeObject *parent,
|
||||||
|
MuMsgOptions opts,
|
||||||
|
unsigned index, MuMsgPartForeachFunc func,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
get_text_from_mime_msg (MuMsg *msg, GMimeMessage *mmsg, MuMsgOptions opts,
|
get_text_from_mime_msg (MuMsg *msg, GMimeMessage *mmsg, MuMsgOptions opts,
|
||||||
unsigned index)
|
unsigned index)
|
||||||
@ -158,9 +161,13 @@ get_text_from_mime_msg (MuMsg *msg, GMimeMessage *mmsg, MuMsgOptions opts,
|
|||||||
GString *gstr;
|
GString *gstr;
|
||||||
|
|
||||||
gstr = g_string_sized_new (4096);
|
gstr = g_string_sized_new (4096);
|
||||||
handle_children (msg, mmsg, opts, index,
|
handle_mime_object (msg,
|
||||||
(MuMsgPartForeachFunc)accumulate_text,
|
mmsg->mime_part,
|
||||||
&gstr);
|
(GMimeObject *) mmsg,
|
||||||
|
opts,
|
||||||
|
0,
|
||||||
|
(MuMsgPartForeachFunc)accumulate_text,
|
||||||
|
&gstr);
|
||||||
|
|
||||||
return g_string_free (gstr, FALSE);
|
return g_string_free (gstr, FALSE);
|
||||||
}
|
}
|
||||||
@ -304,13 +311,6 @@ get_disposition (GMimeObject *mobj)
|
|||||||
return MU_MSG_PART_TYPE_NONE;
|
return MU_MSG_PART_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* declaration, so we can use it in handle_encrypted_part */
|
|
||||||
static gboolean handle_mime_object (MuMsg *msg,
|
|
||||||
GMimeObject *mobj, GMimeObject *parent,
|
|
||||||
MuMsgOptions opts,
|
|
||||||
unsigned index, MuMsgPartForeachFunc func,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
#define SIG_STATUS_REPORT "sig-status-report"
|
#define SIG_STATUS_REPORT "sig-status-report"
|
||||||
|
|
||||||
/* call 'func' with information about this MIME-part */
|
/* call 'func' with information about this MIME-part */
|
||||||
@ -418,7 +418,7 @@ handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent,
|
|||||||
|
|
||||||
msgpart.size = get_part_size (part);
|
msgpart.size = get_part_size (part);
|
||||||
msgpart.part_type = MU_MSG_PART_TYPE_LEAF;
|
msgpart.part_type = MU_MSG_PART_TYPE_LEAF;
|
||||||
msgpart.part_type |= get_disposition ((GMimeObject*)part);
|
msgpart.part_type |= get_disposition ((GMimeObject*)part);
|
||||||
|
|
||||||
ct = g_mime_object_get_content_type ((GMimeObject*)part);
|
ct = g_mime_object_get_content_type ((GMimeObject*)part);
|
||||||
if (GMIME_IS_CONTENT_TYPE(ct)) {
|
if (GMIME_IS_CONTENT_TYPE(ct)) {
|
||||||
@ -474,14 +474,37 @@ handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart, GMimeObject *par
|
|||||||
GMimeMessage *mmsg; /* this may return NULL for some messages */
|
GMimeMessage *mmsg; /* this may return NULL for some messages */
|
||||||
mmsg = g_mime_message_part_get_message (mimemsgpart);
|
mmsg = g_mime_message_part_get_message (mimemsgpart);
|
||||||
if (mmsg)
|
if (mmsg)
|
||||||
return handle_children
|
return handle_mime_object (msg,
|
||||||
(msg, mmsg,
|
mmsg->mime_part,
|
||||||
opts, index, func, user_data);
|
(GMimeObject *) mmsg,
|
||||||
|
opts,
|
||||||
|
index,
|
||||||
|
func,
|
||||||
|
user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
handle_multipart (MuMsg *msg,
|
||||||
|
GMimeMultipart *mpart, GMimeObject *parent, MuMsgOptions opts,
|
||||||
|
unsigned index, MuMsgPartForeachFunc func, gpointer user_data)
|
||||||
|
{
|
||||||
|
gboolean res;
|
||||||
|
GMimeObject *part;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
res = TRUE;
|
||||||
|
for (i = 0; i < mpart->children->len; i++) {
|
||||||
|
part = (GMimeObject *) mpart->children->pdata[i];
|
||||||
|
res &= handle_mime_object (msg, part, (GMimeObject *) mpart,
|
||||||
|
opts, ++index, func, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
handle_mime_object (MuMsg *msg,
|
handle_mime_object (MuMsg *msg,
|
||||||
@ -497,58 +520,18 @@ handle_mime_object (MuMsg *msg,
|
|||||||
(msg, GMIME_MESSAGE_PART(mobj),
|
(msg, GMIME_MESSAGE_PART(mobj),
|
||||||
parent, opts, index, func, user_data);
|
parent, opts, index, func, user_data);
|
||||||
else if ((opts & MU_MSG_OPTION_VERIFY) &&
|
else if ((opts & MU_MSG_OPTION_VERIFY) &&
|
||||||
GMIME_IS_MULTIPART_SIGNED (mobj))
|
GMIME_IS_MULTIPART_SIGNED (mobj))
|
||||||
return check_signature
|
return check_signature
|
||||||
(msg, GMIME_MULTIPART_SIGNED (mobj), opts);
|
(msg, GMIME_MULTIPART_SIGNED (mobj), opts);
|
||||||
else if ((opts & MU_MSG_OPTION_DECRYPT) &&
|
else if ((opts & MU_MSG_OPTION_DECRYPT) &&
|
||||||
GMIME_IS_MULTIPART_ENCRYPTED (mobj))
|
GMIME_IS_MULTIPART_ENCRYPTED (mobj))
|
||||||
return handle_encrypted_part
|
return handle_encrypted_part
|
||||||
(msg, GMIME_MULTIPART_ENCRYPTED (mobj),
|
(msg, GMIME_MULTIPART_ENCRYPTED (mobj),
|
||||||
parent, opts, index, func, user_data);
|
parent, opts, index, func, user_data);
|
||||||
return TRUE;
|
else if (GMIME_IS_MULTIPART (mobj))
|
||||||
}
|
return handle_multipart
|
||||||
|
(msg, GMIME_MULTIPART (mobj),
|
||||||
struct _ForeachData {
|
parent, opts, index, func, user_data);
|
||||||
MuMsgPartForeachFunc func;
|
|
||||||
gpointer user_data;
|
|
||||||
MuMsg *msg;
|
|
||||||
unsigned index;
|
|
||||||
MuMsgOptions opts;
|
|
||||||
|
|
||||||
};
|
|
||||||
typedef struct _ForeachData ForeachData;
|
|
||||||
|
|
||||||
static void
|
|
||||||
each_child (GMimeObject *parent, GMimeObject *part,
|
|
||||||
ForeachData *fdata)
|
|
||||||
{
|
|
||||||
handle_mime_object (fdata->msg,
|
|
||||||
part,
|
|
||||||
parent,
|
|
||||||
fdata->opts,
|
|
||||||
fdata->index++,
|
|
||||||
fdata->func,
|
|
||||||
fdata->user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
handle_children (MuMsg *msg,
|
|
||||||
GMimeMessage *mime_msg, MuMsgOptions opts,
|
|
||||||
unsigned index, MuMsgPartForeachFunc func,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
ForeachData fdata;
|
|
||||||
|
|
||||||
fdata.func = func;
|
|
||||||
fdata.user_data = user_data;
|
|
||||||
fdata.opts = opts;
|
|
||||||
fdata.msg = msg;
|
|
||||||
fdata.index = 0;
|
|
||||||
|
|
||||||
g_mime_message_foreach (mime_msg, (GMimeObjectForeachFunc)each_child,
|
|
||||||
&fdata);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,8 +545,13 @@ mu_msg_part_foreach (MuMsg *msg, MuMsgOptions opts,
|
|||||||
if (!mu_msg_load_msg_file (msg, NULL))
|
if (!mu_msg_load_msg_file (msg, NULL))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return handle_children (msg, msg->_file->_mime_msg,
|
return handle_mime_object (msg,
|
||||||
opts, 0, func, user_data);
|
msg->_file->_mime_msg->mime_part,
|
||||||
|
(GMimeObject *) msg->_file->_mime_msg,
|
||||||
|
opts,
|
||||||
|
0,
|
||||||
|
func,
|
||||||
|
user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user