about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/xmpp/message.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 70b40e25..115bf3da 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -1467,14 +1467,13 @@ _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_m
 #ifdef HAVE_LIBGPGME
     xmpp_stanza_t* ox = xmpp_stanza_get_child_by_name_and_ns(stanza, "openpgp", STANZA_NS_OPENPGP_0);
     if (ox) {
-        message->plain = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox));
-        if (message->plain) {
-            xmpp_stanza_t* x = xmpp_stanza_new_from_string(connection_get_ctx(), message->plain);
-            if (x) {
-                xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(x, "payload");
+        gchar* decrypted = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox));
+        if (decrypted) {
+            xmpp_stanza_t* decrypted_stanza = xmpp_stanza_new_from_string(connection_get_ctx(), decrypted);
+            if (decrypted_stanza) {
+                xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(decrypted_stanza, "payload");
                 if (!p) {
                     log_warning("OX Stanza - no Payload");
-                    message->plain = "OX error: No payload found";
                     return;
                 }
                 xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(p, "body");
@@ -1484,18 +1483,18 @@ _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_m
                 }
                 message->plain = xmpp_stanza_get_text(b);
                 message->encrypted = xmpp_stanza_get_text(ox);
-                if (message->plain == NULL) {
-                    message->plain = xmpp_stanza_get_text(stanza);
-                }
             } else {
-                message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)";
+                cons_show("Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)");
                 log_warning("OX Stanza text to stanza failed");
             }
         } else {
-            message->plain = "Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)";
+            // get alternative text from message body
+            xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(stanza, "body");
+            if (b) {
+                message->plain = xmpp_stanza_get_text(b);
+            }
         }
     } else {
-        message->plain = "OX stanza without openpgp name";
         log_warning("OX Stanza without openpgp stanza");
     }
 #endif // HAVE_LIBGPGME