@remit/web-client-dist 0.0.402 → 0.0.403

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/assets/{BriefPane-D1HAyJwj.js → BriefPane-R4rcTAO3.js} +1 -1
  2. package/assets/{ErrorState-C332ruf-.js → ErrorState-C4QR2OHT.js} +1 -1
  3. package/assets/{FlaggedPane-CZNq4iiw.js → FlaggedPane-CzQn701M.js} +1 -1
  4. package/assets/{FullCompose-C2k-JMrq.js → FullCompose-CTpFjCtM.js} +1 -1
  5. package/assets/MailListHeader-D9UyUWpO.js +7 -0
  6. package/assets/{MailViewChrome-CDCDo6k8.js → MailViewChrome-BZcvy1C_.js} +1 -1
  7. package/assets/MailboxPane-U1SkJ4BI.js +1 -0
  8. package/assets/{NavMenuButton-C70EOG64.js → NavMenuButton-DcnV6Hj5.js} +1 -1
  9. package/assets/{OnboardingWizard-Dmvq_UiW.js → OnboardingWizard-Dz61uK44.js} +1 -1
  10. package/assets/{OutboxPane-CRrYo-Ah.js → OutboxPane-NAu0D-vN.js} +1 -1
  11. package/assets/_mailboxId-ppTzLsI0.js +1 -0
  12. package/assets/_messageId-4WjOyoww.js +1 -0
  13. package/assets/_messageId-CZYt4DU7.js +1 -0
  14. package/assets/_messageId-hnrVh4pn.js +1 -0
  15. package/assets/_outboxMessageId-Bu7skeag.js +1 -0
  16. package/assets/_threadId-B3mAevNn.js +1 -0
  17. package/assets/_threadId-BJHyXjLW.js +1 -0
  18. package/assets/_threadId-DXzrBvlx.js +1 -0
  19. package/assets/{accounts-DKymMdYg.js → accounts-Bjer_T0C.js} +1 -1
  20. package/assets/{advanced-7gVrHHYQ.js → advanced-10eV5vPf.js} +1 -1
  21. package/assets/{appearance-BMe1cgu9.js → appearance-DmVSvDqw.js} +1 -1
  22. package/assets/{attachment-file-8N0XrQKe.js → attachment-file-Bjm6lsCc.js} +1 -1
  23. package/assets/{avatar--VQz8d_L.js → avatar-DV1csnvT.js} +1 -1
  24. package/assets/{bottom-sheet-BvjDLGZa.js → bottom-sheet-BBgLAlb7.js} +1 -1
  25. package/assets/brief-Cr9YlJSF.js +1 -0
  26. package/assets/{brief-DRw-Bxe5.js → brief-fmvzcuvn.js} +1 -1
  27. package/assets/{browser-ponyfill-BspIUGg5.js → browser-ponyfill-IL0YXJKR.js} +1 -1
  28. package/assets/{bug-BRW8WWaz.js → bug-BjQ-Km4e.js} +1 -1
  29. package/assets/{circle-check-BTFZ8lhq.js → circle-check-CccsDKfb.js} +1 -1
  30. package/assets/{circle-check-big-CL1-ZB_O.js → circle-check-big-BLaZbuG9.js} +1 -1
  31. package/assets/{circle-help-yrrwRTfu.js → circle-help-BJd9ea_a.js} +1 -1
  32. package/assets/{clock-C0yW1eee.js → clock-Cyo25YTD.js} +1 -1
  33. package/assets/compose._-_outboxMessageId_-BAb_afcd.js +1 -0
  34. package/assets/compose._-_outboxMessageId_-CLnUkdJ7.js +1 -0
  35. package/assets/compose._-_outboxMessageId_-D_tVDnUF.js +1 -0
  36. package/assets/compose._-_outboxMessageId_-wfhWchvo.js +1 -0
  37. package/assets/{confirm-dialog-vx3llY3y.js → confirm-dialog-CQSTQRV2.js} +1 -1
  38. package/assets/{download-DnKAe7xV.js → download-KdO2vtfS.js} +1 -1
  39. package/assets/{filters-BZDRgbqS.js → filters-BQtHIEIt.js} +1 -1
  40. package/assets/flagged-CqBM51xW.js +1 -0
  41. package/assets/{flagged-CB_-eECE.js → flagged-D8pI5TWD.js} +1 -1
  42. package/assets/folders-DzKrhOGh.js +1 -0
  43. package/assets/format-DlutEuGc.js +1 -0
  44. package/assets/{help-copy-sDsaUy4w.js → help-copy-B9vfpQrv.js} +1 -1
  45. package/assets/index-4WjOyoww.js +1 -0
  46. package/assets/index-Bq2nvB6b.js +1 -0
  47. package/assets/index-CP_u7qA0.js +294 -0
  48. package/assets/index-CPxKl4U-.js +1 -0
  49. package/assets/{index-Bn4mOVkF.css → index-DQPXHKId.css} +1 -1
  50. package/assets/index-DU0Ih05G.js +1 -0
  51. package/assets/{index-Bi4k0VjD.js → index-EM4Uoip4.js} +6 -6
  52. package/assets/index-UR3grqCv.js +1 -0
  53. package/assets/index-hnrVh4pn.js +1 -0
  54. package/assets/index-yDlPrIVD.js +1 -0
  55. package/assets/index-zz2iXRjs.js +1 -0
  56. package/assets/{kbd-xKdnOGJZ.js → kbd-BaSoxAuP.js} +1 -1
  57. package/assets/{labels-rPmbMwhf.js → labels-O2y4gldY.js} +1 -1
  58. package/assets/{mail-o1u4DLkr.js → mail-Czi2Y_GZ.js} +1 -1
  59. package/assets/{mail-CehhDpTR.js → mail-gESMSqqx.js} +1 -1
  60. package/assets/{menu-DwmzGbPW.js → menu-xsfahEJ7.js} +1 -1
  61. package/assets/{onboarding-CxRKGCoI.js → onboarding-CEnH8bth.js} +1 -1
  62. package/assets/outbox-DIxEoc9O.js +1 -0
  63. package/assets/{pencil-DlDFsTyP.js → pencil-BXASGhia.js} +1 -1
  64. package/assets/{rich-text-Bs3K2ckY.js → rich-text-DGY3tZhu.js} +1 -1
  65. package/assets/{rich-text-spellcheck-worker-provider-BxTYxkIb.js → rich-text-spellcheck-worker-provider-DJ4digRi.js} +1 -1
  66. package/assets/{rotate-ccw-JyEVADG2.js → rotate-ccw-D3n8wodI.js} +1 -1
  67. package/assets/{row-actions-CujtZtFp.js → row-actions-P90tXTrG.js} +1 -1
  68. package/assets/{search-scope-BTnbXVTo.js → search-scope-BQ8HHXSV.js} +1 -1
  69. package/assets/search-token-index-CG7hPaco.js +1 -0
  70. package/assets/{search-view-Duk4APqX.js → search-view-CNPgAIwM.js} +1 -1
  71. package/assets/{senders-DD9A8SSC.js → senders-CcBjhLBV.js} +1 -1
  72. package/assets/settings-Em9by5Kf.js +1 -0
  73. package/assets/{settings-screen-DQHIX7C-.js → settings-screen-D-_K_C3M.js} +1 -1
  74. package/assets/{shield-check-DCsAIcLk.js → shield-check-CVmTR1hh.js} +1 -1
  75. package/assets/{suggested-vips-zREyYZ2F.js → suggested-vips-C-kYnJRU.js} +1 -1
  76. package/assets/{useDebouncedValue-CRl9MGSf.js → useDebouncedValue-0nS8-8zw.js} +1 -1
  77. package/assets/{useFilters-DHXpeKMC.js → useFilters-CCgvHNzK.js} +1 -1
  78. package/assets/{useLabels-BcSt40TB.js → useLabels-Bxa6Xpyj.js} +1 -1
  79. package/assets/{useMediaQuery-C90gO3CZ.js → useMediaQuery-kszmEDQl.js} +1 -1
  80. package/assets/{useMessageBodyContent-B-Ao8GWA.js → useMessageBodyContent-gWn_VAyS.js} +1 -1
  81. package/assets/{useRefreshControl-BAeVhAou.js → useRefreshControl-CEi6jGL4.js} +1 -1
  82. package/assets/{useSearchMirror-B7mwdkFd.js → useSearchMirror-DjVzjTGW.js} +1 -1
  83. package/assets/{useSearchTokenContext-CKiYWkSJ.js → useSearchTokenContext-Rec5qr0P.js} +2 -2
  84. package/assets/useSemanticSearch-CAmlG47i.js +1 -0
  85. package/assets/{useSignature-BUA39T5e.js → useSignature-DQ37CqeJ.js} +1 -1
  86. package/index.html +2 -2
  87. package/package.json +1 -1
  88. package/assets/MailListHeader-BWwp1ceH.js +0 -7
  89. package/assets/MailboxPane-DNUgw9hU.js +0 -1
  90. package/assets/_mailboxId-B-sHGfoz.js +0 -1
  91. package/assets/_messageId-C1qKPamr.js +0 -1
  92. package/assets/_messageId-C25UV9LM.js +0 -1
  93. package/assets/_messageId-DeSdz87B.js +0 -1
  94. package/assets/_outboxMessageId-B94Fh1en.js +0 -1
  95. package/assets/_threadId-C7emibLe.js +0 -1
  96. package/assets/_threadId-CViHQCwA.js +0 -1
  97. package/assets/_threadId-aEW3plLl.js +0 -1
  98. package/assets/brief-Bx3Y9xQn.js +0 -1
  99. package/assets/compose._-_outboxMessageId_-Bc7fc59g.js +0 -1
  100. package/assets/compose._-_outboxMessageId_-DHLSYgG-.js +0 -1
  101. package/assets/compose._-_outboxMessageId_-DN5Mftwg.js +0 -1
  102. package/assets/compose._-_outboxMessageId_-StmhPRcC.js +0 -1
  103. package/assets/enums-B_igRgfI.js +0 -1
  104. package/assets/flagged-4DoWrHJ3.js +0 -1
  105. package/assets/folders-DLa_CcpT.js +0 -1
  106. package/assets/format-D7umvejg.js +0 -1
  107. package/assets/index-B61k9RLS.js +0 -294
  108. package/assets/index-BCZl14-3.js +0 -1
  109. package/assets/index-C1qKPamr.js +0 -1
  110. package/assets/index-D9OAW-hw.js +0 -1
  111. package/assets/index-DeSdz87B.js +0 -1
  112. package/assets/index-DlSdWGZB.js +0 -1
  113. package/assets/index-DsUtV_jS.js +0 -1
  114. package/assets/index-J1diOeib.js +0 -1
  115. package/assets/index-_RaWFdnD.js +0 -1
  116. package/assets/move-options-YWV9hlAS.js +0 -1
  117. package/assets/outbox-BYHZDJTa.js +0 -1
  118. package/assets/search-token-index-D2uoFCjs.js +0 -1
  119. package/assets/settings-CAeDAiZ1.js +0 -1
  120. package/assets/useSemanticSearch-_EOOLQQp.js +0 -1
@@ -1 +1 @@
1
- import{G as M,bO as T,bP as O,w as f,r as i,bQ as P,m as h,j as W,bR as Y,bS as V,W as H,k as z,n as J,s as Z,bT as ee,bU as te}from"./index-B61k9RLS.js";import{u as se}from"./useMediaQuery-C90gO3CZ.js";function re(e){const t=M({warn:e?.router===void 0}),s=e?.router||t;return T(s.stores.__store,O(e,s))}function ne(e){const t=M();return T(t.stores.location,O(e,t))}const S="/mail/brief",A="/mail/$mailboxId",v="/mail/outbox",L="/mail/flagged";function oe(e){for(const t of e){if(t.routeId===S)return{list:"brief"};if(t.routeId===L)return{list:"flagged"};if(t.routeId===v)return{list:"outbox"};if(t.routeId===A)return{list:"mailbox",mailboxId:t.params?.mailboxId}}}function Te(e){const t=e.split(/[?#]/)[0].split("/").filter(Boolean);if(t[0]!=="mail")return"";const s=t[1];return s?s==="brief"?S:s==="flagged"?L:s==="outbox"?v:ae(s):""}function Oe(e){if(typeof e!="object"||e===null)return"";const{q:t}=e;return typeof t=="string"?t:""}function ae(e){return`${A}:${e}`}function Pe(e,t){return e===t?!0:e.startsWith(`${t}/`)}function Se(e){const t=e.split(/[?#]/)[0].split("/").filter(Boolean);return t[0]==="mail"&&t.length>2}function g(){const e=re({select:s=>oe(s.matches)?.list}),t=f({from:"/mail/$mailboxId",shouldThrow:!1});return{list:e,mailboxId:t?.mailboxId}}const k=["intelligence","nav","shortcuts"],ie=["nav","shortcuts"],ue=e=>ie.includes(e),ce=P(k);function x(e){const t=new Set(e.split(",").map(s=>ce.safeParse(s)).filter(s=>s.success).map(s=>s.data));return k.filter(s=>t.has(s))}function w(e){return k.filter(t=>e.includes(t)).join(",")}function Ae(){const e=ne({select:t=>w(x(t.hash))});return i.useMemo(()=>x(e),[e])}const le=(e,t)=>!ue(e)&&t;function de(e){return(t="")=>w(x(t).filter(s=>le(s,e)))}function y(){const e=se();return i.useMemo(()=>de(e),[e])}function ve(){const e=h();return i.useCallback(t=>{e({search:!0,hash:w(t),replace:!0,hashScrollIntoView:!1})},[e])}const _="/mail/brief/compose/{-$outboxMessageId}",D="/mail/flagged/compose/{-$outboxMessageId}",B="/mail/outbox/compose/{-$outboxMessageId}",U="/mail/$mailboxId/compose/{-$outboxMessageId}";function F(){const e=f({from:_,shouldThrow:!1}),t=f({from:D,shouldThrow:!1}),s=f({from:B,shouldThrow:!1}),r=f({from:U,shouldThrow:!1});return e??t??s??r}function Le(){return F()!==void 0}function _e(){return F()?.outboxMessageId}function fe(e,t,s){return e==="flagged"?{to:D,params:{outboxMessageId:s}}:e==="outbox"?{to:B,params:{outboxMessageId:s}}:e==="mailbox"&&t?{to:U,params:{mailboxId:t,outboxMessageId:s}}:{to:_,params:{outboxMessageId:s}}}function C(){const e=h(),t=y(),{list:s,mailboxId:r}=g();return i.useCallback((n,o)=>{e({...fe(s,r,n),search:a=>a,hash:o?.keepPanels?!0:t,replace:o?.replace??!1})},[e,t,s,r])}function De(){const e=C();return i.useCallback(()=>e(void 0),[e])}function Be(){const e=C();return i.useCallback(t=>e(t),[e])}function Ue(){const e=C();return i.useCallback(t=>e(t,{replace:!0,keepPanels:!0}),[e])}function Fe(){const e=h(),t=y(),{list:s,mailboxId:r}=g();return i.useCallback(()=>{const n=a=>a,o=t;if(s==="flagged"){e({to:"/mail/flagged",search:n,hash:o});return}if(s==="outbox"){e({to:"/mail/outbox",search:n,hash:o});return}if(s==="mailbox"&&r){e({to:"/mail/$mailboxId",params:{mailboxId:r},search:n,hash:o});return}e({to:"/mail/brief",search:n,hash:o})},[e,t,s,r])}const me=Y(V);function Ne({fragment:e,...t}){const s=y();return W.jsx(me,{...t,hash:e??s})}const he=["reply","reply-all","forward"],pe=P(he),N="/mail/brief/$threadId/$messageId/$mode/{-$outboxMessageId}",K="/mail/flagged/$threadId/$messageId/$mode/{-$outboxMessageId}",Q="/mail/$mailboxId/$threadId/$messageId/$mode/{-$outboxMessageId}";function q(){const e=f({from:N,shouldThrow:!1}),t=f({from:K,shouldThrow:!1}),s=f({from:Q,shouldThrow:!1});return e??t??s}function $(){const e=q();return i.useMemo(()=>{if(!e)return;const t=pe.safeParse(e.mode);return t.success?{kind:"reply",mode:t.data,threadId:e.threadId,sourceMessageId:e.messageId,outboxMessageId:e.outboxMessageId}:{kind:"unknown",segment:e.mode}},[e])}function Ke(){return $()?.kind==="reply"}function G(e,t,s,r){return e==="flagged"?{to:K,params:{...s,outboxMessageId:r}}:e==="mailbox"&&t?{to:Q,params:{...s,mailboxId:t,outboxMessageId:r}}:{to:N,params:{...s,outboxMessageId:r}}}function ge(e,t){if(e?.kind==="reply"&&e.threadId===t.threadId&&e.sourceMessageId===t.messageId)return e.outboxMessageId}function Qe(){const e=h(),t=y(),{list:s,mailboxId:r}=g(),n=$();return i.useCallback(o=>{e({...G(s,r,o,ge(n,o)),search:a=>a,hash:t})},[e,t,s,r,n])}function qe(e,t,s){if(!(!t||!s))return r=>e({threadId:t,messageId:s,mode:r})}function Ge(){const e=h(),{list:t,mailboxId:s}=g(),r=$();return i.useCallback(n=>{r?.kind==="reply"&&e({...G(t,s,{threadId:r.threadId,messageId:r.sourceMessageId,mode:r.mode},n),search:o=>o,hash:!0,replace:!0})},[e,t,s,r])}function Xe(){const e=h(),t=y(),{list:s,mailboxId:r}=g(),n=q();return i.useCallback(()=>{if(!n)return;const o=c=>c,a=t,u={threadId:n.threadId,messageId:n.messageId};if(s==="flagged"){e({to:"/mail/flagged/$threadId/$messageId",params:u,search:o,hash:a});return}if(s==="mailbox"&&r){e({to:"/mail/$mailboxId/$threadId/$messageId",params:{...u,mailboxId:r},search:o,hash:a});return}e({to:"/mail/brief/$threadId/$messageId",params:u,search:o,hash:a})},[e,t,s,r,n])}const ye=e=>{const t=e.filter(n=>!n.isMultipart&&n.disposition!=="attachment"&&n.mediaType==="TEXT"&&n.contentUrl.length>0),s=t.find(n=>n.mediaSubtype.toUpperCase()==="HTML");if(s)return{kind:"html",contentUrl:s.contentUrl};const r=t.find(n=>n.mediaSubtype.toUpperCase()==="PLAIN");return r?{kind:"text",contentUrl:r.contentUrl}:null},R={all:["messages"],detail:e=>[...R.all,"detail",e],body:e=>[...R.detail(e),"body"]};class m extends Error{reason;status;retryAfterSeconds;constructor(t,s,r,n){super(s),this.name="BodyFetchError",this.reason=t,this.status=r,this.retryAfterSeconds=n}}const be=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Ie=8,xe="x-remit-403-reason",Re=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},ke=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,we=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},Ce=async(e,t,s=async()=>null)=>{const r={},n=await s();n&&(r.Authorization=`Bearer ${n}`);const o=await te(e,{headers:r});if(o.status===202)throw new m("not-ready","Message body is still syncing",202,be(o.headers.get("Retry-After")));if(!o.ok){const c=o.headers.get(xe),b=Re(o.status,c);throw new m(b,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const a=o.headers.get("content-type");if(we(t,a))throw new m("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${a}`);const u=await o.text();if(ke(u,a))throw new m("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return u},$e=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),je=({messageId:e,bodyParts:t,enabled:s=!0})=>{const r=t?ye(t):null,n=H(),{getToken:o}=z(),a=i.useRef(null),u=J(),c=i.useRef(!1),b=i.useRef(null),E=e&&r?`${e}:${r.contentUrl}`:null;b.current!==E&&(b.current=E,c.current=!1);const l=Z({queryKey:e?[...R.body(e),r?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!r)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const p=c.current;return c.current=!1,$e({fetchContent:(d,j)=>Ce(d,j,o),refetchDescribeMessage:()=>u.refetchQueries({queryKey:ee({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:p})},enabled:s&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(p,d)=>d instanceof m&&d.reason==="not-ready"?p<Ie:p<1,retryDelay:(p,d)=>d instanceof m&&d.reason==="not-ready"?(c.current=!0,(d.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),I=l.isLoading&&!!r;i.useEffect(()=>{I&&(a.current=performance.now())},[I]),i.useEffect(()=>{l.isSuccess&&a.current!==null&&(n.recordTiming("message.body.load",Math.round(performance.now()-a.current)),a.current=null)},[l.isSuccess,n]);const X=l.data&&r?{kind:r.kind,body:l.data}:void 0;return{picked:r,data:X,isLoading:I,isError:l.isError,error:l.error,refetch:l.refetch}};export{m as B,Ne as N,ne as a,re as b,Oe as c,Ae as d,ve as e,Le as f,oe as g,Ke as h,ue as i,Pe as j,_e as k,Se as l,Te as m,Be as n,y as o,Qe as p,je as q,qe as r,Ue as s,Fe as t,De as u,Ge as v,Xe as w,Re as x,$ as y};
1
+ import{G as M,b$ as T,c0 as O,w as f,r as i,c1 as P,m as h,j as W,c2 as Y,c3 as V,W as H,k as z,n as J,s as Z,c4 as ee,c5 as te}from"./index-CP_u7qA0.js";import{u as se}from"./useMediaQuery-kszmEDQl.js";function re(e){const t=M({warn:e?.router===void 0}),s=e?.router||t;return T(s.stores.__store,O(e,s))}function ne(e){const t=M();return T(t.stores.location,O(e,t))}const A="/mail/brief",S="/mail/$mailboxId",v="/mail/outbox",L="/mail/flagged";function oe(e){for(const t of e){if(t.routeId===A)return{list:"brief"};if(t.routeId===L)return{list:"flagged"};if(t.routeId===v)return{list:"outbox"};if(t.routeId===S)return{list:"mailbox",mailboxId:t.params?.mailboxId}}}function Te(e){const t=e.split(/[?#]/)[0].split("/").filter(Boolean);if(t[0]!=="mail")return"";const s=t[1];return s?s==="brief"?A:s==="flagged"?L:s==="outbox"?v:ae(s):""}function Oe(e){if(typeof e!="object"||e===null)return"";const{q:t}=e;return typeof t=="string"?t:""}function ae(e){return`${S}:${e}`}function Pe(e,t){return e===t?!0:e.startsWith(`${t}/`)}function Ae(e){const t=e.split(/[?#]/)[0].split("/").filter(Boolean);return t[0]==="mail"&&t.length>2}function g(){const e=re({select:s=>oe(s.matches)?.list}),t=f({from:"/mail/$mailboxId",shouldThrow:!1});return{list:e,mailboxId:t?.mailboxId}}const k=["intelligence","nav","shortcuts"],ie=["nav","shortcuts"],ue=e=>ie.includes(e),ce=P(k);function x(e){const t=new Set(e.split(",").map(s=>ce.safeParse(s)).filter(s=>s.success).map(s=>s.data));return k.filter(s=>t.has(s))}function $(e){return k.filter(t=>e.includes(t)).join(",")}function Se(){const e=ne({select:t=>$(x(t.hash))});return i.useMemo(()=>x(e),[e])}const le=(e,t)=>!ue(e)&&t;function de(e){return(t="")=>$(x(t).filter(s=>le(s,e)))}function y(){const e=se();return i.useMemo(()=>de(e),[e])}function ve(){const e=h();return i.useCallback(t=>{e({search:!0,hash:$(t),replace:!0,hashScrollIntoView:!1})},[e])}const _="/mail/brief/compose/{-$outboxMessageId}",D="/mail/flagged/compose/{-$outboxMessageId}",B="/mail/outbox/compose/{-$outboxMessageId}",U="/mail/$mailboxId/compose/{-$outboxMessageId}";function F(){const e=f({from:_,shouldThrow:!1}),t=f({from:D,shouldThrow:!1}),s=f({from:B,shouldThrow:!1}),r=f({from:U,shouldThrow:!1});return e??t??s??r}function Le(){return F()!==void 0}function _e(){return F()?.outboxMessageId}function fe(e,t,s){return e==="flagged"?{to:D,params:{outboxMessageId:s}}:e==="outbox"?{to:B,params:{outboxMessageId:s}}:e==="mailbox"&&t?{to:U,params:{mailboxId:t,outboxMessageId:s}}:{to:_,params:{outboxMessageId:s}}}function w(){const e=h(),t=y(),{list:s,mailboxId:r}=g();return i.useCallback((n,o)=>{e({...fe(s,r,n),search:a=>a,hash:o?.keepPanels?!0:t,replace:o?.replace??!1})},[e,t,s,r])}function De(){const e=w();return i.useCallback(()=>e(void 0),[e])}function Be(){const e=w();return i.useCallback(t=>e(t),[e])}function Ue(){const e=w();return i.useCallback(t=>e(t,{replace:!0,keepPanels:!0}),[e])}function Fe(){const e=h(),t=y(),{list:s,mailboxId:r}=g();return i.useCallback(()=>{const n=a=>a,o=t;if(s==="flagged"){e({to:"/mail/flagged",search:n,hash:o});return}if(s==="outbox"){e({to:"/mail/outbox",search:n,hash:o});return}if(s==="mailbox"&&r){e({to:"/mail/$mailboxId",params:{mailboxId:r},search:n,hash:o});return}e({to:"/mail/brief",search:n,hash:o})},[e,t,s,r])}const me=Y(V);function Ne({fragment:e,...t}){const s=y();return W.jsx(me,{...t,hash:e??s})}const he=["reply","reply-all","forward"],pe=P(he),N="/mail/brief/$threadId/$messageId/$mode/{-$outboxMessageId}",K="/mail/flagged/$threadId/$messageId/$mode/{-$outboxMessageId}",q="/mail/$mailboxId/$threadId/$messageId/$mode/{-$outboxMessageId}";function G(){const e=f({from:N,shouldThrow:!1}),t=f({from:K,shouldThrow:!1}),s=f({from:q,shouldThrow:!1});return e??t??s}function C(){const e=G();return i.useMemo(()=>{if(!e)return;const t=pe.safeParse(e.mode);return t.success?{kind:"reply",mode:t.data,threadId:e.threadId,sourceMessageId:e.messageId,outboxMessageId:e.outboxMessageId}:{kind:"unknown",segment:e.mode}},[e])}function Ke(){return C()?.kind==="reply"}function Q(e,t,s,r){return e==="flagged"?{to:K,params:{...s,outboxMessageId:r}}:e==="mailbox"&&t?{to:q,params:{...s,mailboxId:t,outboxMessageId:r}}:{to:N,params:{...s,outboxMessageId:r}}}function ge(e,t){if(e?.kind==="reply"&&e.threadId===t.threadId&&e.sourceMessageId===t.messageId)return e.outboxMessageId}function qe(){const e=h(),t=y(),{list:s,mailboxId:r}=g(),n=C();return i.useCallback(o=>{e({...Q(s,r,o,ge(n,o)),search:a=>a,hash:t})},[e,t,s,r,n])}function Ge(e,t,s){if(!(!t||!s))return r=>e({threadId:t,messageId:s,mode:r})}function Qe(){const e=h(),{list:t,mailboxId:s}=g(),r=C();return i.useCallback(n=>{r?.kind==="reply"&&e({...Q(t,s,{threadId:r.threadId,messageId:r.sourceMessageId,mode:r.mode},n),search:o=>o,hash:!0,replace:!0})},[e,t,s,r])}function Xe(){const e=h(),t=y(),{list:s,mailboxId:r}=g(),n=G();return i.useCallback(()=>{if(!n)return;const o=c=>c,a=t,u={threadId:n.threadId,messageId:n.messageId};if(s==="flagged"){e({to:"/mail/flagged/$threadId/$messageId",params:u,search:o,hash:a});return}if(s==="mailbox"&&r){e({to:"/mail/$mailboxId/$threadId/$messageId",params:{...u,mailboxId:r},search:o,hash:a});return}e({to:"/mail/brief/$threadId/$messageId",params:u,search:o,hash:a})},[e,t,s,r,n])}const ye=e=>{const t=e.filter(n=>!n.isMultipart&&n.disposition!=="attachment"&&n.mediaType==="TEXT"&&n.contentUrl.length>0),s=t.find(n=>n.mediaSubtype.toUpperCase()==="HTML");if(s)return{kind:"html",contentUrl:s.contentUrl};const r=t.find(n=>n.mediaSubtype.toUpperCase()==="PLAIN");return r?{kind:"text",contentUrl:r.contentUrl}:null},R={all:["messages"],detail:e=>[...R.all,"detail",e],body:e=>[...R.detail(e),"body"]};class m extends Error{reason;status;retryAfterSeconds;constructor(t,s,r,n){super(s),this.name="BodyFetchError",this.reason=t,this.status=r,this.retryAfterSeconds=n}}const be=e=>{const t=Number.parseInt(e??"",10);return!Number.isFinite(t)||t<=0?1:Math.min(t,30)},Ie=8,xe="x-remit-403-reason",Re=(e,t)=>{const s=t?.trim()??"";return e===401?"auth":e===403?s.length>0?"auth":"body-missing":e===404?"body-missing":"generic"},ke=(e,t)=>(t??"").toLowerCase().startsWith("text/html")?/<div\s+id=["']root["']/i.test(e):!1,$e=(e,t)=>{const s=(t??"").toLowerCase();return!!(e==="text"&&s.startsWith("text/html"))},we=async(e,t,s=async()=>null)=>{const r={},n=await s();n&&(r.Authorization=`Bearer ${n}`);const o=await te(e,{headers:r});if(o.status===202)throw new m("not-ready","Message body is still syncing",202,be(o.headers.get("Retry-After")));if(!o.ok){const c=o.headers.get(xe),b=Re(o.status,c);throw new m(b,`Failed to load message body (${o.status} ${o.statusText})`,o.status)}const a=o.headers.get("content-type");if($e(t,a))throw new m("content-type-mismatch",`Refusing to render message body — expected ${t}, got Content-Type ${a}`);const u=await o.text();if(ke(u,a))throw new m("spa-shell-leak","Refusing to render message body — response looks like the SPA shell (CloudFront 403/404 fallback leaked through to /content/*)");return u},Ce=async(e,t)=>(t.isRetryAfterNotReady&&await e.refetchDescribeMessage(),e.fetchContent(t.contentUrl,t.kind)),je=({messageId:e,bodyParts:t,enabled:s=!0})=>{const r=t?ye(t):null,n=H(),{getToken:o}=z(),a=i.useRef(null),u=J(),c=i.useRef(!1),b=i.useRef(null),E=e&&r?`${e}:${r.contentUrl}`:null;b.current!==E&&(b.current=E,c.current=!1);const l=Z({queryKey:e?[...R.body(e),r?.contentUrl??null]:["messages","body","noop"],queryFn:()=>{if(!r)throw new Error("No renderable body part");if(!e)throw new Error("No messageId");const p=c.current;return c.current=!1,Ce({fetchContent:(d,j)=>we(d,j,o),refetchDescribeMessage:()=>u.refetchQueries({queryKey:ee({path:{messageId:e}})})},{contentUrl:r.contentUrl,kind:r.kind,isRetryAfterNotReady:p})},enabled:s&&!!e&&!!r,staleTime:300*1e3,gcTime:1800*1e3,retry:(p,d)=>d instanceof m&&d.reason==="not-ready"?p<Ie:p<1,retryDelay:(p,d)=>d instanceof m&&d.reason==="not-ready"?(c.current=!0,(d.retryAfterSeconds??1)*1e3):1e3,meta:{softError:!0}}),I=l.isLoading&&!!r;i.useEffect(()=>{I&&(a.current=performance.now())},[I]),i.useEffect(()=>{l.isSuccess&&a.current!==null&&(n.recordTiming("message.body.load",Math.round(performance.now()-a.current)),a.current=null)},[l.isSuccess,n]);const X=l.data&&r?{kind:r.kind,body:l.data}:void 0;return{picked:r,data:X,isLoading:I,isError:l.isError,error:l.error,refetch:l.refetch}};export{m as B,Ne as N,ne as a,re as b,Oe as c,Se as d,ve as e,Le as f,oe as g,Ke as h,ue as i,Pe as j,_e as k,Ae as l,Te as m,Be as n,y as o,qe as p,je as q,Ge as r,Ue as s,Fe as t,De as u,Qe as v,Xe as w,Re as x,C as y};
@@ -1 +1 @@
1
- import{j as E,e as q,b as j,B as D,r as i,ax as R,n as C,l as K,W as A,K as Q,J as $,L as z,N as B}from"./index-B61k9RLS.js";import{C as G}from"./circle-check-big-CL1-ZB_O.js";import{R as H,c as N}from"./search-token-index-D2uoFCjs.js";function oe({state:e,onRefresh:t,label:s,errorMessage:a,hasUpdate:n,size:u="sm",className:c}){const o=e==="refreshing",f=e==="error",h=e==="success",g=f?E.jsx(q,{className:"size-4 text-danger"}):h?E.jsx(G,{className:"size-4 text-positive"}):E.jsx(H,{className:j("size-4",o&&"animate-spin")}),y=f?`${s} — failed: ${a??"try again"}`:o?`${s} — refreshing`:h?`${s} — up to date`:n?`${s} — new mail`:s;return E.jsxs("div",{className:"relative inline-flex",children:[E.jsx(D,{variant:"ghost",size:u,icon:g,onClick:t,disabled:o,"aria-label":y,"aria-busy":o||void 0,title:f?a:s,className:c}),e==="idle"&&n&&E.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 size-1.5 rounded-full bg-accent-2"})]})}const W=new Set(["discovering_mailboxes","syncing_inbox","syncing_others"]);function P(e){return!!e&&W.has(e)}const L=3e3,U=L*2,M={syncing:!1,resolved:!1,synced:0,total:0};function ie(e,t){const s=e.join(","),[a,n]=i.useState(!1),[u,c]=i.useState(!1);i.useEffect(()=>{n(!1),c(!1)},[s,t]),i.useEffect(()=>{if(!t)return;const r=setTimeout(()=>c(!0),U);return()=>clearTimeout(r)},[s,t]);const o=N({queries:e.map(r=>({...R({path:{accountId:r}}),enabled:t&&!a,refetchInterval:L,meta:{softError:!0}}))}),f=o.every(r=>r.isSuccess||r.isError),h=o.length===0||f||u;let g=!1,y=0,w=0;for(const r of o)if(P(r.data?.syncPhase)){g=!0;for(const l of r.data?.mailboxes??[])y+=l.messagesSynced,w+=l.messagesTotal}const S=t&&h&&!g;return i.useEffect(()=>{S&&n(!0)},[S]),!t||!h?M:{syncing:g,resolved:!0,synced:y,total:w}}const k=6e4,I=new Set(["sent","drafts","trash","archive"]),v=(e,t)=>{const s=new Map;for(const a of e){const n=t.get(a.mailboxId)?.role;n&&I.has(n)||s.set(a.mailboxId,a.messagesTotal)}return s},J=(e,t)=>{for(const[s,a]of t)if(a>(e.get(s)??0))return!0;return!1},_=i.createContext(null),X=()=>{const e=i.useContext(_);if(!e)throw new Error("useMailFreshness must be used inside <MailFreshnessProvider>");return e};function ce({accountIds:e,children:t}){const s=C(),{resultFolderIndex:a}=K(),n=i.useRef(new Map),u=i.useRef(new Set),[c,o]=i.useState(new Set),f=N({queries:e.map(r=>({...R({path:{accountId:r}}),refetchInterval:k,staleTime:k,meta:{softError:!0}}))}),h=f.map(r=>r.dataUpdatedAt).join(","),g=e.join(",");i.useEffect(()=>{let r=!1;const l=new Set(c);e.forEach((d,x)=>{const p=f[x]?.data;if(!p)return;const m=v(p.mailboxes??[],a);if(!u.current.has(d)){u.current.add(d),n.current.set(d,m);return}if(l.has(d))return;const T=n.current.get(d)??new Map;J(T,m)&&(l.add(d),r=!0)}),r&&o(l)},[g,h]);const y=i.useCallback(r=>r.some(l=>c.has(l)),[c]),w=i.useCallback(r=>{o(l=>{if(r.every(x=>!l.has(x)))return l;const d=new Set(l);for(const x of r)d.delete(x);return d});for(const l of r){const d=s.getQueryData(R({path:{accountId:l}}).queryKey);n.current.set(l,v(d?.mailboxes??[],a)),u.current.add(l)}},[s,a]),S=i.useMemo(()=>({hasNewMail:y,acknowledge:w}),[y,w]);return E.jsx(_.Provider,{value:S,children:t})}const V=2e3,Y=45e3,Z=e=>new Promise(t=>setTimeout(t,e)),b=e=>e instanceof Error&&e.message?e.message:"Something went wrong",ee=e=>{z(e,{softError:!0},"user")&&B(e)},F=e=>e.reduce((t,s)=>Math.max(t,s.lastSyncedAt??0),0),O=(e,t)=>e.fetchQuery({...R({path:{accountId:t}}),staleTime:0}),se=async(e,t,s,a)=>{let n=!1;for(;;){const u=await O(e,t).then(f=>({ok:!0,data:f})).catch(f=>({ok:!1,error:f}));if(!u.ok)return{accountId:t,message:b(u.error)};const{syncPhase:c,mailboxes:o}=u.data;if(P(c))n=!0;else if(n||F(o??[])>s)return c==="error"?{accountId:t,message:"Sync failed for this account"}:void 0;if(Date.now()>=a)return{accountId:t,message:"Refresh is taking longer than usual"};await Z(V)}},te=async(e,t,s,a)=>{const n=await O(e,s).then(o=>({ok:!0,maxLastSynced:F(o.mailboxes??[])})).catch(o=>({ok:!1,error:o}));if(!n.ok)return{accountId:s,enqueued:!1,ok:!1,message:b(n.error)};const u=await $({path:{accountId:s},throwOnError:!0}).then(()=>({ok:!0})).catch(o=>({ok:!1,error:o}));if(!u.ok)return ee(u.error),{accountId:s,enqueued:!1,ok:!1,message:b(u.error)};t.recordEvent("sync.triggered");const c=await se(e,s,n.maxLastSynced,a);return c?{accountId:s,enqueued:!0,ok:!1,message:c.message}:{accountId:s,enqueued:!0,ok:!0}},ue=(e,t={})=>{const s=C(),a=A(),{acknowledge:n}=X(),[u,c]=i.useState("idle"),[o,f]=i.useState(),h=i.useRef(0),g=i.useRef(e);g.current=e;const y=i.useRef(t);y.current=t,i.useEffect(()=>{if(u!=="success")return;const S=setTimeout(()=>c("idle"),2e3);return()=>clearTimeout(S)},[u]);const w=i.useCallback(()=>{const S=g.current;if(S.length===0){c("error"),f("Nothing to refresh yet");return}const r=++h.current;c("refreshing"),f(void 0),(async()=>{const l=Date.now()+Y,d=await Promise.all(S.map(m=>te(s,a,m,l)));if(h.current!==r)return;const x=d.filter(m=>m.enqueued).map(m=>m.accountId);for(const m of x)s.invalidateQueries({queryKey:Q({path:{accountId:m}})});x.length>0&&(y.current.onSettled?.(),n(x));const p=d.filter(m=>!m.ok);p.length===0?c("success"):(c("error"),f(p[0]?.message))})()},[n,s,a]);return{state:u,errorMessage:o,refresh:w}};export{ce as M,oe as R,ue as a,ie as b,P as i,X as u};
1
+ import{j as E,e as q,b as j,B as D,r as i,ax as R,n as C,l as K,W as A,K as Q,J as $,L as z,N as B}from"./index-CP_u7qA0.js";import{C as G}from"./circle-check-big-BLaZbuG9.js";import{R as H,c as N}from"./search-token-index-CG7hPaco.js";function oe({state:e,onRefresh:t,label:s,errorMessage:a,hasUpdate:n,size:u="sm",className:c}){const o=e==="refreshing",f=e==="error",h=e==="success",g=f?E.jsx(q,{className:"size-4 text-danger"}):h?E.jsx(G,{className:"size-4 text-positive"}):E.jsx(H,{className:j("size-4",o&&"animate-spin")}),y=f?`${s} — failed: ${a??"try again"}`:o?`${s} — refreshing`:h?`${s} — up to date`:n?`${s} — new mail`:s;return E.jsxs("div",{className:"relative inline-flex",children:[E.jsx(D,{variant:"ghost",size:u,icon:g,onClick:t,disabled:o,"aria-label":y,"aria-busy":o||void 0,title:f?a:s,className:c}),e==="idle"&&n&&E.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 size-1.5 rounded-full bg-accent-2"})]})}const W=new Set(["discovering_mailboxes","syncing_inbox","syncing_others"]);function P(e){return!!e&&W.has(e)}const L=3e3,U=L*2,M={syncing:!1,resolved:!1,synced:0,total:0};function ie(e,t){const s=e.join(","),[a,n]=i.useState(!1),[u,c]=i.useState(!1);i.useEffect(()=>{n(!1),c(!1)},[s,t]),i.useEffect(()=>{if(!t)return;const r=setTimeout(()=>c(!0),U);return()=>clearTimeout(r)},[s,t]);const o=N({queries:e.map(r=>({...R({path:{accountId:r}}),enabled:t&&!a,refetchInterval:L,meta:{softError:!0}}))}),f=o.every(r=>r.isSuccess||r.isError),h=o.length===0||f||u;let g=!1,y=0,w=0;for(const r of o)if(P(r.data?.syncPhase)){g=!0;for(const l of r.data?.mailboxes??[])y+=l.messagesSynced,w+=l.messagesTotal}const S=t&&h&&!g;return i.useEffect(()=>{S&&n(!0)},[S]),!t||!h?M:{syncing:g,resolved:!0,synced:y,total:w}}const k=6e4,I=new Set(["sent","drafts","trash","archive"]),v=(e,t)=>{const s=new Map;for(const a of e){const n=t.get(a.mailboxId)?.role;n&&I.has(n)||s.set(a.mailboxId,a.messagesTotal)}return s},J=(e,t)=>{for(const[s,a]of t)if(a>(e.get(s)??0))return!0;return!1},_=i.createContext(null),X=()=>{const e=i.useContext(_);if(!e)throw new Error("useMailFreshness must be used inside <MailFreshnessProvider>");return e};function ce({accountIds:e,children:t}){const s=C(),{resultFolderIndex:a}=K(),n=i.useRef(new Map),u=i.useRef(new Set),[c,o]=i.useState(new Set),f=N({queries:e.map(r=>({...R({path:{accountId:r}}),refetchInterval:k,staleTime:k,meta:{softError:!0}}))}),h=f.map(r=>r.dataUpdatedAt).join(","),g=e.join(",");i.useEffect(()=>{let r=!1;const l=new Set(c);e.forEach((d,x)=>{const p=f[x]?.data;if(!p)return;const m=v(p.mailboxes??[],a);if(!u.current.has(d)){u.current.add(d),n.current.set(d,m);return}if(l.has(d))return;const T=n.current.get(d)??new Map;J(T,m)&&(l.add(d),r=!0)}),r&&o(l)},[g,h]);const y=i.useCallback(r=>r.some(l=>c.has(l)),[c]),w=i.useCallback(r=>{o(l=>{if(r.every(x=>!l.has(x)))return l;const d=new Set(l);for(const x of r)d.delete(x);return d});for(const l of r){const d=s.getQueryData(R({path:{accountId:l}}).queryKey);n.current.set(l,v(d?.mailboxes??[],a)),u.current.add(l)}},[s,a]),S=i.useMemo(()=>({hasNewMail:y,acknowledge:w}),[y,w]);return E.jsx(_.Provider,{value:S,children:t})}const V=2e3,Y=45e3,Z=e=>new Promise(t=>setTimeout(t,e)),b=e=>e instanceof Error&&e.message?e.message:"Something went wrong",ee=e=>{z(e,{softError:!0},"user")&&B(e)},F=e=>e.reduce((t,s)=>Math.max(t,s.lastSyncedAt??0),0),O=(e,t)=>e.fetchQuery({...R({path:{accountId:t}}),staleTime:0}),se=async(e,t,s,a)=>{let n=!1;for(;;){const u=await O(e,t).then(f=>({ok:!0,data:f})).catch(f=>({ok:!1,error:f}));if(!u.ok)return{accountId:t,message:b(u.error)};const{syncPhase:c,mailboxes:o}=u.data;if(P(c))n=!0;else if(n||F(o??[])>s)return c==="error"?{accountId:t,message:"Sync failed for this account"}:void 0;if(Date.now()>=a)return{accountId:t,message:"Refresh is taking longer than usual"};await Z(V)}},te=async(e,t,s,a)=>{const n=await O(e,s).then(o=>({ok:!0,maxLastSynced:F(o.mailboxes??[])})).catch(o=>({ok:!1,error:o}));if(!n.ok)return{accountId:s,enqueued:!1,ok:!1,message:b(n.error)};const u=await $({path:{accountId:s},throwOnError:!0}).then(()=>({ok:!0})).catch(o=>({ok:!1,error:o}));if(!u.ok)return ee(u.error),{accountId:s,enqueued:!1,ok:!1,message:b(u.error)};t.recordEvent("sync.triggered");const c=await se(e,s,n.maxLastSynced,a);return c?{accountId:s,enqueued:!0,ok:!1,message:c.message}:{accountId:s,enqueued:!0,ok:!0}},ue=(e,t={})=>{const s=C(),a=A(),{acknowledge:n}=X(),[u,c]=i.useState("idle"),[o,f]=i.useState(),h=i.useRef(0),g=i.useRef(e);g.current=e;const y=i.useRef(t);y.current=t,i.useEffect(()=>{if(u!=="success")return;const S=setTimeout(()=>c("idle"),2e3);return()=>clearTimeout(S)},[u]);const w=i.useCallback(()=>{const S=g.current;if(S.length===0){c("error"),f("Nothing to refresh yet");return}const r=++h.current;c("refreshing"),f(void 0),(async()=>{const l=Date.now()+Y,d=await Promise.all(S.map(m=>te(s,a,m,l)));if(h.current!==r)return;const x=d.filter(m=>m.enqueued).map(m=>m.accountId);for(const m of x)s.invalidateQueries({queryKey:Q({path:{accountId:m}})});x.length>0&&(y.current.onSettled?.(),n(x));const p=d.filter(m=>!m.ok);p.length===0?c("success"):(c("error"),f(p[0]?.message))})()},[n,s,a]);return{state:u,errorMessage:o,refresh:w}};export{ce as M,oe as R,ue as a,ie as b,P as i,X as u};
@@ -1 +1 @@
1
- import{m as v,l as x,r as I}from"./index-B61k9RLS.js";import{b as p,f as b,h as g,c as Q}from"./useMessageBodyContent-B-Ao8GWA.js";import{b as q}from"./search-view-Duk4APqX.js";function W(a){const t=v(),{searchInput:n,searchQuery:e}=x(),i=p({select:o=>Q(o.location.search)}),u=p({select:o=>o.location.pathname}),h=b(),f=g(),m=h||f,{to:s}=a,r="params"in a?a.params.mailboxId:void 0,l=r?`/mail/${r}`:s;I.useEffect(()=>{if(!q({searchInput:n,committedQuery:e,urlQuery:i,pathname:u,listPath:l}))return;const y=!!e&&i!==e&&!m,c=d=>({...d,q:e||void 0});if(!y){t({to:".",search:c,hash:!0,replace:!0});return}if(s==="/mail/$mailboxId"){if(!r)return;t({to:s,params:{mailboxId:r},search:c,hash:!0,replace:!0});return}t({to:s,search:c,hash:!0,replace:!0})},[n,e,i,t,s,r,l,u,m])}export{W as u};
1
+ import{m as v,l as x,r as I}from"./index-CP_u7qA0.js";import{b as p,f as b,h as g,c as Q}from"./useMessageBodyContent-gWn_VAyS.js";import{b as q}from"./search-view-CNPgAIwM.js";function W(a){const t=v(),{searchInput:n,searchQuery:e}=x(),i=p({select:o=>Q(o.location.search)}),u=p({select:o=>o.location.pathname}),h=b(),f=g(),m=h||f,{to:s}=a,r="params"in a?a.params.mailboxId:void 0,l=r?`/mail/${r}`:s;I.useEffect(()=>{if(!q({searchInput:n,committedQuery:e,urlQuery:i,pathname:u,listPath:l}))return;const y=!!e&&i!==e&&!m,c=d=>({...d,q:e||void 0});if(!y){t({to:".",search:c,hash:!0,replace:!0});return}if(s==="/mail/$mailboxId"){if(!r)return;t({to:s,params:{mailboxId:r},search:c,hash:!0,replace:!0});return}t({to:s,search:c,hash:!0,replace:!0})},[n,e,i,t,s,r,l,u,m])}export{W as u};
@@ -1,4 +1,4 @@
1
- import{bY as V,r as g,j as a,b,I as Q,n as Y,a5 as q,a7 as X,a8 as Z,bT as J,b5 as ee,k as te,e as se,X as re,l as ne}from"./index-B61k9RLS.js";import{K as k}from"./kbd-xKdnOGJZ.js";import{B as ae,q as oe,b as ie}from"./useMessageBodyContent-B-Ao8GWA.js";import{M as L}from"./enums-B_igRgfI.js";import{i as ce}from"./search-scope-BTnbXVTo.js";const le=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},de=()=>`
1
+ import{c9 as V,r as g,j as a,b,I as Q,n as q,a5 as Y,a7 as X,a8 as Z,c4 as J,bh as ee,k as te,e as se,X as re,br as L,l as ne}from"./index-CP_u7qA0.js";import{K as k}from"./kbd-BaSoxAuP.js";import{B as ae,q as oe,b as ie}from"./useMessageBodyContent-gWn_VAyS.js";import{i as ce}from"./search-scope-BQ8HHXSV.js";const le=(e,t)=>{const r=e==="newsletter"||e==="marketing"||t;return{framed:r,isPlain:!r}},de=()=>`
2
2
  /* Zero the UA default body margin and clamp the document to the iframe width so
3
3
  wide author markup can't push the body (and the page) past the viewport. */
4
4
  html, body {
@@ -81,4 +81,4 @@ a, a:visited {
81
81
  color: ${t.accent} !important;
82
82
  text-decoration: underline;
83
83
  }
84
- `},A="invert(0.92) hue-rotate(180deg)",N=`img,picture,video,svg,canvas,[style*='background-image'],[background]{filter:${A}}`,Pe=(e,t,s)=>{const r=e?v.dark.canvas:v.light.canvas;return s?e?t?`html,body{margin:0;background-color:${r};color-scheme:dark light}`:`html{margin:0;background-color:#ffffff;filter:${A}}body{margin:0}${N}`:"html,body{margin:0;background-color:#ffffff;color-scheme:light}":e?t?`html,body{margin:0;background-color:${r};color-scheme:dark light}`:`html{margin:0;background-color:${r}}body{margin:0;filter:${A}}${N}`:`html,body{margin:0;background-color:${r};color-scheme:light}`},Ke=(e,t,s,r=Be)=>{const n=t==="plain"?ze(s):Pe(s,$e.test(e),r.background),o=r.spacing?"":Me();return`${De}<style>${n}</style>${e}<style>${Oe()}${o}</style>`},Fe=5e4,He="allow-same-origin allow-popups allow-popups-to-escape-sandbox",Ue=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),Ge=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),We=e=>e===" "?!1:e.length===1?!0:Ge.has(e),S=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!We(e.key))return;const t=e.currentTarget??e.target,s=t?.defaultView?.parent;!s||s===t?.defaultView||s.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},C=({html:e,variant:t="framed",isDark:s=!1,declares:r,className:n})=>{const o=g.useRef(null),[l,m]=g.useState(0),d=g.useMemo(()=>Ke(e,t,s,r),[e,t,s,r]);return g.useEffect(()=>{const c=o.current;if(!c)return;const f=()=>{const i=c.contentDocument;if(!i?.body)return;const x=i.documentElement,y=Ue(i.body.scrollHeight,x?.scrollHeight??0,Fe);m(w=>w===y?w:y)};let u,h;const p=()=>{f(),u?.disconnect(),u=void 0,h?.removeEventListener("keydown",S),h?.removeEventListener("load",f,!0),h=void 0;const i=c.contentDocument;i?.body&&(u=new ResizeObserver(f),u.observe(i.body),i.documentElement&&u.observe(i.documentElement),i.addEventListener("load",f,!0),i.fonts?.ready.then(f),i.addEventListener("keydown",S),h=i)};return c.addEventListener("load",p),()=>{c.removeEventListener("load",p),h?.removeEventListener("keydown",S),h?.removeEventListener("load",f,!0),u?.disconnect()}},[]),a.jsx("iframe",{ref:o,title:"Email content",sandbox:He,srcDoc:d,className:n,style:{width:"100%",border:"none",display:"block",height:l===0?"1px":`${l}px`,colorScheme:"normal"}})},j=()=>a.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),kt=({className:e,children:t})=>a.jsx("div",{className:b("[&_.message-body-frame]:-mx-2 lg:[&_.message-body-frame]:-mx-4",e),children:t}),Ve=({html:e,text:t,isDark:s=!1,category:r,allowImages:n=!1,resolveCid:o,className:l,renderBlockedNotice:m})=>{const d=g.useMemo(()=>!e||typeof document>"u"?null:Le({allowExternalImages:n,resolveCid:o})(e),[e,n,o]),c=d?.html??null,{framed:f,isPlain:u}=le(r,d?.hasAuthorBackground??!1),h=g.useMemo(()=>({background:d?.hasAuthorBackground??!1,spacing:d?.hasAuthorSpacing??!1}),[d?.hasAuthorBackground,d?.hasAuthorSpacing]),p=g.useMemo(()=>!c||n?0:(c.match(/data-blocked-src/g)||[]).length,[c,n]);return!c&&!t?a.jsx("div",{className:b("message-body",l),children:a.jsx(j,{})}):a.jsxs("div",{className:b("message-body",l),children:[p>0&&a.jsx("div",{children:m?.(p)}),c?a.jsx("div",{className:"message-body-frame",children:f?a.jsx("div",{className:"w-full max-w-full",children:a.jsx(C,{html:c,variant:"framed",isDark:s,declares:h})}):a.jsx("div",{className:"max-w-full lg:max-w-2xl",children:a.jsx(C,{html:c,variant:u?"plain":"framed",isDark:s,declares:h})})}):t?a.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):a.jsx(j,{})]})};function St({message:e="Select a thread to read",icon:t,showHints:s=!0,className:r}){return a.jsxs("div",{className:b("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??a.jsx(Q,{className:"size-10 text-fg-subtle"}),a.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),s&&a.jsxs("p",{className:"text-2xs text-fg-subtle",children:[a.jsx(k,{children:"j"})," / ",a.jsx(k,{children:"k"})," to move, ",a.jsx(k,{children:"Enter"})," to open"]})]})}function M(e){const t=[];let s=-1,r=!1;for(let n=0;n<e.length;n++){const o=e[n];if(o==='"'){r=!r,s<0&&(s=n);continue}if(!r&&/\s/.test(o)){s>=0&&t.push({raw:e.slice(s,n),start:s,end:n}),s=-1;continue}s<0&&(s=n)}return s>=0&&t.push({raw:e.slice(s),start:s,end:e.length}),t}const Qe=e=>{if(!e.startsWith('"'))return e;const t=e.slice(1);return t.endsWith('"')?t.slice(0,-1):t};function Ye(e){const t=e.indexOf(":");if(t<=0)return;const s=e.slice(t+1);return{name:e.slice(0,t).toLowerCase(),value:Qe(s),rawValue:s}}const qe=e=>/[\s"]/.test(e),Xe=e=>qe(e)?`"${e.replace(/"/g,"")}"`:e,At=(e,t)=>`${e}:${Xe(t)}`,O=(e,t=Date.now())=>({value:e,setAt:t}),Ze=(e,t,s,r)=>{if(e.addressId!==t)return e;const n={...e.flags??{}};return s?n.trusted=O(!0,r):delete n.trusted,{...e,flags:n}},Je=(e,t,s,r)=>{const n=o=>o.map(l=>Ze(l,t,s,r));return{...e,envelope:{...e.envelope,from:n(e.envelope.from),to:n(e.envelope.to),cc:n(e.envelope.cc),bcc:n(e.envelope.bcc),replyTo:n(e.envelope.replyTo)}}},et=({messageId:e})=>{const t=Y(),{pushError:s}=q(),{mutate:r,isPending:n,error:o,reset:l}=X({...ee(),onMutate:async d=>{const c=d.path.addressId,u=d.body.flags?.trusted?.value===!0,h=J({path:{messageId:e}});await t.cancelQueries({queryKey:h});const p=t.getQueriesData({queryKey:h}).filter(i=>i[1]!==void 0).map(([i,x])=>({queryKey:i,data:x}));return t.setQueriesData({queryKey:h},i=>i&&Je(i,c,u)),{describePrefix:h,previous:p}},onError:(d,c,f)=>{if(f)for(const u of f.previous)t.setQueryData(u.queryKey,u.data);s(Z("Couldn't trust sender","The change wasn't saved.",d))},onSettled:(d,c,f,u)=>{u&&t.invalidateQueries({queryKey:u.describePrefix})}});return{toggleTrusted:(d,c)=>{r({path:{addressId:d},body:{flags:{trusted:O(!c)}}})},isPending:n,error:o,reset:l}},tt=()=>{const[e,t]=g.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return g.useEffect(()=>{const s=document.documentElement,r=new MutationObserver(()=>{t(s.classList.contains("dark"))});return r.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},st=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:s,onLoadOnce:r,onAlwaysTrust:n})=>a.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[a.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{type:"button",onClick:r,className:"text-accent hover:underline",children:"Load once"}),t&&a.jsx("button",{type:"button",onClick:n,"aria-busy":s,className:"text-accent hover:underline aria-busy:opacity-50",children:s?"Trusting…":"Always trust"})]})]}),rt=(e,t)=>{switch(e){case"auth":return{title:"Your session expired",detail:"Sign in again to reload the message body. Other parts of the app may also stop responding until you do."};case"body-missing":return{title:"Message body is missing in storage",detail:"A sync failure may have left this message without its body bytes. Contact support, or run the reconcile script to refetch from the upstream IMAP server."};case"content-type-mismatch":return{title:"Couldn't load message body",detail:"The server returned an unexpected content type for this part. The message body has not been rendered to keep you safe."};case"spa-shell-leak":return{title:"Couldn't load message body",detail:"The server returned the app shell instead of the message body. This is an infrastructure bug — please report it."};case"not-ready":return{title:"Message body is still syncing",detail:"This message's body hasn't finished downloading from the mail server yet. It should appear shortly — reopen the message to try again."};default:return{title:"Couldn't load message body",detail:t}}},nt=e=>e instanceof ae?e.reason:"generic",at=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",ot=({error:e,onRetry:t})=>{const s=nt(e),r=at(e),{title:n,detail:o}=rt(s,r),[l,m]=g.useState(!1),{Account:d}=te();return l?null:a.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":s,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[a.jsx(se,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"font-medium text-danger",children:n}),a.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[s==="auth"&&a.jsx(d,{children:({signOut:c})=>a.jsx("button",{type:"button",onClick:()=>c(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&a.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),a.jsx("button",{type:"button",onClick:()=>m(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:a.jsx(re,{className:"size-4","aria-hidden":"true"})})]})]})},it=()=>a.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),R=()=>a.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),Et=({bodyParts:e,html:t,text:s,isTrusted:r=!1,messageId:n,fromAddressId:o,category:l,className:m})=>{const[d,c]=g.useState(!1),f=r||d,u=tt(),{toggleTrusted:h,isPending:p}=et({messageId:n??""}),i=!!e&&e.length>0,{picked:x,data:y,isLoading:w,isError:D,error:z,refetch:P}=oe({messageId:n,bodyParts:e,enabled:i}),K=g.useMemo(()=>ue(e??[]),[e]),F=i&&y?.kind==="html"?y.body:t,H=i&&y?.kind==="text"?y.body:s;if(i){if(w)return a.jsx("div",{className:b("message-body",m),children:a.jsx(it,{})});if(D)return a.jsx("div",{className:b("message-body",m),children:a.jsx(ot,{error:z,onRetry:()=>P()})});if(!x)return a.jsx("div",{className:b("message-body",m),children:a.jsx(R,{})})}else if(!t&&!s)return a.jsx("div",{className:b("message-body",m),children:a.jsx(R,{})});const U=!!(o&&n),G=()=>{!o||p||(c(!0),h(o,!1))};return a.jsx(Ve,{className:m,html:F,text:H,isDark:u,category:l,allowImages:f,resolveCid:K,renderBlockedNotice:W=>a.jsx(st,{blockedImageCount:W,canAlwaysTrust:U,isTrustPending:p,onLoadOnce:()=>c(!0),onAlwaysTrust:G})})},$={personal:"Personal",uncategorized:"Unclassified",transactional:"Transactional",newsletter:"Newsletter",marketing:"Marketing",social:"Social",automated:"Automated"},ct=Object.values(L).map(e=>({value:e,label:$[e]})),lt={unclassified:"uncategorized"},dt=[{name:"from",label:"Sender",values:"contact"},{name:"subject",label:"Subject",values:"text"},{name:"category",label:"Category",values:"fixed",options:ct},{name:"is",label:"State",values:"fixed",options:[{value:"unread",label:"Unread"},{value:"read",label:"Read"},{value:"starred",label:"Starred"}]},{name:"has",label:"Contents",values:"fixed",options:[{value:"attachment",label:"Has attachment"}]},{name:"in",label:"Folder",values:"mailbox"},{name:"account",label:"Account",values:"account"},{name:"after",label:"Sent on or after",values:"date"},{name:"before",label:"Sent before",values:"date"}],ut=new Map(dt.map(e=>[e.name,e])),Tt=e=>ut.get(e.toLowerCase()),mt=/^\d{4}-\d{2}-\d{2}$/;function ft(e,t,s){if(!mt.test(s))return;const r=Date.parse(`${s}T00:00:00Z`);if(!Number.isNaN(r))return{type:e,raw:t,value:s,epochSeconds:Math.floor(r/1e3)}}function ht(e){const t=e.toLowerCase(),s=lt[t];return s||Object.values(L).find(n=>n===t)}function gt(e,t){switch(t.toLowerCase()){case"unread":return{type:"isUnread",raw:e};case"read":return{type:"isRead",raw:e};case"starred":case"flagged":return{type:"isStarred",raw:e};default:return}}function pt(e,t){const s=Ye(e);if(!s||s.value.length===0)return;const{name:r,value:n}=s;switch(r){case"from":return{type:"from",raw:e,value:n};case"subject":return{type:"subject",raw:e,value:n};case"category":{const o=ht(n);return o?{type:"category",raw:e,value:n,category:o}:void 0}case"is":return gt(e,n);case"has":return n.toLowerCase()==="attachment"?{type:"hasAttachment",raw:e}:void 0;case"before":case"after":return ft(r,e,n);case"in":{const o=t.mailboxesByName?.get(n.toLowerCase());return o?{type:"in",raw:e,value:n,mailboxId:o}:void 0}case"account":{const o=t.accountsByName?.get(n.toLowerCase());return o?{type:"account",raw:e,value:n,accountId:o}:void 0}default:return}}function Nt(e,t={}){const s=[],r=[];for(const n of M(e)){const o=pt(n.raw,t);o?s.push(o):r.push(n.raw)}return{freeText:r.join(" "),tokens:s}}function Ct(e,t){return M(e).filter(s=>s.raw!==t.raw).map(s=>s.raw).join(" ")}function jt(e){switch(e.type){case"from":return`From: ${e.value}`;case"subject":return`Subject: ${e.value}`;case"category":return`Category: ${$[e.category]}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"isRead":return"Read";case"isStarred":return"Starred";case"before":return`Before ${e.value}`;case"after":return`After ${e.value}`;case"in":return`In: ${e.value}`;case"account":return`Account: ${e.value}`}}function Rt(){const{mailboxNameIndex:e,accountNameIndex:t}=ne();return{...ie({select:r=>ce(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}export{kt as M,St as R,dt as S,M as a,Ye as b,Ve as c,et as d,Et as e,jt as f,Tt as g,Nt as p,Ct as r,At as s,Rt as u};
84
+ `},A="invert(0.92) hue-rotate(180deg)",N=`img,picture,video,svg,canvas,[style*='background-image'],[background]{filter:${A}}`,Pe=(e,t,s)=>{const r=e?v.dark.canvas:v.light.canvas;return s?e?t?`html,body{margin:0;background-color:${r};color-scheme:dark light}`:`html{margin:0;background-color:#ffffff;filter:${A}}body{margin:0}${N}`:"html,body{margin:0;background-color:#ffffff;color-scheme:light}":e?t?`html,body{margin:0;background-color:${r};color-scheme:dark light}`:`html{margin:0;background-color:${r}}body{margin:0;filter:${A}}${N}`:`html,body{margin:0;background-color:${r};color-scheme:light}`},Ke=(e,t,s,r=Be)=>{const n=t==="plain"?ze(s):Pe(s,$e.test(e),r.background),o=r.spacing?"":Me();return`${De}<style>${n}</style>${e}<style>${Oe()}${o}</style>`},Fe=5e4,He="allow-same-origin allow-popups allow-popups-to-escape-sandbox",Ue=(e,t,s)=>Math.min(Math.ceil(Math.max(e,t)),s),Ge=new Set(["Enter","Escape","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End"]),We=e=>e===" "?!1:e.length===1?!0:Ge.has(e),S=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!We(e.key))return;const t=e.currentTarget??e.target,s=t?.defaultView?.parent;!s||s===t?.defaultView||s.dispatchEvent(new KeyboardEvent("keydown",{key:e.key,code:e.code,shiftKey:e.shiftKey,bubbles:!0,cancelable:!0}))},C=({html:e,variant:t="framed",isDark:s=!1,declares:r,className:n})=>{const o=g.useRef(null),[l,m]=g.useState(0),d=g.useMemo(()=>Ke(e,t,s,r),[e,t,s,r]);return g.useEffect(()=>{const c=o.current;if(!c)return;const f=()=>{const i=c.contentDocument;if(!i?.body)return;const x=i.documentElement,y=Ue(i.body.scrollHeight,x?.scrollHeight??0,Fe);m(w=>w===y?w:y)};let u,h;const p=()=>{f(),u?.disconnect(),u=void 0,h?.removeEventListener("keydown",S),h?.removeEventListener("load",f,!0),h=void 0;const i=c.contentDocument;i?.body&&(u=new ResizeObserver(f),u.observe(i.body),i.documentElement&&u.observe(i.documentElement),i.addEventListener("load",f,!0),i.fonts?.ready.then(f),i.addEventListener("keydown",S),h=i)};return c.addEventListener("load",p),()=>{c.removeEventListener("load",p),h?.removeEventListener("keydown",S),h?.removeEventListener("load",f,!0),u?.disconnect()}},[]),a.jsx("iframe",{ref:o,title:"Email content",sandbox:He,srcDoc:d,className:n,style:{width:"100%",border:"none",display:"block",height:l===0?"1px":`${l}px`,colorScheme:"normal"}})},j=()=>a.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),vt=({className:e,children:t})=>a.jsx("div",{className:b("[&_.message-body-frame]:-mx-2 lg:[&_.message-body-frame]:-mx-4",e),children:t}),Ve=({html:e,text:t,isDark:s=!1,category:r,allowImages:n=!1,resolveCid:o,className:l,renderBlockedNotice:m})=>{const d=g.useMemo(()=>!e||typeof document>"u"?null:Le({allowExternalImages:n,resolveCid:o})(e),[e,n,o]),c=d?.html??null,{framed:f,isPlain:u}=le(r,d?.hasAuthorBackground??!1),h=g.useMemo(()=>({background:d?.hasAuthorBackground??!1,spacing:d?.hasAuthorSpacing??!1}),[d?.hasAuthorBackground,d?.hasAuthorSpacing]),p=g.useMemo(()=>!c||n?0:(c.match(/data-blocked-src/g)||[]).length,[c,n]);return!c&&!t?a.jsx("div",{className:b("message-body",l),children:a.jsx(j,{})}):a.jsxs("div",{className:b("message-body",l),children:[p>0&&a.jsx("div",{children:m?.(p)}),c?a.jsx("div",{className:"message-body-frame",children:f?a.jsx("div",{className:"w-full max-w-full",children:a.jsx(C,{html:c,variant:"framed",isDark:s,declares:h})}):a.jsx("div",{className:"max-w-full lg:max-w-2xl",children:a.jsx(C,{html:c,variant:u?"plain":"framed",isDark:s,declares:h})})}):t?a.jsx("pre",{className:"email-text whitespace-pre-wrap text-sm leading-relaxed",children:t}):a.jsx(j,{})]})};function kt({message:e="Select a thread to read",icon:t,showHints:s=!0,className:r}){return a.jsxs("div",{className:b("flex flex-1 flex-col items-center justify-center text-center",r),children:[t??a.jsx(Q,{className:"size-10 text-fg-subtle"}),a.jsx("p",{className:"mt-3 text-sm text-fg-muted",children:e}),s&&a.jsxs("p",{className:"text-2xs text-fg-subtle",children:[a.jsx(k,{children:"j"})," / ",a.jsx(k,{children:"k"})," to move, ",a.jsx(k,{children:"Enter"})," to open"]})]})}function M(e){const t=[];let s=-1,r=!1;for(let n=0;n<e.length;n++){const o=e[n];if(o==='"'){r=!r,s<0&&(s=n);continue}if(!r&&/\s/.test(o)){s>=0&&t.push({raw:e.slice(s,n),start:s,end:n}),s=-1;continue}s<0&&(s=n)}return s>=0&&t.push({raw:e.slice(s),start:s,end:e.length}),t}const Qe=e=>{if(!e.startsWith('"'))return e;const t=e.slice(1);return t.endsWith('"')?t.slice(0,-1):t};function qe(e){const t=e.indexOf(":");if(t<=0)return;const s=e.slice(t+1);return{name:e.slice(0,t).toLowerCase(),value:Qe(s),rawValue:s}}const Ye=e=>/[\s"]/.test(e),Xe=e=>Ye(e)?`"${e.replace(/"/g,"")}"`:e,St=(e,t)=>`${e}:${Xe(t)}`,O=(e,t=Date.now())=>({value:e,setAt:t}),Ze=(e,t,s,r)=>{if(e.addressId!==t)return e;const n={...e.flags??{}};return s?n.trusted=O(!0,r):delete n.trusted,{...e,flags:n}},Je=(e,t,s,r)=>{const n=o=>o.map(l=>Ze(l,t,s,r));return{...e,envelope:{...e.envelope,from:n(e.envelope.from),to:n(e.envelope.to),cc:n(e.envelope.cc),bcc:n(e.envelope.bcc),replyTo:n(e.envelope.replyTo)}}},et=({messageId:e})=>{const t=q(),{pushError:s}=Y(),{mutate:r,isPending:n,error:o,reset:l}=X({...ee(),onMutate:async d=>{const c=d.path.addressId,u=d.body.flags?.trusted?.value===!0,h=J({path:{messageId:e}});await t.cancelQueries({queryKey:h});const p=t.getQueriesData({queryKey:h}).filter(i=>i[1]!==void 0).map(([i,x])=>({queryKey:i,data:x}));return t.setQueriesData({queryKey:h},i=>i&&Je(i,c,u)),{describePrefix:h,previous:p}},onError:(d,c,f)=>{if(f)for(const u of f.previous)t.setQueryData(u.queryKey,u.data);s(Z("Couldn't trust sender","The change wasn't saved.",d))},onSettled:(d,c,f,u)=>{u&&t.invalidateQueries({queryKey:u.describePrefix})}});return{toggleTrusted:(d,c)=>{r({path:{addressId:d},body:{flags:{trusted:O(!c)}}})},isPending:n,error:o,reset:l}},tt=()=>{const[e,t]=g.useState(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"));return g.useEffect(()=>{const s=document.documentElement,r=new MutationObserver(()=>{t(s.classList.contains("dark"))});return r.observe(s,{attributes:!0,attributeFilter:["class"]}),()=>r.disconnect()},[]),e},st=({blockedImageCount:e,canAlwaysTrust:t,isTrustPending:s,onLoadOnce:r,onAlwaysTrust:n})=>a.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md bg-surface-sunken/50 px-3 py-2 text-sm",children:[a.jsxs("span",{className:"text-fg-muted",children:[e," image",e>1?"s":""," blocked for privacy"]}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{type:"button",onClick:r,className:"text-accent hover:underline",children:"Load once"}),t&&a.jsx("button",{type:"button",onClick:n,"aria-busy":s,className:"text-accent hover:underline aria-busy:opacity-50",children:s?"Trusting…":"Always trust"})]})]}),rt=(e,t)=>{switch(e){case"auth":return{title:"Your session expired",detail:"Sign in again to reload the message body. Other parts of the app may also stop responding until you do."};case"body-missing":return{title:"Message body is missing in storage",detail:"A sync failure may have left this message without its body bytes. Contact support, or run the reconcile script to refetch from the upstream IMAP server."};case"content-type-mismatch":return{title:"Couldn't load message body",detail:"The server returned an unexpected content type for this part. The message body has not been rendered to keep you safe."};case"spa-shell-leak":return{title:"Couldn't load message body",detail:"The server returned the app shell instead of the message body. This is an infrastructure bug — please report it."};case"not-ready":return{title:"Message body is still syncing",detail:"This message's body hasn't finished downloading from the mail server yet. It should appear shortly — reopen the message to try again."};default:return{title:"Couldn't load message body",detail:t}}},nt=e=>e instanceof ae?e.reason:"generic",at=e=>e instanceof Error?e.message:typeof e=="string"?e:"An unexpected error occurred while loading the message body.",ot=({error:e,onRetry:t})=>{const s=nt(e),r=at(e),{title:n,detail:o}=rt(s,r),[l,m]=g.useState(!1),{Account:d}=te();return l?null:a.jsxs("div",{role:"alert","data-testid":"message-body-error-banner","data-reason":s,className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[a.jsx(se,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"font-medium text-danger",children:n}),a.jsx("p",{className:"text-fg-muted mt-1 break-words",children:o})]}),a.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[s==="auth"&&a.jsx(d,{children:({signOut:c})=>a.jsx("button",{type:"button",onClick:()=>c(),className:"text-sm font-medium text-accent hover:underline",children:"Sign in again"})}),t&&a.jsx("button",{type:"button",onClick:t,className:"text-sm font-medium text-accent hover:underline",children:"Retry"}),a.jsx("button",{type:"button",onClick:()=>m(!0),"aria-label":"Dismiss message body error",className:"rounded-md p-1 text-fg-muted hover:bg-surface-raised hover:text-fg transition-colors",children:a.jsx(re,{className:"size-4","aria-hidden":"true"})})]})]})},it=()=>a.jsxs("div",{className:"animate-pulse space-y-2",role:"status","aria-label":"Loading message body",children:[a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-full"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-11/12"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-3/4"}),a.jsx("div",{className:"h-4 bg-surface-sunken rounded w-5/6"})]}),R=()=>a.jsx("p",{className:"text-fg-muted text-sm italic",children:"This message has no body content."}),At=({bodyParts:e,html:t,text:s,isTrusted:r=!1,messageId:n,fromAddressId:o,category:l,className:m})=>{const[d,c]=g.useState(!1),f=r||d,u=tt(),{toggleTrusted:h,isPending:p}=et({messageId:n??""}),i=!!e&&e.length>0,{picked:x,data:y,isLoading:w,isError:D,error:z,refetch:P}=oe({messageId:n,bodyParts:e,enabled:i}),K=g.useMemo(()=>ue(e??[]),[e]),F=i&&y?.kind==="html"?y.body:t,H=i&&y?.kind==="text"?y.body:s;if(i){if(w)return a.jsx("div",{className:b("message-body",m),children:a.jsx(it,{})});if(D)return a.jsx("div",{className:b("message-body",m),children:a.jsx(ot,{error:z,onRetry:()=>P()})});if(!x)return a.jsx("div",{className:b("message-body",m),children:a.jsx(R,{})})}else if(!t&&!s)return a.jsx("div",{className:b("message-body",m),children:a.jsx(R,{})});const U=!!(o&&n),G=()=>{!o||p||(c(!0),h(o,!1))};return a.jsx(Ve,{className:m,html:F,text:H,isDark:u,category:l,allowImages:f,resolveCid:K,renderBlockedNotice:W=>a.jsx(st,{blockedImageCount:W,canAlwaysTrust:U,isTrustPending:p,onLoadOnce:()=>c(!0),onAlwaysTrust:G})})},$={personal:"Personal",uncategorized:"Unclassified",transactional:"Transactional",newsletter:"Newsletter",marketing:"Marketing",social:"Social",automated:"Automated"},ct=Object.values(L).map(e=>({value:e,label:$[e]})),lt={unclassified:"uncategorized"},dt=[{name:"from",label:"Sender",values:"contact"},{name:"subject",label:"Subject",values:"text"},{name:"category",label:"Category",values:"fixed",options:ct},{name:"is",label:"State",values:"fixed",options:[{value:"unread",label:"Unread"},{value:"read",label:"Read"},{value:"starred",label:"Starred"}]},{name:"has",label:"Contents",values:"fixed",options:[{value:"attachment",label:"Has attachment"}]},{name:"in",label:"Folder",values:"mailbox"},{name:"account",label:"Account",values:"account"},{name:"after",label:"Sent on or after",values:"date"},{name:"before",label:"Sent before",values:"date"}],ut=new Map(dt.map(e=>[e.name,e])),Et=e=>ut.get(e.toLowerCase()),mt=/^\d{4}-\d{2}-\d{2}$/;function ft(e,t,s){if(!mt.test(s))return;const r=Date.parse(`${s}T00:00:00Z`);if(!Number.isNaN(r))return{type:e,raw:t,value:s,epochSeconds:Math.floor(r/1e3)}}function ht(e){const t=e.toLowerCase(),s=lt[t];return s||Object.values(L).find(n=>n===t)}function gt(e,t){switch(t.toLowerCase()){case"unread":return{type:"isUnread",raw:e};case"read":return{type:"isRead",raw:e};case"starred":case"flagged":return{type:"isStarred",raw:e};default:return}}function pt(e,t){const s=qe(e);if(!s||s.value.length===0)return;const{name:r,value:n}=s;switch(r){case"from":return{type:"from",raw:e,value:n};case"subject":return{type:"subject",raw:e,value:n};case"category":{const o=ht(n);return o?{type:"category",raw:e,value:n,category:o}:void 0}case"is":return gt(e,n);case"has":return n.toLowerCase()==="attachment"?{type:"hasAttachment",raw:e}:void 0;case"before":case"after":return ft(r,e,n);case"in":{const o=t.mailboxesByName?.get(n.toLowerCase());return o?{type:"in",raw:e,value:n,mailboxId:o}:void 0}case"account":{const o=t.accountsByName?.get(n.toLowerCase());return o?{type:"account",raw:e,value:n,accountId:o}:void 0}default:return}}function Tt(e,t={}){const s=[],r=[];for(const n of M(e)){const o=pt(n.raw,t);o?s.push(o):r.push(n.raw)}return{freeText:r.join(" "),tokens:s}}function Nt(e,t){return M(e).filter(s=>s.raw!==t.raw).map(s=>s.raw).join(" ")}function Ct(e){switch(e.type){case"from":return`From: ${e.value}`;case"subject":return`Subject: ${e.value}`;case"category":return`Category: ${$[e.category]}`;case"hasAttachment":return"Has attachment";case"isUnread":return"Unread";case"isRead":return"Read";case"isStarred":return"Starred";case"before":return`Before ${e.value}`;case"after":return`After ${e.value}`;case"in":return`In: ${e.value}`;case"account":return`Account: ${e.value}`}}function jt(){const{mailboxNameIndex:e,accountNameIndex:t}=ne();return{...ie({select:r=>ce(r.matches)})?{}:{mailboxesByName:e},accountsByName:t}}export{vt as M,kt as R,dt as S,M as a,qe as b,Ve as c,et as d,At as e,Ct as f,Et as g,Tt as p,Nt as r,St as s,jt as u};
@@ -0,0 +1 @@
1
+ import{n as M,a5 as C,a7 as k,bA as E,bB as I,r as x,j as d,bC as h,bD as A,bE as j,l as R,s as D,bF as Q,br as O}from"./index-CP_u7qA0.js";import{P}from"./attachment-file-Bjm6lsCc.js";import{ak as _,al as z,am as N,an as q}from"./MailListHeader-D9UyUWpO.js";import{a as B}from"./useLabels-Bxa6Xpyj.js";import{b as F}from"./useMessageBodyContent-gWn_VAyS.js";import{n as U}from"./search-query-Cr_ZXBCp.js";import{s as w}from"./search-scope-BQ8HHXSV.js";import{u as G,p as K}from"./useSearchTokenContext-Rec5qr0P.js";const V=t=>{const{mailboxId:a,messages:i}=t,l=M(),{pushError:c}=C(),{mutateAsync:n,isPending:s}=k({...I(),onError:(o,u)=>{c({title:u.body.action==="Remove"?"Couldn't remove label":"Couldn't apply label",detail:E(o),error:o})},onSettled:(o,u,m)=>{_(l,z(N(m.body.messageIds??[],i??[],a)))}});return{applyLabel:x.useCallback((o,u,m)=>{o.length!==0&&q(o,p=>n({body:{messageIds:p,labelId:u,action:m}}))},[n]),isPending:s}};function re({accountId:t,mailboxId:a,messageIds:i}){const{labels:l}=B(t),{applyLabel:c}=V({mailboxId:a}),n=x.useMemo(()=>l.map(s=>({key:s.labelId,label:s.name,icon:d.jsx("span",{className:`size-2.5 rounded-full ${A(s.color)?h[s.color]:h.Default}`}),onSelect:()=>c(i,s.labelId,"Apply")})),[l,i,c]);return n.length===0?null:d.jsx(P,{triggerLabel:"Apply label to selected messages",triggerIcon:d.jsx(j,{className:"size-4 text-fg-subtle"}),triggerText:"Apply label",items:n,align:"start",nested:!0,touch:!1,triggerClassName:"min-h-11 w-full justify-start gap-3 px-4 py-2.5 text-sm font-normal text-fg"})}const $=20,H=new Set(Object.values(O)),J=t=>t!==void 0&&H.has(t)?t:void 0,W=t=>{if(t.some(a=>a.type==="isUnread"))return!1;if(t.some(a=>a.type==="isRead"))return!0};function ne({mailboxId:t,filterCategory:a}={}){const{searchQuery:i}=R(),l=G(),c=F({select:e=>e.matches}),n=U(i),{freeText:s,tokens:r}=K(n,l),o=s.length>0,u=r.find(e=>e.type==="category"),m=J(a)??u?.category,p=r.some(e=>e.type==="hasAttachment")?!0:void 0,b=r.some(e=>e.type==="isStarred")?!0:void 0,y=W(r),f=r.find(e=>e.type==="after"),g=r.find(e=>e.type==="before"),S=r.find(e=>e.type==="in"),T=w({matches:c,callerMailboxId:t,inTokenMailboxId:S?.mailboxId}),{data:v,isLoading:L}=D({...Q({query:{query:s,mailboxId:T,limit:$,...m!==void 0?{category:m}:{},...p!==void 0?{hasAttachment:p}:{},...b!==void 0?{hasStars:b}:{},...y!==void 0?{isRead:y}:{},...f?{sentDateFrom:f.epochSeconds}:{},...g?{sentDateTo:g.epochSeconds}:{}}}),enabled:o,staleTime:6e4});return{hits:v?.items??[],isLoading:o&&L}}export{re as L,ne as u};
@@ -1 +1 @@
1
- import{n as g,a5 as p,s as f,Q as m,r,a7 as y,a8 as T,V as E,a9 as x}from"./index-B61k9RLS.js";const i={html:"",plainText:""},d=e=>{const u=g(),{pushError:o}=p(),{data:n}=f({...m(),staleTime:1/0}),l=r.useMemo(()=>{if(!e||!n)return i;const t=n.accounts.find(a=>a.accountId===e);return t?{html:t.signatureHtml??"",plainText:t.signaturePlainText??""}:i},[e,n]),s=y({...x(),onSuccess:()=>{u.invalidateQueries({queryKey:E()})},onError:t=>{o(T("Couldn't save signature","The signature wasn't saved.",t))}}),c=r.useCallback((t,a)=>{e&&s.mutate({path:{accountId:e},body:{signatureHtml:t,signaturePlainText:a}})},[e,s]);return{signature:l,setSignature:c,isSaving:s.isPending}};export{d as u};
1
+ import{n as g,a5 as p,s as f,Q as m,r,a7 as y,a8 as T,V as E,a9 as x}from"./index-CP_u7qA0.js";const i={html:"",plainText:""},d=e=>{const u=g(),{pushError:o}=p(),{data:n}=f({...m(),staleTime:1/0}),l=r.useMemo(()=>{if(!e||!n)return i;const t=n.accounts.find(a=>a.accountId===e);return t?{html:t.signatureHtml??"",plainText:t.signaturePlainText??""}:i},[e,n]),s=y({...x(),onSuccess:()=>{u.invalidateQueries({queryKey:E()})},onError:t=>{o(T("Couldn't save signature","The signature wasn't saved.",t))}}),c=r.useCallback((t,a)=>{e&&s.mutate({path:{accountId:e},body:{signatureHtml:t,signaturePlainText:a}})},[e,s]);return{signature:l,setSignature:c,isSaving:s.isPending}};export{d as u};
package/index.html CHANGED
@@ -38,8 +38,8 @@
38
38
  } catch (_) {}
39
39
  })();
40
40
  </script>
41
- <script type="module" crossorigin src="/assets/index-B61k9RLS.js"></script>
42
- <link rel="stylesheet" crossorigin href="/assets/index-Bn4mOVkF.css">
41
+ <script type="module" crossorigin src="/assets/index-CP_u7qA0.js"></script>
42
+ <link rel="stylesheet" crossorigin href="/assets/index-DQPXHKId.css">
43
43
  </head>
44
44
  <body>
45
45
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/web-client-dist",
3
- "version": "0.0.402",
3
+ "version": "0.0.403",
4
4
  "description": "Built Remit web client — static assets and the default runtime config.",
5
5
  "files": [
6
6
  "**/*"