SHOW:
|
|
- or go back to the newest paste.
1 | <?php #RAW Mail Parser | |
2 | class RAWMailParser { | |
3 | function __construct(){ | |
4 | //nastavení DateTime funkcí pro použití funkcí strtotime() a date() | |
5 | date_default_timezone_set(@date_default_timezone_get()); | |
6 | return $this; | |
7 | } | |
8 | private $endl = "\r\n"; | |
9 | private $splitter = "\r\n\r\n"; | |
10 | private $ignoreLevel = 1; | |
11 | private $headers = array(); | |
12 | private $sender = array(); | |
13 | private $recipient = array(); | |
14 | private $subject = ''; | |
15 | private $timestamp = 0; | |
16 | private $message = array(); | |
17 | private $embeddedMessage = array(); | |
18 | private $embeddedHeades = array(); | |
19 | private $attachments = array(); | |
20 | private $attachmentsList = array(); | |
21 | private $inline = array(); | |
22 | private $inlineList = array(); | |
23 | private $log = array(); | |
24 | private $charset = 'utf-8'; | |
25 | private $typePriority = array('text/html', 'text/plain'); | |
26 | ||
27 | //Methods: | |
28 | ||
29 | private function log($message, $level, $debug = false){ | |
30 | if($level > $this->ignoreLevel){ | |
31 | $message = "Warning (level $level): $message"; | |
32 | if($debug !== false){ | |
33 | $message .= "\nDebug content: $debug"; | |
34 | } | |
35 | if($this->charset != 'utf-8'){ | |
36 | $message = iconv('utf-8', $this->charset, $message); | |
37 | } | |
38 | $this->log[] = $message; | |
39 | } | |
40 | } | |
41 | private function writeToFile($filename, $content){ | |
42 | $file_handle = fopen($filename, 'w'); | |
43 | if(!$file_handle){ | |
44 | return false; | |
45 | } | |
46 | if(fwrite($file_handle, $content) === false){ | |
47 | return false; | |
48 | } | |
49 | fclose($file_handle); | |
50 | return true; | |
51 | } | |
52 | private function parseHeader($header){ | |
53 | $headers = array(); | |
54 | $header_name = ''; | |
55 | foreach(explode($this->endl, $header) as $line){ | |
56 | if($line[0] == "\t" or $line[0] == " "){ | |
57 | $headers[$header_name] .= PHP_EOL.$line; | |
58 | }elseif(strpos($line, ':') !== false){ | |
59 | list($header_name, $header_content) = explode(':', $line, 2); | |
60 | $header_name = strtolower($header_name); | |
61 | $header_content = trim($header_content); | |
62 | if(isset($headers[$header_name])){ | |
63 | $headers[$header_name] .= $this->endl.$header_content; | |
64 | }else{ | |
65 | $headers[$header_name] = $header_content; | |
66 | } | |
67 | }else{ | |
68 | $this->log('Jedna z hlaviček nemohla být zpracována.', 1, $line); | |
69 | } | |
70 | } | |
71 | return $headers; | |
72 | } | |
73 | private function parseBody($body, $boundary = false, $embedded_message = false){ | |
74 | if($boundary){ | |
75 | //multipart mail | |
76 | $body = explode('--'.$boundary, $body); | |
77 | }else{ | |
78 | //jen zpráva | |
79 | $body = array($body); | |
80 | } | |
81 | foreach($body as $part){ | |
82 | //základní kontrola | |
83 | if(strpos($part, $this->splitter) === false){ // || strpos($part, "--\n") === 0){ | |
84 | $this->log('Jedna z částí emailu byla zahozena, protože byla nejspíš neplatná - neobsahovala oddělovač.', 1, $part); | |
85 | continue; | |
86 | } | |
87 | //analyzování headeru | |
88 | list($header, $content) = explode($this->splitter, $part, 2); | |
89 | $headers = $this->parseHeader(ltrim($header)); | |
90 | //kontrola Content-Type | |
91 | if(isset($headers['content-type'])){ | |
92 | $content_type = $headers['content-type']; | |
93 | }else{ | |
94 | $this->log('Jedna z částí emailu byla zahozena, protože neobsahovala Content-Type hlavičku.', 2, $header); | |
95 | continue; | |
96 | } | |
97 | //kontrola Content-Transfer-Encoding | |
98 | if(isset($headers['content-transfer-encoding'])){ | |
99 | $encoding = $headers['content-transfer-encoding']; | |
100 | //dekódování obsahu | |
101 | if($encoding == 'quoted-printable'){ | |
102 | $content = quoted_printable_decode($content); | |
103 | }elseif($encoding == 'base64'){ | |
104 | $content = base64_decode($content); | |
105 | } | |
106 | } | |
107 | //uložení hlaviček | |
108 | if(isset($headers['from']) && isset($headers['subject'])){ | |
109 | if($embedded_message){ | |
110 | $this->embeddedHeaders = array( | |
111 | 'sender' => $this->getNamesAndEmails($headers['from'])[0], | |
112 | 'subject' => iconv_mime_decode($headers['subject'], 0, $this->charset), | |
113 | 'timestamp' => isset($headers['date']) ? strtotime($headers['date']) : 0 | |
114 | ); | |
115 | }else{ | |
116 | //zjisti předmět zprávy | |
117 | $this->subject = iconv_mime_decode($headers['subject'], 0, $this->charset); | |
118 | //zjisti kdo je odesílatel a kdo je příjemce | |
119 | $this->sender = $this->getNamesAndEmails($headers['from'])[0]; | |
120 | if(isset($headers['to'])){ | |
121 | $this->recipient = $this->getNamesAndEmails($headers['to']); | |
122 | } | |
123 | //zjisti čas, kdy byl email odeslaný | |
124 | if(isset($headers['date'])){ | |
125 | //date_default_timezone_set(@date_default_timezone_get()); | |
126 | $this->timestamp = strtotime($headers['date']); | |
127 | } | |
128 | $this->headers = $headers; | |
129 | } | |
130 | } | |
131 | //zjištění typu | |
132 | $strpos_slash = strpos($content_type, '/'); | |
133 | $type = substr($content_type, 0, $strpos_slash ? $strpos_slash : 0); | |
134 | //text zprávy | |
135 | if($type == 'text'){ | |
136 | //zjisti znakovou sadu | |
137 | $message_charset = $this->getPropertyValue($content_type, 'charset'); | |
138 | if($message_charset && $message_charset != $this->charset){ | |
139 | $content = iconv($message_charset, $this->charset.'//ignore', $content); | |
140 | } | |
141 | //uložení zpracované zprávy | |
142 | if($embedded_message){ | |
143 | //vložená zpráva emailu získaná z typu "message", asi původní zpráva před přeposláním | |
144 | $this->embeddedMessage[$this->getContentType($content_type)] = $content; | |
145 | }else{ | |
146 | //zpráva | |
147 | $this->message[$this->getContentType($content_type)] = $content; | |
148 | } | |
149 | }elseif($type == 'multipart' || $type == 'message'){ | |
150 | //typ multipart nebo message/rfc822 | |
151 | $this->parseBody($content, $this->getPropertyValue($content_type, 'boundary'), $type == 'message' ? true : $embedded_message); | |
152 | }else{ | |
153 | //příloha | |
154 | $inline = (isset($headers['content-id']) && $type == 'image'); //vloží jako inline jen obrázky | |
155 | $disposition = isset($headers['content-disposition']) ? $headers['content-disposition'] : ''; | |
156 | //získání názvu souboru | |
157 | $filename_disposition = $this->getPropertyValue($disposition, 'filename'); | |
158 | $filename_content_type = $this->getPropertyValue($content_type, 'name'); | |
159 | if($filename_disposition){ | |
160 | //název souboru získaný z disposition | |
161 | $filename = $filename_disposition; | |
162 | }elseif($filename_content_type){ | |
163 | //název souboru získaný z content-type | |
164 | $filename = $filename_content_type; | |
165 | }else{ | |
166 | //neznámý název souboru | |
167 | $this->log('Nepodařilo se zjistit název přílohy.', 2); | |
168 | $filename = 'Attachment('.$this->getContentType($content_type).')'; | |
169 | } | |
170 | $filename = iconv_mime_decode($filename, 0, $this->charset); | |
171 | if($inline){ | |
172 | $content_id = $headers['content-id']; | |
173 | if($content_id[0] == '<'){ | |
174 | $content_id = substr($content_id, 1, -1); | |
175 | } | |
176 | //inline příloha (vložená do textu přes Content-Id) | |
177 | $this->inlineList[] = array( | |
178 | 'filename' => $filename, | |
179 | 'content-type' => $this->getContentType($content_type), | |
180 | 'content-id' => $content_id, | |
181 | 'size' => strlen($content) | |
182 | ); | |
183 | $this->inline[] = $content; | |
184 | }else{ | |
185 | //normální příloha | |
186 | $this->attachmentsList[] = array( | |
187 | 'filename' => $filename, | |
188 | 'content-type' => $this->getContentType($content_type), | |
189 | 'content-id' => '<null>', | |
190 | 'size' => strlen($content) | |
191 | ); | |
192 | $this->attachments[] = $content; | |
193 | } | |
194 | } | |
195 | } | |
196 | } | |
197 | public function freeMemory(){ | |
198 | $empty_associative_array = array('name' => '', 'email' => ''); | |
199 | //vynulování proměnných | |
200 | $this->headers = array(); | |
201 | $this->sender = $empty_associative_array; | |
202 | $this->recipient = array($empty_associative_array); | |
203 | $this->subject = ''; | |
204 | $this->timestamp = 0; | |
205 | $this->message = array(); | |
206 | $this->embeddedMessage = array(); | |
207 | $this->embeddedHeaders = array('sender' => $empty_associative_array, 'subject' => '', 'timestamp' => 0); | |
208 | $this->attachmentsList = array(); | |
209 | $this->attachments = array(); | |
210 | $this->inlineList = array(); | |
211 | $this->inline = array(); | |
212 | $this->log = array(); | |
213 | return $this; | |
214 | } | |
215 | public function load($raw_data){ | |
216 | $this->freeMemory(); | |
217 | //kontrola argumentu, jestli to není cesta k souboru | |
218 | if(strlen($raw_data) < 100 && file_exists($raw_data)){ | |
219 | $raw_data = file_get_contents($raw_data); | |
220 | } | |
221 | $raw_data = ltrim($raw_data); | |
222 | //zjisti, co je oddělovač - LF (\n) nebo CRLF (\r\n) | |
223 | $this->endl = $raw_data[strpos($raw_data, "\n") - 1] == "\r" ? "\r\n" : "\n"; | |
224 | $this->splitter = $this->endl.$this->endl; | |
225 | $this->parseBody($raw_data); | |
226 | return true; | |
227 | } | |
228 | private function getPropertyValue($string, $property){ | |
229 | $property = $property.'='; | |
230 | $strpos = strpos($string, $property); | |
231 | if($strpos !== false){ | |
232 | $start = $strpos + strlen($property); | |
233 | $end_by_quote = strpos($string, '"', $start + 1); | |
234 | $end_by_semicolon = strpos($string, ';', $start); | |
235 | $length = ($end_by_quote !== false ? $end_by_quote + 1 : ($end_by_semicolon !== false ? $end_by_semicolon : strlen($string))) - $start; | |
236 | return trim((substr($string, $start, $length)), '\'"'); | |
237 | } | |
238 | return false; | |
239 | } | |
240 | public function getNamesAndEmails($header){ | |
241 | $names_and_emails = array(); | |
242 | foreach(explode(',', $header) as $email_data){ | |
243 | if(strpos($email_data, '<') === false){ | |
244 | $name = ''; | |
245 | //$name = false; | |
246 | $email = $email_data; | |
247 | }else{ | |
248 | list($name, $email) = explode('<', $email_data); | |
249 | $name = trim(iconv_mime_decode($name, 0, $this->charset), '"\' '); | |
250 | /*if(empty($name)){ | |
251 | $name = false; | |
252 | }*/ | |
253 | $email = substr($email, 0, -1); | |
254 | } | |
255 | if(!$this->validateEmail($email)){ | |
256 | if($this->ignoreLevel < 2){ | |
257 | $this->log('Email není ve správném formátu.', 2, $email); | |
258 | //$email = false; | |
259 | } | |
260 | } | |
261 | $names_and_emails[] = array( | |
262 | 'name' => $name, | |
263 | 'email' => $email | |
264 | ); | |
265 | } | |
266 | if(empty($names_and_emails)){ | |
267 | $this->log('Nepodařilo se zjistit žádný email', 2); | |
268 | //return false; | |
269 | $names_and_emails = array(array('', '')); | |
270 | } | |
271 | return $names_and_emails; | |
272 | } | |
273 | private function getContentType($content_type){ | |
274 | $semicolon = strpos($content_type, ';'); | |
275 | return substr($content_type, 0, $semicolon ? $semicolon : strlen($content_type)); | |
276 | } | |
277 | public function validateEmail($email){ | |
278 | return preg_match('/[a-z0-9\.\-\_]+@[a-z\.\-\_]+\.[a-z]{2,4}/', strtolower($email)); | |
279 | } | |
280 | ||
281 | //Get Methods | |
282 | ||
283 | public function getHeaders(){ | |
284 | return $this->headers; | |
285 | } | |
286 | public function getSender(){ | |
287 | return $this->sender; | |
288 | } | |
289 | public function getRecipient(){ | |
290 | return $this->recipient; | |
291 | } | |
292 | public function getSubject(){ | |
293 | return $this->subject; | |
294 | } | |
295 | public function getDate($format = 'U', $timestamp = false){ | |
296 | return date($format, $timestamp ? $timestamp : $this->timestamp); | |
297 | } | |
298 | public function getMessage($type = false, $embeddedMessage = false){ | |
299 | $message = $embeddedMessage !== false ? $embeddedMessage : $this->message; | |
300 | if(empty($message)){ | |
301 | if($embeddedMessage === false){ | |
302 | $this->log('Žádná zpráva není k dispozici. Nejspíš ještě email nebyl zpracován, nebo se při zpracovávání nepodařilo zprávu zachytit, a nebo už byla zpráva smazána (paměť už byla uvolněna).', 2); | |
303 | } | |
304 | return false; | |
305 | } | |
306 | if($type && isset($message[$type])){ | |
307 | return $message[$type]; | |
308 | }elseif($this->ignoreLevel > 1 || !$type){ | |
309 | //zkus vrátit typ podle nastavené priority | |
310 | foreach($this->typePriority as $type){ | |
311 | if(isset($message[$type])){ | |
312 | return $message[$type]; | |
313 | } | |
314 | } | |
315 | //vrať zprávu v jakémkoliv typu | |
316 | return current($message); | |
317 | } | |
318 | //nepodařilo se najít vhodný typ | |
319 | $this->log('Nepodařilo se najít zprávu v požadovaném typu, můžete zkusit povolit vrácení zprávy v jiném dostupném typu nastavením úrovně ignorování chyb na 2.', 2); | |
320 | return false; | |
321 | } | |
322 | public function getEmbeddedMessage($type = false){ | |
323 | return $this->getMessage($type, $this->embeddedMessage); | |
324 | } | |
325 | public function getEmbeddedHeaders(){ | |
326 | return $this->embeddedHeaders; | |
327 | } | |
328 | public function getAttachmentsList($inline = false){ | |
329 | return $inline ? $this->inlineList : $this->attachmentsList; | |
330 | } | |
331 | public function getAttachment($pointer, $inline = false){ | |
332 | $attachments = $inline ? $this->inline : $this->attachments; | |
333 | if(isset($attachments[$pointer])){ | |
334 | return $attachments[$pointer]; | |
335 | }else{ | |
336 | $this->log('Příloha s takovýmto ukazatelem nebyla nalezena', 2, $pointer); | |
337 | return false; | |
338 | } | |
339 | } | |
340 | public function saveAttachments($directory){ | |
341 | //kontrola adresáře | |
342 | if(is_dir($directory)){ | |
343 | //kontrola jestli je adresář prázdný | |
344 | $dir_handle = opendir($directory); | |
345 | while($file = readdir($dir_handle)){ | |
346 | if($file != '.' && $file != '..'){ | |
347 | $this->log('Adresář není prázdný -> mohlo by to způsobit kolizi.', 3); | |
348 | if($this->ignoreLevel < 1){ | |
349 | return false; | |
350 | } | |
351 | break; | |
352 | } | |
353 | } | |
354 | closedir($dir_handle); | |
355 | }else{ | |
356 | if(!mkdir($directory)){ | |
357 | $this->log('Adresář se nepodařilo vytvořit', 3); | |
358 | return false; | |
359 | } | |
360 | } | |
361 | $attachments_list = array(); | |
362 | //ukládání příloh | |
363 | foreach( | |
364 | array( | |
365 | 'inline' => $this->inlineList, | |
366 | 'attachment' => $this->attachmentsList | |
367 | ) as $disposition => $attachment | |
368 | ){ | |
369 | $path = $directory.$disposition; | |
370 | $attachments_info = array(); | |
371 | for($i = 0; $i < count($attachment); $i++){ | |
372 | $log = 'Paměť s přílohami už byla nejspíš vyčištěna (přílohy byly uloženy do souborů) nebo se vyskytla neznámá chyba. Nejspíš bude třeba email znovu zpracovat.'; | |
373 | if($disposition == 'inline'){ | |
374 | //získání vložené přílohy | |
375 | if(isset($this->inline[$i])){ | |
376 | $content = &$this->inline[$i]; | |
377 | }else{ | |
378 | $this->log($log, 2); | |
379 | return false; | |
380 | } | |
381 | }else{ | |
382 | //získání normální přílohy | |
383 | if(isset($this->attachments[$i])){ | |
384 | $content = &$this->attachments[$i]; | |
385 | }else{ | |
386 | $this->log($log, 2); | |
387 | return false; | |
388 | } | |
389 | } | |
390 | $attachments_info[] = implode('|', $attachment[$i]); | |
391 | //uložení přílohy | |
392 | if(!$this->writeToFile($path.$i, $content)){ | |
393 | $this->log('Nepodařilo se vytvořit soubor pro některou z příloh.', 3); | |
394 | return false; | |
395 | } | |
396 | } | |
397 | $attachments_list[$disposition] = implode("\n", $attachments_info); | |
398 | } | |
399 | //uložení informací o přlohách | |
400 | if(!$this->writeToFile($directory.'attachmentsList', implode("\n", $attachments_list))){ | |
401 | $this->log('Nepodařilo se zapsat seznam příloh do souboru.', 3); | |
402 | return false; | |
403 | } | |
404 | //vyčištění paměti s přílohami | |
405 | $this->attachments = array(); | |
406 | $this->inline = array(); | |
407 | return true; | |
408 | } | |
409 | public function getProcessedData(){ | |
410 | return array( | |
411 | $this->recipient, //Příjemce | |
412 | $this->sender, //Odesílatel | |
413 | $this->subject, //Předmět | |
414 | $this->timestamp, //Časový otisk | |
415 | $this->getHeaders(), //Hlavičky | |
416 | $this->getMessage(), //Zpráva | |
417 | $this->getAttachmentsList(),//Seznam příloh | |
418 | $this->getContentType($this->headers['content-type']) //Typ | |
419 | ); | |
420 | } | |
421 | public function getProcessLog($as_array = false){ | |
422 | return $as_array ? $this->log : implode("\n", $this->log); | |
423 | } | |
424 | public function getSavedList($directory){ | |
425 | $list = @file_get_contents($directory.'attachmentsList'); | |
426 | if(!$list){ | |
427 | return false; | |
428 | } | |
429 | $attachments = array( | |
430 | 'inline' => array(), | |
431 | 'attachments' => array() | |
432 | ); | |
433 | $index = 'inline'; | |
434 | $keys = array('filename', 'content-type', 'content-id', 'size'); | |
435 | foreach(explode("\n", $list) as $line){ | |
436 | if(empty($line)){ | |
437 | $index = 'attachments'; | |
438 | continue; | |
439 | } | |
440 | $attachments[$index][] = array_combine($keys, explode('|', $line)); | |
441 | } | |
442 | return $attachments; | |
443 | } | |
444 | public function getPathToAttachment($directory, $disposition, $number){ | |
445 | $path = $directory.$disposition.$number; | |
446 | if(file_exists($path)){ | |
447 | return $path; | |
448 | }else{ | |
449 | $this->log('Nepodařilo se najít požadovaný soubor.', 3); | |
450 | return false; | |
451 | } | |
452 | } | |
453 | ||
454 | //Set Methods | |
455 | ||
456 | public function setIgnoreLevel($level){ | |
457 | $this->ignoreLevel = intval($level); | |
458 | return $this; | |
459 | } | |
460 | public function setCharset($charset){ | |
461 | $this->charset = strtolower($charset); | |
462 | return $this; | |
463 | } | |
464 | public function setTypePriority($priority){ | |
465 | $this->typePriority = (array)$priority; | |
466 | return $this; | |
467 | } | |
468 | ||
469 | //Debug method | |
470 | ||
471 | public function debug(){ | |
472 | var_dump( | |
473 | $this->headers, | |
474 | $this->sender, | |
475 | $this->recipient, | |
476 | $this->subject, | |
477 | $this->getDate('d.m.Y H:i:s'), | |
478 | $this->getMessage(), | |
479 | $this->getAttachmentsList(), | |
480 | $this->log | |
481 | ); | |
482 | } | |
483 | } | |
484 | /* | |
485 | RAWMailParser | |
486 | Construct: | |
487 | ||
488 | public function __construct | |
489 | ||
490 | Proměnné: | |
491 | ||
492 | private $endl | |
493 | private $splitter | |
494 | private $headers | |
495 | private $sender | |
496 | private $recipient | |
497 | private $timestamp | |
498 | private $subject | |
499 | private $message | |
500 | private $embeddedMessage | |
501 | private $embeddedHeaders | |
502 | private $attachmentsList | |
503 | private $attachments | |
504 | private $inlineList | |
505 | private $inline | |
506 | private $ignoreLevel | |
507 | private $typePriority | |
508 | private $log | |
509 | private $charset | |
510 | ||
511 | Methods: | |
512 | ||
513 | private function log | |
514 | private function writeToFile | |
515 | private function parseHeader | |
516 | private function parseBody | |
517 | private function getPropertyValue | |
518 | private function getContentType | |
519 | public function freeMemory | |
520 | public function load | |
521 | public function validateEmail | |
522 | public function getNamesAndEmails | |
523 | public function getHeaders | |
524 | public function getSubject | |
525 | public function getSender | |
526 | public function getRecipient | |
527 | public function getDate | |
528 | public function getMessage | |
529 | public function getattachmentsList | |
530 | public function getAttachment | |
531 | public function saveAttachments | |
532 | public function getSavedList | |
533 | public function getPathToAttachment | |
534 | public function getProcessedData | |
535 | public function setCharset | |
536 | public function setIgnoreLevel | |
537 | public function setTypePriority | |
538 | ||
539 | Popis metod (public): | |
540 | ||
541 | freeMemory | |
542 | Description: vyčistí paměť (přepíše zprávu, přílohy, hlavičky a další proměnné použité při zpracovávání na prázdný řetězec nebo na prázdné pole) / nastavení nechává takové, jaké bylo (nepřepisuje na výchozí hodnoty) | |
543 | Return: $this (object) | |
544 | ||
545 | load | |
546 | Argument: RAW Data nebo cesta k souboru (string) | |
547 | Return: $this (object) | |
548 | ||
549 | validateEmail | |
550 | Argument: email na kontrolu (string) | |
551 | Return: true jestli prošel, false jestli ne (boolean) | |
552 | ||
553 | getNamesAndEmails | |
554 | Argument: obsah hlavičky s emaily, například z "from", "to" nebo "bcc" atd... (string) | |
555 | Return: jména a emaily (pokud nebylo možné zjistit jméno, tak se místo jména vrátí false, nebo pokud email neprojde validací, tak se místo emailu vrátí false v prvku pole) (array(associative array(keys: 'name', 'email')) //asociativní pole vnořené v poli | |
556 | ||
557 | getHeaders | |
558 | Return: hlavičky emailu (associative array, keys: headers names in lowercase - "from", "to", "date", "subject", "content-type", "received"...) | |
559 | ||
560 | getSubject | |
561 | Return: předmět emailu (string) | |
562 | ||
563 | getSender | |
564 | Return: jméno a email odesítalele (associative array, keys: 'name', 'email') | |
565 | ||
566 | getRecipients | |
567 | Return: jména a emaily příjemců (nebo příjemce, jestli byl jen jeden) (array(associative array, keys: 'name', 'email')) | |
568 | ||
569 | getDate | |
570 | Argument: formát funkce date(), (výchozí "U" - timestamp) (string) | |
571 | Argument: timestamp z vloženého emailu message/rfc822 (nepovinný argument, výchozí je timestamp získaný z hlavičky emailu) (int) | |
572 | Return: datum a čas zformátovaný podle argumentu (string) | |
573 | ||
574 | getMessage | |
575 | Argument: typ ve kterém má být zpráva vrácena (např.: "text/html" - v případě, že zpráva tohoto typu nebude k dispozici, vrátí se v nejbližším preferovaným typu) (string) | |
576 | Return: zpráva (string) nebo false (boolean) při neúspěchu | |
577 | ||
578 | getEmbeddedMessage | |
579 | Argument: typ, funguje stejně jako u getMessage (string) | |
580 | Return: vložená zpráva (nejspíš původní zpráva před přeposláním) (string) nebo false (boolean) při neúspěchu | |
581 | ||
582 | getEmbeddedHeaders | |
583 | Return: odesílatel, předmět a čas odeslání vloženého emailu (nejspíš původní zprávy před přeposláním) (associative array, keys: 'sender' (associative array, keys: 'name', 'email'), 'subject' (string), 'timestamp' (int)) | |
584 | ||
585 | getAttachmentsList | |
586 | Argument: vrátit z normálních příloh nebo z vložených (inline)? (nepovinný, výchozí z normálních) (boolean) | |
587 | Return: seznam příloh a informace o nich (název souboru, typ, content-id, velikost souboru) (associative array, keys: 'filename', 'content-type', 'content-id', 'size') | |
588 | ||
589 | getAttachment | |
590 | Argument: ukazatel přílohy - získaný z getAttachmentsList (int) | |
591 | Argument: vrátit z normálních příloh nebo z vložených (inline)? (nepovinný, výchozí z normálních) (boolean) | |
592 | Return: dekódovaný obsah přílohy (string - většinou hodně dlouhý) | |
593 | ||
594 | getProcessedData | |
595 | Return: pole se zpracovanými daty (array [0]=>příjemce, [1]=>odesílatel, [2]=>předmět, [3]=>časové razítko, [4]=>zpráva, [5]=>seznam příloh, [6]=>typ emailu) | |
596 | ||
597 | getProcessLog | |
598 | Argument: vrátit jako pole? (boolean) | |
599 | Return: log s varováními vygenerovanými při zpracovávání (array | string) | |
600 | ||
601 | getSavedList | |
602 | Argument: adresář, ve kterém jsou přílohy uloženy (s lomítkem na konci) | |
603 | Return: asociativní pole s informacemi o přílohách uložených v zadaném adrešáři (associative array, keys: 'inline' => (associative array, keys: 'filename', 'content-type', 'content-id', 'size'), 'attachments' => (associative array, keys: same as previous)) | |
604 | ||
605 | getPathToAttachment | |
606 | Argument: adresář, ve kterém jsou přílohy uloženy (s lomítkem na konci) | |
607 | Argument: dispozice přílohy (vložená nebo normální -> 'inline' nebo 'attachment') | |
608 | Argument: index v seznamu příloh (získaný z getSavedList) | |
609 | Return: cesta k příloze (pro uložení ke klientovi bude třeba přesvědčit prohlížeč že se příloha ve skutečnosti jmenuje tak, jak je to uložený v seznamu příloh, protože na server se ukládá ve tvaru directory/attachment0...) | |
610 | ||
611 | saveAttachments | |
612 | Argument: cesta ke složce, do které mají být přílohy uloženy (bez lomítka na konci) (string) | |
613 | Return: true v případě, že uložení bylo úspěšné, false v případě že ne (boolean) | |
614 | Do složky, kam se budou ukládat přílohy, by kvůli zabezpečení bylo dobrý vytvořit soubor .htacces a napsat do něj: deny from all | |
615 | A pro každý email pak vytvořit složku pro přílohy (např. náhodně vygenerovanou, ale potom by to chtělo si pamatovat jak se jmenuje) | |
616 | ||
617 | setCharset | |
618 | Argument: znaková sada, ve které mají být výstupní hodnoty (string) | |
619 | Return: $this (object) | |
620 | ||
621 | setIgnoreLevel | |
622 | Argument: úroveň ignorování chyb (0 - logování všech varování, 1 - ignorování debug informací, 2 - ignorování základních varování, 3 - ignorování závažnějších varování) (int) | |
623 | Return: $this (object) | |
624 | ||
625 | setTypePriority | |
626 | Argument: priorita typů pro hledání vhodného typu na vrácení zprávy emailu (array | string - přetypuje se na 1-elementové pole) | |
627 | Return: $this (object) | |
628 | */ | |
629 | ?> |