ILIAS  release_8 Revision v8.24
class.ilSoapMailXmlParser.php
Go to the documentation of this file.
1<?php
2/******************************************************************************
3 * This file is part of ILIAS, a powerful learning management system.
4 * ILIAS is licensed with the GPL-3.0, you should have received a copy
5 * of said license along with the source code.
6 * If this is not the case or you just want to try ILIAS, you'll find
7 * us at:
8 * https://www.ilias.de
9 * https://github.com/ILIAS-eLearning
10 *****************************************************************************/
11
18{
19 protected array $mails = [];
20 protected array $mail = [];
21 protected array $attachment = [];
22 protected array $lines = [];
23 protected string $cdata = '';
24
25 public function __construct(string $a_xml)
26 {
27 parent::__construct('', true);
28 $this->setThrowException(true);
29 $this->setXMLContent($a_xml);
30 }
31
32 public function getMails() : array
33 {
34 return $this->mails;
35 }
36
37 public function start() : bool
38 {
39 $this->startParsing();
40 return true;
41 }
42
47 public function setHandlers($a_xml_parser) : void
48 {
49 xml_set_object($a_xml_parser, $this);
50 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
51 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
52 }
53
60 public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs) : void
61 {
62 switch ($a_name) {
63 case 'Mail':
64 $this->mail = array();
65 $this->mail['usePlaceholders'] = (bool) $a_attribs['usePlaceholders'];
66 $this->mail['type'] = $a_attribs['type'] === 'System' ? 'system' : 'normal';
67 break;
68
69 case 'To':
70 $this->mail['to'] = $this->parseName($a_attribs);
71 break;
72
73 case 'Cc':
74 $this->mail['cc'] = $this->parseName($a_attribs);
75 break;
76
77 case 'Bcc':
78 $this->mail['bcc'] = $this->parseName($a_attribs);
79 break;
80
81 case 'Subject':
82 break;
83
84 case 'Message':
85 $this->lines = array();
86 break;
87
88 case 'Attachment':
89 $this->attachment = array();
90 $this->attachment['name'] = $a_attribs['name'];
91 break;
92
93 }
94 }
95
101 public function handlerEndTag($a_xml_parser, string $a_name) : void
102 {
103 switch ($a_name) {
104 case 'Mail':
105 $this->mails[] = $this->mail;
106 break;
107
108 case 'Subject':
109 $this->mail['subject'] = $this->cdata;
110 break;
111
112 case 'Message':
113 $this->mail['body'] = $this->lines;
114 break;
115
116 case 'P':
117 $this->lines[] = trim($this->cdata);
118 break;
119
120 case 'Attachment':
121 $this->attachment['content'] = base64_decode(trim($this->cdata));
122 $this->mail['attachments'][] = $this->attachment;
123 break;
124 }
125
126 $this->cdata = '';
127 }
128
134 public function handlerCharacterData($a_xml_parser, string $a_data) : void
135 {
136 if ($a_data !== "\n") {
137 // Replace multiple tabs with one space
138 $a_data = preg_replace("/\t+/", " ", $a_data);
139 $this->cdata .= $a_data;
140 }
141 }
142
143 protected function parseName(array $a_attribs) : string
144 {
145 if ($a_attribs['obj_id']) {
146 $il_id = explode('_', $a_attribs['obj_id']);
147 if (!$user = ilObjectFactory::getInstanceByObjId($il_id[3], false)) {
148 throw new InvalidArgumentException("Invalid user id given: obj_id => " . $a_attribs['obj_id']);
149 }
150 return $user->getLogin();
151 }
152 return (string) ($a_attribs['name'] ?? '');
153 }
154}
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)
setThrowException(bool $throw_exception)
startParsing()
stores xml data in array
XML parser for soap mails.
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
handler for begin of element
setHandlers($a_xml_parser)
Set event handlers.
handlerEndTag($a_xml_parser, string $a_name)
Handler for end of element.
handlerCharacterData($a_xml_parser, string $a_data)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc