Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gmail-api-parse-message-ts

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gmail-api-parse-message-ts

Parses Gmail API's GET method to iGmail object. Typescript

  • 2.2.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
663
decreased by-51.75%
Maintainers
1
Weekly downloads
 
Created
Source

npm

gmail-api-parse-message typescript

  • Parses Gmail API [message.get] and returns a IGmail object

To install:

npm install --save gmail-api-parse-message-ts --latest

or add to package.json  
"dependencies": {
     "gmail-api-parse-message-ts": "~2.2.9"
}

Example usage

import { ParseGmailApi } from 'gmail-api-parse-message-ts';
import { IGmail } from 'gmail-api-parse-message-ts/dist/iface/iGmail';

export class ParseEmailService {
    /**  fetch single email from Gmail API  */
    async getGmail(id: string): Promise<gapi.client.gmail.Message> {
      const email: gapi.client.gmail.Message = await gapi.client.gmail.users.messages.get({
        userId: 'me',
        id: id,  // format: 'metadata'
        format: 'full'
      });
      return email;
    }
 
    /** Parses Email */
    async parseEmail() {      
          const parse = new ParseGmailApi();
          const gmailResponse = await getEmail('[id of your gmail message]');
          const iGmail = parse.parseMessage(gmailResponse);  // returns IGmail object
          console.log(iGmail);  // see iGmail below
    }
 }

running parseEmail() which returns an iGmail object

interface IGmail {
    id: string;
    threadId: string;
    labelIds: string[];
    snippet: string;
    historyId: string;
    internalDate: number;
    textHtml: string;
    textPlain: string;
    attachments: IAttachment[];
    inline?: IAttachment[];
    headers: Map<string, string>;
}

interface IAttachment {
    filename: string;
    mimeType: string;
    size: number;
    attachmentId: string;
    headers?: any;
    /** data must be URLsafe base64 encoded */
    data?: string;
    dataEncoding?: string;
}

API

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

Forked

Licence

MIT

Keywords

FAQs

Package last updated on 10 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc