ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilFormatMail.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 class ilFormatMail extends ilMail
26 {
27  public function __construct(int $a_user_id)
28  {
29  parent::__construct($a_user_id);
30  }
31 
32  public function formatReplyRecipientsForCC(): string
33  {
34  global $DIC;
35 
36  if (empty($this->mail_data)) {
37  return '';
38  }
39 
40  $newCC = [];
41 
42  $currentUserLogin = $DIC->user()->getLogin();
43 
44  foreach (explode(',', $this->mail_data['rcp_to']) as $to) {
45  $to = trim($to);
46  if ($to !== '' && $currentUserLogin !== $to) {
47  $newCC[] = $to;
48  }
49  }
50 
51  foreach (explode(',', $this->mail_data['rcp_cc']) as $cc) {
52  $cc = trim($cc);
53  if ($cc !== '' && $currentUserLogin !== $cc) {
54  $newCC[] = $cc;
55  }
56  }
57 
58  return $this->mail_data['rcp_cc'] = implode(', ', $newCC);
59  }
60 
61  public function formatReplyRecipient(): string
62  {
63  if (empty($this->mail_data)) {
64  return '';
65  }
66 
67  $user = new ilObjUser((int) $this->mail_data['sender_id']);
68  return $this->mail_data['rcp_to'] = $user->getLogin();
69  }
70 
76  public function appendSearchResult(array $a_names, string $a_type): array
77  {
78  $name_str = implode(',', $a_names);
79 
80  $key = 'rcp_to';
81  if ('cc' === $a_type) {
82  $key = 'rcp_cc';
83  } elseif ('bc' === $a_type) {
84  $key = 'rcp_bcc';
85  }
86 
87  if (!isset($this->mail_data[$key]) || !is_string($this->mail_data[$key])) {
88  $this->mail_data[$key] = '';
89  } else {
90  $this->mail_data[$key] = trim($this->mail_data[$key]);
91  }
92 
93  if ($this->mail_data[$key] !== '') {
94  $this->mail_data[$key] .= ',';
95  }
96  $this->mail_data[$key] .= $name_str;
97 
98  return $this->mail_data;
99  }
100 
101  public function formatLinebreakMessage(string $message): string
102  {
103  $formatted = [];
104 
105  $linebreak = $this->mail_options->getLinebreak();
106 
107  $lines = explode(chr(10), $message);
108  foreach ($lines as $iValue) {
109  if (strpos($iValue, '>') !== 0) {
110  $formatted[] = wordwrap($iValue, $linebreak, chr(10));
111  } else {
112  $formatted[] = $iValue;
113  }
114  }
115  return implode(chr(10), $formatted);
116  }
117 
118  public function appendSignature(string $message): string
119  {
120  $message .= chr(13) . chr(10) . $this->mail_options->getSignature();
121 
122  return $message;
123  }
124 
125  public function prependSignature(string $message): string
126  {
127  return $this->mail_options->getSignature() .
128  chr(13) .
129  chr(10) .
130  chr(13) .
131  chr(10) .
132  $message;
133  }
134 
135  public function formatReplyMessage(string $message): string
136  {
137  $bodylines = preg_split("/\r\n|\n|\r/", $message);
138  foreach ($bodylines as $i => $iValue) {
139  $bodylines[$i] = '> ' . $iValue;
140  }
141 
142  return implode(chr(10), $bodylines);
143  }
144 
145  public function formatReplySubject(string $subject): string
146  {
147  return 'RE: ' . $subject;
148  }
149 
150  public function formatForwardSubject(string $subject): string
151  {
152  return '[FWD: ' . $subject . ']';
153  }
154 }
formatForwardSubject(string $subject)
array $mail_data
appendSignature(string $message)
appendSearchResult(array $a_names, string $a_type)
global $DIC
Definition: feed.php:28
__construct(int $a_user_id)
prependSignature(string $message)
formatLinebreakMessage(string $message)
string $key
Consumer key/client ID value.
Definition: System.php:193
formatReplyMessage(string $message)
formatReplySubject(string $subject)
__construct(Container $dic, ilPlugin $plugin)
$message
Definition: xapiexit.php:32
$i
Definition: metadata.php:41