import{c as q,e as X,g as H}from"./chunk-2AVGQ2MQ.js";var L=X(F=>{"use strict";F.byteLength=z;F.toByteArray=J;F.fromByteArray=Z;var h=[],l=[],$=typeof Uint8Array<"u"?Uint8Array:Array,W="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(b=0,j=W.length;b<j;++b)h[b]=W[b],l[W.charCodeAt(b)]=b;var b,j;l[45]=62;l[95]=63;function E(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");n===-1&&(n=t);var o=n===t?0:4-n%4;return[n,o]}function z(e){var t=E(e),n=t[0],o=t[1];return(n+o)*3/4-o}function G(e,t,n){return(t+n)*3/4-n}function J(e){var t,n=E(e),o=n[0],r=n[1],s=new $(G(e,o,r)),a=0,i=r>0?o-4:o,c;for(c=0;c<i;c+=4)t=l[e.charCodeAt(c)]<<18|l[e.charCodeAt(c+1)]<<12|l[e.charCodeAt(c+2)]<<6|l[e.charCodeAt(c+3)],s[a++]=t>>16&255,s[a++]=t>>8&255,s[a++]=t&255;return r===2&&(t=l[e.charCodeAt(c)]<<2|l[e.charCodeAt(c+1)]>>4,s[a++]=t&255),r===1&&(t=l[e.charCodeAt(c)]<<10|l[e.charCodeAt(c+1)]<<4|l[e.charCodeAt(c+2)]>>2,s[a++]=t>>8&255,s[a++]=t&255),s}function K(e){return h[e>>18&63]+h[e>>12&63]+h[e>>6&63]+h[e&63]}function Y(e,t,n){for(var o,r=[],s=t;s<n;s+=3)o=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(e[s+2]&255),r.push(K(o));return r.join("")}function Z(e){for(var t,n=e.length,o=n%3,r=[],s=16383,a=0,i=n-o;a<i;a+=s)r.push(Y(e,a,a+s>i?i:a+s));return o===1?(t=e[n-1],r.push(h[t>>2]+h[t<<4&63]+"==")):o===2&&(t=(e[n-2]<<8)+e[n-1],r.push(h[t>>10]+h[t>>4&63]+h[t<<2&63]+"=")),r.join("")}});var V=H(L(),1);if(typeof TextDecoder>"u"){let t=typeof process<"u"&&process.versions?.node?typeof __webpack_require__=="function"?__non_webpack_require__:q:void 0;global.TextDecoder=t("util").TextDecoder}var ee=32;function I(e,t,n=!1){let o=e.replace(/\r/g,"").split(`
`),r="";for(let i of o)i.endsWith("=")?r+=i.substring(0,i.length-1):r+=i+`
`;r.endsWith(`
`)&&(r=r.substring(0,r.length-1));let s=[];for(let i=0;i<r.length;i++){let c=r.charAt(i),f=r.charCodeAt(i);switch(c){case"=":let u=parseInt(r.charAt(i+1)+r.charAt(i+2),16);u?(s.push(u),i+=2):s.push(f);break;case"_":s.push(n?ee:f);break;default:s.push(f)}}let a=Uint8Array.from(s);return t?new TextDecoder(t).decode(a):a}function C(e){let t=e.replace(/\s+/g," ").split(" "),n="",o=!1;for(let r of t)O(r)?(!o&&n!==""&&(n+=" "),n+=te(r),o=!0):(n!==""?n+=" "+r.trim():n+=r.trim(),o=!1);return n.trim()}function O(e){if(!e.startsWith("=?")||!e.endsWith("?=")||e.includes(" "))return!1;let t=e.split("?");if(t.length!==5)return!1;let n=t[2].toLowerCase();return n==="q"||n==="b"}function te(e){if(!O(e))return e;let[t,n,o]=e.split("?").slice(1,4);switch(t=t.split("*")[0].toLowerCase(),n=n.toLowerCase(),n){case"b":let r=(0,V.toByteArray)(o);return r?new TextDecoder(t).decode(r):e;case"q":return I(o,t,!0);default:return e}}function _(e,t){return I(e,t,!1)}var k=H(L(),1);function A(e){return e.startsWith('"')&&(e=e.substring(1)),e.endsWith('"')&&(e=e.substring(0,e.length-1)),e}var S=99;function D(e){let t=e.split(";").map(o=>o.trim()),n={};if(t.length>=2)for(let o of t.slice(1)){let r=o.split("="),s=r[0].toLowerCase().trim();if(r.length===1){n[s]="";continue}let a=r[1].trim();r.length>2&&(a=r.slice(1).join("=")),a=A(a),n[s]=C(a)}return t[0]=t[0].toLowerCase(),{firstValue:t[0],parameters:n}}function U(e){let t=D(e);if(!t)return;let n,{firstValue:o,parameters:r}=t;return typeof r.charset=="string"?n=r.charset.split("*")[0]:o.startsWith("text/")&&(n="utf-8"),{type:o,encoding:n,parameters:r}}function P(e,t,n){let o={},r,s,a=t,i,c;for(;a<n;a++){let f=e[a];if(f.startsWith(" ")||f.startsWith("	")){if(typeof r!="string"||typeof s!="string")throw new Error("Unexpected space at the beginning of line "+(a+1));s+=`
`+f.trim()}else{if(r&&s){if(s=C(s),r in o){let d=o[r];typeof d=="string"?o[r]=d+", "+s:o[r]=s}else o[r]=s;r==="Content-Type"&&(i=U(s),i?.type?.startsWith("multipart")&&i?.parameters?.boundary&&(c=i?.parameters?.boundary))}if(f==="")break;if(c&&f.startsWith("--"+c)){a--;break}let u=f.indexOf(":");r=f.substring(0,u).split("-").map(d=>d.charAt(0).toUpperCase()+d.substring(1).toLowerCase()).join("-"),s=f.substring(u+1).trim()}}return!i&&!("Content-Type"in o)&&(i=U("text/plain")),[o,i,a]}function v(e,t,n,o,r){if(e>S)throw new Error("Maximum depth of "+S+" exceeded.");let s,[a,i,c]=P(t,n,o);if(!i)throw new Error('Invalid content type "'+a["Content-Type"]+'" at line '+(c+1));c++;let{type:f,parameters:u}=i;if(f?.startsWith("message")&&f!=="message/delivery-status"){let d=r??o,[x,p]=v(e+1,t,c,d);s={contentType:i,headers:a,body:x},c=p}else if(f?.startsWith("multipart/")){let d=u.boundary,x=[];if(!d)throw new Error("Multipart type lacking boundary at line "+(n+1));let p=!1;for(;c<o;c++){let g=t[c];if(g.startsWith("--"+d)){if(g.startsWith("--"+d+"--")){p=!0;break}let y=t.slice(c+2,o).findIndex(N=>N.startsWith("--"+d));if(!y)throw new Error("Multipart parsing failure (boundary lookahead failed) at line "+c);y+=c+2;let[w,M]=v(e+1,t,c+1,o,y);if(c=M,!w)throw new Error("Multipart parsing failure at line "+M);x.push(w)}}if(!p)throw new Error("Reached line "+(c+1)+' expecing boundary "--'+d+'--", but none was found');s={contentType:i,headers:a,body:x}}else{let d=r??o,x=t.slice(c,d),p=x.join(`
`);if(a["Content-Transfer-Encoding"]){let g=a["Content-Transfer-Encoding"].toLowerCase(),y=g==="base64"?x.join(""):p;if(i.type.startsWith("text/"))switch(g){case"base64":p=new TextDecoder(i.encoding).decode((0,k.toByteArray)(y));break;case"quoted-printable":p=_(y,i.encoding);break}else switch(g){case"base64":p=(0,k.toByteArray)(y);break;case"quoted-printable":p=_(y);break}}s={contentType:i,headers:a,body:p},c=d-1}return[s,c]}function R(e){let t=[],n="",o="",r="",s=e.headers["Content-Disposition"]?D(e.headers["Content-Disposition"]):void 0;if(e.body instanceof Uint8Array||typeof e.body=="string"&&s?.firstValue==="attachment"){let a=e.headers["Content-Id"];if(a){let i=a.indexOf("<"),c=a.indexOf(">");i!==-1&&c!==-1&&i<c?a=a.substring(i+1,c):a=a.trim()}t.push({contentType:e.contentType,body:e.body,contentId:a,filename:s?.parameters?.filename||e.contentType?.parameters?.name||e.headers["Content-Description"]})}else if(e.body instanceof Array||typeof e.body=="object"){let a=e.body instanceof Array?e.body:[e.body];for(let i of a){let[c,f,u,d]=R(i);o+=c?c+`
`:"",n+=f?f+`
`:"",r+=u?u+`
`:"",d.length>0&&t.push(...d)}}else e.contentType.type==="text/html"?n=e.body:e.contentType.type==="text/x-amp-html"?r=e.body:e.contentType.type.startsWith("text/")&&(o=e.body);return[o,n,r,t]}function Q(e){let t={};return t.to=m(e.To),t.cc=m(e.Cc),t.bcc=m(e.Bcc),t.replyTo=m(e["Reply-To"]),t.from=e.From?T(e.From):void 0,t.subject=e.Subject,typeof e.Date=="string"&&(t.date=new Date(e.Date)),t}function T(e){let t=e.indexOf("<"),n=e.lastIndexOf(">");if(t!==-1&&n!==-1){let o=A(e.substring(t+1,n).trim()),r=C(A(e.substring(0,t).trim()));return{address:o,name:r,raw:`"${r}" <${o}>`}}else return{address:e.trim(),raw:e}}function m(e){if(!e)return;let t=[],n="",o=!1;for(let r=0;r<e.length;r++)e[r]==='"'&&e[r-1]!=="\\"?(o=!o,n+=e[r]):e[r]===","&&!o?(t.push(T(n.trim())),n=""):n+=e[r];return n&&t.push(T(n.trim())),t}function B(e){let t=Q(e.headers);t.to=m(e.headers.To),t.cc=m(e.headers.Cc),t.bcc=m(e.headers.Bcc),t.replyTo=m(e.headers["Reply-To"]),t.from=e.headers.From?T(e.headers.From):void 0,t.subject=e.headers.Subject,typeof e.headers.Date=="string"&&(t.date=new Date(e.headers.Date));let[n,o,r,s]=R(e);return t.text=n.trim(),t.html=o.trim(),t.amp=r.trim()||void 0,t.attachments=s,t}function me(e){return typeof e=="string"?B(re(e)):B(e)}function re(e){let t=e.replace(/\r/g,"").split(`
`),[n]=v(1,t,0,t.length);return n}export{me as a};
