Created
October 4, 2008 23:37
-
-
Save fernandotakai/14823 to your computer and use it in GitHub Desktop.
view the last gmail's unread messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function verifyUnreadEmails(url, callback){ | |
jQuery.get(url, null, function(rss){ | |
var entries = []; | |
var rssEntries = jQuery(rss).find("entry") | |
if(rssEntries.length > 0){ | |
for each(entry in rssEntries){ | |
entries.push(entry); | |
} | |
toslice = rssEntries.length + 1; | |
if (toslice > 10) toslice = 10 | |
callback(entries.slice(0, toslice)); | |
} else { | |
callback([]); | |
} | |
}, "xml"); | |
} | |
CmdUtils.CreateCommand({ | |
name: "verify-email", | |
description: "Checks the last unread emails on your inbox! You can pass the label of the emails to the verb like: 'verify-email ubiquity'", | |
author: {name:"Fernando Takai", email:"[email protected]"}, | |
license:"MPL", | |
takes: {'label': noun_arb_text }, | |
icon: "chrome://ubiquity/content/icons/email_open.png", | |
description: "Displays your most recent incoming email. Requires a <a href=\"http://mail.google.com\">Google Mail</a> account.", | |
preview: function( pblock, label) { | |
pblock.innerHTML = "Displays your most recent incoming email..."; | |
var url = "https://mail.google.com/mail/feed/atom/"; | |
if(label.text.length > 0){ | |
url += label.text; | |
} | |
verifyUnreadEmails(url, function(entries) { | |
pblock.innerHTML = ""; | |
var parsedEntries = []; | |
if(entries.length > 0){ | |
for each(entry in entries){ | |
entryParsed = { | |
title:jQuery(entry).find("title").text(), | |
sender:jQuery(entry).find("author name").text(), | |
link: jQuery(entry).find("link").attr("href") | |
} | |
if(entryParsed.title.length > 0) | |
parsedEntries.push(entryParsed); | |
} | |
var template = "<ol>{for entry in entries}<li><a href='${entry.link}'><b>${entry.sender}</b></a> says ${entry.title}<br/></li>{/for}</ol>" | |
pblock.innerHTML = CmdUtils.renderTemplate(template, {entries:parsedEntries}) | |
} else { | |
if(label.text.length > 0){ | |
pblock.innerHTML = "You have no unread emails with label " + label.text; | |
} else { | |
pblock.innerHTML = "You have no unread emails"; | |
} | |
} | |
}); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment