DefinitelyTyped/types/google-apps-script/google-apps-script.gmail.d.ts
Grant Timmerman 9f25bcc456 Update Google Apps Script Types (2017-05-12 -> 2018-07-11) (#27235)
This PR updates Google Apps Script types. (2017-05-12 -> 2018-07-11)
This is a generated type definition.
CC: @erickoledadevrel

---

- [x] Use a meaningful title for the pull request. Include the name of the package modified.
- [x] Test the change in your own code. (Compile and run.)
- [x] Add or edit tests to reflect the change. (Run with `npm test`.)
- [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request).
- [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes).
- [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present).
```
npm run lint google-apps-script
definitely-typed@0.0.2 lint /Users/timmerman/Documents/github/DefinitelyTyped
dtslint types "google-apps-script"
# No result.
```

If changing an existing definition:
- [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://developers.google.com/apps-script/reference/
- [x] Increase the version number in the header if appropriate.
  - The version should be bumped by the publisher.
- [x] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`.
2018-07-13 15:05:15 -07:00

232 lines
9.4 KiB
TypeScript

// Type definitions for Google Apps Script 2018-07-11
// Project: https://developers.google.com/apps-script/
// Definitions by: motemen <https://github.com/motemen/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="google-apps-script.types.d.ts" />
/// <reference path="google-apps-script.base.d.ts" />
declare namespace GoogleAppsScript {
export module Gmail {
/**
* Provides access to Gmail threads, messages, and labels.
*/
export interface GmailApp {
createDraft(recipient: string, subject: string, body: string): GmailDraft;
createDraft(recipient: string, subject: string, body: string, options: Object): GmailDraft;
createLabel(name: string): GmailLabel;
deleteLabel(label: GmailLabel): GmailApp;
getAliases(): string[];
getChatThreads(): GmailThread[];
getChatThreads(start: Integer, max: Integer): GmailThread[];
getDraft(draftId: string): GmailDraft;
getDraftMessages(): GmailMessage[];
getDrafts(): GmailDraft[];
getInboxThreads(): GmailThread[];
getInboxThreads(start: Integer, max: Integer): GmailThread[];
getInboxUnreadCount(): Integer;
getMessageById(id: string): GmailMessage;
getMessagesForThread(thread: GmailThread): GmailMessage[];
getMessagesForThreads(threads: GmailThread[]): GmailMessage[][];
getPriorityInboxThreads(): GmailThread[];
getPriorityInboxThreads(start: Integer, max: Integer): GmailThread[];
getPriorityInboxUnreadCount(): Integer;
getSpamThreads(): GmailThread[];
getSpamThreads(start: Integer, max: Integer): GmailThread[];
getSpamUnreadCount(): Integer;
getStarredThreads(): GmailThread[];
getStarredThreads(start: Integer, max: Integer): GmailThread[];
getStarredUnreadCount(): Integer;
getThreadById(id: string): GmailThread;
getTrashThreads(): GmailThread[];
getTrashThreads(start: Integer, max: Integer): GmailThread[];
getUserLabelByName(name: string): GmailLabel;
getUserLabels(): GmailLabel[];
markMessageRead(message: GmailMessage): GmailApp;
markMessageUnread(message: GmailMessage): GmailApp;
markMessagesRead(messages: GmailMessage[]): GmailApp;
markMessagesUnread(messages: GmailMessage[]): GmailApp;
markThreadImportant(thread: GmailThread): GmailApp;
markThreadRead(thread: GmailThread): GmailApp;
markThreadUnimportant(thread: GmailThread): GmailApp;
markThreadUnread(thread: GmailThread): GmailApp;
markThreadsImportant(threads: GmailThread[]): GmailApp;
markThreadsRead(threads: GmailThread[]): GmailApp;
markThreadsUnimportant(threads: GmailThread[]): GmailApp;
markThreadsUnread(threads: GmailThread[]): GmailApp;
moveMessageToTrash(message: GmailMessage): GmailApp;
moveMessagesToTrash(messages: GmailMessage[]): GmailApp;
moveThreadToArchive(thread: GmailThread): GmailApp;
moveThreadToInbox(thread: GmailThread): GmailApp;
moveThreadToSpam(thread: GmailThread): GmailApp;
moveThreadToTrash(thread: GmailThread): GmailApp;
moveThreadsToArchive(threads: GmailThread[]): GmailApp;
moveThreadsToInbox(threads: GmailThread[]): GmailApp;
moveThreadsToSpam(threads: GmailThread[]): GmailApp;
moveThreadsToTrash(threads: GmailThread[]): GmailApp;
refreshMessage(message: GmailMessage): GmailApp;
refreshMessages(messages: GmailMessage[]): GmailApp;
refreshThread(thread: GmailThread): GmailApp;
refreshThreads(threads: GmailThread[]): GmailApp;
search(query: string): GmailThread[];
search(query: string, start: Integer, max: Integer): GmailThread[];
sendEmail(recipient: string, subject: string, body: string): GmailApp;
sendEmail(recipient: string, subject: string, body: string, options: Object): GmailApp;
setCurrentMessageAccessToken(accessToken: string): void;
starMessage(message: GmailMessage): GmailApp;
starMessages(messages: GmailMessage[]): GmailApp;
unstarMessage(message: GmailMessage): GmailApp;
unstarMessages(messages: GmailMessage[]): GmailApp;
}
/**
* An attachment from Gmail. This is a regular Blob except that it has an extra getSize() method that is faster than calling
* getBytes().length and does not count against the Gmail read quota.
*
* // Logs information about any attachments in the first 100 inbox threads.
* var threads = GmailApp.getInboxThreads(0, 100);
* var msgs = GmailApp.getMessagesForThreads(threads);
* for (var i = 0 ; i < msgs.length; i++) {
* for (var j = 0; j < msgs[i].length; j++) {
* var attachments = msgs[i][j].getAttachments();
* for (var k = 0; k < attachments.length; k++) {
* Logger.log('Message "%s" contains the attachment "%s" (%s bytes)',
* msgs[i][j].getSubject(), attachments[k].getName(), attachments[k].getSize());
* }
* }
* }
*/
export interface GmailAttachment {
copyBlob(): Base.Blob;
getAs(contentType: string): Base.Blob;
getBytes(): Byte[];
getContentType(): string;
getDataAsString(): string;
getDataAsString(charset: string): string;
getName(): string;
getSize(): Integer;
isGoogleType(): boolean;
setBytes(data: Byte[]): Base.Blob;
setContentType(contentType: string): Base.Blob;
setContentTypeFromExtension(): Base.Blob;
setDataFromString(string: string): Base.Blob;
setDataFromString(string: string, charset: string): Base.Blob;
setName(name: string): Base.Blob;
getAllBlobs(): Base.Blob[];
}
/**
* A user-created draft message in a user's Gmail account.
*/
export interface GmailDraft {
deleteDraft(): void;
getId(): string;
getMessage(): GmailMessage;
getMessageId(): string;
send(): GmailMessage;
update(recipient: string, subject: string, body: string): GmailDraft;
update(recipient: string, subject: string, body: string, options: Object): GmailDraft;
}
/**
* A user-created label in a user's Gmail account.
*/
export interface GmailLabel {
addToThread(thread: GmailThread): GmailLabel;
addToThreads(threads: GmailThread[]): GmailLabel;
deleteLabel(): void;
getName(): string;
getThreads(): GmailThread[];
getThreads(start: Integer, max: Integer): GmailThread[];
getUnreadCount(): Integer;
removeFromThread(thread: GmailThread): GmailLabel;
removeFromThreads(threads: GmailThread[]): GmailLabel;
}
/**
* A message in a user's Gmail account.
*/
export interface GmailMessage {
createDraftReply(body: string): GmailDraft;
createDraftReply(body: string, options: Object): GmailDraft;
createDraftReplyAll(body: string): GmailDraft;
createDraftReplyAll(body: string, options: Object): GmailDraft;
forward(recipient: string): GmailMessage;
forward(recipient: string, options: Object): GmailMessage;
getAttachments(): GmailAttachment[];
getBcc(): string;
getBody(): string;
getCc(): string;
getDate(): Date;
getFrom(): string;
getId(): string;
getPlainBody(): string;
getRawContent(): string;
getReplyTo(): string;
getSubject(): string;
getThread(): GmailThread;
getTo(): string;
isDraft(): boolean;
isInChats(): boolean;
isInInbox(): boolean;
isInPriorityInbox(): boolean;
isInTrash(): boolean;
isStarred(): boolean;
isUnread(): boolean;
markRead(): GmailMessage;
markUnread(): GmailMessage;
moveToTrash(): GmailMessage;
refresh(): GmailMessage;
reply(body: string): GmailMessage;
reply(body: string, options: Object): GmailMessage;
replyAll(body: string): GmailMessage;
replyAll(body: string, options: Object): GmailMessage;
star(): GmailMessage;
unstar(): GmailMessage;
}
/**
* A thread in a user's Gmail account.
*/
export interface GmailThread {
addLabel(label: GmailLabel): GmailThread;
createDraftReply(body: string): GmailDraft;
createDraftReply(body: string, options: Object): GmailDraft;
createDraftReplyAll(body: string): GmailDraft;
createDraftReplyAll(body: string, options: Object): GmailDraft;
getFirstMessageSubject(): string;
getId(): string;
getLabels(): GmailLabel[];
getLastMessageDate(): Date;
getMessageCount(): Integer;
getMessages(): GmailMessage[];
getPermalink(): string;
hasStarredMessages(): boolean;
isImportant(): boolean;
isInChats(): boolean;
isInInbox(): boolean;
isInPriorityInbox(): boolean;
isInSpam(): boolean;
isInTrash(): boolean;
isUnread(): boolean;
markImportant(): GmailThread;
markRead(): GmailThread;
markUnimportant(): GmailThread;
markUnread(): GmailThread;
moveToArchive(): GmailThread;
moveToInbox(): GmailThread;
moveToSpam(): GmailThread;
moveToTrash(): GmailThread;
refresh(): GmailThread;
removeLabel(label: GmailLabel): GmailThread;
reply(body: string): GmailThread;
reply(body: string, options: Object): GmailThread;
replyAll(body: string): GmailThread;
replyAll(body: string, options: Object): GmailThread;
}
}
}
declare var GmailApp: GoogleAppsScript.Gmail.GmailApp;