Skip to content

Commit ccb4a51

Browse files
[Outlook] Map snippet to Office.AttachmentContent (#2279)
* Map snippet to Office.AttachmentContent * Run build script
1 parent 3bf5581 commit ccb4a51

File tree

12 files changed

+424
-364
lines changed

12 files changed

+424
-364
lines changed

docs/code-snippets/outlook-snippets.yaml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,38 +216,41 @@ Office.AttachmentsChangedEventArgs:interface:
216216
// Perform operations on the attachment that was added.
217217
}
218218
}
219-
Office.AttachmentContent#format:member:
219+
Office.AttachmentContent:interface:
220220
- |-
221-
const item = Office.context.mailbox.item;
222-
const options = {asyncContext: {currentItem: item}};
223-
item.getAttachmentsAsync(options, callback);
224-
225-
function callback(result) {
221+
Office.context.mailbox.item.getAttachmentsAsync((result) => {
226222
if (result.value.length > 0) {
227223
for (let i = 0 ; i < result.value.length ; i++) {
228-
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
224+
Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
229225
}
230226
}
231-
}
227+
});
232228
233229
function handleAttachmentsCallback(result) {
234-
// Parse string to be a url, an .eml file, a base64-encoded string, or an .icalendar file.
230+
// Identify if an attachment is a Base64-encoded string, .eml file, .icalendar file, or a URL.
235231
switch (result.value.format) {
236232
case Office.MailboxEnums.AttachmentContentFormat.Base64:
237233
// Handle file attachment.
234+
console.log("Attachment is a Base64-encoded string.");
238235
break;
239236
case Office.MailboxEnums.AttachmentContentFormat.Eml:
240237
// Handle email item attachment.
238+
console.log("Attachment is a message.");
241239
break;
242240
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
243241
// Handle .icalender attachment.
242+
console.log("Attachment is a calendar item.");
244243
break;
245244
case Office.MailboxEnums.AttachmentContentFormat.Url:
246245
// Handle cloud attachment.
246+
console.log("Attachment is a cloud attachment.");
247247
break;
248248
default:
249-
// Handle attachment formats that are not supported.
249+
// Handle attachment formats that aren't supported.
250250
}
251+
252+
// Log the content of the attachments as a string.
253+
console.log(result.value.content);
251254
}
252255
Office.Body#getAsync:member(1):
253256
- |-

docs/docs-ref-autogen/outlook/outlook/office.attachmentcontent.yml

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,50 @@ remarks: >-
1818
mode](https://learn.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points)<!--
1919
-->**: Compose or Read
2020
21+
22+
#### Examples
23+
24+
25+
```TypeScript
26+
27+
Office.context.mailbox.item.getAttachmentsAsync((result) => {
28+
if (result.value.length > 0) {
29+
for (let i = 0 ; i < result.value.length ; i++) {
30+
Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
31+
}
32+
}
33+
});
34+
35+
36+
function handleAttachmentsCallback(result) {
37+
// Identify if an attachment is a Base64-encoded string, .eml file, .icalendar file, or a URL.
38+
switch (result.value.format) {
39+
case Office.MailboxEnums.AttachmentContentFormat.Base64:
40+
// Handle file attachment.
41+
console.log("Attachment is a Base64-encoded string.");
42+
break;
43+
case Office.MailboxEnums.AttachmentContentFormat.Eml:
44+
// Handle email item attachment.
45+
console.log("Attachment is a message.");
46+
break;
47+
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
48+
// Handle .icalender attachment.
49+
console.log("Attachment is a calendar item.");
50+
break;
51+
case Office.MailboxEnums.AttachmentContentFormat.Url:
52+
// Handle cloud attachment.
53+
console.log("Attachment is a cloud attachment.");
54+
break;
55+
default:
56+
// Handle attachment formats that aren't supported.
57+
}
58+
59+
// Log the content of the attachments as a string.
60+
console.log(result.value.content);
61+
}
62+
63+
```
64+
2165
isPreview: false
2266
isDeprecated: false
2367
type: interface
@@ -73,41 +117,3 @@ properties:
73117
type: >-
74118
<xref uid="outlook!Office.MailboxEnums.AttachmentContentFormat:enum"
75119
/> | string
76-
description: |-
77-
78-
79-
#### Examples
80-
81-
```TypeScript
82-
const item = Office.context.mailbox.item;
83-
const options = {asyncContext: {currentItem: item}};
84-
item.getAttachmentsAsync(options, callback);
85-
86-
function callback(result) {
87-
if (result.value.length > 0) {
88-
for (let i = 0 ; i < result.value.length ; i++) {
89-
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
90-
}
91-
}
92-
}
93-
94-
function handleAttachmentsCallback(result) {
95-
// Parse string to be a url, an .eml file, a base64-encoded string, or an .icalendar file.
96-
switch (result.value.format) {
97-
case Office.MailboxEnums.AttachmentContentFormat.Base64:
98-
// Handle file attachment.
99-
break;
100-
case Office.MailboxEnums.AttachmentContentFormat.Eml:
101-
// Handle email item attachment.
102-
break;
103-
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
104-
// Handle .icalender attachment.
105-
break;
106-
case Office.MailboxEnums.AttachmentContentFormat.Url:
107-
// Handle cloud attachment.
108-
break;
109-
default:
110-
// Handle attachment formats that are not supported.
111-
}
112-
}
113-
```

docs/docs-ref-autogen/outlook_1_10/outlook/office.attachmentcontent.yml

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,50 @@ remarks: >-
1818
mode](https://learn.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points)<!--
1919
-->**: Compose or Read
2020
21+
22+
#### Examples
23+
24+
25+
```TypeScript
26+
27+
Office.context.mailbox.item.getAttachmentsAsync((result) => {
28+
if (result.value.length > 0) {
29+
for (let i = 0 ; i < result.value.length ; i++) {
30+
Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
31+
}
32+
}
33+
});
34+
35+
36+
function handleAttachmentsCallback(result) {
37+
// Identify if an attachment is a Base64-encoded string, .eml file, .icalendar file, or a URL.
38+
switch (result.value.format) {
39+
case Office.MailboxEnums.AttachmentContentFormat.Base64:
40+
// Handle file attachment.
41+
console.log("Attachment is a Base64-encoded string.");
42+
break;
43+
case Office.MailboxEnums.AttachmentContentFormat.Eml:
44+
// Handle email item attachment.
45+
console.log("Attachment is a message.");
46+
break;
47+
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
48+
// Handle .icalender attachment.
49+
console.log("Attachment is a calendar item.");
50+
break;
51+
case Office.MailboxEnums.AttachmentContentFormat.Url:
52+
// Handle cloud attachment.
53+
console.log("Attachment is a cloud attachment.");
54+
break;
55+
default:
56+
// Handle attachment formats that aren't supported.
57+
}
58+
59+
// Log the content of the attachments as a string.
60+
console.log(result.value.content);
61+
}
62+
63+
```
64+
2165
isPreview: false
2266
isDeprecated: false
2367
type: interface
@@ -73,41 +117,3 @@ properties:
73117
type: >-
74118
<xref uid="outlook!Office.MailboxEnums.AttachmentContentFormat:enum"
75119
/> | string
76-
description: |-
77-
78-
79-
#### Examples
80-
81-
```TypeScript
82-
const item = Office.context.mailbox.item;
83-
const options = {asyncContext: {currentItem: item}};
84-
item.getAttachmentsAsync(options, callback);
85-
86-
function callback(result) {
87-
if (result.value.length > 0) {
88-
for (let i = 0 ; i < result.value.length ; i++) {
89-
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
90-
}
91-
}
92-
}
93-
94-
function handleAttachmentsCallback(result) {
95-
// Parse string to be a url, an .eml file, a base64-encoded string, or an .icalendar file.
96-
switch (result.value.format) {
97-
case Office.MailboxEnums.AttachmentContentFormat.Base64:
98-
// Handle file attachment.
99-
break;
100-
case Office.MailboxEnums.AttachmentContentFormat.Eml:
101-
// Handle email item attachment.
102-
break;
103-
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
104-
// Handle .icalender attachment.
105-
break;
106-
case Office.MailboxEnums.AttachmentContentFormat.Url:
107-
// Handle cloud attachment.
108-
break;
109-
default:
110-
// Handle attachment formats that are not supported.
111-
}
112-
}
113-
```

docs/docs-ref-autogen/outlook_1_11/outlook/office.attachmentcontent.yml

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,50 @@ remarks: >-
1818
mode](https://learn.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points)<!--
1919
-->**: Compose or Read
2020
21+
22+
#### Examples
23+
24+
25+
```TypeScript
26+
27+
Office.context.mailbox.item.getAttachmentsAsync((result) => {
28+
if (result.value.length > 0) {
29+
for (let i = 0 ; i < result.value.length ; i++) {
30+
Office.context.mailbox.item.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
31+
}
32+
}
33+
});
34+
35+
36+
function handleAttachmentsCallback(result) {
37+
// Identify if an attachment is a Base64-encoded string, .eml file, .icalendar file, or a URL.
38+
switch (result.value.format) {
39+
case Office.MailboxEnums.AttachmentContentFormat.Base64:
40+
// Handle file attachment.
41+
console.log("Attachment is a Base64-encoded string.");
42+
break;
43+
case Office.MailboxEnums.AttachmentContentFormat.Eml:
44+
// Handle email item attachment.
45+
console.log("Attachment is a message.");
46+
break;
47+
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
48+
// Handle .icalender attachment.
49+
console.log("Attachment is a calendar item.");
50+
break;
51+
case Office.MailboxEnums.AttachmentContentFormat.Url:
52+
// Handle cloud attachment.
53+
console.log("Attachment is a cloud attachment.");
54+
break;
55+
default:
56+
// Handle attachment formats that aren't supported.
57+
}
58+
59+
// Log the content of the attachments as a string.
60+
console.log(result.value.content);
61+
}
62+
63+
```
64+
2165
isPreview: false
2266
isDeprecated: false
2367
type: interface
@@ -73,41 +117,3 @@ properties:
73117
type: >-
74118
<xref uid="outlook!Office.MailboxEnums.AttachmentContentFormat:enum"
75119
/> | string
76-
description: |-
77-
78-
79-
#### Examples
80-
81-
```TypeScript
82-
const item = Office.context.mailbox.item;
83-
const options = {asyncContext: {currentItem: item}};
84-
item.getAttachmentsAsync(options, callback);
85-
86-
function callback(result) {
87-
if (result.value.length > 0) {
88-
for (let i = 0 ; i < result.value.length ; i++) {
89-
result.asyncContext.currentItem.getAttachmentContentAsync(result.value[i].id, handleAttachmentsCallback);
90-
}
91-
}
92-
}
93-
94-
function handleAttachmentsCallback(result) {
95-
// Parse string to be a url, an .eml file, a base64-encoded string, or an .icalendar file.
96-
switch (result.value.format) {
97-
case Office.MailboxEnums.AttachmentContentFormat.Base64:
98-
// Handle file attachment.
99-
break;
100-
case Office.MailboxEnums.AttachmentContentFormat.Eml:
101-
// Handle email item attachment.
102-
break;
103-
case Office.MailboxEnums.AttachmentContentFormat.ICalendar:
104-
// Handle .icalender attachment.
105-
break;
106-
case Office.MailboxEnums.AttachmentContentFormat.Url:
107-
// Handle cloud attachment.
108-
break;
109-
default:
110-
// Handle attachment formats that are not supported.
111-
}
112-
}
113-
```

0 commit comments

Comments
 (0)