ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilMimeMail Class Reference

Class ilMimeMail. More...

+ Collaboration diagram for ilMimeMail:

Public Member Functions

 __construct ()
 ilMimeMail constructor. More...
 
 Subject (string $subject, bool $a_add_prefix=false)
 
 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
 

Static Protected Attributes

static $defaultTransport = null
 

Detailed Description

Class ilMimeMail.

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

Constructor & Destructor Documentation

◆ __construct()

ilMimeMail::__construct ( )

ilMimeMail constructor.

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

References $DIC, $factory, and settings().

60  {
61  global $DIC;
62 
63  $this->settings = $DIC->settings();
64 
65  if (!(self::getDefaultTransport() instanceof ilMailMimeTransport)) {
66  $factory = $DIC["mail.mime.transport.factory"];
67  self::setDefaultTransport($factory->getTransport());
68  }
69  }
settings()
Definition: settings.php:2
Interface ilMailMimeTransport.
$DIC
Definition: xapitoken.php:46
$factory
Definition: metadata.php:58
+ 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 208 of file class.ilMimeMail.php.

References $filename.

213  : void {
214  if ($file_type === '') {
215  $file_type = 'application/octet-stream';
216  }
217 
218  $this->aattach[] = $filename;
219  $this->actype[] = $file_type;
220  $this->adispo[] = $disposition;
221  $this->adisplay[] = $display_name;
222  }
$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 148 of file class.ilMimeMail.php.

148  : void
149  {
150  if (is_array($bcc)) {
151  $this->abcc = $bcc;
152  } else {
153  $this->abcc[] = $bcc;
154  }
155  }

◆ Body()

ilMimeMail::Body ( string  $body)

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

References $body.

181  : void
182  {
183  $this->body = $body;
184  }

◆ build()

ilMimeMail::build ( )
protected

Build the relevant email data.

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

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

Referenced by Send().

259  : void
260  {
261  global $DIC;
262 
263  $this->finalBodyAlt = '';
264  $this->finalBody = '';
265  $this->images = [];
266 
267  if ($DIC->settings()->get('mail_send_html', 0)) {
268  $skin = $DIC['ilClientIniFile']->readVariable('layout', 'skin');
269 
270  $this->buildBodyMultiParts($skin);
271  $this->buildHtmlInlineImages($skin);
272  } else {
273  $this->finalBody = str_ireplace(["<br />", "<br>", "<br/>"], "\n", $this->body);
274  }
275  }
buildHtmlInlineImages(string $skin)
buildBodyMultiParts(string $skin)
$DIC
Definition: xapitoken.php:46
+ 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 277 of file class.ilMimeMail.php.

References $body, getHtmlEnvelope(), and ilUtil\makeClickable().

Referenced by build().

277  : void
278  {
279  if ($this->body === '') {
280  $this->body = ' ';
281  }
282 
283  if (strip_tags($this->body, '<b><u><i><a>') === $this->body) {
284  // 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>"
285  $this->finalBodyAlt = $this->body;
286  $this->body = ilUtil::makeClickable(nl2br($this->body));
287  } else {
288  // if there is HTML, convert "<br>" to "\n" and strip tags for plain text alternative
289  $this->finalBodyAlt = strip_tags(str_ireplace(["<br />", "<br>", "<br/>"], "\n", $this->body));
290  }
291 
292  $this->finalBody = str_replace('{PLACEHOLDER}', $this->body, $this->getHtmlEnvelope($skin));
293  }
getHtmlEnvelope(string $skin)
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
+ 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 310 of file class.ilMimeMail.php.

Referenced by build().

310  : void
311  {
312  $this->gatherImagesFromDirectory('./Services/Mail/templates/default/img');
313 
314  if ($skin !== 'default') {
315  $skinDirectory = './Customizing/global/skin/' . $skin . '/Services/Mail/img';
316  if (is_dir($skinDirectory) && is_readable($skinDirectory)) {
317  $this->gatherImagesFromDirectory($skinDirectory, true);
318  }
319  }
320  }
+ Here is the caller graph for this function:

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

135  : void
136  {
137  if (is_array($cc)) {
138  $this->acc = $cc;
139  } else {
140  $this->acc[] = $cc;
141  }
142  }

◆ From()

ilMimeMail::From ( ilMailMimeSender  $sender)

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

References $sender.

113  : void
114  {
115  $this->sender = $sender;
116  }

◆ getAttachments()

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

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

References $i, and $name.

Referenced by ilMailMimeTransportBase\send().

227  : array
228  {
229  $attachments = [];
230 
231  $i = 0;
232  foreach ($this->aattach as $attachment) {
233  $name = '';
234  if (isset($this->adisplay[$i]) && is_string($this->adisplay[$i]) && $this->adisplay[$i] !== '') {
235  $name = $this->adisplay[$i];
236  }
237 
238  $attachments[] = [
239  'path' => $attachment,
240  'name' => $name
241  ];
242  ++$i;
243  }
244 
245  return $attachments;
246  }
if($format !==null) $name
Definition: metadata.php:230
$i
Definition: metadata.php:24
+ Here is the caller graph for this function:

◆ getBcc()

ilMimeMail::getBcc ( )
Returns
string[]

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

References $abcc.

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

176  : array
177  {
178  return $this->abcc;
179  }
+ Here is the caller graph for this function:

◆ getCc()

ilMimeMail::getCc ( )
Returns
string[]

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

References $acc.

Referenced by ilMailMimeTransportBase\send().

168  : array
169  {
170  return $this->acc;
171  }
+ Here is the caller graph for this function:

◆ getDefaultTransport()

static ilMimeMail::getDefaultTransport ( )
static

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

Referenced by ilMailTest\testExternalMailDeliveryToLocalRecipientsWorksAsExpected().

88  {
89  return self::$defaultTransport;
90  }
Interface ilMailMimeTransport.
+ Here is the caller graph for this function:

◆ getFinalBody()

ilMimeMail::getFinalBody ( )

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

References $finalBody.

Referenced by ilMailMimeTransportBase\send().

186  : string
187  {
188  return $this->finalBody;
189  }
+ Here is the caller graph for this function:

◆ getFinalBodyAlt()

ilMimeMail::getFinalBodyAlt ( )

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

References $finalBodyAlt.

Referenced by ilMailMimeTransportBase\send().

191  : string
192  {
193  return $this->finalBodyAlt;
194  }
+ Here is the caller graph for this function:

◆ getFrom()

ilMimeMail::getFrom ( )

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

References $sender.

Referenced by ilMailMimeTransportBase\send().

197  {
198  return $this->sender;
199  }
Interface ilMailMimeTransport.
+ Here is the caller graph for this function:

◆ getHtmlEnvelope()

ilMimeMail::getHtmlEnvelope ( string  $skin)
protected

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

Referenced by buildBodyMultiParts().

295  : string
296  {
297  $bracket_path = './Services/Mail/templates/default/tpl.html_mail_template.html';
298 
299  if ($skin !== 'default') {
300  $tplpath = './Customizing/global/skin/' . $skin . '/Services/Mail/tpl.html_mail_template.html';
301 
302  if (file_exists($tplpath)) {
303  $bracket_path = './Customizing/global/skin/' . $skin . '/Services/Mail/tpl.html_mail_template.html';
304  }
305  }
306 
307  return file_get_contents($bracket_path);
308  }
+ 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 251 of file class.ilMimeMail.php.

Referenced by ilMailMimeTransportBase\send().

251  : array
252  {
253  return array_values($this->images);
254  }
+ Here is the caller graph for this function:

◆ getSubject()

ilMimeMail::getSubject ( )

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

References $subject.

Referenced by ilMailMimeTransportBase\send().

108  : string
109  {
110  return $this->subject;
111  }
+ Here is the caller graph for this function:

◆ getTo()

ilMimeMail::getTo ( )
Returns
string[]

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

References $sendto.

Referenced by ilMailMimeTransportBase\send().

160  : array
161  {
162  return $this->sendto;
163  }
+ Here is the caller graph for this function:

◆ Send()

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

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

References build().

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

◆ setDefaultTransport()

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

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

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

75  : void
76  {
77  if ($transport !== null && !($transport instanceof ilMailMimeTransport)) {
78  throw new InvalidArgumentException(sprintf(
79  "The passed argument must be null or of type 'ilMailMimeTransport', %s given!",
80  gettype($transport)
81  ));
82  }
83 
84  self::$defaultTransport = $transport;
85  }
Interface ilMailMimeTransport.
+ Here is the caller graph for this function:

◆ Subject()

ilMimeMail::Subject ( string  $subject,
bool  $a_add_prefix = false 
)

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

References $subject, and settings().

92  : void
93  {
94  if ($a_add_prefix) {
95  // #9096
96  $subjectPrefix = $this->settings->get('mail_subject_prefix');
97  if (false === $subjectPrefix) {
98  $subjectPrefix = self::MAIL_SUBJECT_PREFIX;
99  }
100  if ($subjectPrefix !== '') {
101  $subject = $subjectPrefix . ' ' . $subject;
102  }
103  }
104 
105  $this->subject = $subject;
106  }
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

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

122  : void
123  {
124  if (is_array($to)) {
125  $this->sendto = $to;
126  } else {
127  $this->sendto[] = $to;
128  }
129  }

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(), and buildBodyMultiParts().

◆ $defaultTransport

ilMimeMail::$defaultTransport = null
staticprotected

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

◆ $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().

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