| 678 */ |
678 */ |
| 679 static gboolean |
679 static gboolean |
| 680 msim_incoming_im(MsimSession *session, MsimMessage *msg) |
680 msim_incoming_im(MsimSession *session, MsimMessage *msg) |
| 681 { |
681 { |
| 682 gchar *username, *msg_msim_markup, *msg_purple_markup; |
682 gchar *username, *msg_msim_markup, *msg_purple_markup; |
| |
683 gchar *userid; |
| 683 time_t time_received; |
684 time_t time_received; |
| |
685 PurpleConversation *conv; |
| 684 |
686 |
| 685 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
687 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
| 686 g_return_val_if_fail(msg != NULL, FALSE); |
688 g_return_val_if_fail(msg != NULL, FALSE); |
| 687 |
689 |
| 688 username = msim_msg_get_string(msg, "_username"); |
690 username = msim_msg_get_string(msg, "_username"); |
| |
691 /* I know this isn't really a string... but we need it to be one for |
| |
692 * purple_find_conversation_with_account(). */ |
| |
693 userid = msim_msg_get_string(msg, "f"); |
| 689 g_return_val_if_fail(username != NULL, FALSE); |
694 g_return_val_if_fail(username != NULL, FALSE); |
| |
695 |
| |
696 purple_debug_info("msim_incoming_im", "UserID is %s", userid); |
| 690 |
697 |
| 691 if (msim_is_userid(username)) { |
698 if (msim_is_userid(username)) { |
| 692 purple_debug_info("msim", "Ignoring message from spambot (%s) on account %s\n", |
699 purple_debug_info("msim", "Ignoring message from spambot (%s) on account %s\n", |
| 693 username, purple_account_get_username(session->account)); |
700 username, purple_account_get_username(session->account)); |
| 694 g_free(username); |
701 g_free(username); |
| 695 return FALSE; |
702 return FALSE; |
| 696 } |
703 } |
| |
704 |
| |
705 /* See if a conversation with their UID already exists...*/ |
| |
706 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, userid, session->account); |
| |
707 if (conv) { |
| |
708 /* Since the conversation exists... We need to normalize it */ |
| |
709 purple_conversation_set_name(conv, username); |
| |
710 } |
| 697 |
711 |
| 698 msg_msim_markup = msim_msg_get_string(msg, "msg"); |
712 msg_msim_markup = msim_msg_get_string(msg, "msg"); |
| 699 g_return_val_if_fail(msg_msim_markup != NULL, FALSE); |
713 g_return_val_if_fail(msg_msim_markup != NULL, FALSE); |
| 700 |
714 |
| 701 msg_purple_markup = msim_markup_to_html(session, msg_msim_markup); |
715 msg_purple_markup = msim_markup_to_html(session, msg_msim_markup); |
| 702 g_free(msg_msim_markup); |
716 g_free(msg_msim_markup); |
| 703 |
717 |
| 704 time_received = msim_msg_get_integer(msg, "date"); |
718 time_received = msim_msg_get_integer(msg, "date"); |
| 705 if (!time_received) { |
719 if (!time_received) { |
| |
720 purple_debug_info("msim_incoming_im", "date in message not set.\n"); |
| 706 time_received = time(NULL); |
721 time_received = time(NULL); |
| 707 } |
722 } |
| 708 |
723 |
| 709 serv_got_im(session->gc, username, msg_purple_markup, PURPLE_MESSAGE_RECV, time_received); |
724 serv_got_im(session->gc, username, msg_purple_markup, PURPLE_MESSAGE_RECV, time_received); |
| 710 |
725 |