From 4b999cc43ad14cc3871dcb29d8e89b6bde555798 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 25 Nov 2014 09:06:46 +0000 Subject: [PATCH] removing PHPMailer require, no more empty Bcc, and first version for send class using new egw_mailer --- phpgwapi/inc/class.egw_mailer.inc.php | 21 ++++++---- phpgwapi/inc/class.send.inc.php | 57 +-------------------------- 2 files changed, 15 insertions(+), 63 deletions(-) diff --git a/phpgwapi/inc/class.egw_mailer.inc.php b/phpgwapi/inc/class.egw_mailer.inc.php index ced6c7c0b6..15758eb567 100644 --- a/phpgwapi/inc/class.egw_mailer.inc.php +++ b/phpgwapi/inc/class.egw_mailer.inc.php @@ -10,8 +10,6 @@ * @version $Id$ */ -require_once(EGW_API_INC.'/class.phpmailer.inc.php'); - /** * Log mails to log file specified in $GLOBALS['egw_info']['server']['log_mail'] * or regular error_log for true (can be set either in DB or header.inc.php). @@ -31,6 +29,7 @@ class egw_mailer extends Horde_Mime_Mail protected $account; /** + * Header / recipients set via Add(Address|Cc|Bcc|Replyto) * * @var Horde_Mail_Rfc822_List */ @@ -140,12 +139,19 @@ class egw_mailer extends Horde_Mime_Mail /** * Write Bcc as header for storing in sent or as draft * - * Bcc is normally only add to recipients while sending, but not added visible as header! + * Bcc is normally only add to recipients while sending, but not added visible as header. + * + * This function is should only be called AFTER calling send, or when NOT calling send at all! */ function forceBccHeader() { $this->_headers->removeHeader('Bcc'); - $this->_headers->addHeader('Bcc', $this->bcc); + + // only add Bcc header, if we have bcc's + if (count($this->bcc)) + { + $this->_headers->addHeader('Bcc', $this->bcc); + } } /** @@ -226,16 +232,12 @@ class egw_mailer extends Horde_Mime_Mail // pass file as resource to Horde_Mime_Part::setContent() if (!($resource = fopen($file, 'r'))) - //if (!($resource = file_get_contents($file))) { throw new egw_exception_not_found("File '$file' not found!"); } $part = new Horde_Mime_Part(); $part->setType($type ? $type : egw_vfs::mime_content_type($file)); $part->setContents($resource); - // this should not be necessary, because binary data get detected by mime-type, - // but at least Cyrus complains about NUL characters - $part->setTransferEncoding('base64', array('send' => true)); $part->setName($name ? $name : egw_vfs::basename($file)); // store "text/calendar" as _htmlBody, to trigger "multipart/alternative" @@ -244,6 +246,9 @@ class egw_mailer extends Horde_Mime_Mail $this->_htmlBody = $part; return; } + // this should not be necessary, because binary data get detected by mime-type, + // but at least Cyrus complains about NUL characters + $part->setTransferEncoding('base64', array('send' => true)); $part->setDisposition('attachment'); return $this->addMimePart($part); diff --git a/phpgwapi/inc/class.send.inc.php b/phpgwapi/inc/class.send.inc.php index 7e3a912a14..b3e8a8776e 100644 --- a/phpgwapi/inc/class.send.inc.php +++ b/phpgwapi/inc/class.send.inc.php @@ -1,6 +1,6 @@ debug && is_numeric($this->debug)) $this->SMTPDebug = $this->debug; if ($this->Subject || $this->Body || count($this->to)) { - if ($this->debug) error_log(__METHOD__." ".print_r($this->Subject,true)." to be send"); - return PHPMailer::Send(); + return parent::send(); } parent::__construct(); // calling parent constructor - - $this->CharSet = translation::charset(); - $this->IsSmtp(); - - // smtp settings from default account of current user - $account = emailadmin_account::read(emailadmin_account::get_default_acc_id(true)); // true=SMTP - $this->Host = $account->acc_smtp_host; - $this->Port = $account->acc_smtp_port; - switch($account->acc_smtp_ssl) - { - case emailadmin_account::SSL_TLS: // requires modified PHPMailer, or comment next two lines to use just ssl! - $this->Host = 'tlsv1://'.$this->Host; - break; - case emailadmin_account::SSL_SSL: - $this->Host = 'ssl://'.$this->Host; - break; - case emailadmin_account::SSL_STARTTLS: // PHPMailer uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3 - $this->Host = 'tls://'.$this->Host; - } - $this->SMTPAuth = !empty($account->acc_smtp_username); - $this->Username = $account->acc_smtp_username; - $this->Password = $account->acc_smtp_password; - $this->defaultDomain = $account->acc_domain; - // we do not want to use the phpmailer defaults, as it is bound to fail anyway - // !from should be connected to the account used! - $this->From = ''; - $this->FromName = ''; - // use smpt-username as sender, if available, but only if it is a full email address - // we use setFrom as of from now on as it sets From, FromName and Sender - // error_log(__METHOD__.__LINE__.array2string($account)); - $Sender = $account->acc_smtp_username && strpos($account->acc_smtp_username, '@') !== false ? - $account->acc_smtp_username : $account->ident_email; - /*emailadmin_account Object has some possible info on the accounts realname - [acc_name] => example given (mail@domain.suffix) - [ident_realname] => example given - [ident_email] => mail@domain.suffix (maybe this is the content of $Sender !) - [ident_org] => not considered - [ident_name] => example - */ - $Name = ($account['ident_realname']?$account['ident_realname']:($account['ident_name']?$account['ident_name']: - ($account['acc_name']?$account['acc_name']:$Sender))); - //error_log(__METHOD__.__LINE__.$Sender.','.$Name); - $this->setFrom($Sender,$Name); - $this->Hostname = $GLOBALS['egw_info']['server']['hostname']; - - if ($this->debug) error_log(__METHOD__."() initialised egw_mailer with ".array2string($this)." from mail default account ".array2string($account->params)); } /**