[0005735] Problems with sending emails with encoding other than ASCII - fixed.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 15 Mar 2024 10:46:33 +0000 (11:46 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 15 Mar 2024 10:46:33 +0000 (11:46 +0100)
inventory/includes/inventory_db.inc
reporting/includes/class.mail.inc
reporting/includes/pdf_report.inc
reporting/rep107.php
reporting/rep108.php

index df25675516832e4ba3361dfb3c2e7fe8d1a06c0c..ddc817ad3bdb30848a2621ebba799e05bcf00568 100644 (file)
@@ -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();
index 9ae05ea9acca9686041ff762edb7a1414c75a13f..583a20a489032b0c1342dd4995cbc5d2f0c9462a 100644 (file)
@@ -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" <adr@host>'.
+    // 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
index ecb31b0e46a5c3620bf1d3b2b08a9600f75d6f68..a803fe3f9a640a030b8f7208d16400a8d5c00d5d 100644 (file)
@@ -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);
index 1362d5d1591816a6304cf7fa8f2765f14c4a2ff6..3aa5d050263f20af554f3028597d5887e6c61df5 100644 (file)
@@ -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)
index f2d6d42387ad5b5f368f51d802bdeb1f5a0f2fd8..3c8b7310603de03df262b8358108855624bab293 100644 (file)
@@ -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"]));       
         }