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

Replace image urls by cid urls when composing/sending a message #4988

Closed
rcubetrac opened this issue Jul 9, 2009 · 14 comments
Closed

Replace image urls by cid urls when composing/sending a message #4988

rcubetrac opened this issue Jul 9, 2009 · 14 comments

Comments

@rcubetrac
Copy link

Reported by rosali on 9 Jul 2009 12:28 UTC as Trac ticket #1485968

I'd like to see a feature to embed images as cid url attachments.

Something like here:

http://www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-in-HTML-Email-P113.html

Migrated-From: http://trac.roundcube.net/ticket/1485968

@rcubetrac
Copy link
Author

Comment by rosali on 10 Jul 2009 09:21 UTC

see:

http://www.roundcubeforum.net/release-discussion/4982-how-send-signatures-images-mail.html

@rcubetrac
Copy link
Author

Comment by @thomascube on 10 Jul 2009 11:23 UTC

It's possible to embed images with the HTML editor. Attached images should be selectable there. Or do you mean that RoundCube should fetch images linked by URL and embed them in the message?

@rcubetrac
Copy link
Author

Comment by rosali on 10 Jul 2009 12:16 UTC

Replying to thomasb:

It's possible to embed images with the HTML editor. Attached images should be selectable there. Or do you mean that RoundCube should fetch images linked by URL and embed them in the message?

Yes, that's what I mean.

@rcubetrac
Copy link
Author

Comment by @thomascube on 10 Jul 2009 13:44 UTC

Well, this may delay the sending for several seconds because fetching images via http could take its time...

@rcubetrac
Copy link
Author

Comment by rosali on 10 Jul 2009 14:54 UTC

Replying to rosali:

Replying to thomasb:

It's possible to embed images with the HTML editor. Attached images should be selectable there. Or do you mean that RoundCube should fetch images linked by URL and embed them in the message?

Yes, that's what I mean.

Optional? IMO this would be a great feature.

@rcubetrac
Copy link
Author

Comment by Gl0ubI on 10 Jul 2009 15:50 UTC

Maybe a suggestion : why don't activate image button on tool bar in the prfrence pane ?

[[Image(http://gl0ubi.free.fr/signature_html.png)]]

Images will be stored on server where RoundCube is installed, so no more problem to get it ? no ?

@rcubetrac
Copy link
Author

Comment by Cooldown on 11 Oct 2010 11:15 UTC

[ Placeholder for "How to implement a signature image via identity edit tab" ]

I'll complete the placeholder text for this later .. i lost the whole text after clicking on "attach file" :/

Regards, Cooldown

@rcubetrac
Copy link
Author

Comment by Cooldown on 11 Oct 2010 12:03 UTC

How to: "Replace image urls by cid urls when composing/sending a message"

  1. Download the TinyMCE iBrowser plugin from
    [Extract to roundcube/program/js/tiny_mce/plugins/ibrowser

  2. Open roundcube/program/js/tiny_mce/plugins/ibrowser/config.inc.php and modify as needed (see ibrowser_config.inc.txt for details)

  3. Copy attached get_signature_img.php to roundcube/ dir

  4. Modify get_signature_img.php as needed (see attached file for details)

  5. Open file roundcube/program/js/tiny_mce/plugins/ibrowser/ibrowser.php

  • locate IF-Code Block with comment
// check if valid image is selected
  • locate
if ('<?php echo $cfg['furl'](http://www.net4visions.com/ibrowser.html]

2)); ?>' == true) {
  • inside this block replace
args.src = '<?php echo $cfg[?>' + args.src;

with

args.src = '<?php echo $cfg['base_url']('base_url'];).'/'.$cfg[?>' + args.src;

  1. Open file roundcube/program/js/tiny_mce/plugins/ibrowser/scripts/phpThumb/phpThumb.config.php
  • Comment out existing PHPTHUMB_CONFIG vars 'document_root', 'cache_directory'
  • replace or add
$PHPTHUMB_CONFIG['document_root']('image_dir'].'/get_signature_img.php?i=';) = $cfg[= $cfg['cache_dir']('root_dir'];
$PHPTHUMB_CONFIG['cache_directory']);
  1. Open file roundcube/program/js/editor.js
  • Add
plugins: 'ibrowser',

after

theme_advanced_buttons3 : '',
  • Add to one of the theme_advanced_button bars "ibrowser"

And you are done.

Additional Notes

  • get_signature_img.php reads an image via readfile_chunked() function. If an E-Mail is send, the image is added as cid so that MS-Outlook will show the image correctly (as it doesn't if you try to embed an image via base64).
  • E-Mail-Composing must be set to HTML in Settings Tab in order to work properly
  • ibrowser config.inc.php
    • you have to play around with root_dir, base_url, main_dir, image_dir, user_dir
    • . image_dir: relative path to get_signature_img (img src tag after clicking "insert")
    • . user_dir: signature images per user
    • . ilibs: defined Libraries (Select Box)

Note: Sometimes the select box of ibrowser will not show uploaded images on startup (first click on "insert button"). I suppose this is currently a bug, cause the select box will only refresh the underlying file box onChange. Maybe this could be fixed later.

If you have another way to implement this, feel free to shout it out loud ^^

Maybe this could be implemented as a Plugin later? If yes, then the user_id should be changeable via a hook/or config, so that users will not be restricted to roundcube user_ids.

Regards, Cooldown

PS: Sorry for the double post. But i didn't know that attaching a file will kill my current post.

@rcubetrac
Copy link
Author

Comment by Silencer on 1 Feb 2011 17:15 UTC

People are still requesting this (in the above mentioned forum thread). In the meantime, the user langejan advised to "put the image for your signature(s) in the tinymce's emoticons folder. Roundcube will automatically turn this into cid: attachments. This way you don't have to edit files.".

@rcubetrac
Copy link
Author

Comment by rosali on 2 Feb 2011 06:05 UTC

I think this feature could be implemented by using the function 'rcmail_fix_emoticon_paths'.

@rcubetrac
Copy link
Author

Comment by cebe on 8 Feb 2012 10:18 UTC

Why this very classic feature is set to "later" ? If needed, just limit image size to 10 or 20 ko.

@rcubetrac
Copy link
Author

Comment by oliverfoster on 24 Aug 2012 22:42 UTC

Replying to rosali:

I'd like to see a feature to embed images as cid url attachments.

Something like here:

http://www.phpeveryday.com/articles/PHP-Email-Using-Embedded-Images-in-HTML-Email-P113.html

I have a solution to images which are directly copied and pasted into the editor (i.e. screen-print and paste, or copy image from one browser window onto a composing email). It is messy but it makes a point that this feature is possible and simple.
It takes the src="data:image/png;base64,..." encoded image tag data and adds them on as message parts, changing the tags data to a src="cid:.." reference before sending them to the SMTP server. This means that images pasted directly into the edit control appear in Outlook and other message clients in the right format.
The code has been improved to work with other attachments and no attachments by either appending to the existing 'multipart/alternative" section or creating a new one.

This code should be added to the top of the send_mail function in program/include/rcube_smtp.php:

function images_hack(&$body,&$headers) {

    if (strpos($body,"data:image/png;base64") == false) {
        return;
    }


    $oldtagtype = substr($body,0 ,strpos($body,"\r\n", strpos($body,"\r\n") + 2));
    $oldtag = substr($body,2,strpos($body,"\r\n")-2);
    $oldtagn = substr($oldtag,2,strlen($oldtag)-2);

    $redone = "";
    $attachzone = false;
    if (strpos($oldtagtype,'Content-Type: multipart/alternative;') != false) {
        $attachzone = true;
        $removeupto = strpos($body,"--".$oldtag."\r\n", strlen("--".$oldtag."\r\n"));
        $redone = str_replace("=\r\n","",substr($body,0,$removeupto - 1)).substr($body,$removeupto,strlen($body));
        $lpos = strrpos($redone,"--".$oldtag."--");
        $redone = substr($redone,0, $lpos-1)."\r\n";

    } else {
        $removeupto = strpos($body,"--".$oldtag."--\r\n", strlen("--".$oldtag."\r\n"));
        $redone = str_replace("=\r\n","",substr($body,0,$removeupto - 1)).substr($body,$removeupto,strlen($body));
    }

    preg_match_all('/<img[$result);
    $img = array();
    $i = 0;
    foreach( $result[0](^>]+>/i',$redone,) as $img_tag)
    {
        preg_match_all('/(src)=3D"([$img[$i](^"]*)"/i',$img_tag,));
        $i++;
    }


    $top = "";
    $bottom = "";
    $added = false;
    $imgid = 0;
    for ($l = 0; $l < count ($img); $l++){
        for ($i = 0; $i < count($img[$i++) {;
            if (substr($img[$l]($l][1]);)[== "data:image/png;base64") {
                if (!$added && !$attachzone) {
                    $top = "--".$oldtag."new"."\r\n";
                    $top.='Content-Type: multipart/alternative; boundary="'.$oldtag.'"'."\r\n";
                    $top.="\r\n";
                }

                $place = strpos($redone,$img[$l](2][$i],0,strpos($img[$l][2][$i],",")))[= substr($redone,0,$place).'cid:image00'.$imgid.'.png@'.$oldtagn.substr($redone,$place+strlen($img[$l](2][$i]);
                $redone)[(!$attachzone) {
                    $bottom.="--".$oldtag."new"."\r\n";
                } else {
                    $bottom.="--".$oldtag."\r\n";
                }
                $bottom.='Content-Type: image/png; name="image00'.$imgid.'.png"'."\r\n";
                $bottom.='Content-Transfer-Encoding: base64'."\r\n";
                $bottom.='Content-ID: <image00'.$imgid.'.png@'.$oldtagn.'>'."\r\n";
                $bottom.="\r\n";
                $dta = substr($img[$l](2][$i]),strlen($redone)-1);

                if)[2][$i],strpos($img[$l][2][$i],",")+1,strlen($img[$l][2][$i])-strpos($img[$l][2][$i],",")-1);
                $dta = str_split($dta,75);
                $dta = join("\r\n",$dta);
                $bottom.=$dta."\r\n";
                $bottom.="\r\n";
                $imgid++;
                $added = true;
            }
        }
    }
    if ($added) {
        $place = strpos($headers,$oldtag);
        if (!$attachzone) {
            $bottom.="--".$oldtag."new"."--\r\n";
            $headers = substr($headers,0,$place).$oldtag."new".substr($headers,$place+strlen($oldtag),strlen($headers)-1);
        } else {
            $bottom.="--".$oldtag."--\r\n";
        }
        $headers = str_replace("Content-Type: multipart/alternative;","Content-Type: multipart/related;",$headers);
        $headers = str_replace("Content-Type: multipart/mixed;","Content-Type: multipart/related;",$headers);
    }
    $cmp=$top.$redone."\r\n".$bottom;
    $body = $cmp;

}
images_hack($body,$headers);

@rcubetrac
Copy link
Author

Comment by @alecpl on 11 Dec 2012 19:11 UTC

Actually data URIs are replaced with CID-images in git-master version, however two requests are still valid:

  1. convert external image URLs into cid-attachments
  2. better support for images in signatures (currently only drag&drop in supported browser is possible).

@alecpl
Copy link
Member

alecpl commented Apr 23, 2017

So, at the moment it looks that the last thing is attaching external images. I'm not a big fan of this feature. It is possible to write a plugin. Closing.

@alecpl alecpl closed this as completed Apr 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants