ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSoapMailXmlParser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
5include_once './Services/Xml/classes/class.ilSaxParser.php';
6include_once './Services/User/classes/class.ilObjUser.php';
7
17{
21 public function __construct($a_xml)
22 {
23 parent::__construct('', true);
24 $this->setThrowException(true);
25 $this->setXMLContent($a_xml);
26 }
27
32 public function getMails()
33 {
34 return (array) $this->mails;
35 }
36
44 public function start()
45 {
46 $this->startParsing();
47 return true;
48 }
49
50
57 public function setHandlers($a_xml_parser)
58 {
59 xml_set_object($a_xml_parser, $this);
60 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
61 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
62 }
63
71 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
72 {
73 switch ($a_name) {
74 case 'Mail':
75 $this->mail = array();
76 $this->mail['usePlaceholders'] = $a_attribs['usePlaceholders'] ? true : false;
77 $this->mail['type'] = $a_attribs['type'] == 'System' ? 'system' : 'normal';
78 break;
79
80 case 'To':
81 $this->mail['to'] = $this->parseName($a_attribs);
82 break;
83
84 case 'Cc':
85 $this->mail['cc'] = $this->parseName($a_attribs);
86 break;
87
88 case 'Bcc':
89 $this->mail['bcc'] = $this->parseName($a_attribs);
90 break;
91
92 case 'Subject':
93 break;
94
95 case 'Message':
96 $this->lines = array();
97 break;
98
99 case 'Attachment':
100 $this->attachment = array();
101 $this->attachment['name'] = $a_attribs['name'];
102 break;
103
104 }
105 }
106
113 public function handlerEndTag($a_xml_parser, $a_name)
114 {
115 switch ($a_name) {
116 case 'Mail':
117 $this->mails[] = $this->mail;
118 break;
119
120 case 'Subject':
121 $this->mail['subject'] = $this->cdata;
122 break;
123
124 case 'Message':
125 $this->mail['body'] = (array) $this->lines;
126 break;
127
128 case 'P':
129 $this->lines[] = trim($this->cdata);
130 break;
131
132 case 'Attachment':
133 $this->attachment['content'] = base64_decode(trim($this->cdata));
134 $this->mail['attachments'][] = $this->attachment;
135 break;
136 }
137
138 $this->cdata = '';
139 }
140
147 public function handlerCharacterData($a_xml_parser, $a_data)
148 {
149 if ($this->in_metadata) {
150 parent::handlerCharacterData($a_xml_parser, $a_data);
151 }
152
153 if ($a_data != "\n") {
154 // Replace multiple tabs with one space
155 $a_data = preg_replace("/\t+/", " ", $a_data);
156 $this->cdata .= $a_data;
157 }
158 }
159
166 protected function parseName($a_attribs)
167 {
168 include_once './Services/Object/classes/class.ilObjectFactory.php';
169
170 if ($a_attribs['obj_id']) {
171 $il_id = explode('_', $a_attribs['obj_id']);
172 $GLOBALS['ilLog']->write('il ID:' . print_r($il_id, true));
173 if (!$user = ilObjectFactory::getInstanceByObjId($il_id[3], false)) {
174 throw new InvalidArgumentException("Invalid user id given: obj_id => " . $a_attribs['obj_id']);
175 }
176 return $user->getLogin();
177 } else {
178 return $a_attribs['name'];
179 }
180 }
181}
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setThrowException($throwException)
set error handling
setXMLContent($a_xml_content)
startParsing()
stores xml data in array
XML parser for soap mails.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
__construct($a_xml)
Constructor.
setHandlers($a_xml_parser)
set event handlers
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
parseName($a_attribs)
extract user name
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
mail($to, $subject, $message, $additional_headers=null, $additional_parameters=null)