diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index e96adea7531..0d235a21798 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -41,7 +41,10 @@ class CMailFile public $sendmode; public $sendsetup; - public $subject; // Topic: Subject of email + /** + * @var string Subject of email + */ + public $subject; public $addr_from; // From: Label and EMail of sender (must include '<>'). For example '' or 'John Doe ' or ''). Note that with gmail smtps, value here is forced by google to account (but not the reply-to). // Sender: Who send the email ("Sender" has sent emails on behalf of "From"). // Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain. @@ -148,7 +151,7 @@ class CMailFile // Add autocopy to if not already in $to (Note: Adding bcc for specific modules are also done from pages) if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && !preg_match('/'.preg_quote($conf->global->MAIN_MAIL_AUTOCOPY_TO, '/').'/i', $to)) { - $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO; + $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO; } $this->subject = $subject; @@ -161,7 +164,9 @@ class CMailFile $this->addr_cc = $addr_cc; $this->addr_bcc = $addr_bcc; $this->deliveryreceipt = $deliveryreceipt; - if (empty($replyto)) $replyto = $from; + if (empty($replyto)) { + $replyto = $from; + } $this->reply_to = $replyto; $this->errors_to = $errors_to; $this->trackid = $trackid; @@ -180,15 +185,18 @@ class CMailFile $this->sendmode = $smtpContextSendMode; } } - if (empty($this->sendmode)) $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE; - if (empty($this->sendmode)) $this->sendmode = 'mail'; + if (empty($this->sendmode)) { + $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE; + } + if (empty($this->sendmode)) { + $this->sendmode = 'mail'; + } // We define end of line (RFC 821). $this->eol = "\r\n"; // We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n). $this->eol2 = "\r\n"; - if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) - { + if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) { $this->eol = "\n"; $this->eol2 = "\n"; $moreinheader = str_replace("\r\n", "\n", $moreinheader); @@ -206,23 +214,22 @@ class CMailFile dol_syslog("CMailFile::CMailfile: sendmode=".$this->sendmode." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, replyto=$replyto trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG); dol_syslog("CMailFile::CMailfile: subject=".$subject.", deliveryreceipt=".$deliveryreceipt.", msgishtml=".$msgishtml, LOG_DEBUG); - if (empty($subject)) - { + if (empty($subject)) { dol_syslog("CMailFile::CMailfile: Try to send an email with empty subject"); $this->error = 'ErrorSubjectIsRequired'; return; } - if (empty($msg)) - { + if (empty($msg)) { dol_syslog("CMailFile::CMailfile: Try to send an email with empty body"); $msg = '.'; // Avoid empty message (with empty message content, you will see a multipart structure) } // Detect if message is HTML (use fast method) - if ($msgishtml == -1) - { + if ($msgishtml == -1) { $this->msgishtml = 0; - if (dol_textishtml($msg)) $this->msgishtml = 1; + if (dol_textishtml($msg)) { + $this->msgishtml = 1; + } } else { $this->msgishtml = $msgishtml; } @@ -237,26 +244,23 @@ class CMailFile // Replace relative /viewimage to absolute path $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1); - if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml = 1; // To force to send everything with content type html. + if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) { + $this->msgishtml = 1; // To force to send everything with content type html. + } // Detect images - if ($this->msgishtml) - { + if ($this->msgishtml) { $this->html = $msg; $findimg = 0; - if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) - { + if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) { $findimg = $this->findHtmlImages($dolibarr_main_data_root.'/medias'); } // Define if there is at least one file - if ($findimg) - { - foreach ($this->html_images as $i => $val) - { - if ($this->html_images[$i]) - { + if ($findimg) { + foreach ($this->html_images as $i => $val) { + if ($this->html_images[$i]) { $this->atleastoneimage = 1; dol_syslog("CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i]['name'], LOG_DEBUG); } @@ -265,12 +269,9 @@ class CMailFile } // Define if there is at least one file - if (is_array($filename_list)) - { - foreach ($filename_list as $i => $val) - { - if ($filename_list[$i]) - { + if (is_array($filename_list)) { + foreach ($filename_list as $i => $val) { + if ($filename_list[$i]) { $this->atleastonefile = 1; dol_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG); } @@ -279,7 +280,7 @@ class CMailFile // Add autocopy to if not already in $to (Note: Adding bcc for specific modules are also done from pages) if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && !preg_match('/'.preg_quote($conf->global->MAIN_MAIL_AUTOCOPY_TO, '/').'/i', $to)) { - $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO; + $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO; } $this->addr_to = $to; @@ -292,8 +293,7 @@ class CMailFile $this->deliveryreceipt = $deliveryreceipt; $this->trackid = $trackid; - if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) - { + if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) { $this->addr_to = $conf->global->MAIN_MAIL_FORCE_SENDTO; $this->addr_cc = ''; $this->addr_bcc = ''; @@ -311,8 +311,7 @@ class CMailFile // We set all data according to choosed sending method. // We also set a value for ->msgid - if ($this->sendmode == 'mail') - { + if ($this->sendmode == 'mail') { // Use mail php function (default PHP method) // ------------------------------------------ @@ -323,15 +322,15 @@ class CMailFile // Define smtp_headers (this also set ->msgid) $smtp_headers = $this->write_smtpheaders(); - if (!empty($moreinheader)) $smtp_headers .= $moreinheader; // $moreinheader contains the \r\n + if (!empty($moreinheader)) { + $smtp_headers .= $moreinheader; // $moreinheader contains the \r\n + } // Define mime_headers $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); - if (!empty($this->html)) - { - if (!empty($css)) - { + if (!empty($this->html)) { + if (!empty($css)) { $this->css = $css; $this->buildCSS(); // Build a css style (mode = all) into this->styleCSS and this->bodyCSS } @@ -357,8 +356,7 @@ class CMailFile $this->message = 'This is a message with multiple parts in MIME format.'.$this->eol; $this->message .= $text_body.$files_encoded; $this->message .= "--".$this->mixed_boundary."--".$this->eol; - } elseif ($this->sendmode == 'smtps') - { + } elseif ($this->sendmode == 'smtps') { // Use SMTPS library // ------------------------------------------ @@ -378,12 +376,12 @@ class CMailFile $smtps->setTrackId($this->trackid); $smtps->setReplyTo($this->getValidAddress($this->reply_to, 0, 1)); - if (!empty($moreinheader)) $smtps->setMoreInHeader($moreinheader); + if (!empty($moreinheader)) { + $smtps->setMoreInHeader($moreinheader); + } - if (!empty($this->html)) - { - if (!empty($css)) - { + if (!empty($this->html)) { + if (!empty($css)) { $this->css = $css; $this->buildCSS(); } @@ -394,21 +392,20 @@ class CMailFile // Replace . alone on a new line with .. to avoid to have SMTP interpret this as end of message $msg = preg_replace('/(\r|\n)\.(\r|\n)/ims', '\1..\2', $msg); - if ($this->msgishtml) $smtps->setBodyContent($msg, 'html'); - else $smtps->setBodyContent($msg, 'plain'); + if ($this->msgishtml) { + $smtps->setBodyContent($msg, 'html'); + } else { + $smtps->setBodyContent($msg, 'plain'); + } - if ($this->atleastoneimage) - { - foreach ($this->images_encoded as $img) - { + if ($this->atleastoneimage) { + foreach ($this->images_encoded as $img) { $smtps->setImageInline($img['image_encoded'], $img['name'], $img['content_type'], $img['cid']); } } - if (!empty($this->atleastonefile)) - { - foreach ($filename_list as $i => $val) - { + if (!empty($this->atleastonefile)) { + foreach ($filename_list as $i => $val) { $content = file_get_contents($filename_list[$i]); $smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]); } @@ -418,7 +415,9 @@ class CMailFile $smtps->setBCC($this->addr_bcc); $smtps->setErrorsTo($this->errors_to); $smtps->setDeliveryReceipt($this->deliveryreceipt); - if (!empty($conf->global->$keyforsslseflsigned)) $smtps->setOptions(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true))); + if (!empty($conf->global->$keyforsslseflsigned)) { + $smtps->setOptions(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true))); + } $host = dol_getprefix('email'); $this->msgid = time().'.SMTPs-dolibarr-'.$this->trackid.'@'.$host; @@ -465,8 +464,7 @@ class CMailFile $regexp = '/([a-z0-9_\.\-\+])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i'; // This regular expression extracts all emails from a string $emailMatchs = preg_match_all($regexp, $from, $adressEmailFrom); $adressEmailFrom = reset($adressEmailFrom); - if ($emailMatchs !== false && filter_var($conf->global->MAIN_MAIL_SMTPS_ID, FILTER_VALIDATE_EMAIL) && $conf->global->MAIN_MAIL_SMTPS_ID !== $adressEmailFrom) - { + if ($emailMatchs !== false && filter_var($conf->global->MAIN_MAIL_SMTPS_ID, FILTER_VALIDATE_EMAIL) && $conf->global->MAIN_MAIL_SMTPS_ID !== $adressEmailFrom) { $result = $this->message->setFrom($conf->global->MAIN_MAIL_SMTPS_ID); } else { $result = $this->message->setFrom($this->getArrayAddress($this->addr_from)); @@ -511,10 +509,8 @@ class CMailFile $msg = $this->checkIfHTML($msg); } - if ($this->atleastoneimage) - { - foreach ($this->images_encoded as $img) - { + if ($this->atleastoneimage) { + foreach ($this->images_encoded as $img) { //$img['fullpath'],$img['image_encoded'],$img['name'],$img['content_type'],$img['cid'] $attachment = Swift_Image::fromPath($img['fullpath']); // embed image @@ -534,10 +530,8 @@ class CMailFile $this->message->addPart(dol_nl2br($msg), 'text/html'); } - if (!empty($this->atleastonefile)) - { - foreach ($filename_list as $i => $val) - { + if (!empty($this->atleastonefile)) { + foreach ($filename_list as $i => $val) { //$this->message->attach(Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i])); $attachment = Swift_Attachment::fromPath($filename_list[$i], $mimetype_list[$i]); if (!empty($mimefilename_list[$i])) { @@ -547,10 +541,16 @@ class CMailFile } } - if (!empty($this->addr_cc)) $this->message->setCc($this->getArrayAddress($this->addr_cc)); - if (!empty($this->addr_bcc)) $this->message->setBcc($this->getArrayAddress($this->addr_bcc)); + if (!empty($this->addr_cc)) { + $this->message->setCc($this->getArrayAddress($this->addr_cc)); + } + if (!empty($this->addr_bcc)) { + $this->message->setBcc($this->getArrayAddress($this->addr_bcc)); + } //if (! empty($this->errors_to)) $this->message->setErrorsTo($this->getArrayAddress($this->errors_to)); - if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($this->addr_from)); + if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) { + $this->message->setReadReceiptTo($this->getArrayAddress($this->addr_from)); + } } else { // Send mail method not correctly defined // -------------------------------------- @@ -573,29 +573,25 @@ class CMailFile $res = false; - if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) - { + if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) { require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager = new HookManager($db); $hookmanager->initHooks(array('mail')); $parameters = array(); $action = ''; $reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) - { + if ($reshook < 0) { $this->error = "Error in hook maildao sendMail ".$reshook; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); return $reshook; } - if ($reshook == 1) // Hook replace standard code - { + if ($reshook == 1) { // Hook replace standard code return true; } $sendingmode = $this->sendmode; - if ($this->context == 'emailing' && !empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail') - { + if ($this->context == 'emailing' && !empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail') { // List of sending methods $listofmethods = array(); $listofmethods['mail'] = 'PHP mail function'; @@ -610,8 +606,7 @@ class CMailFile $this->errors[] = $langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]); $this->error .= '
'.$langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']); $this->errors[] = $langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']); - if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) - { + if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) { $this->error .= '
'.$langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS); $this->errors[] = $langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS); } @@ -619,33 +614,37 @@ class CMailFile } // Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL = 10; + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) { + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL = 10; + } $tmparray1 = explode(',', $this->addr_to); - if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL) - { + if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL) { $this->error = 'Too much recipients in to:'; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); return false; } - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL = 10; + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) { + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL = 10; + } $tmparray2 = explode(',', $this->addr_cc); - if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL) - { + if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL) { $this->error = 'Too much recipients in cc:'; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); return false; } - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL = 10; + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) { + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL = 10; + } $tmparray3 = explode(',', $this->addr_bcc); - if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL) - { + if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL) { $this->error = 'Too much recipients in bcc:'; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); return false; } - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10; - if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) - { + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) { + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10; + } + if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) { $this->error = 'Too much recipients in to:, cc:, bcc:'; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); return false; @@ -674,8 +673,7 @@ class CMailFile } // Action according to choosed sending method - if ($this->sendmode == 'mail') - { + if ($this->sendmode == 'mail') { // Use mail php function (default PHP method) // ------------------------------------------ dol_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject, LOG_DEBUG); @@ -683,59 +681,67 @@ class CMailFile //dol_syslog("CMailFile::sendfile message=\n".$message); // If Windows, sendmail_from must be defined - if (isset($_SERVER["WINDIR"])) - { - if (empty($this->addr_from)) $this->addr_from = 'robot@example.com'; + if (isset($_SERVER["WINDIR"])) { + if (empty($this->addr_from)) { + $this->addr_from = 'robot@example.com'; + } @ini_set('sendmail_from', $this->getValidAddress($this->addr_from, 2)); } // Force parameters //dol_syslog("CMailFile::sendfile conf->global->".$keyforsmtpserver."=".$conf->global->$keyforsmtpserver." cpnf->global->".$keyforsmtpport."=".$conf->global->$keyforsmtpport, LOG_DEBUG); - if (!empty($conf->global->$keyforsmtpserver)) ini_set('SMTP', $conf->global->$keyforsmtpserver); - if (!empty($conf->global->$keyforsmtpport)) ini_set('smtp_port', $conf->global->$keyforsmtpport); + if (!empty($conf->global->$keyforsmtpserver)) { + ini_set('SMTP', $conf->global->$keyforsmtpserver); + } + if (!empty($conf->global->$keyforsmtpport)) { + ini_set('smtp_port', $conf->global->$keyforsmtpport); + } $res = true; - if ($res && !$this->subject) - { + if ($res && !$this->subject) { $this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."
Subject is empty"; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); $res = false; } $dest = $this->getValidAddress($this->addr_to, 2); - if ($res && !$dest) - { + if ($res && !$dest) { $this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."
Recipient address '$dest' invalid"; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); $res = false; } - if ($res) - { + if ($res) { $additionnalparam = ''; // By default - if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)) - { + if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)) { // le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA // Le forcage de la valeur grace à l'option -f de sendmail est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie. // Having this variable defined may create problems with some sendmail (option -f refused) // Having this variable not defined may create problems with some other sendmail (option -f required) $additionnalparam .= ($additionnalparam ? ' ' : '').(!empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f'.$this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO, 2) : ($this->addr_from != '' ? '-f'.$this->getValidAddress($this->addr_from, 2) : '')); } - if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender - { + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) { // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender $additionnalparam .= ($additionnalparam ? ' ' : '').'-ba'; } - if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam ? ' ' : '').'-U '.$additionnalparam; // Use -U to add additionnal params + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) { + $additionnalparam .= ($additionnalparam ? ' ' : '').'-U '.$additionnalparam; // Use -U to add additionnal params + } $linuxlike = 1; - if (preg_match('/^win/i', PHP_OS)) $linuxlike = 0; - if (preg_match('/^mac/i', PHP_OS)) $linuxlike = 0; + if (preg_match('/^win/i', PHP_OS)) { + $linuxlike = 0; + } + if (preg_match('/^mac/i', PHP_OS)) { + $linuxlike = 0; + } dol_syslog("CMailFile::sendfile: mail start".($linuxlike ? '' : " HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')).", additionnal_parameters=".$additionnalparam, LOG_DEBUG); $this->message = stripslashes($this->message); - if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); + if (!empty($conf->global->MAIN_MAIL_DEBUG)) { + $this->dump_mail(); + } // Encode subject if required. $subjecttouse = $this->subject; @@ -743,11 +749,13 @@ class CMailFile $subjecttouse = $this->encodetorfc2822($subjecttouse); } - if (!empty($additionnalparam)) $res = mail($dest, $subjecttouse, $this->message, $this->headers, $additionnalparam); - else $res = mail($dest, $subjecttouse, $this->message, $this->headers); + if (!empty($additionnalparam)) { + $res = mail($dest, $subjecttouse, $this->message, $this->headers, $additionnalparam); + } else { + $res = mail($dest, $subjecttouse, $this->message, $this->headers); + } - if (!$res) - { + if (!$res) { $langs->load("errors"); $this->error = "Failed to send mail with php mail"; if (!$linuxlike) { @@ -761,18 +769,19 @@ class CMailFile } } - if (isset($_SERVER["WINDIR"])) - { + if (isset($_SERVER["WINDIR"])) { @ini_restore('sendmail_from'); } // Restore parameters - if (!empty($conf->global->$keyforsmtpserver)) ini_restore('SMTP'); - if (!empty($conf->global->$keyforsmtpport)) ini_restore('smtp_port'); - } elseif ($this->sendmode == 'smtps') - { - if (!is_object($this->smtps)) - { + if (!empty($conf->global->$keyforsmtpserver)) { + ini_restore('SMTP'); + } + if (!empty($conf->global->$keyforsmtpport)) { + ini_restore('smtp_port'); + } + } elseif ($this->sendmode == 'smtps') { + if (!is_object($this->smtps)) { $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."
Constructor of object CMailFile was not initialized without errors."; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); return false; @@ -783,14 +792,22 @@ class CMailFile $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library // Clean parameters - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP'); - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport = ini_get('smtp_port'); + if (empty($conf->global->$keyforsmtpserver)) { + $conf->global->$keyforsmtpserver = ini_get('SMTP'); + } + if (empty($conf->global->$keyforsmtpport)) { + $conf->global->$keyforsmtpport = ini_get('smtp_port'); + } // If we use SSL/TLS $server = $conf->global->$keyforsmtpserver; $secure = ''; - if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl'; - if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls'; + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) { + $secure = 'ssl'; + } + if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) { + $secure = 'tls'; + } $server = ($secure ? $secure.'://' : '').$server; $port = $conf->global->$keyforsmtpport; @@ -799,74 +816,87 @@ class CMailFile $this->smtps->setPort($port); // 25, 465...; $loginid = ''; $loginpass = ''; - if (!empty($conf->global->$keyforsmtpid)) - { + if (!empty($conf->global->$keyforsmtpid)) { $loginid = $conf->global->$keyforsmtpid; $this->smtps->setID($loginid); } - if (!empty($conf->global->$keyforsmtppw)) - { + if (!empty($conf->global->$keyforsmtppw)) { $loginpass = $conf->global->$keyforsmtppw; $this->smtps->setPW($loginpass); } $res = true; $from = $this->smtps->getFrom('org'); - if ($res && !$from) - { + if ($res && !$from) { $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport." - Sender address '$from' invalid"; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); $res = false; } $dest = $this->smtps->getTo(); - if ($res && !$dest) - { + if ($res && !$dest) { $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport." - Recipient address '$dest' invalid"; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); $res = false; } - if ($res) - { - if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); + if ($res) { + if (!empty($conf->global->MAIN_MAIL_DEBUG)) { + $this->smtps->setDebug(true); + } $result = $this->smtps->sendMsg(); //print $result; - if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); + if (!empty($conf->global->MAIN_MAIL_DEBUG)) { + $this->dump_mail(); + } $result = $this->smtps->getErrors(); - if (empty($this->error) && empty($result)) - { + if (empty($this->error) && empty($result)) { dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); $res = true; } else { - if (empty($this->error)) $this->error = $result; + if (empty($this->error)) { + $this->error = $result; + } dol_syslog("CMailFile::sendfile: mail end error with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport." - ".$this->error, LOG_ERR); $res = false; } } - } elseif ($this->sendmode == 'swiftmailer') - { + } elseif ($this->sendmode == 'swiftmailer') { // Use Swift Mailer library // ------------------------------------------ require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php'; // Clean parameters - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP'); - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport = ini_get('smtp_port'); + if (empty($conf->global->$keyforsmtpserver)) { + $conf->global->$keyforsmtpserver = ini_get('SMTP'); + } + if (empty($conf->global->$keyforsmtpport)) { + $conf->global->$keyforsmtpport = ini_get('smtp_port'); + } // If we use SSL/TLS $server = $conf->global->$keyforsmtpserver; $secure = ''; - if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl'; - if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls'; + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) { + $secure = 'ssl'; + } + if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) { + $secure = 'tls'; + } $this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure); - if (!empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid); - if (!empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw); - if (!empty($conf->global->$keyforsslseflsigned)) $this->transport->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false))); + if (!empty($conf->global->$keyforsmtpid)) { + $this->transport->setUsername($conf->global->$keyforsmtpid); + } + if (!empty($conf->global->$keyforsmtppw)) { + $this->transport->setPassword($conf->global->$keyforsmtppw); + } + if (!empty($conf->global->$keyforsslseflsigned)) { + $this->transport->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false))); + } //$smtps->_msgReplyTo = 'reply@web.com'; // Switch content encoding to base64 - avoid the doubledot issue with quoted-printable @@ -898,7 +928,9 @@ class CMailFile } catch (Exception $e) { $this->error = $e->getMessage(); } - if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); + if (!empty($conf->global->MAIN_MAIL_DEBUG)) { + $this->dump_mail(); + } $res = true; if (!empty($this->error) || !$result) { @@ -916,8 +948,7 @@ class CMailFile $parameters = array(); $action = ''; $reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) - { + if ($reshook < 0) { $this->error = "Error in hook maildao sendMailAfter ".$reshook; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); @@ -1014,9 +1045,13 @@ class CMailFile { if (!preg_match('/^[\s\t]*styleCSS)) $out .= $this->styleCSS; + if (!empty($this->styleCSS)) { + $out .= $this->styleCSS; + } $out .= "bodyCSS)) $out .= $this->bodyCSS; + if (!empty($this->bodyCSS)) { + $out .= $this->bodyCSS; + } $out .= ">"; $out .= $msg; $out .= ""; @@ -1070,29 +1105,37 @@ class CMailFile // Sender //$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2; $out .= "From: ".$this->getValidAddress($this->addr_from, 3, 1).$this->eol2; - if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) - { + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) { $out .= "To: ".$this->getValidAddress($this->addr_to, 0, 1).$this->eol2; } // Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that. $out .= "Return-Path: ".$this->getValidAddress($this->addr_from, 0, 1).$this->eol2; - if (isset($this->reply_to) && $this->reply_to) $out .= "Reply-To: ".$this->getValidAddress($this->reply_to, 2).$this->eol2; - if (isset($this->errors_to) && $this->errors_to) $out .= "Errors-To: ".$this->getValidAddress($this->errors_to, 2).$this->eol2; + if (isset($this->reply_to) && $this->reply_to) { + $out .= "Reply-To: ".$this->getValidAddress($this->reply_to, 2).$this->eol2; + } + if (isset($this->errors_to) && $this->errors_to) { + $out .= "Errors-To: ".$this->getValidAddress($this->errors_to, 2).$this->eol2; + } // Receiver - if (isset($this->addr_cc) && $this->addr_cc) $out .= "Cc: ".$this->getValidAddress($this->addr_cc, 2).$this->eol2; - if (isset($this->addr_bcc) && $this->addr_bcc) $out .= "Bcc: ".$this->getValidAddress($this->addr_bcc, 2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? + if (isset($this->addr_cc) && $this->addr_cc) { + $out .= "Cc: ".$this->getValidAddress($this->addr_cc, 2).$this->eol2; + } + if (isset($this->addr_bcc) && $this->addr_bcc) { + $out .= "Bcc: ".$this->getValidAddress($this->addr_bcc, 2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? + } // Delivery receipt - if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2; + if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) { + $out .= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2; + } //$out.= "X-Priority: 3".$this->eol2; $out .= 'Date: '.date("r").$this->eol2; $trackid = $this->trackid; - if ($trackid) - { + if ($trackid) { // References is kept in response and Message-ID is returned into In-Reply-To: $this->msgid = time().'.phpmail-dolibarr-'.$trackid.'@'.$host; $out .= 'Message-ID: <'.$this->msgid.">".$this->eol2; // Uppercase seems replaced by phpmail @@ -1103,7 +1146,9 @@ class CMailFile $out .= 'Message-ID: <'.$this->msgid.">".$this->eol2; } - if (!empty($_SERVER['REMOTE_ADDR'])) $out .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR'].$this->eol2; + if (!empty($_SERVER['REMOTE_ADDR'])) { + $out .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR'].$this->eol2; + } $out .= "X-Mailer: Dolibarr version ".DOL_VERSION." (using php mail)".$this->eol2; $out .= "Mime-Version: 1.0".$this->eol2; @@ -1131,14 +1176,13 @@ class CMailFile $mimedone = 0; $out = ""; - if (is_array($filename_list)) - { + if (is_array($filename_list)) { $filename_list_size = count($filename_list); - for ($i = 0; $i < $filename_list_size; $i++) - { - if ($filename_list[$i]) - { - if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; + for ($i = 0; $i < $filename_list_size; $i++) { + if ($filename_list[$i]) { + if ($mimefilename_list[$i]) { + $filename_list[$i] = $mimefilename_list[$i]; + } $out .= "X-attachments: $filename_list[$i]".$this->eol2; } } @@ -1164,8 +1208,7 @@ class CMailFile $out .= "--".$this->mixed_boundary.$this->eol; - if ($this->atleastoneimage) - { + if ($this->atleastoneimage) { $out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; $out .= $this->eol; $out .= "--".$this->alternative_boundary.$this->eol; @@ -1173,14 +1216,12 @@ class CMailFile // Make RFC821 Compliant, replace bare linefeeds $strContent = preg_replace("/(?global->MAIN_FIX_FOR_BUGGED_MTA)) - { + if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) { $strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars } $strContentAltText = ''; - if ($this->msgishtml) - { + if ($this->msgishtml) { // Similar code to forge a text from html is also in smtps.class.php $strContentAltText = preg_replace("/]*>/", " ", $strContent); $strContentAltText = html_entity_decode(strip_tags($strContentAltText)); @@ -1195,10 +1236,8 @@ class CMailFile // TODO Encode main content into base64 and use the chunk_split, or quoted-printable $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n")); // TODO Using this method creates unexpected line break on text/plain content. - if ($this->msgishtml) - { - if ($this->atleastoneimage) - { + if ($this->msgishtml) { + if ($this->atleastoneimage) { $out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; $out .= $this->eol.($strContentAltText ? $strContentAltText : strip_tags($strContent)).$this->eol; // Add plain text message @@ -1208,8 +1247,7 @@ class CMailFile $out .= "--".$this->related_boundary.$this->eol; } - if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part - { + if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { // Add plain text message part before html part $out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; $out .= $this->eol; $out .= "--".$this->alternative_boundary.$this->eol; @@ -1223,8 +1261,7 @@ class CMailFile //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; // TODO Use base64 $out .= $this->eol.$strContent.$this->eol; - if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part - { + if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { // Add plain text message part after html part $out .= "--".$this->alternative_boundary."--".$this->eol; } } else { @@ -1236,8 +1273,7 @@ class CMailFile $out .= $this->eol; // Encode images - if ($this->atleastoneimage) - { + if ($this->atleastoneimage) { $out .= $this->write_images($this->images_encoded); // always end related and end alternative after inline images $out .= "--".$this->related_boundary."--".$this->eol; @@ -1263,15 +1299,14 @@ class CMailFile $out = ''; $filename_list_size = count($filename_list); - for ($i = 0; $i < $filename_list_size; $i++) - { - if ($filename_list[$i]) - { + for ($i = 0; $i < $filename_list_size; $i++) { + if ($filename_list[$i]) { dol_syslog("CMailFile::write_files: i=$i"); $encoded = $this->_encode_file($filename_list[$i]); - if ($encoded >= 0) - { - if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; + if ($encoded >= 0) { + if ($mimefilename_list[$i]) { + $filename_list[$i] = $mimefilename_list[$i]; + } if (!$mimetype_list[$i]) { $mimetype_list[$i] = "application/octet-stream"; } @@ -1307,10 +1342,8 @@ class CMailFile // phpcs:enable $out = ''; - if (is_array($images_list)) - { - foreach ($images_list as $img) - { + if (is_array($images_list)) { + foreach ($images_list as $img) { dol_syslog("CMailFile::write_images: ".$img["name"]); $out .= "--".$this->related_boundary.$this->eol; // always related for an inline image @@ -1344,16 +1377,14 @@ class CMailFile $_retVal = 0; $timeout = 5; // Timeout in seconds - if (function_exists('fsockopen')) - { + if (function_exists('fsockopen')) { $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER'; $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT'; $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID'; $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW'; $keyfortls = 'MAIN_MAIL_EMAIL_TLS'; $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS'; - if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') - { + if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') { $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING'; $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_EMAILING'; $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID_EMAILING'; @@ -1363,26 +1394,32 @@ class CMailFile } // If we use SSL/TLS - if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host = 'ssl://'.$host; + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) { + $host = 'ssl://'.$host; + } // tls smtp start with no encryption //if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host; dol_syslog("Try socket connection to host=".$host." port=".$port); //See if we can connect to the SMTP server if ($socket = @fsockopen( - $host, // Host to test, IP or domain. Add ssl:// for SSL/TLS. - $port, // which Port number to use - $errno, // actual system level error - $errstr, // and any text that goes with the error - $timeout // timeout for reading/writing data over the socket + $host, // Host to test, IP or domain. Add ssl:// for SSL/TLS. + $port, // which Port number to use + $errno, // actual system level error + $errstr, // and any text that goes with the error + $timeout // timeout for reading/writing data over the socket )) { // Windows still does not have support for this timeout function - if (function_exists('stream_set_timeout')) stream_set_timeout($socket, $timeout, 0); + if (function_exists('stream_set_timeout')) { + stream_set_timeout($socket, $timeout, 0); + } dol_syslog("Now we wait for answer 220"); // Check response from Server - if ($_retVal = $this->server_parse($socket, "220")) $_retVal = $socket; + if ($_retVal = $this->server_parse($socket, "220")) { + $_retVal = $socket; + } } else { $this->error = utf8_check('Error '.$errno.' - '.$errstr) ? 'Error '.$errno.' - '.$errstr : utf8_encode('Error '.$errno.' - '.$errstr); } @@ -1405,17 +1442,14 @@ class CMailFile $_retVal = true; // Indicates if Object was created or not $server_response = ''; - while (substr($server_response, 3, 1) != ' ') - { - if (!($server_response = fgets($socket, 256))) - { + while (substr($server_response, 3, 1) != ' ') { + if (!($server_response = fgets($socket, 256))) { $this->error = "Couldn't get mail server response codes"; return false; } } - if (!(substr($server_response, 0, 3) == $response)) - { + if (!(substr($server_response, 0, 3) == $response)) { $this->error = "Ran into problems sending Mail.\r\nResponse: $server_response"; $_retVal = false; } @@ -1437,17 +1471,13 @@ class CMailFile $matches = array(); preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches); // If "xxx.ext" or 'xxx.ext' found - if (!empty($matches)) - { + if (!empty($matches)) { $i = 0; - foreach ($matches[1] as $full) - { - if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs)) // If xxx is 'file=aaa' - { + foreach ($matches[1] as $full) { + if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs)) { // If xxx is 'file=aaa' $img = $regs[1]; - if (file_exists($images_dir.'/'.$img)) - { + if (file_exists($images_dir.'/'.$img)) { // Image path in src $src = preg_quote($full, '/'); @@ -1458,8 +1488,7 @@ class CMailFile $this->html_images[$i]["name"] = $img; // Content type - if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg)) - { + if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg)) { $ext = strtolower($reg[1]); $this->html_images[$i]["content_type"] = $this->image_types[$ext]; } @@ -1472,22 +1501,18 @@ class CMailFile } } - if (!empty($this->html_images)) - { + if (!empty($this->html_images)) { $inline = array(); $i = 0; - foreach ($this->html_images as $img) - { + foreach ($this->html_images as $img) { $fullpath = $images_dir.'/'.$img["name"]; // If duplicate images are embedded, they may show up as attachments, so remove them. - if (!in_array($fullpath, $inline)) - { + if (!in_array($fullpath, $inline)) { // Read image file - if ($image = file_get_contents($fullpath)) - { + if ($image = file_get_contents($fullpath)) { // On garde que le nom de l'image preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i', $img["name"], $regs); $imgName = $regs[1]; @@ -1538,11 +1563,9 @@ class CMailFile // Boucle sur chaque composant de l'adresse $i = 0; - foreach ($arrayaddress as $val) - { + foreach ($arrayaddress as $val) { $regs = array(); - if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) - { + if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) { $name = trim($regs[1]); $email = trim($regs[2]); } else { @@ -1550,8 +1573,7 @@ class CMailFile $email = trim($val); } - if ($email) - { + if ($email) { $i++; $newemail = ''; @@ -1559,31 +1581,32 @@ class CMailFile $newemail = $name ? $name : $email; $newemail = ''.$newemail.''; } - if ($format == 4) - { + if ($format == 4) { $newemail = $name ? $name : $email; } - if ($format == 2) - { + if ($format == 2) { $newemail = $email; } - if ($format == 1 || $format == 3) - { + if ($format == 1 || $format == 3) { $newemail = '<'.$email.'>'; } - if ($format == 0 || $format == 3) - { - if (!empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail = '<'.$email.'>'; - elseif (!$name) $newemail = '<'.$email.'>'; - else $newemail = ($format == 3 ? '"' : '').($encode ?self::encodetorfc2822($name) : $name).($format == 3 ? '"' : '').' <'.$email.'>'; + if ($format == 0 || $format == 3) { + if (!empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) { + $newemail = '<'.$email.'>'; + } elseif (!$name) { + $newemail = '<'.$email.'>'; + } else { + $newemail = ($format == 3 ? '"' : '').($encode ?self::encodetorfc2822($name) : $name).($format == 3 ? '"' : '').' <'.$email.'>'; + } } $ret = ($ret ? $ret.',' : '').$newemail; // Stop if we have too much records - if ($maxnumberofemail && $i >= $maxnumberofemail) - { - if (count($arrayaddress) > $maxnumberofemail) $ret .= '...'; + if ($maxnumberofemail && $i >= $maxnumberofemail) { + if (count($arrayaddress) > $maxnumberofemail) { + $ret .= '...'; + } break; } } @@ -1608,10 +1631,8 @@ class CMailFile $arrayaddress = explode(',', $address); // Boucle sur chaque composant de l'adresse - foreach ($arrayaddress as $val) - { - if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) - { + foreach ($arrayaddress as $val) { + if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) { $name = trim($regs[1]); $email = trim($regs[2]); } else { diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 1b29af772a7..ca0bf2da2b2 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1132,7 +1132,7 @@ class FormMail extends Form } /** - * get Html For Asking for Deliveriy Receipt + * get Html For Asking for Delivery Receipt * * @return string html */ @@ -1445,7 +1445,9 @@ class FormMail extends Form // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__ if (!empty($line->fk_product)) { - if (!is_object($extrafields)) $extrafields = new ExtraFields($this->db); + if (!is_object($extrafields)) { + $extrafields = new ExtraFields($this->db); + } $extrafields->fetch_name_optionals_label('product', true); $product = new Product($this->db); $product->fetch($line->fk_product, '', '', 1); @@ -1509,9 +1511,15 @@ class FormMail extends Form //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing $onlinepaymentenabled = 0; - if (!empty($conf->paypal->enabled)) $onlinepaymentenabled++; - if (!empty($conf->paybox->enabled)) $onlinepaymentenabled++; - if (!empty($conf->stripe->enabled)) $onlinepaymentenabled++; + if (!empty($conf->paypal->enabled)) { + $onlinepaymentenabled++; + } + if (!empty($conf->paybox->enabled)) { + $onlinepaymentenabled++; + } + if (!empty($conf->stripe->enabled)) { + $onlinepaymentenabled++; + } if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) { $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN; if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { @@ -1540,7 +1548,9 @@ class FormMail extends Form } foreach ($tmparray as $key => $val) { - if (empty($val)) $tmparray[$key] = $key; + if (empty($val)) { + $tmparray[$key] = $key; + } } return $tmparray;