-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Microsoft Outlook: New Attachment Received & Download Attachment #16324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
components/microsoft_outlook/actions/download-attachment/download-attachment.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import microsoftOutlook from "../../microsoft_outlook.app.mjs"; | ||
| import fs from "fs"; | ||
| import mime from "mime-types"; | ||
|
|
||
| export default { | ||
| key: "microsoft_outlook-download-attachment", | ||
| name: "Download Attachment", | ||
| description: "Downloads an attachment to the /tmp directory. [See the documentation](https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| microsoftOutlook, | ||
| messageId: { | ||
| propDefinition: [ | ||
| microsoftOutlook, | ||
| "messageId", | ||
| ], | ||
| description: "The identifier of the message containing the attachment to download", | ||
| }, | ||
| attachmentId: { | ||
| propDefinition: [ | ||
| microsoftOutlook, | ||
| "attachmentId", | ||
| (c) => ({ | ||
| messageId: c.messageId, | ||
| }), | ||
| ], | ||
| }, | ||
| filename: { | ||
| type: "string", | ||
| label: "Filename", | ||
| description: "The filename to save the attachment as in the /tmp directory", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.microsoftOutlook.getAttachment({ | ||
| $, | ||
| messageId: this.messageId, | ||
| attachmentId: this.attachmentId, | ||
| responseType: "arraybuffer", | ||
| }); | ||
|
|
||
| const rawcontent = response.toString("base64"); | ||
| const buffer = Buffer.from(rawcontent, "base64"); | ||
| const downloadedFilepath = `/tmp/${this.filename}`; | ||
| fs.writeFileSync(downloadedFilepath, buffer); | ||
| const contentType = mime.lookup(downloadedFilepath); | ||
|
|
||
| return { | ||
| fileName: this.filename, | ||
| contentType, | ||
| filePath: downloadedFilepath, | ||
| }; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
components/microsoft_outlook/sources/common/common-new-email.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import common from "./common.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| props: { | ||
| ...common.props, | ||
| folderIds: { | ||
| propDefinition: [ | ||
| common.props.microsoftOutlook, | ||
| "folderIds", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| hooks: { | ||
| ...common.hooks, | ||
| async deploy() { | ||
| this.db.set("sentItemFolderId", await this.getFolderIdByName("Sent Items")); | ||
| this.db.set("draftsFolderId", await this.getFolderIdByName("Drafts")); | ||
|
|
||
| const events = await this.getSampleEvents({ | ||
| pageSize: 25, | ||
| }); | ||
| if (!events || events.length == 0) { | ||
| return; | ||
| } | ||
| for (const item of events) { | ||
| this.emitEvent(item); | ||
| } | ||
| }, | ||
| async activate() { | ||
| await this.activate({ | ||
| changeType: "created", | ||
| resource: "/me/messages", | ||
| }); | ||
| }, | ||
| async deactivate() { | ||
| await this.deactivate(); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| async getFolderIdByName(name) { | ||
| const { value: folders } = await this.microsoftOutlook.listFolders(); | ||
| const folder = folders.find(({ displayName }) => displayName === name); | ||
| return folder?.id; | ||
| }, | ||
| isRelevant(item) { | ||
| if (this.folderIds?.length) { | ||
| return this.folderIds.includes(item.parentFolderId); | ||
| } | ||
| // if no folderIds are specified, filter out items in Sent Items & Drafts | ||
| const sentItemFolderId = this.db.get("sentItemFolderId"); | ||
| const draftsFolderId = this.db.get("draftsFolderId"); | ||
| return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId; | ||
| }, | ||
| }, | ||
| }; | ||
2 changes: 1 addition & 1 deletion
2
...ents/microsoft_outlook/sources/common.mjs → ...crosoft_outlook/sources/common/common.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.