-
Notifications
You must be signed in to change notification settings - Fork 4
/
easyEws1.0.20.min.js
1 lines (1 loc) · 16.6 KB
/
easyEws1.0.20.min.js
1
function __nonInstanceEasyEwsClass(){function e(e,t,n,i){this.name=e,this.emailAddress=t,this.routiingType=n,this.mailboxType=i}function t(){if(0==l.length||u>100)a(m);else{var e=l.pop();d.push(e),easyEws.expandGroup(e,function(e){for(var n=0;n<e.length;n++){var i=e[n];if("PublicDL"==i.MailboxType()||"PrivateDL"==i.MailboxType())d.indexOf(i.Address())<0&&l.indexOf(i.Address())<0&&(u++,l.push(i.Address()));else{for(var s=!1,a=0;a<m.length;a++){var r=m[a];if(r.Address()==i.Address()){s=!0;break}}0==s&&m.push(i)}}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 i(e,t,n,i){Office.context.mailbox.makeEwsRequestAsync(e,function(s){if("succeeded"==s.status){var a=new DOMParser,r=a.parseFromString(s.value,"text/xml");t(r),i("STATUS: "+s.status+"\n---- START SOAP ----\n"+e+"\n---- END SOAP ----\n---- START RESPONSE ----\n"+s.value+"---- END RESPONSE ----")}else null!=n&&(n("makeEwsRequestAsync failed. "+s.error),i("STATUS: "+s.status+"\nERROR: "+s.error+"\n---- START SOAP ----\n"+e+"\n---- END SOAP ----\n---- START RESPONSE ----\n"+s.value+"---- END RESPONSE ----"))})}function s(e,t){var n=t.substring(t.indexOf(":")+1),i=e.getElementsByTagName(t);return null!=i&&0!=i.length||(i=e.getElementsByTagName(n)),i}var a,r,o,l=[],d=[],m=[],u=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),i(o,function(e){var l="";try{l=s(e,"t:InReplyTo")[0].textContent}catch(e){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),i(o,function(e){var n=s(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),i(l,function(t){if(a){var n=s(t,"m:MessageText");if(null!=n&&n.length>0&&"No results were found."==n[0].innerHTML)a(null);else{for(var i=[],r=s(t,"t:Mailbox"),o=0;o<r.length;o++){var l=r[o],d=s(l,"t:Name")[0].textContent,m=s(l,"t:EmailAddress")[0].textContent,u=s(l,"t:RoutingType")[0].textContent,c=s(l,"t:MailboxType")[0].textContent,h=new e(d,m,u,c);i.push(h)}a(i)}}},function(e){null!=r&&r(e)},function(e){null!=o&&o(e)})},this.sendMailItem=function(e){var t=e.subject,s="html"==e.bodytype.toLowerCase()?"HTML":"Text",a="HTML"==s?escapeHTML(e.body):e.body,r=void 0!==e.recipients&&null!==e.recipients?e.recipients:[],o=void 0!==e.attachments&&null!==e.attachments?e.attachments:[new SimpleAttachmentObject("","")],l=void 0!==e.folderid&&null!==e.folderid&&""!==e.folderid?e.folderid:"sentitems",d=e.successCallback,m=e.errorCallback,u=e.debugCallback,c="";if(null!=r&&0!=r.length){if(r.forEach(function(e){c+="<t:Mailbox><t:EmailAddress>"+e+"</t:EmailAddress></t:Mailbox>"}),c="<t:ToRecipients>"+c+"</t:ToRecipients>",null!=o&&o.length>0){var h="";o.forEach(function(e){""!==e.name&&""!==e.mime&&("item"==e.type?h+="<t:ItemAttachment><t:Name>"+e.name+'</t:Name><t:IsInline>false</t:IsInline><t:Message><t:MimeContent CharacterSet="UTF-8">'+e.mime+"</t:MimeContent></t:Message></t:ItemAttachment>":h+="<t:FileAttachment><t:Name>"+e.name+"</t:Name><t:IsInline>false</t:IsInline><t:IsContactPhoto>false</t:IsContactPhoto><t:Content>"+e.mime+"</t:Content></t:FileAttachment>")}),""!==h&&(h="<t:Attachments>"+h+"</t:Attachments>")}var p='<m:SavedItemFolderId><t:DistinguishedFolderId Id="'+l+'" /></m:SavedItemFolderId>',I='<m:CreateItem MessageDisposition="SendAndSaveCopy">'+p+" <m:Items> <t:Message> <t:Subject>"+t+'</t:Subject> <t:Body BodyType="'+s+'">'+a+"</t:Body>"+h+c+" </t:Message> </m:Items></m:CreateItem>";I=n(I),i(I,function(e){var t=e.getElementsByTagName("m:ResponseCode")[0];null==t&&(t=e.getElementsByTagName("ResponseCode")[0]);var n=t.textContent;"NoError"==n?d(n):null!=m&&m(n)},function(e){null!=m&&m(e)},function(e){null!=u&&u(e)})}else m("No recipients defined.")},this.sendPlainTextEmailWithAttachment=function(e,t,n,i,s,a,r,o){var l=new SimpleAttachmentObject(i,s,"item"),d=new SendMailFunctionObject(e,t,"text",[n],[l],"sentitems",a,r,o);this.sendMailItem(d)},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),i(o,function(e){var n=s(e,"t:MimeContent"),i=n[0].textContent;t(i)},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.updateEwsHeader=function(e,t,s,a,r,o,l){var d='<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">';a&&(d='<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendOnlyToChanged">');var m=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>'+s+"</t:Value> </t:ExtendedProperty> </t:Message> </t:SetItemField> </t:Updates> </t:ItemChange> </m:ItemChanges></m:UpdateItem>";m=n(m),i(m,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),i(o,function(e){for(var n=s(e,"t:ItemId"),i=0;i<n.length;i++)l.push(n[i].getAttribute("Id"));t(l)},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.getMailItem=function(e,t,s,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),i(r,function(e){var n=new MailItem(e);t(n)},function(e){null!=s&&s(e)},function(e){null!=a&&a(e)})},this.splitGroupsAsync=function(e,n,i,s){l=[],m=[],d=[],u=0,l.push(e),a=n,r=i,o=s,t()},this.expandGroup=function(e,t,a,r){var o=e.replace("&","&").replace("&","&"),l="<m:ExpandDL> <m:Mailbox> <t:EmailAddress>"+o+"</t:EmailAddress> </m:Mailbox></m:ExpandDL>";l=n(l);var d=[];i(l,function(e){for(var n=s(e,"t:Mailbox"),i=0;i<n.length;i++)d.push(new MailboxUser(n[i]));t(d)},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),i(o,function(e){var n=[];try{var i=s(e,"t:ItemId");if(null==i)null!=a&&a(new Error("The XML returned from the server could not be parsed."));else if(0==i.length)t(null);else{for(var r=0;r<i.length;r++)n.push(i[r].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 m="";i(d,function(e){try{if(null==e)return void r(null);for(var n=s(e,"t:ExtendedProperty"),i=0;i<n.length;i++){var a=n[i],l=s(a,"t:ExtendedFieldURI")[0].getAttribute("PropertyName"),d=s(a,"t:Value")[0].textContent;l==t&&(m=d)}r(m)}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;i(o,function(e){try{if(null==e)return void t(null);var n=s(e,"t:InternetMessageHeader");if(null!==n&&null!=n){for(var i=0;i<n.length;i++)l.add(n[i].getAttribute("HeaderName"),n[i].textContent);t(l)}else t(null)}catch(e){null!=a&&a(e)}},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.updateFolderProperty=function(e,t,s,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>'+s+"</t:Value> </t:ExtendedProperty> </t:Folder> </t:SetFolderField> </t:Updates> </t:FolderChange> </m:FolderChanges> </m:UpdateFolder>";l=n(l),i(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),i(l,function(e){var t=s(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),i(o,function(e){var n=s(e,"t:FolderId");if(n.length>0){var i=n[0].getAttribute("Id");t(i)}else a("Unable to get folder ID")},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.moveItem=function(e,t,s,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),i(o,function(e){null!=s&&s("succeeeded")},function(e){null!=a&&a(e)},function(e){null!=r&&r(e)})},this.getAllRecipientsAsync=function(e,t,n){var i=[],s=[];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<s.length;a++){var r=s[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}else{for(n=!1,a=0;a<i.length;a++){r=i[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||i.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<s.length;a++){var r=s[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}else{for(n=!1,a=0;a<i.length;a++){r=i[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||i.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<s.length;a++){var r=s[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||s.push(e)}else{for(n=!1,a=0;a<i.length;a++){r=i[a];if(r.emailAddress==e.emailAddress){n=!0;break}}n||i.push(e)}}),t(i,s)):t(i,s)}})}})}})}}function SimpleAttachmentObject(e,t,n){this.name=e||"",this.mime=t||"",this.type=n||""}function SendMailFunctionObject(e,t,n,i,s,a,r,o,l){this.subject=e||"",this.body=t||"",this.bodytype=n||"text",this.recipients=null!=i?i:[""],this.attachments=null!=s?s:[new SimpleAttachmentObject("","")],this.folderid=null!=a&&""!==a?a:"sentitems",this.successCallback=r||{},this.errorCallback=o||{},this.debugCallback=l||{}}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}}function escapeHTML(e){var t=function(e){var t={"&":"&","<":"<",">":">",'"':"""};return t[e]||e};return e.replace(/[&<>"]/g,t)}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){};