MediaWiki  REL1_24
MailAddress.php
Go to the documentation of this file.
00001 <?php
00032 class MailAddress {
00038     function __construct( $address, $name = null, $realName = null ) {
00039         if ( is_object( $address ) && $address instanceof User ) {
00040             // Old calling format, now deprecated
00041             wfDeprecated( __METHOD__ . ' with a User object' , '1.24' );
00042             $this->address = $address->getEmail();
00043             $this->name = $address->getName();
00044             $this->realName = $address->getRealName();
00045         } else {
00046             $this->address = strval( $address );
00047             $this->name = strval( $name );
00048             $this->realName = strval( $realName );
00049         }
00050     }
00051 
00059     public static function newFromUser( User $user ) {
00060         return new MailAddress( $user->getEmail(), $user->getName(), $user->getRealName() );
00061     }
00062 
00067     function toString() {
00068         # PHP's mail() implementation under Windows is somewhat shite, and
00069         # can't handle "Joe Bloggs <[email protected]>" format email addresses,
00070         # so don't bother generating them
00071         if ( $this->address ) {
00072             if ( $this->name != '' && !wfIsWindows() ) {
00073                 global $wgEnotifUseRealName;
00074                 $name = ( $wgEnotifUseRealName && $this->realName !== '' ) ? $this->realName : $this->name;
00075                 $quoted = UserMailer::quotedPrintable( $name );
00076                 if ( strpos( $quoted, '.' ) !== false || strpos( $quoted, ',' ) !== false ) {
00077                     $quoted = '"' . $quoted . '"';
00078                 }
00079                 return "$quoted <{$this->address}>";
00080             } else {
00081                 return $this->address;
00082             }
00083         } else {
00084             return "";
00085         }
00086     }
00087 
00088     function __toString() {
00089         return $this->toString();
00090     }
00091 }