From f9aab939ccd4e7fa734761e09462ec5e98758d91 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Fri, 22 Feb 2013 00:09:04 +0000 Subject: [PATCH] Always flag delivery reports with Non_Text_Content Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=61254 --- telepathy-glib/message.c | 6 +++-- tests/Makefile.am | 7 +++++ tests/message.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/message.c diff --git a/telepathy-glib/message.c b/telepathy-glib/message.c index 2c27b44..3817074 100644 --- a/telepathy-glib/message.c +++ b/telepathy-glib/message.c @@ -750,9 +750,11 @@ tp_message_to_text (TpMessage *message, if (tp_asv_get_boolean (header, "rescued", NULL)) flags |= TP_CHANNEL_TEXT_MESSAGE_FLAG_RESCUED; - /* If the message is on an extended interface or only contains headers, - * definitely set the "your client is too old" flag. */ + /* If the message is on an extended interface, is a delivery report, or only + * contains headers, definitely set the "your client is too old" flag. */ if (message->parts->len <= 1 || + tp_asv_get_uint32 (header, "message-type", NULL) + == TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT || g_hash_table_lookup (header, "interface") != NULL) { flags |= TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT; diff --git a/tests/Makefile.am b/tests/Makefile.am index f6397ae..bb9f705 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,6 +14,7 @@ programs_list = \ test-heap \ test-internal-debug \ test-intset \ + test-message \ test-signal-connect-object \ test-util \ test-debug-domain \ @@ -123,6 +124,12 @@ test_debug_domain_SOURCES = \ test_internal_debug_SOURCES = \ internal-debug.c +test_message_SOURCES = \ + message.c +test_message_LDADD = \ + $(top_builddir)/tests/lib/libtp-glib-tests.la \ + $(LDADD) + test_signal_connect_object_SOURCES = \ signal-connect-object.c test_signal_connect_object_LDADD = \ diff --git a/tests/message.c b/tests/message.c new file mode 100644 index 0000000..4fc08a9 --- /dev/null +++ b/tests/message.c @@ -0,0 +1,70 @@ +/* Tests of TpMessage + * + * Copyright © 2013 Collabora Ltd. + * + * Copying and distribution of this file, with or without modification, + * are permitted in any medium without royalty provided the copyright + * notice and this notice are preserved. + */ + +#include "tests/lib/util.h" + +static void +test_delivery_report_with_body (void) +{ + TpMessage *message = tp_client_message_new (); + guint i; + gchar *text; + TpChannelTextMessageFlags flags; + + g_test_bug ("61254"); + + tp_message_set_uint32 (message, 0, "message-type", + TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT); + tp_message_set_uint32 (message, 0, "delivery-status", + TP_DELIVERY_STATUS_PERMANENTLY_FAILED); + + /* message from server (alternative in English) */ + i = tp_message_append_part (message); + tp_message_set_string (message, i, "alternative", "404"); + tp_message_set_string (message, i, "content-type", "text/plain"); + tp_message_set_string (message, i, "lang", "en"); + tp_message_set_string (message, i, "content", + "I have no contact with that name"); + + /* message from server (alternative in German) */ + i = tp_message_append_part (message); + tp_message_set_string (message, i, "alternative", "404"); + tp_message_set_string (message, i, "content-type", "text/plain"); + tp_message_set_string (message, i, "lang", "de"); + tp_message_set_string (message, i, "content", + "Ich habe keinen Kontakt mit diesem Namen"); + + text = tp_message_to_text (message, &flags); + + g_assert (text != NULL); + /* tp_message_to_text should only pick one language, and it's arbitrarily the + * first. */ + g_assert_cmpstr (text, ==, "I have no contact with that name"); + + /* This is a delivery report, so old clients should know that there's + * something more to the message than just a message. + */ + g_assert_cmpuint (flags, ==, TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT); + + g_free (text); + g_object_unref (message); +} + +int +main (int argc, + char **argv) +{ + tp_tests_init (&argc, &argv); + g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id="); + + g_test_add_func ("/text-channel/delivery-report-with-body", + test_delivery_report_with_body); + + return g_test_run (); +} -- 1.8.1.rc0