Highway to PSR2
[openemr.git] / portal / patient / fwk / libs / verysimple / Email / Recipient.php
blobb705da078fcbf1721f207f2c925301f5b6e96609
1 <?php
2 /** @package verysimple::Email */
4 /**
5 * Object representation of an Email recipient
7 * @package verysimple::Email
8 * @author VerySimple Inc.
9 * @copyright 1997-2007 VerySimple, Inc.
10 * @license LGPL
11 * @version 1.1
13 class Recipient
15 var $Email;
16 var $RealName;
17 function __construct($email, $name = "")
19 if ($name) {
20 $this->Email = $email;
21 $this->RealName = $name != "" ? $name : $email;
22 } else {
23 $this->Parse($email);
27 /**
28 * Returns true if the provided email address appears to be valid.
29 * This does not determine if the address is actually legit, only
30 * if it is formatted properly
32 * @param
33 * string email address to validate
34 * @return bool 1 (true) if $email is valid, 0 (false) if not
36 static function IsEmailInValidFormat($email)
38 return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,25})$/i", $email);
41 /**
42 * Parses an address in the either format:
43 * "Real Name <email@address.com>" or "email@address.com"
45 * @param string $val
46 * to parse
48 function Parse($val)
50 $pair = explode("<", $val);
52 if (isset($pair [1])) {
53 $this->RealName = trim($pair [0]);
54 $this->Email = trim(str_replace(">", "", $pair [1]));
55 } else {
56 $this->Email = $val;
57 $this->RealName = $val;
60 // just in case there was no realname
61 if ($this->RealName == "") {
62 $this->RealName = $this->Email;
66 /**
67 * Returns true if $this->Email appears to be a valid email
69 * @return bool
71 function IsValidEmail()
73 return Recipient::IsEmailInValidFormat($this->Email);