ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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

final const MAIL_SUBJECT_PREFIX = '[ILIAS]'
 

Protected Member Functions

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

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)
 
 getPathToRootDirectory ()
 

Private Attributes

readonly Refinery $refinery
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilMimeMail::__construct ( )

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

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

55  {
56  global $DIC;
57  $this->settings = $DIC->settings();
58 
59  if (!(self::getDefaultTransport() instanceof ilMailMimeTransport)) {
60  $factory = $DIC->mail()->mime()->transportFactory();
61  self::setDefaultTransport($factory->getTransport());
62  }
63 
64  $this->subjectBuilder = new ilMailMimeSubjectBuilder($this->settings, self::MAIL_SUBJECT_PREFIX);
65  $this->refinery = $DIC->refinery();
66  }
Class ilMailMimeSubjectBuilder.
Interface ilMailMimeTransport.
global $DIC
Definition: shib_login.php:22
+ 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 180 of file class.ilMimeMail.php.

References $filename.

185  : void {
186  if ($file_type === '') {
187  $file_type = 'application/octet-stream';
188  }
189 
190  $this->aattach[] = $filename;
191  $this->actype[] = $file_type;
192  $this->adispo[] = $disposition;
193  $this->adisplay[] = $display_name;
194  }
$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 120 of file class.ilMimeMail.php.

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

◆ Body()

ilMimeMail::Body ( string  $body)

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

References $body.

153  : void
154  {
155  $this->body = $body;
156  }

◆ build()

ilMimeMail::build ( )
protected

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

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

Referenced by Send().

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

◆ buildBodyMultiParts()

ilMimeMail::buildBodyMultiParts ( string  $skin,
string  $style 
)
protected

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

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

Referenced by build().

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

◆ buildHtmlInlineImages()

ilMimeMail::buildHtmlInlineImages ( string  $skin,
string  $style 
)
protected

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

References $location, and getPathToRootDirectory().

Referenced by build().

302  : void
303  {
304  $this->gatherImagesFromDirectory(
305  $this->getPathToRootDirectory() . '/components/ILIAS/Mail/templates/default/img'
306  );
307 
308  if ($skin !== 'default') {
309  $locations = [
310  $skin,
311  $skin . '/' . $style
312  ];
313 
314  foreach ($locations as $location) {
315  $custom_directory = $this->getPathToRootDirectory(
316  ) . '/public/Customizing/skin/' . $location . '/components/ILIAS/Mail/img';
317  if (is_dir($custom_directory) && is_readable($custom_directory)) {
318  $this->gatherImagesFromDirectory($custom_directory, true);
319  break;
320  }
321  }
322  }
323  }
$location
Definition: buildRTE.php:22
+ Here is the call graph for this function:
+ 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 108 of file class.ilMimeMail.php.

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

◆ From()

ilMimeMail::From ( ilMailMimeSender  $sender)

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

References $sender.

88  : void
89  {
90  $this->sender = $sender;
91  }
ilMailMimeSender $sender

◆ getAttachments()

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

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

Referenced by ilMailMimeTransportBase\send().

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

◆ getBcc()

ilMimeMail::getBcc ( )
Returns
string[]

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

References $abcc.

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

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

◆ getCc()

ilMimeMail::getCc ( )
Returns
string[]

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

References $acc.

Referenced by ilMailMimeTransportBase\send().

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

◆ getDefaultTransport()

static ilMimeMail::getDefaultTransport ( )
static

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

Referenced by ilMailTest\testExternalMailDeliveryToLocalRecipientsWorksAsExpected().

74  {
75  return self::$defaultTransport;
76  }
Interface ilMailMimeTransport.
+ Here is the caller graph for this function:

◆ getFinalBody()

ilMimeMail::getFinalBody ( )

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

References $finalBody.

Referenced by ilMailMimeTransportBase\send().

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

◆ getFinalBodyAlt()

ilMimeMail::getFinalBodyAlt ( )

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

References $finalBodyAlt.

Referenced by ilMailMimeTransportBase\send().

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

◆ getFrom()

ilMimeMail::getFrom ( )

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

References $sender.

Referenced by ilMailMimeTransportBase\send().

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

◆ getHtmlEnvelope()

ilMimeMail::getHtmlEnvelope ( string  $skin,
string  $style 
)
protected

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

References $location, and getPathToRootDirectory().

Referenced by buildBodyMultiParts().

280  : string
281  {
282  $bracket_path = $this->getPathToRootDirectory() . '/components/ILIAS/Mail/templates/default/tpl.html_mail_template.html';
283  if ($skin !== 'default') {
284  $locations = [
285  $skin,
286  $skin . '/' . $style
287  ];
288 
289  foreach ($locations as $location) {
290  $custom_path = $this->getPathToRootDirectory(
291  ) . '/public/Customizing/skin/' . $location . '/components/ILIAS/Mail/tpl.html_mail_template.html';
292  if (is_file($custom_path)) {
293  $bracket_path = $custom_path;
294  break;
295  }
296  }
297  }
298 
299  return file_get_contents($bracket_path);
300  }
$location
Definition: buildRTE.php:22
+ Here is the call graph for this function:
+ 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 224 of file class.ilMimeMail.php.

Referenced by ilMailMimeTransportBase\send().

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

◆ getPathToRootDirectory()

ilMimeMail::getPathToRootDirectory ( )
private

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

Referenced by buildHtmlInlineImages(), and getHtmlEnvelope().

275  : string
276  {
277  return realpath(dirname(__DIR__, 4) . '/');
278  }
+ Here is the caller graph for this function:

◆ getSubject()

ilMimeMail::getSubject ( )

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

References $subject.

Referenced by ilMailMimeTransportBase\send().

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

◆ getTo()

ilMimeMail::getTo ( )
Returns
string[]

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

References $sendto.

Referenced by ilMailMimeTransportBase\send().

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

◆ removeHTMLTags()

ilMimeMail::removeHTMLTags ( string  $maybeHTML)
private

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

Referenced by build().

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

◆ Send()

ilMimeMail::Send ( ?ilMailMimeTransport  $transport = null)

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

References build().

346  : bool
347  {
348  if (!($transport instanceof ilMailMimeTransport)) {
349  $transport = self::getDefaultTransport();
350  }
351 
352  $this->build();
353 
354  return $transport->send($this);
355  }
Interface ilMailMimeTransport.
+ Here is the call graph for this function:

◆ setDefaultTransport()

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

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

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

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

◆ Subject()

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

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

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

◆ To()

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

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

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

Field Documentation

◆ $aattach

array ilMimeMail::$aattach = []
protected

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

◆ $abcc

array ilMimeMail::$abcc = []
protected

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

Referenced by getBcc().

◆ $acc

array ilMimeMail::$acc = []
protected

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

Referenced by getCc().

◆ $actype

array ilMimeMail::$actype = []
protected

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

◆ $adisplay

array ilMimeMail::$adisplay = []
protected

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

◆ $adispo

array ilMimeMail::$adispo = []
protected

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

◆ $body

string ilMimeMail::$body = ''
protected

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

Referenced by Body().

◆ $defaultTransport

ilMailMimeTransport ilMimeMail::$defaultTransport = null
staticprotected

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

◆ $finalBody

string ilMimeMail::$finalBody = ''
protected

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

Referenced by getFinalBody().

◆ $finalBodyAlt

string ilMimeMail::$finalBodyAlt = ''
protected

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

Referenced by getFinalBodyAlt().

◆ $images

array ilMimeMail::$images = []
protected

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

◆ $refinery

readonly Refinery ilMimeMail::$refinery
private

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

◆ $sender

ilMailMimeSender ilMimeMail::$sender
protected

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

Referenced by From(), and getFrom().

◆ $sendto

array ilMimeMail::$sendto = []
protected

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

Referenced by getTo().

◆ $settings

ilSetting ilMimeMail::$settings
protected

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

◆ $subject

string ilMimeMail::$subject = ''
protected

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

Referenced by getSubject().

◆ $subjectBuilder

ilMailMimeSubjectBuilder ilMimeMail::$subjectBuilder
protected

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

◆ MAIL_SUBJECT_PREFIX

final 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: