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 }
wfIsWindows()
Check if the operating system is Windows.
Stores a single person's name and email address.
Definition: MailAddress.php:36
string $realName
Definition: MailAddress.php:45
static newFromUser(UserEmailContact $user)
Create a new MailAddress object for the given user.
Definition: MailAddress.php:72
string $name
Definition: MailAddress.php:40
toString()
Return formatted and quoted address to insert into SMTP headers.
Definition: MailAddress.php:80
__construct( $address, $name=null, $realName=null)
Definition: MailAddress.php:59
string $address
Definition: MailAddress.php:50
static quotedPrintable( $string, $charset='')
Converts a string into quoted-printable format.
Definition: UserMailer.php:521
$wgEnotifUseRealName
Config variable stub for the EnotifUseRealName setting, for use by phpdoc and IDEs.
getRealName()
Get user real name or an empty string if unknown.
getUser()
Get the identity of the user this contact belongs to.
getEmail()
Get user email address an empty string if unknown.