gmail-api-parse-message typescript
- Parses Gmail API [message.get] and returns a IEmail object
To install :
npm install --save gmail-api-parse-message-ts --latest
Example usage
import { ParseGmailApi, IEmail } from 'gmail-api-parse-message-ts';
export class ParseEmailService {
async getGmailFromApi(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: 'full'
});
return email;
}
async parseEmail() {
const parse = new ParseGmailApi();
const gmailResponse = await getEmailFromApi('[id of your gmail message]');
const email : IEmail = parse.parseMessage(gmailResponse);
console.log(email);
}
API
parseMessage(response): IEmail
getEmptyEmail(): IEmail
public parseReceivers(receiverStr: string = "", checkIfEmailIsValid: boolean = true): IReceiver[]
public isEmailValid(s: string): boolean
Interfaces
interface IEmail {
id: string;
threadId: string;
snippet: string;
historyId: string;
internalDate: number;
sentDate: number;
from: IReceiver;
to: IReceiver[];
cc: IReceiver[];
bcc: IReceiver[];
subject: string;
textHtml: string,
textPlain: string,
attachments: IAttachment[],
inline?: IAttachment[],
size: number;
labelIds: string[],
labels?: IGapiLabel[],
headers: Map<string, string>,
isUnread: boolean;
isDownloaded: boolean;
}
interface IAttachment {
filename: string;
mimeType: string;
size: number;
attachmentId: string;
headers?: any;
data?: string;
dataEncoding?: string;
}
interface IReceiver {
name: string;
email: string;
isValid: boolean;
}
interface IGapiLabel {
id?: string;
labelListVisibility?: string;
messageListVisibility?: string;
messagesTotal?: number;
messagesUnread?: number;
name?: string;
threadsTotal?: number;
threadsUnread?: number;
type?: string;
}
Forked
Licence
MIT