[balsa] Use strcmp() instead of g_ascii_strcasecmp()
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] Use strcmp() instead of g_ascii_strcasecmp()
- Date: Tue, 19 Nov 2019 00:09:18 +0000 (UTC)
commit 3dc339ceaf2162500f3f931b7e9b72104393ff05
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Mon Nov 18 19:07:24 2019 -0500
Use strcmp() instead of g_ascii_strcasecmp()
when we know it is safe.
libbalsa_message_body_get_mime_type() is guaranteed to return a
lower case string, so we can safely use strcmp().
* libbalsa/body.c (libbalsa_message_body_set_parts),
(libbalsa_message_body_get_pixbuf),
(libbalsa_message_body_is_flowed):
* libbalsa/html.c (lbh_cid_cb), (libbalsa_html_type):
* src/balsa-message.c (mpart_content_name), (display_part),
(part_create_menu), (libbalsa_can_display), (preferred_part),
(get_crypto_content_icon), (libbalsa_msg_try_decrypt),
(libbalsa_msg_perform_crypto_real):
* src/balsa-mime-widget.c (balsa_mime_widget_new):
* src/balsa-print-object.c (balsa_print_objects_append_from_body):
* src/print-gtk.c (find_alt_part), (scan_body):
ChangeLog | 17 ++++++++++++++++
libbalsa/body.c | 13 ++++++------
libbalsa/html.c | 10 +++++-----
src/balsa-message.c | 52 ++++++++++++++++++++++++------------------------
src/balsa-mime-widget.c | 15 +++++++-------
src/balsa-print-object.c | 4 ++--
src/print-gtk.c | 12 +++++------
7 files changed, 69 insertions(+), 54 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0cd7a4be6..e8c61621c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2019-11-18 Peter Bloomfield <pbloomfield bellsouth net>
+
+ libbalsa_message_body_get_mime_type() is guaranteed to return a
+ lower case string, so we can safely use strcmp().
+
+ * libbalsa/body.c (libbalsa_message_body_set_parts),
+ (libbalsa_message_body_get_pixbuf),
+ (libbalsa_message_body_is_flowed):
+ * libbalsa/html.c (lbh_cid_cb), (libbalsa_html_type):
+ * src/balsa-message.c (mpart_content_name), (display_part),
+ (part_create_menu), (libbalsa_can_display), (preferred_part),
+ (get_crypto_content_icon), (libbalsa_msg_try_decrypt),
+ (libbalsa_msg_perform_crypto_real):
+ * src/balsa-mime-widget.c (balsa_mime_widget_new):
+ * src/balsa-print-object.c (balsa_print_objects_append_from_body):
+ * src/print-gtk.c (find_alt_part), (scan_body):
+
2019-11-17 Albrecht Dreß <albrecht dress arcor de>
Fix handling of Multipart/Related
diff --git a/libbalsa/body.c b/libbalsa/body.c
index 35acc0275..0aea5118c 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -250,9 +250,8 @@ libbalsa_message_body_set_parts(LibBalsaMessageBody * body)
gchar *mime_type;
mime_type = libbalsa_message_body_get_mime_type(body);
- if (strcmp(mime_type, "text/rfc822-headers") == 0) {
+ if (strcmp(mime_type, "text/rfc822-headers") == 0)
libbalsa_message_body_set_text_rfc822headers(body);
- }
g_free(mime_type);
}
@@ -691,9 +690,9 @@ libbalsa_message_body_get_pixbuf(LibBalsaMessageBody * body, GError ** err)
#define ENABLE_WORKAROUND_FOR_IE_NON_IANA_MIME_TYPE TRUE
#if ENABLE_WORKAROUND_FOR_IE_NON_IANA_MIME_TYPE
- if (!loader
- && (!g_ascii_strcasecmp(mime_type, "image/pjpeg")
- || !g_ascii_strcasecmp(mime_type, "image/jpg"))) {
+ if (loader == NULL
+ && (strcmp(mime_type, "image/pjpeg") == 0 ||
+ strcmp(mime_type, "image/jpg") == 0)) {
g_clear_error(err);
loader = gdk_pixbuf_loader_new_with_mime_type("image/jpeg", err);
}
@@ -829,11 +828,11 @@ libbalsa_message_body_is_flowed(LibBalsaMessageBody * body)
gboolean flowed = FALSE;
content_type = libbalsa_message_body_get_mime_type(body);
- if (g_ascii_strcasecmp(content_type, "text/plain") == 0) {
+ if (strcmp(content_type, "text/plain") == 0) {
gchar *format =
libbalsa_message_body_get_parameter(body, "format");
- if (format) {
+ if (format != NULL) {
flowed = (g_ascii_strcasecmp(format, "flowed") == 0);
g_free(format);
}
diff --git a/libbalsa/html.c b/libbalsa/html.c
index 891ad9baf..3f2f746b7 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -570,8 +570,8 @@ lbh_cid_cb(WebKitURISchemeRequest * request,
mime_type = libbalsa_message_body_get_mime_type(body);
webkit_uri_scheme_request_finish(request, stream, len,
mime_type);
- g_object_unref(stream);
g_free(mime_type);
+ g_object_unref(stream);
}
}
}
@@ -1181,11 +1181,11 @@ libbalsa_html_filter(LibBalsaHTMLType html_type, gchar ** text, guint len)
LibBalsaHTMLType
libbalsa_html_type(const gchar * mime_type)
{
- if (!strcmp(mime_type, "text/html"))
+ if (strcmp(mime_type, "text/html") == 0)
return LIBBALSA_HTML_TYPE_HTML;
- if (!strcmp(mime_type, "text/enriched"))
+ if (strcmp(mime_type, "text/enriched") == 0)
return LIBBALSA_HTML_TYPE_ENRICHED;
- if (!strcmp(mime_type, "text/richtext"))
+ if (strcmp(mime_type, "text/richtext") == 0)
return LIBBALSA_HTML_TYPE_RICHTEXT;
return LIBBALSA_HTML_TYPE_NONE;
}
@@ -1195,7 +1195,7 @@ libbalsa_html_type(const gchar * mime_type)
LibBalsaHTMLType
libbalsa_html_type(const gchar * mime_type)
{
- if (!strcmp(mime_type, "text/html"))
+ if (strcmp(mime_type, "text/html") == 0)
return LIBBALSA_HTML_TYPE_HTML;
return LIBBALSA_HTML_TYPE_NONE;
}
diff --git a/src/balsa-message.c b/src/balsa-message.c
index b52001d95..e61611e77 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -1333,15 +1333,15 @@ part_info_init(BalsaMessage * balsa_message, BalsaPartInfo * info)
static inline gchar *
mpart_content_name(const gchar *content_type)
{
- if (g_ascii_strcasecmp(content_type, "multipart/mixed") == 0)
+ if (strcmp(content_type, "multipart/mixed") == 0)
return g_strdup(_("mixed parts"));
- else if (g_ascii_strcasecmp(content_type, "multipart/alternative") == 0)
+ else if (strcmp(content_type, "multipart/alternative") == 0)
return g_strdup(_("alternative parts"));
- else if (g_ascii_strcasecmp(content_type, "multipart/signed") == 0)
+ else if (strcmp(content_type, "multipart/signed") == 0)
return g_strdup(_("signed parts"));
- else if (g_ascii_strcasecmp(content_type, "multipart/encrypted") == 0)
+ else if (strcmp(content_type, "multipart/encrypted") == 0)
return g_strdup(_("encrypted parts"));
- else if (g_ascii_strcasecmp(content_type, "message/rfc822") == 0)
+ else if (strcmp(content_type, "message/rfc822") == 0)
return g_strdup(_("RFC822 message"));
else
return g_strdup_printf(_("“%s” parts"),
@@ -1419,16 +1419,16 @@ display_part(BalsaMessage * balsa_message, LibBalsaMessageBody * body,
content_desc = libbalsa_vfs_content_description(content_type);
if(!is_multipart ||
- g_ascii_strcasecmp(content_type, "message/rfc822")==0 ||
- g_ascii_strcasecmp(content_type, "multipart/signed")==0 ||
- g_ascii_strcasecmp(content_type, "multipart/encrypted")==0 ||
- g_ascii_strcasecmp(content_type, "multipart/mixed")==0 ||
- g_ascii_strcasecmp(content_type, "multipart/alternative")==0) {
+ strcmp(content_type, "message/rfc822") == 0 ||
+ strcmp(content_type, "multipart/signed") == 0 ||
+ strcmp(content_type, "multipart/encrypted") == 0 ||
+ strcmp(content_type, "multipart/mixed") == 0 ||
+ strcmp(content_type, "multipart/alternative") == 0) {
info = balsa_part_info_new(body);
balsa_message->info_count++;
- if (g_ascii_strcasecmp(content_type, "message/rfc822") == 0 &&
+ if (strcmp(content_type, "message/rfc822") == 0 &&
body->embhdrs) {
gchar *from = balsa_message_sender_to_gchar(body->embhdrs->from, 0);
gchar *subj = g_strdup(body->embhdrs->subject);
@@ -1667,7 +1667,7 @@ part_create_menu (BalsaPartInfo* info)
G_CALLBACK (balsa_mime_widget_ctx_menu_save), (gpointer) info->body);
gtk_menu_shell_append (GTK_MENU_SHELL (info->popup_menu), menu_item);
- if (g_ascii_strcasecmp(content_type, "message/rfc822") == 0) {
+ if (strcmp(content_type, "message/rfc822") == 0) {
GtkWidget *submenu;
menu_item =
@@ -2020,7 +2020,7 @@ libbalsa_can_display(LibBalsaMessageBody *part)
if (!balsa_app.display_alt_plain &&
libbalsa_html_type(content_type))
res = TRUE;
- else if(g_ascii_strcasecmp(content_type, "multipart/related") == 0 &&
+ else if(strcmp(content_type, "multipart/related") == 0 &&
part->parts)
res = libbalsa_can_display(part->parts);
g_free(content_type);
@@ -2051,8 +2051,8 @@ preferred_part(LibBalsaMessageBody *parts)
content_type = libbalsa_message_body_get_mime_type(body);
- if (g_ascii_strcasecmp(content_type, "text/plain") == 0 ||
- g_ascii_strcasecmp(content_type, "text/calendar") == 0)
+ if (strcmp(content_type, "text/plain") == 0 ||
+ strcmp(content_type, "text/calendar") == 0)
preferred = body;
#ifdef HAVE_HTML_WIDGET
else if (libbalsa_can_display(body))
@@ -2742,9 +2742,9 @@ get_crypto_content_icon(LibBalsaMessageBody * body, const gchar * content_type,
return icon;
if (*icon_title &&
- g_ascii_strcasecmp(content_type, "application/pgp-signature") &&
- g_ascii_strcasecmp(content_type, "application/pkcs7-signature") &&
- g_ascii_strcasecmp(content_type, "application/x-pkcs7-signature")) {
+ strcmp(content_type, "application/pgp-signature") != 0 &&
+ strcmp(content_type, "application/pkcs7-signature") != 0 &&
+ strcmp(content_type, "application/x-pkcs7-signature") != 0) {
gchar *info_str;
info_str = g_mime_gpgme_sigstat_info(body->sig_info, TRUE);
@@ -2791,9 +2791,9 @@ libbalsa_msg_try_decrypt(LibBalsaMessage * message, LibBalsaMessageBody * body,
weird cases where such parts are nested, so do it in a loop. */
this_body = body;
mime_type = libbalsa_message_body_get_mime_type(this_body);
- while (!g_ascii_strcasecmp(mime_type, "multipart/encrypted") ||
- !g_ascii_strcasecmp(mime_type, "application/pkcs7-mime") ||
- !g_ascii_strcasecmp(mime_type, "application/x-pkcs7-mime")) {
+ while (strcmp(mime_type, "multipart/encrypted") == 0 ||
+ strcmp(mime_type, "application/pkcs7-mime") == 0 ||
+ strcmp(mime_type, "application/x-pkcs7-mime") == 0) {
gint encrres;
/* FIXME: not checking for body_ref > 1 (or > 2 when re-checking, which
@@ -3139,7 +3139,7 @@ libbalsa_msg_perform_crypto_real(LibBalsaMessage * message,
/* Check for multipart/signed and check the signature. */
mime_type = libbalsa_message_body_get_mime_type(body);
- if (!g_ascii_strcasecmp(mime_type, "multipart/signed"))
+ if (strcmp(mime_type, "multipart/signed") == 0)
libbalsa_msg_try_mp_signed(message, body, chk_crypto);
g_free(mime_type);
@@ -3150,10 +3150,10 @@ libbalsa_msg_perform_crypto_real(LibBalsaMessage * message,
while (chk_body) {
mime_type = libbalsa_message_body_get_mime_type(chk_body);
- if (g_ascii_strcasecmp(mime_type, "application/octet-stream") &&
- g_ascii_strcasecmp(mime_type, "application/pkcs7-signature") &&
- g_ascii_strcasecmp(mime_type, "application/x-pkcs7-signature") &&
- g_ascii_strcasecmp(mime_type, "application/pgp-signature"))
+ if (strcmp(mime_type, "application/octet-stream") != 0 &&
+ strcmp(mime_type, "application/pkcs7-signature") != 0 &&
+ strcmp(mime_type, "application/x-pkcs7-signature") != 0 &&
+ strcmp(mime_type, "application/pgp-signature") != 0)
libbalsa_msg_part_2440(message, chk_body, chk_crypto);
g_free(mime_type);
diff --git a/src/balsa-mime-widget.c b/src/balsa-mime-widget.c
index e907ae6cf..6b691e98f 100644
--- a/src/balsa-mime-widget.c
+++ b/src/balsa-mime-widget.c
@@ -117,10 +117,9 @@ balsa_mime_widget_new(BalsaMessage * bm, LibBalsaMessageBody * mime_body, gpoint
delegate = mime_delegate;
while (delegate->handler &&
((delegate->wildcard &&
- g_ascii_strncasecmp(delegate->mime_type, content_type,
- strlen(delegate->mime_type))) ||
- (!delegate->wildcard &&
- g_ascii_strcasecmp(delegate->mime_type, content_type))))
+ strncmp(delegate->mime_type, content_type, strlen(delegate->mime_type)) != 0) ||
+ (!delegate->wildcard &&
+ strcmp(delegate->mime_type, content_type) != 0)))
delegate++;
if (delegate->handler)
@@ -134,9 +133,9 @@ balsa_mime_widget_new(BalsaMessage * bm, LibBalsaMessageBody * mime_body, gpoint
g_signal_connect(mw, "focus_out_event",
G_CALLBACK(balsa_mime_widget_unlimit_focus), bm);
if (mime_body->sig_info != NULL &&
- g_ascii_strcasecmp("application/pgp-signature", content_type) != 0 &&
- g_ascii_strcasecmp("application/pkcs7-signature", content_type) != 0 &&
- g_ascii_strcasecmp("application/x-pkcs7-signature", content_type) != 0) {
+ strcmp("application/pgp-signature", content_type) != 0 &&
+ strcmp("application/pkcs7-signature", content_type) != 0 &&
+ strcmp("application/x-pkcs7-signature", content_type) != 0) {
GtkWidget *signature = balsa_mime_widget_signature_widget(mime_body, content_type);
GtkWidget *crypto_frame =
balsa_mime_widget_crypto_frame(mime_body, GTK_WIDGET(mw),
@@ -152,7 +151,7 @@ balsa_mime_widget_new(BalsaMessage * bm, LibBalsaMessageBody * mime_body, gpoint
priv = balsa_mime_widget_get_instance_private(mw);
priv->container = container;
} else if (mime_body->was_encrypted &&
- g_ascii_strcasecmp("multipart/signed", content_type) != 0) {
+ strcmp("multipart/signed", content_type) != 0) {
GtkWidget *crypto_frame =
balsa_mime_widget_crypto_frame(mime_body, GTK_WIDGET(mw), TRUE, TRUE, NULL);
BalsaMimeWidgetPrivate *priv;
diff --git a/src/balsa-print-object.c b/src/balsa-print-object.c
index 5f3ae19ad..f3e39f5e2 100644
--- a/src/balsa-print-object.c
+++ b/src/balsa-print-object.c
@@ -137,9 +137,9 @@ balsa_print_objects_append_from_body(GList * list,
for (n = 0;
pr_handlers[n].type &&
((pr_handlers[n].use_len == -1 &&
- g_ascii_strcasecmp(pr_handlers[n].type, conttype)) ||
+ strcmp(pr_handlers[n].type, conttype) != 0) ||
(pr_handlers[n].use_len > 0 &&
- g_ascii_strncasecmp(pr_handlers[n].type, conttype, pr_handlers[n].use_len)));
+ strncmp(pr_handlers[n].type, conttype, pr_handlers[n].use_len) != 0));
n++);
result = pr_handlers[n].handler(list, context, mime_body, psetup);
g_free(conttype);
diff --git a/src/print-gtk.c b/src/print-gtk.c
index 910f399de..d2ca1754a 100644
--- a/src/print-gtk.c
+++ b/src/print-gtk.c
@@ -138,14 +138,14 @@ find_alt_part(LibBalsaMessageBody *parts,
gchar *mime_type;
mime_type = libbalsa_message_body_get_mime_type(use_part);
- if ((g_ascii_strncasecmp(mime_type, "multipart/", 10U) == 0) && (use_part->parts != NULL)) {
+ if ((strncmp(mime_type, "multipart/", 10U) == 0) && (use_part->parts != NULL)) {
/* consider the first child of a multipart */
g_free(mime_type);
mime_type = libbalsa_message_body_get_mime_type(use_part->parts);
}
- if (((g_ascii_strcasecmp(mime_type, "text/plain") == 0) && !print_alt_html) ||
- ((g_ascii_strcasecmp(mime_type, "text/html") == 0) && print_alt_html)) {
+ if (((strcmp(mime_type, "text/plain") == 0) && !print_alt_html) ||
+ ((strcmp(mime_type, "text/html") == 0) && print_alt_html)) {
g_free(mime_type);
return use_part;
}
@@ -211,9 +211,9 @@ scan_body(GList *bpo_list, GtkPrintContext * context, BalsaPrintSetup * psetup,
conttype = libbalsa_message_body_get_mime_type(body);
add_signature = body->sig_info &&
- g_ascii_strcasecmp(conttype, "application/pgp-signature") &&
- g_ascii_strcasecmp(conttype, "application/pkcs7-signature") &&
- g_ascii_strcasecmp(conttype, "application/x-pkcs7-signature");
+ strcmp(conttype, "application/pgp-signature") != 0 &&
+ strcmp(conttype, "application/pkcs7-signature") != 0 &&
+ strcmp(conttype, "application/x-pkcs7-signature") != 0;
is_mp_signed = libbalsa_message_body_multipart_signed(body);
if (is_mp_signed || (!add_signature && body->was_encrypted)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]