removing PHPMailer require, no more empty Bcc, and first version for send class using new egw_mailer

This commit is contained in:
Ralf Becker 2014-11-25 09:06:46 +00:00
parent b967548cb5
commit 4b999cc43a
2 changed files with 15 additions and 63 deletions

View File

@ -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);

View File

@ -1,6 +1,6 @@
<?php
/**
* eGroupWare API: Sending mail via egw_mailer
* EGroupware API: Sending mail via egw_mailer
*
* @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
@ -17,11 +17,6 @@
*/
class send extends egw_mailer
{
var $err = array();
var $to_res = array();
// switching on debug with a numeric value other than 0, switches debug in PHPMailer/SMTP Class on
var $debug = false;
/**
* eGW specific initialisation of the PHPMailer: charset, language, smtp-host, ...
*
@ -30,59 +25,11 @@ class send extends egw_mailer
*/
function send()
{
if ($this->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));
}
/**