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 * purple_notify_emails(void *handle, size_t count, gboolean detailed, const char **subjects, const char **froms, const char **tos, const char **urls, PurpleNotifyCloseCallback cb, gpointer user_data) { PurpleNotifyUiOps *ops; if (count == 1) { return purple_notify_email(handle, (subjects == NULL ? NULL : *subjects), (froms == NULL ? NULL : *froms), (tos == NULL ? NULL : *tos), (urls == NULL ? NULL : *urls), cb, user_data); } ops = purple_notify_get_ui_ops(); if (ops != NULL && ops->notify_emails != NULL) { void *ui_handle; purple_signal_emit(purple_notify_get_handle(), "displaying-emails-notification", subjects, froms, tos, urls, count); ui_handle = ops->notify_emails(handle, count, detailed, subjects, froms, tos, urls); if (ui_handle != NULL) { PurpleNotifyInfo *info = g_new0(PurpleNotifyInfo, 1); info->type = PURPLE_NOTIFY_EMAILS; info->handle = handle; info->ui_handle = ui_handle; info->cb = cb; info->cb_user_data = user_data; handles = g_list_append(handles, info); return info->ui_handle; } } if (cb != NULL) cb(user_data); return NULL; }
static void fb_got_notifications_cb(FacebookAccount *fba, gchar *url_text, gsize len, gpointer userdata) { gchar *salvaged; time_t last_fetch_time; time_t time_of_message; time_t newest_message = 0; xmlnode *channel;//VOXOX - CJC - 2009.07.06 xmlnode *rss_root;//VOXOX - CJC - 2009.07.06 xmlnode *item;//VOXOX - CJC - 2009.07.06 xmlnode *link;//VOXOX - CJC - 2009.07.06 xmlnode *title;//VOXOX - CJC - 2009.07.06 gchar *tmp; gchar month_string[4], weekday[4]; guint year, month, day, hour, minute, second; long timezone; gchar *subject, *url; month_string[3] = weekday[3] = '\0'; year = month = day = hour = minute = second = 0; if (!url_text || !len) return; last_fetch_time = purple_account_get_int(fba->account, "facebook_notifications_last_fetch", 0); /* purple_debug_info("facebook", "last fetch time: %zu\n", last_fetch_time); */ salvaged = purple_utf8_salvage(url_text); rss_root = xmlnode_from_str(salvaged, -1); g_free(salvaged); if (rss_root == NULL) { purple_debug_error("facebook", "Could not load RSS file\n"); return; } channel = xmlnode_get_child(rss_root, "channel"); if (channel == NULL) { purple_debug_warning("facebook", "Invalid RSS feed\n"); xmlnode_free(rss_root); return; } item = xmlnode_get_child(channel, "item"); if (item == NULL) { purple_debug_info("facebook", "No new notifications\n"); } for (; item != NULL; item = xmlnode_get_next_twin(item)) { xmlnode *pubDate = xmlnode_get_child(item, "pubDate"); if (!pubDate) continue; tmp = xmlnode_get_data_unescaped(pubDate); /* rss times are in Thu, 19 Jun 2008 15:51:25 -1100 format */ sscanf(tmp, "%3s, %2u %3s %4u %2u:%2u:%2u %5ld", (char*)&weekday, &day, (char*)&month_string, &year, &hour, &minute, &second, &timezone); if (g_str_equal(month_string, "Jan")) month = 0; else if (g_str_equal(month_string, "Feb")) month = 1; else if (g_str_equal(month_string, "Mar")) month = 2; else if (g_str_equal(month_string, "Apr")) month = 3; else if (g_str_equal(month_string, "May")) month = 4; else if (g_str_equal(month_string, "Jun")) month = 5; else if (g_str_equal(month_string, "Jul")) month = 6; else if (g_str_equal(month_string, "Aug")) month = 7; else if (g_str_equal(month_string, "Sep")) month = 8; else if (g_str_equal(month_string, "Oct")) month = 9; else if (g_str_equal(month_string, "Nov")) month = 10; else if (g_str_equal(month_string, "Dec")) month = 11; g_free(tmp); /* try using pidgin's functions */ tmp = g_strdup_printf("%04u%02u%02uT%02u%02u%02u%05ld", year, month, day, hour, minute, second, timezone); time_of_message = purple_str_to_time(tmp, FALSE, NULL, NULL, NULL); g_free(tmp); if (time_of_message <= 0) { /* there's no cross-platform, portable way of converting string to time which doesn't need a new version of glib, so just cheat */ time_of_message = second + 60*minute + 3600*hour + 86400*day + 2592000*month + 31536000*(year-1970); } if (time_of_message > newest_message) { /* we'll keep the newest message to save */ newest_message = time_of_message; } if (time_of_message <= last_fetch_time) { /* fortunatly, rss messages are ordered from newest to oldest */ /* so if this message is older than the last one, ignore rest */ break; } link = xmlnode_get_child(item, "link"); if (link) { url = xmlnode_get_data_unescaped(link); } else { url = g_strdup(""); } title = xmlnode_get_child(item, "title"); if (title) { subject = xmlnode_get_data_unescaped(title); } else { subject = g_strdup(""); } purple_notify_email(fba->pc, subject, NULL, fba->account->username, url, NULL, NULL); g_free(subject); g_free(url); } xmlnode_free(rss_root); if (newest_message > last_fetch_time) { /* update the last fetched time if we had newer messages */ purple_account_set_int(fba->account, "facebook_notifications_last_fetch", newest_message); } }