MediaWiki REL1_35
MailAddress.php
Go to the documentation of this file.
1<?php
38 public $name;
39
43 public $realName;
44
48 public $address;
49
57 public function __construct( $address, $name = null, $realName = null ) {
58 $this->address = strval( $address );
59 $this->name = strval( $name );
60 $this->realName = strval( $realName );
61 }
62
70 public static function newFromUser( User $user ) {
71 return new MailAddress( $user->getEmail(), $user->getName(), $user->getRealName() );
72 }
73
78 public function toString() {
79 if ( !$this->address ) {
80 return '';
81 }
82
83 # PHP's mail() implementation under Windows is somewhat shite, and
84 # can't handle "Joe Bloggs <joe@bloggs.com>" format email addresses,
85 # so don't bother generating them
86 if ( $this->name === '' || wfIsWindows() ) {
87 return $this->address;
88 }
89
91 $name = ( $wgEnotifUseRealName && $this->realName !== '' ) ? $this->realName : $this->name;
92 $quoted = UserMailer::quotedPrintable( $name );
93 // Must only be quoted if string does not use =? encoding (T191931)
94 if ( $quoted === $name ) {
95 $quoted = '"' . addslashes( $quoted ) . '"';
96 }
97
98 return "$quoted <{$this->address}>";
99 }
100
101 public function __toString() {
102 return $this->toString();
103 }
104}
$wgEnotifUseRealName
Use real name instead of username in e-mail "from" field.
wfIsWindows()
Check if the operating system is Windows.
Stores a single person's name and email address.
string $realName
toString()
Return formatted and quoted address to insert into SMTP headers.
__construct( $address, $name=null, $realName=null)
Stable to call.
string $address
static newFromUser(User $user)
Create a new MailAddress object for the given user.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:2150
getRealName()
Get the user's real name.
Definition User.php:2636
getEmail()
Get the user's e-mail address.
Definition User.php:2545