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;
}
static MuMsg*
msg_new (void)
{
@ -97,7 +96,6 @@ mu_msg_new_from_file (const char *path, const char *mdir,
return self;
}
MuMsg*
mu_msg_new_from_doc (XapianDocument *doc, GError **err)
{
@ -121,7 +119,6 @@ mu_msg_new_from_doc (XapianDocument *doc, GError **err)
return self;
}
static void
mu_msg_destroy (MuMsg *self)
{
@ -141,7 +138,6 @@ mu_msg_destroy (MuMsg *self)
g_slice_free (MuMsg, self);
}
MuMsg*
mu_msg_ref (MuMsg *self)
{
@ -180,7 +176,6 @@ free_later_lst (MuMsg *self, GSList *lst)
return lst;
}
/* use this instead of mu_msg_get_path so we don't get into infinite
* regress...*/
static const char*
@ -209,7 +204,6 @@ get_path (MuMsg *self)
return free_later_str (self, val);
}
/* for some data, we need to read the message file from disk */
gboolean
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);
}
void
mu_msg_unload_msg_file (MuMsg *msg)
{
@ -242,7 +235,6 @@ mu_msg_unload_msg_file (MuMsg *msg)
msg->_file = NULL;
}
static const GSList*
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);
}
static const char*
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;
}
static gint64
get_num_field (MuMsg *self, MuMsgFieldId mfid)
{
@ -308,7 +298,6 @@ get_num_field (MuMsg *self, MuMsgFieldId mfid)
return val;
}
const char*
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));
}
time_t
mu_msg_get_timestamp (MuMsg *self)
{
@ -343,7 +331,6 @@ mu_msg_get_timestamp (MuMsg *self)
return statbuf.st_mtime;
}
const char*
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);
}
const char*
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);
}
const char*
mu_msg_get_mailing_list (MuMsg *self)
{
@ -387,7 +371,6 @@ mu_msg_get_mailing_list (MuMsg *self)
return free_later_str (self, decml);
}
const char*
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);
}
const char*
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);
}
const char*
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);
}
const char*
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);
}
time_t
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);
}
MuFlags
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);
}
MuMsgPrio
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);
}
struct _BodyData {
GString *gstr;
gboolean want_html;
};
typedef struct _BodyData BodyData;
static void
accumulate_body (MuMsg *msg, MuMsgPart *mpart, BodyData *bdata)
{
char *txt;
gboolean err;
GMimePart *mimepart;
gboolean has_err, is_plain, is_html;
if (!GMIME_IS_PART(mpart->data))
return;
if (mpart->part_type & MU_MSG_PART_TYPE_ATTACHMENT)
return;
mimepart = (GMimePart*)mpart->data;
is_html = mpart->part_type & MU_MSG_PART_TYPE_TEXT_HTML;
is_plain = mpart->part_type & MU_MSG_PART_TYPE_TEXT_PLAIN;
txt = NULL;
err = TRUE;
has_err = TRUE;
if (bdata->want_html && is_html || !bdata->want_html && is_plain)
txt = mu_msg_mime_part_to_string (mimepart, &has_err);
/* text-like attachments are included when in text-mode */
if (!bdata->want_html &&
(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)
if (!has_err && txt)
bdata->gstr = g_string_append (bdata->gstr, txt);
g_free (txt);
}
static char*
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);
}
typedef struct {
GMimeContentType *ctype;
gboolean want_html;
@ -546,7 +516,6 @@ find_content_type (MuMsg *msg, MuMsgPart *mpart, ContentTypeData *cdata)
GMIME_OBJECT(wanted));
}
static const GSList*
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;
}
const GSList*
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);
}
const char*
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));
}
const char*
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));
}
const GSList*
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);
}
const GSList*
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);
}
const char*
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);
}
const GSList*
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);
}
gint64
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);
}
static gboolean
fill_contact (MuMsgContact *self, InternetAddress *addr,
MuMsgContactType ctype)
@ -682,7 +640,6 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
return self->address != NULL;
}
static void
address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
MuMsgContactForeachFunc func, gpointer user_data)
@ -706,7 +663,6 @@ address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
}
}
static void
addresses_foreach (const char* addrs, MuMsgContactType ctype,
MuMsgContactForeachFunc func, gpointer user_data)
@ -723,7 +679,6 @@ addresses_foreach (const char* addrs, MuMsgContactType ctype,
}
}
static void
msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func,
gpointer user_data)
@ -748,7 +703,6 @@ msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func,
}
}
static void
msg_contact_foreach_doc (MuMsg *msg, MuMsgContactForeachFunc func,
gpointer user_data)
@ -763,7 +717,6 @@ msg_contact_foreach_doc (MuMsg *msg, MuMsgContactForeachFunc func,
MU_MSG_CONTACT_TYPE_BCC, func, user_data);
}
void
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
gpointer user_data)
@ -779,8 +732,6 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
g_return_if_reached ();
}
static int
cmp_str (const char *s1, const char *s2)
{
@ -816,7 +767,6 @@ cmp_str (const char *s1, const char *s2)
}
}
static int
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));
}
int
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 */
}
gboolean
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;
}
/* we need do to determine the
* /home/foo/Maildir/bar
* from the /bar
@ -925,7 +871,6 @@ get_target_mdir (MuMsg *msg, const char *target_maildir, GError **err)
return rv;
}
/*
* 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
@ -970,7 +915,6 @@ mu_msg_move_to_maildir (MuMsg *self, const char *maildir,
return self->_file ? TRUE : FALSE;
}
/*
* Rename a message-file, keeping the same flags. This is useful for tricking
* some 3rd party progs such as mbsync