ILIAS  release_7 Revision v7.30-3-g800a261c036
ilMimeMail Class Reference

Class ilMimeMail. More...

+ Collaboration diagram for ilMimeMail:

Public Member Functions

 __construct ()
 ilMimeMail constructor. More...
 
 Subject (string $subject, bool $addPrefix=false, string $contextPrefix='')
 
 getSubject ()
 
 From (ilMailMimeSender $sender)
 
 To ($to)
 Set the mail recipient. More...
 
 Cc ($cc)
 Set the cc mail recipient. More...
 
 Bcc ($bcc)
 Set the bcc mail recipient. More...
 
 getTo ()
 
 getCc ()
 
 getBcc ()
 
 Body (string $body)
 
 getFinalBody ()
 
 getFinalBodyAlt ()
 
 getFrom ()
 
 Attach (string $filename, string $file_type='', string $disposition='inline', ?string $display_name=null)
 Attach a file to the mail. More...
 
 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 ()
 Build the relevant email data. More...
 
 buildBodyMultiParts (string $skin)
 
 getHtmlEnvelope (string $skin)
 
 buildHtmlInlineImages (string $skin)
 

Protected Attributes

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

Static Protected Attributes

static $defaultTransport = null
 

Private Member Functions

 removeHTMLTags (string $maybeHTML)
 

Detailed Description

Class ilMimeMail.

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

Constructor & Destructor Documentation

◆ __construct()

ilMimeMail::__construct ( )

ilMimeMail constructor.

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

63 {
64 global $DIC;
65
66 $this->settings = $DIC->settings();
67
68 if (!(self::getDefaultTransport() instanceof ilMailMimeTransport)) {
69 $factory = $DIC["mail.mime.transport.factory"];
70 self::setDefaultTransport($factory->getTransport());
71 }
72
73 $this->subjectBuilder = new ilMailMimeSubjectBuilder($this->settings, self::MAIL_SUBJECT_PREFIX);
74 }
Class ilMailMimeSubjectBuilder.
static setDefaultTransport(?ilMailMimeTransport $transport)
global $DIC
Definition: goto.php:24
Interface ilMailMimeTransport.
$factory
Definition: metadata.php:58
settings()
Definition: settings.php:2

References $DIC, $factory, setDefaultTransport(), and 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 
)

Attach a file to the mail.

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 202 of file class.ilMimeMail.php.

207 : void {
208 if ($file_type === '') {
209 $file_type = 'application/octet-stream';
210 }
211
212 $this->aattach[] = $filename;
213 $this->actype[] = $file_type;
214 $this->adispo[] = $disposition;
215 $this->adisplay[] = $display_name;
216 }
$filename
Definition: buildRTE.php:89

◆ Bcc()

ilMimeMail::Bcc (   $bcc)

Set the bcc mail recipient.

Parameters
string|string[]BCC email address, accept both a single address or an array of addresses

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

142 : void
143 {
144 if (is_array($bcc)) {
145 $this->abcc = $bcc;
146 } else {
147 $this->abcc[] = $bcc;
148 }
149 }

◆ Body()

ilMimeMail::Body ( string  $body)

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

175 : void
176 {
177 $this->body = $body;
178 }

References $body.

◆ build()

ilMimeMail::build ( )
protected

Build the relevant email data.

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

253 : void
254 {
255 global $DIC;
256
257 $this->finalBodyAlt = '';
258 $this->finalBody = '';
259 $this->images = [];
260
261 if ($DIC->settings()->get('mail_send_html', 0)) {
262 $skin = $DIC['ilClientIniFile']->readVariable('layout', 'skin');
263
264 $this->buildBodyMultiParts($skin);
265 $this->buildHtmlInlineImages($skin);
266 } else {
267 $this->finalBody = $this->removeHTMLTags($this->body);
268 }
269 }
buildHtmlInlineImages(string $skin)
buildBodyMultiParts(string $skin)
removeHTMLTags(string $maybeHTML)

References $DIC.

◆ buildBodyMultiParts()

ilMimeMail::buildBodyMultiParts ( string  $skin)
protected

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

279 : void
280 {
281 if ($this->body === '') {
282 $this->body = ' ';
283 }
284
285 if (strip_tags($this->body, '<b><u><i><a>') === $this->body) {
286 // Let's assume(!) that there is no HTML (except certain tags, e.g. used for object title formatting, where the consumer is not aware of this), so convert "\n" to "<br>"
287 $this->finalBodyAlt = strip_tags($this->body);
288 $this->body = \ilUtil::makeClickable(nl2br($this->body));
289 } else {
290 // if there is HTML, convert "<br>" to "\n" and strip tags for plain text alternative
291 $this->finalBodyAlt = strip_tags(str_ireplace(["<br />", "<br>", "<br/>"], "\n", $this->body));
292 }
293
294 $this->finalBody = str_replace('{PLACEHOLDER}', $this->body, $this->getHtmlEnvelope($skin));
295 }
getHtmlEnvelope(string $skin)
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen

References ilUtil\makeClickable().

+ Here is the call graph for this function:

◆ buildHtmlInlineImages()

ilMimeMail::buildHtmlInlineImages ( string  $skin)
protected

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

312 : void
313 {
314 $this->gatherImagesFromDirectory('./Services/Mail/templates/default/img');
315
316 if ($skin !== 'default') {
317 $skinDirectory = './Customizing/global/skin/' . $skin . '/Services/Mail/img';
318 if (is_dir($skinDirectory) && is_readable($skinDirectory)) {
319 $this->gatherImagesFromDirectory($skinDirectory, true);
320 }
321 }
322 }

◆ Cc()

ilMimeMail::Cc (   $cc)

Set the cc mail recipient.

Parameters
string|string[]CC email address, accept both a single address or an array of addresses

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

129 : void
130 {
131 if (is_array($cc)) {
132 $this->acc = $cc;
133 } else {
134 $this->acc[] = $cc;
135 }
136 }

◆ From()

ilMimeMail::From ( ilMailMimeSender  $sender)

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

107 : void
108 {
109 $this->sender = $sender;
110 }

References $sender.

◆ getAttachments()

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

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

221 : array
222 {
223 $attachments = [];
224
225 $i = 0;
226 foreach ($this->aattach as $attachment) {
227 $name = '';
228 if (isset($this->adisplay[$i]) && is_string($this->adisplay[$i]) && $this->adisplay[$i] !== '') {
229 $name = $this->adisplay[$i];
230 }
231
232 $attachments[] = [
233 'path' => $attachment,
234 'name' => $name
235 ];
236 ++$i;
237 }
238
239 return $attachments;
240 }
if($format !==null) $name
Definition: metadata.php:230
$i
Definition: metadata.php:24

References $i, and $name.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getBcc()

ilMimeMail::getBcc ( )
Returns
string[]

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

170 : array
171 {
172 return $this->abcc;
173 }

References $abcc.

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

+ Here is the caller graph for this function:

◆ getCc()

ilMimeMail::getCc ( )
Returns
string[]

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

162 : array
163 {
164 return $this->acc;
165 }

References $acc.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getDefaultTransport()

static ilMimeMail::getDefaultTransport ( )
static

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

93 {
95 }
static $defaultTransport

References $defaultTransport.

Referenced by ilMailTest\testExternalMailDeliveryToLocalRecipientsWorksAsExpected().

+ Here is the caller graph for this function:

◆ getFinalBody()

ilMimeMail::getFinalBody ( )

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

180 : string
181 {
182 return $this->finalBody;
183 }

References $finalBody.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getFinalBodyAlt()

ilMimeMail::getFinalBodyAlt ( )

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

185 : string
186 {
187 return $this->finalBodyAlt;
188 }

References $finalBodyAlt.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getFrom()

ilMimeMail::getFrom ( )

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

191 {
192 return $this->sender;
193 }
Interface ilMailMimeTransport.

References $sender.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getHtmlEnvelope()

ilMimeMail::getHtmlEnvelope ( string  $skin)
protected

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

297 : string
298 {
299 $bracket_path = './Services/Mail/templates/default/tpl.html_mail_template.html';
300
301 if ($skin !== 'default') {
302 $tplpath = './Customizing/global/skin/' . $skin . '/Services/Mail/tpl.html_mail_template.html';
303
304 if (file_exists($tplpath)) {
305 $bracket_path = './Customizing/global/skin/' . $skin . '/Services/Mail/tpl.html_mail_template.html';
306 }
307 }
308
309 return file_get_contents($bracket_path);
310 }

◆ 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 245 of file class.ilMimeMail.php.

245 : array
246 {
247 return array_values($this->images);
248 }

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getSubject()

ilMimeMail::getSubject ( )

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

102 : string
103 {
104 return $this->subject;
105 }

References $subject.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ getTo()

ilMimeMail::getTo ( )
Returns
string[]

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

154 : array
155 {
156 return $this->sendto;
157 }

References $sendto.

Referenced by ilMailMimeTransportBase\send().

+ Here is the caller graph for this function:

◆ removeHTMLTags()

ilMimeMail::removeHTMLTags ( string  $maybeHTML)
private

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

271 : string
272 {
273 $maybeHTML = str_ireplace(['<br />', '<br>', '<br/>'], "\n", $maybeHTML);
274 $maybeHTML = strip_tags($maybeHTML);
275
276 return $maybeHTML;
277 }

◆ Send()

ilMimeMail::Send ( ilMailMimeTransport  $transport = null)
Parameters
$transportilMailMimeTransport|null
Returns
bool A boolean flag whether the transport might be successful

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 }
build()
Build the relevant email data.
static getDefaultTransport()
send(ilMimeMail $mail)

◆ setDefaultTransport()

static ilMimeMail::setDefaultTransport ( ?ilMailMimeTransport  $transport)
static
Parameters
ilMailMimeTransport | null$transport
Exceptions
InvalidArgumentException

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

80 : void
81 {
82 if ($transport !== null && !($transport instanceof ilMailMimeTransport)) {
83 throw new InvalidArgumentException(sprintf(
84 "The passed argument must be null or of type 'ilMailMimeTransport', %s given!",
85 gettype($transport)
86 ));
87 }
88
89 self::$defaultTransport = $transport;
90 }

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

+ Here is the caller graph for this function:

◆ Subject()

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

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

97 : void
98 {
99 $this->subject = $this->subjectBuilder->subject($subject, $addPrefix, $contextPrefix);
100 }

References $subject.

◆ To()

ilMimeMail::To (   $to)

Set the mail recipient.

Parameters
string|string[]To email address, accept both a single address or an array of addresses

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

116 : void
117 {
118 if (is_array($to)) {
119 $this->sendto = $to;
120 } else {
121 $this->sendto[] = $to;
122 }
123 }

Field Documentation

◆ $aattach

ilMimeMail::$aattach = []
protected

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

◆ $abcc

ilMimeMail::$abcc = []
protected

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

Referenced by getBcc().

◆ $acc

ilMimeMail::$acc = []
protected

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

Referenced by getCc().

◆ $actype

ilMimeMail::$actype = []
protected

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

◆ $adisplay

ilMimeMail::$adisplay = []
protected

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

◆ $adispo

ilMimeMail::$adispo = []
protected

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

◆ $body

ilMimeMail::$body = ''
protected

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

Referenced by Body().

◆ $defaultTransport

ilMimeMail::$defaultTransport = null
staticprotected

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

Referenced by getDefaultTransport().

◆ $finalBody

ilMimeMail::$finalBody = ''
protected

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

Referenced by getFinalBody().

◆ $finalBodyAlt

ilMimeMail::$finalBodyAlt = ''
protected

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

Referenced by getFinalBodyAlt().

◆ $images

ilMimeMail::$images = []
protected

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

◆ $sender

ilMimeMail::$sender
protected

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

Referenced by From(), and getFrom().

◆ $sendto

ilMimeMail::$sendto = []
protected

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

Referenced by getTo().

◆ $settings

ilMimeMail::$settings
protected

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

◆ $subject

ilMimeMail::$subject = ''
protected

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

Referenced by getSubject(), and Subject().

◆ $subjectBuilder

ilMimeMail::$subjectBuilder
protected

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

◆ MAIL_SUBJECT_PREFIX

const ilMimeMail::MAIL_SUBJECT_PREFIX = '[ILIAS]'

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

Referenced by ilObjMailGUI\populateExternalSettingsForm().


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