From 3330db62f6dbf8394d6c61cf0e7b0296f12cbbe5 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 11 May 2009 23:32:58 +0000 Subject: [PATCH] =?UTF-8?q?Add:=20possibilit=E9=20d'envoyer=20un=20fichier?= =?UTF-8?q?=20attach=E9=20avec=20du=20html=20contenant=20des=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev/mail/dolibarr_mail_attachement.txt | 1 + ...dolibarr_mail_attachementwithimageHTML.txt | 68 +++++++++++++++ dev/mail/dolibarr_mail_withimageHTML.txt | 36 ++++++++ htdocs/compta/facture.php | 2 +- htdocs/lib/CMailFile.class.php | 83 +++++++++++++------ 5 files changed, 163 insertions(+), 27 deletions(-) create mode 100644 dev/mail/dolibarr_mail_attachementwithimageHTML.txt create mode 100644 dev/mail/dolibarr_mail_withimageHTML.txt diff --git a/dev/mail/dolibarr_mail_attachement.txt b/dev/mail/dolibarr_mail_attachement.txt index 635f74ad7b4..67d8aacb54a 100644 --- a/dev/mail/dolibarr_mail_attachement.txt +++ b/dev/mail/dolibarr_mail_attachement.txt @@ -10,6 +10,7 @@ Content-Type: text/plain; charset=UTF-8 Testé --8f5b32f1596aaf192b28988da8f0c4e9 +--8f5b32f1596aaf192b28988da8f0c4e9 Content-Type: image/jpeg; name="images.jpg" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="images.jpg" diff --git a/dev/mail/dolibarr_mail_attachementwithimageHTML.txt b/dev/mail/dolibarr_mail_attachementwithimageHTML.txt new file mode 100644 index 00000000000..204801b683c --- /dev/null +++ b/dev/mail/dolibarr_mail_attachementwithimageHTML.txt @@ -0,0 +1,68 @@ +From: dolibarr-robot@domain.com +Return-Path: dolibarr-robot@domain.com +X-Mailer: Dolibarr version 2.7.0-beta (using php mail) +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Content-Type: multipart/mixed; boundary="468358388441498ebb24096bfda88a45" +X-attachments: document.pdf + +--468358388441498ebb24096bfda88a45 +Content-Type: multipart/related; boundary="de50511a21aa12aa7e67f9606279f097" + +--de50511a21aa12aa7e67f9606279f097 +Content-Type: text/html; charset=UTF-8 + + +--de50511a21aa12aa7e67f9606279f097 +--de50511a21aa12aa7e67f9606279f097 +Content-Type: image/jpeg; name="image.jpg" +Content-Transfer-Encoding: base64 +Content-Disposition: inline; filename="2pac.jpg" +Content-ID: <1c184fb7828cd6c1cdb1606d3946f6a4> + +/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYI +DAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkF +BQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU +FBQUFBT/wAARCAAQABADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQF +BgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEI +I0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNk +ZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLD +xMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEB +AQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJB +UQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZH +SElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaan +qKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oA +DAMBAAIRAxEAPwD6I/bC/bMXwjqQ+G/gK+ZvFN3KtrfapaDzDp+4hSkYB+aXn1G31B5X +zD4UftWfEX4cfEnw14COtj4sadqTwQzjUnUX+lNJOIT5t1E8qtglWO5nOGC5U8V2PxJ/ +YyTQzNcJoFxeoklw0HirwX+61iFJS5YXNmxKXQAkKl4yJCOAoo/ZX/ZRtXWO4KXtt4Ot +LpZpL26t3s73xFcRPlCY2w8FpGy5CHDSMOflyXwlCrKvGop2ppaxsvefdvdJdEt+vn5X +s68q3M3pf7l2ts79/uP/2Q== + +--de50511a21aa12aa7e67f9606279f097-- + +--468358388441498ebb24096bfda88a45 +Content-Type: application/pdf; name="document.pdf" +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; filename="document.pdf" + +JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291 +cmNlcyAyIDAgUgovQW5ub3RzIFs8PC9UeXBlIC9Bbm5vdCAvU3VidHlwZSAvTGluayAv +UmVjdCBbNDMuODUgNTEzLjMyIDEwMy44OCA1MDcuMzJdIC9Cb3JkZXIgWzAgMCAwXSAv +QSA8PC9TIC9VUkkgL1VSSSAoAlME1QKhXCnBPIbOysN1wUeE1fgiub0xNE5oyCk+Pj4+ +XQovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRl +RGVjb2RlIC9MZW5ndGggMjEwMT4+CnN0cmVhbQpnqpCIFi9ogze2ZuZz3Qgr2FNprO9n +s/t+zbdkUE2dQIKoKYMEJGIKBZRSUxy+zNT67GRPHIAN9ZHzEmj8jr8XmlgfXOfXf1iw +rutK6rbXCKUjXsYd/75vfkcqbN5xeHIrKw/EvrYEORNVDafZgvrjA70y9UPQk/hOF5Z8 +b0j9uE5W70mcGP7LPxfKGxiGJ9u+8LQrzb6zWm6/KOC8z5HvwPXUnuIeG2d9uDTxk/Qe +AF73RXDaUb/d7jUf9KV4t4cGArBO70WLuz6xRafwmQR6/6C39eKWOjMIahwzHaazD3Oi +nPsS/3meLTPrlEfpEexNafMS1M1X29i525l7YmpmcyaJWYoklZa4SU/fCm9KPMDJwTUa +eV9tUaaN1DScWCSP6o4fFE4Bn8sjm+0w6THbim8Xe5IA/zvDjtGZNtp4tZuujbJ22igr +crWyPFBx8M9Nb+H59ifgQqX5FRv8Q3wbTNy0sWrrZi0/FNtj2OkK+KxC9he/+lsaDiKw +dF+R08L6Qj5kJgUS9GvAPs9DJ+LmOW70nUflzISNFlQJkDLEkd6YB3m97tAji9SzbqZt +o9CFUO94RUiiEpmahN6IfgQXpQJUft9yuDseAluyCkKif5QkQA3IvwVYD2mv0R1uc9gY ++NSryk3w2w6tdSCslrFzinE1v9fVKLFOgz9oGaxibOBKO8DoZhd65/7Jf5btwzwU/Nhg +8ikI7MTz88vKOicfH3lkGtzoz1wm465e6uMZQG2mwETM/QmppfyqTDO4Ok6nbx5X8Mhi +fZt0uru+Tc93cnQQ82A5KVrVVvvahsyxtQFRMOgFLl8ct3wu6NVPyQPby9YUk2J4dpQr +R5X+bCaMew5mDNsdjMV95GesdhT3n3y32Az+XZsuecMoxePVX5S+GRSu/9XVL9Z+w7Ki + +--468358388441498ebb24096bfda88a45-- \ No newline at end of file diff --git a/dev/mail/dolibarr_mail_withimageHTML.txt b/dev/mail/dolibarr_mail_withimageHTML.txt new file mode 100644 index 00000000000..af8f0acf220 --- /dev/null +++ b/dev/mail/dolibarr_mail_withimageHTML.txt @@ -0,0 +1,36 @@ +From: dolibarr-robot@domain.com +Return-Path: dolibarr-robot@domain.com +X-Mailer: Dolibarr version 2.7.0-beta (using php mail) +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Content-Type: multipart/related; boundary="de50511a21aa12aa7e67f9606279f097" +--de50511a21aa12aa7e67f9606279f097 +Content-Type: text/html; charset=UTF-8 + + +--de50511a21aa12aa7e67f9606279f097 +--de50511a21aa12aa7e67f9606279f097 +Content-Type: image/jpeg; name="image.jpg" +Content-Transfer-Encoding: base64 +Content-Disposition: inline; filename="2pac.jpg" +Content-ID: <1c184fb7828cd6c1cdb1606d3946f6a4> + +/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYI +DAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkF +BQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU +FBQUFBT/wAARCAAQABADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQF +BgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEI +I0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNk +ZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLD +xMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEB +AQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJB +UQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZH +SElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaan +qKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oA +DAMBAAIRAxEAPwD6I/bC/bMXwjqQ+G/gK+ZvFN3KtrfapaDzDp+4hSkYB+aXn1G31B5X +zD4UftWfEX4cfEnw14COtj4sadqTwQzjUnUX+lNJOIT5t1E8qtglWO5nOGC5U8V2PxJ/ +YyTQzNcJoFxeoklw0HirwX+61iFJS5YXNmxKXQAkKl4yJCOAoo/ZX/ZRtXWO4KXtt4Ot +LpZpL26t3s73xFcRPlCY2w8FpGy5CHDSMOflyXwlCrKvGop2ppaxsvefdvdJdEt+vn5X +s68q3M3pf7l2ts79/uP/2Q== + +--de50511a21aa12aa7e67f9606279f097-- diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f86936a7967..a7247a4b7a7 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1226,7 +1226,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a // Send mail require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php'); - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1); if ($mailfile->error) { $mesg='
'.$mailfile->error.'
'; diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php index 1f0b8b78e07..7a91dff701d 100644 --- a/htdocs/lib/CMailFile.class.php +++ b/htdocs/lib/CMailFile.class.php @@ -90,8 +90,10 @@ class CMailFile global $conf; // Evite caractere bizarre avec les accents - $subject = utf8_decode($subject); - $from = utf8_decode($from); + //Todo l'envoi par mailing donne des caractères bizarre, + // alors que l'envoi d'un document facture ou autre est correcte + //$subject = utf8_decode($subject); + //$from = utf8_decode($from); // If ending method not defined if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail'; @@ -147,6 +149,12 @@ class CMailFile // On defini mime_boundary $this->mime_boundary = md5(uniqid("dolibarr")); + + // On defini related_boundary + $this->related_boundary = md5(uniqid("dolibarr")); + + // On defini alternative_boundary + $this->alternative_boundary = md5(uniqid("dolibarr")); // On definit fin de ligne $this->eol="\n"; @@ -210,22 +218,7 @@ class CMailFile $smtps->setSubject($subject); $smtps->setTO($to); $smtps->setFrom($from); - if ($this->atleastoneimage) - { - $msg = $this->html; - /* - $out=''; - // Check if html header already in message - $htmlalreadyinmsg=0; - if (eregi('^[ \t]*html)) $htmlalreadyinmsg=1; - - if (! $htmlalreadyinmsg) $out .= ""; - $out.= $this->html; - if (! $htmlalreadyinmsg) $out .= ""; - $msg = $out; - */ - } - + if ($this->atleastoneimage) $msg = $this->html; if ($this->msgishtml) $smtps->setBodyContent($msg,'html'); else $smtps->setBodyContent($msg,'plain'); @@ -487,18 +480,18 @@ class CMailFile if ($this->atleastoneimage) { - if (! $this->atleastonefile) $out.= "Content-Type: multipart/related; boundary=\"".$this->mime_boundary."\"".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol; + if (! $this->atleastonefile) $out.= "Content-Type: multipart/related; boundary=\"".$this->mime_boundary."\"".$this->eol; } else if ($this->msgishtml) { - if (! $this->atleastonefile) $out.= "Content-Type: text/html; boundary=\"".$this->mime_boundary."\"".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol; + if (! $this->atleastonefile) $out.= "Content-Type: text/html; boundary=\"".$this->mime_boundary."\"".$this->eol; } else { - if (! $this->atleastonefile) $out.= "Content-Type: text/plain; boundary=\"".$this->mime_boundary."\"".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol; + if (! $this->atleastonefile) $out.= "Content-Type: text/plain; boundary=\"".$this->mime_boundary."\"".$this->eol; } dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out, LOG_DEBUG); @@ -529,6 +522,13 @@ class CMailFile } if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; $out.= "X-attachments: $filename_list[$i]".$this->eol; + + if ($mimedone!=2 && $this->atleastoneimage) + { + $out.= "--" . $this->mime_boundary . $this->eol; + $out.= "Content-Type: multipart/related; boundary=\"".$this->related_boundary."\"".$this->eol; + $mimedone=2; + } } } } @@ -553,7 +553,14 @@ class CMailFile { if ($this->msgishtml) { - $out.= "--" . $this->mime_boundary . $this->eol; + if ($this->atleastonefile && $this->atleastoneimage) + { + $out.= "--" . $this->related_boundary . $this->eol; + } + else + { + $out.= "--" . $this->mime_boundary . $this->eol; + } $out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol; } else @@ -574,13 +581,23 @@ class CMailFile if (! $htmlalreadyinmsg) $out .= ""; if ($this->atleastonefile || $this->atleastoneimage) { - $out.= $this->eol . "--" . $this->mime_boundary . $this->eol; + if ($this->atleastonefile && $this->atleastoneimage) + { + $out.= $this->eol . "--" . $this->related_boundary . $this->eol; + } + else + { + $out.= $this->eol . "--" . $this->mime_boundary . $this->eol; + } } } else { $out.= $msgtext; - $out.= $this->eol . "--" . $this->mime_boundary . $this->eol; + if ($this->atleastonefile) + { + $out.= $this->eol . "--" . $this->mime_boundary . $this->eol; + } } return $out; @@ -790,7 +807,14 @@ class CMailFile { dol_syslog("CMailFile::write_images: i=$i"); - $out.= "--" . $this->mime_boundary . $this->eol; + if (! $this->atleastonefile) + { + $out.= "--" . $this->mime_boundary . $this->eol; + } + else + { + $out.= "--" . $this->related_boundary . $this->eol; + } $out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol; $out.= "Content-Transfer-Encoding: base64".$this->eol; $out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol; @@ -806,7 +830,14 @@ class CMailFile } // Fin de tous les attachements - $out.= "--" . $this->mime_boundary . "--" . $this->eol; + if (! $this->atleastonefile) + { + $out.= "--" . $this->mime_boundary . "--" . $this->eol; + } + else + { + $out.= "--" . $this->related_boundary . "--" . $this->eol; + } return $out; }