[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.send.inc.php (source)

   1  <?php
   2    /**************************************************************************\
   3    * eGroupWare API - smtp mailer using PHPMailer                             *
   4    * This file written by RalfBecker@outdoor-training.de                      *
   5    * ------------------------------------------------------------------------ *
   6    * This library is free software; you can redistribute it and/or modify it  *
   7    * under the terms of the GNU Lesser General Public License as published by *
   8    * the Free Software Foundation; either version 2.1 of the License,         *
   9    * or any later version.                                                    *
  10    * This library is distributed in the hope that it will be useful, but      *
  11    * WITHOUT ANY WARRANTY; without even the implied warranty of               *
  12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
  13    * See the GNU Lesser General Public License for more details.              *
  14    * You should have received a copy of the GNU Lesser General Public License *
  15    * along with this library; if not, write to the Free Software Foundation,  *
  16    * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
  17    \**************************************************************************/
  18  
  19    /* $Id: class.send.inc.php 21435 2006-04-24 18:50:32Z ralfbecker $ */
  20  
  21      require_once (EGW_API_INC.'/class.phpmailer.inc.php');
  22  
  23      /**
  24      * New eGW send-class. It implements the old interface (msg-method) on top of PHPMailer.
  25      *
  26      * The configuration is read from Admin >> Site configuration and it does NOT depend on one of the email-apps anymore.
  27      *
  28      * @author RalfBecker@outdoor-training.de
  29      */
  30      class send extends PHPMailer
  31      {
  32          var $err    = array();
  33          var $to_res = array();
  34  
  35          /**
  36          * eGW specific initialisation of the PHPMailer: charset, language, smtp-host, ...
  37          *
  38          * To be able to call PHPMailer's Send function, we check if a subject, body or address is set and call it in that case,
  39          * else we do our constructors work.
  40          */
  41  		function send()
  42          {
  43              if ($this->Subject || $this->Body || count($this->to))
  44              {
  45                  return PHPMailer::Send();
  46              }
  47              $this->CharSet = $GLOBALS['egw']->translation->charset();
  48              list($lang,$nation) = explode('-',$GLOBALS['egw_info']['user']['preferences']['common']['lang']);
  49              $lang_path = EGW_SERVER_ROOT.'/phpgwapi/setup/';
  50              if ($nation && file_exists($lang_path."phpmailer.lang-$nation.php"))    // atm. only for pt-br => br
  51              {
  52                  $lang = $nation;
  53              }
  54              $this->SetLanguage($lang,$lang_path);
  55  
  56              $this->IsSmtp();
  57              $this->Host = $GLOBALS['egw_info']['server']['smtp_server']?$GLOBALS['egw_info']['server']['smtp_server']:'localhost';
  58              $this->Port = $GLOBALS['egw_info']['server']['smtp_port']?$GLOBALS['egw_info']['server']['smtp_port']:25;
  59              $this->SMTPAuth = !empty($GLOBALS['egw_info']['server']['smtp_auth_user']);
  60              $this->Username = $GLOBALS['egw_info']['server']['smtp_auth_user'];
  61              $this->Password = $GLOBALS['egw_info']['server']['smtp_auth_passwd'];
  62  
  63              $this->Hostname = $GLOBALS['egw_info']['server']['hostname'];
  64          }
  65  
  66          /**
  67          * Reset all Settings to send multiple Messages
  68          */
  69  		function ClearAll()
  70          {
  71              $this->err = array();
  72  
  73              $this->Subject = $this->Body = $this->AltBody = '';
  74              $this->IsHTML(False);
  75              $this->ClearAllRecipients();
  76              $this->ClearAttachments();
  77              $this->ClearCustomHeaders();
  78  
  79              $this->FromName = $GLOBALS['egw_info']['user']['fullname'];
  80              $this->From = $GLOBALS['egw_info']['user']['email'];
  81              $this->Sender = '';
  82  
  83              $this->AddCustomHeader('X-Mailer:eGroupWare (http://www.eGroupWare.org)');
  84          }
  85  
  86          /**
  87          * Emulating the old send::msg interface for compatibility with existing code
  88          *
  89          * You can either use that code or the PHPMailer variables and methods direct.
  90          */
  91  		function msg($service, $to, $subject, $body, $msgtype='', $cc='', $bcc='', $from='', $sender='', $content_type='', $boundary='Message-Boundary')
  92          {
  93              //echo "<p>send::msg(,to='$to',subject='$subject',,'$msgtype',cc='$cc',bcc='$bcc',from='$from',sender='$sender','$content_type','$boundary')<pre>$body</pre>\n";
  94              $this->ClearAll();    // reset everything to its default, we might be called more then once !!!
  95  
  96              if ($service != 'email')
  97              {
  98                  return False;
  99              }
 100              if ($from)
 101              {
 102                  if (preg_match('/"?(.+)"?<(.+)>/',$from,$matches))
 103                  {
 104                      list(,$this->FromName,$this->From) = $matches;
 105                  }
 106                  else
 107                  {
 108                      $this->From = $from;
 109                      $this->FromName = '';
 110                  }
 111              }
 112              if ($sender)
 113              {
 114                  $this->Sender = $sender;
 115              }
 116              foreach(array('to','cc','bcc') as $adr)
 117              {
 118                  if ($$adr)
 119                  {
 120                      if (preg_match_all('/"?(.+)"?<(.+)>,?/',$$adr,$matches))
 121                      {
 122                          $names = $matches[1];
 123                          $addresses = $matches[2];
 124                      }
 125                      else
 126                      {
 127                          $addresses = explode(',',trim($$adr));
 128                          $names = array();
 129                      }
 130                      $method = 'Add'.($adr == 'to' ? 'Address' : $adr);
 131  
 132                      foreach($addresses as $n => $address)
 133                      {
 134                          $this->$method($address,$names[$n]);
 135                      }
 136                  }
 137              }
 138              if (!empty($msgtype))
 139              {
 140                  $this->AddCustomHeader('X-eGW-Type: '.$msgtype);
 141              }
 142              if ($content_type)
 143              {
 144                  $this->ContentType = $content_type;
 145              }
 146              $this->Subject = $subject;
 147              $this->Body = $body;
 148  
 149              //echo "PHPMailer = <pre>".print_r($this,True)."</pre>\n";
 150              if (!$this->Send())
 151              {
 152                  $this->err = array(
 153                      'code' => 1,    // we dont get a numerical code from PHPMailer
 154                      'msg'  => $this->ErrorInfo,
 155                      'desc' => $this->ErrorInfo,
 156                  );
 157                  return False;
 158              }
 159              return True;
 160          }
 161  
 162          /**
 163          * encode 8-bit chars in subject-line
 164          *
 165          * This is not needed any more, as it is done be PHPMailer, but older code depend on it.
 166          */
 167  		function encode_subject($subject)
 168          {
 169              return $subject;
 170          }
 171      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7