diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php
index fce813aaa05..d27e6e59fb4 100644
--- a/htdocs/core/actions_sendmails.inc.php
+++ b/htdocs/core/actions_sendmails.inc.php
@@ -22,7 +22,7 @@
*/
-// TODO Include this include file into all class objects
+// TODO Include this include file into all element pages allowing email sending
// $id must be defined
// $actiontypecode must be defined
@@ -161,9 +161,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$filename = $attachedfiles['names'];
$mimetype = $attachedfiles['mimes'];
+ $trackid = GETPOST('trackid','aZ');
+
// Send mail
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
- $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1);
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
if ($mailfile->error)
{
$mesgs[]='
'.$mailfile->error.'
';
diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php
index 967b764dc65..6e41384dbce 100644
--- a/htdocs/core/class/CMailFile.class.php
+++ b/htdocs/core/class/CMailFile.class.php
@@ -4,7 +4,7 @@
* Copyright (C) Eric Seigne
* Copyright (C) 2000-2005 Rodolphe Quiedeville
* Copyright (C) 2003 Jean-Louis Bergamo
- * Copyright (C) 2004-2012 Laurent Destailleur
+ * Copyright (C) 2004-2015 Laurent Destailleur
* Copyright (C) 2005-2012 Regis Houssin
*
* This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,7 @@
/**
* Class to send emails (with attachments or not)
- * Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to);
+ * Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid);
* $mailfile->sendfile();
*/
class CMailFile
@@ -45,6 +45,7 @@ class CMailFile
var $addr_to;
var $addr_cc;
var $addr_bcc;
+ var $trackid;
var $mixed_boundary;
var $related_boundary;
@@ -65,6 +66,9 @@ class CMailFile
//! Defined background directly in body tag
var $bodyCSS;
+ var $headers;
+ var $message;
+
// Image
var $html;
var $image_boundary;
@@ -95,10 +99,11 @@ class CMailFile
* @param string $addr_bcc Email bcc (Note: This is autocompleted with MAIN_MAIL_AUTOCOPY_TO if defined)
* @param int $deliveryreceipt Ask a delivery receipt
* @param int $msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown make autodetection (with fast mode, not reliable)
- * @param string $errors_to Email errors
+ * @param string $errors_to Email for errors-to
* @param string $css Css option
+ * @param string $trackid Tracking string
*/
- function __construct($subject,$to,$from,$msg,$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='')
+ function __construct($subject,$to,$from,$msg,$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='',$trackid='')
{
global $conf;
@@ -124,7 +129,7 @@ class CMailFile
// If ending method not defined
if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail';
- dol_syslog("CMailFile::CMailfile: MAIN_MAIL_SENDMODE=".$conf->global->MAIN_MAIL_SENDMODE." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to", LOG_DEBUG);
+ dol_syslog("CMailFile::CMailfile: MAIN_MAIL_SENDMODE=".$conf->global->MAIN_MAIL_SENDMODE." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, trackid=$trackid", LOG_DEBUG);
dol_syslog("CMailFile::CMailfile: subject=$subject, deliveryreceipt=$deliveryreceipt, msgishtml=$msgishtml", LOG_DEBUG);
// Detect if message is HTML (use fast method)
@@ -190,6 +195,7 @@ class CMailFile
$this->addr_cc = $addr_cc;
$this->addr_bcc = $addr_bcc;
$this->deliveryreceipt = $deliveryreceipt;
+ $this->trackid = $trackid;
$smtp_headers = $this->write_smtpheaders();
// Define mime_headers
@@ -249,6 +255,7 @@ class CMailFile
$smtps->setSubject($this->encodetorfc2822($subject));
$smtps->setTO($this->getValidAddress($to,0,1));
$smtps->setFrom($this->getValidAddress($from,0,1));
+ $smtps->setTrackId($trackid);
if (! empty($this->html))
{
@@ -301,6 +308,7 @@ class CMailFile
$this->phpmailer->Subject($this->encodetorfc2822($subject));
$this->phpmailer->setTO($this->getValidAddress($to,0,1));
$this->phpmailer->SetFrom($this->getValidAddress($from,0,1));
+ // TODO Add trackid into smtp header
if (! empty($this->html))
{
@@ -516,7 +524,7 @@ class CMailFile
/**
* Encode subject according to RFC 2822 - http://en.wikipedia.org/wiki/MIME#Encoded-Word
- *
+ *
* @param string $stringtoencode String to encode
* @return string string encoded
*/
@@ -674,7 +682,17 @@ class CMailFile
//$out.= "X-Priority: 3".$this->eol2;
$out.= 'Date: ' . date("r") . $this->eol2;
- $out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
+
+ $trackid = $this->trackid;
+ if ($trackid)
+ {
+ $out.= 'Message-ID: <' . time() . '.phpmail-'.$trackid.'@' . $host . ">" . $this->eol2;
+ $out.= 'references: <' . time() . '.phpmail-'.$trackid.'@' . $host . ">" . $this->eol2;
+ }
+ else
+ {
+ $out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
+ }
$out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2;
$out.= "Mime-Version: 1.0".$this->eol2;
diff --git a/htdocs/core/class/smtps.class.php b/htdocs/core/class/smtps.class.php
index 5c7d73eb136..5cc62c56bc6 100644
--- a/htdocs/core/class/smtps.class.php
+++ b/htdocs/core/class/smtps.class.php
@@ -1,7 +1,7 @@
[with a *lot* of help!]
- * Copyright (C) 2005-2012 Laurent Destailleur
+ * Copyright (C) 2005-2015 Laurent Destailleur
* Copyright (C) 2006-2011 Regis Houssin
*
* This program is free software; you can redistribute it and/or modify
@@ -224,7 +224,7 @@ class SMTPs
var $log = '';
var $_errorsTo = '';
var $_deliveryReceipt = 0;
-
+ var $_trackId = '';
/**
@@ -248,6 +248,27 @@ class SMTPs
return $this->_deliveryReceipt;
}
+ /**
+ * Set trackid
+ *
+ * @param string $_val Value
+ * @return void
+ */
+ function setTrackId($_val = '')
+ {
+ $this->_trackId = $_val;
+ }
+
+ /**
+ * get trackid
+ *
+ * @return string Delivery receipt
+ */
+ function getTrackId()
+ {
+ return $this->_trackId;
+ }
+
/**
* Set errors to
*
@@ -1106,11 +1127,23 @@ class SMTPs
$host=preg_replace('@ssl://@i','',$host); // Remove prefix
//NOTE: Message-ID should probably contain the username of the user who sent the msg
- $_header .= 'Subject: ' . $this->getSubject() . "\r\n"
- . 'Date: ' . date("r") . "\r\n"
- . 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
- // . 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
- // . 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
+ $_header .= 'Subject: ' . $this->getSubject() . "\r\n";
+ $_header .= 'Date: ' . date("r") . "\r\n";
+
+ $trackid = $this->getTrackId();
+ if ($trackid)
+ {
+ $_header .= 'Message-ID: <' . time() . '.SMTPs-'.$trackid.'@' . $host . ">\r\n";
+ $_header .= 'references: <' . time() . '.SMTPs-'.$trackid.'@' . $host . ">\r\n";
+ }
+ else
+ {
+ $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
+ }
+
+ //$_header .=
+ // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"
+ // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
if ( $this->getSensitivity() )
$_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n";