Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments not showing inline #17

Open
tjrexer opened this issue Oct 16, 2020 · 6 comments
Open

Attachments not showing inline #17

tjrexer opened this issue Oct 16, 2020 · 6 comments

Comments

@tjrexer
Copy link

tjrexer commented Oct 16, 2020

I've been trying to get the attachments to show inline, but they seem to all be added at the end. Is this a problem with .getAs? All of the images are rendered correctly, but the Blob class just seems to ignore all the cid references.

I haven't seen any traction on this repo in a while, so I don't expect an answer from pixelcog.

@steinkem
Copy link

steinkem commented Aug 20, 2021

I had the same issue, fixed by adding code below to the function embedInlineImages_. Add it right before the line return processImgAttachments(html);

html = html.replace(/(<img[^>]+src=)(["'])((?:(?!\2)[^\\]|\\.)*)\2/gi, function(m, tag, q, src) { var idx = images.findIndex(item => item.getName() === src.replace("cid:","")); return tag + q + (renderDataUri_(images[idx]) || images[idx]) + q; });

@bleu34
Copy link

bleu34 commented Sep 1, 2022

I had the same issue, fixed by adding code below to the function embedInlineImages_. Add it right before the line return processImgAttachments(html);

html = html.replace(/(<img[^>]+src=)(["'])((?:(?!\2)[^\\]|\\.)*)\2/gi, function(m, tag, q, src) { var idx = images.findIndex(item => item.getName() === src.replace("cid:","")); return tag + q + (renderDataUri_(images[idx]) || images[idx]) + q; });

Thanks a lot @steinkem, the trick is putting the images inline !
I have a bug with some mails which are not or partially putting the inline images. I was not able to determine what triggers this bug. Did you also experienced that ? and did you solved it ?

@bleu34
Copy link

bleu34 commented Sep 1, 2022

I made a test with 1 mail containing 2 images, I then replied with 1 image, replied with 1 image, replied with 1 image, replied with 1 image. And the bug is really ramdom :

Mail 1 Mail 2 Mail 3 Mail 4 Mail 5
Image 6 ------- ------- ------- ------- OK
Image 5 ------- ------- ------- Fail Fail
Image 4 ------- ------- OK Fail Fail
Image 3 ------- Fail OK OK OK
Image 2 Fail OK OK Fail OK
Image 1 OK Fail Fail OK OK

I launched several times the script for the same mail, it is each time the same Fail.

@bleu34
Copy link

bleu34 commented Sep 5, 2022

I now guess it is due to the Blob size limitation of 2Mo of the Replace function.

@AlexBeep
Copy link

AlexBeep commented Nov 9, 2022

You can see the problem when clicking on "original message" in gmail.
In the area containing img-cids there are newline or carrige return divided by "=".

If this breaks the tag (e.g.
<img=
src=3D"cid:ii_l9yhg5hk0"
) there will nothing be found.

I added this code in the beginning of function embedInlineImages_

let rawnew = raw.replace(/=[\n\r]/gi, '');
rawnew = rawnew.replace(/[\n\r]/gi, '');

and changed the line
raw.replace(/<img[^>]+src=(?:3D)?(["'])cid:((?:(?!\1)[^\\]|\\.)*)\1/gi, function(m, q, cid) {
to
rawnew.replace(/<img[^>]+src=(?:3D)?(["'])cid:((?:(?!\1)[^\\]|\\.)*)\1/gi, function(m, q, cid) {

This regex can probably be written in one line but my brain is not processing that :-)

@bleu34
Copy link

bleu34 commented Aug 29, 2023

@AlexBeep : Well spotted for the area divided by "=". Your Regex does the job.

I have another problem with images which are not inserted in the mail with img-cids, but which are hyperlinks like this :
</div><div><sp= an id=3D"gmail-docs-internal-guid-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"><im= g width=3D"960px;" height=3D"468px;" src=3D"https://lh4.googleusercontent.c= om/xxxxxxxyyyyyyyyyyyzzzzzzzzzzxxxxxxxxyyyyyyyyyyyyyyyzzzzzzzxxxxxxxyyyyyy= xxxxxxxyyyyyyyyyyyzzzzzzzzzzxxxxxxxxyyyyyyyyyyyyyyyzzzzzzzxxxxxxxyyyyyyxxxx= yyyyyzz=3Ds2048">
There is the same divider "=" but also the end is not needed '=3Ds2048' (and the = is not a divider).

Have you experienced the same and did somebody found the solution ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants