updates
[silc.git] / apps / irssi / src / silc / core / client_ops.c
index ce62c19a61ca4bc56891d164d1d32072ff160d8c..ba4d6cf27eebeaf7567d1dbb59bd06f98ed38a4a 100644 (file)
@@ -106,6 +106,29 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
       nick = silc_nicklist_insert(chanrec, chu, FALSE);
   }
 
+  if (flags & SILC_MESSAGE_FLAG_DATA) {
+    /* MIME object received, try to display it as well as we can */
+    char type[128];
+    unsigned char *data;
+
+    memset(type, 0, sizeof(type));
+    if (!silc_mime_parse(message, message_len, NULL, 0, type, sizeof(type) - 1,
+                        NULL, 0, &data, NULL))
+      return;
+
+    /* Then figure out what we can display */
+    if (strstr(type, "text/") && !strstr(type, "text/t140") &&
+       !strstr(type, "text/vnd")) {
+      /* It is something textual, display it */
+      message = (const unsigned char *)data;
+    } else {
+      message = NULL;
+    }
+  }
+
+  if (!message)
+    return;
+
   if (flags & SILC_MESSAGE_FLAG_ACTION)
     printformat_module("fe-common/silc", server, channel->channel_name,
                       MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_ACTION, 
@@ -139,6 +162,30 @@ void silc_private_message(SilcClient client, SilcClientConnection conn,
   if (sender->username)
     snprintf(userhost, sizeof(userhost) - 1, "%s@%s",
             sender->username, sender->hostname);
+
+  if (flags & SILC_MESSAGE_FLAG_DATA) {
+    /* MIME object received, try to display it as well as we can */
+    char type[128];
+    unsigned char *data;
+
+    memset(type, 0, sizeof(type));
+    if (!silc_mime_parse(message, message_len, NULL, 0, type, sizeof(type) - 1,
+                        NULL, 0, &data, NULL))
+      return;
+
+    /* Then figure out what we can display */
+    if (strstr(type, "text/") && !strstr(type, "text/t140") &&
+       !strstr(type, "text/vnd")) {
+      /* It is something textual, display it */
+      message = (const unsigned char *)data;
+    } else {
+      message = NULL;
+    }
+  }
+
+  if (!message)
+    return;
+
   signal_emit("message private", 4, server, message,
              sender->nickname ? sender->nickname : "[<unknown>]",
              sender->username ? userhost : NULL);