# HG changeset patch # User Stu Tomlinson # Date 1181521415 0 # Node ID b1754db7010b9f26ece9c8ee54d59d0e89ce6f00 # Parent 91460e381dbc725dd1722da476c0a766c53ff6e1# Parent abc4dcd25c501a646b7852096f71e5539821a25a merge of '1e340ceaf355a27660847defa34d87510ce35d6d' and 'fbd7e09eb7982024bdb675a64ce31c7410e0b220' diff -r 91460e381dbc -r b1754db7010b libpurple/protocols/oscar/oscar.c --- a/libpurple/protocols/oscar/oscar.c Sun Jun 10 20:23:00 2007 +0000 +++ b/libpurple/protocols/oscar/oscar.c Mon Jun 11 00:23:35 2007 +0000 @@ -4167,6 +4167,7 @@ PeerConnection *conn; int ret; char *tmp1, *tmp2; + gboolean is_html; od = (OscarData *)gc->proto_data; account = purple_connection_get_account(gc); @@ -4185,7 +4186,6 @@ } else { struct buddyinfo *bi; struct aim_sendimext_args args; - gsize len; PurpleConversation *conv; PurpleStoredImage *img; @@ -4276,22 +4276,43 @@ if (aim_sn_is_sms(name)) { /* Messaging an SMS (mobile) user */ tmp2 = purple_markup_strip_html(tmp1); + is_html = FALSE; } else if (aim_sn_is_icq(purple_account_get_username(account))) { - if (aim_sn_is_icq(name)) + if (aim_sn_is_icq(name)) { /* From ICQ to ICQ */ tmp2 = purple_markup_strip_html(tmp1); - else + is_html = FALSE; + } else { /* From ICQ to AIM */ tmp2 = g_strdup(tmp1); + is_html = TRUE; + } } else { /* From AIM to AIM and AIM to ICQ */ tmp2 = g_strdup(tmp1); + is_html = TRUE; } g_free(tmp1); tmp1 = tmp2; - len = strlen(tmp1); purple_plugin_oscar_convert_to_best_encoding(gc, name, tmp1, (char **)&args.msg, &args.msglen, &args.charset, &args.charsubset); + if (is_html && (args.msglen > MAXMSGLEN)) { + /* If the length was too long, try stripping the HTML and then running it back through + * purple_strdup_withhtml() and the encoding process. The result may be shorter. */ + g_free((char *)args.msg); + + tmp2 = purple_markup_strip_html(tmp1); + g_free(tmp1); + + tmp1 = purple_strdup_withhtml(tmp2); + g_free(tmp2); + + purple_plugin_oscar_convert_to_best_encoding(gc, name, tmp1, (char **)&args.msg, &args.msglen, &args.charset, &args.charsubset); + + purple_debug_info("oscar", "Sending %s as %s because the original was too long.", + message, (char *)args.msg); + } + purple_debug_info("oscar", "Sending IM, charset=0x%04hx, charsubset=0x%04hx, length=%d\n", args.charset, args.charsubset, args.msglen); ret = aim_im_sendch1_ext(od, &args); @@ -5323,7 +5344,7 @@ OscarData *od = (OscarData *)gc->proto_data; PurpleConversation *conv = NULL; struct chat_connection *c = NULL; - char *buf, *buf2; + char *buf, *buf2, *buf3; guint16 charset, charsubset; char *charsetstr = NULL; int len; @@ -5335,7 +5356,6 @@ return -EINVAL; buf = purple_strdup_withhtml(message); - len = strlen(buf); if (strstr(buf, " c->maxlen) || (len > c->maxvis)) { + /* If the length was too long, try stripping the HTML and then running it back through + * purple_strdup_withhtml() and the encoding process. The result may be shorter. */ g_free(buf2); - return -E2BIG; + + buf3 = purple_markup_strip_html(buf); + g_free(buf); + + buf = purple_strdup_withhtml(buf3); + g_free(buf3); + + purple_plugin_oscar_convert_to_best_encoding(gc, NULL, buf, &buf2, &len, &charset, &charsubset); + + if ((len > c->maxlen) || (len > c->maxvis)) { + purple_debug_warning("oscar", "Could not send %s because (%i > maxlen %i) or (%i > maxvis %i)", + buf2, len, c->maxlen, len, c->maxvis); + g_free(buf); + g_free(buf2); + return -E2BIG; + } + + purple_debug_info("oscar", "Sending %s as %s because the original was too long.", + message, buf2); } if (charset == AIM_CHARSET_ASCII) @@ -5361,6 +5401,7 @@ charsetstr = "iso-8859-1"; aim_chat_send_im(od, c->conn, 0, buf2, len, charsetstr, "en"); g_free(buf2); + g_free(buf); return 0; } diff -r 91460e381dbc -r b1754db7010b pidgin/gtkimhtml.c --- a/pidgin/gtkimhtml.c Sun Jun 10 20:23:00 2007 +0000 +++ b/pidgin/gtkimhtml.c Mon Jun 11 00:23:35 2007 +0000 @@ -3173,6 +3173,7 @@ char *basename = g_path_get_basename(filename); char *ext = strrchr(basename, '.'); #endif + char *newfilename; gtk_widget_destroy(image->filesel); image->filesel = NULL; @@ -3187,7 +3188,7 @@ gchar *fmt_ext = extensions[0]; const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); - if(!strcmp(fmt_ext, file_ext)){ + if(!g_ascii_strcasecmp(fmt_ext, file_ext)){ type = gdk_pixbuf_format_get_name(format); break; } @@ -3220,6 +3221,7 @@ /* If I can't find a valid type, I will just tell the user about it and then assume it's a png */ if (!type){ + char *basename, *tmp; #if GTK_CHECK_VERSION(2,4,0) GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Unrecognized file type\n\nDefaulting to PNG.")); @@ -3230,10 +3232,26 @@ g_signal_connect_swapped(dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); gtk_widget_show(dialog); + type = g_strdup("png"); + basename = g_path_get_basename(filename); + tmp = strrchr(basename, '.'); + if (tmp != NULL) + tmp[0] = '\0'; + newfilename = g_strdup_printf("%s.png", basename); + g_free(basename); + } else { + /* + * We're able to save the file in it's original format, so we + * can use the original file name. + */ + newfilename = g_strdup(filename); } - gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); + gdk_pixbuf_save(image->pixbuf, newfilename, type, &error, NULL); + + g_free(newfilename); + g_free(type); if (error){ #if GTK_CHECK_VERSION(2,4,0) @@ -3247,8 +3265,6 @@ gtk_widget_show(dialog); g_error_free(error); } - - g_free(type); } #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */