69 $this->_replacements = (array) $replacements;
71 $this->_replacements = $replacements;
84 $to = array_keys($message->getTo());
85 $address = array_shift($to);
87 $body = $message->getBody();
88 $search = array_keys($replacements);
89 $replace = array_values($replacements);
90 $bodyReplaced = str_replace(
91 $search, $replace, $body
93 if ($body != $bodyReplaced) {
94 $this->_originalBody = $body;
95 $message->setBody($bodyReplaced);
98 foreach ($message->getHeaders()->getAll() as $header) {
99 $body = $header->getFieldBodyModel();
101 if (is_array($body)) {
102 $bodyReplaced = array();
103 foreach ($body as $key => $value) {
106 $key = is_string($key) ? str_replace($search, $replace, $key, $count1) : $key;
107 $value = is_string($value) ? str_replace($search, $replace, $value, $count2) : $value;
108 $bodyReplaced[$key] = $value;
110 if (!$count && ($count1 || $count2)) {
115 $bodyReplaced = str_replace($search, $replace, $body, $count);
119 $this->_originalHeaders[$header->getFieldName()] = $body;
120 $header->setFieldBodyModel($bodyReplaced);
124 $children = (array) $message->getChildren();
125 foreach ($children as $child) {
126 list($type) = sscanf($child->getContentType(),
'%[^/]/%s');
127 if (
'text' == $type) {
128 $body = $child->getBody();
129 $bodyReplaced = str_replace(
130 $search, $replace, $body
132 if ($body != $bodyReplaced) {
133 $child->setBody($bodyReplaced);
134 $this->_originalChildBodies[$child->getId()] = $body;
138 $this->_lastMessage = $message;
159 return $this->_replacements->getReplacementsFor($address);
161 return isset($this->_replacements[$address])
162 ? $this->_replacements[$address]
181 if ($this->_lastMessage === $message) {
182 if (isset($this->_originalBody)) {
183 $message->
setBody($this->_originalBody);
184 $this->_originalBody = null;
186 if (!empty($this->_originalHeaders)) {
187 foreach ($message->
getHeaders()->getAll() as $header) {
189 $header->setFieldBodyModel($this->_originalHeaders[$header->getFieldName()]);
192 $this->_originalHeaders = array();
194 if (!empty($this->_originalChildBodies)) {
196 foreach ($children as $child) {
197 $id = $child->getId();
198 if (array_key_exists($id, $this->_originalChildBodies)) {
199 $child->setBody($this->_originalChildBodies[$id]);
202 $this->_originalChildBodies = array();
204 $this->_lastMessage = null;