UNPKG

@nocobase/plugin-workflow-mailer

Version:
1 lines 217 kB
(function(){"use strict";var e={54:function(e){function _handleAddress(e){let t;let i=false;let a="text";let s;let n=[];let o={address:[],comment:[],group:[],text:[]};let r;let p;for(r=0,p=e.length;r<p;r++){t=e[r];if(t.type==="operator"){switch(t.value){case"<":a="address";break;case"(":a="comment";break;case":":a="group";i=true;break;default:a="text"}}else if(t.value){if(a==="address"){t.value=t.value.replace(/^[^<]*<\s*/,"")}o[a].push(t.value)}}if(!o.text.length&&o.comment.length){o.text=o.comment;o.comment=[]}if(i){o.text=o.text.join(" ");n.push({name:o.text||s&&s.name,group:o.group.length?addressparser(o.group.join(",")):[]})}else{if(!o.address.length&&o.text.length){for(r=o.text.length-1;r>=0;r--){if(o.text[r].match(/^[^@\s]+@[^@\s]+$/)){o.address=o.text.splice(r,1);break}}let _regexHandler=function(e){if(!o.address.length){o.address=[e.trim()];return" "}else{return e}};if(!o.address.length){for(r=o.text.length-1;r>=0;r--){o.text[r]=o.text[r].replace(/\s*\b[^@\s]+@[^\s]+\b\s*/,_regexHandler).trim();if(o.address.length){break}}}}if(!o.text.length&&o.comment.length){o.text=o.comment;o.comment=[]}if(o.address.length>1){o.text=o.text.concat(o.address.splice(1))}o.text=o.text.join(" ");o.address=o.address.join(" ");if(!o.address&&i){return[]}else{s={address:o.address||o.text||"",name:o.text||o.address||""};if(s.address===s.name){if((s.address||"").match(/@/)){s.name=""}else{s.address=""}}n.push(s)}}return n}class Tokenizer{constructor(e){this.str=(e||"").toString();this.operatorCurrent="";this.operatorExpecting="";this.node=null;this.escaped=false;this.list=[];this.operators={'"':'"',"(":")","<":">",",":"",":":";",";":""}}tokenize(){let e,t=[];for(let t=0,i=this.str.length;t<i;t++){e=this.str.charAt(t);this.checkChar(e)}this.list.forEach((e=>{e.value=(e.value||"").toString().trim();if(e.value){t.push(e)}}));return t}checkChar(e){if(this.escaped){}else if(e===this.operatorExpecting){this.node={type:"operator",value:e};this.list.push(this.node);this.node=null;this.operatorExpecting="";this.escaped=false;return}else if(!this.operatorExpecting&&e in this.operators){this.node={type:"operator",value:e};this.list.push(this.node);this.node=null;this.operatorExpecting=this.operators[e];this.escaped=false;return}else if(['"',"'"].includes(this.operatorExpecting)&&e==="\\"){this.escaped=true;return}if(!this.node){this.node={type:"text",value:""};this.list.push(this.node)}if(e==="\n"){e=" "}if(e.charCodeAt(0)>=33||[" ","\t"].includes(e)){this.node.value+=e}this.escaped=false}}function addressparser(e,t){t=t||{};let i=new Tokenizer(e);let a=i.tokenize();let s=[];let n=[];let o=[];a.forEach((e=>{if(e.type==="operator"&&(e.value===","||e.value===";")){if(n.length){s.push(n)}n=[]}else{n.push(e)}}));if(n.length){s.push(n)}s.forEach((e=>{e=_handleAddress(e);if(e.length){o=o.concat(e)}}));if(t.flatten){let e=[];let walkAddressList=t=>{t.forEach((t=>{if(t.group){return walkAddressList(t.group)}else{e.push(t)}}))};walkAddressList(o);return e}return o}e.exports=addressparser},742:function(e,t,i){const a=i(781).Transform;function encode(e){if(typeof e==="string"){e=Buffer.from(e,"utf-8")}return e.toString("base64")}function wrap(e,t){e=(e||"").toString();t=t||76;if(e.length<=t){return e}let i=[];let a=0;let s=t*1024;while(a<e.length){let n=e.substr(a,s).replace(new RegExp(".{"+t+"}","g"),"$&\r\n").trim();i.push(n);a+=s}return i.join("\r\n").trim()}class Encoder extends a{constructor(e){super();this.options=e||{};if(this.options.lineLength!==false){this.options.lineLength=this.options.lineLength||76}this._curLine="";this._remainingBytes=false;this.inputBytes=0;this.outputBytes=0}_transform(e,t,i){if(t!=="buffer"){e=Buffer.from(e,t)}if(!e||!e.length){return setImmediate(i)}this.inputBytes+=e.length;if(this._remainingBytes&&this._remainingBytes.length){e=Buffer.concat([this._remainingBytes,e],this._remainingBytes.length+e.length);this._remainingBytes=false}if(e.length%3){this._remainingBytes=e.slice(e.length-e.length%3);e=e.slice(0,e.length-e.length%3)}else{this._remainingBytes=false}let a=this._curLine+encode(e);if(this.options.lineLength){a=wrap(a,this.options.lineLength);let e=a.lastIndexOf("\n");if(e<0){this._curLine=a;a=""}else if(e===a.length-1){this._curLine=""}else{this._curLine=a.substr(e+1);a=a.substr(0,e+1)}}if(a){this.outputBytes+=a.length;this.push(Buffer.from(a,"ascii"))}setImmediate(i)}_flush(e){if(this._remainingBytes&&this._remainingBytes.length){this._curLine+=encode(this._remainingBytes)}if(this._curLine){this._curLine=wrap(this._curLine,this.options.lineLength);this.outputBytes+=this._curLine.length;this.push(this._curLine,"ascii");this._curLine=""}e()}}e.exports={encode:encode,wrap:wrap,Encoder:Encoder}},148:function(e,t,i){const a=i(421);const s=i(689);const n=i(58);const o=i(781).PassThrough;const r=i(147);const p=i(17);const l=i(113);const c="sha256";const d=128*1024;class DKIMSigner{constructor(e,t,i,a){this.options=e||{};this.keys=t;this.cacheTreshold=Number(this.options.cacheTreshold)||d;this.hashAlgo=this.options.hashAlgo||c;this.cacheDir=this.options.cacheDir||false;this.chunks=[];this.chunklen=0;this.readPos=0;this.cachePath=this.cacheDir?p.join(this.cacheDir,"message."+Date.now()+"-"+l.randomBytes(14).toString("hex")):false;this.cache=false;this.headers=false;this.bodyHash=false;this.parser=false;this.relaxedBody=false;this.input=i;this.output=a;this.output.usingCache=false;this.hasErrored=false;this.input.on("error",(e=>{this.hasErrored=true;this.cleanup();a.emit("error",e)}))}cleanup(){if(!this.cache||!this.cachePath){return}r.unlink(this.cachePath,(()=>false))}createReadCache(){this.cache=r.createReadStream(this.cachePath);this.cache.once("error",(e=>{this.cleanup();this.output.emit("error",e)}));this.cache.once("close",(()=>{this.cleanup()}));this.cache.pipe(this.output)}sendNextChunk(){if(this.hasErrored){return}if(this.readPos>=this.chunks.length){if(!this.cache){return this.output.end()}return this.createReadCache()}let e=this.chunks[this.readPos++];if(this.output.write(e)===false){return this.output.once("drain",(()=>{this.sendNextChunk()}))}setImmediate((()=>this.sendNextChunk()))}sendSignedOutput(){let e=0;let signNextKey=()=>{if(e>=this.keys.length){this.output.write(this.parser.rawHeaders);return setImmediate((()=>this.sendNextChunk()))}let t=this.keys[e++];let i=n(this.headers,this.hashAlgo,this.bodyHash,{domainName:t.domainName,keySelector:t.keySelector,privateKey:t.privateKey,headerFieldNames:this.options.headerFieldNames,skipFields:this.options.skipFields});if(i){this.output.write(Buffer.from(i+"\r\n"))}return setImmediate(signNextKey)};if(this.bodyHash&&this.headers){return signNextKey()}this.output.write(this.parser.rawHeaders);this.sendNextChunk()}createWriteCache(){this.output.usingCache=true;this.cache=r.createWriteStream(this.cachePath);this.cache.once("error",(e=>{this.cleanup();this.relaxedBody.unpipe(this.cache);this.relaxedBody.on("readable",(()=>{while(this.relaxedBody.read()!==null){}}));this.hasErrored=true;this.output.emit("error",e)}));this.cache.once("close",(()=>{this.sendSignedOutput()}));this.relaxedBody.removeAllListeners("readable");this.relaxedBody.pipe(this.cache)}signStream(){this.parser=new a;this.relaxedBody=new s({hashAlgo:this.hashAlgo});this.parser.on("headers",(e=>{this.headers=e}));this.relaxedBody.on("hash",(e=>{this.bodyHash=e}));this.relaxedBody.on("readable",(()=>{let e;if(this.cache){return}while((e=this.relaxedBody.read())!==null){this.chunks.push(e);this.chunklen+=e.length;if(this.chunklen>=this.cacheTreshold&&this.cachePath){return this.createWriteCache()}}}));this.relaxedBody.on("end",(()=>{if(this.cache){return}this.sendSignedOutput()}));this.parser.pipe(this.relaxedBody);setImmediate((()=>this.input.pipe(this.parser)))}}class DKIM{constructor(e){this.options=e||{};this.keys=[].concat(this.options.keys||{domainName:e.domainName,keySelector:e.keySelector,privateKey:e.privateKey})}sign(e,t){let i=new o;let a=e;let s=false;if(Buffer.isBuffer(e)){s=e;a=new o}else if(typeof e==="string"){s=Buffer.from(e);a=new o}let n=this.options;if(t&&Object.keys(t).length){n={};Object.keys(this.options||{}).forEach((e=>{n[e]=this.options[e]}));Object.keys(t||{}).forEach((e=>{if(!(e in n)){n[e]=t[e]}}))}let r=new DKIMSigner(n,this.keys,a,i);setImmediate((()=>{r.signStream();if(s){setImmediate((()=>{a.end(s)}))}}));return i}}e.exports=DKIM},421:function(e,t,i){const a=i(781).Transform;class MessageParser extends a{constructor(e){super(e);this.lastBytes=Buffer.alloc(4);this.headersParsed=false;this.headerBytes=0;this.headerChunks=[];this.rawHeaders=false;this.bodySize=0}updateLastBytes(e){let t=this.lastBytes.length;let i=Math.min(e.length,t);for(let e=0,a=t-i;e<a;e++){this.lastBytes[e]=this.lastBytes[e+i]}for(let a=1;a<=i;a++){this.lastBytes[t-a]=e[e.length-a]}}checkHeaders(e){if(this.headersParsed){return true}let t=this.lastBytes.length;let i=0;this.curLinePos=0;for(let a=0,s=this.lastBytes.length+e.length;a<s;a++){let s;if(a<t){s=this.lastBytes[a]}else{s=e[a-t]}if(s===10&&a){let s=a-1<t?this.lastBytes[a-1]:e[a-1-t];let n=a>1?a-2<t?this.lastBytes[a-2]:e[a-2-t]:false;if(s===10){this.headersParsed=true;i=a-t+1;this.headerBytes+=i;break}else if(s===13&&n===10){this.headersParsed=true;i=a-t+1;this.headerBytes+=i;break}}}if(this.headersParsed){this.headerChunks.push(e.slice(0,i));this.rawHeaders=Buffer.concat(this.headerChunks,this.headerBytes);this.headerChunks=null;this.emit("headers",this.parseHeaders());if(e.length-1>i){let t=e.slice(i);this.bodySize+=t.length;setImmediate((()=>this.push(t)))}return false}else{this.headerBytes+=e.length;this.headerChunks.push(e)}this.updateLastBytes(e);return false}_transform(e,t,i){if(!e||!e.length){return i()}if(typeof e==="string"){e=Buffer.from(e,t)}let a;try{a=this.checkHeaders(e)}catch(e){return i(e)}if(a){this.bodySize+=e.length;this.push(e)}setImmediate(i)}_flush(e){if(this.headerChunks){let e=Buffer.concat(this.headerChunks,this.headerBytes);this.bodySize+=e.length;this.push(e);this.headerChunks=null}e()}parseHeaders(){let e=(this.rawHeaders||"").toString().split(/\r?\n/);for(let t=e.length-1;t>0;t--){if(/^\s/.test(e[t])){e[t-1]+="\n"+e[t];e.splice(t,1)}}return e.filter((e=>e.trim())).map((e=>({key:e.substr(0,e.indexOf(":")).trim().toLowerCase(),line:e})))}}e.exports=MessageParser},689:function(e,t,i){const a=i(781).Transform;const s=i(113);class RelaxedBody extends a{constructor(e){super();e=e||{};this.chunkBuffer=[];this.chunkBufferLen=0;this.bodyHash=s.createHash(e.hashAlgo||"sha1");this.remainder="";this.byteLength=0;this.debug=e.debug;this._debugBody=e.debug?[]:false}updateHash(e){let t;let i="";let a="file";for(let t=e.length-1;t>=0;t--){let s=e[t];if(a==="file"&&(s===10||s===13)){}else if(a==="file"&&(s===9||s===32)){a="line"}else if(a==="line"&&(s===9||s===32)){}else if(a==="file"||a==="line"){a="body";if(t===e.length-1){break}}if(t===0){if(a==="file"&&(!this.remainder||/[\r\n]$/.test(this.remainder))||a==="line"&&(!this.remainder||/[ \t]$/.test(this.remainder))){this.remainder+=e.toString("binary");return}else if(a==="line"||a==="file"){i=e.toString("binary");e=false;break}}if(a!=="body"){continue}i=e.slice(t+1).toString("binary");e=e.slice(0,t+1);break}let s=!!this.remainder;if(e&&!s){for(let t=0,i=e.length;t<i;t++){if(t&&e[t]===10&&e[t-1]!==13){s=true;break}else if(t&&e[t]===13&&e[t-1]===32){s=true;break}else if(t&&e[t]===32&&e[t-1]===32){s=true;break}else if(e[t]===9){s=true;break}}}if(s){t=this.remainder+(e?e.toString("binary"):"");this.remainder=i;t=t.replace(/\r?\n/g,"\n").replace(/[ \t]*$/gm,"").replace(/[ \t]+/gm," ").replace(/\n/g,"\r\n");e=Buffer.from(t,"binary")}else if(i){this.remainder=i}if(this.debug){this._debugBody.push(e)}this.bodyHash.update(e)}_transform(e,t,i){if(!e||!e.length){return i()}if(typeof e==="string"){e=Buffer.from(e,t)}this.updateHash(e);this.byteLength+=e.length;this.push(e);i()}_flush(e){if(/[\r\n]$/.test(this.remainder)&&this.byteLength>2){this.bodyHash.update(Buffer.from("\r\n"))}if(!this.byteLength){this.push(Buffer.from("\r\n"))}this.emit("hash",this.bodyHash.digest("base64"),this.debug?Buffer.concat(this._debugBody):false);e()}}e.exports=RelaxedBody},58:function(e,t,i){const a=i(886);const s=i(9);const n=i(113);e.exports=(e,t,i,a)=>{a=a||{};let s="From:Sender:Reply-To:Subject:Date:Message-ID:To:"+"Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID:"+"Content-Description:Resent-Date:Resent-From:Resent-Sender:"+"Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:"+"List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:"+"List-Owner:List-Archive";let o=a.headerFieldNames||s;let r=relaxedHeaders(e,o,a.skipFields);let p=generateDKIMHeader(a.domainName,a.keySelector,r.fieldNames,t,i);let l,c;r.headers+="dkim-signature:"+relaxedHeaderLine(p);l=n.createSign(("rsa-"+t).toUpperCase());l.update(r.headers);try{c=l.sign(a.privateKey,"base64")}catch(e){return false}return p+c.replace(/(^.{73}|.{75}(?!\r?\n|\r))/g,"$&\r\n ").trim()};e.exports.relaxedHeaders=relaxedHeaders;function generateDKIMHeader(e,t,i,n,o){let r=["v=1","a=rsa-"+n,"c=relaxed/relaxed","d="+a.toASCII(e),"q=dns/txt","s="+t,"bh="+o,"h="+i].join("; ");return s.foldLines("DKIM-Signature: "+r,76)+";\r\n b="}function relaxedHeaders(e,t,i){let a=new Set;let s=new Set;let n=new Map;(i||"").toLowerCase().split(":").forEach((e=>{s.add(e.trim())}));(t||"").toLowerCase().split(":").filter((e=>!s.has(e.trim()))).forEach((e=>{a.add(e.trim())}));for(let t=e.length-1;t>=0;t--){let i=e[t];if(a.has(i.key)&&!n.has(i.key)){n.set(i.key,relaxedHeaderLine(i.line))}}let o=[];let r=[];a.forEach((e=>{if(n.has(e)){r.push(e);o.push(e+":"+n.get(e))}}));return{headers:o.join("\r\n")+"\r\n",fieldNames:r.join(":")}}function relaxedHeaderLine(e){return e.substr(e.indexOf(":")+1).replace(/\r?\n/g,"").replace(/\s+/g," ").trim()}},415:function(e,t,i){const a=i(310);const s=1800;class Cookies{constructor(e){this.options=e||{};this.cookies=[]}set(e,t){let i=a.parse(t||"");let n=this.parse(e);let o;if(n.domain){o=n.domain.replace(/^\./,"");if(i.hostname.length<o.length||("."+i.hostname).substr(-o.length+1)!=="."+o){n.domain=i.hostname}}else{n.domain=i.hostname}if(!n.path){n.path=this.getPath(i.pathname)}if(!n.expires){n.expires=new Date(Date.now()+(Number(this.options.sessionTimeout||s)||s)*1e3)}return this.add(n)}get(e){return this.list(e).map((e=>e.name+"="+e.value)).join("; ")}list(e){let t=[];let i;let a;for(i=this.cookies.length-1;i>=0;i--){a=this.cookies[i];if(this.isExpired(a)){this.cookies.splice(i,i);continue}if(this.match(a,e)){t.unshift(a)}}return t}parse(e){let t={};(e||"").toString().split(";").forEach((e=>{let i=e.split("=");let a=i.shift().trim().toLowerCase();let s=i.join("=").trim();let n;if(!a){return}switch(a){case"expires":s=new Date(s);if(s.toString()!=="Invalid Date"){t.expires=s}break;case"path":t.path=s;break;case"domain":n=s.toLowerCase();if(n.length&&n.charAt(0)!=="."){n="."+n}t.domain=n;break;case"max-age":t.expires=new Date(Date.now()+(Number(s)||0)*1e3);break;case"secure":t.secure=true;break;case"httponly":t.httponly=true;break;default:if(!t.name){t.name=a;t.value=s}}}));return t}match(e,t){let i=a.parse(t||"");if(i.hostname!==e.domain&&(e.domain.charAt(0)!=="."||("."+i.hostname).substr(-e.domain.length)!==e.domain)){return false}let s=this.getPath(i.pathname);if(s.substr(0,e.path.length)!==e.path){return false}if(e.secure&&i.protocol!=="https:"){return false}return true}add(e){let t;let i;if(!e||!e.name){return false}for(t=0,i=this.cookies.length;t<i;t++){if(this.compare(this.cookies[t],e)){if(this.isExpired(e)){this.cookies.splice(t,1);return false}this.cookies[t]=e;return true}}if(!this.isExpired(e)){this.cookies.push(e)}return true}compare(e,t){return e.name===t.name&&e.path===t.path&&e.domain===t.domain&&e.secure===t.secure&&e.httponly===e.httponly}isExpired(e){return e.expires&&e.expires<new Date||!e.value}getPath(e){let t=(e||"/").split("/");t.pop();t=t.join("/").trim();if(t.charAt(0)!=="/"){t="/"+t}if(t.substr(-1)!=="/"){t+="/"}return t}}e.exports=Cookies},324:function(e,t,i){const a=i(685);const s=i(687);const n=i(310);const o=i(796);const r=i(781).PassThrough;const p=i(415);const l=i(491);const c=i(808);const d=5;e.exports=function(e,t){return nmfetch(e,t)};e.exports.Cookies=p;function nmfetch(e,t){t=t||{};t.fetchRes=t.fetchRes||new r;t.cookies=t.cookies||new p;t.redirects=t.redirects||0;t.maxRedirects=isNaN(t.maxRedirects)?d:t.maxRedirects;if(t.cookie){[].concat(t.cookie||[]).forEach((i=>{t.cookies.set(i,e)}));t.cookie=false}let i=t.fetchRes;let m=n.parse(e);let h=(t.method||"").toString().trim().toUpperCase()||"GET";let u=false;let f;let x;let g=m.protocol==="https:"?s:a;let v={"accept-encoding":"gzip,deflate","user-agent":"nodemailer/"+l.version};Object.keys(t.headers||{}).forEach((e=>{v[e.toLowerCase().trim()]=t.headers[e]}));if(t.userAgent){v["user-agent"]=t.userAgent}if(m.auth){v.Authorization="Basic "+Buffer.from(m.auth).toString("base64")}if(f=t.cookies.get(e)){v.cookie=f}if(t.body){if(t.contentType!==false){v["Content-Type"]=t.contentType||"application/x-www-form-urlencoded"}if(typeof t.body.pipe==="function"){v["Transfer-Encoding"]="chunked";x=t.body;x.on("error",(t=>{if(u){return}u=true;t.type="FETCH";t.sourceUrl=e;i.emit("error",t)}))}else{if(t.body instanceof Buffer){x=t.body}else if(typeof t.body==="object"){try{x=Buffer.from(Object.keys(t.body).map((e=>{let i=t.body[e].toString().trim();return encodeURIComponent(e)+"="+encodeURIComponent(i)})).join("&"))}catch(t){if(u){return}u=true;t.type="FETCH";t.sourceUrl=e;i.emit("error",t);return}}else{x=Buffer.from(t.body.toString().trim())}v["Content-Type"]=t.contentType||"application/x-www-form-urlencoded";v["Content-Length"]=x.length}h=(t.method||"").toString().trim().toUpperCase()||"POST"}let b;let w={method:h,host:m.hostname,path:m.path,port:m.port?m.port:m.protocol==="https:"?443:80,headers:v,rejectUnauthorized:false,agent:false};if(t.tls){Object.keys(t.tls).forEach((e=>{w[e]=t.tls[e]}))}if(m.protocol==="https:"&&m.hostname&&m.hostname!==w.host&&!c.isIP(m.hostname)&&!w.servername){w.servername=m.hostname}try{b=g.request(w)}catch(t){u=true;setImmediate((()=>{t.type="FETCH";t.sourceUrl=e;i.emit("error",t)}));return i}if(t.timeout){b.setTimeout(t.timeout,(()=>{if(u){return}u=true;b.abort();let t=new Error("Request Timeout");t.type="FETCH";t.sourceUrl=e;i.emit("error",t)}))}b.on("error",(t=>{if(u){return}u=true;t.type="FETCH";t.sourceUrl=e;i.emit("error",t)}));b.on("response",(a=>{let s;if(u){return}switch(a.headers["content-encoding"]){case"gzip":case"deflate":s=o.createUnzip();break}if(a.headers["set-cookie"]){[].concat(a.headers["set-cookie"]||[]).forEach((i=>{t.cookies.set(i,e)}))}if([301,302,303,307,308].includes(a.statusCode)&&a.headers.location){t.redirects++;if(t.redirects>t.maxRedirects){u=true;let t=new Error("Maximum redirect count exceeded");t.type="FETCH";t.sourceUrl=e;i.emit("error",t);b.abort();return}t.method="GET";t.body=false;return nmfetch(n.resolve(e,a.headers.location),t)}i.statusCode=a.statusCode;i.headers=a.headers;if(a.statusCode>=300&&!t.allowErrorResponse){u=true;let t=new Error("Invalid status code "+a.statusCode);t.type="FETCH";t.sourceUrl=e;i.emit("error",t);b.abort();return}a.on("error",(t=>{if(u){return}u=true;t.type="FETCH";t.sourceUrl=e;i.emit("error",t);b.abort()}));if(s){a.pipe(s).pipe(i);s.on("error",(t=>{if(u){return}u=true;t.type="FETCH";t.sourceUrl=e;i.emit("error",t);b.abort()}))}else{a.pipe(i)}}));setImmediate((()=>{if(x){try{if(typeof x.pipe==="function"){return x.pipe(b)}else{b.write(x)}}catch(t){u=true;t.type="FETCH";t.sourceUrl=e;i.emit("error",t);return}}b.end()}));return i}},711:function(e,t,i){const a=i(491);const s=i(358);class JSONTransport{constructor(e){e=e||{};this.options=e||{};this.name="JSONTransport";this.version=a.version;this.logger=s.getLogger(this.options,{component:this.options.component||"json-transport"})}send(e,t){e.message.keepBcc=true;let i=e.data.envelope||e.message.getEnvelope();let a=e.message.messageId();let s=[].concat(i.to||[]);if(s.length>3){s.push("...and "+s.splice(2).length+" more")}this.logger.info({tnx:"send",messageId:a},"Composing JSON structure of %s to <%s>",a,s.join(", "));setImmediate((()=>{e.normalize(((e,s)=>{if(e){this.logger.error({err:e,tnx:"send",messageId:a},"Failed building JSON structure for %s. %s",a,e.message);return t(e)}delete s.envelope;delete s.normalizedHeaders;return t(null,{envelope:i,messageId:a,message:this.options.skipEncoding?s:JSON.stringify(s)})}))}))}}e.exports=JSONTransport},530:function(e,t,i){const a=i(110);const s=i(9);const n=i(358).parseDataURI;class MailComposer{constructor(e){this.mail=e||{};this.message=false}compile(){this._alternatives=this.getAlternatives();this._htmlNode=this._alternatives.filter((e=>/^text\/html\b/i.test(e.contentType))).pop();this._attachments=this.getAttachments(!!this._htmlNode);this._useRelated=!!(this._htmlNode&&this._attachments.related.length);this._useAlternative=this._alternatives.length>1;this._useMixed=this._attachments.attached.length>1||this._alternatives.length&&this._attachments.attached.length===1;if(this.mail.raw){this.message=new a("message/rfc822",{newline:this.mail.newline}).setRaw(this.mail.raw)}else if(this._useMixed){this.message=this._createMixed()}else if(this._useAlternative){this.message=this._createAlternative()}else if(this._useRelated){this.message=this._createRelated()}else{this.message=this._createContentNode(false,[].concat(this._alternatives||[]).concat(this._attachments.attached||[]).shift()||{contentType:"text/plain",content:""})}if(this.mail.headers){this.message.addHeader(this.mail.headers)}["from","sender","to","cc","bcc","reply-to","in-reply-to","references","subject","message-id","date"].forEach((e=>{let t=e.replace(/-(\w)/g,((e,t)=>t.toUpperCase()));if(this.mail[t]){this.message.setHeader(e,this.mail[t])}}));if(this.mail.envelope){this.message.setEnvelope(this.mail.envelope)}this.message.messageId();return this.message}getAttachments(e){let t,i;let a=[].concat(this.mail.attachments||[]).map(((e,t)=>{let i;let a=/^message\//i.test(e.contentType);if(/^data:/i.test(e.path||e.href)){e=this._processDataUrl(e)}let n=e.contentType||s.detectMimeType(e.filename||e.path||e.href||"bin");let o=/^image\//i.test(n);let r=e.contentDisposition||(a||o&&e.cid?"inline":"attachment");i={contentType:n,contentDisposition:r,contentTransferEncoding:"contentTransferEncoding"in e?e.contentTransferEncoding:"base64"};if(e.filename){i.filename=e.filename}else if(!a&&e.filename!==false){i.filename=(e.path||e.href||"").split("/").pop().split("?").shift()||"attachment-"+(t+1);if(i.filename.indexOf(".")<0){i.filename+="."+s.detectExtension(i.contentType)}}if(/^https?:\/\//i.test(e.path)){e.href=e.path;e.path=undefined}if(e.cid){i.cid=e.cid}if(e.raw){i.raw=e.raw}else if(e.path){i.content={path:e.path}}else if(e.href){i.content={href:e.href,httpHeaders:e.httpHeaders}}else{i.content=e.content||""}if(e.encoding){i.encoding=e.encoding}if(e.headers){i.headers=e.headers}return i}));if(this.mail.icalEvent){if(typeof this.mail.icalEvent==="object"&&(this.mail.icalEvent.content||this.mail.icalEvent.path||this.mail.icalEvent.href||this.mail.icalEvent.raw)){t=this.mail.icalEvent}else{t={content:this.mail.icalEvent}}i={};Object.keys(t).forEach((e=>{i[e]=t[e]}));i.contentType="application/ics";if(!i.headers){i.headers={}}i.filename=i.filename||"invite.ics";i.headers["Content-Disposition"]="attachment";i.headers["Content-Transfer-Encoding"]="base64"}if(!e){return{attached:a.concat(i||[]),related:[]}}else{return{attached:a.filter((e=>!e.cid)).concat(i||[]),related:a.filter((e=>!!e.cid))}}}getAlternatives(){let e=[],t,i,a,n,o,r;if(this.mail.text){if(typeof this.mail.text==="object"&&(this.mail.text.content||this.mail.text.path||this.mail.text.href||this.mail.text.raw)){t=this.mail.text}else{t={content:this.mail.text}}t.contentType="text/plain; charset=utf-8"}if(this.mail.watchHtml){if(typeof this.mail.watchHtml==="object"&&(this.mail.watchHtml.content||this.mail.watchHtml.path||this.mail.watchHtml.href||this.mail.watchHtml.raw)){a=this.mail.watchHtml}else{a={content:this.mail.watchHtml}}a.contentType="text/watch-html; charset=utf-8"}if(this.mail.amp){if(typeof this.mail.amp==="object"&&(this.mail.amp.content||this.mail.amp.path||this.mail.amp.href||this.mail.amp.raw)){n=this.mail.amp}else{n={content:this.mail.amp}}n.contentType="text/x-amp-html; charset=utf-8"}if(this.mail.icalEvent){if(typeof this.mail.icalEvent==="object"&&(this.mail.icalEvent.content||this.mail.icalEvent.path||this.mail.icalEvent.href||this.mail.icalEvent.raw)){o=this.mail.icalEvent}else{o={content:this.mail.icalEvent}}r={};Object.keys(o).forEach((e=>{r[e]=o[e]}));if(r.content&&typeof r.content==="object"){r.content._resolve=true}r.filename=false;r.contentType="text/calendar; charset=utf-8; method="+(r.method||"PUBLISH").toString().trim().toUpperCase();if(!r.headers){r.headers={}}}if(this.mail.html){if(typeof this.mail.html==="object"&&(this.mail.html.content||this.mail.html.path||this.mail.html.href||this.mail.html.raw)){i=this.mail.html}else{i={content:this.mail.html}}i.contentType="text/html; charset=utf-8"}[].concat(t||[]).concat(a||[]).concat(n||[]).concat(i||[]).concat(r||[]).concat(this.mail.alternatives||[]).forEach((t=>{let i;if(/^data:/i.test(t.path||t.href)){t=this._processDataUrl(t)}i={contentType:t.contentType||s.detectMimeType(t.filename||t.path||t.href||"txt"),contentTransferEncoding:t.contentTransferEncoding};if(t.filename){i.filename=t.filename}if(/^https?:\/\//i.test(t.path)){t.href=t.path;t.path=undefined}if(t.raw){i.raw=t.raw}else if(t.path){i.content={path:t.path}}else if(t.href){i.content={href:t.href}}else{i.content=t.content||""}if(t.encoding){i.encoding=t.encoding}if(t.headers){i.headers=t.headers}e.push(i)}));return e}_createMixed(e){let t;if(!e){t=new a("multipart/mixed",{baseBoundary:this.mail.baseBoundary,textEncoding:this.mail.textEncoding,boundaryPrefix:this.mail.boundaryPrefix,disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}else{t=e.createChild("multipart/mixed",{disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}if(this._useAlternative){this._createAlternative(t)}else if(this._useRelated){this._createRelated(t)}[].concat(!this._useAlternative&&this._alternatives||[]).concat(this._attachments.attached||[]).forEach((e=>{if(!this._useRelated||e!==this._htmlNode){this._createContentNode(t,e)}}));return t}_createAlternative(e){let t;if(!e){t=new a("multipart/alternative",{baseBoundary:this.mail.baseBoundary,textEncoding:this.mail.textEncoding,boundaryPrefix:this.mail.boundaryPrefix,disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}else{t=e.createChild("multipart/alternative",{disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}this._alternatives.forEach((e=>{if(this._useRelated&&this._htmlNode===e){this._createRelated(t)}else{this._createContentNode(t,e)}}));return t}_createRelated(e){let t;if(!e){t=new a('multipart/related; type="text/html"',{baseBoundary:this.mail.baseBoundary,textEncoding:this.mail.textEncoding,boundaryPrefix:this.mail.boundaryPrefix,disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}else{t=e.createChild('multipart/related; type="text/html"',{disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}this._createContentNode(t,this._htmlNode);this._attachments.related.forEach((e=>this._createContentNode(t,e)));return t}_createContentNode(e,t){t=t||{};t.content=t.content||"";let i;let s=(t.encoding||"utf8").toString().toLowerCase().replace(/[-_\s]/g,"");if(!e){i=new a(t.contentType,{filename:t.filename,baseBoundary:this.mail.baseBoundary,textEncoding:this.mail.textEncoding,boundaryPrefix:this.mail.boundaryPrefix,disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}else{i=e.createChild(t.contentType,{filename:t.filename,textEncoding:this.mail.textEncoding,disableUrlAccess:this.mail.disableUrlAccess,disableFileAccess:this.mail.disableFileAccess,normalizeHeaderKey:this.mail.normalizeHeaderKey,newline:this.mail.newline})}if(t.headers){i.addHeader(t.headers)}if(t.cid){i.setHeader("Content-Id","<"+t.cid.replace(/[<>]/g,"")+">")}if(t.contentTransferEncoding){i.setHeader("Content-Transfer-Encoding",t.contentTransferEncoding)}else if(this.mail.encoding&&/^text\//i.test(t.contentType)){i.setHeader("Content-Transfer-Encoding",this.mail.encoding)}if(!/^text\//i.test(t.contentType)||t.contentDisposition){i.setHeader("Content-Disposition",t.contentDisposition||(t.cid&&/^image\//i.test(t.contentType)?"inline":"attachment"))}if(typeof t.content==="string"&&!["utf8","usascii","ascii"].includes(s)){t.content=Buffer.from(t.content,s)}if(t.raw){i.setRaw(t.raw)}else{i.setContent(t.content)}return i}_processDataUrl(e){let t;if((e.path||e.href).match(/^data:/)){t=n(e.path||e.href)}if(!t){return e}e.content=t.data;e.contentType=e.contentType||t.contentType;if("path"in e){e.path=false}if("href"in e){e.href=false}return e}}e.exports=MailComposer},857:function(e,t,i){const a=i(361);const s=i(358);const n=i(314);const o=i(530);const r=i(148);const p=i(568);const l=i(837);const c=i(310);const d=i(491);const m=i(733);const h=i(808);const u=i(523);const f=i(113);class Mail extends a{constructor(e,t,i){super();this.options=t||{};this._defaults=i||{};this._defaultPlugins={compile:[(...e)=>this._convertDataImages(...e)],stream:[]};this._userPlugins={compile:[],stream:[]};this.meta=new Map;this.dkim=this.options.dkim?new r(this.options.dkim):false;this.transporter=e;this.transporter.mailer=this;this.logger=s.getLogger(this.options,{component:this.options.component||"mail"});this.logger.debug({tnx:"create"},"Creating transport: %s",this.getVersionString());if(typeof this.transporter.on==="function"){this.transporter.on("log",(e=>{this.logger.debug({tnx:"transport"},"%s: %s",e.type,e.message)}));this.transporter.on("error",(e=>{this.logger.error({err:e,tnx:"transport"},"Transport Error: %s",e.message);this.emit("error",e)}));this.transporter.on("idle",((...e)=>{this.emit("idle",...e)}))}["close","isIdle","verify"].forEach((e=>{this[e]=(...t)=>{if(typeof this.transporter[e]==="function"){if(e==="verify"&&typeof this.getSocket==="function"){this.transporter.getSocket=this.getSocket;this.getSocket=false}return this.transporter[e](...t)}else{this.logger.warn({tnx:"transport",methodName:e},"Non existing method %s called for transport",e);return false}}}));if(this.options.proxy&&typeof this.options.proxy==="string"){this.setupProxy(this.options.proxy)}}use(e,t){e=(e||"").toString();if(!this._userPlugins.hasOwnProperty(e)){this._userPlugins[e]=[t]}else{this._userPlugins[e].push(t)}return this}sendMail(e,t=null){let i;if(!t){i=new Promise(((e,i)=>{t=s.callbackPromise(e,i)}))}if(typeof this.getSocket==="function"){this.transporter.getSocket=this.getSocket;this.getSocket=false}let a=new m(this,e);this.logger.debug({tnx:"transport",name:this.transporter.name,version:this.transporter.version,action:"send"},"Sending mail using %s/%s",this.transporter.name,this.transporter.version);this._processPlugins("compile",a,(e=>{if(e){this.logger.error({err:e,tnx:"plugin",action:"compile"},"PluginCompile Error: %s",e.message);return t(e)}a.message=new o(a.data).compile();a.setMailerHeader();a.setPriorityHeaders();a.setListHeaders();this._processPlugins("stream",a,(e=>{if(e){this.logger.error({err:e,tnx:"plugin",action:"stream"},"PluginStream Error: %s",e.message);return t(e)}if(a.data.dkim||this.dkim){a.message.processFunc((e=>{let t=a.data.dkim?new r(a.data.dkim):this.dkim;this.logger.debug({tnx:"DKIM",messageId:a.message.messageId(),dkimDomains:t.keys.map((e=>e.keySelector+"."+e.domainName)).join(", ")},"Signing outgoing message with %s keys",t.keys.length);return t.sign(e,a.data._dkim)}))}this.transporter.send(a,((...e)=>{if(e[0]){this.logger.error({err:e[0],tnx:"transport",action:"send"},"Send Error: %s",e[0].message)}t(...e)}))}))}));return i}getVersionString(){return l.format("%s (%s; +%s; %s/%s)",d.name,d.version,d.homepage,this.transporter.name,this.transporter.version)}_processPlugins(e,t,i){e=(e||"").toString();if(!this._userPlugins.hasOwnProperty(e)){return i()}let a=this._userPlugins[e]||[];let s=this._defaultPlugins[e]||[];if(a.length){this.logger.debug({tnx:"transaction",pluginCount:a.length,step:e},"Using %s plugins for %s",a.length,e)}if(a.length+s.length===0){return i()}let n=0;let o="default";let processPlugins=()=>{let e=o==="default"?s:a;if(n>=e.length){if(o==="default"&&a.length){o="user";n=0;e=a}else{return i()}}let r=e[n++];r(t,(e=>{if(e){return i(e)}processPlugins()}))};processPlugins()}setupProxy(e){let t=c.parse(e);this.getSocket=(e,i)=>{let a=t.protocol.replace(/:$/,"").toLowerCase();if(this.meta.has("proxy_handler_"+a)){return this.meta.get("proxy_handler_"+a)(t,e,i)}switch(a){case"http":case"https":p(t.href,e.port,e.host,((e,t)=>{if(e){return i(e)}return i(null,{connection:t})}));return;case"socks":case"socks5":case"socks4":case"socks4a":{if(!this.meta.has("proxy_socks_module")){return i(new Error("Socks module not loaded"))}let connect=a=>{let s=!!this.meta.get("proxy_socks_module").SocksClient;let n=s?this.meta.get("proxy_socks_module").SocksClient:this.meta.get("proxy_socks_module");let o=Number(t.protocol.replace(/\D/g,""))||5;let r={proxy:{ipaddress:a,port:Number(t.port),type:o},[s?"destination":"target"]:{host:e.host,port:e.port},command:"connect"};if(t.auth){let e=decodeURIComponent(t.auth.split(":").shift());let i=decodeURIComponent(t.auth.split(":").pop());if(s){r.proxy.userId=e;r.proxy.password=i}else if(o===4){r.userid=e}else{r.authentication={username:e,password:i}}}n.createConnection(r,((e,t)=>{if(e){return i(e)}return i(null,{connection:t.socket||t})}))};if(h.isIP(t.hostname)){return connect(t.hostname)}return u.resolve(t.hostname,((e,t)=>{if(e){return i(e)}connect(Array.isArray(t)?t[0]:t)}))}}i(new Error("Unknown proxy configuration"))}}_convertDataImages(e,t){if(!this.options.attachDataUrls&&!e.data.attachDataUrls||!e.data.html){return t()}e.resolveContent(e.data,"html",((i,a)=>{if(i){return t(i)}let s=0;a=(a||"").toString().replace(/(<img\b[^<>]{0,1024} src\s{0,20}=[\s"']{0,20})(data:([^;]+);[^"'>\s]+)/gi,((t,i,a,o)=>{let r=f.randomBytes(10).toString("hex")+"@localhost";if(!e.data.attachments){e.data.attachments=[]}if(!Array.isArray(e.data.attachments)){e.data.attachments=[].concat(e.data.attachments||[])}e.data.attachments.push({path:a,cid:r,filename:"image-"+ ++s+"."+n.detectExtension(o)});return i+"cid:"+r}));e.data.html=a;t()}))}set(e,t){return this.meta.set(e,t)}get(e){return this.meta.get(e)}}e.exports=Mail},733:function(e,t,i){const a=i(358);const s=i(110);const n=i(9);class MailMessage{constructor(e,t){this.mailer=e;this.data={};this.message=null;t=t||{};let i=e.options||{};let a=e._defaults||{};Object.keys(t).forEach((e=>{this.data[e]=t[e]}));this.data.headers=this.data.headers||{};Object.keys(a).forEach((e=>{if(!(e in this.data)){this.data[e]=a[e]}else if(e==="headers"){Object.keys(a.headers).forEach((e=>{if(!(e in this.data.headers)){this.data.headers[e]=a.headers[e]}}))}}));["disableFileAccess","disableUrlAccess","normalizeHeaderKey"].forEach((e=>{if(e in i){this.data[e]=i[e]}}))}resolveContent(...e){return a.resolveContent(...e)}resolveAll(e){let t=[[this.data,"html"],[this.data,"text"],[this.data,"watchHtml"],[this.data,"amp"],[this.data,"icalEvent"]];if(this.data.alternatives&&this.data.alternatives.length){this.data.alternatives.forEach(((e,i)=>{t.push([this.data.alternatives,i])}))}if(this.data.attachments&&this.data.attachments.length){this.data.attachments.forEach(((e,i)=>{if(!e.filename){e.filename=(e.path||e.href||"").split("/").pop().split("?").shift()||"attachment-"+(i+1);if(e.filename.indexOf(".")<0){e.filename+="."+n.detectExtension(e.contentType)}}if(!e.contentType){e.contentType=n.detectMimeType(e.filename||e.path||e.href||"bin")}t.push([this.data.attachments,i])}))}let i=new s;let o=["from","to","cc","bcc","sender","replyTo"];o.forEach((e=>{let t;if(this.message){t=[].concat(i._parseAddresses(this.message.getHeader(e==="replyTo"?"reply-to":e))||[])}else if(this.data[e]){t=[].concat(i._parseAddresses(this.data[e])||[])}if(t&&t.length){this.data[e]=t}else if(e in this.data){this.data[e]=null}}));let r=["from","sender"];r.forEach((e=>{if(this.data[e]){this.data[e]=this.data[e].shift()}}));let p=0;let resolveNext=()=>{if(p>=t.length){return e(null,this.data)}let i=t[p++];if(!i[0]||!i[0][i[1]]){return resolveNext()}a.resolveContent(...i,((t,a)=>{if(t){return e(t)}let s={content:a};if(i[0][i[1]]&&typeof i[0][i[1]]==="object"&&!Buffer.isBuffer(i[0][i[1]])){Object.keys(i[0][i[1]]).forEach((e=>{if(!(e in s)&&!["content","path","href","raw"].includes(e)){s[e]=i[0][i[1]][e]}}))}i[0][i[1]]=s;resolveNext()}))};setImmediate((()=>resolveNext()))}normalize(e){let t=this.data.envelope||this.message.getEnvelope();let i=this.message.messageId();this.resolveAll(((a,s)=>{if(a){return e(a)}s.envelope=t;s.messageId=i;["html","text","watchHtml","amp"].forEach((e=>{if(s[e]&&s[e].content){if(typeof s[e].content==="string"){s[e]=s[e].content}else if(Buffer.isBuffer(s[e].content)){s[e]=s[e].content.toString()}}}));if(s.icalEvent&&Buffer.isBuffer(s.icalEvent.content)){s.icalEvent.content=s.icalEvent.content.toString("base64");s.icalEvent.encoding="base64"}if(s.alternatives&&s.alternatives.length){s.alternatives.forEach((e=>{if(e&&e.content&&Buffer.isBuffer(e.content)){e.content=e.content.toString("base64");e.encoding="base64"}}))}if(s.attachments&&s.attachments.length){s.attachments.forEach((e=>{if(e&&e.content&&Buffer.isBuffer(e.content)){e.content=e.content.toString("base64");e.encoding="base64"}}))}s.normalizedHeaders={};Object.keys(s.headers||{}).forEach((e=>{let t=[].concat(s.headers[e]||[]).shift();t=t&&t.value||t;if(t){if(["references","in-reply-to","message-id","content-id"].includes(e)){t=this.message._encodeHeaderValue(e,t)}s.normalizedHeaders[e]=t}}));if(s.list&&typeof s.list==="object"){let e=this._getListHeaders(s.list);e.forEach((e=>{s.normalizedHeaders[e.key]=e.value.map((e=>e&&e.value||e)).join(", ")}))}if(s.references){s.normalizedHeaders.references=this.message._encodeHeaderValue("references",s.references)}if(s.inReplyTo){s.normalizedHeaders["in-reply-to"]=this.message._encodeHeaderValue("in-reply-to",s.inReplyTo)}return e(null,s)}))}setMailerHeader(){if(!this.message||!this.data.xMailer){return}this.message.setHeader("X-Mailer",this.data.xMailer)}setPriorityHeaders(){if(!this.message||!this.data.priority){return}switch((this.data.priority||"").toString().toLowerCase()){case"high":this.message.setHeader("X-Priority","1 (Highest)");this.message.setHeader("X-MSMail-Priority","High");this.message.setHeader("Importance","High");break;case"low":this.message.setHeader("X-Priority","5 (Lowest)");this.message.setHeader("X-MSMail-Priority","Low");this.message.setHeader("Importance","Low");break;default:}}setListHeaders(){if(!this.message||!this.data.list||typeof this.data.list!=="object"){return}if(this.data.list&&typeof this.data.list==="object"){this._getListHeaders(this.data.list).forEach((e=>{e.value.forEach((t=>{this.message.addHeader(e.key,t)}))}))}}_getListHeaders(e){return Object.keys(e).map((t=>({key:"list-"+t.toLowerCase().trim(),value:[].concat(e[t]||[]).map((e=>({prepared:true,foldLines:true,value:[].concat(e||[]).map((e=>{if(typeof e==="string"){e={url:e}}if(e&&e.url){if(t.toLowerCase().trim()==="id"){let t=e.comment||"";if(n.isPlainText(t)){t='"'+t+'"'}else{t=n.encodeWord(t)}return(e.comment?t+" ":"")+this._formatListUrl(e.url).replace(/^<[^:]+\/{,2}/,"")}let i=e.comment||"";if(!n.isPlainText(i)){i=n.encodeWord(i)}return this._formatListUrl(e.url)+(e.comment?" ("+i+")":"")}return""})).filter((e=>e)).join(", ")})))})))}_formatListUrl(e){e=e.replace(/[\s<]+|[\s>]+/g,"");if(/^(https?|mailto|ftp):/.test(e)){return"<"+e+">"}if(/^[^@]+@[^@]+$/.test(e)){return"<mailto:"+e+">"}return"<http://"+e+">"}}e.exports=MailMessage},9:function(e,t,i){const a=i(742);const s=i(831);const n=i(314);e.exports={isPlainText(e,t){const i=t?/[\x00-\x08\x0b\x0c\x0e-\x1f"\u0080-\uFFFF]/:/[\x00-\x08\x0b\x0c\x0e-\x1f\u0080-\uFFFF]/;if(typeof e!=="string"||i.test(e)){return false}else{return true}},hasLongerLines(e,t){if(e.length>128*1024){return true}return new RegExp("^.{"+(t+1)+",}","m").test(e)},encodeWord(e,t,i){t=(t||"Q").toString().toUpperCase().trim().charAt(0);i=i||0;let n;let o="UTF-8";if(i&&i>7+o.length){i-=7+o.length}if(t==="Q"){n=s.encode(e).replace(/[^a-z0-9!*+\-/=]/gi,(e=>{let t=e.charCodeAt(0).toString(16).toUpperCase();if(e===" "){return"_"}else{return"="+(t.length===1?"0"+t:t)}}))}else if(t==="B"){n=typeof e==="string"?e:a.encode(e);i=i?Math.max(3,(i-i%4)/4*3):0}if(i&&(t!=="B"?n:a.encode(e)).length>i){if(t==="Q"){n=this.splitMimeEncodedString(n,i).join("?= =?"+o+"?"+t+"?")}else{let e=[];let s="";for(let t=0,o=n.length;t<o;t++){let r=n.charAt(t);if(/[\ud83c\ud83d\ud83e]/.test(r)&&t<o-1){r+=n.charAt(++t)}if(Buffer.byteLength(s+r)<=i||t===0){s+=r}else{e.push(a.encode(s));s=r}}if(s){e.push(a.encode(s))}if(e.length>1){n=e.join("?= =?"+o+"?"+t+"?")}else{n=e.join("")}}}else if(t==="B"){n=a.encode(e)}return"=?"+o+"?"+t+"?"+n+(n.substr(-2)==="?="?"":"?=")},encodeWords(e,t,i,a){i=i||0;let s;let n=e.match(/(?:^|\s)([^\s]*["\u0080-\uFFFF])/);if(!n){return e}if(a){return this.encodeWord(e,t,i)}let o=e.match(/(["\u0080-\uFFFF][^\s]*)[^"\u0080-\uFFFF]*$/);if(!o){return e}let r=n.index+(n[0].match(/[^\s]/)||{index:0}).index;let p=o.index+(o[1]||"").length;s=(r?e.substr(0,r):"")+this.encodeWord(e.substring(r,p),t||"Q",i)+(p<e.length?e.substr(p):"");return s},buildHeaderValue(e){let t=[];Object.keys(e.params||{}).forEach((i=>{let a=e.params[i];if(!this.isPlainText(a,true)||a.length>=75){this.buildHeaderParam(i,a,50).forEach((e=>{if(!/[\s"\\;:/=(),<>@[\]?]|^[-']|'$/.test(e.value)||e.key.substr(-1)==="*"){t.push(e.key+"="+e.value)}else{t.push(e.key+"="+JSON.stringify(e.value))}}))}else if(/[\s'"\\;:/=(),<>@[\]?]|^-/.test(a)){t.push(i+"="+JSON.stringify(a))}else{t.push(i+"="+a)}}));return e.value+(t.length?"; "+t.join("; "):"")},buildHeaderParam(e,t,i){let a=[];let s=typeof t==="string"?t:(t||"").toString();let n;let o,r;let p;let l=0;let c,d;i=i||50;if(this.isPlainText(t,true)){if(s.length<=i){return[{key:e,value:s}]}s=s.replace(new RegExp(".{"+i+"}","g"),(e=>{a.push({line:e});return""}));if(s){a.push({line:s})}}else{if(/[\uD800-\uDBFF]/.test(s)){n=[];for(c=0,d=s.length;c<d;c++){o=s.charAt(c);r=o.charCodeAt(0);if(r>=55296&&r<=56319&&c<d-1){o+=s.charAt(c+1);n.push(o);c++}else{n.push(o)}}s=n}p="utf-8''";let e=true;l=0;for(c=0,d=s.length;c<d;c++){o=s[c];if(e){o=this.safeEncodeURIComponent(o)}else{o=o===" "?o:this.safeEncodeURIComponent(o);if(o!==s[c]){if((this.safeEncodeURIComponent(p)+o).length>=i){a.push({line:p,encoded:e});p="";l=c-1}else{e=true;c=l;p="";continue}}}if((p+o).length>=i){a.push({line:p,encoded:e});p=o=s[c]===" "?" ":this.safeEncodeURIComponent(s[c]);if(o===s[c]){e=false;l=c-1}else{e=true}}else{p+=o}}if(p){a.push({line:p,encoded:e})}}return a.map(((t,i)=>({key:e+"*"+i+(t.encoded?"*":""),value:t.line})))},parseHeaderValue(e){let t={value:false,params:{}};let i=false;let a="";let s="value";let n=false;let o=false;let r;for(let p=0,l=e.length;p<l;p++){r=e.charAt(p);if(s==="key"){if(r==="="){i=a.trim().toLowerCase();s="value";a="";continue}a+=r}else{if(o){a+=r}else if(r==="\\"){o=true;continue}else if(n&&r===n){n=false}else if(!n&&r==='"'){n=r}else if(!n&&r===";"){if(i===false){t.value=a.trim()}else{t.params[i]=a.trim()}s="key";a=""}else{a+=r}o=false}}if(s==="value"){if(i===false){t.value=a.trim()}else{t.params[i]=a.trim()}}else if(a.trim()){t.params[a.trim().toLowerCase()]=""}Object.keys(t.params).forEach((e=>{let i,a,s,n;if(s=e.match(/(\*(\d+)|\*(\d+)\*|\*)$/)){i=e.substr(0,s.index);a=Number(s[2]||s[3])||0;if(!t.params[i]||typeof t.params[i]!=="object"){t.params[i]={charset:false,values:[]}}n=t.params[e];if(a===0&&s[0].substr(-1)==="*"&&(s=n.match(/^([^']*)'[^']*'(.*)$/))){t.params[i].charset=s[1]||"iso-8859-1";n=s[2]}t.params[i].values[a]=n;delete t.params[e]}}));Object.keys(t.params).forEach((e=>{let i;if(t.params[e]&&Array.isArray(t.params[e].values)){i=t.params[e].values.map((e=>e||"")).join("");if(t.params[e].charset){t.params[e]="=?"+t.params[e].charset+"?Q?"+i.replace(/[=?_\s]/g,(e=>{let t=e.charCodeAt(0).toString(16);if(e===" "){return"_"}else{return"%"+(t.length<2?"0":"")+t}})).replace(/%/g,"=")+"?="}else{t.params[e]=i}}}));return t},detectExtension:e=>n.detectExtension(e),detectMimeType:e=>n.detectMimeType(e),foldLines(e,t,i){e=(e||"").toString();t=t||76;let a=0,s=e.length,n="",o,r;while(a<s){o=e.substr(a,t);if(o.length<t){n+=o;break}if(r=o.match(/^[^\n\r]*(\r?\n|\r)/)){o=r[0];n+=o;a+=o.length;continue}else if((r=o.match(/(\s+)[^\s]*$/))&&r[0].length-(i?(r[1]||"").length:0)<o.length){o=o.substr(0,o.length-(r[0].length-(i?(r[1]||"").length:0)))}else if(r=e.substr(a+o.length).match(/^[^\s]+(\s*)/)){o=o+r[0].substr(0,r[0].length-(!i?(r[1]||"").length:0))}n+=o;a+=o.length;if(a<s){n+="\r\n"}}return n},splitMimeEncodedString:(e,t)=>{let i,a,s,n,o=[];t=Math.max(t||0,12);while(e.length){i=e.substr(0,t);if(a=i.match(/[=][0-9A-F]?$/i)){i=i.substr(0,a.index)}n=false;while(!n){n=true;if(a=e.substr(i.length).match(/^[=]([0-9A-F]{2})/i)){s=parseInt(a[1],16);if(s<194&&s>127){i=i.substr(0,i.length-3);n=false}}}if(i.length){o.push(i)}e=e.substr(i.length)}return o},encodeURICharComponent:e=>{let t="";let i=e.charCodeAt(0).toString(16).toUpperCase();if(i.length%2){i="0"+i}if(i.length>2){for(let e=0,a=i.length/2;e<a;e++){t+="%"+i.substr(e,2)}}else{t+="%"+i}return t},safeEncodeURIComponent(e){e=(e||"").toString();try{e=encodeURIComponent(e)}catch(t){return e.replace(/[^\x00-\x1F *'()<>@,;:\\"[\]?=\u007F-\uFFFF]+/g,"")}return e.replace(/[\x00-\x1F *'()<>@,;:\\"[\]?=\u007F-\uFFFF]/g,(e=>this.encodeURICharComponent(e)))}}},314:function(e,t,i){const a=i(17);const s="application/octet-stream";const n="bin";const o=new Map([["application/acad","dwg"],["application/applixware","aw"],["application/arj","arj"],["application/atom+xml","xml"],["application/atomcat+xml","atomcat"],["application/atomsvc+xml","atomsvc"],["application/base64",["mm","mme"]],["application/binhex","hqx"],["application/binhex4","hqx"],["application/book",["book","boo"]],["application/ccxml+xml,","ccxml"],["application/cdf","cdf"],["application/cdmi-capability","cdmia"],["application/cdmi-container","cdmic"],["application/cdmi-domain","cdmid"],["application/cdmi-object","cdmio"],["application/cdmi-queue","cdmiq"],["application/clariscad","ccad"],["application/commonground","dp"],["application/cu-seeme","cu"],["application/davmount+xml","davmount"],["application/drafting","drw"],["application/dsptype","tsp"],["application/dssc+der","dssc"],["application/dssc+xml","xdssc"],["application/dxf","dxf"],["application/ecmascript",["js","es"]],["application/emma+xml","emma"],["application/envoy","evy"],["application/epub+zip","epub"],["application/excel",["xls","xl","xla","xlb","xlc","xld","xlk","xll","xlm","xlt","xlv","xlw"]],["application/exi","exi"],["application/font-tdpfr","pfr"],["application/fractals","fif"],["application/freeloader","frl"],["application/futuresplash","spl"],["application/gnutar","tgz"],["application/groupwise","vew"],["application/hlp","hlp"],["application/hta","hta"],["application/hyperstudio","stk"],["application/i-deas","unv"],["application/iges",["iges","igs"]],["application/inf","inf"],["application/internet-property-stream","acx"],["application/ipfix","ipfix"],["application/java","class"],["application/java-archive","jar"],["application/java-byte-code","class"],["application/java-serialized-object","ser"],["application/java-vm","class"],["application/javascript","js"],["application/json","json"],["application/lha","lha"],["application/lzx","lzx"],["application/mac-binary","bin"],["application/mac-binhex","hqx"],["application/mac-binhex40","hqx"],["application/mac-compactpro","cpt"],["application/macbinary","bin"],["application/mads+xml","mads"],["application/marc","mrc"],["application/marcxml+xml","mrcx"],["application/mathematica","ma"],["application/mathml+xml","mathml"],["application/mbedlet","mbd"],["application/mbox","mbox"],["application/mcad","mcd"],["application/mediaservercontrol+xml","mscml"],["application/metalink4+xml","meta4"],["application/mets+xml","mets"],["application/mime","aps"],["application/mods+xml","mods"],["application/mp21","m21"],["application/mp4","mp4"],["application/mspowerpoint",["ppt","pot","pps","ppz"]],["application/msword",["doc","dot","w6w","wiz","word"]],["application/mswrite","wri"],["application/mxf","mxf"],["application/netmc","mcp"],["application/octet-stream",["*"]],["application/oda","oda"],["application/oebps-package+xml","opf"],["application/ogg","ogx"],["application/olescript","axs"],["application/onenote","onetoc"],["application/patch-ops-error+xml","xer"],["application/pdf","pdf"],["application/pgp-encrypted","asc"],["application/pgp-signature","pgp"],["application/pics-rules","prf"],["application/pkcs-12","p12"],["application/pkcs-crl","crl"],["application/pkcs10","p10"],["application/pkcs7-mime",["p7c","p7m"]],["application/pkcs7-signature","p7s"],["application/pkcs8","p8"],["application/pkix-attr-cert","ac"],["application/pkix-cert",["cer","crt"]],["application/pkix-crl","crl"],["application/pkix-pkipath","pkipath"],["application/pkixcmp","pki"],["application/plain","text"],["application/pls+xml","pls"],["application/p