MediaWiki  1.34.0
UserMailer Class Reference

Collection of static functions for sending mail. More...

Static Public Member Functions

static quotedPrintable ( $string, $charset='')
 Converts a string into quoted-printable format. More...
 
static rfc822Phrase ( $phrase)
 Converts a string into a valid RFC 822 "phrase", such as is used for the sender name. More...
 
static sanitizeHeaderValue ( $val)
 Strips bad characters from a header value to prevent PHP mail header injection attacks. More...
 
static send ( $to, $from, $subject, $body, $options=[])
 This function will perform a direct (authenticated) login to a SMTP Server to use for mail relaying if 'wgSMTP' specifies an array of parameters. More...
 

Static Protected Member Functions

static sendInternal (array $to, MailAddress $from, $subject, $body, $options=[])
 Helper function fo UserMailer::send() which does the actual sending. More...
 
static sendWithPear ( $mailer, $dest, $headers, $body)
 Send mail using a PEAR mailer. More...
 

Static Private Member Functions

static arrayToHeaderString ( $headers, $endl=PHP_EOL)
 Creates a single string from an associative array. More...
 
static errorHandler ( $code, $string)
 Set the mail error message in self::$mErrorString. More...
 
static isMailMimeUsable ()
 Whether the PEAR Mail_mime library is usable. More...
 
static isMailUsable ()
 Whether the PEAR Mail library is usable. More...
 
static makeMsgId ()
 Create a value suitable for the MessageId Header. More...
 

Static Private Attributes

static $mErrorString
 

Detailed Description

Collection of static functions for sending mail.

Definition at line 30 of file UserMailer.php.

Member Function Documentation

◆ arrayToHeaderString()

static UserMailer::arrayToHeaderString (   $headers,
  $endl = PHP_EOL 
)
staticprivate

Creates a single string from an associative array.

Parameters
array$headersAssociative Array: keys are header field names, values are ... values.
string$endlThe end of line character. Defaults to "\\n"

Note RFC2822 says newlines must be CRLF (\r\n) but php mail naively "corrects" it and requires \n for the "correction" to work

Returns
string

Definition at line 67 of file UserMailer.php.

References sanitizeHeaderValue().

Referenced by sendInternal().

◆ errorHandler()

static UserMailer::errorHandler (   $code,
  $string 
)
staticprivate

Set the mail error message in self::$mErrorString.

Parameters
int$codeError number
string$stringError message

Definition at line 471 of file UserMailer.php.

◆ isMailMimeUsable()

static UserMailer::isMailMimeUsable ( )
staticprivate

Whether the PEAR Mail_mime library is usable.

This will try and load it if it is not already.

Returns
bool

Definition at line 199 of file UserMailer.php.

◆ isMailUsable()

static UserMailer::isMailUsable ( )
staticprivate

Whether the PEAR Mail library is usable.

This will try and load it if it is not already.

Returns
bool

Definition at line 213 of file UserMailer.php.

◆ makeMsgId()

static UserMailer::makeMsgId ( )
staticprivate

Create a value suitable for the MessageId Header.

Returns
string

Definition at line 82 of file UserMailer.php.

References $wgServer, $wgSMTP, WikiMap\getCurrentWikiDbDomain(), and wfParseUrl().

Referenced by sendInternal().

◆ quotedPrintable()

static UserMailer::quotedPrintable (   $string,
  $charset = '' 
)
static

Converts a string into quoted-printable format.

Since
1.17

From PHP5.3 there is a built in function quoted_printable_encode() This method does not duplicate that. This method is doing Q encoding inside encoded-words as defined by RFC 2047 This is for email headers. The built in quoted_printable_encode() is for email bodies

Parameters
string$string
string$charset
Returns
string

Definition at line 510 of file UserMailer.php.

References $matches.

Referenced by sendInternal(), and MailAddress\toString().

◆ rfc822Phrase()

static UserMailer::rfc822Phrase (   $phrase)
static

Converts a string into a valid RFC 822 "phrase", such as is used for the sender name.

Parameters
string$phrase
Returns
string

Definition at line 489 of file UserMailer.php.

References sanitizeHeaderValue().

◆ sanitizeHeaderValue()

static UserMailer::sanitizeHeaderValue (   $val)
static

Strips bad characters from a header value to prevent PHP mail header injection attacks.

Parameters
string$valString to be santizied
Returns
string

Definition at line 480 of file UserMailer.php.

Referenced by arrayToHeaderString(), and rfc822Phrase().

◆ send()

static UserMailer::send (   $to,
  $from,
  $subject,
  $body,
  $options = [] 
)
static

This function will perform a direct (authenticated) login to a SMTP Server to use for mail relaying if 'wgSMTP' specifies an array of parameters.

It requires PEAR:Mail to do that. Otherwise it just uses the standard PHP 'mail' function.

Parameters
MailAddress | MailAddress[]$toRecipient's email (or an array of them)
MailAddress$fromSender's email
string$subjectEmail's subject.
string | string[]$bodyEmail's text or Array of two strings to be the text and html bodies
array$optionsKeys: 'replyTo' MailAddress 'contentType' string default 'text/plain; charset=UTF-8' 'headers' array Extra headers to set
Exceptions
MWException
Exception
Returns
Status

Definition at line 115 of file UserMailer.php.

References $status, $wgAllowHTMLEmail, StatusValue\newFatal(), StatusValue\newGood(), Hooks\run(), sendInternal(), and wfDebug().

Referenced by EmaillingJob\run(), EmailNotification\sendImpersonal(), User\sendMail(), EmailNotification\sendPersonalised(), and SpecialEmailUser\submit().

◆ sendInternal()

static UserMailer::sendInternal ( array  $to,
MailAddress  $from,
  $subject,
  $body,
  $options = [] 
)
staticprotected

Helper function fo UserMailer::send() which does the actual sending.

It expects a $to list which the UserMailerSplitTo hook would not split further.

Parameters
MailAddress[]$toArray of recipients' email addresses
MailAddress$fromSender's email
string$subjectEmail's subject.
string | string[]$bodyEmail's text or Array of two strings to be the text and html bodies
array$optionsKeys: 'replyTo' MailAddress 'contentType' string default 'text/plain; charset=UTF-8' 'headers' array Extra headers to set
Exceptions
MWException
Exception
Returns
Status

Definition at line 238 of file UserMailer.php.

References $status, $wgAdditionalMailParams, $wgEnotifMaxRecips, $wgSMTP, arrayToHeaderString(), MWTimestamp\getLocalInstance(), SpecialPage\getTitleFor(), makeMsgId(), StatusValue\newFatal(), StatusValue\newGood(), PROTO_CANONICAL, quotedPrintable(), Hooks\run(), sendWithPear(), MailAddress\toString(), wfDebug(), and wfIsWindows().

Referenced by send().

◆ sendWithPear()

static UserMailer::sendWithPear (   $mailer,
  $dest,
  $headers,
  $body 
)
staticprotected

Send mail using a PEAR mailer.

Parameters
Mail_smtp$mailer
string[] | string$dest
array$headers
string$body
Returns
Status

Definition at line 43 of file UserMailer.php.

References StatusValue\newFatal(), StatusValue\newGood(), and wfDebug().

Referenced by sendInternal().

Member Data Documentation

◆ $mErrorString

UserMailer::$mErrorString
staticprivate

Definition at line 31 of file UserMailer.php.


The documentation for this class was generated from the following file: