ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMimeMail Class Reference
+ Collaboration diagram for ilMimeMail:

Public Member Functions

 __construct ()
 
 Subject (string $subject, bool $add_prefix=false, string $context_prefix='')
 
 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 string 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 $subject_builder
 
ilSetting $settings
 
string $subject = ''
 
string $body = ''
 
string $final_body = ''
 
string $final_body_alt = ''
 
array $sendto = []
 
array $acc = []
 
array $abcc = []
 
array $images = []
 
array $aattach = []
 
array $actype = []
 
array $adispo = []
 
array $adisplay = []
 

Static Protected Attributes

static ilMailMimeTransport $default_transport = null
 

Private Member Functions

 removeHTMLTags (string $maybe_html)
 
 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.

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->subject_builder = new ilMailMimeSubjectBuilder($this->settings, self::MAIL_SUBJECT_PREFIX);
65 $this->refinery = $DIC->refinery();
66 }
static setDefaultTransport(?ilMailMimeTransport $transport)
global $DIC
Definition: shib_login.php:26

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

+ 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.

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[]$bccBCC 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.

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

References $body.

◆ build()

ilMimeMail::build ( )
protected

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

229 : void
230 {
231 global $DIC;
232
233 $this->final_body_alt = '';
234 $this->final_body = '';
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->final_body = $this->removeHTMLTags($this->body);
245 }
246 }
removeHTMLTags(string $maybe_html)
buildBodyMultiParts(string $skin, string $style)
buildHtmlInlineImages(string $skin, string $style)

References $DIC.

◆ buildBodyMultiParts()

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

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

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->final_body_alt = 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->final_body_alt = strip_tags(str_ireplace(["<br />", "<br>", "<br/>"], "\n", $this->body));
270 }
271
272 $this->final_body = str_replace('{PLACEHOLDER}', $this->body, $this->getHtmlEnvelope($skin, $style));
273 }
getHtmlEnvelope(string $skin, string $style)

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ buildHtmlInlineImages()

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

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

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

References $location.

◆ Cc()

ilMimeMail::Cc (   $cc)
Parameters
string | string[]$ccCC 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.

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

References $sender.

◆ getAttachments()

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

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

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 }

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getBcc()

ilMimeMail::getBcc ( )
Returns
string[]

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

148 : array
149 {
150 return $this->abcc;
151 }

References $abcc.

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

+ Here is the caller graph for this function:

◆ getCc()

ilMimeMail::getCc ( )
Returns
string[]

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

140 : array
141 {
142 return $this->acc;
143 }

References $acc.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getDefaultTransport()

static ilMimeMail::getDefaultTransport ( )
static

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

74 {
76 }
static ilMailMimeTransport $default_transport

References $default_transport.

Referenced by ilMailTest\testExternalMailDeliveryWorksAsExpected().

+ Here is the caller graph for this function:

◆ getFinalBody()

ilMimeMail::getFinalBody ( )

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

158 : string
159 {
160 return $this->final_body;
161 }
string $final_body

References $final_body.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getFinalBodyalt()

ilMimeMail::getFinalBodyalt ( )

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

163 : string
164 {
166 }
string $final_body_alt

References $final_body_alt.

Referenced by ilMailMimeTransportBase\send().

+ 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().

+ 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.

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 }

References $location.

◆ 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.

224 : array
225 {
226 return array_values($this->images);
227 }

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getPathToRootDirectory()

ilMimeMail::getPathToRootDirectory ( )
private

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

275 : string
276 {
277 return realpath(dirname(__DIR__, 4) . '/');
278 }

◆ getSubject()

ilMimeMail::getSubject ( )

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

83 : string
84 {
85 return $this->subject;
86 }

References $subject.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getTo()

ilMimeMail::getTo ( )
Returns
string[]

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

132 : array
133 {
134 return $this->sendto;
135 }

References $sendto.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ removeHTMLTags()

ilMimeMail::removeHTMLTags ( string  $maybe_html)
private

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

248 : string
249 {
250 $maybe_html = str_ireplace(['<br />', '<br>', '<br/>'], "\n", $maybe_html);
251
252 return strip_tags($maybe_html);
253 }

◆ Send()

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

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

346 : bool
347 {
348 if (!($transport instanceof ilMailMimeTransport)) {
349 $transport = self::getDefaultTransport();
350 }
351
352 $this->build();
353
354 return $transport->send($this);
355 }
static getDefaultTransport()

◆ setDefaultTransport()

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

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

68 : void
69 {
70 self::$default_transport = $transport;
71 }

Referenced by __construct(), ilMailMimeTest\setUp(), and ilMailTest\testExternalMailDeliveryWorksAsExpected().

+ Here is the caller graph for this function:

◆ Subject()

ilMimeMail::Subject ( string  $subject,
bool  $add_prefix = false,
string  $context_prefix = '' 
)

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

78 : void
79 {
80 $this->subject = $this->subject_builder->subject($subject, $add_prefix, $context_prefix);
81 }

References $subject.

◆ To()

ilMimeMail::To (   $to)
Parameters
string | string[]$toTo 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().

◆ $default_transport

ilMailMimeTransport ilMimeMail::$default_transport = null
staticprotected

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

Referenced by getDefaultTransport().

◆ $final_body

string ilMimeMail::$final_body = ''
protected

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

Referenced by getFinalBody().

◆ $final_body_alt

string ilMimeMail::$final_body_alt = ''
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(), and Subject().

◆ $subject_builder

ilMailMimeSubjectBuilder ilMimeMail::$subject_builder
protected

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

◆ MAIL_SUBJECT_PREFIX

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