Skip to content

Instantly share code, notes, and snippets.

@pdehaan
Created May 14, 2015 06:04
Show Gist options
  • Select an option

  • Save pdehaan/91f87b46558076b19829 to your computer and use it in GitHub Desktop.

Select an option

Save pdehaan/91f87b46558076b19829 to your computer and use it in GitHub Desktop.
restmail+fetch example
var fetch = require('node-fetch')
fetch.Promise = require('promise')
getEmails('testfetch@restmail.net')
// Filter only FxA emails and only return the x-link header.
.then((messages) => messages.filter(filterFunc).map(getLink))
.then(console.log)
.catch(console.error)
function getEmails (account) {
// Retrieve restmail account and convert response to JSON.
return fetch(`https://restmail.net/mail/${account}`).then((response) => response.json())
}
function getLink (message) {
return message.headers['x-link']
}
function isFxAEmail (message) {
return (message.from[0].name === 'Firefox Accounts')
}
function filterFunc (message) {
return isFxAEmail(message) && !!getLink(message)
}
{
"name": "node-fetch-test",
"version": "1.0.0",
"author": "Peter deHaan",
"dependencies": {
"babel": "5.3.3",
"node-fetch": "1.2.1",
"promise": "7.0.1"
},
"devDependencies": {
"standard": "3.8.0"
},
"license": "WTFPL",
"main": "index.js",
"scripts": {
"start": "babel-node index",
"test": "standard"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment