You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a plugin which get all images using data url (<img="data:..." />) into attachments because gmail does not read image in data url format.
As the signature settings don't allow to attach files to the message in order to render them without the use of an external url, the goal is to create signature with image as data url and then intercept the message before it's being sent to convert these image to images like <img src="cid:${attachment.cid}"> to allow all email clients to read them properly. The same way Evolution currently does on linux.
I've been able to create the plugin but I am stuck in the process of attaching the file. I did not find in the documentation how we are supposed to create an attachment to the mail in the applyTransformsForSendng method.
import{ComposerExtension,File}from'mailspring-exports';exportdefaultclassReplaceBase64ExtensionextendsComposerExtension{staticapplyTransformsForSending({ draftBodyRootNode, draft, recipient }){// code pour intercepté le mail, regarder toutes les images qui utilisent une url en base64 // et remplacer par des fichiers en pièce jointe// ...console.log("[BASE64]","will intercept message",{ draftBodyRootNode, draft, recipient })letbody=draftBodyRootNode.innerHTML;letmatches=body.match(/<img[^>]*src="data:image\/(.*);base64,([^"]*)"[^>]*>/g);if(!matches){return;}matches.forEach(match=>{letdata=match.match(/src="data:image\/(.*);base64,([^"]*)"/);console.log("Attachments to add...",data);lettype=data[1];letbase64=data[2];/****** Part which is not working let attachment = File.fromBase64(base64, `image.${type}`); draft.attachments.push(attachment); *******/body=body.replace(match,`<img src="cid:${attachment.cid}">`);});draftBodyRootNode.innerHTML=body;console.log("Replaced body",body);}}
Is there any solution for a plugin to dynamically create an attachment?
The text was updated successfully, but these errors were encountered:
I'm trying to create a plugin which get all images using data url (<img="data:..." />) into attachments because gmail does not read image in data url format.
As the signature settings don't allow to attach files to the message in order to render them without the use of an external url, the goal is to create signature with image as data url and then intercept the message before it's being sent to convert these image to images like
<img src="cid:${attachment.cid}">
to allow all email clients to read them properly. The same way Evolution currently does on linux.I've been able to create the plugin but I am stuck in the process of attaching the file. I did not find in the documentation how we are supposed to create an attachment to the mail in the applyTransformsForSendng method.
Is there any solution for a plugin to dynamically create an attachment?
The text was updated successfully, but these errors were encountered: