Fix encrypted multiparts and attachments indexing

Pull request #483 does not handle encrypted multiparts properly.  It
used to just verify the signature and not process the parts of the
multipart.  This commit resolves this issue.

Additionally it did not index attachments properly and in the case of a
multipart directly containing more than one multiparts resulted on non
unique indexing of attachments/parts.  This commit resolves this issue
as well.
This commit is contained in:
Foivos S. Zakkak
2014-10-12 22:38:53 +03:00
parent 46934a9167
commit 6f50298667

View File

@ -156,21 +156,22 @@ accumulate_text (MuMsg *msg, MuMsgPart *part, GString **gstrp)
static gboolean handle_mime_object (MuMsg *msg, static gboolean handle_mime_object (MuMsg *msg,
GMimeObject *mobj, GMimeObject *parent, GMimeObject *mobj, GMimeObject *parent,
MuMsgOptions opts, MuMsgOptions opts,
unsigned index, MuMsgPartForeachFunc func, unsigned *index, MuMsgPartForeachFunc func,
gpointer user_data); 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)
{ {
GString *gstr; GString *gstr;
unsigned index;
index = 0;
gstr = g_string_sized_new (4096); gstr = g_string_sized_new (4096);
handle_mime_object (msg, handle_mime_object (msg,
mmsg->mime_part, mmsg->mime_part,
(GMimeObject *) mmsg, (GMimeObject *) mmsg,
opts, opts,
0, &index,
(MuMsgPartForeachFunc)accumulate_text, (MuMsgPartForeachFunc)accumulate_text,
&gstr); &gstr);
@ -211,8 +212,7 @@ mu_msg_part_get_text (MuMsg *msg, MuMsgPart *self, MuMsgOptions opts)
/* apparently, g_mime_message_part_get_message may still /* apparently, g_mime_message_part_get_message may still
* return NULL */ * return NULL */
if (mime_msg) if (mime_msg)
return get_text_from_mime_msg (msg, mime_msg, return get_text_from_mime_msg (msg, mime_msg, opts);
opts, self->index);
return NULL; return NULL;
} }
@ -377,7 +377,7 @@ get_console_pw (const char* user_id, const char *prompt_ctx,
static gboolean static gboolean
handle_encrypted_part (MuMsg *msg, handle_encrypted_part (MuMsg *msg,
GMimeMultipartEncrypted *part, GMimeObject *parent, GMimeMultipartEncrypted *part, GMimeObject *parent,
MuMsgOptions opts, unsigned index, MuMsgOptions opts, unsigned *index,
MuMsgPartForeachFunc func, gpointer user_data) MuMsgPartForeachFunc func, gpointer user_data)
{ {
GError *err; GError *err;
@ -400,7 +400,7 @@ handle_encrypted_part (MuMsg *msg,
if (dec) { if (dec) {
gboolean rv; gboolean rv;
rv = handle_mime_object (msg, dec, parent, opts, rv = handle_mime_object (msg, dec, parent, opts,
index + 1, func, user_data); index, func, user_data);
g_object_unref (dec); g_object_unref (dec);
return rv; return rv;
} }
@ -413,7 +413,7 @@ handle_encrypted_part (MuMsg *msg,
/* call 'func' with information about this MIME-part */ /* call 'func' with information about this MIME-part */
static gboolean static gboolean
handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent, handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent,
MuMsgOptions opts, unsigned index, MuMsgOptions opts, unsigned *index,
MuMsgPartForeachFunc func, gpointer user_data) MuMsgPartForeachFunc func, gpointer user_data)
{ {
GMimeContentType *ct; GMimeContentType *ct;
@ -445,7 +445,7 @@ handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent,
g_object_get_data (G_OBJECT(parent), SIG_STATUS_REPORT); g_object_get_data (G_OBJECT(parent), SIG_STATUS_REPORT);
msgpart.data = (gpointer)part; msgpart.data = (gpointer)part;
msgpart.index = index; msgpart.index = (*index)++;
func (msg, &msgpart, user_data); func (msg, &msgpart, user_data);
@ -456,7 +456,7 @@ handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent,
/* call 'func' with information about this MIME-part */ /* call 'func' with information about this MIME-part */
static gboolean static gboolean
handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart, GMimeObject *parent, handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart, GMimeObject *parent,
MuMsgOptions opts, unsigned index, MuMsgOptions opts, unsigned *index,
MuMsgPartForeachFunc func, gpointer user_data) MuMsgPartForeachFunc func, gpointer user_data)
{ {
MuMsgPart msgpart; MuMsgPart msgpart;
@ -465,7 +465,7 @@ handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart, GMimeObject *par
msgpart.type = "message"; msgpart.type = "message";
msgpart.subtype = "rfc822"; msgpart.subtype = "rfc822";
msgpart.index = index; msgpart.index = (*index)++;
/* msgpart.size = 0; /\* maybe calculate this? *\/ */ /* msgpart.size = 0; /\* maybe calculate this? *\/ */
@ -492,9 +492,8 @@ handle_message_part (MuMsg *msg, GMimeMessagePart *mimemsgpart, GMimeObject *par
} }
static gboolean static gboolean
handle_multipart (MuMsg *msg, handle_multipart (MuMsg *msg, GMimeMultipart *mpart, MuMsgOptions opts,
GMimeMultipart *mpart, GMimeObject *parent, MuMsgOptions opts, unsigned *index, MuMsgPartForeachFunc func, gpointer user_data)
unsigned index, MuMsgPartForeachFunc func, gpointer user_data)
{ {
gboolean res; gboolean res;
GMimeObject *part; GMimeObject *part;
@ -504,7 +503,7 @@ handle_multipart (MuMsg *msg,
for (i = 0; i < mpart->children->len; i++) { for (i = 0; i < mpart->children->len; i++) {
part = (GMimeObject *) mpart->children->pdata[i]; part = (GMimeObject *) mpart->children->pdata[i];
res &= handle_mime_object (msg, part, (GMimeObject *) mpart, res &= handle_mime_object (msg, part, (GMimeObject *) mpart,
opts, ++index, func, user_data); opts, index, func, user_data);
} }
return res; return res;
@ -514,7 +513,7 @@ handle_multipart (MuMsg *msg,
static gboolean static gboolean
handle_mime_object (MuMsg *msg, handle_mime_object (MuMsg *msg,
GMimeObject *mobj, GMimeObject *parent, MuMsgOptions opts, GMimeObject *mobj, GMimeObject *parent, MuMsgOptions opts,
unsigned index, MuMsgPartForeachFunc func, gpointer user_data) unsigned *index, MuMsgPartForeachFunc func, gpointer user_data)
{ {
if (GMIME_IS_PART (mobj)) if (GMIME_IS_PART (mobj))
return handle_part return handle_part
@ -525,10 +524,17 @@ 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 gboolean verified, multipart;
verified = check_signature
(msg, GMIME_MULTIPART_SIGNED (mobj), opts); (msg, GMIME_MULTIPART_SIGNED (mobj), opts);
else if ((opts & MU_MSG_OPTION_DECRYPT) && multipart = handle_multipart
(msg, GMIME_MULTIPART (mobj),
opts, index, func, user_data);
return verified && multipart;
} 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),
@ -545,6 +551,9 @@ gboolean
mu_msg_part_foreach (MuMsg *msg, MuMsgOptions opts, mu_msg_part_foreach (MuMsg *msg, MuMsgOptions opts,
MuMsgPartForeachFunc func, gpointer user_data) MuMsgPartForeachFunc func, gpointer user_data)
{ {
unsigned index;
index = 0;
g_return_val_if_fail (msg, FALSE); g_return_val_if_fail (msg, FALSE);
if (!mu_msg_load_msg_file (msg, NULL)) if (!mu_msg_load_msg_file (msg, NULL))
@ -554,7 +563,7 @@ mu_msg_part_foreach (MuMsg *msg, MuMsgOptions opts,
msg->_file->_mime_msg->mime_part, msg->_file->_mime_msg->mime_part,
(GMimeObject *) msg->_file->_mime_msg, (GMimeObject *) msg->_file->_mime_msg,
opts, opts,
0, &index,
func, func,
user_data); user_data);
} }