source: branches/2.0/expressoMail1_2/inc/class.phpmailer.php @ 2938

Revision 2938, 52.0 KB checked in by amuller, 14 years ago (diff)

Ticket #818 - Remove a validação equívocada

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2////////////////////////////////////////////////////
3// PHPMailer - PHP email class
4//
5// Class for sending email using either
6// sendmail, PHP mail(), or SMTP.  Methods are
7// based upon the standard AspEmail(tm) classes.
8//
9// Copyright (C) 2001 - 2003  Brent R. Matzelle
10//
11// License: LGPL, see LICENSE
12////////////////////////////////////////////////////
13
14/**
15 * PHPMailer - PHP email transport class
16 * @package PHPMailer
17 * @author Brent R. Matzelle
18 * @copyright 2001 - 2003 Brent R. Matzelle
19 */
20class PHPMailer
21{
22    /////////////////////////////////////////////////
23    // PUBLIC VARIABLES
24    /////////////////////////////////////////////////
25
26    /**
27     * Email priority (1 = High, 3 = Normal, 5 = low).
28     * @var int
29     */
30    var $Priority          = 3;
31        /**
32         * Email Importance.
33         */
34        var $Importance        = "";
35
36    /**
37     * Sets the CharSet of the message.
38     * @var string
39     */
40    var $CharSet           = "iso-8859-1";
41
42    /**
43     * Sets the Content-type of the message.
44     * @var string
45     */
46    var $ContentType        = "text/plain";
47
48    /**
49     * Sets the Encoding of the message. Options for this are "8bit",
50     * "7bit", "binary", "base64", and "quoted-printable".
51     * @var string
52     */
53    var $Encoding          = "quoted-printable";
54
55    /**
56     * Holds the most recent mailer error message.
57     * @var string
58     */
59    var $ErrorInfo         = "";
60
61    /**
62     * Sets the From email address for the message.
63     * @var string
64     */
65    var $From               = "root@localhost";
66
67    /**
68     * Sets the From name of the message.
69     * @var string
70     */
71    var $FromName           = "Root User";
72
73    /**
74     * Sets the Sender email (Return-Path) of the message.  If not empty,
75     * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
76     * @var string
77     */
78    var $Sender            = "";
79        var $SenderName         = "";
80    /**
81     * Sets the Subject of the message.
82     * @var string
83     */
84    var $Subject           = "teste";
85
86    /**
87     * Sets the Body of the message.  This can be either an HTML or text body.
88     * If HTML then run IsHTML(true).
89     * @var string
90     */
91    var $Body               = "";
92
93    /**
94     * Sets the text-only body of the message.  This automatically sets the
95     * email to multipart/alternative.  This body can be read by mail
96     * clients that do not have HTML email capability such as mutt. Clients
97     * that can read HTML will view the normal Body.
98     * @var string
99     */
100    var $AltBody           = "";
101
102    /**
103     * Sets the signed body of the message.  This automatically sets the
104     * email to multipart/signed.
105     * @var string
106     */
107    var $SignedBody           = false;
108    var $SMIME                  = false;
109    var $Certs_crypt            = array();
110    /**
111     * Sets the encrypted body of the message.  This automatically sets the
112     * email to multipart/encript.
113     * @var string
114     */
115    var $CryptedBody           = "";
116
117    /**
118     * Sets word wrapping on the body of the message to a given number of
119     * characters.
120     * @var int
121     */
122    var $WordWrap          = 0;
123
124    /**
125     * Method to send mail: ("mail", "sendmail", or "smtp").
126     * @var string
127     */
128    var $Mailer            = "mail";
129
130    /**
131     * Sets the path of the sendmail program.
132     * @var string
133     */
134    var $Sendmail          = "/usr/sbin/sendmail";
135   
136    /**
137     * Path to PHPMailer plugins.  This is now only useful if the SMTP class
138     * is in a different directory than the PHP include path. 
139     * @var string
140     */
141    var $PluginDir         = "";
142
143    /**
144     *  Holds PHPMailer version.
145     *  @var string
146     */
147    var $Version           = "1.2";
148
149    /**
150     * Sets the email address that a reading confirmation will be sent.
151     * @var string
152     */
153    var $ConfirmReadingTo  = "";
154
155    /**
156     *  Sets the hostname to use in Message-Id and Received headers
157     *  and as default HELO string. If empty, the value returned
158     *  by SERVER_NAME is used or 'localhost.localdomain'.
159     *  @var string
160     */
161    var $Hostname          = "";
162       
163        var $SaveMessageInFolder = "";
164        var $SaveMessageAsDraft = "";
165
166    var $xMailer           = "";
167
168    /////////////////////////////////////////////////
169    // SMTP VARIABLES
170    /////////////////////////////////////////////////
171
172    /**
173     *  Sets the SMTP hosts.  All hosts must be separated by a
174     *  semicolon.  You can also specify a different port
175     *  for each host by using this format: [hostname:port]
176     *  (e.g. "smtp1.example.com:25;smtp2.example.com").
177     *  Hosts will be tried in order.
178     *  @var string
179     */
180    var $Host        = "localhost";
181
182    /**
183     *  Sets the default SMTP server port.
184     *  @var int
185     */
186    var $Port        = 25;
187
188    /**
189     *  Sets the SMTP HELO of the message (Default is $Hostname).
190     *  @var string
191     */
192    var $Helo        = "";
193
194    /**
195     *  Sets SMTP authentication. Utilizes the Username and Password variables.
196     *  @var bool
197     */
198    var $SMTPAuth     = false;
199
200    /**
201     *  Sets SMTP username.
202     *  @var string
203     */
204    var $Username     = "";
205
206    /**
207     *  Sets SMTP password.
208     *  @var string
209     */
210    var $Password     = "";
211
212    /**
213     *  Sets the SMTP server timeout in seconds. This function will not
214     *  work with the win32 version.
215     *  @var int
216     */
217    var $Timeout      = 300;
218
219    /**
220     *  Sets SMTP class debugging on or off.
221     *  @var bool
222     */
223    var $SMTPDebug    = false;
224
225    /**
226     * Prevents the SMTP connection from being closed after each mail
227     * sending.  If this is set to true then to close the connection
228     * requires an explicit call to SmtpClose().
229     * @var bool
230     */
231    var $SMTPKeepAlive = false;
232
233    /**#@+
234     * @access private
235     */
236    var $smtp            = NULL;
237    var $to              = array();
238    var $cc              = array();
239    var $bcc             = array();
240    var $ReplyTo         = array();
241    var $attachment      = array();
242    var $CustomHeader    = array();
243    var $message_type    = "";
244    var $boundary        = array();
245    var $language        = array();
246    var $error_count     = 0;
247    var $LE              = "\n";
248    /**#@-*/
249   
250    /////////////////////////////////////////////////
251    // VARIABLE METHODS
252    /////////////////////////////////////////////////
253
254        function isImportant() {
255                $this->Importance = "High";
256        }
257       
258    /**
259     * Sets message type to HTML. 
260     * @param bool $bool
261     * @return void
262     */
263    function IsHTML($bool) {
264        if($bool == true)
265            $this->ContentType = "text/html";
266        else
267            $this->ContentType = "text/plain";
268    }
269
270    /**
271     * Sets Mailer to send message using SMTP.
272     * @return void
273     */
274    function IsSMTP() {
275        $this->Mailer = "smtp";
276    }
277
278    /**
279     * Sets Mailer to send message using PHP mail() function.
280     * @return void
281     */
282    function IsMail() {
283        $this->Mailer = "mail";
284    }
285
286    /**
287     * Sets Mailer to send message using the $Sendmail program.
288     * @return void
289     */
290    function IsSendmail() {
291        $this->Mailer = "sendmail";
292    }
293
294    /**
295     * Sets Mailer to send message using the qmail MTA.
296     * @return void
297     */
298    function IsQmail() {
299        $this->Sendmail = "/var/qmail/bin/sendmail";
300        $this->Mailer = "sendmail";
301    }
302
303
304    /////////////////////////////////////////////////
305    // RECIPIENT METHODS
306    /////////////////////////////////////////////////
307
308    /**
309     * Adds a "To" address. 
310     * @param string $address
311     * @param string $name
312     * @return void
313     */
314    function AddAddress($address, $name = "") {
315        $cur = count($this->to);
316        $this->to[$cur][0] = trim($address);
317        $this->to[$cur][1] = $name;
318    }
319
320    /**
321     * Adds a "Cc" address. Note: this function works
322     * with the SMTP mailer on win32, not with the "mail"
323     * mailer. 
324     * @param string $address
325     * @param string $name
326     * @return void
327    */
328    function AddCC($address, $name = "") {
329        $cur = count($this->cc);
330        $this->cc[$cur][0] = trim($address);
331        $this->cc[$cur][1] = $name;
332    }
333
334    /**
335     * Adds a "Bcc" address. Note: this function works
336     * with the SMTP mailer on win32, not with the "mail"
337     * mailer. 
338     * @param string $address
339     * @param string $name
340     * @return void
341     */
342    function AddBCC($address, $name = "") {
343        $cur = count($this->bcc);
344        $this->bcc[$cur][0] = trim($address);
345        $this->bcc[$cur][1] = $name;
346    }
347
348    /**
349     * Adds a "Reply-to" address. 
350     * @param string $address
351     * @param string $name
352     * @return void
353     */
354    function AddReplyTo($address, $name = "") {
355        $cur = count($this->ReplyTo);
356        $this->ReplyTo[$cur][0] = trim($address);
357        $this->ReplyTo[$cur][1] = $name;
358    }
359
360
361    /////////////////////////////////////////////////
362    // MAIL SENDING METHODS
363    /////////////////////////////////////////////////
364
365    /**
366     * Creates message and assigns Mailer. If the message is
367     * not sent successfully then it returns false.  Use the ErrorInfo
368     * variable to view description of the error. 
369     * @return bool
370     */
371    function Send() {
372       
373   
374        $header = "";
375        $body = "";
376        $result = true;
377               
378        if(((count($this->to) + count($this->cc) + count($this->bcc)) < 1) && (!$this->SaveMessageAsDraft))
379        {
380            $this->SetError($this->Lang("provide_address"));           
381            return false;
382        }
383               
384        // Set whether the message is multipart/alternative
385        if(!empty($this->AltBody))
386            $this->ContentType = "multipart/alternative";
387
388        $this->error_count = 0; // reset errors
389        $this->SetMessageType();
390        $header .= $this->CreateHeader();
391
392        if ($this->SMIME == false)
393        {
394            $body = $this->CreateBody();
395            if($body == "")
396            {
397                return false;
398            }
399        }
400               
401        // Choose the mailer
402        switch($this->Mailer)
403        {
404            // Usado para processar o email e retornar para a applet
405                case "smime":
406                $retorno['body'] = $header.$this->LE.$body;
407                $retorno['type'] =  $this->write_message_type();
408                        return $retorno;
409            case "sendmail":
410                $result = $this->SendmailSend($header, $body);
411                break;
412            case "mail":
413                $result = $this->MailSend($header, $body);
414                break;
415            case "smtp":
416                $result = $this->SmtpSend($header, $body);
417                break;
418            default:
419                    $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
420                $result = false;
421                break;
422        }
423
424        return $result;
425    }
426   
427    /**
428     * Sends mail using the $Sendmail program. 
429     * @access private
430     * @return bool
431     */
432    function SendmailSend($header, $body) {
433        if ($this->Sender != "")
434            $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
435        else
436            $sendmail = sprintf("%s -oi -t", $this->Sendmail);
437
438        if(!@$mail = popen($sendmail, "w"))
439        {
440            $this->SetError($this->Lang("execute") . $this->Sendmail);
441            return false;
442        }
443
444        fputs($mail, $header);
445        fputs($mail, $body);
446       
447        $result = pclose($mail) >> 8 & 0xFF;
448        if($result != 0)
449        {
450            $this->SetError($this->Lang("execute") . $this->Sendmail);
451            return false;
452        }
453
454        return true;
455    }
456
457    /**
458     * Sends mail using the PHP mail() function. 
459     * @access private
460     * @return bool
461     */
462    function MailSend($header, $body) {
463        $to = "";
464        for($i = 0; $i < count($this->to); $i++)
465        {
466            if($i != 0) { $to .= ", "; }
467            $to .= $this->to[$i][0];
468        }
469
470        if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
471        {
472            $old_from = ini_get("sendmail_from");
473            ini_set("sendmail_from", $this->Sender);
474            $params = sprintf("-oi -f %s", $this->Sender);
475            $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
476                        $header, $params);
477        }
478        else
479            $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
480
481        if (isset($old_from))
482            ini_set("sendmail_from", $old_from);
483
484        if(!$rt)
485        {
486            $this->SetError($this->Lang("instantiate"));
487            return false;
488        }
489
490        return true;
491    }
492
493    /**
494     * Sends mail via SMTP using PhpSMTP (Author:
495     * Chris Ryan).  Returns bool.  Returns false if there is a
496     * bad MAIL FROM, RCPT, or DATA input.
497     * @access private
498     * @return bool
499     */
500    function SmtpSend($header, $body) {
501        include_once($this->PluginDir . "class.smtp.php");
502        $error = "";
503
504        $bad_rcpt = array();
505        $errorx = '';
506        if(!$this->SmtpConnect())
507            return false;
508
509        if($this->SMIME)
510        {
511            $header='';
512            $body = $this->Body;
513        }
514
515        $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
516        if(!$this->smtp->Mail($smtp_from))
517        {
518            $error = $this->Lang("from_failed") . $smtp_from;
519            $this->SetError($error);
520            $this->smtp->Reset();
521            return false;
522        }
523
524        // Attempt to send attach all recipients
525        for($i = 0; $i < count($this->to); $i++)
526        {
527                if(!$this->smtp->Recipient($this->to[$i][0]))
528                        $bad_rcpt[] = $this->to[$i][0];
529        }
530        for($i = 0; $i < count($this->cc); $i++)
531        {
532                if(!$this->smtp->Recipient($this->cc[$i][0]))
533                        $bad_rcpt[] = $this->cc[$i][0];
534        }
535        for($i = 0; $i < count($this->bcc); $i++)
536        {
537                if(!$this->smtp->Recipient($this->bcc[$i][0]))
538                        $bad_rcpt[] = $this->bcc[$i][0];     
539        }
540        if($errorx != '')
541                {
542                        $error = $errorx;
543                        $error = $this->Lang("recipients_failed")  . '  ' . $errorx;
544                        $this->SetError($error);
545                        $this->smtp->Reset();
546                        return false;
547                }
548
549        if(count($bad_rcpt) > 0) // Create error message
550        {
551            //Postfix version 2.3.8-2
552            $smtp_code_error = substr($this->smtp->error['smtp_msg'], 0, 5);
553            //Postfix version 2.1.5-9
554            $array_error = explode(":", $this->smtp->error['smtp_msg']);
555           
556            for($i = 0; $i < count($bad_rcpt); $i++)
557            {
558                if($i != 0) { $error .= ", "; }
559                $error .= $bad_rcpt[$i];
560            }
561            if (($smtp_code_error == '5.7.1') || (trim($array_error[2]) == 'Access denied'))
562                $error = $this->Lang("not_allowed") . $error;
563            else
564                $error = $this->Lang("recipients_failed") . $error;
565            $this->SetError($error);
566            $this->smtp->Reset();
567            return false;
568        }
569
570        // Vai verificar se deve cifrar a msg ......
571        if(count($this->Certs_crypt) > 0)
572                {
573            // Vai cifrar a msg antes de enviar ......
574                        include_once("../security/classes/CertificadoB.php");
575
576            $teste1 = array();
577            $aux_cifra1 = $header . $body;
578
579            // Início relocação dos headers
580            // Esta relocação dos headers podem causar problemas.
581
582            $match = 0;
583            $pattern = '/^Disposition\-Notification\-To:.*\n/m';
584            $match = preg_match($pattern, $aux_cifra1, $teste1);
585
586            if (!empty($match)){
587                $aux_cifra1 = preg_replace($pattern, '', $aux_cifra1, 1); // retira o Disposition-Notification-To
588
589                $match = 0;
590                $teste2 = array();
591                $pattern = '/^MIME\-Version:.*\n/m';
592                $match = preg_match($pattern, $aux_cifra1, $teste2);
593                $aux_cifra1 = preg_replace($pattern, $teste1[0].$teste2[0], $aux_cifra1, 1); // Adiciona Disposition-Notification-To logo acima de MIME-Version
594
595            }
596            // Fim relocação dos headers
597
598           // Vai partir em duas partes a msg.  A primeira parte he a dos headers, e a segunda vai ser criptografada ...
599            $pos_content_type = strpos($aux_cifra1,'Content-Type:');
600            $pos_MIME_Version = strpos($aux_cifra1,'MIME-Version: 1.0' . chr(0x0D) . chr(0x0A));
601            $valx_len = 19;
602            if($pos_MIME_Version === False)
603                    {
604                $pos_MIME_Version = strpos($aux_cifra1,'MIME-Version: 1.0' . chr(0x0A));
605                $valx_len = 18;
606                    }
607
608            if($pos_MIME_Version >= $pos_content_type)
609            {
610                // nao deve enviar a msg..... O header MIME-Version com posicao invalida ......
611                $this->SetError('Formato dos headers da msg estao invalidos.(CD-17) - A');
612                $this->smtp->Reset();
613                return false;
614            }
615
616            $aux_cifra2 = array();
617            $aux_cifra2[] = substr($aux_cifra1,0,$pos_MIME_Version - 1);
618            $aux_cifra2[] = substr($aux_cifra1,$pos_MIME_Version + $valx_len);
619
620               /*
621                        // este explode pode ser fonte de problemas .......
622                        $aux_cifra2 = explode('MIME-Version: 1.0' . chr(0x0A), $aux_cifra1);
623                        // Pode ocorrer um erro se nao tiver o header MIME-Version .....
624                        if(count($aux_cifra2)  != 2 )
625                                {
626                                        $aux_cifra2 = explode('MIME-Version: 1.0' . chr(0x0D) . chr(0x0A), $aux_cifra1);
627                                        if(count($aux_cifra2)  != 2 )
628                                                {
629                                                        // nao deve enviar a msg..... nao tem o header MIME-Version ......
630                                                        $this->SetError('Formato dos headers da msg estao invalidos.(CD-17) - ' . count($aux_cifra2));
631                                                        $this->smtp->Reset();
632                                                        return false;
633                                                }
634                                }
635                */
636                        $certificado = new certificadoB();
637                        $h = array();
638                        $aux_body = $certificado->encriptar($aux_cifra2[1], $this->Certs_crypt, $h);
639                        if(!$aux_body)
640            {
641                $this->SetError('Ocorreu um erro. A msg nao foi enviada. (CD-18)');
642                $this->smtp->Reset();
643                return false;
644            }
645                        // salvar sem cifra......
646                        //$smtpSent = $this->smtp->Data($aux_cifra2[0] . $aux_body);
647
648                        // salva a msg sifrada. neste caso deve ter sido adicionado o certificado do autor da msg......
649                        $header = $aux_cifra2[0];
650                        $body = $aux_body;
651        $smtpSent = $this->smtp->Data($header . $body);
652        }
653        else
654                {
655                        $smtpSent = $this->smtp->Data($header . $body);
656                }
657
658        if(!$smtpSent)
659        {
660            $this->SetError($this->Lang("data_not_accepted") .' '. $this->smtp->error['error'] .','. $this->smtp->error['smtp_code'].','. $this->smtp->error['smtp_msg']);
661            $this->smtp->Reset();
662            return false;
663        }
664        if($this->SMTPKeepAlive == true)
665            $this->smtp->Reset();
666        else
667            $this->SmtpClose();
668
669        if ($this->SaveMessageInFolder){
670                        $username = $_SESSION['phpgw_info']['expressomail']['user']['userid'];
671                        $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd'];
672                        $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer'];
673                        $imap_port      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort'];
674                       
675                        if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
676                        {
677                                $imap_options = '/tls/novalidate-cert';
678                        }
679                        else
680                        {
681                                $imap_options = '/notls/novalidate-cert';
682                        }               
683                        $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$this->SaveMessageInFolder, $username, $password);
684
685                        ##
686                        # @AUTHOR Rodrigo Souza dos Santos
687                        # @DATE 2008/09/11
688                        # @BRIEF Adding arbitrarily the BCC field. You may need to
689                        #        check if this field already exists in the header.
690                        ##
691                        if ( count($this->bcc) > 0 )
692                        {
693                                $target = stripos($header, 'subject');
694                                $header = substr($header, 0, $target) . $this->AddrAppend("Bcc", $this->bcc) . substr($header, $target);
695                        }
696            $new_headerx = str_replace(chr(0x0A),chr(0x0D).chr(0x0A), $header);
697                        $new_bodyx = str_replace(chr(0x0A),chr(0x0D).chr(0x0A), $body);
698                        $new_header = str_replace(chr(0x0D).chr(0x0D).chr(0x0A), chr(0x0D).chr(0x0A),$new_headerx);
699                        $new_body = str_replace(chr(0x0D).chr(0x0D).chr(0x0A), chr(0x0D).chr(0x0A), $new_bodyx);
700                       
701                        if ($this->SaveMessageAsDraft){
702                                imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$this->SaveMessageInFolder, $new_header . $new_body, "\\Seen \\Draft");
703                                return true;
704                        }
705                        else
706                                imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$this->SaveMessageInFolder, $new_header . $new_body, "\\Seen");
707        }       
708       
709        return $smtpSent;
710    }
711
712    /**
713     * Initiates a connection to an SMTP server.  Returns false if the
714     * operation failed.
715     * @access private
716     * @return bool
717     */
718    function SmtpConnect() {
719        if($this->smtp == NULL) { $this->smtp = new SMTP(); }
720
721        $this->smtp->do_debug = $this->SMTPDebug;
722        $hosts = explode(";", $this->Host);
723        $index = 0;
724        $connection = ($this->smtp->Connected());
725
726        // Retry while there is no connection
727        while($index < count($hosts) && $connection == false)
728        {
729            if(strstr($hosts[$index], ":"))
730                list($host, $port) = explode(":", $hosts[$index]);
731            else
732            {
733                $host = $hosts[$index];
734                $port = $this->Port;
735            }
736
737            if($this->smtp->Connect($host, $port, $this->Timeout))
738            {
739                if ($this->Helo != '')
740                    $this->smtp->Hello($this->Helo);
741                else
742                    $this->smtp->Hello($this->ServerHostname());
743       
744                if($this->SMTPAuth)
745                {
746                    if(!$this->smtp->Authenticate($this->Username,
747                                                  $this->Password))
748                    {
749                        $this->SetError($this->Lang("authenticate"));
750                        $this->smtp->Reset();
751                        $connection = false;
752                    }
753                }
754                $connection = true;
755            }
756            $index++;
757        }
758        if(!$connection)
759            $this->SetError($this->Lang("connect_host"));
760
761        return $connection;
762    }
763
764    /**
765     * Closes the active SMTP session if one exists.
766     * @return void
767     */
768    function SmtpClose() {
769        if($this->smtp != NULL)
770        {
771            if($this->smtp->Connected())
772            {
773                $this->smtp->Quit();
774                $this->smtp->Close();
775            }
776        }
777    }
778
779    /**
780     * Sets the language for all class error messages.  Returns false
781     * if it cannot load the language file.  The default language type
782     * is English.
783     * @param string $lang_type Type of language (e.g. Portuguese: "br")
784     * @param string $lang_path Path to the language file directory
785     * @access public
786     * @return bool
787     */
788    function SetLanguage($lang_type, $lang_path = "setup/") {
789        if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
790            include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
791        else if(file_exists($lang_path.'phpmailer.lang-en.php'))
792            include($lang_path.'phpmailer.lang-en.php');
793        else
794        {
795            $this->SetError("Could not load language file");
796            return false;
797        }
798        $this->language = $PHPMAILER_LANG;
799   
800        return true;
801    }
802
803    /////////////////////////////////////////////////
804    // MESSAGE CREATION METHODS
805    /////////////////////////////////////////////////
806
807    /**
808     * Creates recipient headers. 
809     * @access private
810     * @return string
811     */
812    function AddrAppend($type, $addr) {
813        $addr_str = $type . ": ";
814        $addr_str .= $this->AddrFormat($addr[0]);
815        if(count($addr) > 1)
816        {
817            for($i = 1; $i < count($addr); $i++)
818                $addr_str .= ", " . $this->AddrFormat($addr[$i]);
819        }
820        $addr_str .= $this->LE;
821
822        return $addr_str;
823    }
824   
825    /**
826     * Formats an address correctly.
827     * @access private
828     * @return string
829     */
830    function AddrFormat($addr) {
831        if(empty($addr[1]))
832            $formatted = $addr[0];
833        else
834        {
835            $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
836                         $addr[0] . ">";
837        }
838
839        return $formatted;
840    }
841
842    /**
843     * Wraps message for use with mailers that do not
844     * automatically perform wrapping and for quoted-printable.
845     * Original written by philippe. 
846     * @access private
847     * @return string
848     */
849    function WrapText($message, $length, $qp_mode = false) {
850        $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
851
852        $message = $this->FixEOL($message);
853        if (substr($message, -1) == $this->LE)
854            $message = substr($message, 0, -1);
855
856        $line = explode($this->LE, $message);
857        $message = "";
858        for ($i=0 ;$i < count($line); $i++)
859        {
860          $line_part = explode(" ", $line[$i]);
861          $buf = "";
862          for ($e = 0; $e<count($line_part); $e++)
863          {
864              $word = $line_part[$e];
865              if ($qp_mode and (strlen($word) > $length))
866              {
867                $space_left = $length - strlen($buf) - 1;
868                if ($e != 0)
869                {
870                    if ($space_left > 20)
871                    {
872                        $len = $space_left;
873                        if (substr($word, $len - 1, 1) == "=")
874                          $len--;
875                        elseif (substr($word, $len - 2, 1) == "=")
876                          $len -= 2;
877                        $part = substr($word, 0, $len);
878                        $word = substr($word, $len);
879                        $buf .= " " . $part;
880                        $message .= $buf . sprintf("=%s", $this->LE);
881                    }
882                    else
883                    {
884                        $message .= $buf . $soft_break;
885                    }
886                    $buf = "";
887                }
888                while (strlen($word) > 0)
889                {
890                    $len = $length;
891                    if (substr($word, $len - 1, 1) == "=")
892                        $len--;
893                    elseif (substr($word, $len - 2, 1) == "=")
894                        $len -= 2;
895                    $part = substr($word, 0, $len);
896                    $word = substr($word, $len);
897
898                    if (strlen($word) > 0)
899                        $message .= $part . sprintf("=%s", $this->LE);
900                    else
901                        $buf = $part;
902                }
903              }
904              else
905              {
906                $buf_o = $buf;
907                $buf .= ($e == 0) ? $word : (" " . $word);
908
909                if (strlen($buf) > $length and $buf_o != "")
910                {
911                    $message .= $buf_o . $soft_break;
912                    $buf = $word;
913                }
914              }
915          }
916          $message .= $buf . $this->LE;
917        }
918
919        return $message;
920    }
921   
922    /**
923     * Set the body wrapping.
924     * @access private
925     * @return void
926     */
927    function SetWordWrap() {
928        if($this->WordWrap < 1)
929            return;
930           
931        switch($this->message_type)
932        {
933           case "alt":
934              // fall through
935           case "alt_attachments":
936              $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
937              break;
938           default:
939              $this->Body = $this->WrapText($this->Body, $this->WordWrap);
940              break;
941        }
942    }
943
944    /**
945     * Assembles message header. 
946     * @access private
947     * @return string
948     */
949    function CreateHeader() {
950        $result = "";
951       
952        // Set the boundaries
953        $uniq_id = md5(uniqid(time()));
954        $this->boundary[1] = "b1_" . $uniq_id;
955        $this->boundary[2] = "b2_" . $uniq_id;
956
957        $result .= $this->HeaderLine("Date", $this->RFCDate());
958        if($this->Sender == "")
959            $result .= $this->HeaderLine("Return-Path", trim($this->From));
960        else
961            $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
962       
963        // To be created automatically by mail()
964        if($this->Mailer != "mail")
965        {
966            if(count($this->to) > 0)
967                $result .= $this->AddrAppend("To", $this->to);
968            else if ((count($this->cc) == 0) && (!$this->SaveMessageAsDraft))
969            {
970                $result .= $this->HeaderLine("To", $this->Lang('undisclosed-recipient'));
971            }
972            if(count($this->cc) > 0)
973                $result .= $this->AddrAppend("Cc", $this->cc);
974        }
975
976                if (!$this->SaveMessageAsDraft){
977                $from = array();
978            $from[0][0] = trim($this->From);
979                $from[0][1] = $this->FromName;
980                $result .= $this->AddrAppend("From", $from);
981                }
982                if($this->Sender) {
983                        $sender = array();
984                        $sender[0][0] = trim($this->Sender);
985                $sender[0][1] = $this->SenderName;
986                $result .= $this->AddrAppend("Sender", $sender);
987                }
988
989        // sendmail and mail() extract Bcc from the header before sending
990        if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
991            $result .= $this->AddrAppend("Bcc", $this->bcc);
992
993        if(count($this->ReplyTo) > 0)
994            $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
995
996        // mail() sets the subject itself
997        if($this->Mailer != "mail")
998            $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
999
1000        $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
1001        $result .= $this->HeaderLine("X-Priority", $this->Priority);
1002        $result .= $this->HeaderLine("Importance", $this->Importance);
1003        $result .= $this->HeaderLine("X-Mailer", "ExpressoMail [version " . $this->Version . "]");
1004       
1005        if($this->ConfirmReadingTo != "")
1006        {
1007            $result .= $this->HeaderLine("Disposition-Notification-To",
1008                       "<" . trim($this->ConfirmReadingTo) . ">");
1009        }
1010
1011        // Add custom headers
1012        for($index = 0; $index < count($this->CustomHeader); $index++)
1013        {
1014            $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
1015                       $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
1016        }
1017        $result .= $this->HeaderLine("MIME-Version", "1.0");
1018
1019        $result .= $this->write_message_type();
1020
1021        if($this->Mailer != "mail")
1022            $result .= $this->LE.$this->LE;
1023
1024        return $result;
1025    }
1026
1027
1028    function write_message_type()
1029        {
1030                $result = "";
1031        switch($this->message_type)
1032        {
1033            case "plain":
1034                $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
1035                $result .= sprintf("Content-Type: %s; charset=\"%s\"",
1036                                    $this->ContentType, $this->CharSet);
1037                return $result;
1038            case "attachments":
1039                // fall through
1040            case "alt_attachments":
1041                if($this->InlineImageExists())
1042                {
1043                    $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
1044                                    "multipart/related", $this->LE, $this->LE,
1045                                    $this->boundary[1], $this->LE);
1046                }
1047                else
1048                {
1049                    $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
1050                    $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
1051                }
1052                return $result;
1053            case "alt":
1054                $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
1055                $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
1056                return $result;
1057        }
1058
1059        if($this->Mailer != "mail")
1060            $result .= $this->LE.$this->LE;
1061
1062        return $result;
1063    }
1064
1065    /**
1066     * Assembles the message body.  Returns an empty string on failure.
1067     * @access private
1068     * @return string
1069     */
1070    function CreateBody() {
1071        $result = "";
1072
1073        $this->SetWordWrap();
1074        switch($this->message_type)
1075        {
1076            case "alt":
1077                $result .= $this->GetBoundary($this->boundary[1], "",
1078                                              "text/plain", "");
1079                $result .= $this->EncodeString($this->AltBody, $this->Encoding);
1080                $result .= $this->LE.$this->LE;
1081                $result .= $this->GetBoundary($this->boundary[1], "",
1082                                              "text/html", "");
1083               
1084                $result .= $this->EncodeString($this->Body, $this->Encoding);
1085                $result .= $this->LE.$this->LE;
1086   
1087                $result .= $this->EndBoundary($this->boundary[1]);
1088                break;
1089            case "plain":
1090                $result .= $this->EncodeString($this->Body, $this->Encoding);
1091                break;
1092            case "attachments":
1093                $result .= $this->GetBoundary($this->boundary[1], "", "", "");
1094                $result .= $this->EncodeString($this->Body, $this->Encoding);
1095                $result .= $this->LE;
1096     
1097                $result .= $this->AttachAll();
1098                break;
1099            case "alt_attachments":
1100                $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
1101                $result .= sprintf("Content-Type: %s;%s" .
1102                                   "\tboundary=\"%s\"%s",
1103                                   "multipart/alternative", $this->LE,
1104                                   $this->boundary[2], $this->LE.$this->LE);
1105   
1106                // Create text body
1107                $result .= $this->GetBoundary($this->boundary[2], "",
1108                                              "text/plain", "") . $this->LE;
1109
1110                $result .= $this->EncodeString($this->AltBody, $this->Encoding);
1111                $result .= $this->LE.$this->LE;
1112   
1113                // Create the HTML body
1114                $result .= $this->GetBoundary($this->boundary[2], "",
1115                                              "text/html", "") . $this->LE;
1116   
1117                $result .= $this->EncodeString($this->Body, $this->Encoding);
1118                $result .= $this->LE.$this->LE;
1119
1120                $result .= $this->EndBoundary($this->boundary[2]);
1121               
1122                $result .= $this->AttachAll();
1123                break;
1124        }
1125        if($this->IsError())
1126            $result = "";
1127
1128        return $result;
1129    }
1130
1131    /**
1132     * Returns the start of a message boundary.
1133     * @access private
1134     */
1135    function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1136        $result = "";
1137        if($charSet == "") { $charSet = $this->CharSet; }
1138        if($contentType == "") { $contentType = $this->ContentType; }
1139        if($encoding == "") { $encoding = $this->Encoding; }
1140
1141        $result .= $this->TextLine("--" . $boundary);
1142        $result .= sprintf("Content-Type: %s; charset = \"%s\"",
1143                            $contentType, $charSet);
1144        $result .= $this->LE;
1145        $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
1146        $result .= $this->LE;
1147       
1148        return $result;
1149    }
1150   
1151    /**
1152     * Returns the end of a message boundary.
1153     * @access private
1154     */
1155    function EndBoundary($boundary) {
1156        return $this->LE . "--" . $boundary . "--" . $this->LE;
1157    }
1158   
1159    /**
1160     * Sets the message type.
1161     * @access private
1162     * @return void
1163     */
1164    function SetMessageType() {
1165        if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
1166            $this->message_type = "plain";
1167        else
1168        {
1169            if(count($this->attachment) > 0)
1170                $this->message_type = "attachments";
1171            if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
1172                $this->message_type = "alt";
1173            if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
1174                $this->message_type = "alt_attachments";
1175        }
1176    }
1177
1178    /**
1179     * Returns a formatted header line.
1180     * @access private
1181     * @return string
1182     */
1183    function HeaderLine($name, $value) {
1184        return $name . ": " . $value . $this->LE;
1185    }
1186
1187    /**
1188     * Returns a formatted mail line.
1189     * @access private
1190     * @return string
1191     */
1192    function TextLine($value) {
1193        return $value . $this->LE;
1194    }
1195
1196    /////////////////////////////////////////////////
1197    // ATTACHMENT METHODS
1198    /////////////////////////////////////////////////
1199
1200    /**
1201     * Adds an attachment from a path on the filesystem.
1202     * Returns false if the file could not be found
1203     * or accessed.
1204     * @param string $path Path to the attachment.
1205     * @param string $name Overrides the attachment name.
1206     * @param string $encoding File encoding (see $Encoding).
1207     * @param string $type File extension (MIME) type.
1208     * @return bool
1209     */
1210    function AddAttachment($path, $name = "", $encoding = "base64",
1211                           $type = "application/octet-stream") {
1212        if(!@is_file($path))
1213        {
1214            $this->SetError($this->Lang("file_access") . $path);
1215            return false;
1216        }
1217
1218        $filename = basename($path);
1219        if($name == "")
1220            $name = $filename;
1221
1222        $cur = count($this->attachment);
1223        $this->attachment[$cur][0] = $path;
1224        $this->attachment[$cur][1] = $filename;
1225        $this->attachment[$cur][2] = $name;
1226        $this->attachment[$cur][3] = $encoding;
1227        $this->attachment[$cur][4] = $type;
1228        $this->attachment[$cur][5] = false; // isStringAttachment
1229        $this->attachment[$cur][6] = "attachment";
1230        $this->attachment[$cur][7] = 0;
1231
1232        return true;
1233    }
1234
1235    /**
1236     * Attaches all fs, string, and binary attachments to the message.
1237     * Returns an empty string on failure.
1238     * @access private
1239     * @return string
1240     */
1241    function AttachAll() {
1242        // Return text of body
1243        $mime = array();
1244
1245        // Add all attachments
1246        for($i = 0; $i < count($this->attachment); $i++)
1247        {
1248            // Check for string attachment
1249            $bString = $this->attachment[$i][5];
1250            if ($bString)
1251                $string = $this->attachment[$i][0];
1252            else
1253                $path = $this->attachment[$i][0];
1254
1255            $filename    = $this->attachment[$i][1];
1256            $name        = $this->attachment[$i][2];
1257            $encoding    = $this->attachment[$i][3];
1258            $type        = $this->attachment[$i][4];
1259            $disposition = $this->attachment[$i][6];
1260            $cid         = $this->attachment[$i][7];
1261           
1262            $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1263            $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
1264            $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1265
1266            if($disposition == "inline")
1267                $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1268
1269            $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
1270                              $disposition, $name, $this->LE.$this->LE);
1271
1272            // Encode as string attachment
1273            if($bString)
1274            {
1275                $mime[] = $this->EncodeString($string, $encoding);
1276                if($this->IsError()) { return ""; }
1277                $mime[] = $this->LE.$this->LE;
1278            }
1279            else
1280            {
1281                $mime[] = $this->EncodeFile($path, $encoding);               
1282                if($this->IsError()) { return ""; }
1283                $mime[] = $this->LE.$this->LE;
1284            }
1285        }
1286
1287        $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1288
1289        return join("", $mime);
1290    }
1291   
1292    /**
1293     * Encodes attachment in requested format.  Returns an
1294     * empty string on failure.
1295     * @access private
1296     * @return string
1297     */
1298    function EncodeFile ($path, $encoding = "base64") {
1299        if(!@$fd = fopen($path, "rb"))
1300        {
1301            $this->SetError($this->Lang("file_open") . $path);
1302            return "";
1303        }
1304        $magic_quotes = get_magic_quotes_runtime();
1305        set_magic_quotes_runtime(0);
1306        $file_buffer = fread($fd, filesize($path));
1307        $file_buffer = $this->EncodeString($file_buffer, $encoding);
1308        fclose($fd);
1309        set_magic_quotes_runtime($magic_quotes);
1310
1311        return $file_buffer;
1312    }
1313
1314    /**
1315     * Encodes string to requested format. Returns an
1316     * empty string on failure.
1317     * @access private
1318     * @return string
1319     */
1320    function EncodeString ($str, $encoding = "base64") {
1321        $encoded = "";
1322        switch(strtolower($encoding)) {
1323          case "base64":
1324              // chunk_split is found in PHP >= 3.0.6
1325              $encoded = @chunk_split(base64_encode($str), 76, $this->LE);
1326              break;
1327          case "7bit":
1328          case "8bit":
1329              $encoded = $this->FixEOL($str);
1330              if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1331                $encoded .= $this->LE;
1332              break;
1333          case "binary":
1334              $encoded = $str;
1335              break;
1336          case "quoted-printable":
1337              $encoded = $this->EncodeQP($str);
1338              break;
1339          default:
1340              $this->SetError($this->Lang("encoding") . $encoding);
1341              break;
1342        }
1343        return $encoded;
1344    }
1345
1346    /**
1347     * Encode a header string to best of Q, B, quoted or none. 
1348     * @access private
1349     * @return string
1350     */
1351    function EncodeHeader ($str, $position = 'text') {
1352      $x = 0;
1353     
1354      switch (strtolower($position)) {
1355        case 'phrase':
1356          if (!preg_match('/[\200-\377]/', $str)) {
1357            // Can't use addslashes as we don't know what value has magic_quotes_sybase.
1358            $encoded = addcslashes($str, "\0..\37\177\\\"");
1359
1360            if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
1361              return ($encoded);
1362            else
1363              return ("\"$encoded\"");
1364          }
1365          $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1366          break;
1367        case 'comment':
1368          $x = preg_match_all('/[()"]/', $str, $matches);
1369          // Fall-through
1370        case 'text':
1371        default:
1372          $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1373          break;
1374      }
1375
1376      if ($x == 0)
1377        return ($str);
1378
1379      $maxlen = 75 - 7 - strlen($this->CharSet);
1380      // Try to select the encoding which should produce the shortest output
1381      if (strlen($str)/3 < $x) {
1382        $encoding = 'B';
1383        $encoded = base64_encode($str);
1384        $maxlen -= $maxlen % 4;
1385        $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1386      } else {
1387        $encoding = 'Q';
1388        $encoded = $this->EncodeQ($str, $position);
1389        $encoded = $this->WrapText($encoded, $maxlen, true);
1390        $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
1391      }
1392
1393      $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1394      $encoded = trim(str_replace("\n", $this->LE, $encoded));
1395     
1396      return $encoded;
1397    }
1398   
1399    /**
1400     * Encode string to quoted-printable. 
1401     * @access private
1402     * @return string
1403     */
1404    function EncodeQP ($str) {
1405        $encoded = $this->FixEOL($str);
1406        if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1407            $encoded .= $this->LE;
1408
1409        // Replace every high ascii, control and = characters
1410        $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
1411                  "'='.sprintf('%02X', ord('\\1'))", $encoded);
1412        // Replace every spaces and tabs when it's the last character on a line
1413        $encoded = preg_replace("/([\011\040])".$this->LE."/e",
1414                  "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
1415
1416        // Maximum line length of 76 characters before CRLF (74 + space + '=')
1417        $encoded = $this->WrapText($encoded, 74, true);
1418               
1419        return $encoded;
1420    }
1421
1422    /**
1423     * Encode string to q encoding. 
1424     * @access private
1425     * @return string
1426     */
1427    function EncodeQ ($str, $position = "text") {
1428        // There should not be any EOL in the string
1429        $encoded = preg_replace("[\r\n]", "", $str);
1430        switch (strtolower($position)) {
1431          case "phrase":
1432            $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1433            break;
1434          case "comment":
1435            $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1436          case "text":
1437          default:
1438            // Replace every high ascii, control =, ? and _ characters
1439            $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1440                  "'='.sprintf('%02X', ord('\\1'))", $encoded);
1441            break;
1442        }
1443       
1444        // Replace every spaces to _ (more readable than =20)
1445        $encoded = str_replace(" ", "_", $encoded);
1446
1447        return $encoded;
1448    }
1449
1450    /**
1451     * Adds a string or binary attachment (non-filesystem) to the list.
1452     * This method can be used to attach ascii or binary data,
1453     * such as a BLOB record from a database.
1454     * @param string $string String attachment data.
1455     * @param string $filename Name of the attachment.
1456     * @param string $encoding File encoding (see $Encoding).
1457     * @param string $type File extension (MIME) type.
1458     * @return void
1459     */
1460    function AddStringAttachment($string, $filename, $encoding = "base64",
1461                                 $type = "application/octet-stream") {
1462        // Append to $attachment array
1463        $cur = count($this->attachment);
1464        $this->attachment[$cur][0] = $string;
1465        $this->attachment[$cur][1] = $filename;
1466        $this->attachment[$cur][2] = $filename;
1467        $this->attachment[$cur][3] = $encoding;
1468        $this->attachment[$cur][4] = $type;
1469        $this->attachment[$cur][5] = true; // isString
1470        $this->attachment[$cur][6] = "attachment";
1471        $this->attachment[$cur][7] = 0;
1472    }
1473   
1474    /**
1475     * Adds an embedded attachment.  This can include images, sounds, and
1476     * just about any other document.  Make sure to set the $type to an
1477     * image type.  For JPEG images use "image/jpeg" and for GIF images
1478     * use "image/gif".
1479     * @param string $path Path to the attachment.
1480     * @param string $cid Content ID of the attachment.  Use this to identify
1481     *        the Id for accessing the image in an HTML form.
1482     * @param string $name Overrides the attachment name.
1483     * @param string $encoding File encoding (see $Encoding).
1484     * @param string $type File extension (MIME) type. 
1485     * @return bool
1486     */
1487    function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
1488                              $type = "application/octet-stream") {
1489   
1490        if(!@is_file($path))
1491        {
1492            $this->SetError($this->Lang("file_access") . $path);
1493            return false;
1494        }
1495
1496        $filename = basename($path);
1497        if($name == "")
1498            $name = $filename;
1499
1500        // Append to $attachment array
1501        $cur = count($this->attachment);
1502        $this->attachment[$cur][0] = $path;
1503        $this->attachment[$cur][1] = $filename;
1504        $this->attachment[$cur][2] = $name;
1505        $this->attachment[$cur][3] = $encoding;
1506        $this->attachment[$cur][4] = $type;
1507        $this->attachment[$cur][5] = false; // isStringAttachment
1508        $this->attachment[$cur][6] = "inline";
1509        $this->attachment[$cur][7] = $cid;
1510   
1511        return true;
1512    }
1513   
1514    /**
1515     * Returns true if an inline attachment is present.
1516     * @access private
1517     * @return bool
1518     */
1519    function InlineImageExists() {
1520        $result = false;
1521        for($i = 0; $i < count($this->attachment); $i++)
1522        {
1523            if($this->attachment[$i][6] == "inline")
1524            {
1525                $result = true;
1526                break;
1527            }
1528        }
1529       
1530        return $result;
1531    }
1532
1533    /////////////////////////////////////////////////
1534    // MESSAGE RESET METHODS
1535    /////////////////////////////////////////////////
1536
1537    /**
1538     * Clears all recipients assigned in the TO array.  Returns void.
1539     * @return void
1540     */
1541    function ClearAddresses() {
1542        $this->to = array();
1543    }
1544
1545    /**
1546     * Clears all recipients assigned in the CC array.  Returns void.
1547     * @return void
1548     */
1549    function ClearCCs() {
1550        $this->cc = array();
1551    }
1552
1553    /**
1554     * Clears all recipients assigned in the BCC array.  Returns void.
1555     * @return void
1556     */
1557    function ClearBCCs() {
1558        $this->bcc = array();
1559    }
1560
1561    /**
1562     * Clears all recipients assigned in the ReplyTo array.  Returns void.
1563     * @return void
1564     */
1565    function ClearReplyTos() {
1566        $this->ReplyTo = array();
1567    }
1568
1569    /**
1570     * Clears all recipients assigned in the TO, CC and BCC
1571     * array.  Returns void.
1572     * @return void
1573     */
1574    function ClearAllRecipients() {
1575        $this->to = array();
1576        $this->cc = array();
1577        $this->bcc = array();
1578    }
1579
1580    /**
1581     * Clears all previously set filesystem, string, and binary
1582     * attachments.  Returns void.
1583     * @return void
1584     */
1585    function ClearAttachments() {
1586        $this->attachment = array();
1587    }
1588
1589    /**
1590     * Clears all custom headers.  Returns void.
1591     * @return void
1592     */
1593    function ClearCustomHeaders() {
1594        $this->CustomHeader = array();
1595    }
1596
1597
1598    /////////////////////////////////////////////////
1599    // MISCELLANEOUS METHODS
1600    /////////////////////////////////////////////////
1601
1602    /**
1603     * Adds the error message to the error container.
1604     * Returns void.
1605     * @access private
1606     * @return void
1607     */
1608    function SetError($msg) {
1609        $this->error_count++;
1610        $this->ErrorInfo = $msg;
1611    }
1612
1613    /**
1614     * Returns the proper RFC 822 formatted date.
1615     * @access private
1616     * @return string
1617     */
1618    function RFCDate() {
1619        $tz = date("Z");
1620        $tzs = ($tz < 0) ? "-" : "+";
1621        $tz = abs($tz);
1622        $tz = ($tz/3600)*100 + ($tz%3600)/60;
1623        $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
1624
1625        return $result;
1626    }
1627   
1628    /**
1629     * Returns the appropriate server variable.  Should work with both
1630     * PHP 4.1.0+ as well as older versions.  Returns an empty string
1631     * if nothing is found.
1632     * @access private
1633     * @return mixed
1634     */
1635    function ServerVar($varName) {
1636        global $HTTP_SERVER_VARS;
1637        global $HTTP_ENV_VARS;
1638
1639        if(!isset($_SERVER))
1640        {
1641            $_SERVER = $HTTP_SERVER_VARS;
1642            if(!isset($_SERVER["REMOTE_ADDR"]))
1643                $_SERVER = $HTTP_ENV_VARS; // must be Apache
1644        }
1645       
1646        if(isset($_SERVER[$varName]))
1647            return $_SERVER[$varName];
1648        else
1649            return "";
1650    }
1651
1652    /**
1653     * Returns the server hostname or 'localhost.localdomain' if unknown.
1654     * @access private
1655     * @return string
1656     */
1657    function ServerHostname() {
1658        if ($this->Hostname != "")
1659            $result = $this->Hostname;
1660        elseif ($this->ServerVar('SERVER_NAME') != "")
1661            $result = $this->ServerVar('SERVER_NAME');
1662        else
1663            $result = "localhost.localdomain";
1664
1665        return $result;
1666    }
1667
1668    /**
1669     * Returns a message in the appropriate language.
1670     * @access private
1671     * @return string
1672     */
1673    function Lang($key) {
1674        if(count($this->language) < 1)
1675            $this->SetLanguage("br"); // set the default language
1676   
1677        if(isset($this->language[$key]))
1678            return $this->language[$key];
1679        else
1680            return "Language string failed to load: " . $key;
1681    }
1682   
1683    /**
1684     * Returns true if an error occurred.
1685     * @return bool
1686     */
1687    function IsError() {
1688        return ($this->error_count > 0);
1689    }
1690
1691    /**
1692     * Changes every end of line from CR or LF to CRLF. 
1693     * @access private
1694     * @return string
1695     */
1696    function FixEOL($str) {
1697        $str = str_replace("\r\n", "\n", $str);
1698        $str = str_replace("\r", "\n", $str);
1699        $str = str_replace("\n", $this->LE, $str);
1700        return $str;
1701    }
1702
1703    /**
1704     * Adds a custom header.
1705     * @return void
1706     */
1707    function AddCustomHeader($custom_header) {
1708        $this->CustomHeader[] = explode(":", $custom_header, 2);
1709    }
1710}
1711
1712?>
Note: See TracBrowser for help on using the repository browser.