Closed carera closed 4 years ago
I figured out it can be worked around with manually adding t:
prefix to the elements:
Restriction: {
't:IsEqualTo': {
't:FieldURI': {attributes: {FieldURI: 'message:IsRead'}},
't:FieldURIOrConstant': {
't:Constant': {attributes: {Value: 'false'}}
}
}
},
I am not sure what are the t:
prefixes, but it seems they are required and the processing procedure does not add them
Glad you got it figured out!
t: = Type m: = Message
Those are supposed to be automatically prefixed when forming the XML, but as seen in issue #61 it doesn't always seem to do so. I haven't had time to investigate where the issue is (I suspect it to be something in the node-soap library) so for now manually adding the prefix is the appropriate workaround.
After this I need to call GetItem to get the body of email. Can you provide the pointer how to integrate "GetItem" and "FindItem" integrated together in single program using this node-ews framework. Any pointer will be appreciated...
@carera what ews function did you use to retreive emails, im using expandDL but no messages are returned.
ews.run(ewsFunction, ewsArgs).then(result => {
console.log(JSON.stringify(result.ResponseMessages));
console.log(JSON.stringify(result.ResponseMessages.FindItemResponseMessage.RootFolder.Items));
if (!result.ResponseMessages.FindItemResponseMessage.RootFolder.Items.Message.length) {
result.ResponseMessages.FindItemResponseMessage.RootFolder.Items.Message = [result.ResponseMessages.FindItemResponseMessage.RootFolder.Items.Message]
}
async.eachSeries(result.ResponseMessages.FindItemResponseMessage.RootFolder.Items.Message, function(item, eachCallback){
console.log('item.ItemId ==>', item.ItemId);
getItem(item.ItemId.attributes, function(){
eachCallback();
});
})
}).catch(err => {
console.log(err.stack);
});
var getItem = function(item, callback){
const ewsFunction = 'GetItem';
const ewsArgs = {
'ItemShape': {
'BaseShape': 'Default',
'IncludeMimeContent':'true'
},
"ItemIds" : {
"ItemId" : {
"attributes": {
"ChangeKey" : item.ChangeKey,
"Id" : item.Id
}
},
}
};
ews.run(ewsFunction, ewsArgs).then(result => {
console.log(JSON.stringify(result));
callback(result)
}).catch(err => {
console.log(err.stack);
callback(err);
});
}
var readEmail = function(limit, isRead){
const ewsFunction = 'FindItem';
isRead = !!isRead;
//limit = limit
const ewsArgs = {
'attributes': {
'Traversal': 'Shallow'
},
'ItemShape': {
'BaseShape': 'IdOnly'
},
'ParentFolderIds' : {
'DistinguishedFolderId': {
'attributes': {
'Id': 'inbox'
}
}
},
'AdditionalProperties':[{
'FieldURI':{
'attributes': {
'FieldURI': 'item:Subject'
}
},
'FieldURI':{
'attributes': {
'FieldURI': 'message:IsRead'
}
}
}],
'Restriction':{
't:IsEqualTo':{
't:FieldURI':{
'attributes': {
'FieldURI': 'message:IsRead'
}
},
't:FieldURIOrConstant':{
't:Constant':{
'attributes': {
'Value': isRead.toString()
},
}
}
}
},
'IndexedPageItemView': {
'attributes': {
'BasePoint': 'Beginning',
'Offset': '0',
'MaxEntriesReturned': limit.toString()
}
}
};
Hi all, I am trying to fetch all unread emails in mailbox:
But the restriction element just does not work and the result fetches all emails regardless of their read status. I have also tried the
IsEqualTo
to be an object:I have also tried similar approach as with multiple tags of identical name (https://github.com/CumberlandGroup/node-ews/issues/65):
But still got the same result. Any ideas?