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:
Foivos S. Zakkak
2014-10-10 07:40:37 +03:00
parent ad0f14ff3b
commit 29e53d2eba

View File

@ -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,7 +161,11 @@ 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,
mmsg->mime_part,
(GMimeObject *) mmsg,
opts,
0,
(MuMsgPartForeachFunc)accumulate_text, (MuMsgPartForeachFunc)accumulate_text,
&gstr); &gstr);
@ -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 */
@ -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,
@ -505,50 +528,10 @@ handle_mime_object (MuMsg *msg,
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);
} }