* further refactoring/cleanup of MuMsgPart
This commit is contained in:
@ -34,6 +34,9 @@
|
|||||||
#include "mu-msg-crypto.h"
|
#include "mu-msg-crypto.h"
|
||||||
#endif /*BUILD_CRYPTO*/
|
#endif /*BUILD_CRYPTO*/
|
||||||
|
|
||||||
|
static gboolean handle_children (MuMsg *msg, GMimeObject *mobj, MuMsgOptions opts,
|
||||||
|
unsigned index, MuMsgPartForeachFunc func, gpointer user_data);
|
||||||
|
|
||||||
|
|
||||||
struct _DoData {
|
struct _DoData {
|
||||||
GMimeObject *mime_obj;
|
GMimeObject *mime_obj;
|
||||||
@ -102,86 +105,49 @@ get_matching_part_index (MuMsg *msg, MuMsgOptions opts,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct _TxtData {
|
|
||||||
GString *gstr;
|
|
||||||
gboolean decrypt;
|
|
||||||
};
|
|
||||||
typedef struct _TxtData TxtData;
|
|
||||||
|
|
||||||
static gchar *mime_message_to_string (GMimeMessage *mimemsg, gboolean decrypt);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_mime_part_get_text (GMimeObject *parent, GMimeObject *part, TxtData *tdata)
|
accumulate_text (MuMsg *msg, MuMsgPart *part, GString **gstrp)
|
||||||
{
|
{
|
||||||
char *txt;
|
if (GMIME_IS_MESSAGE(part->data)) {
|
||||||
txt = NULL;
|
const gchar *str;
|
||||||
|
char *adrs;
|
||||||
|
GMimeMessage *mimemsg;
|
||||||
|
InternetAddressList *addresses;
|
||||||
|
/* put sender, recipients and subject in the string, so they
|
||||||
|
* can be indexed as well */
|
||||||
|
mimemsg = GMIME_MESSAGE (part->data);
|
||||||
|
str = g_mime_message_get_sender (mimemsg);
|
||||||
|
g_string_append_printf
|
||||||
|
(*gstrp, "%s%s", str ? str : "", str ? "\n" : "");
|
||||||
|
str = g_mime_message_get_subject (mimemsg);
|
||||||
|
g_string_append_printf
|
||||||
|
(*gstrp, "%s%s", str ? str : "", str ? "\n" : "");
|
||||||
|
addresses = g_mime_message_get_all_recipients (mimemsg);
|
||||||
|
adrs = internet_address_list_to_string (addresses, FALSE);
|
||||||
|
g_object_unref (addresses);
|
||||||
|
g_string_append_printf
|
||||||
|
(*gstrp, "%s%s", adrs ? adrs : "", adrs ? "\n" : "");
|
||||||
|
g_free (adrs);
|
||||||
|
|
||||||
if (GMIME_IS_MESSAGE(part)) {
|
} else if (GMIME_IS_PART (part->data)) {
|
||||||
txt = mime_message_to_string (GMIME_MESSAGE(part),
|
|
||||||
tdata->decrypt);
|
|
||||||
if (txt)
|
|
||||||
tdata->gstr =
|
|
||||||
g_string_append (tdata->gstr, txt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GMIME_IS_PART (part)) {
|
|
||||||
GMimeContentType *ctype;
|
GMimeContentType *ctype;
|
||||||
gboolean err;
|
gboolean err;
|
||||||
ctype = g_mime_object_get_content_type (part);
|
char *txt;
|
||||||
|
ctype = g_mime_object_get_content_type ((GMimeObject*)part->data);
|
||||||
if (!g_mime_content_type_is_type (ctype, "text", "plain"))
|
if (!g_mime_content_type_is_type (ctype, "text", "plain"))
|
||||||
return; /* not plain text */
|
return; /* not plain text */
|
||||||
txt = mu_msg_mime_part_to_string
|
txt = mu_msg_mime_part_to_string
|
||||||
((GMimePart*)part, &err);
|
((GMimePart*)part, &err);
|
||||||
}
|
if (txt)
|
||||||
|
g_string_append (*gstrp, txt);
|
||||||
if (txt) {
|
|
||||||
tdata->gstr = g_string_append_c (tdata->gstr, '\n');
|
|
||||||
tdata->gstr = g_string_append (tdata->gstr, txt);
|
|
||||||
g_free (txt);
|
g_free (txt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar*
|
|
||||||
mime_message_to_string (GMimeMessage *mimemsg, gboolean decrypt)
|
|
||||||
{
|
|
||||||
TxtData tdata;
|
|
||||||
InternetAddressList *addresses;
|
|
||||||
gchar *adrs;
|
|
||||||
const char *str;
|
|
||||||
|
|
||||||
tdata.gstr = g_string_sized_new (2048); /* just a guess */
|
|
||||||
|
|
||||||
/* put sender, recipients and subject in the string, so they
|
|
||||||
* can be indexed as well */
|
|
||||||
str = g_mime_message_get_sender(mimemsg);
|
|
||||||
if (str) {
|
|
||||||
g_string_append (tdata.gstr, str);
|
|
||||||
g_string_append_c (tdata.gstr, '\n');
|
|
||||||
}
|
|
||||||
str = g_mime_message_get_subject(mimemsg);
|
|
||||||
if (str) {
|
|
||||||
g_string_append (tdata.gstr, str);
|
|
||||||
g_string_append_c (tdata.gstr, '\n');
|
|
||||||
}
|
|
||||||
addresses = g_mime_message_get_all_recipients (mimemsg);
|
|
||||||
adrs = internet_address_list_to_string (addresses, FALSE);
|
|
||||||
g_object_unref(G_OBJECT(addresses));
|
|
||||||
if (adrs)
|
|
||||||
g_string_append (tdata.gstr, adrs);
|
|
||||||
g_free (adrs);
|
|
||||||
|
|
||||||
/* recurse through all text parts */
|
|
||||||
tdata.decrypt = decrypt;
|
|
||||||
mu_mime_message_foreach
|
|
||||||
(mimemsg, decrypt,
|
|
||||||
(GMimeObjectForeachFunc)each_mime_part_get_text,
|
|
||||||
&tdata);
|
|
||||||
|
|
||||||
return g_string_free (tdata.gstr, FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
mu_msg_part_get_text (MuMsg *msg, MuMsgPart *self, gboolean *err)
|
mu_msg_part_get_text (MuMsg *msg, MuMsgPart *self, MuMsgOptions opts,
|
||||||
|
gboolean *err)
|
||||||
{
|
{
|
||||||
GMimeObject *mobj;
|
GMimeObject *mobj;
|
||||||
|
|
||||||
@ -189,18 +155,18 @@ mu_msg_part_get_text (MuMsg *msg, MuMsgPart *self, gboolean *err)
|
|||||||
g_return_val_if_fail (self && self->data, NULL);
|
g_return_val_if_fail (self && self->data, NULL);
|
||||||
mobj = (GMimeObject*)self->data;
|
mobj = (GMimeObject*)self->data;
|
||||||
|
|
||||||
if (GMIME_IS_PART(mobj)) {
|
if (GMIME_IS_PART (mobj) &&
|
||||||
/* ignore all but plain text */
|
(strcasecmp (self->type, "text") == 0) &&
|
||||||
if ((strcasecmp (self->type, "text") != 0) ||
|
(strcasecmp (self->subtype, "plain") == 0))
|
||||||
(strcasecmp (self->subtype, "plain") != 0))
|
|
||||||
return NULL;
|
|
||||||
return mu_msg_mime_part_to_string ((GMimePart*)mobj, err);
|
return mu_msg_mime_part_to_string ((GMimePart*)mobj, err);
|
||||||
|
else {
|
||||||
|
GString *gstr;
|
||||||
|
gstr = g_string_sized_new (4096);
|
||||||
|
handle_children (msg, mobj, opts, self->index,
|
||||||
|
(MuMsgPartForeachFunc)accumulate_text,
|
||||||
|
&gstr);
|
||||||
|
return g_string_free (gstr, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GMIME_IS_MESSAGE(mobj))
|
|
||||||
return mime_message_to_string ((GMimeMessage*)mobj,TRUE);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -371,10 +337,8 @@ get_disposition (GMimeObject *mobj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
handle_children (MuMsg *msg,
|
handle_children (MuMsg *msg, GMimeObject *mobj, MuMsgOptions opts,
|
||||||
GMimeObject *mobj, MuMsgOptions opts,
|
unsigned index, MuMsgPartForeachFunc func, gpointer user_data);
|
||||||
unsigned index, MuMsgPartForeachFunc func,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
/* call 'func' with information about this MIME-part */
|
/* call 'func' with information about this MIME-part */
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|||||||
@ -95,8 +95,8 @@ char *mu_msg_part_get_filename (MuMsgPart *mpart, gboolean construct_if_needed)
|
|||||||
*
|
*
|
||||||
* @return utf8 string for this MIME part, to be freed by caller
|
* @return utf8 string for this MIME part, to be freed by caller
|
||||||
*/
|
*/
|
||||||
char* mu_msg_part_get_text (MuMsg *msg, MuMsgPart *part, gboolean *err)
|
char* mu_msg_part_get_text (MuMsg *msg, MuMsgPart *part, MuMsgOptions opts,
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
gboolean *err) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user