Changeset 95 for trunk/Packages/Common/Mail.php
- Timestamp:
- Dec 6, 2021, 11:33:48 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Mail.php
r92 r95 9 9 class Mail 10 10 { 11 var $Priorities; 12 var $Subject; 13 var $From; 14 var $Recipients; 15 var $Bodies; 16 var $Attachments; 17 var $AgentIdent; 18 var $Organization; 19 var $ReplyTo; 20 var $Headers; 11 public string $Subject; 12 public string $From; 13 public array $Recipients; 14 public array $Bodies; 15 public array $Attachments; 16 public string $AgentIdent; 17 public string $Organization; 18 public string $ReplyTo; 19 public array $Headers; 20 private array $Priorities; 21 private string $Boundary; 21 22 22 23 function __construct() … … 28 29 } 29 30 30 function Clear() 31 function Clear(): void 31 32 { 32 33 $this->Bodies = array(); … … 41 42 } 42 43 43 function AddToCombined( $Address)44 function AddToCombined(string $Address): void 44 45 { 45 46 $this->Recipients[] = array('Address' => $Address, 'Type' => 'SendCombined'); 46 47 } 47 48 48 function AddTo( $Address, $Name)49 function AddTo(string $Address, string $Name): void 49 50 { 50 51 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Send'); 51 52 } 52 53 53 function AddCc( $Address, $Name)54 function AddCc(string $Address, string $Name): void 54 55 { 55 56 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'Copy'); 56 57 } 57 58 58 function AddBcc( $Address, $Name)59 function AddBcc(string $Address, string $Name): void 59 60 { 60 61 $this->Recipients[] = array('Address' => $Address, 'Name' => $Name, 'Type' => 'HiddenCopy'); 61 62 } 62 63 63 function AddBody( $Content, $MimeType = 'text/plain', $Charset = 'utf-8')64 function AddBody(string $Content, string $MimeType = 'text/plain', string $Charset = 'utf-8'): void 64 65 { 65 66 $this->Bodies[] = array('Content' => $Content, 'Type' => strtolower($MimeType), … … 67 68 } 68 69 69 function Organization( $org)70 function Organization(string $org): void 70 71 { 71 72 if (trim($org != '')) $this->xheaders['Organization'] = $org; 72 73 } 73 74 74 function Priority( $Priority)75 function Priority(int $Priority): bool 75 76 { 76 77 if (!intval($Priority)) return false; 77 78 78 if (!isset($this-> priorities[$Priority - 1])) return false;79 80 $this->xheaders['X-Priority'] = $this-> priorities[$Priority - 1];79 if (!isset($this->Priorities[$Priority - 1])) return false; 80 81 $this->xheaders['X-Priority'] = $this->Priorities[$Priority - 1]; 81 82 return true; 82 83 } 83 84 84 function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT) 85 function AttachFile($FileName, $FileType, $Disposition = DISPOSITION_ATTACHMENT): void 85 86 { 86 87 $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType, … … 88 89 } 89 90 90 function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT) 91 function AttachData($FileName, $FileType, $Data, $Disposition = DISPOSITION_ATTACHMENT): void 91 92 { 92 93 $this->Attachments[] = array('FileName' => $FileName, 'FileType' => $FileType, … … 94 95 } 95 96 96 function Send() 97 function Send(): bool 97 98 { 98 99 if (count($this->Bodies) == 0) throw new Exception(T('Mail message need at least one text body')); … … 144 145 if ($this->Subject == '') throw new Exception(T('Mail message missing Subject')); 145 146 146 147 147 $res = mail($To, $this->Subject, $Body, $Headers); 148 148 return $res; 149 149 } 150 150 151 function ValidEmail( $Address)152 { 153 if ( ereg(".*<(.+)>", $Address, $regs)) $Address = $regs[1];154 if ( ereg("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address))151 function ValidEmail(string $Address): bool 152 { 153 if (preg_match(".*<(.+)>", $Address, $regs)) $Address = $regs[1]; 154 if (preg_match("^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$", $Address)) 155 155 return true; 156 156 else return false; 157 157 } 158 158 159 function CheckAdresses( $Addresses)159 function CheckAdresses(array $Addresses): void 160 160 { 161 161 foreach ($Addresses as $Address) 162 162 { 163 163 if (!$this->ValidEmail($Address)) 164 throw new Exception(sprintf(T('Mail message invalid address %s'), $Address)); 165 } 166 } 167 168 private function ContentEncoding($Charset) 164 { 165 throw new Exception(sprintf(T('Mail message invalid address %s'), $Address)); 166 } 167 } 168 } 169 170 private function ContentEncoding($Charset): string 169 171 { 170 172 if ($Charset != CHARSET_ASCII) return '8bit'; … … 172 174 } 173 175 174 private function BuildAttachment($Body) 176 private function BuildAttachment($Body): string 175 177 { 176 178 if (count($this->Attachments) > 0) … … 206 208 } 207 209 208 private function BuildBody() 210 private function BuildBody(): string 209 211 { 210 212 $Result = ''; … … 219 221 $this->Headers['Content-Transfer-Encoding'] = $this->ContentEncoding($this->Bodies[0]['Charset']); 220 222 } 221 222 223 223 224 foreach ($this->Bodies as $Body)
Note:
See TracChangeset
for help on using the changeset viewer.