Skip to content

sarora2073/gmail-api-parse-message

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm

gmail-api-parse-message

Parses the response from the Gmail API's GET message method.

Changelog

9-20-2018 - modified original package to parse email addresses to extract the name and email address separately, instead of just displaying the raw string

Example usage

var rp = require('request-promise');
var parseMessage = require('gmail-api-parse-message');

rp({
  uri: 'https://www.googleapis.com/gmail/v1/users/me/messages/{MESSAGE_ID}?access_token={ACCESS_TOKEN}',
  json: true
}).then(function (response) {
  var parsedMessage = parseMessage(response);
  console.log(parsedMessage);
  // { 
  //   id: '{MESSAGE_ID}',
  //   threadId: '{THREAD_ID}',
  //   labelIds: [ 'SENT', 'INBOX', 'UNREAD' ],
  //   snippet: 'This is one cool message, buddy.',
  //   historyId: '701725',
  //   internalDate: 1451995756000,
  //   attachments: [{ 
  //     filename: 'example.jpg',
  //     mimeType: 'image/jpeg',
  //     size: 100446,
  //     attachmentId: '{ATTACHMENT_ID}' 
  //   }],
  //   headers: {
  //     subject: 'Example subject',
  //     from: {name: 'Example Name', address: example@gmail.com' },
  //     to: {name: 'Foo Bar', address: 'foo@gmail.com' },
  //     ...
  //   },
  //   textPlain: 'This is one cool *message*, buddy.\r\n',
  //   textHtml: '<div dir="ltr">This is one cool <b>message</b>, buddy.</div>\r\n' 
  // }
});

API

/**
 * Takes a response from the Gmail API's GET message method and extracts all the relevant data.
 * @param  {object} response - The response from the Gmail API parsed to a JavaScript object.
 * @return {object} result
 */
 parseMessage(response);

Licence

MIT

About

Parses the response from the Gmail API's GET message method

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%