forked from davecra/easyEWS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasyEws1.0.10.min.js
1 lines (1 loc) · 13.3 KB
/
easyEws1.0.10.min.js
1
function __nonInstanceEasyEwsClass(){function e(){if(0==o.length||u>100)i(d);else{var t=o.pop();l.push(t),easyEws.expandGroup(t,function(t){t.forEach(function(e,t){if("PublicDL"==e.MailboxType()||"PrivateDL"==e.MailboxType())l.indexOf(e.Address)<0&&o.indexOf(e.Address)<0&&(u++,o.push(e.Address));else{for(var n=!1,s=0;s<d.length;s++){var i=d[s];if(i.Address==e.Address){n=!0;break}}0==n&&d.push(e)}}),e()},function(e){r(e)},function(e){a(e)})}}function t(e){var t='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> <soap:Header> <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" /> </soap:Header> <soap:Body>'+e+"</soap:Body></soap:Envelope>";return t}function n(e,t,n,s){Office.context.mailbox.makeEwsRequestAsync(e,function(i){if("succeeded"==i.status){var r=$.parseXML(i.value);t(r),s("STATUS: "+i.status+"\n---- START SOAP ----\n"+e+"\n---- END SOAP ----\n---- START RESPONSE ----\n"+i.value+"---- END RESPONSE ----")}else null!=n&&(n("makeEwsRequestAsync failed. "+i.error),s("STATUS: "+i.status+"\nERROR: "+i.error+"\n---- START SOAP ----\n"+e+"\n---- END SOAP ----\n---- START RESPONSE ----\n"+i.value+"---- END RESPONSE ----"))})}function s(e,t){var n=t.substring(t.indexOf(":")+1),s=e.getElementsByTagName(t);return null!=s&&0!=s.length||(s=e.getElementsByTagName(n)),s}var i,r,a,o=[],l=[],d=[],u=0;this.sendPlainTextEmailWithAttachment=function(e,s,i,r,a,o,l,d){var u='<m:CreateItem MessageDisposition="SendAndSaveCopy"> <m:Items> <t:Message> <t:Subject>'+e+'</t:Subject> <t:Body BodyType="Text">'+s+"</t:Body> <t:Attachments> <t:ItemAttachment> <t:Name>"+r+'</t:Name> <t:IsInline>false</t:IsInline> <t:Message> <t:MimeContent CharacterSet="UTF-8">'+a+"</t:MimeContent> </t:Message> </t:ItemAttachment> </t:Attachments> <t:ToRecipients><t:Mailbox><t:EmailAddress>"+i+"</t:EmailAddress></t:Mailbox></t:ToRecipients> </t:Message> </m:Items></m:CreateItem>";u=t(u),n(u,function(e){var t=e.getElementsByTagName("m:ResponseCode")[0];null==t&&(t=e.getElementsByTagName("ResponseCode")[0]);var n=t.textContent;"NoError"==n?o(n):null!=l&&l(n)},function(e){null!=l&&l(e)},function(e){null!=d&&d(e)})},this.getMailItemMimeContent=function(e,i,r,a){var o='<m:GetItem> <m:ItemShape> <t:BaseShape>IdOnly</t:BaseShape> <t:IncludeMimeContent>true</t:IncludeMimeContent> </m:ItemShape> <m:ItemIds> <t:ItemId Id="'+e+'"/> </m:ItemIds></m:GetItem>';o=t(o),n(o,function(e){var t=s(e,"t:MimeContent"),n=t[0].textContent;i(n)},function(e){null!=r&&r(e)},function(e){null!=a&&a(e)})},this.updateEwsHeader=function(e,s,i,r,a,o,l){var d='<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">';r&&(d='<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendOnlyToChanged">');var u=d+' <m:ItemChanges> <t:ItemChange> <t:ItemId Id="'+e+'"/> <t:Updates> <t:SetItemField> <t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="'+s+'" PropertyType="String" /> <t:Message> <t:ExtendedProperty> <t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="'+s+'" PropertyType="String" /> <t:Value>'+i+"</t:Value> </t:ExtendedProperty> </t:Message> </t:SetItemField> </t:Updates> </t:ItemChange> </m:ItemChanges></m:UpdateItem>";u=t(u),n(u,function(e){a&&a("succeeded")},function(e){null!=o&&o(e)},function(e){null!=l&&l(e)})},this.getFolderItemIds=function(e,i,r,a){var o='<m:FindItem Traversal="Shallow"> <m:ItemShape> <t:BaseShape>IdOnly</t:BaseShape> </m:ItemShape> <m:ParentFolderIds> <t:FolderId Id="'+e+'"/> </m:ParentFolderIds></m:FindItem>',l=[];o=t(o),n(o,function(e){var t=s(e,"t:ItemId");$.each(t,function(e,t){l.push(t.getAttribute("Id"))}),i(l)},function(e){null!=r&&r(e)},function(e){null!=a&&a(e)})},this.getMailItem=function(e,s,i,r){var a='<m:GetItem> <m:ItemShape> <t:BaseShape>Default</t:BaseShape> <t:IncludeMimeContent>true</t:IncludeMimeContent> </m:ItemShape> <m:ItemIds> <t:ItemId Id="'+e+'" /> </m:ItemIds></m:GetItem>';a=t(a),n(a,function(e){var t=new MailItem(e);s(t)},function(e){null!=i&&i(e)},function(e){null!=r&&r(e)})},this.splitGroupsAsync=function(t,n,s,m){o=[],d=[],l=[],u=0,o.push(t),i=n,r=s,a=m,e()},this.expandGroup=function(e,i,r,a){var o="<m:ExpandDL> <m:Mailbox> <t:EmailAddress>"+e+"</t:EmailAddress> </m:Mailbox></m:ExpandDL>";o=t(o);var l=[];n(o,function(e){var t=s(e,"t:Mailbox");$.each(t,function(e,t){l.push(new MailboxUser(t))}),i(l)},function(e){null!=r&&r(e)},function(e){null!=a&&a(e)})},this.findConversationItems=function(e,i,r,a){var o=' <m:GetConversationItems> <m:ItemShape> <t:BaseShape>IdOnly</t:BaseShape> <t:AdditionalProperties> <t:FieldURI FieldURI="item:Subject" /> <t:FieldURI FieldURI="item:DateTimeReceived" /> </t:AdditionalProperties> </m:ItemShape> <m:FoldersToIgnore> <t:DistinguishedFolderId Id="deleteditems" /> <t:DistinguishedFolderId Id="drafts" /> </m:FoldersToIgnore> <m:SortOrder>TreeOrderDescending</m:SortOrder> <m:Conversations> <t:Conversation> <t:ConversationId Id="'+e+'" /> </t:Conversation> </m:Conversations> </m:GetConversationItems>';o=t(o),n(o,function(e){var t=[];try{var n=s(e,"t:ItemId");null==n?null!=r&&r(new Error("The XML returned from the server could not be parsed.")):0==n.length?i(null):($.each(n,function(e,n){t.push(n.getAttribute("Id"))}),i(t))}catch(e){null!=r&&r(e)}},function(e){null!=r&&r(e)},function(e){null!=a&&a(e)})},this.getSpecificHeader=function(e,i,r,a,o,l){var d=' <m:GetItem> <m:ItemShape> <t:BaseShape>IdOnly</t:BaseShape> <t:AdditionalProperties> <t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="'+i+'" PropertyType="'+r+'" /> </t:AdditionalProperties> </m:ItemShape> <m:ItemIds> <t:ItemId Id="'+e+'" /> </m:ItemIds> </m:GetItem>';d=t(d);var u="";n(d,function(e){try{if(null==e)return void a(null);var t=s(e,"t:ExtendedProperty");$.each(t,function(e,t){var n=s(t,"t:ExtendedFieldURI")[0].getAttribute("PropertyName"),r=s(t,"t:Value")[0].textContent;n==i&&(u=r)}),a(u)}catch(e){null!=o&&o(e)}},function(e){null!=o&&o(e)},function(e){null!=l&&l(e)})},this.getEwsHeaders=function(e,i,r,a){var o=' <m:GetItem> <m:ItemShape> <t:BaseShape>AllProperties</t:BaseShape> <t:IncludeMimeContent>true</t:IncludeMimeContent> </m:ItemShape> <m:ItemIds> <t:ItemId Id="'+e+'" /> </m:ItemIds> </m:GetItem>';o=t(o);var l=new Dictionary;n(o,function(e){try{if(null==e)return void i(null);var t=s(e,"t:InternetMessageHeader");$.each(t,function(e,t){l.add(t.getAttribute("HeaderName"),t.textContent)}),i(l)}catch(e){null!=r&&r(e)}},function(e){null!=r&&r(e)},function(e){null!=a&&a(e)})},this.updateFolderProperty=function(e,s,i,r,a,o){var l=' <m:UpdateFolder> <m:FolderChanges> <t:FolderChange> <t:FolderId Id="'+e+'" /> <t:Updates> <t:SetFolderField> <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="'+s+'" PropertyType="String" /> <t:Folder> <t:ExtendedProperty> <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="'+s+'" PropertyType="String" /> <t:Value>'+i+"</t:Value> </t:ExtendedProperty> </t:Folder> </t:SetFolderField> </t:Updates> </t:FolderChange> </m:FolderChanges> </m:UpdateFolder>";l=t(l),n(l,function(e){null!=r&&r("succeeeded")},function(e){null!=a&&a(e)},function(e){null!=o&&o(e)})},this.getFolderProperty=function(e,i,r,a,o){var l='<m:GetFolder><m:FolderShape><t:BaseShape>IdOnly</t:BaseShape><t:AdditionalProperties><t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="'+i+'" PropertyType="String" /></t:AdditionalProperties></m:FolderShape><m:FolderIds><t:FolderId Id="'+e+'"/></m:FolderIds></m:GetFolder>';l=t(l),n(l,function(e){var t=s(e,"t:Value");r(t.length>0?t[0].textContent:null)},function(e){null!=a&&a(e)},function(e){null!=o&&o(e)})},this.getFolderId=function(e,i,r,a){var o=' <m:GetFolder> <m:FolderShape> <t:BaseShape>IdOnly</t:BaseShape> </m:FolderShape> <m:FolderIds> <t:DistinguishedFolderId Id="'+e+'" /> </m:FolderIds> </m:GetFolder>';o=t(o),n(o,function(e){var t=s(e,"t:FolderId");if(t.length>0){var n=t[0].getAttribute("Id");i(n)}else r("Unable to get folder ID")},function(e){null!=r&&r(e)},function(e){null!=a&&a(e)})},this.moveItem=function(e,s,i,r,a){var o='<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> <ToFolderId> <t:DistinguishedFolderId Id="'+s+'"/> </ToFolderId> <ItemIds> <t:ItemId Id="'+e+'"/> </ItemIds></MoveItem>';o=t(o),n(o,function(e){null!=i&&i("succeeeded")},function(e){null!=r&&r(e)},function(e){null!=a&&a(e)})},this.getAllRecipientsAsync=function(e,t,n){var s=[],i=[];e.to.getAsync(function(r){if(r.error)n(error);else{var a=r.value;a.length>0&&a.forEach(function(e,t){if(e.recipientType==Office.MailboxEnums.RecipientType.DistributionList){for(var n=!1,r=0;r<i.length;r++){var a=i[r];if(a.emailAddress==e.emailAddress){n=!0;break}}n||i.push(e)}else{for(var n=!1,r=0;r<s.length;r++){var a=s[r];if(a.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}}),e.cc.getAsync(function(r){if(r.error)n(error);else{var a=r.value;a.length>0&&a.forEach(function(e,t){if(e.recipientType==Office.MailboxEnums.RecipientType.DistributionList){for(var n=!1,r=0;r<i.length;r++){var a=i[r];if(a.emailAddress==e.emailAddress){n=!0;break}}n||i.push(e)}else{for(var n=!1,r=0;r<s.length;r++){var a=s[r];if(a.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}}),e.bcc.getAsync(function(e){if(e.error)n(error);else{var r=e.value;r.length>0?(r.forEach(function(e,t){if(e.recipientType==Office.MailboxEnums.RecipientType.DistributionList){for(var n=!1,r=0;r<i.length;r++){var a=i[r];if(a.emailAddress==e.emailAddress){n=!0;break}}n||i.push(e)}else{for(var n=!1,r=0;r<s.length;r++){var a=s[r];if(a.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}}),t(s,i)):t(s,i)}})}})}})}}function MailItem(e){this.value=e||{},this.MimeContent=function(){return this.value.getElementsByTagName("t:MimeContent")[0].textContent},this.CharacterSet=function(){return this.value.getElementsByTagName("t:MimeContent")[0].getAttribute("CharacterSet")},this.Subject=function(){return this.value.getElementsByTagName("t:Subject")[0].textContent},this.Body=function(){return this.value.getElementsByTagName("t:Body")[0].textContent}}function MailboxUser(e){this.value=e||{},this.Name=function(){return this.value.getElementsByTagName("t:Name")[0].textContent},this.Address=function(){return this.value.getElementsByTagName("t:EmailAddress")[0].textContent},this.RoutingType=function(){return this.value.getElementsByTagName("t:RoutingType")[0].textContent},this.MailboxType=function(){return this.value.getElementsByTagName("t:MailboxType")[0].textContent}}function Dictionary(e){this.values=e||{};var t=function(e,t){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t(n,e[n])};this.containsKey=function(e){return Object.prototype.hasOwnProperty.call(this.values,e)&&Object.prototype.propertyIsEnumerable.call(this.values,e)},this.forEach=function(e){t(this.values,e)},this.lookup=function(e){return this.values[e]},this.add=function(e,t){this.values[e]=t},this.length=function(){var e=0;return t(this.values,function(){e++}),e}}var easyEws=new __nonInstanceEasyEwsClass,successCallback=function(e){},successCallbackMailItem=function(e){},successCallbackArray=function(e){},successCallbackMailboxUserArray=function(e){},successCallbackDictionary=function(e){},errorCallback=function(e){},debugCallback=function(e){},getAllRecipientsCallbackDelegate=function(e,t){};