ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMimeMail Class Reference
+ Collaboration diagram for ilMimeMail:

Public Member Functions

 __construct ()
 
 Subject (string $subject, bool $addPrefix=false, string $contextPrefix='')
 
 getSubject ()
 
 From (ilMailMimeSender $sender)
 
 To ($to)
 
 Cc ($cc)
 
 Bcc ($bcc)
 
 getTo ()
 
 getCc ()
 
 getBcc ()
 
 Body (string $body)
 
 getFinalBody ()
 
 getFinalBodyAlt ()
 
 getFrom ()
 
 Attach (string $filename, string $file_type='', string $disposition='inline', ?string $display_name=null)
 
 getAttachments ()
 
 getImages ()
 
 Send (ilMailMimeTransport $transport=null)
 

Static Public Member Functions

static setDefaultTransport (?ilMailMimeTransport $transport)
 
static getDefaultTransport ()
 

Data Fields

const MAIL_SUBJECT_PREFIX = '[ILIAS]'
 

Protected Member Functions

 build ()
 
 buildBodyMultiParts (string $skin)
 
 getHtmlEnvelope (string $skin)
 
 buildHtmlInlineImages (string $skin)
 

Protected Attributes

ilMailMimeSender $sender
 
ilMailMimeSubjectBuilder $subjectBuilder
 
ilSetting $settings
 
string $subject = ''
 
string $body = ''
 
string $finalBody = ''
 
string $finalBodyAlt = ''
 
array $sendto = []
 
array $acc = []
 
array $abcc = []
 
array $images = []
 
array $aattach = []
 
array $actype = []
 
array $adispo = []
 
array $adisplay = []
 

Static Protected Attributes

static ilMailMimeTransport $defaultTransport = null
 

Private Member Functions

 removeHTMLTags (string $maybeHTML)
 

Private Attributes

Refinery $refinery
 

Detailed Description

Definition at line 23 of file class.ilMimeMail.php.

Constructor & Destructor Documentation

◆ __construct()

ilMimeMail::__construct ( )

Definition at line 52 of file class.ilMimeMail.php.

References $DIC, $factory, ILIAS\Repository\refinery(), and ILIAS\Repository\settings().

53  {
54  global $DIC;
55  $this->settings = $DIC->settings();
56 
57  if (!(self::getDefaultTransport() instanceof ilMailMimeTransport)) {
58  $factory = $DIC["mail.mime.transport.factory"];
59  self::setDefaultTransport($factory->getTransport());
60  }
61 
62  $this->subjectBuilder = new ilMailMimeSubjectBuilder($this->settings, self::MAIL_SUBJECT_PREFIX);
63  $this->refinery = $DIC->refinery();
64  }
Class ilMailMimeSubjectBuilder.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$factory
Definition: metadata.php:75
+ Here is the call graph for this function:

Member Function Documentation

◆ Attach()

ilMimeMail::Attach ( string  $filename,
string  $file_type = '',
string  $disposition = 'inline',
?string  $display_name = null 
)
Parameters
string$filenamePath of the file to attach
string$file_typeMIME-type of the file. default to 'application/x-unknown-content-type'
string$dispositionInstruct the Mailclient to display the file if possible ("inline") or always as a link ("attachment") possible values are "inline", "attachment"
string | null$display_nameFilename to use in email (if different from source file)

Definition at line 178 of file class.ilMimeMail.php.

References $filename.

183  : void {
184  if ($file_type === '') {
185  $file_type = 'application/octet-stream';
186  }
187 
188  $this->aattach[] = $filename;
189  $this->actype[] = $file_type;
190  $this->adispo[] = $disposition;
191  $this->adisplay[] = $display_name;
192  }
$filename
Definition: buildRTE.php:78

◆ Bcc()

ilMimeMail::Bcc (   $bcc)
Parameters
string|string[]$bcc BCC email address, accept both a single address or an array of addresses

Definition at line 118 of file class.ilMimeMail.php.

118  : void
119  {
120  if (is_array($bcc)) {
121  $this->abcc = $bcc;
122  } else {
123  $this->abcc[] = $bcc;
124  }
125  }

◆ Body()

ilMimeMail::Body ( string  $body)

Definition at line 151 of file class.ilMimeMail.php.

References $body.

151  : void
152  {
153  $this->body = $body;
154  }

◆ build()

ilMimeMail::build ( )
protected

Definition at line 227 of file class.ilMimeMail.php.

References $DIC, buildBodyMultiParts(), buildHtmlInlineImages(), and removeHTMLTags().

Referenced by Send().

227  : void
228  {
229  global $DIC;
230 
231  $this->finalBodyAlt = '';
232  $this->finalBody = '';
233  $this->images = [];
234 
235  if ($DIC->settings()->get('mail_send_html', '0')) {
236  $skin = $DIC['ilClientIniFile']->readVariable('layout', 'skin');
237 
238  $this->buildBodyMultiParts($skin);
239  $this->buildHtmlInlineImages($skin);
240  } else {
241  $this->finalBody = $this->removeHTMLTags($this->body);
242  }
243  }
buildHtmlInlineImages(string $skin)
removeHTMLTags(string $maybeHTML)
global $DIC
Definition: feed.php:28
buildBodyMultiParts(string $skin)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildBodyMultiParts()

ilMimeMail::buildBodyMultiParts ( string  $skin)
protected

Definition at line 252 of file class.ilMimeMail.php.

References getHtmlEnvelope(), and ILIAS\Repository\refinery().

Referenced by build().

252  : void
253  {
254  if ($this->body === '') {
255  $this->body = ' ';
256  }
257 
258  if (strip_tags($this->body, '<b><u><i><a>') === $this->body) {
259  // Let's assume(!) that there is no HTML
260  // (except certain tags, e.g. used for object title formatting, where the consumer is not aware of this),
261  // so convert "\n" to "<br>"
262  $this->finalBodyAlt = strip_tags($this->body);
263  $this->body = $this->refinery->string()->makeClickable()->transform(nl2br($this->body));
264  } else {
265  // if there is HTML, convert "<br>" to "\n" and strip tags for plain text alternative
266  $this->finalBodyAlt = strip_tags(str_ireplace(["<br />", "<br>", "<br/>"], "\n", $this->body));
267  }
268 
269  $this->finalBody = str_replace('{PLACEHOLDER}', $this->body, $this->getHtmlEnvelope($skin));
270  }
getHtmlEnvelope(string $skin)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildHtmlInlineImages()

ilMimeMail::buildHtmlInlineImages ( string  $skin)
protected

Definition at line 287 of file class.ilMimeMail.php.

Referenced by build().

287  : void
288  {
289  $this->gatherImagesFromDirectory('./Services/Mail/templates/default/img');
290 
291  if ($skin !== 'default') {
292  $skinDirectory = './Customizing/global/skin/' . $skin . '/Services/Mail/img';
293  if (is_dir($skinDirectory) && is_readable($skinDirectory)) {
294  $this->gatherImagesFromDirectory($skinDirectory, true);
295  }
296  }
297  }
+ Here is the caller graph for this function:

◆ Cc()

ilMimeMail::Cc (   $cc)
Parameters
string|string[]$cc CC email address, accept both a single address or an array of addresses

Definition at line 106 of file class.ilMimeMail.php.

106  : void
107  {
108  if (is_array($cc)) {
109  $this->acc = $cc;
110  } else {
111  $this->acc[] = $cc;
112  }
113  }

◆ From()

ilMimeMail::From ( ilMailMimeSender  $sender)

Definition at line 86 of file class.ilMimeMail.php.

References $sender.

86  : void
87  {
88  $this->sender = $sender;
89  }
ilMailMimeSender $sender

◆ getAttachments()

ilMimeMail::getAttachments ( )
Returns
array{path: string, name: string}[]

Definition at line 197 of file class.ilMimeMail.php.

References $i, and $name.

Referenced by ilMailMimeTransportBase\send().

197  : array
198  {
199  $attachments = [];
200 
201  $i = 0;
202  foreach ($this->aattach as $attachment) {
203  $name = '';
204  if (isset($this->adisplay[$i]) && is_string($this->adisplay[$i]) && $this->adisplay[$i] !== '') {
205  $name = $this->adisplay[$i];
206  }
207 
208  $attachments[] = [
209  'path' => $attachment,
210  'name' => $name
211  ];
212  ++$i;
213  }
214 
215  return $attachments;
216  }
if($format !==null) $name
Definition: metadata.php:247
$i
Definition: metadata.php:41
+ Here is the caller graph for this function:

◆ getBcc()

ilMimeMail::getBcc ( )
Returns
string[]

Definition at line 146 of file class.ilMimeMail.php.

References $abcc.

Referenced by ilMailMimeTransportBase\send(), and ilMailTest\testExternalMailDeliveryToLocalRecipientsWorksAsExpected().

146  : array
147  {
148  return $this->abcc;
149  }
+ Here is the caller graph for this function:

◆ getCc()

ilMimeMail::getCc ( )
Returns
string[]

Definition at line 138 of file class.ilMimeMail.php.

References $acc.

Referenced by ilMailMimeTransportBase\send().

138  : array
139  {
140  return $this->acc;
141  }
+ Here is the caller graph for this function:

◆ getDefaultTransport()

static ilMimeMail::getDefaultTransport ( )
static

Definition at line 71 of file class.ilMimeMail.php.

Referenced by ilMailTest\testExternalMailDeliveryToLocalRecipientsWorksAsExpected().

72  {
73  return self::$defaultTransport;
74  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ getFinalBody()

ilMimeMail::getFinalBody ( )

Definition at line 156 of file class.ilMimeMail.php.

References $finalBody.

Referenced by ilMailMimeTransportBase\send().

156  : string
157  {
158  return $this->finalBody;
159  }
+ Here is the caller graph for this function:

◆ getFinalBodyAlt()

ilMimeMail::getFinalBodyAlt ( )

Definition at line 161 of file class.ilMimeMail.php.

References $finalBodyAlt.

Referenced by ilMailMimeTransportBase\send().

161  : string
162  {
163  return $this->finalBodyAlt;
164  }
string $finalBodyAlt
+ Here is the caller graph for this function:

◆ getFrom()

ilMimeMail::getFrom ( )

Definition at line 166 of file class.ilMimeMail.php.

References $sender.

Referenced by ilMailMimeTransportBase\send().

167  {
168  return $this->sender;
169  }
Interface ilMailMimeTransport.
ilMailMimeSender $sender
+ Here is the caller graph for this function:

◆ getHtmlEnvelope()

ilMimeMail::getHtmlEnvelope ( string  $skin)
protected

Definition at line 272 of file class.ilMimeMail.php.

Referenced by buildBodyMultiParts().

272  : string
273  {
274  $bracket_path = './Services/Mail/templates/default/tpl.html_mail_template.html';
275 
276  if ($skin !== 'default') {
277  $tplpath = './Customizing/global/skin/' . $skin . '/Services/Mail/tpl.html_mail_template.html';
278 
279  if (is_file($tplpath)) {
280  $bracket_path = './Customizing/global/skin/' . $skin . '/Services/Mail/tpl.html_mail_template.html';
281  }
282  }
283 
284  return file_get_contents($bracket_path);
285  }
+ Here is the caller graph for this function:

◆ getImages()

ilMimeMail::getImages ( )
Returns
array{path: string, cid: string, name: string}[] An array of images. Each element must container to associative keys, 'path', 'cid' and 'name'

Definition at line 222 of file class.ilMimeMail.php.

Referenced by ilMailMimeTransportBase\send().

222  : array
223  {
224  return array_values($this->images);
225  }
+ Here is the caller graph for this function:

◆ getSubject()

ilMimeMail::getSubject ( )

Definition at line 81 of file class.ilMimeMail.php.

References $subject.

Referenced by ilMailMimeTransportBase\send().

81  : string
82  {
83  return $this->subject;
84  }
+ Here is the caller graph for this function:

◆ getTo()

ilMimeMail::getTo ( )
Returns
string[]

Definition at line 130 of file class.ilMimeMail.php.

References $sendto.

Referenced by ilMailMimeTransportBase\send().

130  : array
131  {
132  return $this->sendto;
133  }
+ Here is the caller graph for this function:

◆ removeHTMLTags()

ilMimeMail::removeHTMLTags ( string  $maybeHTML)
private

Definition at line 245 of file class.ilMimeMail.php.

Referenced by build().

245  : string
246  {
247  $maybeHTML = str_ireplace(['<br />', '<br>', '<br/>'], "\n", $maybeHTML);
248 
249  return strip_tags($maybeHTML);
250  }
+ Here is the caller graph for this function:

◆ Send()

ilMimeMail::Send ( ilMailMimeTransport  $transport = null)

Definition at line 320 of file class.ilMimeMail.php.

References build().

320  : bool
321  {
322  if (!($transport instanceof ilMailMimeTransport)) {
323  $transport = self::getDefaultTransport();
324  }
325 
326  $this->build();
327 
328  return $transport->send($this);
329  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
send(ilMimeMail $mail)
+ Here is the call graph for this function:

◆ setDefaultTransport()

static ilMimeMail::setDefaultTransport ( ?ilMailMimeTransport  $transport)
static

Definition at line 66 of file class.ilMimeMail.php.

Referenced by ilMailMimeTest\setUp(), and ilMailTest\testExternalMailDeliveryToLocalRecipientsWorksAsExpected().

66  : void
67  {
68  self::$defaultTransport = $transport;
69  }
+ Here is the caller graph for this function:

◆ Subject()

ilMimeMail::Subject ( string  $subject,
bool  $addPrefix = false,
string  $contextPrefix = '' 
)

Definition at line 76 of file class.ilMimeMail.php.

76  : void
77  {
78  $this->subject = $this->subjectBuilder->subject($subject, $addPrefix, $contextPrefix);
79  }

◆ To()

ilMimeMail::To (   $to)
Parameters
string|string[]$to To email address, accept both a single address or an array of addresses

Definition at line 94 of file class.ilMimeMail.php.

94  : void
95  {
96  if (is_array($to)) {
97  $this->sendto = $to;
98  } else {
99  $this->sendto[] = $to;
100  }
101  }

Field Documentation

◆ $aattach

array ilMimeMail::$aattach = []
protected

Definition at line 43 of file class.ilMimeMail.php.

◆ $abcc

array ilMimeMail::$abcc = []
protected

Definition at line 39 of file class.ilMimeMail.php.

Referenced by getBcc().

◆ $acc

array ilMimeMail::$acc = []
protected

Definition at line 37 of file class.ilMimeMail.php.

Referenced by getCc().

◆ $actype

array ilMimeMail::$actype = []
protected

Definition at line 45 of file class.ilMimeMail.php.

◆ $adisplay

array ilMimeMail::$adisplay = []
protected

Definition at line 49 of file class.ilMimeMail.php.

◆ $adispo

array ilMimeMail::$adispo = []
protected

Definition at line 47 of file class.ilMimeMail.php.

◆ $body

string ilMimeMail::$body = ''
protected

Definition at line 31 of file class.ilMimeMail.php.

Referenced by Body().

◆ $defaultTransport

ilMailMimeTransport ilMimeMail::$defaultTransport = null
staticprotected

Definition at line 26 of file class.ilMimeMail.php.

◆ $finalBody

string ilMimeMail::$finalBody = ''
protected

Definition at line 32 of file class.ilMimeMail.php.

Referenced by getFinalBody().

◆ $finalBodyAlt

string ilMimeMail::$finalBodyAlt = ''
protected

Definition at line 33 of file class.ilMimeMail.php.

Referenced by getFinalBodyAlt().

◆ $images

array ilMimeMail::$images = []
protected

Definition at line 41 of file class.ilMimeMail.php.

◆ $refinery

Refinery ilMimeMail::$refinery
private

Definition at line 50 of file class.ilMimeMail.php.

◆ $sender

ilMailMimeSender ilMimeMail::$sender
protected

Definition at line 27 of file class.ilMimeMail.php.

Referenced by From(), and getFrom().

◆ $sendto

array ilMimeMail::$sendto = []
protected

Definition at line 35 of file class.ilMimeMail.php.

Referenced by getTo().

◆ $settings

ilSetting ilMimeMail::$settings
protected

Definition at line 29 of file class.ilMimeMail.php.

◆ $subject

string ilMimeMail::$subject = ''
protected

Definition at line 30 of file class.ilMimeMail.php.

Referenced by getSubject().

◆ $subjectBuilder

ilMailMimeSubjectBuilder ilMimeMail::$subjectBuilder
protected

Definition at line 28 of file class.ilMimeMail.php.

◆ MAIL_SUBJECT_PREFIX

const ilMimeMail::MAIL_SUBJECT_PREFIX = '[ILIAS]'

Definition at line 25 of file class.ilMimeMail.php.

Referenced by ilObjMailGUI\populateExternalSettingsForm().


The documentation for this class was generated from the following file: