ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilFormatMail.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13include_once "Services/Mail/classes/class.ilMail.php";
14
15class ilFormatMail extends ilMail
16{
17
24 public function __construct($a_user_id)
25 {
26 parent::__construct($a_user_id);
27 }
28
34 public function formatReplyMessage()
35 {
36 if (empty($this->mail_data)) {
37 return false;
38 }
39
40 $bodylines = preg_split("/\r\n|\n|\r/", $this->mail_data["m_message"]);
41 for ($i = 0; $i < count($bodylines); $i++) {
42 $bodylines[$i] = "> " . $bodylines[$i];
43 }
44
45 return $this->mail_data["m_message"] = implode(chr(10), $bodylines);
46 }
47
53 public function formatReplySubject()
54 {
55 if (empty($this->mail_data)) {
56 return false;
57 }
58 return $this->mail_data["m_subject"] = "RE: " . $this->mail_data["m_subject"];
59 }
60
67 {
68 global $DIC;
69
70 if (empty($this->mail_data)) {
71 return '';
72 }
73
74 $newCC = array();
75
76 $currentUserLogin = $DIC->user()->getLogin();
77
78 foreach (explode(',', $this->mail_data['rcp_to']) as $to) {
79 if (trim($to) != '' && $currentUserLogin != trim($to)) {
80 $newCC[] = trim($to);
81 }
82 }
83
84 foreach (explode(',', $this->mail_data['rcp_cc']) as $cc) {
85 if (trim($cc) != '' && $currentUserLogin != trim($cc)) {
86 $newCC[] = trim($cc);
87 }
88 }
89
90 return ($this->mail_data['rcp_cc'] = implode(', ', $newCC));
91 }
92
98 public function formatReplyRecipient()
99 {
100 if (empty($this->mail_data)) {
101 return false;
102 }
103
104 require_once './Services/User/classes/class.ilObjUser.php';
105
106 $user = new ilObjUser($this->mail_data["sender_id"]);
107 return $this->mail_data["rcp_to"] = $user->getLogin();
108 }
114 public function formatForwardSubject()
115 {
116 if (empty($this->mail_data)) {
117 return false;
118 }
119 return $this->mail_data["m_subject"] = "[FWD: " . $this->mail_data["m_subject"] . "]";
120 }
121
129 public function appendSearchResult($a_names, $a_type)
130 {
131 if (empty($this->mail_data)) {
132 return false;
133 }
134 $name_str = implode(',', $a_names);
135 switch ($a_type) {
136 case 'to':
137 $this->mail_data["rcp_to"] = trim($this->mail_data["rcp_to"]);
138 if ($this->mail_data["rcp_to"]) {
139 $this->mail_data["rcp_to"] = $this->mail_data["rcp_to"] . ",";
140 }
141 $this->mail_data["rcp_to"] = $this->mail_data["rcp_to"] . $name_str;
142 break;
143
144 case 'cc':
145 $this->mail_data["rcp_cc"] = trim($this->mail_data["rcp_cc"]);
146 if ($this->mail_data["rcp_cc"]) {
147 $this->mail_data["rcp_cc"] = $this->mail_data["rcp_cc"] . ",";
148 }
149 $this->mail_data["rcp_cc"] = $this->mail_data["rcp_cc"] . $name_str;
150 break;
151
152 case 'bc':
153 $this->mail_data["rcp_bcc"] = trim($this->mail_data["rcp_bcc"]);
154 if ($this->mail_data["rcp_bcc"]) {
155 $this->mail_data["rcp_bcc"] = $this->mail_data["rcp_bcc"] . ",";
156 }
157 $this->mail_data["rcp_bcc"] = $this->mail_data["rcp_bcc"] . $name_str;
158 break;
159
160 }
161 return $this->mail_data;
162 }
163
168 public function formatLinebreakMessage(string $message) : string
169 {
170 $formatted = [];
171
172 $linebreak = $this->mail_options->getLinebreak();
173
174 $lines = explode(chr(10), $message);
175 for ($i = 0; $i < count($lines); $i++) {
176 if (substr($lines[$i], 0, 1) != '>') {
177 $formatted[] = wordwrap($lines[$i], $linebreak, chr(10));
178 } else {
179 $formatted[] = $lines[$i];
180 }
181 }
182 $formatted = implode(chr(10), $formatted);
183
184 return $formatted;
185 }
186
187
188
194 public function appendSignature()
195 {
196 return $this->mail_data["m_message"] .= chr(13) . chr(10) . $this->mail_options->getSignature();
197 }
198
202 public function prependSignature()
203 {
204 return $this->mail_options->getSignature() . chr(13) . chr(10) . chr(13) . chr(10) . $this->mail_data["m_message"];
205 }
206} // END class.ilFormatMail
An exception for terminatinating execution or to throw for unit testing.
Class UserMail this class handles user mails.
appendSignature()
append signature to mail body @access public
formatReplyRecipientsForCC()
get reply recipients for cc @access public
formatReplyRecipient()
get reply recipient @access public
appendSearchResult($a_names, $a_type)
append search result to recipient @access public
formatReplySubject()
format a reply subject @access public
__construct($a_user_id)
Constructor setup an mail object.
formatForwardSubject()
format a forward subject @access public
formatReplyMessage()
format a reply message @access public
formatLinebreakMessage(string $message)
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a_type
Definition: workflow.php:92
$message
Definition: xapiexit.php:14
$DIC
Definition: xapitoken.php:46