[balsa/75-html-display-printing] fix wrong display/printout if the user overrides HTML preferences
- From: Albrecht Dreß <albrecht src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/75-html-display-printing] fix wrong display/printout if the user overrides HTML preferences
- Date: Wed, 4 May 2022 19:17:28 +0000 (UTC)
commit ed340fce8c99f7f4aef14af8a2fba040c548ed16
Author: Albrecht Dreß <albrecht dress netcologne de>
Date: Wed May 4 21:17:23 2022 +0200
fix wrong display/printout if the user overrides HTML preferences
See https://gitlab.gnome.org/GNOME/balsa/-/issues/75#note_1444507 for a
description of the issue.
Changes:
- libbalsa/body.[ch]: replace multipart/alternative selection state by a
tri-state enum
- src/balsa-message.c: use the automatic selection (settings, HTML prefs
db) of the multipart/alternative subpart only initially
- src/print-gtk.c: eval tri-state enum
Signed-off-by: Albrecht Dreß <albrecht dress netcologne de>
libbalsa/body.c | 15 ++++++++++-----
libbalsa/body.h | 14 +++++++++++---
src/balsa-message.c | 35 ++++++++++++++++++++++++-----------
src/print-gtk.c | 4 ++--
4 files changed, 47 insertions(+), 21 deletions(-)
---
diff --git a/libbalsa/body.c b/libbalsa/body.c
index a3410497c..0dcb5f243 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -1007,7 +1007,11 @@ libbalsa_message_body_set_html_selected(LibBalsaMessageBody *body)
gchar *conttype;
conttype = libbalsa_message_body_get_mime_type(body);
- mp_alt_body->html_selected = libbalsa_html_type(conttype) != LIBBALSA_HTML_TYPE_NONE;
+ if (libbalsa_html_type(conttype) != LIBBALSA_HTML_TYPE_NONE) {
+ mp_alt_body->mp_alt_selection = LIBBALSA_MP_ALT_HTML;
+ } else {
+ mp_alt_body->mp_alt_selection = LIBBALSA_MP_ALT_PLAIN;
+ }
g_free(conttype);
}
}
@@ -1017,19 +1021,20 @@ libbalsa_message_body_set_html_selected(LibBalsaMessageBody *body)
/** @brief Check if a multipart/alternative HTML or plain part is selected
*
* @param[in] body message body
- * @return TRUE iff body is a child of a multipart/alternative for which the HTML part is selected
+ * @return which part of a multipart/alternative is selected, @ref LIBBALSA_MP_ALT_AUTO if @em body id not
part of a
+ * multipart/alternative or if the selection shall be done automatically
* @sa find_mp_alt_parent()
*/
-gboolean
+LibBalsaMpAltSelection
libbalsa_message_body_get_html_selected(LibBalsaMessageBody *body)
{
LibBalsaMessageBody *mp_alt_body;
- gboolean result = FALSE;
+ LibBalsaMpAltSelection result = LIBBALSA_MP_ALT_AUTO;
g_return_val_if_fail(body != NULL, FALSE);
mp_alt_body = find_mp_alt_parent(body);
if (mp_alt_body != NULL) {
- result = mp_alt_body->html_selected;
+ result = mp_alt_body->mp_alt_selection;
}
return result;
}
diff --git a/libbalsa/body.h b/libbalsa/body.h
index 4fb6adc0b..58a03dd68 100644
--- a/libbalsa/body.h
+++ b/libbalsa/body.h
@@ -57,6 +57,14 @@ enum _LibBalsaAttachMode {
LIBBALSA_ATTACH_AS_EXTBODY
};
+typedef enum _LibBalsaMpAltSelection LibBalsaMpAltSelection;
+
+enum _LibBalsaMpAltSelection {
+ LIBBALSA_MP_ALT_AUTO = 0, /**< Automatically select text/plain or text/html. */
+ LIBBALSA_MP_ALT_PLAIN, /**< User selected text/plain. */
+ LIBBALSA_MP_ALT_HTML /**< User selected text/html. */
+};
+
#define LIBBALSA_MESSAGE_BODY_SAFE (S_IRUSR | S_IWUSR)
#define LIBBALSA_MESSAGE_BODY_UNSAFE \
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
@@ -85,7 +93,7 @@ struct _LibBalsaMessageBody {
#ifdef HAVE_HTML_WIDGET
gboolean html_ext_loaded; /* if external HTML content was loaded */
- gboolean html_selected; /* if the HTML part of a multipart/alternative is selected */
+ LibBalsaMpAltSelection mp_alt_selection; /* which part of a multipart/alternative is selected */
#endif /* HAVE_HTML_WIDGET */
LibBalsaMessageBody *parent; /* Parent part in the message */
@@ -140,10 +148,10 @@ LibBalsaMessageBody *libbalsa_message_body_mp_related_root(LibBalsaMessageBody *
#ifdef HAVE_HTML_WIDGET
void libbalsa_message_body_set_html_selected(LibBalsaMessageBody *body);
-gboolean libbalsa_message_body_get_html_selected(LibBalsaMessageBody *body);
+LibBalsaMpAltSelection libbalsa_message_body_get_html_selected(LibBalsaMessageBody *body);
#else
#define libbalsa_message_body_set_html_selected(x)
-#define libbalsa_message_body_get_html_selected(x) FALSE
+#define libbalsa_message_body_get_html_selected(x) LIBBALSA_MP_ALT_AUTO
#endif /*HAVE_HTML_WIDGET*/
guint libbalsa_message_body_protect_mode(const LibBalsaMessageBody * body);
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 7b9163542..e69c4bf95 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -2013,17 +2013,30 @@ balsa_message_has_previous_part(BalsaMessage * balsa_message)
static gboolean
libbalsa_can_display(LibBalsaMessageBody *part, InternetAddressList *from)
{
- gchar *content_type = libbalsa_message_body_get_mime_type(part);
- gboolean res = FALSE;
- if ((!balsa_app.display_alt_plain || libbalsa_html_get_prefer_html(from) ||
- libbalsa_message_body_get_html_selected(part)) &&
- (libbalsa_html_type(content_type) != LIBBALSA_HTML_TYPE_NONE))
- res = TRUE;
- else if(strcmp(content_type, "multipart/related") == 0 &&
- part->parts)
- res = libbalsa_can_display(part->parts, from);
- g_free(content_type);
- return res;
+ gchar *content_type = libbalsa_message_body_get_mime_type(part);
+ gboolean res;
+
+ if (strcmp(content_type, "multipart/related") == 0) {
+ res = (part->parts != NULL) ? libbalsa_can_display(part->parts, from) : FALSE;
+ } else {
+ switch (libbalsa_message_body_get_html_selected(part)) {
+ case LIBBALSA_MP_ALT_AUTO:
+ res = (!balsa_app.display_alt_plain || libbalsa_html_get_prefer_html(from)) &&
+ (libbalsa_html_type(content_type) != LIBBALSA_HTML_TYPE_NONE);
+ break;
+ case LIBBALSA_MP_ALT_PLAIN:
+ res = FALSE;
+ break;
+ case LIBBALSA_MP_ALT_HTML:
+ res = (libbalsa_html_type(content_type) != LIBBALSA_HTML_TYPE_NONE);
+ break;
+ default:
+ g_assert_not_reached(); /* paranoid check... */
+ }
+ }
+
+ g_free(content_type);
+ return res;
}
#endif /* HAVE_HTML_WIDGET */
diff --git a/src/print-gtk.c b/src/print-gtk.c
index d2b4d54c2..521d0662d 100644
--- a/src/print-gtk.c
+++ b/src/print-gtk.c
@@ -249,7 +249,7 @@ scan_body(GList *bpo_list, GtkPrintContext * context, BalsaPrintSetup * psetup,
if (strcmp(conttype, "multipart/alternative") == 0) {
#ifdef HAVE_HTML_WIDGET
- print_part = select_from_mp_alt(body->parts, body->html_selected);
+ print_part = select_from_mp_alt(body->parts, body->mp_alt_selection ==
LIBBALSA_MP_ALT_HTML);
#else
print_part = select_from_mp_alt(body->parts, FALSE);
#endif
@@ -262,7 +262,7 @@ scan_body(GList *bpo_list, GtkPrintContext * context, BalsaPrintSetup * psetup,
mp_rel_root_type = libbalsa_message_body_get_mime_type(mp_rel_root);
if (strcmp(mp_rel_root_type, "multipart/alternative") == 0) {
#ifdef HAVE_HTML_WIDGET
- print_part = select_from_mp_alt(mp_rel_root->parts,
mp_rel_root->html_selected);
+ print_part = select_from_mp_alt(mp_rel_root->parts,
mp_rel_root->mp_alt_selection == LIBBALSA_MP_ALT_HTML);
#else
print_part = select_from_mp_alt(mp_rel_root->parts, FALSE);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]