Merged from trunk

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75660 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2009-04-29 11:52:40 +00:00 committed by Sam Minnee
parent fe87ef75d4
commit 30589491be
2 changed files with 102 additions and 82 deletions

View File

@ -89,7 +89,7 @@ class Email extends ViewableData {
/**
* @param array $customHeaders A map of header-name -> header-value
*/
protected $customHeaders;
protected $customHeaders = array();
/**
* @param array $attachements Internal, use {@link attachFileFromString()} or {@link attachFile()}
@ -160,11 +160,12 @@ class Email extends ViewableData {
}
public function setBounceHandlerURL( $bounceHandlerURL ) {
if( $bounceHandlerURL )
if($bounceHandlerURL) {
$this->bounceHandlerURL = $bounceHandlerURL;
else
} else {
$this->bounceHandlerURL = $_SERVER['HTTP_HOST'] . Director::baseURL() . 'Email_BounceHandler';
}
}
public function attachFile($filename, $attachedFilename = null, $mimetype = null) {
$absoluteFileName = Director::getAbsFile($filename);
@ -230,6 +231,14 @@ class Email extends ViewableData {
$this->bcc = $val;
}
/**
* Set the "Reply-To" header with an email address.
* @param string $email The email address of the "Reply-To" header
*/
public function replyTo($email) {
$this->addCustomHeader('Reply-To', $email);
}
/**
* Add a custom header to this value.
* Useful for implementing all those cool features that we didn't think of.
@ -360,11 +369,16 @@ class Email extends ViewableData {
}
/**
* @desc Send the email in plaintext
* Send the email in plaintext.
*
* @see send() for sending emails with HTML content.
* @uses Mailer->sendPlain()
*
* @param string $messageID Optional message ID so the message can be identified in bounces etc.
* @return bool Success of the sending operation from an MTA perspective.
* Doesn't actually give any indication if the mail has been delivered to the recipient properly)
*/
function sendPlain($messageID = null) {
global $project;
Requirements::clear();
$this->parseVariables(true);
@ -373,11 +387,13 @@ class Email extends ViewableData {
$this->setBounceHandlerURL($this->bounceHandlerURL);
$headers = $this->customHeaders;
$headers['X-SilverStripeBounceURL'] = $this->bounceHandlerURL;
if($messageID) $headers['X-SilverStripeMessageID'] = $project . '.' . $messageID;
if($messageID) $headers['X-SilverStripeMessageID'] = project() . '.' . $messageID;
if($project) $headers['X-SilverStripeSite'] = $project;
if(project()) $headers['X-SilverStripeSite'] = project();
$to = $this->to;
$subject = $this->subject;
@ -388,17 +404,24 @@ class Email extends ViewableData {
if($this->bcc) $subject .= ", bcc to $this->bcc";
$subject .= ']';
} else {
if($this->cc) $headers["Cc"] = $this->cc;
if($this->bcc) $headers["Bcc"] = $this->bcc;
if($this->cc) $headers['Cc'] = $this->cc;
if($this->bcc) $headers['Bcc'] = $this->bcc;
}
if(self::$cc_all_emails_to) {
if(trim($headers['Cc'])) $headers['Cc'] .= ', ';
$headers['Cc'] .= self::$cc_all_emails_to;
if(!empty($headers['Cc']) && trim($headers['Cc'])) {
$headers['Cc'] .= ', ' . self::$cc_all_emails_to;
} else {
$headers['Cc'] = self::$cc_all_emails_to;
}
}
if(self::$bcc_all_emails_to) {
if(trim($headers['Bcc'])) $headers['Bcc'] .= ', ';
$headers['Bcc'] .= self::$bcc_all_emails_to;
if(!empty($headers['Bcc']) && trim($headers['Bcc'])) {
$headers['Bcc'] .= ', ' . self::$bcc_all_emails_to;
} else {
$headers['Bcc'] = self::$bcc_all_emails_to;
}
}
Requirements::restore();
@ -414,9 +437,7 @@ class Email extends ViewableData {
$this->parseVariables();
if( empty( $this->from ) ){
$this->from = Email::getAdminEmail();
}
if(empty($this->from)) $this->from = Email::getAdminEmail();
$this->setBounceHandlerURL( $this->bounceHandlerURL );
@ -439,8 +460,8 @@ class Email extends ViewableData {
unset($headers['Cc']);
unset($headers['Bcc']);
} else {
if($this->cc) $headers["Cc"] = $this->cc;
if($this->bcc) $headers["Bcc"] = $this->bcc;
if($this->cc) $headers['Cc'] = $this->cc;
if($this->bcc) $headers['Bcc'] = $this->bcc;
}
if(self::$cc_all_emails_to) {
@ -520,7 +541,6 @@ class Email extends ViewableData {
self::$bcc_all_emails_to = $emailAddress;
}
/**
* Checks for RFC822-valid email format.
*

View File

@ -297,7 +297,7 @@ class Permission extends DataObject {
if(is_numeric($arg)) {
$perm->Arg = $arg;
} else {
use_error("Permission::checkMember: bad arg '$arg'",
user_error("Permission::checkMember: bad arg '$arg'",
E_USER_ERROR);
}
}
@ -331,7 +331,7 @@ class Permission extends DataObject {
if(is_numeric($arg)) {
$perm->Arg = $arg;
} else {
use_error("Permission::checkMember: bad arg '$arg'",
user_error("Permission::checkMember: bad arg '$arg'",
E_USER_ERROR);
}
}