MediaWiki  master
MailAddress.php
Go to the documentation of this file.
1 <?php
28 
36 class MailAddress {
40  public $name;
41 
45  public $realName;
46 
50  public $address;
51 
59  public function __construct( $address, $name = null, $realName = null ) {
60  $this->address = strval( $address );
61  $this->name = strval( $name );
62  $this->realName = strval( $realName );
63  }
64 
72  public static function newFromUser( UserEmailContact $user ) {
73  return new MailAddress( $user->getEmail(), $user->getUser()->getName(), $user->getRealName() );
74  }
75 
80  public function toString() {
81  if ( !$this->address ) {
82  return '';
83  }
84 
85  # PHP's mail() implementation under Windows is somewhat shite, and
86  # can't handle "Joe Bloggs <joe@bloggs.com>" format email addresses,
87  # so don't bother generating them
88  if ( $this->name === '' || wfIsWindows() ) {
89  return $this->address;
90  }
91 
92  global $wgEnotifUseRealName;
93  $name = ( $wgEnotifUseRealName && $this->realName !== '' ) ? $this->realName : $this->name;
95  // Must only be quoted if string does not use =? encoding (T191931)
96  if ( $quoted === $name ) {
97  $quoted = '"' . addslashes( $quoted ) . '"';
98  }
99 
100  return "$quoted <{$this->address}>";
101  }
102 
103  public function __toString() {
104  return $this->toString();
105  }
106 }
MailAddress\$name
string $name
Definition: MailAddress.php:40
UserMailer\quotedPrintable
static quotedPrintable( $string, $charset='')
Converts a string into quoted-printable format.
Definition: UserMailer.php:510
MailAddress\$realName
string $realName
Definition: MailAddress.php:45
MailAddress\toString
toString()
Return formatted and quoted address to insert into SMTP headers.
Definition: MailAddress.php:80
MailAddress
Stores a single person's name and email address.
Definition: MailAddress.php:36
$wgEnotifUseRealName
$wgEnotifUseRealName
Use real name instead of username in e-mail "from" field.
Definition: DefaultSettings.php:2038
MediaWiki\Mail\UserEmailContact\getUser
getUser()
Get the identity of the user this contact belongs to.
MailAddress\newFromUser
static newFromUser(UserEmailContact $user)
Create a new MailAddress object for the given user.
Definition: MailAddress.php:72
MediaWiki\Mail\UserEmailContact\getRealName
getRealName()
Get user real name or an empty string if unknown.
MailAddress\__construct
__construct( $address, $name=null, $realName=null)
Definition: MailAddress.php:59
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition: GlobalFunctions.php:1695
MediaWiki\Mail\UserEmailContact
Definition: UserEmailContact.php:11
MailAddress\$address
string $address
Definition: MailAddress.php:50
MediaWiki\Mail\UserEmailContact\getEmail
getEmail()
Get user email address an empty string if unknown.
MailAddress\__toString
__toString()
Definition: MailAddress.php:103