mu: don't include text attachments as part of body

It's somewhat nice in some case, but not generally so; so let's not do
it.
This commit is contained in:
djcb
2019-02-18 08:30:55 +02:00
parent 1b408928c8
commit 9bffb465bd

View File

@ -61,7 +61,6 @@ gmime_uninit (void)
_gmime_initialized = FALSE; _gmime_initialized = FALSE;
} }
static MuMsg* static MuMsg*
msg_new (void) msg_new (void)
{ {
@ -97,7 +96,6 @@ mu_msg_new_from_file (const char *path, const char *mdir,
return self; return self;
} }
MuMsg* MuMsg*
mu_msg_new_from_doc (XapianDocument *doc, GError **err) mu_msg_new_from_doc (XapianDocument *doc, GError **err)
{ {
@ -121,7 +119,6 @@ mu_msg_new_from_doc (XapianDocument *doc, GError **err)
return self; return self;
} }
static void static void
mu_msg_destroy (MuMsg *self) mu_msg_destroy (MuMsg *self)
{ {
@ -141,7 +138,6 @@ mu_msg_destroy (MuMsg *self)
g_slice_free (MuMsg, self); g_slice_free (MuMsg, self);
} }
MuMsg* MuMsg*
mu_msg_ref (MuMsg *self) mu_msg_ref (MuMsg *self)
{ {
@ -180,7 +176,6 @@ free_later_lst (MuMsg *self, GSList *lst)
return lst; return lst;
} }
/* use this instead of mu_msg_get_path so we don't get into infinite /* use this instead of mu_msg_get_path so we don't get into infinite
* regress...*/ * regress...*/
static const char* static const char*
@ -209,7 +204,6 @@ get_path (MuMsg *self)
return free_later_str (self, val); return free_later_str (self, val);
} }
/* for some data, we need to read the message file from disk */ /* for some data, we need to read the message file from disk */
gboolean gboolean
mu_msg_load_msg_file (MuMsg *self, GError **err) mu_msg_load_msg_file (MuMsg *self, GError **err)
@ -232,7 +226,6 @@ mu_msg_load_msg_file (MuMsg *self, GError **err)
return (self->_file != NULL); return (self->_file != NULL);
} }
void void
mu_msg_unload_msg_file (MuMsg *msg) mu_msg_unload_msg_file (MuMsg *msg)
{ {
@ -242,7 +235,6 @@ mu_msg_unload_msg_file (MuMsg *msg)
msg->_file = NULL; msg->_file = NULL;
} }
static const GSList* static const GSList*
get_str_list_field (MuMsg *self, MuMsgFieldId mfid) get_str_list_field (MuMsg *self, MuMsgFieldId mfid)
{ {
@ -263,7 +255,6 @@ get_str_list_field (MuMsg *self, MuMsgFieldId mfid)
return free_later_lst (self, val); return free_later_lst (self, val);
} }
static const char* static const char*
get_str_field (MuMsg *self, MuMsgFieldId mfid) get_str_field (MuMsg *self, MuMsgFieldId mfid)
{ {
@ -288,7 +279,6 @@ get_str_field (MuMsg *self, MuMsgFieldId mfid)
return do_free ? free_later_str (self, val) : val; return do_free ? free_later_str (self, val) : val;
} }
static gint64 static gint64
get_num_field (MuMsg *self, MuMsgFieldId mfid) get_num_field (MuMsg *self, MuMsgFieldId mfid)
{ {
@ -308,7 +298,6 @@ get_num_field (MuMsg *self, MuMsgFieldId mfid)
return val; return val;
} }
const char* const char*
mu_msg_get_header (MuMsg *self, const char *header) mu_msg_get_header (MuMsg *self, const char *header)
{ {
@ -324,7 +313,6 @@ mu_msg_get_header (MuMsg *self, const char *header)
(self, mu_msg_file_get_header (self->_file, header)); (self, mu_msg_file_get_header (self->_file, header));
} }
time_t time_t
mu_msg_get_timestamp (MuMsg *self) mu_msg_get_timestamp (MuMsg *self)
{ {
@ -343,7 +331,6 @@ mu_msg_get_timestamp (MuMsg *self)
return statbuf.st_mtime; return statbuf.st_mtime;
} }
const char* const char*
mu_msg_get_path (MuMsg *self) mu_msg_get_path (MuMsg *self)
{ {
@ -351,7 +338,6 @@ mu_msg_get_path (MuMsg *self)
return get_str_field (self, MU_MSG_FIELD_ID_PATH); return get_str_field (self, MU_MSG_FIELD_ID_PATH);
} }
const char* const char*
mu_msg_get_subject (MuMsg *self) mu_msg_get_subject (MuMsg *self)
{ {
@ -366,8 +352,6 @@ mu_msg_get_msgid (MuMsg *self)
return get_str_field (self, MU_MSG_FIELD_ID_MSGID); return get_str_field (self, MU_MSG_FIELD_ID_MSGID);
} }
const char* const char*
mu_msg_get_mailing_list (MuMsg *self) mu_msg_get_mailing_list (MuMsg *self)
{ {
@ -387,7 +371,6 @@ mu_msg_get_mailing_list (MuMsg *self)
return free_later_str (self, decml); return free_later_str (self, decml);
} }
const char* const char*
mu_msg_get_maildir (MuMsg *self) mu_msg_get_maildir (MuMsg *self)
{ {
@ -395,7 +378,6 @@ mu_msg_get_maildir (MuMsg *self)
return get_str_field (self, MU_MSG_FIELD_ID_MAILDIR); return get_str_field (self, MU_MSG_FIELD_ID_MAILDIR);
} }
const char* const char*
mu_msg_get_from (MuMsg *self) mu_msg_get_from (MuMsg *self)
{ {
@ -403,7 +385,6 @@ mu_msg_get_from (MuMsg *self)
return get_str_field (self, MU_MSG_FIELD_ID_FROM); return get_str_field (self, MU_MSG_FIELD_ID_FROM);
} }
const char* const char*
mu_msg_get_to (MuMsg *self) mu_msg_get_to (MuMsg *self)
{ {
@ -418,7 +399,6 @@ mu_msg_get_cc (MuMsg *self)
return get_str_field (self, MU_MSG_FIELD_ID_CC); return get_str_field (self, MU_MSG_FIELD_ID_CC);
} }
const char* const char*
mu_msg_get_bcc (MuMsg *self) mu_msg_get_bcc (MuMsg *self)
{ {
@ -426,7 +406,6 @@ mu_msg_get_bcc (MuMsg *self)
return get_str_field (self, MU_MSG_FIELD_ID_BCC); return get_str_field (self, MU_MSG_FIELD_ID_BCC);
} }
time_t time_t
mu_msg_get_date (MuMsg *self) mu_msg_get_date (MuMsg *self)
{ {
@ -434,7 +413,6 @@ mu_msg_get_date (MuMsg *self)
return (time_t)get_num_field (self, MU_MSG_FIELD_ID_DATE); return (time_t)get_num_field (self, MU_MSG_FIELD_ID_DATE);
} }
MuFlags MuFlags
mu_msg_get_flags (MuMsg *self) mu_msg_get_flags (MuMsg *self)
{ {
@ -449,7 +427,6 @@ mu_msg_get_size (MuMsg *self)
return (size_t)get_num_field (self, MU_MSG_FIELD_ID_SIZE); return (size_t)get_num_field (self, MU_MSG_FIELD_ID_SIZE);
} }
MuMsgPrio MuMsgPrio
mu_msg_get_prio (MuMsg *self) mu_msg_get_prio (MuMsg *self)
{ {
@ -457,45 +434,39 @@ mu_msg_get_prio (MuMsg *self)
return (MuMsgPrio)get_num_field (self, MU_MSG_FIELD_ID_PRIO); return (MuMsgPrio)get_num_field (self, MU_MSG_FIELD_ID_PRIO);
} }
struct _BodyData { struct _BodyData {
GString *gstr; GString *gstr;
gboolean want_html; gboolean want_html;
}; };
typedef struct _BodyData BodyData; typedef struct _BodyData BodyData;
static void static void
accumulate_body (MuMsg *msg, MuMsgPart *mpart, BodyData *bdata) accumulate_body (MuMsg *msg, MuMsgPart *mpart, BodyData *bdata)
{ {
char *txt; char *txt;
gboolean err; GMimePart *mimepart;
gboolean has_err, is_plain, is_html;
if (!GMIME_IS_PART(mpart->data)) if (!GMIME_IS_PART(mpart->data))
return; return;
if (mpart->part_type & MU_MSG_PART_TYPE_ATTACHMENT)
return;
txt = NULL; mimepart = (GMimePart*)mpart->data;
err = TRUE; is_html = mpart->part_type & MU_MSG_PART_TYPE_TEXT_HTML;
is_plain = mpart->part_type & MU_MSG_PART_TYPE_TEXT_PLAIN;
/* text-like attachments are included when in text-mode */ txt = NULL;
has_err = TRUE;
if (bdata->want_html && is_html || !bdata->want_html && is_plain)
txt = mu_msg_mime_part_to_string (mimepart, &has_err);
if (!bdata->want_html && if (!has_err && txt)
(mpart->part_type & MU_MSG_PART_TYPE_TEXT_PLAIN))
txt = mu_msg_mime_part_to_string (
(GMimePart*)mpart->data, &err);
else if (!(mpart->part_type & MU_MSG_PART_TYPE_ATTACHMENT) &&
bdata->want_html &&
(mpart->part_type & MU_MSG_PART_TYPE_TEXT_HTML))
txt = mu_msg_mime_part_to_string (
(GMimePart*)mpart->data, &err);
if (!err && txt)
bdata->gstr = g_string_append (bdata->gstr, txt); bdata->gstr = g_string_append (bdata->gstr, txt);
g_free (txt); g_free (txt);
} }
static char* static char*
get_body (MuMsg *self, MuMsgOptions opts, gboolean want_html) get_body (MuMsg *self, MuMsgOptions opts, gboolean want_html)
{ {
@ -515,7 +486,6 @@ get_body (MuMsg *self, MuMsgOptions opts, gboolean want_html)
return g_string_free (bdata.gstr, FALSE); return g_string_free (bdata.gstr, FALSE);
} }
typedef struct { typedef struct {
GMimeContentType *ctype; GMimeContentType *ctype;
gboolean want_html; gboolean want_html;
@ -546,7 +516,6 @@ find_content_type (MuMsg *msg, MuMsgPart *mpart, ContentTypeData *cdata)
GMIME_OBJECT(wanted)); GMIME_OBJECT(wanted));
} }
static const GSList* static const GSList*
get_content_type_parameters (MuMsg *self, MuMsgOptions opts, gboolean want_html) get_content_type_parameters (MuMsg *self, MuMsgOptions opts, gboolean want_html)
{ {
@ -581,7 +550,6 @@ get_content_type_parameters (MuMsg *self, MuMsgOptions opts, gboolean want_html)
return NULL; return NULL;
} }
const GSList* const GSList*
mu_msg_get_body_text_content_type_parameters (MuMsg *self, MuMsgOptions opts) mu_msg_get_body_text_content_type_parameters (MuMsg *self, MuMsgOptions opts)
{ {
@ -589,7 +557,6 @@ mu_msg_get_body_text_content_type_parameters (MuMsg *self, MuMsgOptions opts)
return get_content_type_parameters(self, opts, FALSE); return get_content_type_parameters(self, opts, FALSE);
} }
const char* const char*
mu_msg_get_body_html (MuMsg *self, MuMsgOptions opts) mu_msg_get_body_html (MuMsg *self, MuMsgOptions opts)
{ {
@ -597,8 +564,6 @@ mu_msg_get_body_html (MuMsg *self, MuMsgOptions opts)
return free_later_str (self, get_body (self, opts, TRUE)); return free_later_str (self, get_body (self, opts, TRUE));
} }
const char* const char*
mu_msg_get_body_text (MuMsg *self, MuMsgOptions opts) mu_msg_get_body_text (MuMsg *self, MuMsgOptions opts)
{ {
@ -606,7 +571,6 @@ mu_msg_get_body_text (MuMsg *self, MuMsgOptions opts)
return free_later_str (self, get_body (self, opts, FALSE)); return free_later_str (self, get_body (self, opts, FALSE));
} }
const GSList* const GSList*
mu_msg_get_references (MuMsg *self) mu_msg_get_references (MuMsg *self)
{ {
@ -614,7 +578,6 @@ mu_msg_get_references (MuMsg *self)
return get_str_list_field (self, MU_MSG_FIELD_ID_REFS); return get_str_list_field (self, MU_MSG_FIELD_ID_REFS);
} }
const GSList* const GSList*
mu_msg_get_tags (MuMsg *self) mu_msg_get_tags (MuMsg *self)
{ {
@ -622,7 +585,6 @@ mu_msg_get_tags (MuMsg *self)
return get_str_list_field (self, MU_MSG_FIELD_ID_TAGS); return get_str_list_field (self, MU_MSG_FIELD_ID_TAGS);
} }
const char* const char*
mu_msg_get_field_string (MuMsg *self, MuMsgFieldId mfid) mu_msg_get_field_string (MuMsg *self, MuMsgFieldId mfid)
{ {
@ -630,7 +592,6 @@ mu_msg_get_field_string (MuMsg *self, MuMsgFieldId mfid)
return get_str_field (self, mfid); return get_str_field (self, mfid);
} }
const GSList* const GSList*
mu_msg_get_field_string_list (MuMsg *self, MuMsgFieldId mfid) mu_msg_get_field_string_list (MuMsg *self, MuMsgFieldId mfid)
{ {
@ -638,8 +599,6 @@ mu_msg_get_field_string_list (MuMsg *self, MuMsgFieldId mfid)
return get_str_list_field (self, mfid); return get_str_list_field (self, mfid);
} }
gint64 gint64
mu_msg_get_field_numeric (MuMsg *self, MuMsgFieldId mfid) mu_msg_get_field_numeric (MuMsg *self, MuMsgFieldId mfid)
{ {
@ -647,7 +606,6 @@ mu_msg_get_field_numeric (MuMsg *self, MuMsgFieldId mfid)
return get_num_field (self, mfid); return get_num_field (self, mfid);
} }
static gboolean static gboolean
fill_contact (MuMsgContact *self, InternetAddress *addr, fill_contact (MuMsgContact *self, InternetAddress *addr,
MuMsgContactType ctype) MuMsgContactType ctype)
@ -682,7 +640,6 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
return self->address != NULL; return self->address != NULL;
} }
static void static void
address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype, address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
MuMsgContactForeachFunc func, gpointer user_data) MuMsgContactForeachFunc func, gpointer user_data)
@ -706,7 +663,6 @@ address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
} }
} }
static void static void
addresses_foreach (const char* addrs, MuMsgContactType ctype, addresses_foreach (const char* addrs, MuMsgContactType ctype,
MuMsgContactForeachFunc func, gpointer user_data) MuMsgContactForeachFunc func, gpointer user_data)
@ -723,7 +679,6 @@ addresses_foreach (const char* addrs, MuMsgContactType ctype,
} }
} }
static void static void
msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func, msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func,
gpointer user_data) gpointer user_data)
@ -748,7 +703,6 @@ msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func,
} }
} }
static void static void
msg_contact_foreach_doc (MuMsg *msg, MuMsgContactForeachFunc func, msg_contact_foreach_doc (MuMsg *msg, MuMsgContactForeachFunc func,
gpointer user_data) gpointer user_data)
@ -763,7 +717,6 @@ msg_contact_foreach_doc (MuMsg *msg, MuMsgContactForeachFunc func,
MU_MSG_CONTACT_TYPE_BCC, func, user_data); MU_MSG_CONTACT_TYPE_BCC, func, user_data);
} }
void void
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func, mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
gpointer user_data) gpointer user_data)
@ -779,8 +732,6 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
g_return_if_reached (); g_return_if_reached ();
} }
static int static int
cmp_str (const char *s1, const char *s2) cmp_str (const char *s1, const char *s2)
{ {
@ -816,7 +767,6 @@ cmp_str (const char *s1, const char *s2)
} }
} }
static int static int
cmp_subject (const char* s1, const char *s2) cmp_subject (const char* s1, const char *s2)
{ {
@ -832,7 +782,6 @@ cmp_subject (const char* s1, const char *s2)
mu_str_subject_normalize (s2)); mu_str_subject_normalize (s2));
} }
int int
mu_msg_cmp (MuMsg *m1, MuMsg *m2, MuMsgFieldId mfid) mu_msg_cmp (MuMsg *m1, MuMsg *m2, MuMsgFieldId mfid)
{ {
@ -858,7 +807,6 @@ mu_msg_cmp (MuMsg *m1, MuMsg *m2, MuMsgFieldId mfid)
return 0; /* TODO: handle lists */ return 0; /* TODO: handle lists */
} }
gboolean gboolean
mu_msg_is_readable (MuMsg *self) mu_msg_is_readable (MuMsg *self)
{ {
@ -867,8 +815,6 @@ mu_msg_is_readable (MuMsg *self)
return access (mu_msg_get_path (self), R_OK) == 0 ? TRUE : FALSE; return access (mu_msg_get_path (self), R_OK) == 0 ? TRUE : FALSE;
} }
/* we need do to determine the /* we need do to determine the
* /home/foo/Maildir/bar * /home/foo/Maildir/bar
* from the /bar * from the /bar
@ -925,7 +871,6 @@ get_target_mdir (MuMsg *msg, const char *target_maildir, GError **err)
return rv; return rv;
} }
/* /*
* move a msg to another maildir, trying to maintain 'integrity', * move a msg to another maildir, trying to maintain 'integrity',
* ie. msg in 'new/' will go to new/, one in cur/ goes to cur/. be * ie. msg in 'new/' will go to new/, one in cur/ goes to cur/. be
@ -970,7 +915,6 @@ mu_msg_move_to_maildir (MuMsg *self, const char *maildir,
return self->_file ? TRUE : FALSE; return self->_file ? TRUE : FALSE;
} }
/* /*
* Rename a message-file, keeping the same flags. This is useful for tricking * Rename a message-file, keeping the same flags. This is useful for tricking
* some 3rd party progs such as mbsync * some 3rd party progs such as mbsync