Fixed bug #431256 - Alias expanded not RFC 821-compatible
[squirrelmail.git] / functions / smtp.php
index 153f15e530699a5ff52e6342cd8b90ba5d6de68e..92ab7f72a91538a4a1740c9cad233c7e6b80a55c 100644 (file)
       return $array;
    }
 
+
+   // looks up aliases in the addressbook and expands them to
+   // the RFC 821 valid RCPT address. ie <user@example.com>
+   // Adds @$domain if it wasn't in the address book and if it
+   // doesn't have an @ symbol in it
+   function expandRcptAddrs ($array) {
+      global $domain;
+
+      // don't show errors -- kinda critical that we don't see
+      // them here since the redirect won't work if we do show them
+      $abook = addressbook_init(false);
+      for ($i=0; $i < count($array); $i++) {
+         $result = $abook->lookup($array[$i]);
+         $ret = "";
+         if (isset($result['email'])) {
+            $ret = '<'.$result['email'].'>';
+            $array[$i] = $ret;
+         }
+         else
+         {
+            if (strpos($array[$i], '@') === false)
+               $array[$i] .= '@' . $domain;
+            $array[$i] = '<' . $array[$i] . '>';
+         }
+      }
+      return $array;
+   }
+
+
    // Attach the files that are due to be attached
    function attachFiles ($fp) {
       global $attachments, $attachment_dir;
          $smtpPort, $data_dir, $color, $use_authenticated_smtp, $identity, 
         $key, $onetimepad;
 
-      $to = expandAddrs(parseAddrs($t));
-      $cc = expandAddrs(parseAddrs($c));
-      $bcc = expandAddrs(parseAddrs($b));
+      $to = expandRcptAddrs(parseAddrs($t));
+      $cc = expandRcptAddrs(parseAddrs($c));
+      $bcc = expandRcptAddrs(parseAddrs($b));
       if (isset($identity) && $identity != 'default')
         $from_addr = getPref($data_dir, $username, 'email_address' . $identity);
       else