Outlook OfficeJS API cannot resolve content type if extension is in uppercase - outlook-web-addins

OfficeJS does not seem to be able to resolve the content type of a file if the file extension is uppercase. This can be easily reproduced by attaching a file with an uppercase file name (e.g. FOO.JPEG) and executing the following code:
window.Office.context.mailbox.item.attachments.forEach(function(file) { console.log("name: " + file.name + " type:" + file.contentType);})
Is this a bug?

Office.context.mailbox.item.attachments returns Array of AttachmentDetails. The AttachmentDetails represents an attachment on an item from the server and contains properties of the attachment, for example name, size, etc. One of the property is contentType. All of them are just the Exchange properties and whatever Exchange has set into those properties, the JavaScript API will gives you. For example, the following is the attachment with small letters extension ...
Exchange has completed the PR_ATTACH_MIME_TAG_W property with content type. If you will use Office Js API contentType will return this value. In the same time, the attachment with all CAPS (on our Exchange server) would not have the PR_ATTACH_MIME_TAG_W at all ...
This happen because Exchange doesn't have mapping "JPEG" extension. Obviously if you would use Office Js API contentType function it will return empty string. This is exactly what you observe.
To add this mapping you would need to refer to your System Administrator. As long as the mapping will be added to your environment, Exchange will be resolving this file extensions and Office Js API will deliver this value to you.

Related

How to get contents of a single file uploaded via Microsoft Forms using 'File Identifier'?

Desired Behaviour
Upload file using Microsoft Forms
Get file content
Create new file in new location
Delete original file
Actual Behaviour
I am getting error at step 2:
"body": {
"status": 404,
"message": "File not found\r\nclientRequestId: yadda-yadda\r\nserviceRequestId: yadda-yadda"
}
What I've Tried
In the Power Automate flow, the trigger is:
When a new response is submitted
The next action is:
Get response details
The Raw Outputs of this last action is essentially:
"body": {
"responder": "me#domain.com",
"submitDate": "7/5/2021 3:17:56 AM",
"my-text-field-01": "text string here",
"my-file-upload-field-01": [{.....}],
"my-file-upload-field-02": [{.....}],
"my-text-field-02": "text string here"
}
The file upload fields have this schema:
{
"name": "My File Name_Uploader Name.docx",
"link": "https://my-tenant.sharepoint.com/sites/my-team-site/_layouts/15/Doc.aspx?sourcedoc=%7B0F1C3107-32C9-4CEF-B4BA-87E57C9DC514%7D&file=My%20File%20Name_Uploader%20Name.docx&action=default&mobileredirect=true",
"id": "01NSAULIQHGEOA7SJS55GLJOUH4V6J3RIU",
"type": null,
"size": 20400,
"referenceId": "01NSAULISZJG7M56NSV5AIDUQFHG3BOBCH",
"driveId": "letters-and-numbers-here",
"status": 1,
"uploadSessionUrl": null
}
Strangely, the id or referenceId values in this object do not correspond with the Document ID that is displayed when looking at the document's properties in the SharePoint document library:
Anyhow, I can target the uploaded file properties with these expressions in the flow:
json(body('Get_response_details')?['random-letters-and-numbers'])[0]['name']
json(body('Get_response_details')?['random-letters-and-numbers'])[0]['driveId']
json(body('Get_response_details')?['random-letters-and-numbers'])[0]['id']
The next action I want to take is Get file content.
It seems this can be done via the following actions:
SharePoint Connectors
Get file content
Get file content using path
OneDrive for Business Connectors
Get file content
Get file content using path
I'd like to use Get file content (as it seems more dynamic than having to pass through a hardcoded path).
Several posts suggest the value I pass through to this action as the File ID should be a concatenation of driveId and id, ie:
driveId.id
Sources:
Move, rename a file submitted in a Microsoft Form
Working with files from the Forms "File Upload" question type
However, when I try the following:
I get the error:
"body": {
"status": 404,
"message": "File not found\r\nclientRequestId: yadda-yadda\r\nserviceRequestId: yadda-yadda"
}
Question
What should I be passing into Get file content as the File Identifier?
Edit 1
After reading this, perhaps File Identifier actually refers to a 'file path', ie:
/Shared Documents/Apps/Microsoft Forms/My Form Name/Question/My File Name.docx
Ergh, I tried the path above as the File Identifier (by using the UI to manually select the file) and it works - not sure how I can create it dynamically as passing in a dynamic file name does not work:
/Shared Documents/Apps/Microsoft Forms/My Form Name/Question/#{variables('file_upload_wor_document_name')}
Edit 2
The last code snippet works as File Identifier when using SharePoint's Get file content using path connector.
Would still appreciate any clarification on all the different types of id that are referred to in SharePoint/Power Automate/MS Graph etc and why driveId.id was suggested as the value to use in some places.
I am finding not having access to the relevant file id at different times is problematic, eg the Delete file action requires File Identifier to delete the file uploaded to Microsoft Forms - and I don't have access to that from the Get response details response.
You may find what you need by first getting the file metadata. When working with files uploaded through forms I sometimes use the following steps:
Parse JSON for the question related to the uploaded file(s).
Get File Metadata (in my example, using path)
Now you have the details for doing what you want. In my example to create a table in the uploaded XLXS file for other uses.
Example: Getting file metadata from MS/Forms Upload

How to convert REST API's request body of String datatype into JSON Object in Node JS and test that in Postman?

I have a Node JS application running with Express and mongodb. I have a use case where my device sends data to my server. It might be JSON data or Comma-Separated String(Only String, not CSV file). I need to check which type of data is coming and manipulate that to JSON if request body would be a String. When I was trying to display the data type of data being sent to the server, it's displaying as "object" even after giving the "String" data as input. And the operation is getting successful but data is not inserting into the database. Can anyone help me in resolving this issue?
Sample Payload(request.body) would be,
"heat:22,humidity:36,deviceId:sb-0001"
Expected response is,
{
"heat": "22",
"humidity": "36",
"deviceId": "sb-0001"
}
#Aravind Actually typeof will returns "string" if operand is a string.So please check whether the string is coming or not in body, because if it is null then typeof will return "object".
I need to check which type of data is coming and manipulate that to JSON ...
HTTP is build upon the media-type concept that defines the syntax used in the payload of that type as well as the semantics of the elements used within that payload. You might take a look at how HTML defines forms to get a grip what a media-type specification should include. Through content negotiation client and server agree on a common media-type and thus a representation format to exchange payloads for supported by both. This simply increases interoperability between the participants as they exchange data in well-defined, hopefully standardized, representation formats both understand and support.
Through Accept headers a receiver can state preferences on which types to receive, including a weighting scheme to indicate that a certain representation format is preferred over an other one but the recipient is also fine with the other one, while a Content-Type header will indicate the actual representation format being sent.
RFC 7111 defines text/csv for CSV based representations and RFC 8259 specifies application/json for JSON payload. As the sender hopefully knows what kind of document it sends to the receiver, you can use this information to distinguish the payload on the receiver side. Note however that according to Fielding true REST APIs must use representation formats that support hypertext-driven interaction flows to allow clients to take further actions upon the payload received without having to invoke some external documentation. Both, JSON and CSV, by default don't support such an interaction model, that is abreviated with the term HATEOAS. For your simple scenario the content type negotiation might though be sufficient enough to solve your needs.
In terms of processing CSV and converting the data to JSON this is simply a matter of splitting up the CSV string on the delimiter symbol (, in the sample) to key-value pairs and then splitting the key and values further on the : symbol and adding these to a new JSON object. There is also a csvtojson library available at NPM that you might utilize in such a case.

Adding Azure Information Protection Label to Powershell script using Outlook 2016

I'm trying to add a custom header for AIP's msip_labels to a Powershell script that I'm writing. I've figured out how to do this with .Net.SMTP using:
$message.Headers.Add("msip_labels","MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Enabled=True; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_SiteId=00000000-1111-2222-3333-444444444444; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Owner=user2#domain.tld; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_SetDate=$((Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")); MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Name=Internal; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Application Microsoft Azure Information Protection; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_ActionId ffffffff-5555-6666-7777-888888888888; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Extended_MSFT_Method Manual")
Based on research I've done this should work using Outlook 2016 in theory:
$Outlook = New-Object -ComObject Outlook.Application
$message = $Outlook.CreateItem(0)
$message.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels", "MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Enabled=True; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_SiteId=00000000-1111-2222-3333-444444444444; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Owner=user2#domain.tld; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_SetDate=$((Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")); MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Name=Internal; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Application=Microsoft Azure Information Protection; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_ActionId=ffffffff-5555-6666-7777-888888888888; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Extended_MSFT_Method=Manual")
$message.To = "user1#domain.tld"
$message.Cc = "user3#domain.tld"
$message.Subject = "Report"
$message.HTMLBody = #"
<p><font face = "Calibri" size = "3">Hello World</p></font>
"#
$reportMessage.Send()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Outlook) | Out-Null
I confirmed this using a MAPI viewer that this is what's used in Outlook itself with other emails I've sent using just Outlook. But, when I tried running this in my script I get this error:
Exception setting "SetProperty": Cannot convert the "MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Enabled=True; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_SiteId=00000000-1111-2222-3333-444444444444;
MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Owner=user2#domain.tld; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_SetDate=$((Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")); MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Name=Internal;
MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Application=Microsoft Azure Information Protection; MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_ActionId=ffffffff-5555-6666-7777-888888888888;
MSIP_Label_aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee_Extended_MSFT_Method=Manual" value of type "string" to type "Object".
At C:\emailtest.ps1:21 char:1
+ $message.PropertyAccessor.SetProperty("http://schemas.microsoft ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : RuntimeException
Which doesn't seem to make much sense it's suppose to be a string in the MAPI schema, so I'm not sure why it thinks it should be an object. I even tried converting those values to objects using ConvertFrom-String, but it didn't work. Any advice on this would be greatly appreciated.
Try to reduce the string length you pass as a value. Does it work correctly?
It seems you need to use a low-level API on which Outlook is based on - Extended MAPI. It doesn't have any restrictions on the string length unlike OOM if you use the OpenProperty method. Also, you may consider using any third-party wrapper around that API such as Redemption.
If you use PropertyAccessor, you must have good knowledge of exception handling logic. Below I list some roadblocks that you may run into:
The body and content of an attachment of an Outlook items are not accessible through PropertyAccessor.
The PropertyAccessor ignores any seconds of the date/time value
String properties are limited in size depending on the information store type.
Limitation: Personal Folders files (.pst) and Exchange offline folders files (.ost) cannot be more than 4,088 bytes.
Limitation: For direct online access to Exchange mailbox or Public Folders hierarchy, the limit is 16,372 bytes.
Binary properties only those whose values are under 4,088 byte can be retrieved or set. (If trying to use larger values, you get an out-of-memory error).
You may find the Don't stumble over a stone working with the PropertyAccessor and StorageItem classes in Outlook 2007 article helpful.
It worked for me by appending a null character at the end of the string ( "`0" ) This is required by type "PtypString", required by property.
https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcdata/0c77892e-288e-435a-9c49-be1c20c7afdb

How to send selected lnbox mail as a attachment through outlook addins using Atl/Com project in VC++

the following is my code:
_ApplicationPtr pApp(Application);
_MailItemPtr pNewMailItem;
pApp->CreateItem(olMailItem,(IDispatch**)&pNewMailItem);
pNewMailItem->put_BCC(L"mailid1");
pNewMailItem->put_Body(L"Mail Send from Visual C++/ATL");
pNewMailItem->put_To(L"mailid2");
pNewMailItem->Send();
I am able to send a new mail but not getting how to attach the selected inbox mail .
Please suggest me some references for proceeding further.
To attach an email you need to access the handle to the Attachmentsobject associated with your MailItem object, and attach your file with a call to Attachments::Add.
Here's a minimal working example. I haven't tested this particular code, so consider a kind of pseudo-code:
_ApplicationPtr pApp(Application);
_MailItemPtr pNewMailItem;
pApp->CreateItem(olMailItem,(IDispatch**)&pNewMailItem);
Outlook::AttachmentsPtr pAttachments;
pNewMailItem->get_Attachments(&pAttachments);
// you need to specify your own values for these parameters
ATL::CComVariant filePath(someFilePath);
ATL::CComVariant displayName("some name");
ATL::CComVariant type(Outlook::olByValue); // to attach a copy
ATL::CComVariant position(1); // add as 1st attachment
Outlook::AttachmentPtr pAttachment;
pAttachments->Add(filePath, displayName, type, position, &pAttachment);

How to display actual value of a property which is using property expansion

I require some help on being able to get around displaying an endpoint from a SOAP Request.
Below I have a piece of code which retrieves an endpoint from a SOAP Request named 'TestAvailability' and outputs it to a file (the code is within a groovy script step).
def endpoint = testRunner.testCase.getTestStepByName('TestStep').get
Now here is the catch, in the file it outputs the endpoint as so:
ENDPOINT: ${#Project#BASE_URL}this_is_the_endpoint
The reason it displays ${#Project#BASE_URL} is because this is a variable set at project level so that the user can select their relevant environment from a drop down menu and that value will be displayed for the variable: ${#Project#BASE_URL}
But I don't want the project variable to be displayed but instead its value like so if ${#Project#BASE_URL} is set to 'testenv'
ENDPOINT: testenv_this_is_the_endpoint
My question is how do I change the code in order to display the endpoint correctly when outputted to a file?
You have a trivial issue. Since it is using property expansion in the endpoint, it request to expand it.
All you need is to change below statement
From:
testResult.append "\n\nENDPOINT: " +endpoint
To:
testResult.append "\n\nENDPOINT: ${context.expand(endpoint)}"

Resources