MediaWiki REL1_39
MailAddress.php
Go to the documentation of this file.
1<?php
28
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
93 $name = ( $wgEnotifUseRealName && $this->realName !== '' ) ? $this->realName : $this->name;
94 $quoted = UserMailer::quotedPrintable( $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.
string $realName
static newFromUser(UserEmailContact $user)
Create a new MailAddress object for the given user.
toString()
Return formatted and quoted address to insert into SMTP headers.
__construct( $address, $name=null, $realName=null)
string $address
$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.