Oihana PHP Enums

MailPriority uses ConstantsTrait

Canonical message-priority levels, with conversions to the three competing header conventions used in the wild.

A message "priority" is expressed three different ways depending on the header; this enum keeps a single canonical vocabulary (high / normal / low) and maps it onto each:

Level X-Priority Importance Priority (RFC 2156)
high 1 high urgent
normal 3 normal normal
low 5 low non-urgent
MailPriority::toXPriority( MailPriority::HIGH ) ; // 1
MailPriority::toPriority ( 'urgent' ) ;           // 'urgent'  (normalised)
MailPriority::fromXPriority( 2 ) ;                // 'high'
Tags
author

Marc Alcaraz

since
1.2.0
see
MailHeader::X_PRIORITY
MailHeader::IMPORTANCE
MailHeader::PRIORITY

Table of Contents

Constants

HIGH  : string = 'high'
Highest priority — `X-Priority: 1`, `Importance: high`, `Priority: urgent`.
LOW  : string = 'low'
Lowest priority — `X-Priority: 5`, `Importance: low`, `Priority: non-urgent`.
NORMAL  : string = 'normal'
Default priority — `X-Priority: 3`, `Importance: normal`, `Priority: normal`.

Methods

fromXPriority()  : string
Maps a numeric `X-Priority` value onto a canonical level (`1`–`2` → high, `3` → normal, `4`–`5` → low).
normalize()  : string
Folds any known spelling onto a canonical level.
toImportance()  : string
Maps a level onto the `Importance` header value (`high` / `normal` / `low`).
toPriority()  : string
Maps a level onto the RFC 2156 `Priority` header value (`urgent` / `normal` / `non-urgent`).
toXPriority()  : int
Maps a level onto the numeric `X-Priority` value (`1` highest … `5` lowest).

Constants

HIGH

Highest priority — `X-Priority: 1`, `Importance: high`, `Priority: urgent`.

public string HIGH = 'high'

LOW

Lowest priority — `X-Priority: 5`, `Importance: low`, `Priority: non-urgent`.

public string LOW = 'low'

NORMAL

Default priority — `X-Priority: 3`, `Importance: normal`, `Priority: normal`.

public string NORMAL = 'normal'

Methods

fromXPriority()

Maps a numeric `X-Priority` value onto a canonical level (`1`–`2` → high, `3` → normal, `4`–`5` → low).

public static fromXPriority(int $priority) : string
Parameters
$priority : int

The numeric X-Priority value.

Return values
string

One of self::HIGH / self::NORMAL / self::LOW.

normalize()

Folds any known spelling onto a canonical level.

public static normalize(string|null $value) : string

Recognises the canonical values, the Priority tokens (urgent / non-urgent) and numeric X-Priority values (15). Anything unknown, empty or null falls back to self::NORMAL.

Parameters
$value : string|null

A priority value in any supported spelling.

Return values
string

One of self::HIGH / self::NORMAL / self::LOW.

toImportance()

Maps a level onto the `Importance` header value (`high` / `normal` / `low`).

public static toImportance(string|null $level) : string
Parameters
$level : string|null

A priority value in any supported spelling.

Return values
string

The Importance value.

toPriority()

Maps a level onto the RFC 2156 `Priority` header value (`urgent` / `normal` / `non-urgent`).

public static toPriority(string|null $level) : string
Parameters
$level : string|null

A priority value in any supported spelling.

Return values
string

The Priority value.

toXPriority()

Maps a level onto the numeric `X-Priority` value (`1` highest … `5` lowest).

public static toXPriority(string|null $level) : int
Parameters
$level : string|null

A priority value in any supported spelling.

Return values
int

1, 3 or 5.

On this page

Search results