void jabber_gmail_init(JabberStream *js) { JabberIq *iq; PurpleXmlNode *usersetting, *mailnotifications; if (!purple_account_get_check_mail(purple_connection_get_account(js->gc))) return; /* * Quoting https://developers.google.com/talk/jep_extensions/usersettings: * To ensure better compatibility with other clients, rather than * setting this value to "false" to turn off notifications, it is * recommended that a client set this to "true" and filter incoming * email notifications itself. */ iq = jabber_iq_new(js, JABBER_IQ_SET); usersetting = purple_xmlnode_new_child(iq->node, "usersetting"); purple_xmlnode_set_namespace(usersetting, "google:setting"); mailnotifications = purple_xmlnode_new_child(usersetting, "mailnotifications"); purple_xmlnode_set_attrib(mailnotifications, "value", "true"); jabber_iq_send(iq); iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY); jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); jabber_iq_send(iq); }
static void email_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { MsnSession *session; PurpleConnection *gc; GHashTable *table; char *from, *subject, *tmp; session = cmdproc->session; gc = session->account->gc; if (!purple_account_get_check_mail (session->account)) return; if (strcmp(msg->remote_user, "Hotmail")) { pecan_warning ("unofficial message"); return; } if (!session->passport_info.mail_url) { pecan_error ("no url"); return; } table = msn_message_get_hashtable_from_body(msg); from = subject = NULL; tmp = g_hash_table_lookup(table, "From"); if (tmp != NULL) from = purple_mime_decode_field(tmp); tmp = g_hash_table_lookup(table, "Subject"); if (tmp != NULL) subject = purple_mime_decode_field(tmp); /** @todo go to the extact email */ purple_notify_email(gc, (subject != NULL ? subject : ""), (from != NULL ? from : ""), msn_session_get_username (session), session->passport_info.mail_url, NULL, NULL); g_free(from); g_free(subject); g_hash_table_destroy(table); }
void jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type, const char *id, PurpleXmlNode *new_mail) { PurpleXmlNode *query; JabberIq *iq; /* bail if the user isn't interested */ if (!purple_account_get_check_mail(purple_connection_get_account(js->gc))) return; /* Is this an initial incoming mail notification? If so, send a request for more info */ if (type != JABBER_IQ_SET) return; /* Acknowledge the notification */ iq = jabber_iq_new(js, JABBER_IQ_RESULT); if (from) purple_xmlnode_set_attrib(iq->node, "to", from); purple_xmlnode_set_attrib(iq->node, "id", id); jabber_iq_send(iq); purple_debug_misc("jabber", "Got new mail notification. Sending request for more info\n"); iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY); jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); query = purple_xmlnode_get_child(iq->node, "query"); if (js->gmail_last_time) purple_xmlnode_set_attrib(query, "newer-than-time", js->gmail_last_time); if (js->gmail_last_tid) purple_xmlnode_set_attrib(query, "newer-than-tid", js->gmail_last_tid); jabber_iq_send(iq); return; }
static void initial_mdata_msg (MsnCmdProc *cmdproc, MsnMessage *msg) { MsnSession *session; PurpleConnection *gc; GHashTable *table; session = cmdproc->session; gc = session->account->gc; if (strcmp (msg->remote_user, "Hotmail")) { pecan_warning ("unofficial message"); return; } table = msn_message_get_hashtable_from_body (msg); { gchar *mdata; mdata = g_hash_table_lookup (table, "Mail-Data"); if (mdata) { gchar *iu = NULL; const gchar *start; const gchar *end; guint len; len = strlen (mdata); start = g_strstr_len (mdata, len, "<IU>"); if (start) { start += strlen ("<IU>"); end = g_strstr_len (start, len - (start - mdata), "</IU>"); if (end > start) iu = g_strndup (start, end - start); } if (iu) { session->inbox_unread_count = atoi (iu); g_free (iu); } do { start = g_strstr_len (start, len - (start - mdata), "<M>"); if (start) { start += strlen ("<M>"); end = g_strstr_len (start, len - (start - mdata), "</M>"); if (end > start) { gchar *read_set; #if 0 { gchar *field; gchar *tmp; tmp = pecan_get_xml_field ("N", start, end); field = purple_mime_decode_field (tmp); g_print ("field={%s}\n", field); g_free (field); g_free (tmp); } #endif read_set = pecan_get_xml_field ("RS", start, end); if (strcmp (read_set, "0") == 0) { gchar *passport; gchar *message_id; passport = pecan_get_xml_field ("E", start, end); message_id = pecan_get_xml_field ("I", start, end); pecan_oim_session_request (session->oim_session, passport, message_id); g_free (passport); g_free (message_id); } g_free (read_set); start = end + strlen ("</M>"); } } } while (start); } if (purple_account_get_check_mail (session->account) && session->passport_info.email_enabled == 1) { msn_cmdproc_send (cmdproc, "URL", "%s", "INBOX"); } } g_hash_table_destroy(table); }
static void url_cmd (MsnCmdProc *cmdproc, MsnCommand *cmd) { MsnSession *session; PurpleConnection *connection; const gchar *rru; const gchar *url; gchar creds[64]; glong tmp_timestamp; session = cmdproc->session; connection = purple_account_get_connection (session->account); rru = cmd->params[1]; url = cmd->params[2]; session->passport_info.mail_url_timestamp = time (NULL); tmp_timestamp = session->passport_info.mail_url_timestamp - session->passport_info.sl; { PurpleCipher *cipher; PurpleCipherContext *context; guchar digest[16]; gchar *buf; buf = pecan_strdup_printf ("%s%ld%s", session->passport_info.mspauth ? session->passport_info.mspauth : "BOGUS", tmp_timestamp, purple_connection_get_password (connection)); cipher = purple_ciphers_find_cipher ("md5"); context = purple_cipher_context_new (cipher, NULL); 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 (creds, 0, sizeof (creds)); { gchar buf2[3]; gint i; for (i = 0; i < 16; i++) { g_snprintf (buf2, sizeof (buf2), "%02x", digest[i]); strcat (creds, buf2); } } } g_free (session->passport_info.mail_url); session->passport_info.mail_url = g_strdup_printf ("%s&auth=%s&creds=%s&sl=%ld&username=%s&mode=ttl&sid=%s&id=2&rru=%ssvc_mail&js=yes", url, session->passport_info.mspauth, creds, tmp_timestamp, msn_session_get_username (session), session->passport_info.sid, rru); /* The user wants to check his email */ if (cmd->trans && cmd->trans->data) { purple_notify_uri (connection, session->passport_info.mail_url); return; } if (purple_account_get_check_mail (session->account)) { static gboolean is_initial = TRUE; if (!is_initial) return; if (session->inbox_unread_count > 0) { const gchar *passport; const gchar *main_url; passport = msn_session_get_username (session); main_url = session->passport_info.mail_url; purple_notify_emails (connection, session->inbox_unread_count, FALSE, NULL, NULL, &passport, &main_url, NULL, NULL); } is_initial = FALSE; } }
static void msn_parse_oim_xml(MsnOim *oim, xmlnode *node) { xmlnode *mNode; xmlnode *iu_node; MsnSession *session = oim->session; g_return_if_fail(node != NULL); if (strcmp(node->name, "MD") != 0) { char *xmlmsg = xmlnode_to_str(node, NULL); purple_debug_info("msn", "WTF is this? %s\n", xmlmsg); g_free(xmlmsg); return; } iu_node = xmlnode_get_child(node, "E/IU"); if (iu_node != NULL && purple_account_get_check_mail(session->account)) { char *unread = xmlnode_get_data(iu_node); const char *passports[2] = { msn_user_get_passport(session->user) }; const char *urls[2] = { session->passport_info.mail_url }; int count = atoi(unread); /* XXX/khc: pretty sure this is wrong */ if (count > 0) purple_notify_emails(session->account->gc, count, FALSE, NULL, NULL, passports, urls, NULL, NULL); g_free(unread); } for(mNode = xmlnode_get_child(node, "M"); mNode; mNode = xmlnode_get_next_twin(mNode)){ char *passport, *msgid, *nickname, *rtime = NULL; xmlnode *e_node, *i_node, *n_node, *rt_node; e_node = xmlnode_get_child(mNode, "E"); passport = xmlnode_get_data(e_node); i_node = xmlnode_get_child(mNode, "I"); msgid = xmlnode_get_data(i_node); n_node = xmlnode_get_child(mNode, "N"); nickname = xmlnode_get_data(n_node); rt_node = xmlnode_get_child(mNode, "RT"); if (rt_node != NULL) { rtime = xmlnode_get_data(rt_node); } /* purple_debug_info("msn", "E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime); */ if (!g_list_find_custom(oim->oim_list, msgid, (GCompareFunc)msn_recv_data_equal)) { MsnOimRecvData *data = msn_oim_recv_data_new(oim, msgid); msn_oim_post_single_get_msg(oim, data); msgid = NULL; } g_free(passport); g_free(msgid); g_free(rtime); g_free(nickname); } }