Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

Copyright (c) 2001-2010, Richard Heyes Copyright 2011-2017 Horde LLC (http://www.horde.org/) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Copyright: 2001-2010 Richard Heyes
Copyright: 2002-2011 Timo Sirainen
Copyright: 2011-2017 Horde LLC
License: http://www.horde.org/licenses/bsd New BSD License
File Size: 896 lines (25 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Horde_Mail_Rfc822  - X-Ref

RFC 822/2822/3490/5322 Email parser/validator.

parseAddressList($address, array $params = array()   X-Ref
Starts the whole process.

param: mixed $address   The address(es) to validate. Either a string,
param: array $params    Optional parameters:
return: Horde_Mail_Rfc822_List  A list object.

encode($str, $type = 'address')   X-Ref
Quotes and escapes the given string if necessary using rules contained
in RFC 2822 [3.2.5].

param: string $str   The string to be quoted and escaped.
param: string $type  Either 'address', 'comment' (@since 2.6.0), or
return: string  The correctly quoted and escaped string.

trimAddress($address)   X-Ref
If an email address has no personal information, get rid of any angle
brackets (<>) around it.

param: string $address  The address to trim.
return: string  The trimmed address.

_parseAddressList()   X-Ref
address-list = (address *("," address)) / obs-addr-list


_parseAddress()   X-Ref
address = mailbox / group


_parseGroup()   X-Ref
group           = display-name ":" [mailbox-list / CFWS] ";" [CFWS]
display-name    = phrase

return: boolean  True if a group was parsed.

_parseMailbox()   X-Ref
mailbox = name-addr / addr-spec

return: mixed  Mailbox object if mailbox was parsed, or false.

_parseNameAddr()   X-Ref
name-addr    = [display-name] angle-addr
display-name = phrase

return: mixed  Mailbox object, or false.

_parseAddrSpec()   X-Ref
addr-spec = local-part "@" domain

return: mixed  Mailbox object.

_parseLocalPart()   X-Ref
local-part      = dot-atom / quoted-string / obs-local-part
obs-local-part  = word *("." word)

return: string  The local part.

_parseAngleAddr()   X-Ref
"<" [ "@" route ":" ] local-part "@" domain ">"

return: mixed  Mailbox object, or false.

_parseDomainList()   X-Ref
obs-domain-list = "@" domain *(*(CFWS / "," ) [CFWS] "@" domain)

return: array  Routes.

_rfc822ParsePhrase(&$phrase)   X-Ref
phrase     = 1*word / obs-phrase
word       = atom / quoted-string
obs-phrase = word *(word / "." / CFWS)

param: string &$phrase  The phrase data.

_rfc822ParseQuotedString(&$str)   X-Ref

param: string &$phrase  The quoted string data.

_rfc822ParseDotAtom(&$str, $validate = null)   X-Ref
dot-atom        = [CFWS] dot-atom-text [CFWS]
dot-atom-text   = 1*atext *("." 1*atext)

atext           = ; Any character except controls, SP, and specials.

For RFC-822 compatibility allow LWSP around '.'.


param: string &$str      The atom/dot data.
param: string $validate  Use these characters as delimiter.

_rfc822ParseAtomOrDot(&$str)   X-Ref
atom  = [CFWS] 1*atext [CFWS]
atext = ; Any character except controls, SP, and specials.

This method doesn't just silently skip over WS.

param: string &$str  The atom/dot data.

_rfc822ParseDomain(&$str)   X-Ref
domain          = dot-atom / domain-literal / obs-domain
domain-literal  = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]
obs-domain      = atom *("." atom)

param: string &$str  The domain string.

_rfc822ParseDomainLiteral(&$str)   X-Ref
domain-literal  = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]
dcontent        = dtext / quoted-pair
dtext           = NO-WS-CTL /     ; Non white space controls
%d33-90 /       ; The rest of the US-ASCII
%d94-126        ;  characters not including "[",
;  "]", or "\"

param: string &$str  The domain string.

_rfc822SkipLwsp($advance = false)   X-Ref

param: boolean $advance  Advance cursor?

_rfc822SkipComment()   X-Ref


_rfc822IsAtext($chr, $validate = null)   X-Ref
Check if data is an atom.

param: string $chr       The character to check.
param: string $validate  If in non-validate mode, use these characters
return: boolean  True if a valid atom.

_curr($advance = false)   X-Ref
Return current character.

param: boolean $advance  If true, advance the cursor.
return: string  The current character (false if EOF reached).

approximateCount($data)   X-Ref
Returns an approximate count of how many addresses are in the string.
This is APPROXIMATE as it only splits based on a comma which has no
preceding backslash.

param: string $data  Addresses to count.
return: integer  Approximate count.

isValidInetAddress($data, $strict = false)   X-Ref
Validates whether an email is of the common internet form:
<user>@<domain>. This can be sufficient for most people.

Optional stricter mode can be utilized which restricts mailbox
characters allowed to: alphanumeric, full stop, hyphen, and underscore.

param: string $data     Address to check.
param: boolean $strict  Strict check?
return: mixed  False if it fails, an indexed array username/domain if