Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Immo-Ka Admin iOS9// File : ImmoKaAdmin/Features/MailView.swift10// Description : courrier des administrateurs — boîtes et dossiers avec11// leurs non-lus, liste paginée par curseur, recherche,12// lecture (texte brut par défaut), lu / non lu, étoile,13// corbeille, réponse, nouveau message, pièces jointes14// remises à la feuille de partage. Le HTML d'un courriel15// n'est jamais interprété avec JavaScript : « Afficher la16// mise en forme » passe par une vue isolée (HTMLView).17// Module : ImmoKaAdmin18// Repository : https://git.spboucher.ai/immo-ka-admin-ios19// Project Website : https://www.immo-ka.com20// Created : 2026-11-3021// Last Modified : 2026-11-3022//23// =============================================================================24// AUTHOR & PROFESSIONAL AFFILIATION25// =============================================================================26//27// Author : Simon-Pierre Boucher28// Position : Professor of Finance29// Institution : Université du Québec en Outaouais (UQO)30// Department : Département des sciences administratives31// Organization : SP Boucher32//33// Website : https://spboucher.ai34// Git : https://git.spboucher.ai35//36// =============================================================================37// OFFICIAL CONTACT DIRECTORY38// =============================================================================39//40// General : info@spboucher.ai41// Professional : contact@spboucher.ai42// Direct : simon@spboucher.ai43// Research : research@spboucher.ai44// Development : dev@spboucher.ai45// Support : support@spboucher.ai46// Security/Admin : admin@spboucher.ai47// Notifications : notifications@spboucher.ai48//49// Preferred Contact: support@spboucher.ai50//51// =============================================================================52// COPYRIGHT & INTELLECTUAL PROPERTY53// =============================================================================54//55// Copyright (c) 202656// Simon-Pierre Boucher57//58// All rights reserved where applicable.59//60// This file is governed by the applicable project license,61// copyright notices, institutional agreements and relevant law.62//63// Unless expressly authorized by the applicable license or64// rights holder, copying, redistribution, sublicensing,65// publication and commercial exploitation are not permitted.66//67// Existing third-party rights and notices remain unaffected.68//69// =============================================================================70// CONFIDENTIALITY & SECURITY71// =============================================================================72//73// Classification : Public74// Distribution : Public repository; use is governed by the project license75// Security Contact : admin@spboucher.ai76//77// Access to this source does not independently grant permission78// to redistribute or disclose confidential materials.79//80// Do not embed credentials, private keys, access tokens,81// certificates or confidential personal information.82//83// =============================================================================84// LICENSE & MAINTENANCE85// =============================================================================86//87// License : None specified (no license file in this repository)88// Maintainer : Simon-Pierre Boucher89// Technical Contact: dev@spboucher.ai90//91// =============================================================================92// END OF SP BOUCHER SOURCE HEADER93// =============================================================================9495import SwiftUI9697struct MailView: View {98 @Environment(AdminSession.self) private var session99 @State private var boxes: [Mailbox]?100 @State private var address = ""101 @State private var folder = "inbox"102 @State private var messages: [MailMessage] = []103 @State private var cursor: String?104 @State private var hasMore = false105 @State private var loading = true106 @State private var loadingMore = false107 @State private var failure: String?108 @State private var search = ""109 @State private var composing: MailDraft?110111 private var addresses: [String] { boxes?.map(\.address) ?? session.me?.admin.mailboxes ?? [] }112 private var key: String { address + "|" + folder + "|" + search.trimmingCharacters(in: .whitespaces) }113114 var body: some View {115 Group {116 if session.me?.mail == false {117 EmptyState(symbol: "envelope.badge.shield.half.filled", title: "Courrier non configuré", message: "Le serveur n'a pas d'accès au courrier pour l'administration.")118 .frame(maxWidth: .infinity, maxHeight: .infinity)119 } else {120 VStack(spacing: 0) {121 header122 Divider().overlay(Theme.line)123 list124 }125 }126 }127 .background(Theme.bg)128 .navigationTitle("Courrier")129 .navigationBarTitleDisplayMode(.inline)130 .searchable(text: $search, prompt: "Chercher dans ce dossier")131 .toolbar {132 ToolbarItem(placement: .primaryAction) {133 Button { composing = MailDraft(from: address, to: [], cc: nil, subject: "", text: "", replyToMessageID: nil) } label: { Image(systemName: "square.and.pencil") }134 .disabled(address.isEmpty)135 .accessibilityLabel("Nouveau message")136 .accessibilityIdentifier("mail.compose")137 }138 }139 .navigationDestination(for: String.self) { id in140 MailMessageView(id: id) { Task { await reload() } }141 }142 .sheet(item: $composing) { draft in143 ComposeView(draft: draft, addresses: addresses) { Task { await reload() } }144 }145 .task { await loadBoxes() }146 .task(id: key) {147 guard !address.isEmpty else { return }148 // la recherche attend la fin de la frappe149 if !search.isEmpty { try? await Task.sleep(for: .milliseconds(400)); if Task.isCancelled { return } }150 await loadFirstPage()151 }152 }153154 private var header: some View {155 HStack(spacing: 10) {156 Menu {157 Picker("Boîte", selection: $address) { ForEach(addresses, id: \.self) { Text(verbatim: $0).tag($0) } }158 } label: {159 Label { Text(verbatim: address.isEmpty ? "Boîte" : address).lineLimit(1) } icon: { Image(systemName: "at") }160 .font(.subheadline.weight(.medium))161 }162 .accessibilityLabel("Boîte : \(address)")163 .accessibilityIdentifier("mail.box")164 Spacer(minLength: 8)165 Menu {166 Picker("Dossier", selection: $folder) {167 ForEach(MailFolder.roles, id: \.self) { role in168 let unread = boxes?.first { $0.address == address }?.folder(role: role)?.unread ?? 0169 Label(unread > 0 ? "\(MailFolder.label(role: role)) (\(unread))" : MailFolder.label(role: role), systemImage: MailFolder.symbol(role: role)).tag(role)170 }171 }172 } label: {173 Label(MailFolder.label(role: folder), systemImage: MailFolder.symbol(role: folder)).font(.subheadline.weight(.medium))174 }175 .accessibilityLabel("Dossier : \(MailFolder.label(role: folder))")176 .accessibilityIdentifier("mail.folder")177 }178 .padding(.horizontal, 16).frame(minHeight: 44)179 }180181 @ViewBuilder182 private var list: some View {183 if loading && messages.isEmpty {184 ProgressView().frame(maxWidth: .infinity, maxHeight: .infinity)185 } else if let failure, messages.isEmpty {186 EmptyState(symbol: "wifi.exclamationmark", title: "Chargement impossible", message: failure, actionTitle: "Réessayer") { Task { await reload() } }187 .frame(maxWidth: .infinity, maxHeight: .infinity)188 } else {189 List {190 if messages.isEmpty {191 EmptyState(symbol: "tray", title: search.isEmpty ? "Aucun message dans ce dossier" : "Aucun message ne correspond").listRowBackground(Color.clear)192 }193 ForEach(messages) { m in194 NavigationLink(value: m.id) { MailRow(message: m, sent: folder == "sent") }.accessibilityIdentifier("mail.row")195 }196 if hasMore {197 Button { Task { await loadMore() } } label: {198 HStack { if loadingMore { ProgressView() }; Text("Messages plus anciens") }.frame(maxWidth: .infinity)199 }200 .disabled(loadingMore)201 .accessibilityIdentifier("mail.more")202 }203 }204 .listStyle(.plain)205 .refreshable { await reload() }206 }207 }208209 private func loadBoxes() async {210 do {211 let b = try await session.call { try await $0.mailboxes() }212 boxes = b213 if address.isEmpty || !b.contains(where: { $0.address == address }) { address = b.first?.address ?? "" }214 } catch {215 if address.isEmpty { address = session.me?.admin.mailboxes.first ?? "" }216 if messages.isEmpty { failure = AdminError.message(error) }217 }218 }219220 private func loadFirstPage() async {221 loading = true222 let q = search.trimmingCharacters(in: .whitespaces)223 do {224 let page = try await session.call { try await $0.messages(address: address, folder: folder, text: q.isEmpty ? nil : q) }225 if Task.isCancelled { return }226 messages = page.data; cursor = page.nextCursor; hasMore = page.hasMore && page.nextCursor != nil227 failure = nil228 } catch is CancellationError {229 return230 } catch {231 messages = []; hasMore = false232 failure = AdminError.message(error)233 }234 loading = false235 }236237 private func loadMore() async {238 guard hasMore, let cursor, !loadingMore else { return }239 loadingMore = true240 defer { loadingMore = false }241 let q = search.trimmingCharacters(in: .whitespaces)242 if let page = try? await session.call({ try await $0.messages(address: address, folder: folder, text: q.isEmpty ? nil : q, cursor: cursor) }) {243 messages += page.data.filter { n in !messages.contains { $0.id == n.id } }244 self.cursor = page.nextCursor; hasMore = page.hasMore && page.nextCursor != nil245 }246 }247248 private func reload() async {249 await loadBoxes()250 await loadFirstPage()251 }252}253254private struct MailRow: View {255 let message: MailMessage256 let sent: Bool257 var body: some View {258 let m = message259 HStack(alignment: .top, spacing: 10) {260 Circle().fill(m.unread ? Theme.accentUI : Color.clear).frame(width: 8, height: 8).padding(.top, 6).accessibilityHidden(true)261 VStack(alignment: .leading, spacing: 3) {262 HStack(alignment: .firstTextBaseline) {263 Text(verbatim: sent ? "À : " + (m.to.first.map { MailLogic.label($0) } ?? "—") : MailLogic.label(m.from.first))264 .font(.subheadline.weight(m.unread ? .bold : .medium)).foregroundStyle(Theme.ink).lineLimit(1)265 Spacer(minLength: 6)266 if m.starred { Image(systemName: "star.fill").font(.caption).foregroundStyle(Theme.high).accessibilityHidden(true) }267 if m.hasAttachment { Image(systemName: "paperclip").font(.caption).foregroundStyle(Theme.ink3).accessibilityHidden(true) }268 Text(verbatim: Fmt.short(m.date)).font(.caption).monospacedDigit().foregroundStyle(Theme.ink3)269 }270 Text(verbatim: m.subject ?? "(sans objet)").font(.subheadline).foregroundStyle(m.unread ? Theme.ink : Theme.ink2).lineLimit(1)271 if let p = m.preview { Text(verbatim: p.replacingOccurrences(of: "\n", with: " ")).font(.footnote).foregroundStyle(Theme.ink3).lineLimit(2) }272 }273 }274 .padding(.vertical, 2)275 .accessibilityElement(children: .ignore)276 .accessibilityLabel("\(m.unread ? "Non lu. " : "")\(m.starred ? "Marqué d'une étoile. " : "")\(MailLogic.label(m.from.first)). \(m.subject ?? "sans objet"). \(Fmt.short(m.date))\(m.hasAttachment ? ". Pièce jointe" : "")")277 }278}279280// MARK: - Lecture281282struct MailMessageView: View {283 let id: String284 var changed: () -> Void285 @Environment(AdminSession.self) private var session286 @Environment(Navigator.self) private var nav287 @Environment(\.dismiss) private var dismiss288 @State private var message: MailMessage?289 @State private var failure: String?290 @State private var actionError: String?291 @State private var showFormatted = false292 @State private var replying: MailDraft?293 @State private var confirmTrash = false294 @State private var downloading: String?295 @State private var shared: SharedFile?296297 var body: some View {298 Loadable(value: message, failure: failure, retry: { Task { await load() } }) { m in299 ScrollView {300 VStack(alignment: .leading, spacing: 14) {301 Text(verbatim: m.subject ?? "(sans objet)").font(.editorial(22)).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)302 .textSelection(.enabled).accessibilityAddTraits(.isHeader).accessibilityIdentifier("mail.subject")303 VStack(alignment: .leading, spacing: 4) {304 line("De", m.from.map(MailLogic.full).joined(separator: ", "))305 line("À", m.to.map(MailLogic.full).joined(separator: ", "))306 if !m.cc.isEmpty { line("Cc", m.cc.map(MailLogic.full).joined(separator: ", ")) }307 if !m.replyTo.isEmpty { line("Répondre à", m.replyTo.map(MailLogic.full).joined(separator: ", ")) }308 line("Reçu", m.date.map { Fmt.dateTime($0) } ?? "—")309 line("Boîte", m.mailbox)310 if m.spf != nil || m.dkim != nil || m.dmarc != nil {311 line("Authentification", ["SPF \(m.spf ?? "—")", "DKIM \(m.dkim ?? "—")", "DMARC \(m.dmarc ?? "—")"].joined(separator: " · "))312 }313 }314 if let actionError { ErrorBanner(text: actionError) }315 // actions dans le contenu : sur iPhone, une barre d'outils du bas serait couverte par la barre d'onglets316 HStack(spacing: 8) {317 Button { replying = MailLogic.replyDraft(m, when: m.date.map { Fmt.dateTime($0) } ?? "") } label: { Label("Répondre", systemImage: "arrowshape.turn.up.left") }318 .buttonStyle(SoftButtonStyle())319 .accessibilityIdentifier("mail.reply")320 Spacer(minLength: 0)321 iconButton(m.unread ? "envelope.open" : "envelope.badge", m.unread ? "Marquer comme lu" : "Marquer comme non lu", "mail.unread") { patch(unread: !m.unread) }322 iconButton(m.starred ? "star.fill" : "star", m.starred ? "Retirer l'étoile" : "Marquer d'une étoile", "mail.star") { patch(starred: !m.starred) }323 iconButton("trash", "Mettre à la corbeille", "mail.trash", tint: Theme.bad) { confirmTrash = true }324 }325 Divider().overlay(Theme.line)326 if m.truncated { Label("Ce message est très long : seul son début est affiché.", systemImage: "scissors").font(.footnote).foregroundStyle(Theme.ink3) }327 if showFormatted, let html = m.html, !html.isEmpty {328 HTMLView(html: html).frame(minHeight: 420)329 .clipShape(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))330 .overlay(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous).strokeBorder(Theme.line, lineWidth: 1))331 .accessibilityIdentifier("mail.html")332 Text("Mise en forme affichée sans exécuter de script ni charger d'image ou de contenu distant ; les liens sont inertes.").font(.caption).foregroundStyle(Theme.ink3)333 } else {334 let body = MailLogic.bodyText(m)335 if body.isEmpty { Text("Ce message n'a pas de texte.").font(.subheadline).foregroundStyle(Theme.ink3) }336 else { PlainText(text: body, font: .body, color: Theme.ink).accessibilityIdentifier("mail.body") }337 }338 if let html = m.html, !html.isEmpty {339 Button(showFormatted ? "Afficher le texte brut" : "Afficher la mise en forme") { showFormatted.toggle() }340 .font(.subheadline.weight(.medium)).frame(minHeight: 44).accessibilityIdentifier("mail.format")341 }342 if !m.attachments.isEmpty {343 VStack(alignment: .leading, spacing: 8) {344 Text("Pièces jointes").font(.caption.weight(.semibold)).tracking(0.8).textCase(.uppercase).foregroundStyle(Theme.ink3)345 ForEach(m.attachments) { a in346 Button { download(m, a) } label: {347 HStack(spacing: 10) {348 if downloading == a.id { ProgressView() } else { Image(systemName: "paperclip").foregroundStyle(Theme.ink2) }349 VStack(alignment: .leading, spacing: 1) {350 Text(verbatim: MailLogic.fileName(a)).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink).lineLimit(1)351 Text(verbatim: [a.type, MailLogic.size(a.size)].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: " · ")).font(.caption).foregroundStyle(Theme.ink3)352 }353 Spacer()354 Image(systemName: "square.and.arrow.up").foregroundStyle(Theme.ink3)355 }356 .padding(12)357 .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))358 }359 .buttonStyle(.plain)360 .disabled(downloading != nil)361 .accessibilityLabel("Télécharger et partager \(MailLogic.fileName(a))")362 .accessibilityIdentifier("mail.attachment")363 }364 Text("Une pièce jointe n'est jamais ouverte par l'app : elle est téléchargée puis remise à la feuille de partage.").font(.caption).foregroundStyle(Theme.ink3)365 }366 }367 }368 .padding(20)369 .frame(maxWidth: 820, alignment: .leading)370 .frame(maxWidth: .infinity)371 }372 }373 .background(Theme.bg)374 .navigationTitle("Message")375 .navigationBarTitleDisplayMode(.inline)376 .task { await load() }377 .sheet(item: $replying) { draft in378 ComposeView(draft: draft, addresses: session.me?.admin.mailboxes ?? [draft.from], lockedSender: true) { changed() }379 }380 .sheet(item: $shared) { ShareSheet(url: $0.url) }381 .alert("Mettre ce message à la corbeille ?", isPresented: $confirmTrash) {382 Button("Mettre à la corbeille", role: .destructive) { trash() }383 Button("Annuler", role: .cancel) {}384 }385 }386387 private func iconButton(_ symbol: String, _ label: String, _ id: String, tint: Color = Theme.ink, action: @escaping () -> Void) -> some View {388 Button(action: action) {389 Image(systemName: symbol).font(.body.weight(.medium)).foregroundStyle(tint)390 .frame(width: 44, height: 44)391 .background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))392 }393 .buttonStyle(.plain)394 .accessibilityLabel(label)395 .accessibilityIdentifier(id)396 }397398 private func line(_ label: String, _ value: String) -> some View {399 HStack(alignment: .firstTextBaseline, spacing: 8) {400 Text(label).font(.caption.weight(.semibold)).foregroundStyle(Theme.ink3).frame(width: 96, alignment: .leading)401 Text(verbatim: value.isEmpty ? "—" : value).font(.footnote).foregroundStyle(Theme.ink2).textSelection(.enabled).fixedSize(horizontal: false, vertical: true)402 }403 .accessibilityElement(children: .combine)404 }405406 private func load() async {407 do {408 var m = try await session.call { try await $0.message(id) }409 failure = nil410 // ouvrir un message non lu le marque comme lu, comme dans tout logiciel de courrier411 if m.unread, (try? await session.call({ try await $0.patchMessage(id, unread: false) })) != nil { m.unread = false; changed() }412 message = m413 } catch {414 if message == nil { failure = AdminError.message(error) }415 }416 }417418 private func patch(unread: Bool? = nil, starred: Bool? = nil) {419 actionError = nil420 Task {421 do {422 try await session.call { try await $0.patchMessage(id, unread: unread, starred: starred) }423 if let unread { message?.unread = unread; nav.show(unread ? "Marqué comme non lu" : "Marqué comme lu") }424 if let starred { message?.starred = starred }425 changed()426 } catch { actionError = AdminError.message(error) }427 }428 }429430 private func trash() {431 actionError = nil432 Task {433 do { try await session.call { try await $0.trashMessage(id) }; nav.show("Message mis à la corbeille"); changed(); dismiss() }434 catch { actionError = AdminError.message(error) }435 }436 }437438 private func download(_ m: MailMessage, _ a: MailAttachment) {439 downloading = a.id; actionError = nil440 Task {441 defer { downloading = nil }442 do { shared = SharedFile(url: try await session.call { try await $0.attachment(messageID: m.id, attachment: a) }.url) }443 catch { actionError = AdminError.message(error) }444 }445 }446}447448struct SharedFile: Identifiable { let url: URL; var id: String { url.path } }449450/// Feuille de partage du système pour un fichier téléchargé.451struct ShareSheet: UIViewControllerRepresentable {452 let url: URL453 func makeUIViewController(context: Context) -> UIActivityViewController { UIActivityViewController(activityItems: [url], applicationActivities: nil) }454 func updateUIViewController(_ controller: UIActivityViewController, context: Context) {}455}456457// MARK: - Rédaction458459extension MailDraft: Identifiable { var id: String { (replyToMessageID ?? "nouveau") + "|" + from } }460461struct ComposeView: View {462 let addresses: [String]463 var lockedSender = false464 var sent: () -> Void465 @Environment(AdminSession.self) private var session466 @Environment(Navigator.self) private var nav467 @Environment(\.dismiss) private var dismiss468 @State private var from: String469 @State private var to: String470 @State private var cc = ""471 @State private var subject: String472 @State private var text: String473 private let replyTo: String?474 @State private var busy = false475 @State private var failure: String?476 @State private var confirmDiscard = false477 private let initialText: String478479 init(draft: MailDraft, addresses: [String], lockedSender: Bool = false, sent: @escaping () -> Void) {480 self.addresses = addresses; self.lockedSender = lockedSender; self.sent = sent481 _from = State(initialValue: draft.from.isEmpty ? (addresses.first ?? "") : draft.from)482 _to = State(initialValue: draft.to.joined(separator: ", "))483 _subject = State(initialValue: draft.subject)484 _text = State(initialValue: draft.text)485 replyTo = draft.replyToMessageID486 initialText = draft.text487 }488489 private var recipients: [String] { MailLogic.parseRecipients(to) }490 private var copies: [String] { MailLogic.parseRecipients(cc) }491 private var invalid: [String] { (recipients + copies).filter { !MailLogic.looksLikeEmail($0) } }492 private var ready: Bool { !from.isEmpty && !recipients.isEmpty && invalid.isEmpty && !subject.trimmingCharacters(in: .whitespaces).isEmpty && !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }493494 var body: some View {495 NavigationStack {496 Form {497 if let failure { Section { ErrorBanner(text: failure).listRowInsets(EdgeInsets()) } }498 Section {499 if lockedSender || addresses.count < 2 {500 InfoRow(label: "De", value: from)501 } else {502 Picker("De", selection: $from) { ForEach(addresses, id: \.self) { Text(verbatim: $0).tag($0) } }.accessibilityIdentifier("compose.from")503 }504 TextField("À", text: $to, axis: .vertical).textInputAutocapitalization(.never).autocorrectionDisabled().keyboardType(.emailAddress)505 .accessibilityLabel("Destinataires").accessibilityIdentifier("compose.to")506 TextField("Cc (facultatif)", text: $cc, axis: .vertical).textInputAutocapitalization(.never).autocorrectionDisabled().keyboardType(.emailAddress)507 .accessibilityLabel("Copie").accessibilityIdentifier("compose.cc")508 TextField("Objet", text: $subject).accessibilityIdentifier("compose.subject")509 } footer: {510 if !invalid.isEmpty { Text(verbatim: "Adresse non reconnue : \(invalid.joined(separator: ", "))").foregroundStyle(Theme.bad) }511 else if lockedSender { Text("La réponse part de la boîte qui a reçu le message.") }512 else { Text("Plusieurs adresses : séparez-les par une virgule.") }513 }514 Section {515 TextEditor(text: $text).frame(minHeight: 240).accessibilityLabel("Message").accessibilityIdentifier("compose.text")516 }517 }518 .navigationTitle(replyTo == nil ? "Nouveau message" : "Réponse")519 .navigationBarTitleDisplayMode(.inline)520 .toolbar {521 ToolbarItem(placement: .cancellationAction) {522 Button("Annuler") { if text != initialText || !to.isEmpty && replyTo == nil { confirmDiscard = true } else { dismiss() } }.accessibilityIdentifier("compose.cancel")523 }524 ToolbarItem(placement: .confirmationAction) {525 Button(action: send) { if busy { ProgressView() } else { Text("Envoyer").fontWeight(.semibold) } }526 .disabled(!ready || busy)527 .accessibilityIdentifier("compose.send")528 }529 }530 .alert("Abandonner ce message ?", isPresented: $confirmDiscard) {531 Button("Abandonner", role: .destructive) { dismiss() }532 Button("Continuer d'écrire", role: .cancel) {}533 } message: {534 Text("Il n'est pas enregistré comme brouillon.")535 }536 .interactiveDismissDisabled(busy)537 }538 }539540 private func send() {541 guard ready, !busy else { return }542 busy = true; failure = nil543 let draft = MailDraft(from: from, to: recipients, cc: copies.isEmpty ? nil : copies, subject: subject.trimmingCharacters(in: .whitespaces), text: text, replyToMessageID: replyTo)544 Task {545 defer { busy = false }546 do {547 try await session.call { try await $0.sendMail(draft) }548 nav.show("Message envoyé")549 sent()550 dismiss()551 } catch { failure = AdminError.message(error) }552 }553 }554}555