return;
}
- $address = $nu->getEmail();
- $f = new EmailUserForm( $nu->getName() . " <{$address}>", $target );
+ $f = new EmailUserForm( $nu );
if ( "success" == $action ) {
$f->showSuccess();
*/
class EmailUserForm {
- var $mAddress;
var $target;
var $text, $subject;
- function EmailUserForm( $addr, $target ) {
+ /**
+ * @param User $target
+ */
+ function EmailUserForm( $target ) {
global $wgRequest;
- $this->mAddress = $addr;
$this->target = $target;
$this->text = $wgRequest->getText( 'wpText' );
$this->subject = $wgRequest->getText( 'wpSubject' );
$emf = wfMsg( "emailfrom" );
$sender = $wgUser->getName();
$emt = wfMsg( "emailto" );
- $rcpt = str_replace( "_", " ", $this->target );
+ $rcpt = $this->target->getName();
$emr = wfMsg( "emailsubject" );
$emm = wfMsg( "emailmessage" );
$ems = wfMsg( "emailsend" );
$titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
$action = $titleObj->escapeLocalURL( "target=" .
- urlencode( $this->target ) . "&action=submit" );
+ urlencode( $this->target->getName() ) . "&action=submit" );
$token = $wgUser->editToken();
$wgOut->addHTML( "
function doSubmit() {
global $wgOut, $wgUser;
- $from = wfQuotedPrintable( $wgUser->getName() ) . " <" . $wgUser->getEmail() . ">";
- $subject = wfQuotedPrintable( $this->subject );
+ $to = new MailAddress( $this->target );
+ $from = new MailAddress( $wgUser );
+ $subject = $this->subject;
- if (wfRunHooks('EmailUser', array(&$this->mAddress, &$from, &$subject, &$this->text))) {
+ if( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$this->text ) ) ) {
- $mailResult = userMailer( $this->mAddress, $from, $subject, $this->text );
+ $mailResult = userMailer( $to, $from, $subject, $this->text );
if( WikiError::isError( $mailResult ) ) {
$wgOut->addHTML( wfMsg( "usermailererror" ) . $mailResult);
} else {
$titleObj = Title::makeTitle( NS_SPECIAL, "Emailuser" );
- $encTarget = wfUrlencode( $this->target );
+ $encTarget = wfUrlencode( $this->target->getName() );
$wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) );
- wfRunHooks('EmailUserComplete', array($this->mAddress, $from, $subject, $this->text));
+ wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $this->text ) );
}
}
}
return '"' . $phrase . '"';
}
+class MailAddress {
+ /**
+ * @param mixed $address String with an email address, or a User object
+ * @param string $name Human-readable name if a string address is given
+ */
+ function MailAddress( $address, $name=null ) {
+ if( is_object( $address ) && is_a( $address, 'User' ) ) {
+ $this->address = $address->getEmail();
+ $this->name = $address->getName();
+ } else {
+ $this->address = strval( $address );
+ $this->name = strval( $name );
+ }
+ }
+
+ /**
+ * Return formatted and quoted address to insert into SMTP headers
+ * @return string
+ */
+ function toString() {
+ if( $this->name != '' ) {
+ return wfQuotedPrintable( $this->name ) . " <" . $this->address . ">";
+ } else {
+ return $this->address;
+ }
+ }
+}
+
/**
* This function will perform a direct (authenticated) login to
* a SMTP Server to use for mail relaying if 'wgSMTP' specifies an
* array of parameters. It requires PEAR:Mail to do that.
* Otherwise it just uses the standard PHP 'mail' function.
*
- * @param string $to recipient's email
- * @param string $from sender's email
+ * @param MailAddress $to recipient's email
+ * @param MailAddress $from sender's email
* @param string $subject email's subject
* @param string $body email's text
* @param string $replyto optional reply-to email (default : false)
require_once( 'Mail.php' );
$timestamp = time();
-
- $headers['From'] = $from;
- $headers['To'] = $to;
+ $dest = $to->toString();
+
+ $headers['From'] = $from->toString();
+ $headers['To'] = $dest;
if ( $replyto ) {
$headers['Reply-To'] = $replyto;
}
- $headers['Subject'] = $subject;
+ $headers['Subject'] = wfQuotedPrintable( $subject );
$headers['Date'] = date( 'r' );
$headers['MIME-Version'] = '1.0';
$headers['Content-type'] = 'text/plain; charset='.$wgOutputEncoding;
$headers['Content-transfer-encoding'] = '8bit';
- $headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>';
+ $headers['Message-ID'] = "<{$timestamp}" . $wgUser->getName() . '@' . $wgSMTP['IDHost'] . '>'; // FIXME
$headers['X-Mailer'] = 'MediaWiki mailer';
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('smtp', $wgSMTP);
- wfDebug( "Sending mail via PEAR::Mail to $to\n" );
- $mailResult =& $mail_object->send($to, $headers, $body);
+ wfDebug( "Sending mail via PEAR::Mail to $dest" );
+ $mailResult =& $mail_object->send($dest, $headers, $body);
# Based on the result return an error string,
if ($mailResult === true) {
"Content-type: text/plain; charset={$wgOutputEncoding}\n" .
"Content-Transfer-Encoding: 8bit\n" .
"X-Mailer: MediaWiki mailer\n".
- 'From: ' . $from . "\n";
+ 'From: ' . $from->toString() . "\n";
if ($replyto) {
$headers .= "Reply-To: $replyto\n";
}
+ $dest = $to->toString();
+
$wgErrorString = '';
set_error_handler( 'mailErrorHandler' );
- wfDebug( "Sending mail via internal mail() function to $to\n" );
- mail( $to, $subject, $body, $headers );
+ wfDebug( "Sending mail via internal mail() function to $dest\n" );
+ mail( $dest, wfQuotedPrintable( $subject ), $body, $headers );
restore_error_handler();
if ( $wgErrorString ) {
# the user has not opted-out and the option is enabled at the
# global configuration level.
$name = $wgUser->getName();
- $adminAddress = 'WikiAdmin <' . $wgEmergencyContact . '>';
- $editorAddress = wfRFC822Phrase( $name ) . ' <' . $wgUser->getEmail() . '>';
+ $adminAddress = new MailAddress( $wgEmergencyContact, 'WikiAdmin' );
+ $editorAddress = new MailAddress( $wgUser );
if( $wgEnotifRevealEditorAddress
&& ( $wgUser->getEmail() != '' )
&& $wgUser->getOption( 'enotifrevealaddr' ) ) {
// From the PHP manual:
// Note: The to parameter cannot be an address in the form of "Something <someone@example.com>".
// The mail command will not parse this properly while talking with the MTA.
- $to = $watchingUser->getEmail();
+ $to = new MailAddress( $watchingUser );
$body = str_replace( '$WATCHINGUSERNAME', $watchingUser->getName() , $this->body );
$timecorrection = $watchingUser->getOption( 'timecorrection' );