Courrier v1.5 (tt-2026-11-068) : telechargement securise des pieces jointes depuis le panneau de lecture
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGaEeWkqZYNP6Wn3mGQsrL
This commit is contained in:
1 parent
a9fbd45081
commit
ce10cae840
7 files changed
+176
-10
No files matched your search
+41
-6
@@ -14,7 +14,7 @@
|
||||
suivi: 'M12 6v6l4 2|M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0',
|
||||
pj: 'm21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48',
|
||||
groupes: 'M3 7h7v7H3z|M14 7h7v7h-7z|M3 17h18',
|
||||
fermer: 'M18 6 6 18|m6 6 12 12', gauche: 'm15 18-6-6 6-6', droite: 'm9 18 6-6-6-6', bas: 'm6 9 6 6 6-6', fleche: 'M5 12h14|m12 5 7 7-7 7'
|
||||
telecharger: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4|m7 10 5 5 5-5|M12 15V3', fermer: 'M18 6 6 18|m6 6 12 12', gauche: 'm15 18-6-6 6-6', droite: 'm9 18 6-6-6-6', bas: 'm6 9 6 6 6-6', fleche: 'M5 12h14|m12 5 7 7-7 7'
|
||||
};
|
||||
var NAV = [
|
||||
['tri', 'Tri du jour', true], ['categories', 'Catégories', true], ['groupes', 'Groupes', true], ['regles', 'Règles', true],
|
||||
@@ -378,6 +378,28 @@
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(iso)) return String(v || '');
|
||||
return nomJour(iso).toLowerCase() + ' ' + fr(iso) + ' à ' + heureTunis(v);
|
||||
}
|
||||
function estSignature(p) {
|
||||
return /^image\//.test(p.type || '') && Number(p.taille) < 20480 && !p.bloquee;
|
||||
}
|
||||
function telechargerPiece(id, p, bt) {
|
||||
bt.disabled = true; annoncer('Téléchargement de ' + p.nom + ' en cours');
|
||||
fetch(API + '/mail/piece?id=' + encodeURIComponent(id) + '&nom=' + encodeURIComponent(p.nom), { credentials: 'same-origin', redirect: 'manual' })
|
||||
.then(function (rep) {
|
||||
if (rep.type === 'opaqueredirect') { sessionExpiree(); throw new Error('session'); }
|
||||
if (rep.status === 403) throw new Error('Ce type de fichier est bloqué par sécurité.');
|
||||
if (rep.status === 413) throw new Error('Pièce jointe trop volumineuse (25 Mo maximum).');
|
||||
if (!rep.ok) throw new Error('Pièce jointe indisponible pour le moment.');
|
||||
return rep.blob();
|
||||
})
|
||||
.then(function (blob) {
|
||||
var url = URL.createObjectURL(blob), a = document.createElement('a');
|
||||
a.href = url; a.download = p.nom; document.body.appendChild(a); a.click(); a.remove();
|
||||
setTimeout(function () { URL.revokeObjectURL(url); }, 4000);
|
||||
annoncer(p.nom + ' téléchargé');
|
||||
})
|
||||
.catch(function (e) { if (e.message !== 'session') annoncer(e.message); })
|
||||
.then(function () { bt.disabled = false; });
|
||||
}
|
||||
function afficherMail(cont, m, r, c) {
|
||||
var badges = h('div', { class: 'lect-badges' }, h('span', { class: 'lect-cat' }, pastille(couleur(m.cat, c && c.id)), m.cat));
|
||||
(m.etiquettes || []).forEach(function (t) { badges.appendChild(h('span', { class: 'etq', text: t })); });
|
||||
@@ -398,14 +420,27 @@
|
||||
}
|
||||
if (r.tronque) cont.appendChild(h('p', { class: 'lect-note', text: 'Le texte est très long : seul le début est affiché.' }));
|
||||
var pj = r.pieces_jointes || [];
|
||||
if (pj.length) {
|
||||
var signature = pj.filter(estSignature), utiles = pj.filter(function (p) { return !estSignature(p); });
|
||||
function extDe(p) { var e = String(p.nom || '').indexOf('.') > -1 ? String(p.nom).split('.').pop().toUpperCase() : ''; return e && e.length <= 5 ? e + ' · ' : ''; }
|
||||
if (utiles.length) {
|
||||
var ul = h('ul');
|
||||
pj.forEach(function (p) {
|
||||
var ext = String(p.nom || '').indexOf('.') > -1 ? String(p.nom).split('.').pop().toUpperCase() : '';
|
||||
utiles.forEach(function (p) {
|
||||
var action;
|
||||
if (p.bloquee) action = h('span', { class: 'info bloquee', text: 'Bloquée par sécurité' });
|
||||
else {
|
||||
var bt = h('button', { type: 'button', class: 'btn-icone', 'aria-label': 'Télécharger ' + p.nom, title: 'Télécharger' }, icone('telecharger'));
|
||||
bt.addEventListener('click', function () { telechargerPiece(r.message_id || m.id, p, bt); });
|
||||
action = bt;
|
||||
}
|
||||
ul.appendChild(h('li', null, icone('pj', 18), h('span', { class: 'nom coupe', title: p.nom, text: p.nom }),
|
||||
h('span', { class: 'info', text: (ext && ext.length <= 5 ? ext + ' · ' : '') + tailleLisible(p.taille) })));
|
||||
h('span', { class: 'info', text: extDe(p) + tailleLisible(p.taille) }), action));
|
||||
});
|
||||
cont.appendChild(h('section', { class: 'lect-pj', 'aria-labelledby': 'lect-pj-t' }, h('h3', { id: 'lect-pj-t', text: 'Pièces jointes (' + pj.length + ')' }), ul));
|
||||
cont.appendChild(h('section', { class: 'lect-pj', 'aria-labelledby': 'lect-pj-t' }, h('h3', { id: 'lect-pj-t', text: 'Pièces jointes (' + utiles.length + ')' }), ul));
|
||||
}
|
||||
if (signature.length) {
|
||||
var us = h('ul');
|
||||
signature.forEach(function (p) { us.appendChild(h('li', null, icone('pj', 18), h('span', { class: 'nom coupe', title: p.nom, text: p.nom }), h('span', { class: 'info', text: tailleLisible(p.taille) }))); });
|
||||
cont.appendChild(h('details', { class: 'lect-histo lect-sig' }, h('summary', null, 'Images intégrées au message (' + signature.length + ')'), us));
|
||||
}
|
||||
cont.appendChild(h('p', { class: 'lect-note', text: 'Lecture seule : le mail n\'est pas modifié dans votre messagerie.' }));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user