Include base64 photos in email body

- Photos are now included in a separate 'FOTO BIJLAGEN' section
- Each photo shows filename with extension (e.g., Foto_van_het_apparaat.jpeg)
- Base64 data wrapped with START/EINDE markers for easy extraction
- Added warning if email exceeds 100KB (mailto limit)
- Instructions included for decoding base64 images
main
killercow 2 weeks ago
parent 46fca0ccdf
commit 20e0720ffe

@ -1016,18 +1016,52 @@ input.invalid, select.invalid, textarea.invalid {
body += 'Versie: ' + CONFIG.version + '\n'; body += 'Versie: ' + CONFIG.version + '\n';
body += 'Datum: ' + formatDateTime(new Date()) + '\n\n'; body += 'Datum: ' + formatDateTime(new Date()) + '\n\n';
// Collect photos separately
const photos = [];
Object.entries(data).forEach(([key, value]) => { Object.entries(data).forEach(([key, value]) => {
if (value && value !== '' && !key.includes('foto') && !key.includes('photo')) { if (value && value !== '') {
// Check if this is a photo (base64 image)
if (typeof value === 'string' && value.startsWith('data:image/')) {
const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key;
// Extract extension from data URL (e.g., data:image/jpeg;base64,...)
const mimeMatch = value.match(/data:image\/([a-z]+);/);
const ext = mimeMatch ? mimeMatch[1] : 'jpg';
photos.push({
name: labelText,
extension: ext,
data: value
});
} else {
const label = document.querySelector(`label[for="${key}"]`); const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key; const labelText = label ? label.textContent.replace('*', '').trim() : key;
const displayValue = Array.isArray(value) ? value.join(', ') : value; const displayValue = Array.isArray(value) ? value.join(', ') : value;
body += labelText + ': ' + displayValue + '\n'; body += labelText + ': ' + displayValue + '\n';
} }
}
}); });
body += '\n========================\n'; body += '\n========================\n';
body += 'Let op: Foto\'s kunnen niet via mailto worden verzonden.\n';
body += 'Gebruik CSV export voor complete data inclusief foto\'s.'; // Add photos section if there are any
if (photos.length > 0) {
body += '\nFOTO BIJLAGEN (BASE64)\n';
body += '========================\n';
body += 'Onderstaande foto\'s zijn gecodeerd in base64 formaat.\n';
body += 'Kopieer de tekst tussen START en EINDE naar een base64 decoder\n';
body += 'of gebruik een online tool zoals base64-image.de\n\n';
photos.forEach((photo, index) => {
const filename = photo.name.replace(/[^a-zA-Z0-9]/g, '_') + '.' + photo.extension;
body += '--- FOTO ' + (index + 1) + ': ' + filename + ' ---\n';
body += '>>> START BASE64 >>>\n';
body += photo.data + '\n';
body += '<<< EINDE BASE64 <<<\n\n';
});
} else {
body += 'Geen foto\'s toegevoegd aan dit formulier.\n';
}
const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) + const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) +
'?subject=' + encodeURIComponent(subject) + '?subject=' + encodeURIComponent(subject) +
@ -1039,6 +1073,12 @@ input.invalid, select.invalid, textarea.invalid {
button.disabled = false; button.disabled = false;
} }
// Check if mailto URL is too long (most clients support ~2000 chars)
if (mailto.length > 100000) {
showToast('Email te groot door foto. Gebruik CSV export.', 'error');
return;
}
window.location.href = mailto; window.location.href = mailto;
}, 50); }, 50);
}; };

@ -1047,18 +1047,52 @@ select {
body += 'Versie: ' + CONFIG.version + '\n'; body += 'Versie: ' + CONFIG.version + '\n';
body += 'Datum: ' + formatDateTime(new Date()) + '\n\n'; body += 'Datum: ' + formatDateTime(new Date()) + '\n\n';
// Collect photos separately
const photos = [];
Object.entries(data).forEach(([key, value]) => { Object.entries(data).forEach(([key, value]) => {
if (value && value !== '' && !key.includes('foto') && !key.includes('photo')) { if (value && value !== '') {
// Check if this is a photo (base64 image)
if (typeof value === 'string' && value.startsWith('data:image/')) {
const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key;
// Extract extension from data URL (e.g., data:image/jpeg;base64,...)
const mimeMatch = value.match(/data:image\/([a-z]+);/);
const ext = mimeMatch ? mimeMatch[1] : 'jpg';
photos.push({
name: labelText,
extension: ext,
data: value
});
} else {
const label = document.querySelector(`label[for="${key}"]`); const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key; const labelText = label ? label.textContent.replace('*', '').trim() : key;
const displayValue = Array.isArray(value) ? value.join(', ') : value; const displayValue = Array.isArray(value) ? value.join(', ') : value;
body += labelText + ': ' + displayValue + '\n'; body += labelText + ': ' + displayValue + '\n';
} }
}
}); });
body += '\n========================\n'; body += '\n========================\n';
body += 'Let op: Foto\'s kunnen niet via mailto worden verzonden.\n';
body += 'Gebruik CSV export voor complete data inclusief foto\'s.'; // Add photos section if there are any
if (photos.length > 0) {
body += '\nFOTO BIJLAGEN (BASE64)\n';
body += '========================\n';
body += 'Onderstaande foto\'s zijn gecodeerd in base64 formaat.\n';
body += 'Kopieer de tekst tussen START en EINDE naar een base64 decoder\n';
body += 'of gebruik een online tool zoals base64-image.de\n\n';
photos.forEach((photo, index) => {
const filename = photo.name.replace(/[^a-zA-Z0-9]/g, '_') + '.' + photo.extension;
body += '--- FOTO ' + (index + 1) + ': ' + filename + ' ---\n';
body += '>>> START BASE64 >>>\n';
body += photo.data + '\n';
body += '<<< EINDE BASE64 <<<\n\n';
});
} else {
body += 'Geen foto\'s toegevoegd aan dit formulier.\n';
}
const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) + const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) +
'?subject=' + encodeURIComponent(subject) + '?subject=' + encodeURIComponent(subject) +
@ -1070,6 +1104,12 @@ select {
button.disabled = false; button.disabled = false;
} }
// Check if mailto URL is too long (most clients support ~2000 chars)
if (mailto.length > 100000) {
showToast('Email te groot door foto. Gebruik CSV export.', 'error');
return;
}
window.location.href = mailto; window.location.href = mailto;
}, 50); }, 50);
}; };

@ -1078,18 +1078,52 @@ input.invalid, select.invalid, textarea.invalid {
body += 'Versie: ' + CONFIG.version + '\n'; body += 'Versie: ' + CONFIG.version + '\n';
body += 'Datum: ' + formatDateTime(new Date()) + '\n\n'; body += 'Datum: ' + formatDateTime(new Date()) + '\n\n';
// Collect photos separately
const photos = [];
Object.entries(data).forEach(([key, value]) => { Object.entries(data).forEach(([key, value]) => {
if (value && value !== '' && !key.includes('foto') && !key.includes('photo')) { if (value && value !== '') {
// Check if this is a photo (base64 image)
if (typeof value === 'string' && value.startsWith('data:image/')) {
const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key;
// Extract extension from data URL (e.g., data:image/jpeg;base64,...)
const mimeMatch = value.match(/data:image\/([a-z]+);/);
const ext = mimeMatch ? mimeMatch[1] : 'jpg';
photos.push({
name: labelText,
extension: ext,
data: value
});
} else {
const label = document.querySelector(`label[for="${key}"]`); const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key; const labelText = label ? label.textContent.replace('*', '').trim() : key;
const displayValue = Array.isArray(value) ? value.join(', ') : value; const displayValue = Array.isArray(value) ? value.join(', ') : value;
body += labelText + ': ' + displayValue + '\n'; body += labelText + ': ' + displayValue + '\n';
} }
}
}); });
body += '\n========================\n'; body += '\n========================\n';
body += 'Let op: Foto\'s kunnen niet via mailto worden verzonden.\n';
body += 'Gebruik CSV export voor complete data inclusief foto\'s.'; // Add photos section if there are any
if (photos.length > 0) {
body += '\nFOTO BIJLAGEN (BASE64)\n';
body += '========================\n';
body += 'Onderstaande foto\'s zijn gecodeerd in base64 formaat.\n';
body += 'Kopieer de tekst tussen START en EINDE naar een base64 decoder\n';
body += 'of gebruik een online tool zoals base64-image.de\n\n';
photos.forEach((photo, index) => {
const filename = photo.name.replace(/[^a-zA-Z0-9]/g, '_') + '.' + photo.extension;
body += '--- FOTO ' + (index + 1) + ': ' + filename + ' ---\n';
body += '>>> START BASE64 >>>\n';
body += photo.data + '\n';
body += '<<< EINDE BASE64 <<<\n\n';
});
} else {
body += 'Geen foto\'s toegevoegd aan dit formulier.\n';
}
const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) + const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) +
'?subject=' + encodeURIComponent(subject) + '?subject=' + encodeURIComponent(subject) +
@ -1101,6 +1135,12 @@ input.invalid, select.invalid, textarea.invalid {
button.disabled = false; button.disabled = false;
} }
// Check if mailto URL is too long (most clients support ~2000 chars)
if (mailto.length > 100000) {
showToast('Email te groot door foto. Gebruik CSV export.', 'error');
return;
}
window.location.href = mailto; window.location.href = mailto;
}, 50); }, 50);
}; };

@ -1327,18 +1327,52 @@ JAVASCRIPT = """
body += 'Versie: ' + CONFIG.version + '\\n'; body += 'Versie: ' + CONFIG.version + '\\n';
body += 'Datum: ' + formatDateTime(new Date()) + '\\n\\n'; body += 'Datum: ' + formatDateTime(new Date()) + '\\n\\n';
// Collect photos separately
const photos = [];
Object.entries(data).forEach(([key, value]) => { Object.entries(data).forEach(([key, value]) => {
if (value && value !== '' && !key.includes('foto') && !key.includes('photo')) { if (value && value !== '') {
// Check if this is a photo (base64 image)
if (typeof value === 'string' && value.startsWith('data:image/')) {
const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key;
// Extract extension from data URL (e.g., data:image/jpeg;base64,...)
const mimeMatch = value.match(/data:image\\/([a-z]+);/);
const ext = mimeMatch ? mimeMatch[1] : 'jpg';
photos.push({
name: labelText,
extension: ext,
data: value
});
} else {
const label = document.querySelector(`label[for="${key}"]`); const label = document.querySelector(`label[for="${key}"]`);
const labelText = label ? label.textContent.replace('*', '').trim() : key; const labelText = label ? label.textContent.replace('*', '').trim() : key;
const displayValue = Array.isArray(value) ? value.join(', ') : value; const displayValue = Array.isArray(value) ? value.join(', ') : value;
body += labelText + ': ' + displayValue + '\\n'; body += labelText + ': ' + displayValue + '\\n';
} }
}
}); });
body += '\\n========================\\n'; body += '\\n========================\\n';
body += 'Let op: Foto\\'s kunnen niet via mailto worden verzonden.\\n';
body += 'Gebruik CSV export voor complete data inclusief foto\\'s.'; // Add photos section if there are any
if (photos.length > 0) {
body += '\\nFOTO BIJLAGEN (BASE64)\\n';
body += '========================\\n';
body += 'Onderstaande foto\\'s zijn gecodeerd in base64 formaat.\\n';
body += 'Kopieer de tekst tussen START en EINDE naar een base64 decoder\\n';
body += 'of gebruik een online tool zoals base64-image.de\\n\\n';
photos.forEach((photo, index) => {
const filename = photo.name.replace(/[^a-zA-Z0-9]/g, '_') + '.' + photo.extension;
body += '--- FOTO ' + (index + 1) + ': ' + filename + ' ---\\n';
body += '>>> START BASE64 >>>\\n';
body += photo.data + '\\n';
body += '<<< EINDE BASE64 <<<\\n\\n';
});
} else {
body += 'Geen foto\\'s toegevoegd aan dit formulier.\\n';
}
const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) + const mailto = 'mailto:' + encodeURIComponent(CONFIG.export.mailto.to) +
'?subject=' + encodeURIComponent(subject) + '?subject=' + encodeURIComponent(subject) +
@ -1350,6 +1384,12 @@ JAVASCRIPT = """
button.disabled = false; button.disabled = false;
} }
// Check if mailto URL is too long (most clients support ~2000 chars)
if (mailto.length > 100000) {
showToast('Email te groot door foto. Gebruik CSV export.', 'error');
return;
}
window.location.href = mailto; window.location.href = mailto;
}, 50); }, 50);
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.