pidgin: 5e33eda7: Fixup MSN mailbox handling based on a pa...

qulogic at pidgin.im qulogic at pidgin.im
Thu Jul 17 01:30:49 EDT 2008


-----------------------------------------------------------------
Revision: 5e33eda76b698c04377f5ad6cdd3ad1ec87d2eff
Ancestor: 889c6eeda92624e506b1e771e8c58be72298b456
Author: qulogic at pidgin.im
Date: 2008-07-17T05:25:48
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/5e33eda76b698c04377f5ad6cdd3ad1ec87d2eff

Modified files:
        libpurple/protocols/msn/msn.c
        libpurple/protocols/msn/notification.c
        libpurple/protocols/msn/session.c
        libpurple/protocols/msn/session.h

ChangeLog: 

Fixup MSN mailbox handling based on a patch from Felipe, plus various 
other things that I cleaned up in the URL command handler.
 
Updates are now made after at least 750 seconds because Felipe found 
that to be the magic value, and updating every time we receive a QNG is 
totally unreliable. They aren't even received when using the HTTP 
method, for example.

Opening the inbox is now always available. I'm not sure why it was 
limited to just @hotmail.com and @msn.com, but I certainly haven't been 
testing with either of those. I think the correct way to determine if 
an inbox exists is to just use the URL command and see, but I don't 
have one of those no-inbox accounts.

The initial email notification is no longer called explicitly for 
@hotmail.com and @msn.com accounts. I, at least, get an initial mail 
notification, but the rest of Felipe's patch negates the need to do 
this, anyway.

References #5762.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msn.c	1b8684900822bfc42582e8b6666e0d2dffd522b6
+++ libpurple/protocols/msn/msn.c	44fe68f25cfd61d2a76b1291fc600fce77d851f8
@@ -428,14 +428,25 @@ msn_show_hotmail_inbox(PurplePluginActio
 	gc = (PurpleConnection *) action->context;
 	session = gc->proto_data;
 
-	if (session->passport_info.file == NULL)
-	{
+	/** apparently the correct value is 777, use 750 as a failsafe */ 
+	if (time (NULL) - session->passport_info.mail_timestamp >= 750) {
+		MsnTransaction *trans;
+		MsnCmdProc *cmdproc;
+
+		cmdproc = session->notification->cmdproc;
+
+		trans = msn_transaction_new(cmdproc, "URL", "%s", "INBOX");
+		msn_transaction_set_data(trans, GUINT_TO_POINTER (TRUE));
+
+		msn_cmdproc_send_trans(cmdproc, trans);
+
+	} else if (session->passport_info.file != NULL) {
+		purple_notify_uri(gc, session->passport_info.file);
+
+	} else {
 		purple_notify_error(gc, NULL,
 						  _("This Hotmail account may not be active."), NULL);
-		return;
 	}
-
-	purple_notify_uri(gc, session->passport_info.file);
 }
 
 static void
@@ -824,10 +835,6 @@ msn_actions(PurplePlugin *plugin, gpoint
 static GList *
 msn_actions(PurplePlugin *plugin, gpointer context)
 {
-	PurpleConnection *gc = (PurpleConnection *)context;
-	PurpleAccount *account;
-	const char *user;
-
 	GList *m = NULL;
 	PurplePluginAction *act;
 
@@ -867,18 +874,11 @@ msn_actions(PurplePlugin *plugin, gpoint
 	m = g_list_append(m, act);
 #endif
 
-	account = purple_connection_get_account(gc);
-	user = msn_normalize(account, purple_account_get_username(account));
+	m = g_list_append(m, NULL);
+	act = purple_plugin_action_new(_("Open Hotmail Inbox"),
+			msn_show_hotmail_inbox);
+	m = g_list_append(m, act);
 
-	if ((strstr(user, "@hotmail.") != NULL) ||
-		(strstr(user, "@msn.com") != NULL))
-	{
-		m = g_list_append(m, NULL);
-		act = purple_plugin_action_new(_("Open Hotmail Inbox"),
-				msn_show_hotmail_inbox);
-		m = g_list_append(m, act);
-	}
-
 	return m;
 }
 
============================================================
--- libpurple/protocols/msn/notification.c	8e22f58bbfa151fe1346e83034a9f8d0f4c80cc0
+++ libpurple/protocols/msn/notification.c	1fde905033e0673b9e3455d6d744b026ec480b6c
@@ -918,29 +918,7 @@ qng_cmd(MsnCmdProc *cmdproc, MsnCommand 
 static void
 qng_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
-	MsnSession *session;
-	static int count = 0;
-	const char *passport;
-	PurpleAccount *account;
-
-	session = cmdproc->session;
-	account = session->account;
-
-	if (session->passport_info.file == NULL)
-		return;
-
-	passport = purple_normalize(account, purple_account_get_username(account));
-
-	if ((strstr(passport, "@hotmail.") == NULL) &&
-		(strstr(passport, "@live.com") == NULL) &&
-		(strstr(passport, "@msn.com") == NULL))
-		return;
-
-	if (count++ < 26)
-		return;
-
-	count = 0;
-	msn_cmdproc_send(cmdproc, "URL", "%s", "INBOX");
+	/* TODO: Call PNG after the timeout specified. */
 }
 
 
@@ -1273,46 +1251,39 @@ url_cmd(MsnCmdProc *cmdproc, MsnCommand 
 url_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnSession *session;
+	PurpleConnection *gc;
 	PurpleAccount *account;
 	const char *rru;
 	const char *url;
-	PurpleCipher *cipher;
-	PurpleCipherContext *context;
-	guchar digest[16];
+	PurpleCipherContext *cipher;
+	gchar digest[33];
 	FILE *fd;
 	char *buf;
-	char buf2[3];
-	char sendbuf[64];
-	int i;
 
+	gulong tmp_timestamp;
+
 	session = cmdproc->session;
 	account = session->account;
+	gc = account->gc;
 
 	rru = cmd->params[1];
 	url = cmd->params[2];
 
+	session->passport_info.mail_timestamp = time(NULL);
+	tmp_timestamp = session->passport_info.mail_timestamp - session->passport_info.sl;
+
 	buf = g_strdup_printf("%s%lu%s",
 			   session->passport_info.mspauth ? session->passport_info.mspauth : "BOGUS",
-			   time(NULL) - session->passport_info.sl,
-			   purple_connection_get_password(account->gc));
+			   tmp_timestamp,
+			   purple_connection_get_password(gc));
 
-	cipher = purple_ciphers_find_cipher("md5");
-	context = purple_cipher_context_new(cipher, NULL);
+	cipher = purple_cipher_context_new_by_name("md5", NULL);
+	purple_cipher_context_append(cipher, (const guchar *)buf, strlen(buf));
+	purple_cipher_context_digest_to_str(cipher, sizeof(digest), digest, NULL);
+	purple_cipher_context_destroy(cipher);
 
-	purple_cipher_context_append(context, (const guchar *)buf, strlen(buf));
-	purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
-	purple_cipher_context_destroy(context);
-
 	g_free(buf);
 
-	memset(sendbuf, 0, sizeof(sendbuf));
-
-	for (i = 0; i < 16; i++)
-	{
-		g_snprintf(buf2, sizeof(buf2), "%02x", digest[i]);
-		strcat(sendbuf, buf2);
-	}
-
 	if (session->passport_info.file != NULL)
 	{
 		g_unlink(session->passport_info.file);
@@ -1324,6 +1295,11 @@ url_cmd(MsnCmdProc *cmdproc, MsnCommand 
 		purple_debug_error("msn",
 						 "Error opening temp passport file: %s\n",
 						 g_strerror(errno));
+		/* The user wanted to check his or her email */
+		if (cmd->trans && cmd->trans->data)
+			/* TODO: This error might be a bit technical... */
+			purple_notify_error(gc, NULL,
+							  _("Error opening temporary passport file."), NULL);
 	}
 	else
 	{
@@ -1355,14 +1331,14 @@ url_cmd(MsnCmdProc *cmdproc, MsnCommand 
 					session->passport_info.kv);
 		fprintf(fd, "<input type=\"hidden\" name=\"id\" value=\"2\">\n");
 		fprintf(fd, "<input type=\"hidden\" name=\"sl\" value=\"%ld\">\n",
-				time(NULL) - session->passport_info.sl);
+				tmp_timestamp);
 		fprintf(fd, "<input type=\"hidden\" name=\"rru\" value=\"%s\">\n",
 				rru);
 		if (session->passport_info.mspauth != NULL)
 			fprintf(fd, "<input type=\"hidden\" name=\"auth\" value=\"%s\">\n",
 					session->passport_info.mspauth);
 		fprintf(fd, "<input type=\"hidden\" name=\"creds\" value=\"%s\">\n",
-				sendbuf); /* TODO Digest me (huh? -- ChipX86) */
+				digest); /* TODO Digest me (huh? -- ChipX86) */
 		fprintf(fd, "<input type=\"hidden\" name=\"svc\" value=\"mail\">\n");
 		fprintf(fd, "<input type=\"hidden\" name=\"js\" value=\"yes\">\n");
 		fprintf(fd, "</form></body>\n");
@@ -1374,6 +1350,12 @@ url_cmd(MsnCmdProc *cmdproc, MsnCommand 
 							 "Error closing temp passport file: %s\n",
 							 g_strerror(errno));
 
+			/* The user wanted to check his or her email */
+			if (cmd->trans && cmd->trans->data)
+				/* TODO: This error might be a bit technical... */
+				purple_notify_error(gc, NULL,
+								  _("Error closing temporary passport file."), NULL);
+
 			g_unlink(session->passport_info.file);
 			g_free(session->passport_info.file);
 			session->passport_info.file = NULL;
@@ -1402,6 +1384,10 @@ url_cmd(MsnCmdProc *cmdproc, MsnCommand 
 			}
 		}
 #endif
+
+		/* The user wants to check his or her email */
+		if (cmd->trans && cmd->trans->data)
+			purple_notify_uri(purple_account_get_connection(account), session->passport_info.file);
 	}
 }
 /**************************************************************************
============================================================
--- libpurple/protocols/msn/session.c	d6be2d414b5426ce33305b5c5ba4af58bb8cee39
+++ libpurple/protocols/msn/session.c	c03702e8345fe1dbd39a1199b18f8ed29c52924a
@@ -454,7 +454,6 @@ msn_session_finish_login(MsnSession *ses
 	PurpleAccount *account;
 	PurpleConnection *gc;
 	PurpleStoredImage *img;
-	const char *passport;
 
 	if (session->logged_in)
 		return;
@@ -474,17 +473,5 @@ msn_session_finish_login(MsnSession *ses
 
 	/* Sync users */
 	msn_session_sync_users(session);
-	/* It seems that some accounts that haven't accessed hotmail for a while
-	 * and @msn.com accounts don't automatically get the initial email
-	 * notification so we always request it on login
-	 */
-
-	passport = purple_normalize(account, purple_account_get_username(account));
-
-	if ((strstr(passport, "@hotmail.") != NULL) ||
-		(strstr(passport, "@msn.com") != NULL))
-	{
-		msn_cmdproc_send(session->notification->cmdproc, "URL", "%s", "INBOX");
-	}
 }
 
============================================================
--- libpurple/protocols/msn/session.h	f2e6c96f9ed27494d0b6ce5fec2567e30b8f0098
+++ libpurple/protocols/msn/session.h	b91539c11dcd3cdfd50f5d7caa3fd7bf5687884f
@@ -118,6 +118,7 @@ struct _MsnSession
 		char *file;
 		char *client_ip;
 		int client_port;
+		gulong mail_timestamp;
 	} passport_info;
 
 	GHashTable *soap_table;


More information about the Commits mailing list