From: Janusz Dobrowolski Date: Fri, 15 Mar 2024 10:46:33 +0000 (+0100) Subject: [0005735] Problems with sending emails with encoding other than ASCII - fixed. X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=0cbe5791fbc7f09ab9dda6b92d1ae27e61d26953 [0005735] Problems with sending emails with encoding other than ASCII - fixed. --- diff --git a/inventory/includes/inventory_db.inc b/inventory/includes/inventory_db.inc index df256755..ddc817ad 100644 --- a/inventory/includes/inventory_db.inc +++ b/inventory/includes/inventory_db.inc @@ -94,14 +94,13 @@ function send_reorder_email($loc, $st_ids, $st_names, $st_num, $st_reorder) require_once($path_to_root . "/reporting/includes/class.mail.inc"); $company = get_company_prefs(); $mail = new email($company['coy_name'], $company['email']); - $to = $loc['location_name'] . " <" . $loc['email'] . ">"; $subject = _("Stocks below Re-Order Level at ") . $loc['location_name']; $msg = "\n"; for ($i = 0; $i < count($st_ids); $i++) $msg .= $st_ids[$i] . " " . $st_names[$i] . ", " . _("Re-Order Level") . ": " . $st_reorder[$i] . ", " . _("Below") . ": " . $st_num[$i] . "\n"; $msg .= "\n" . _("Please reorder") . "\n\n"; $msg .= $company['coy_name']; - $mail->to($to); + $mail->to($loc['location_name'], $loc['email']); $mail->subject($subject); $mail->text($msg); return $mail->send(); diff --git a/reporting/includes/class.mail.inc b/reporting/includes/class.mail.inc index 9ae05ea9..583a20a4 100644 --- a/reporting/includes/class.mail.inc +++ b/reporting/includes/class.mail.inc @@ -44,25 +44,43 @@ class email function __construct($name, $mail) { $this->boundary = md5(uniqid(time())); - $this->headers['From'] = "$name <$mail>"; + $this->headers['From'] = $this->encode($name)." <$mail>"; + $bcc = get_company_pref('bcc_email'); if ($bcc) $this->bcc[] = $bcc; } - function to($mail) + function encode($txt) + { + + $opts = array('input-charset' => $_SESSION['language']->encoding, + 'output-charest' => 'utf-8', // utf-8 works always nowadays + 'line-length'=> 72, + 'linebreak-chars'=>'\n', + 'scheme' => 'Q', + ); + return substr(iconv_mime_encode(null, $txt, $opts), 2); + } + + // + // For backward compatibility in extensions address can be passed + // in $name in form: '"full name" '. + // Don't use this form unless all the mail addresses are encoded in ASCII + // + function to($name, $mail='') { - $this->to[] = $mail; + $this->to[] = $mail=='' ? $name : ($this->encode($name)." <$mail>"); } - function cc($mail) + function cc($name, $mail='') { - $this->cc[] = $mail; + $this->cc[] = $mail=='' ? $name : ($this->encode($name)." <$mail>"); } - function bcc($mail) + function bcc($name='', $mail='') { - $this->bcc[] = $mail; + $this->bcc[] = $mail=='' ? $name : ($this->encode($name)." <$mail>"); } function attachment($file, $filename=null) @@ -74,7 +92,7 @@ class email function subject($subject) { - $this->subject = $subject; + $this->subject = $this->encode($subject); } function text($text) @@ -120,11 +138,11 @@ class email { // Add CC Recipients if (!empty($this->cc)) - $this->headers['Cc'] = implode(", ", $this->cc); + $this->headers['Cc'] = implode(", ", $this->cc); // Add BCC Recipients if (!empty($this->bcc)) - $this->headers['Bcc'] = implode(", ", $this->bcc); + $this->headers['Bcc'] = implode(", ", $this->bcc); $this->headers['Content-Type'] = "multipart/mixed;\n boundary=\"$this->boundary\""; // Add Attachments diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index ecb31b0e..a803fe3f 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -998,14 +998,13 @@ class FrontReport extends Cpdf continue; $emailtype = true; $this->SetLang($contact['lang']); + $coy_name = @html_entity_decode($this->company['coy_name'], ENT_QUOTES, $_SESSION['language']->encoding=='iso-8859-2' ? 'ISO-8859-1' : $_SESSION['language']->encoding); require_once($path_to_root . "/reporting/includes/class.mail.inc"); - $mail = new email(str_replace(",", "", $this->company['coy_name']), + $mail = new email(str_replace(",", "", $coy_name), $this->company['email']); $mail->charset = $this->encoding; - $to = str_replace(",", "", $contact['name'].' '.$contact['name2']) - ." <" . $contact['email'] . ">"; $msg = _("Dear") . " " . $contact['name2'] . ",\n\n" . _("Attached you will find ") . " " . $subject ."\n\n"; @@ -1024,8 +1023,9 @@ class FrontReport extends Cpdf } $msg .= _("Kindest regards") . "\n\n"; - $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone']; - $mail->to($to); $try++; + $sender = $this->user . "\n" . $coy_name . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone']; + $mail->to(str_replace(",", "", $contact['name'].' '.$contact['name2']), $contact['email']); + $try++; $mail->subject($subject); $mail->text($msg . $sender); $mail->attachment($fname, $this->filename); diff --git a/reporting/rep107.php b/reporting/rep107.php index 1362d5d1..3aa5d050 100644 --- a/reporting/rep107.php +++ b/reporting/rep107.php @@ -324,7 +324,7 @@ function print_invoices() $rep->Font(); if ($email == 1) { - $rep->End($email, sprintf(_("Invoice %s from %s"), $myrow['reference'], get_company_pref('coy_name'))); + $rep->End($email, sprintf(_("Invoice %s from %s"), $myrow['reference'], htmlspecialchars_decode(get_company_pref('coy_name')))); } } if ($email == 0) diff --git a/reporting/rep108.php b/reporting/rep108.php index f2d6d423..3c8b7310 100644 --- a/reporting/rep108.php +++ b/reporting/rep108.php @@ -177,7 +177,7 @@ function print_statements() if ($email == 1) { if (($CustomerRecord["Balance"]) != ($CustomerRecord["Balance"] - $CustomerRecord["Due"])) - $rep->End($email, _("Statement") . " " . _("as of") . " " . sql2date($date) . " " . _("from") . " " . get_company_pref('coy_name')); + $rep->End($email, _("Statement") . " " . _("as of") . " " . sql2date($date) . " " . _("from") . " " . htmlspecialchars_decode(get_company_pref('coy_name'))); else display_notification(sprintf(_("Customer %s has no overdue debits. No e-mail is sent."), $myrow["DebtorName"])); }