MediaWiki  master
MailAddress.php
Go to the documentation of this file.
1 <?php
34 class MailAddress {
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 
90  global $wgEnotifUseRealName;
91  $name = ( $wgEnotifUseRealName && $this->realName !== '' ) ? $this->realName : $this->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 }
MailAddress\$name
string $name
Definition: MailAddress.php:38
UserMailer\quotedPrintable
static quotedPrintable( $string, $charset='')
Converts a string into quoted-printable format.
Definition: UserMailer.php:510
MailAddress\$realName
string $realName
Definition: MailAddress.php:43
MailAddress\toString
toString()
Return formatted and quoted address to insert into SMTP headers.
Definition: MailAddress.php:78
MailAddress\newFromUser
static newFromUser(User $user)
Create a new MailAddress object for the given user.
Definition: MailAddress.php:70
MailAddress
Stores a single person's name and email address.
Definition: MailAddress.php:34
User\getEmail
getEmail()
Get the user's e-mail address.
Definition: User.php:2482
$wgEnotifUseRealName
$wgEnotifUseRealName
Use real name instead of username in e-mail "from" field.
Definition: DefaultSettings.php:1975
MailAddress\__construct
__construct( $address, $name=null, $realName=null)
Stable to call.
Definition: MailAddress.php:57
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition: GlobalFunctions.php:1846
User\getRealName
getRealName()
Get the user's real name.
Definition: User.php:2573
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:56
MailAddress\$address
string $address
Definition: MailAddress.php:48
User\getName
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2054
MailAddress\__toString
__toString()
Definition: MailAddress.php:101