-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheasyEws1.0.14.min.js
1 lines (1 loc) · 15.1 KB
/
easyEws1.0.14.min.js
1
function __nonInstanceEasyEwsClass(){function e(e,t,n,s){this.name=e,this.emailAddress=t,this.routiingType=n,this.mailboxType=s}function t(){if(0==l.length||m>100)a(u);else{var e=l.pop();d.push(e),easyEws.expandGroup(e,function(e){for(var n=0;n<e.length;n++){var s=e[n];if("PublicDL"==s.MailboxType()||"PrivateDL"==s.MailboxType())d.indexOf(s.Address)<0&&l.indexOf(s.Address)<0&&(m++,l.push(s.Address));else{for(var i=!1,a=0;a<u.length;a++){var r=u[a];if(r.Address==s.Address){i=!0;break}}0==i&&u.push(s)}}t()},function(e){r(e)},function(e){o(e)})}}function n(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 s(e,t,n,s){Office.context.mailbox.makeEwsRequestAsync(e,function(i){if("succeeded"==i.status){var a=$.parseXML(i.value);t(a),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 i(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 a,r,o,l=[],d=[],u=[],m=0;this.getParentId=function(e,t,a,r){var o='<m:GetItem> <m:ItemShape> <t:BaseShape>AllProperties</t:BaseShape> </m:ItemShape> <m:ItemIds> <t:ItemId Id="'+e+'"/> </m:ItemIds></m:GetItem>';o=n(o),s(o,function(e){var l="";try{l=i(e,"t:InReplyTo")[0].textContent}catch{return void t(null)}l=l.replace("<","<").replace(">",">"),o='<m:FindItem Traversal="Shallow">\t<m:ItemShape>\t\t<t:BaseShape>IdOnly</t:BaseShape>\t</m:ItemShape>\t<m:IndexedPageItemView MaxEntriesReturned="50" Offset="0" BasePoint="Beginning" />\t<m:Restriction>\t\t<t:Contains ContainmentMode="Substring" ContainmentComparison="IgnoreCase">\t\t\t<t:FieldURI FieldURI="message:InternetMessageId" />\t\t\t<t:Constant Value="'+l+'" />\t\t</t:Contains>\t</m:Restriction>\t<m:ParentFolderIds>\t\t<t:DistinguishedFolderId Id="inbox" />\t</m:ParentFolderIds></m:FindItem>',o=n(o),s(o,function(e){var n=i(e,"t:ItemId")[0].attributes.Id.value;t&&t(n)},function(e){a&&a(e)},function(e){r&&r(e)})},function(e){a&&a(e)},function(e){r&&r(e)})},this.resolveRecipient=function(t,a,r,o){var l='<ResolveNames xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" ReturnFullContactData="true"><UnresolvedEntry>'+t+"</UnresolvedEntry></ResolveNames>";l=n(l),s(l,function(t){if(a){var n=i(t,"m:MessageText");if(null!=n&&n.length>0&&"No results were found."==n[0].innerHTML)a(null);else{var s=[],r=i(t,"t:Mailbox");$.each(r,function(t,n){var a=i(n,"t:Name")[0].textContent,r=i(n,"t:EmailAddress")[0].textContent,o=i(n,"t:RoutingType")[0].textContent,l=i(n,"t:MailboxType")[0].textContent,d=new e(a,r,o,l);s.push(d)}),a(s)}}},function(e){null!=r&&r(e)},function(e){null!=o&&o(e)})},this.sendPlainTextEmailWithAttachment=function(e,t,i,a,r,o,l,d){var u='<m:CreateItem MessageDisposition="SendAndSaveCopy"> <m:Items> <t:Message> <t:Subject>'+e+'</t:Subject> <t:Body BodyType="Text">'+t+"</t:Body> <t:Attachments> <t:ItemAttachment> <t:Name>"+a+'</t:Name> <t:IsInline>false</t:IsInline> <t:Message> <t:MimeContent CharacterSet="UTF-8">'+r+"</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=n(u),s(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,t,a,r){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=n(o),s(o,function(e){var n=i(e,"t:MimeContent"),s=n[0].textContent;t(s)},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.updateEwsHeader=function(e,t,i,a,r,o,l){var d='<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">';a&&(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="'+t+'" PropertyType="String" /> <t:Message> <t:ExtendedProperty> <t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="'+t+'" PropertyType="String" /> <t:Value>'+i+"</t:Value> </t:ExtendedProperty> </t:Message> </t:SetItemField> </t:Updates> </t:ItemChange> </m:ItemChanges></m:UpdateItem>";u=n(u),s(u,function(e){r&&r("succeeded")},function(e){null!=o&&o(e)},function(e){null!=l&&l(e)})},this.getFolderItemIds=function(e,t,a,r){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=n(o),s(o,function(e){var n=i(e,"t:ItemId");$.each(n,function(e,t){l.push(t.getAttribute("Id"))}),t(l)},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.getMailItem=function(e,t,i,a){var r='<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>';r=n(r),s(r,function(e){var n=new MailItem(e);t(n)},function(e){null!=i&&i(e)},function(e){null!=a&&a(e)})},this.splitGroupsAsync=function(e,n,s,i){l=[],u=[],d=[],m=0,l.push(e),a=n,r=s,o=i,t()},this.expandGroup=function(e,t,a,r){var o="<m:ExpandDL> <m:Mailbox> <t:EmailAddress>"+e+"</t:EmailAddress> </m:Mailbox></m:ExpandDL>";o=n(o);var l=[];s(o,function(e){var n=i(e,"t:Mailbox");$.each(n,function(e,t){l.push(new MailboxUser(t))}),t(l)},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.findConversationItems=function(e,t,a,r){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=n(o),s(o,function(e){var n=[];try{var s=i(e,"t:ItemId");null==s?null!=a&&a(new Error("The XML returned from the server could not be parsed.")):0==s.length?t(null):($.each(s,function(e,t){n.push(t.getAttribute("Id"))}),t(n))}catch(e){null!=a&&a(e)}},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.getSpecificHeader=function(e,t,a,r,o,l){var d=' <m:GetItem> <m:ItemShape> <t:BaseShape>IdOnly</t:BaseShape> <t:AdditionalProperties> <t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="'+t+'" PropertyType="'+a+'" /> </t:AdditionalProperties> </m:ItemShape> <m:ItemIds> <t:ItemId Id="'+e+'" /> </m:ItemIds> </m:GetItem>';d=n(d);var u="";s(d,function(e){try{if(null==e)return void r(null);var n=i(e,"t:ExtendedProperty");$.each(n,function(e,n){var s=i(n,"t:ExtendedFieldURI")[0].getAttribute("PropertyName"),a=i(n,"t:Value")[0].textContent;s==t&&(u=a)}),r(u)}catch(e){null!=o&&o(e)}},function(e){null!=o&&o(e)},function(e){null!=l&&l(e)})},this.getEwsHeaders=function(e,t,a,r){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=n(o);var l=new Dictionary;s(o,function(e){try{if(null==e)return void t(null);var n=i(e,"t:InternetMessageHeader");$.each(n,function(e,t){l.add(t.getAttribute("HeaderName"),t.textContent)}),t(l)}catch(e){null!=a&&a(e)}},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.updateFolderProperty=function(e,t,i,a,r,o){var l=' <m:UpdateFolder> <m:FolderChanges> <t:FolderChange> <t:FolderId Id="'+e+'" /> <t:Updates> <t:SetFolderField> <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="'+t+'" PropertyType="String" /> <t:Folder> <t:ExtendedProperty> <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="'+t+'" PropertyType="String" /> <t:Value>'+i+"</t:Value> </t:ExtendedProperty> </t:Folder> </t:SetFolderField> </t:Updates> </t:FolderChange> </m:FolderChanges> </m:UpdateFolder>";l=n(l),s(l,function(e){null!=a&&a("succeeeded")},function(e){null!=r&&r(e)},function(e){null!=o&&o(e)})},this.getFolderProperty=function(e,t,a,r,o){var l='<m:GetFolder><m:FolderShape><t:BaseShape>IdOnly</t:BaseShape><t:AdditionalProperties><t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="'+t+'" PropertyType="String" /></t:AdditionalProperties></m:FolderShape><m:FolderIds><t:FolderId Id="'+e+'"/></m:FolderIds></m:GetFolder>';l=n(l),s(l,function(e){var t=i(e,"t:Value");t.length>0?a(t[0].textContent):a(null)},function(e){null!=r&&r(e)},function(e){null!=o&&o(e)})},this.getFolderId=function(e,t,a,r){var o=' <m:GetFolder> <m:FolderShape> <t:BaseShape>IdOnly</t:BaseShape> </m:FolderShape> <m:FolderIds> <t:DistinguishedFolderId Id="'+e+'" /> </m:FolderIds> </m:GetFolder>';o=n(o),s(o,function(e){var n=i(e,"t:FolderId");if(n.length>0){var s=n[0].getAttribute("Id");t(s)}else a("Unable to get folder ID")},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.moveItem=function(e,t,i,a,r){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="'+t+'"/> </ToFolderId> <ItemIds> <t:ItemId Id="'+e+'"/> </ItemIds></MoveItem>';o=n(o),s(o,function(e){null!=i&&i("succeeeded")},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.getAllRecipientsAsync=function(e,t,n){var s=[],i=[];e.to.getAsync(function(a){if(a.error)n(error);else{var r=a.value;r.length>0&&r.forEach(function(e,t){if(e.recipientType==Office.MailboxEnums.RecipientType.DistributionList){for(var n=!1,a=0;a<i.length;a++){var r=i[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||i.push(e)}else{for(n=!1,a=0;a<s.length;a++){r=s[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}}),e.cc.getAsync(function(a){if(a.error)n(error);else{var r=a.value;r.length>0&&r.forEach(function(e,t){if(e.recipientType==Office.MailboxEnums.RecipientType.DistributionList){for(var n=!1,a=0;a<i.length;a++){var r=i[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||i.push(e)}else{for(n=!1,a=0;a<s.length;a++){r=s[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}}),e.bcc.getAsync(function(e){if(e.error)n(error);else{var a=e.value;a.length>0?(a.forEach(function(e,t){if(e.recipientType==Office.MailboxEnums.RecipientType.DistributionList){for(var n=!1,a=0;a<i.length;a++){var r=i[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||i.push(e)}else{for(n=!1,a=0;a<s.length;a++){r=s[a];if(r.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){};