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
Example usage
import { ParseGmailApi } from 'gmail-api-parse-message-ts';
import { IGmail } from 'gmail-api-parse-message-ts/dist/iface/iGmail';
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 getEmail('[id of your gmail message]');
const email : IEmail = parse.parseMessage(gmailResponse);
console.log(email);
}
}
running parseEmail() which returns an iGmail object
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;
}
interface IAttachment {
filename: string;
mimeType: string;
size: number;
attachmentId: string;
headers?: any;
data?: string;
dataEncoding?: string;
}
interface IReceiver {
name: string;
email: string;
}
interface IGapiLabel {
id?: string;
labelListVisibility?: string;
messageListVisibility?: string;
messagesTotal?: number;
messagesUnread?: number;
name?: string;
threadsTotal?: number;
threadsUnread?: number;
type?: string;
}
API
parseMessage(response);
getEmptyEmail();
Forked
Licence
MIT