ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilMail Class Reference

Class Mail this class handles base functions for mail handling. More...

+ Inheritance diagram for ilMail:
+ Collaboration diagram for ilMail:

Public Member Functions

 __construct ($a_user_id)
 Constructor setup an mail object @access public. More...
 
 __get ($name)
 Magic interceptor method __get Used to include files / instantiate objects at runtime. More...
 
 doesRecipientStillExists ($a_recipient, $a_existing_recipients)
 
 enableSOAP ($a_status)
 
 isSOAPEnabled ()
 
 setSaveInSentbox ($a_save_in_sentbox)
 
 getSaveInSentbox ()
 
 setMailSendType ($a_types)
 
 setMailRcpTo ($a_rcp_to)
 
 setMailRcpCc ($a_rcp_cc)
 
 setMailRcpBc ($a_rcp_bc)
 
 setMailSubject ($a_subject)
 
 setMailMessage ($a_message)
 
 readMailObjectReferenceId ()
 read and set mail object id @access private More...
 
 getMailObjectReferenceId ()
 
 formatNamesForOutput ($users='')
 Prepends the fullname of each ILIAS login name (is user has a public profile) found in the passed string and brackets the ILIAS login name afterwards. More...
 
 getPreviousMail ($a_mail_id)
 
 getNextMail ($a_mail_id)
 
 getMailsOfFolder ($a_folder_id, $filter=array())
 
 countMailsOfFolder ($a_folder_id)
 count all mails of a specific folder @access public More...
 
 deleteMailsOfFolder ($a_folder_id)
 delete all mails of a specific folder @access public More...
 
 getMailCounterData ()
 get mail counter data returns data array with indexes "total","read","unread" @access public More...
 
 getMail ($a_mail_id)
 get data of one mail @access public More...
 
 markRead ($a_mail_ids)
 mark mails as read @access public More...
 
 markUnread ($a_mail_ids)
 mark mails as unread @access public More...
 
 moveMailsToFolder ($a_mail_ids, $a_folder_id)
 move mail to folder @access public More...
 
 deleteMails (array $a_mail_ids)
 Delete mails. More...
 
 fetchMailData ($a_row)
 fetch all query data from table mail @access public More...
 
 getNewDraftId ($usrId, $folderId)
 
 updateDraft ( $a_folder_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_type, $a_m_email, $a_m_subject, $a_m_message, $a_draft_id=0, $a_use_placeholders=0, $a_tpl_context_id=null, $a_tpl_context_params=array())
 
 sendInternalMail ($a_folder_id, $a_sender_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_status, $a_m_type, $a_m_email, $a_m_subject, $a_m_message, $a_user_id=0, $a_use_placeholders=0, $a_tpl_context_id=null, $a_tpl_context_params=array())
 save mail in folder @access private More...
 
 distributeMail ($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_subject, $a_message, $a_attachments, $sent_mail_id, $a_type, $a_action, $a_use_placeholders=0)
 send internal message to recipients @access private More...
 
 getUserIds ($a_recipients)
 get user_ids More...
 
 checkMail ($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_type)
 check if mail is complete, recipients are valid @access public More...
 
 getEmailsOfRecipients ($a_rcp)
 get email addresses of recipients @access public More...
 
 checkRecipients ($a_recipients)
 check if recipients are valid @access public More...
 
 savePostData ($a_user_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_type, $a_m_email, $a_m_subject, $a_m_message, $a_use_placeholders, $a_tpl_context_id=null, $a_tpl_ctx_params=array())
 save post data in table @access public More...
 
 getSavedData ()
 get saved data @access public More...
 
 validateRecipients ($a_rcp_to, $a_rcp_cc, $a_rcp_bc)
 
 sendMail ($a_rcp_to, $a_rcp_cc, $a_rcp_bc, $a_m_subject, $a_m_message, $a_attachment, $a_type, $a_use_placeholders=0)
 send external mail using class.ilMimeMail.php More...
 
 parseRcptOfMailingLists ($rcpt='', $maintain_lists=false)
 
 saveInSentbox ($a_attachment, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_type, $a_m_subject, $a_m_message)
 send mime mail using class.ilMimeMail.php More...
 
 sendMimeMail ($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_attachments, $a_no_soap=false)
 send mime mail using class.ilMimeMail.php All external mails are send to SOAP::sendMail starting a kind of background process More...
 
 getEmailOfSender ()
 get email of sender @access public More...
 
 saveAttachments ($a_attachments)
 set attachments More...
 
 getAttachments ()
 get attachments @access public More...
 
 explodeRecipients ($a_recipients, $use_pear=true)
 explode recipient string allowed seperators are ',' ';' ' ' More...
 
 __getCountRecipient ($rcp, $a_only_email=true)
 
 __getCountRecipients ($a_to, $a_cc, $a_bcc, $a_only_email=true)
 
 __getEmailRecipients ($a_rcp)
 
 __prependMessage ($a_m_message, $rcp_to, $rcp_cc)
 
 __substituteRecipients ($a_rcp, $direction)
 Note: This function can only be used, when ILIAS is configured to not use standards compliant mail addresses. More...
 
 appendInstallationSignature ($a_flag=null)
 Setter/Getter for appending the installation signarue. More...
 

Static Public Member Functions

static addFullname ($a_email, $a_fullname)
 
static getIliasMailerAddress ()
 Builds an email address used for system notifications. More...
 
static _getUserInternalMailboxAddress ($usr_id, $login=null, $firstname=null, $lastname=null)
 
static _getAutoGeneratedMessageString ($lang=null)
 get auto generated info string More...
 
static _getInstallationSignature ()
 Static getter for the installation signature. More...
 
static getSubjectPrefix ()
 Get text that will be prepended to auto generated mails. More...
 
static getSalutation ($a_usr_id, $a_language=null)
 Get salutation. More...
 

Data Fields

 $ilias
 
 $lng
 
 $mfile
 
 $mail_options
 
 $user_id
 
 $table_mail
 
 $table_mail_saved
 
 $mail_counter
 
 $mail_data
 
 $mail_obj_ref_id
 
 $mail_send_type
 
 $save_in_sentbox
 
 $mail_rcp_to
 
 $mail_rcp_cc
 
 $mail_rcp_bc
 
 $mail_subject
 
 $mail_message
 
 $mail_use_placeholders = 0
 
 $soap_enabled = true
 
 $mail_to_global_roles = 0
 
const ILIAS_HOST = 'ilias'
 

Protected Member Functions

 replacePlaceholders ($a_message, $a_user_id=0)
 

Static Protected Member Functions

static getCachedUserInstance ($a_usr_id)
 Returns a cached instance of ilObjUser. More...
 

Protected Attributes

 $appendInstallationSignature = false
 
 $properties = array()
 

Static Protected Attributes

static $userInstances = array()
 

Private Member Functions

 setUsePear ($bool)
 
 getUsePear ()
 
 validatePear ($a_recipients)
 

Private Attributes

 $use_pear = true
 

Detailed Description

Class Mail this class handles base functions for mail handling.

RFC 822 compliant e-mail addresses

If ILIAS is configured to use standards compliant e-mail addresses, then this class supports RFC 822 compliant address lists as specified in http://www.ietf.org/rfc/rfc0822.txt

Examples: The following mailbox addresses work for sending an e-mail to the user with the login john.doe and e-mail address jd@ma.nosp@m.il.c.nosp@m.om. The user is member of the course "French Course". The member role of the course object has the name "il_crs_member_998" and the object ID "1000".

john.doe John Doe <john.doe> john.doe@ilias #member@[French Course] #il_crs_member_998 #il_role_1000 jd@ma.nosp@m.il.c.nosp@m.om John Doe jd@ma.nosp@m.il.c.nosp@m.om

Syntax Rules: The following excerpt from chapter 6.1 "Syntax" of RFC 822 is relevant for the semantics described below:

addr-spec = local-part [ "@", domain ]

Semantics: User account mailbox address:

  • The local-part denotes the login of an ILIAS user account.
  • The domain denotes the current ILIAS client.
  • The local-part must not start with a "#" character
  • The domain must be omitted or must have the value "ilias"

Role object mailbox address:

  • The local part denotes the title of an ILIAS role.
  • The domain denotes the title of an ILIAS object.
  • The local-part must start with a "#" character.
  • If the domain is omitted, the title "ilias" is assumed.
  • If the local-part starts with "#il_role_" its remaining characters directly specify the object id of the role. For example "#il_role_1234 identifies the role with object id "1234". - If the object title identifies an object that is an ILIAS role, then the local-part is ignored. - If the object title identifies an object that is not an ILIAS role, then the local-part is used to identify a local role for that object. - The local-part can be a substring of the role name. For example, "#member" can be used instead of "#il_crs_member_1234". External E-Mail address: - The local-part must not start with a "#" character - The domain must be specified and it must not have the value "ilias" <h2>Non-compliant e-mail addresses </h2> If ILIAS is not configured to use standards compliant e-mail addresses, then the following description applies: Examples: The following mailbox addresses work for sending an e-mail to the user with the login john.doe, who is member of the course "French Course". Assuming that the member role of the course object has the name "il_crs_member_998" and the object ID "1000". john.doe #il_crs_member_998 #il_role_1000 jd@mail.com Syntax: The following syntax rule is relevant for the semantics described below: addr-spec = local-part [ "", domain ]

Semantics: User account mailbox address:

  • The local-part denotes the login of an ILIAS user account.
  • The domain must be omitted.
  • The local-part must not start with a "#" character

Role object mailbox address:

  • The local part denotes the title of an ILIAS role.
  • The local-part must start with a "#" character.
  • The domain must be omitted.
  • If the local-part start with "#il_role_" its remaining characters directly specify the object id of the role. For example "#il_role_1234 identifies the role with object id "1234". External E-Mail address: - The local-part must not start with a "#" character - The domain must be specified and it must not have the value "ilias"
Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 109 of file class.ilMail.php.

Constructor & Destructor Documentation

◆ __construct()

ilMail::__construct (   $a_user_id)

Constructor setup an mail object @access public.

Parameters
integeruser_id

Reimplemented in ilFormatMail.

Definition at line 236 of file class.ilMail.php.

237 {
238 require_once "./Services/Mail/classes/class.ilFileDataMail.php";
239 require_once "Services/Mail/classes/class.ilMailOptions.php";
240
241 global $ilias, $lng, $ilUser;
242
243 $lng->loadLanguageModule("mail");
244
245 // Initiate variables
246 $this->ilias =& $ilias;
247 $this->lng =& $lng;
248 $this->table_mail = 'mail';
249 $this->table_mail_saved = 'mail_saved';
250 $this->user_id = $a_user_id;
251 $this->mfile = new ilFileDataMail($this->user_id);
252 $this->mail_options = new ilMailOptions($a_user_id);
253
254 // DEFAULT: sent mail aren't stored insentbox of user.
255 $this->setSaveInSentbox(false);
256
257 // GET REFERENCE ID OF MAIL OBJECT
259 }
This class handles all operations on files (attachments) in directory ilias_data/mail.
Class UserMail this class handles user mails.
setSaveInSentbox($a_save_in_sentbox)
readMailObjectReferenceId()
read and set mail object id @access private
redirection script todo: (a better solution should control the processing via a xml file)
global $ilUser
Definition: imgupload.php:15

References $ilias, $ilUser, $lng, readMailObjectReferenceId(), and setSaveInSentbox().

+ Here is the call graph for this function:

Member Function Documentation

◆ __get()

ilMail::__get (   $name)

Magic interceptor method __get Used to include files / instantiate objects at runtime.

Parameters
stringThe name of the class property

Definition at line 268 of file class.ilMail.php.

269 {
270 global $ilUser;
271
272 if(isset($this->properties[$name]))
273 {
274 return $this->properties[$name];
275 }
276
277 // Used to include files / instantiate objects at runtime
278 if($name == 'mlists')
279 {
280 if(is_object($ilUser))
281 {
282 require_once 'Services/Contact/classes/class.ilMailingLists.php';
283 $this->properties[$name] = new ilMailingLists($ilUser);
284 return $this->properties[$name];
285 }
286 }
287 }

References $ilUser.

◆ __getCountRecipient()

ilMail::__getCountRecipient (   $rcp,
  $a_only_email = true 
)

Definition at line 2571 of file class.ilMail.php.

2572 {
2573 $counter = 0;
2574
2575 $this->validatePear($rcp);
2576 if (ilMail::_usePearMail() && $this->getUsePear())
2577 {
2578 $tmp_rcp = $this->explodeRecipients($rcp);
2579 if (! is_a($tmp_rcp, 'PEAR_Error'))
2580 {
2581 foreach ($tmp_rcp as $to)
2582 {
2583 if ($a_only_email)
2584 {
2585 // Fixed mantis bug #5875
2586 if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2587 {
2588 continue;
2589 }
2590
2591 // Addresses which aren't on the self::ILIAS_HOST host, and
2592 // which have a mailbox which does not start with '#',
2593 // are external e-mail addresses
2594 if ($to->host != self::ILIAS_HOST && substr($to->mailbox,0,1) != '#' && substr($to->mailbox,0,2) != '"#')
2595 {
2596 ++$counter;
2597 }
2598 }
2599 else
2600 {
2601 ++$counter;
2602 }
2603 }
2604 }
2605 }
2606 else
2607 {
2608 foreach ($this->explodeRecipients($rcp,$this->getUsePear()) as $to)
2609 {
2610 if ($a_only_email)
2611 {
2612 $to = $this->__substituteRecipients($to,"resubstitute");
2613 if (strpos($to,'@'))
2614 {
2615 // Fixed mantis bug #5875
2616 if(ilObjUser::_lookupId($to))
2617 {
2618 continue;
2619 }
2620
2621 ++$counter;
2622 }
2623 }
2624 else
2625 {
2626 ++$counter;
2627 }
2628 }
2629 }
2630 return $counter;
2631 }
explodeRecipients($a_recipients, $use_pear=true)
explode recipient string allowed seperators are ',' ';' ' '
__substituteRecipients($a_rcp, $direction)
Note: This function can only be used, when ILIAS is configured to not use standards compliant mail ad...
validatePear($a_recipients)
static _lookupId($a_user_str)
Lookup id by login.

References __substituteRecipients(), ilObjUser\_lookupId(), explodeRecipients(), getUsePear(), and validatePear().

Referenced by __getCountRecipients().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __getCountRecipients()

ilMail::__getCountRecipients (   $a_to,
  $a_cc,
  $a_bcc,
  $a_only_email = true 
)

Definition at line 2634 of file class.ilMail.php.

2635 {
2636 return $this->__getCountRecipient($a_to,$a_only_email)
2637 + $this->__getCountRecipient($a_cc,$a_only_email)
2638 + $this->__getCountRecipient($a_bcc,$a_only_email);
2639 }
__getCountRecipient($rcp, $a_only_email=true)

References __getCountRecipient().

Referenced by sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __getEmailRecipients()

ilMail::__getEmailRecipients (   $a_rcp)

Definition at line 2641 of file class.ilMail.php.

2642 {
2643 if (ilMail::_usePearMail())
2644 {
2645 $rcp = array();
2646 $tmp_rcp = $this->explodeRecipients($a_rcp);
2647 if (! is_a($tmp_rcp, 'PEAR_Error'))
2648 {
2649 foreach ($tmp_rcp as $to)
2650 {
2651 if(substr($to->mailbox,0,1) != '#' && substr($to->mailbox,0,2) != '"#' && $to->host != self::ILIAS_HOST)
2652 {
2653 // Fixed mantis bug #5875
2654 if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2655 {
2656 continue;
2657 }
2658
2659 $rcp[] = $to->mailbox.'@'.$to->host;
2660 }
2661 }
2662 }
2663 return implode(',',$rcp);
2664 }
2665 else
2666 {
2667 foreach ($this->explodeRecipients($a_rcp) as $to)
2668 {
2669 $to = $this->__substituteRecipients($to,"resubstitute");
2670 if(strpos($to,'@'))
2671 {
2672 // Fixed mantis bug #5875
2673 if(ilObjUser::_lookupId($to))
2674 {
2675 continue;
2676 }
2677
2678 $rcp[] = $to;
2679 }
2680 }
2681 return implode(',',$rcp ? $rcp : array());
2682 }
2683 }

References __substituteRecipients(), ilObjUser\_lookupId(), and explodeRecipients().

Referenced by sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __prependMessage()

ilMail::__prependMessage (   $a_m_message,
  $rcp_to,
  $rcp_cc 
)

Definition at line 2685 of file class.ilMail.php.

2686 {
2687 $inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 3";
2688
2689 $message = $inst_name." To:".$rcp_to."\n";
2690
2691 if ($rcp_cc)
2692 {
2693 $message .= "Cc: ".$rcp_cc;
2694 }
2695
2696 $message .= "\n\n";
2697 $message .= $a_m_message;
2698
2699 return $message;
2700 }

◆ __substituteRecipients()

ilMail::__substituteRecipients (   $a_rcp,
  $direction 
)

Note: This function can only be used, when ILIAS is configured to not use standards compliant mail addresses.

If standards compliant mail addresses are used, substitution is not supported, because then we do the parsing of mail addresses using the Pear Mail Extension.

Definition at line 2709 of file class.ilMail.php.

2710 {
2711 $new_name = array();
2712
2713 $tmp_names = $this->explodeRecipients($a_rcp);
2714
2715
2716 foreach($tmp_names as $name)
2717 {
2718 if(strpos($name,"#") === 0)
2719 {
2720 $new_name[] = $name;
2721 continue;
2722 }
2723 switch($direction)
2724 {
2725 case "substitute":
2726 if(strpos($name,"@") and ilObjUser::_loginExists($name))
2727 {
2728 $new_name[] = preg_replace("/@/","�#�",$name);
2729 }
2730 else
2731 {
2732 $new_name[] = $name;
2733 }
2734 break;
2735
2736 case "resubstitute":
2737 if(stristr($name,"�#�"))
2738 {
2739 $new_name[] = preg_replace("/�#�/","@",$name);
2740 }
2741 else
2742 {
2743 $new_name[] = $name;
2744 }
2745 break;
2746 }
2747 }
2748 return implode(",",$new_name);
2749 }
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...

References ilObjUser\_loginExists(), and explodeRecipients().

Referenced by __getCountRecipient(), __getEmailRecipients(), distributeMail(), and sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getAutoGeneratedMessageString()

static ilMail::_getAutoGeneratedMessageString (   $lang = null)
static

get auto generated info string

@access public

Parameters
stringlanguage

Definition at line 2817 of file class.ilMail.php.

2818 {
2819 global $ilSetting;
2820
2821 if(!$lang)
2822 {
2823 include_once('./Services/Language/classes/class.ilLanguageFactory.php');
2825 }
2826 $http_path = ilUtil::_getHttpPath();
2827
2828 $lang->loadLanguageModule('mail');
2829 return sprintf($lang->txt('mail_auto_generated_info'),
2830 $ilSetting->get('inst_name','ILIAS 5'),
2831 $http_path)."\n\n";
2832 }
static _getLanguage($a_lang_key='')
Get langauge object.
static _getHttpPath()
global $ilSetting
Definition: privfeed.php:40

References $ilSetting, $lang, ilUtil\_getHttpPath(), and ilLanguageFactory\_getLanguage().

Referenced by ilECSAppEventListener\_sendNotification(), ilSystemNotification\compose(), ilMailSummaryNotification\send(), ilPaymentNotification\send(), ilRemoteObjectBase\sendNewContentNotification(), ilECSObjectSettings\sendNewContentNotification(), and ilAuthContainerECS\sendNotification().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getInstallationSignature()

static ilMail::_getInstallationSignature ( )
static

Static getter for the installation signature.

@access public

Returns
string The installation mail signature

Definition at line 2886 of file class.ilMail.php.

2887 {
2888 global $ilClientIniFile;
2889
2890 $signature = "\n\n* * * * *\n";
2891
2892 $signature .= $ilClientIniFile->readVariable('client', 'name')."\n";
2893 if(strlen($desc = $ilClientIniFile->readVariable('client', 'description')))
2894 {
2895 $signature .= $desc."\n";
2896 }
2897
2898 $signature .= ilUtil::_getHttpPath();
2899
2900 $clientdirs = glob(ILIAS_WEB_DIR."/*", GLOB_ONLYDIR);
2901 if(is_array($clientdirs) && count($clientdirs) > 1)
2902 {
2903 // #18051
2904 $signature .= '/login.php?client_id='.CLIENT_ID;
2905 }
2906
2907 $signature .= "\n\n";
2908
2909 return $signature;
2910 }
const ILIAS_WEB_DIR

References ilUtil\_getHttpPath(), and ILIAS_WEB_DIR.

Referenced by ilSystemNotification\compose(), ilMailCronOrphanedMailsNotification\send(), ilMailSummaryNotification\send(), ilPaymentNotification\send(), ilCronDeleteInactiveUserReminderMailNotification\send(), sendMail(), and ilObjSurveyGUI\sendUserResultsMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getUserInternalMailboxAddress()

static ilMail::_getUserInternalMailboxAddress (   $usr_id,
  $login = null,
  $firstname = null,
  $lastname = null 
)
static
STATIC METHOD.
Returns the internal mailbox address for the specified user.

This functions (may) perform faster, if the login, firstname and lastname are supplied as parameters aloing with the $usr_id.

Parameters
usr_idthe usr_id of the user
loginoptional, but if you supply it, you have to supply the firstname and the lastname as well
firstnameoptional
lastname@access public

Definition at line 2766 of file class.ilMail.php.

2767 {
2768 if (ilMail::_usePearMail())
2769 {
2770 if ($login == null)
2771 {
2772 require_once './Services/User/classes/class.ilObjUser.php';
2773 $usr_obj = self::getCachedUserInstance($usr_id);
2774 $login = $usr_obj->getLogin();
2775 $firstname = $usr_obj->getFirstname();
2776 $lastname = $usr_obj->getLastname();
2777 }
2778 // The following line of code creates a properly formatted mailbox
2779 // address. Unfortunately, it does not work, because ILIAS removes
2780 // everything between '<' '>' characters
2781 // Therefore, we just return the login - sic.
2782 // FIXME - Make this work in a future release
2783 /*
2784 return preg_replace('/[()<>@,;:\\".\[\]]/','',$firstname.' '.$lastname).' <'.$login.'>';
2785 */
2786 return $login.'hhho';
2787 }
2788 else
2789 {
2790 return $login;
2791 }
2792 }
static getCachedUserInstance($a_usr_id)
Returns a cached instance of ilObjUser.

References getCachedUserInstance().

+ Here is the call graph for this function:

◆ addFullname()

static ilMail::addFullname (   $a_email,
  $a_fullname 
)
static
Parameters
string$a_email
string$a_fullname
Returns
string

Definition at line 2272 of file class.ilMail.php.

2273 {
2274 include_once 'Services/Mail/classes/class.ilMimeMail.php';
2275 return ilMimeMail::_mimeEncode($a_fullname).' <'.$a_email.'>';
2276 }
_mimeEncode($a_string)

References ilMimeMail\_mimeEncode().

+ Here is the call graph for this function:

◆ appendInstallationSignature()

ilMail::appendInstallationSignature (   $a_flag = null)

Setter/Getter for appending the installation signarue.

@access public

Parameters
mixedboolean or nothing
Returns
mixed boolean if called without passing any params, otherwise $this

Definition at line 2867 of file class.ilMail.php.

2868 {
2869 if(null === $a_flag) {
2871 }
2872
2873 $this->appendInstallationSignature = $a_flag;
2874
2875 return $this;
2876 }
appendInstallationSignature($a_flag=null)
Setter/Getter for appending the installation signarue.
$appendInstallationSignature

References $appendInstallationSignature, and appendInstallationSignature().

Referenced by appendInstallationSignature(), and sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkMail()

ilMail::checkMail (   $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_m_subject,
  $a_m_message,
  $a_type 
)

check if mail is complete, recipients are valid @access public

Parameters
stringrcp_to
stringrcp_cc
stringrcp_bcc
stringm_subject
stringm_message
Returns
string error message

Definition at line 1494 of file class.ilMail.php.

1495 {
1496 $error_message = '';
1497
1498 $a_m_subject = trim($a_m_subject);
1499 $a_rcp_to = trim($a_rcp_to);
1500
1501 if (empty($a_m_subject))
1502 {
1503 $error_message .= $error_message ? "<br>" : '';
1504 $error_message .= $this->lng->txt("mail_add_subject");
1505 }
1506
1507 if (empty($a_rcp_to))
1508 {
1509 $error_message .= $error_message ? "<br>" : '';
1510 $error_message .= $this->lng->txt("mail_add_recipient");
1511 }
1512
1513 return $error_message;
1514 }

Referenced by sendMail().

+ Here is the caller graph for this function:

◆ checkRecipients()

ilMail::checkRecipients (   $a_recipients)

check if recipients are valid @access public

Parameters
stringstring with login names or group names (start with #)
Returns
Returns an empty string, if all recipients are okay. Returns a string with invalid recipients, if some are not okay.

Definition at line 1622 of file class.ilMail.php.

1623 {
1624 global $rbacsystem,$rbacreview;
1625 $wrong_rcps = '';
1626
1627 $this->validatePear($a_recipients);
1628 if (ilMail::_usePearMail() && $this->getUsePear())
1629 {
1630 $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1631
1632 if (is_a($tmp_rcp, 'PEAR_Error'))
1633 {
1634 $colon_pos = strpos($tmp_rcp->message, ':');
1635 $wrong_rcps = '<br />'.(($colon_pos === false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1636 }
1637 else
1638 {
1639 foreach ($tmp_rcp as $rcp)
1640 {
1641 // NO ROLE MAIL ADDRESS
1642 if (substr($rcp->mailbox,0,1) != '#' && substr($rcp->mailbox,0,2) != '"#')
1643 {
1644 // ALL RECIPIENTS MUST EITHER HAVE A VALID LOGIN OR A VALID EMAIL
1645 $user_id = ($rcp->host == self::ILIAS_HOST) ? ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)) : false;
1646 if ($user_id == false && $rcp->host == self::ILIAS_HOST)
1647 {
1648 $wrong_rcps .= "<br />".htmlentities($rcp->mailbox);
1649 continue;
1650 }
1651
1652 // CHECK IF USER CAN RECEIVE MAIL
1653 if ($user_id)
1654 {
1655 if(!$rbacsystem->checkAccessOfUser($user_id, "internal_mail", $this->getMailObjectReferenceId()))
1656 {
1657 $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1658 " (".$this->lng->txt("user_cant_receive_mail").")";
1659 continue;
1660 }
1661 }
1662 }
1663 else if (substr($rcp->mailbox, 0, 7) == '#il_ml_')
1664 {
1665 if (!$this->mlists->mailingListExists($rcp->mailbox))
1666 {
1667 $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1668 " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1669 }
1670
1671 continue;
1672 }
1673 else
1674 {
1675
1676 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1677
1678 if(!$this->mail_to_global_roles && is_array($role_ids))
1679 {
1680 foreach($role_ids as $role_id)
1681 {
1682 if($rbacreview->isGlobalRole($role_id))
1683 {
1684 include_once('Services/Mail/exceptions/class.ilMailException.php');
1685 throw new ilMailException('mail_to_global_roles_not_allowed');
1686
1687 }
1688 }
1689 }
1690 if (count($role_ids) == 0)
1691 {
1692 $wrong_rcps .= '<br />'.htmlentities($rcp->mailbox).
1693 ' ('.$this->lng->txt('mail_no_recipient_found').')';
1694 continue;
1695 }
1696 else if (count($role_ids) > 1)
1697 {
1698 $wrong_rcps .= '<br/>'.htmlentities($rcp->mailbox).
1699 ' ('.sprintf($this->lng->txt('mail_multiple_recipients_found'), implode(',', $role_ids)).')';
1700 }
1701 }
1702 }
1703 }
1704 }
1705 else // NO PEAR
1706 {
1707 $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1708
1709 foreach ($tmp_rcp as $rcp)
1710 {
1711 if (empty($rcp))
1712 {
1713 continue;
1714 }
1715 // NO GROUP
1716 if (substr($rcp,0,1) != '#' && substr($rcp,0,2) != '"#')
1717 {
1718 $usr_id = ilObjUser::getUserIdByLogin(addslashes($rcp));
1719 if(!$usr_id && !ilUtil::is_email($rcp))
1720 {
1721 $wrong_rcps .= "<br />".htmlentities($rcp);
1722 continue;
1723 }
1724
1725 // CHECK IF USER CAN RECEIVE MAIL
1726 if($usr_id)
1727 {
1728 if(!$rbacsystem->checkAccessOfUser($usr_id, "internal_mail", $this->getMailObjectReferenceId()))
1729 {
1730 $wrong_rcps .= "<br />".htmlentities($rcp).
1731 " (".$this->lng->txt("user_cant_receive_mail").")";
1732 continue;
1733 }
1734 }
1735 }
1736 else if(substr($rcp, 0, 7) == '#il_ml_')
1737 {
1738 if (!$this->mlists->mailingListExists($rcp))
1739 {
1740 $wrong_rcps .= "<br />".htmlentities($rcp).
1741 " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1742 }
1743
1744 continue;
1745 }
1746 else if (ilUtil::groupNameExists(addslashes(substr($rcp,1))))
1747 {
1748 continue;
1749 }
1750 else
1751 {
1752 $role_id = $rbacreview->roleExists(addslashes(substr($rcp, 1)));
1753 if($role_id)
1754 {
1755 if(!$this->mail_to_global_roles && $rbacreview->isGlobalRole($role_id))
1756 {
1757 include_once('Services/Mail/exceptions/class.ilMailException.php');
1758 throw new ilMailException('mail_to_global_roles_not_allowed');
1759 }
1760 continue;
1761 }
1762
1763 if(substr(addslashes($rcp), 1, 8) == 'il_role_')
1764 {
1765 $role_id = substr(addslashes($rcp), 9);
1766 $roles_object_id = $rbacreview->getObjectOfRole($role_id);
1767 if($roles_object_id > 0)
1768 {
1769 if(!$this->mail_to_global_roles && $rbacreview->isGlobalRole($role_id))
1770 {
1771 include_once('Services/Mail/exceptions/class.ilMailException.php');
1772 throw new ilMailException('mail_to_global_roles_not_allowed');
1773 }
1774 }
1775 continue;
1776 }
1777
1778 $wrong_rcps .= "<br />" . htmlentities($rcp) . " (" . $this->lng->txt("mail_no_valid_group_role") . ")";
1779 continue;
1780 }
1781 }
1782 }
1783 return $wrong_rcps;
1784 }
ILIAS Exception for Service Mail.
const ILIAS_HOST
getUserIdByLogin($a_login)
static is_email($a_email)
This preg-based function checks whether an e-mail address is formally valid.
static groupNameExists($a_group_name, $a_id=0)
checks if group name already exists.

References $user_id, explodeRecipients(), getUsePear(), ilObjUser\getUserIdByLogin(), ilUtil\groupNameExists(), ILIAS_HOST, ilUtil\is_email(), and validatePear().

Referenced by validateRecipients().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countMailsOfFolder()

ilMail::countMailsOfFolder (   $a_folder_id)

count all mails of a specific folder @access public

Parameters
integerid of folder
Returns
bool number of mails

Definition at line 631 of file class.ilMail.php.

632 {
633 global $ilDB;
634
635 $res = $ilDB->queryf("
636 SELECT COUNT(*) FROM ". $this->table_mail ."
637 WHERE user_id = %s
638 AND folder_id = %s",
639 array('integer', 'integer'),
640 array($this->user_id, $a_folder_id));
641
642 return $res->numRows();
643 }
global $ilDB

References $ilDB, and $res.

◆ deleteMails()

ilMail::deleteMails ( array  $a_mail_ids)

Delete mails.

Parameters
arraymail ids
Returns
bool

Definition at line 856 of file class.ilMail.php.

857 {
858 global $ilDB;
859
860 foreach($a_mail_ids as $id)
861 {
862 $ilDB->manipulateF("
863 DELETE FROM ". $this->table_mail ."
864 WHERE user_id = %s
865 AND mail_id = %s ",
866 array('integer', 'integer'),
867 array($this->user_id, $id)
868 );
869 $this->mfile->deassignAttachmentFromDirectory($id);
870 }
871
872 return true;
873 }

References $ilDB.

Referenced by deleteMailsOfFolder(), and sendMail().

+ Here is the caller graph for this function:

◆ deleteMailsOfFolder()

ilMail::deleteMailsOfFolder (   $a_folder_id)

delete all mails of a specific folder @access public

Parameters
integerid of folder

Definition at line 651 of file class.ilMail.php.

652 {
653 if ($a_folder_id)
654 {
655 global $ilDB;
656
657 /*$statement = $ilDB->manipulateF("
658 DELETE FROM ". $this->table_mail ."
659 WHERE user_id = %s
660 AND folder_id = %s",
661 array('integer', 'integer'),
662 array($this->user_id, $a_folder_id));*/
663 $mails = $this->getMailsOfFolder($a_folder_id);
664 foreach((array)$mails as $mail_data)
665 {
666 $this->deleteMails(array($mail_data['mail_id']));
667 }
668
669 return true;
670 }
671
672 return false;
673 }
deleteMails(array $a_mail_ids)
Delete mails.
getMailsOfFolder($a_folder_id, $filter=array())

References $ilDB, $mail_data, deleteMails(), and getMailsOfFolder().

+ Here is the call graph for this function:

◆ distributeMail()

ilMail::distributeMail (   $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_subject,
  $a_message,
  $a_attachments,
  $sent_mail_id,
  $a_type,
  $a_action,
  $a_use_placeholders = 0 
)

send internal message to recipients @access private

Parameters
stringto
stringcc
stringbcc
stringsubject
stringmessage
arrayattachments
integerid of mail which is stored in sentbox
array'normal' and/or 'system' and/or 'email'
Returns
bool

Definition at line 1096 of file class.ilMail.php.

1097 {
1098 global $log;
1099
1100 include_once 'Services/Mail/classes/class.ilMailbox.php';
1101 include_once './Services/User/classes/class.ilObjUser.php';
1102
1103 if (!ilMail::_usePearMail())
1104 {
1105 // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
1106 $a_rcp_to = $this->__substituteRecipients($a_rcp_to, 'resubstitute');
1107 $a_rcp_cc = $this->__substituteRecipients($a_rcp_cc, 'resubstitute');
1108 $a_rcp_bcc = $this->__substituteRecipients($a_rcp_bcc, 'resubstitute');
1109 }
1110
1111 $mbox = new ilMailbox();
1112
1113 if (!$a_use_placeholders) # No Placeholders
1114 {
1115 $rcp_ids = $this->getUserIds(trim($a_rcp_to).','.trim($a_rcp_cc).','.trim($a_rcp_bcc));
1116
1117 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1118 "Parsed TO/CC/BCC user ids from given recipients: %s", implode(', ', $rcp_ids)
1119 ));
1120
1121 $as_email = array();
1122
1123 foreach($rcp_ids as $id)
1124 {
1125 $tmp_mail_options = new ilMailOptions($id);
1126
1127 // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1128 $tmp_user = self::getCachedUserInstance($id);
1129 $user_is_active = $tmp_user->getActive();
1130 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1131
1132 // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1133 if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1134 {
1135 continue;
1136 }
1137
1138 // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS/HER MAIL
1139 // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1140
1141 // Do not send external mails to inactive users!!!
1142 if($user_is_active)
1143 {
1144 if (!$user_can_read_internal_mails ||
1145 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1146 {
1147 $as_email[] = $tmp_user->getEmail();
1148 continue;
1149 }
1150
1151 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1152 {
1153 $as_email[] = $tmp_user->getEmail();
1154 }
1155 }
1156 $mbox->setUserId($id);
1157 $inbox_id = $mbox->getInboxFolder();
1158
1159 $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1160 $a_attachments, $a_rcp_to,
1161 $a_rcp_cc, '', 'unread', $a_type,
1162 0, $a_subject, $a_message, $id, 0);
1163 if ($a_attachments)
1164 {
1165 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1166 }
1167 }
1168
1169 // SEND EMAIL TO ALL USERS WHO DECIDED 'email' or 'both'
1170 $to = array();
1171 $bcc = array();
1172
1173 if(count($as_email) == 1)
1174 {
1175 $to[] = $as_email[0];
1176 }
1177 else
1178 {
1179 foreach ($as_email as $email)
1180 {
1181 $bcc[] = $email;
1182 }
1183 }
1184
1185 if(count($to) > 0 || count($bcc) > 0)
1186 {
1187 $this->sendMimeMail(implode(',', $to), '', implode(',', $bcc), $a_subject, $a_message, $a_attachments);
1188 }
1189 }
1190 else # Use Placeholders
1191 {
1192 // to
1193 $rcp_ids_replace = $this->getUserIds(trim($a_rcp_to));
1194
1195 // cc / bcc
1196 $rcp_ids_no_replace = $this->getUserIds(trim($a_rcp_cc).','.trim($a_rcp_bcc));
1197
1198 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1199 "Parsed TO user ids from given recipients for serial letter notification: %s", implode(', ', $rcp_ids_replace)
1200 ));
1201 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1202 "Parsed CC/BCC user ids from given recipients for serial letter notification: %s", implode(', ', $rcp_ids_no_replace)
1203 ));
1204
1205 $as_email = array();
1206
1207 // to
1208 foreach($rcp_ids_replace as $id)
1209 {
1210 $tmp_mail_options = new ilMailOptions($id);
1211
1212 // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1213 $tmp_user = self::getCachedUserInstance($id);
1214 $user_is_active = $tmp_user->getActive();
1215 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1216
1217 // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1218 if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1219 {
1220 continue;
1221 }
1222
1223 // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1224 // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1225
1226 // Do not send external mails to inactive users!!!
1227 if($user_is_active)
1228 {
1229 if (!$user_can_read_internal_mails ||
1230 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1231 {
1232 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1233 continue;
1234 }
1235
1236 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1237 {
1238 $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1239 }
1240 }
1241 $mbox->setUserId($id);
1242 $inbox_id = $mbox->getInboxFolder();
1243
1244 $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1245 $a_attachments, $a_rcp_to,
1246 $a_rcp_cc, '', 'unread', $a_type,
1247 0, $a_subject, $a_message, $id, 1);
1248 if ($a_attachments)
1249 {
1250 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1251 }
1252 }
1253
1254 if (count($as_email))
1255 {
1256 foreach ($as_email as $id => $email)
1257 {
1258 $this->sendMimeMail($email, '', '', $a_subject, $this->replacePlaceholders($a_message, $id), $a_attachments);
1259 }
1260 }
1261
1262 $as_email = array();
1263
1264 // cc / bcc
1265 foreach($rcp_ids_no_replace as $id)
1266 {
1267 $tmp_mail_options = new ilMailOptions($id);
1268
1269 // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1270 $tmp_user = self::getCachedUserInstance($id);
1271 $user_is_active = $tmp_user->getActive();
1272 $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1273
1274 // Do not send external mails to inactive users!!!
1275 if($user_is_active)
1276 {
1277 // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1278 if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1279 {
1280 continue;
1281 }
1282
1283 // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1284 // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1285 if (!$user_can_read_internal_mails ||
1286 $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1287 {
1288 $as_email[] = $tmp_user->getEmail();
1289 continue;
1290 }
1291
1292 if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1293 {
1294 $as_email[] = $tmp_user->getEmail();
1295 }
1296 }
1297 $mbox->setUserId($id);
1298 $inbox_id = $mbox->getInboxFolder();
1299
1300 $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1301 $a_attachments, $a_rcp_to,
1302 $a_rcp_cc, '', 'unread', $a_type,
1303 0, $a_subject, $a_message, $id, 0);
1304 if ($a_attachments)
1305 {
1306 $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1307 }
1308 }
1309
1310 if (count($as_email))
1311 {
1312 $this->sendMimeMail('', '', implode(',', $as_email), $a_subject, $a_message, $a_attachments);
1313 }
1314 }
1315
1316 return true;
1317 }
static getLogger($a_component_id)
Get component logger.
replacePlaceholders($a_message, $a_user_id=0)
sendMimeMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_attachments, $a_no_soap=false)
send mime mail using class.ilMimeMail.php All external mails are send to SOAP::sendMail starting a ki...
getUserIds($a_recipients)
get user_ids
sendInternalMail($a_folder_id, $a_sender_id, $a_attachments, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_status, $a_m_type, $a_m_email, $a_m_subject, $a_m_message, $a_user_id=0, $a_use_placeholders=0, $a_tpl_context_id=null, $a_tpl_context_params=array())
save mail in folder @access private
Mail Box class Base class for creating and handling mail boxes.

References $log, __substituteRecipients(), getCachedUserInstance(), ilLoggerFactory\getLogger(), getUserIds(), replacePlaceholders(), sendInternalMail(), and sendMimeMail().

Referenced by sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doesRecipientStillExists()

ilMail::doesRecipientStillExists (   $a_recipient,
  $a_existing_recipients 
)

Definition at line 289 of file class.ilMail.php.

290 {
291 if(self::_usePearMail())
292 {
293 $recipients = $this->explodeRecipients($a_existing_recipients);
294 if(is_a($recipients, 'PEAR_Error'))
295 {
296 return false;
297 }
298 else
299 {
300 foreach($recipients as $rcp)
301 {
302 if (substr($rcp->mailbox, 0, 1) != '#')
303 {
304 if(trim($rcp->mailbox) == trim($a_recipient) ||
305 trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
306 {
307 return true;
308 }
309 }
310 else if (substr($rcp->mailbox, 0, 7) == '#il_ml_')
311 {
312 if(trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
313 {
314 return true;
315 }
316 }
317 else
318 {
319 if(trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
320 {
321 return true;
322 }
323 }
324 }
325 }
326 }
327 else
328 {
329 $recipients = $this->explodeRecipients($a_existing_recipients);
330 if(count($recipients))
331 {
332 foreach($recipients as $recipient)
333 {
334 if(trim($recipient) == trim($a_recipient))
335 {
336 return true;
337 }
338 }
339 }
340 }
341
342 return false;
343 }

References explodeRecipients().

+ Here is the call graph for this function:

◆ enableSOAP()

ilMail::enableSOAP (   $a_status)

Definition at line 352 of file class.ilMail.php.

353 {
354 $this->soap_enabled = $a_status;
355 }

◆ explodeRecipients()

ilMail::explodeRecipients (   $a_recipients,
  $use_pear = true 
)

explode recipient string allowed seperators are ',' ';' ' '

Returns an array with recipient objects

@access private

Returns
array with recipient objects. array[i]->mailbox gets the mailbox of the recipient. array[i]->host gets the host of the recipients. Returns a PEAR_Error object, if exploding failed. Use is_a() to test, if the return value is a PEAR_Error, then use $rcp->message to retrieve the error message.

Definition at line 2511 of file class.ilMail.php.

2512 {
2513 $a_recipients = trim($a_recipients);
2514
2515 // WHITESPACE IS NOT ALLOWED AS SEPERATOR
2516 #$a_recipients = preg_replace("/ /",",",$a_recipients);
2517 $a_recipients = preg_replace("/;/",",",$a_recipients);
2518
2519 if (ilMail::_usePearMail() && $use_pear == true)
2520 {
2521 if (strlen(trim($a_recipients)) > 0)
2522 {
2523 ilLoggerFactory::getLogger('mail')->debug(sprintf(
2524 "Started Mail_RFC822 parsing of recipient string: %s", $a_recipients
2525 ));
2526
2527 require_once './Services/PEAR/lib/Mail/RFC822.php';
2528 $parser = new Mail_RFC822();
2529 $addresses = $parser->parseAddressList($a_recipients, self::ILIAS_HOST, false, true);
2530
2531 if(!is_a($a_recipients, 'PEAR_Error'))
2532 {
2533 ilLoggerFactory::getLogger('mail')->debug(sprintf(
2534 "Parsed addresses: %s", implode(',', array_map(function($address) {
2535 return $address->mailbox . '@' . $address->host;
2536 }, $addresses))
2537 ));
2538 }
2539 else
2540 {
2541 ilLoggerFactory::getLogger('mail')->debug(sprintf(
2542 "Parsing with Mail_RFC822 failed ..."
2543 ));
2544 }
2545
2546 return $addresses;
2547 } else {
2548 return array();
2549 }
2550 }
2551 else
2552 {
2553 $rcps = array();
2554 foreach(explode(',',$a_recipients) as $tmp_rec)
2555 {
2556 if($tmp_rec)
2557 {
2558 $rcps[] = trim($tmp_rec);
2559 }
2560 }
2561 if(strlen($a_recipients) > 0)
2562 {
2563 ilLoggerFactory::getLogger('mail')->debug(sprintf(
2564 "Parsed recipient string %s with result: %s", $a_recipients, implode(',', $rcps)
2565 ));
2566 }
2567 return is_array($rcps) ? $rcps : array();
2568 }
2569 }

References $use_pear, and ilLoggerFactory\getLogger().

Referenced by __getCountRecipient(), __getEmailRecipients(), __substituteRecipients(), checkRecipients(), doesRecipientStillExists(), getEmailsOfRecipients(), getUserIds(), parseRcptOfMailingLists(), and validatePear().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchMailData()

ilMail::fetchMailData (   $a_row)

fetch all query data from table mail @access public

Parameters
objectobject of query
Returns
array array of query data

Definition at line 881 of file class.ilMail.php.

882 {
883 if (!$a_row) return;
884
885 return array(
886 "mail_id" => $a_row->mail_id,
887 "user_id" => $a_row->user_id,
888 "folder_id" => $a_row->folder_id,
889 "sender_id" => $a_row->sender_id,
890 "attachments" => unserialize(stripslashes($a_row->attachments)),
891 "send_time" => $a_row->send_time,
892 "rcp_to" => $a_row->rcp_to,
893 "rcp_cc" => $a_row->rcp_cc,
894 "rcp_bcc" => $a_row->rcp_bcc,
895 "m_status" => $a_row->m_status,
896 "m_type" => unserialize(stripslashes($a_row->m_type)),
897 "m_email" => $a_row->m_email,
898 "m_subject" => $a_row->m_subject,
899 "m_message" => $a_row->m_message,
900 "import_name" => $a_row->import_name,
901 "use_placeholders"=> $a_row->use_placeholders,
902 "tpl_ctx_id" => $a_row->tpl_ctx_id,
903 "tpl_ctx_params" => (array)(@json_decode($a_row->tpl_ctx_params, true))
904 );
905 }

Referenced by getMail(), getMailsOfFolder(), getNextMail(), getPreviousMail(), and getSavedData().

+ Here is the caller graph for this function:

◆ formatNamesForOutput()

ilMail::formatNamesForOutput (   $users = '')

Prepends the fullname of each ILIAS login name (is user has a public profile) found in the passed string and brackets the ILIAS login name afterwards.

Parameters
string$usersString containing to, cc or bcc recipients
Returns
string Formatted names

@access public

Definition at line 470 of file class.ilMail.php.

471 {
472 $users = trim($users);
473 if($users)
474 {
475 if(strstr($users, ','))
476 {
477 $rcp_to_array = array();
478
479 $recipients = explode(',', $users);
480 foreach($recipients as $recipient)
481 {
482 $recipient = trim($recipient);
483 if($uid = ilObjUser::_lookupId($recipient))
484 {
485 if (in_array(ilObjUser::_lookupPref($uid, 'public_profile'), array("y", "g")))
486 {
487 $tmp_obj = self::getCachedUserInstance($uid);
488 $rcp_to_array[] = $tmp_obj->getFullname().' ['.$recipient.']';
489 }
490 else
491 {
492 $rcp_to_array[] = $recipient;
493 }
494 }
495 else
496 {
497 $rcp_to_array[] = $recipient;
498 }
499 }
500
501 return trim(implode(', ', $rcp_to_array));
502 }
503 else
504 {
505 if($uid = ilObjUser::_lookupId($users))
506 {
507 if (in_array(ilObjUser::_lookupPref($uid, 'public_profile'), array("y", "g")))
508 {
509 $tmp_obj = self::getCachedUserInstance($uid);
510 return $tmp_obj->getFullname().' ['.$users.']';
511 }
512 else
513 {
514 return $users;
515 }
516 }
517 else
518 {
519 return $users;
520 }
521 }
522 }
523 else
524 {
525 return $this->lng->txt('not_available');
526 }
527 }
_lookupPref($a_usr_id, $a_keyword)

References ilObjUser\_lookupId(), ilObjUser\_lookupPref(), and getCachedUserInstance().

+ Here is the call graph for this function:

◆ getAttachments()

ilMail::getAttachments ( )

get attachments @access public

Returns
array array of attachments

Definition at line 2493 of file class.ilMail.php.

2494 {
2495 return $this->mail_data["attachments"] ? $this->mail_data["attachments"] : array();
2496 }

◆ getCachedUserInstance()

static ilMail::getCachedUserInstance (   $a_usr_id)
staticprotected

Returns a cached instance of ilObjUser.

Parameters
integer$a_usr_id
Returns
ilObjUser

Definition at line 2991 of file class.ilMail.php.

2992 {
2993 if(isset(self::$userInstances[$a_usr_id]))
2994 {
2995 return self::$userInstances[$a_usr_id];
2996 }
2997
2998 self::$userInstances[$a_usr_id] = new ilObjUser($a_usr_id);
2999 return self::$userInstances[$a_usr_id];
3000 }

Referenced by _getUserInternalMailboxAddress(), distributeMail(), formatNamesForOutput(), getEmailOfSender(), getEmailsOfRecipients(), and replacePlaceholders().

+ Here is the caller graph for this function:

◆ getEmailOfSender()

ilMail::getEmailOfSender ( )

get email of sender @access public

Returns
string email

Definition at line 2449 of file class.ilMail.php.

2450 {
2451 $umail = self::getCachedUserInstance($this->user_id);
2452 $sender = $umail->getEmail();
2453
2454 if (ilUtil::is_email($sender))
2455 {
2456 return $sender;
2457 }
2458 else
2459 {
2460 return '';
2461 }
2462 }

References getCachedUserInstance(), and ilUtil\is_email().

+ Here is the call graph for this function:

◆ getEmailsOfRecipients()

ilMail::getEmailsOfRecipients (   $a_rcp)

get email addresses of recipients @access public

Parameters
stringstring with login names or group names (start with #) or email address
Returns
string seperated by ','

Definition at line 1522 of file class.ilMail.php.

1523 {
1524 global $rbacreview;
1525
1526 $addresses = array();
1527
1528 $this->validatePear($a_rcp);
1529 if (ilMail::_usePearMail() && $this->getUsePear())
1530 {
1531 $tmp_rcp = $this->explodeRecipients($a_rcp);
1532 if (! is_a($tmp_rcp, 'PEAR_Error'))
1533 {
1534 foreach ($tmp_rcp as $rcp)
1535 {
1536 // NO GROUP
1537 if (substr($rcp->mailbox,0,1) != '#' && substr($rcp->mailbox,0, 2) != '"#')
1538 {
1539 if (strtolower($rcp->host) != self::ILIAS_HOST)
1540 {
1541 $addresses[] = $rcp->mailbox.'@'.$rcp->host;
1542 continue;
1543 }
1544
1545 if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)))
1546 {
1547 $tmp_user = self::getCachedUserInstance($id);
1548 $addresses[] = $tmp_user->getEmail();
1549 continue;
1550 }
1551 }
1552 else
1553 {
1554 // Roles
1555 $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1556 foreach($role_ids as $role_id)
1557 {
1558 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1559 {
1560 $tmp_user = self::getCachedUserInstance($usr_id);
1561 $addresses[] = $tmp_user->getEmail();
1562 }
1563 }
1564 }
1565 }
1566 }
1567 }
1568 else
1569 {
1570 $tmp_rcp = $this->explodeRecipients($a_rcp, $this->getUsePear());
1571
1572 foreach ($tmp_rcp as $rcp)
1573 {
1574 // NO GROUP
1575 if (substr($rcp,0,1) != '#' && substr($rcp,0,2) != '"#')
1576 {
1577 if (strpos($rcp,'@'))
1578 {
1579 $addresses[] = $rcp;
1580 continue;
1581 }
1582
1583 if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp)))
1584 {
1585 $tmp_user = self::getCachedUserInstance($id);
1586 $addresses[] = $tmp_user->getEmail();
1587 continue;
1588 }
1589 }
1590 else
1591 {
1592 // GROUP THINGS
1593 include_once("./Services/Object/classes/class.ilObjectFactory.php");
1594 include_once('./Modules/Group/classes/class.ilObjGroup.php');
1595
1596 // Fix
1597 foreach(ilObjGroup::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($rcp,1)))) as $ref_id)
1598 {
1600 break;
1601 }
1602 // GET EMAIL OF MEMBERS AND STORE THEM IN $addresses
1603 foreach ($grp_object->getGroupMemberIds() as $id)
1604 {
1605 $tmp_user = self::getCachedUserInstance($id);
1606 $addresses[] = $tmp_user->getEmail();
1607 }
1608 }
1609 }
1610 }
1611
1612 return $addresses;
1613 }
_lookupIdByTitle($a_title)
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences($a_id)
get all reference ids of object
$ref_id
Definition: sahs_server.php:39

References $ref_id, ilObject\_getAllReferences(), ilObjGroup\_lookupIdByTitle(), explodeRecipients(), getCachedUserInstance(), ilObjectFactory\getInstanceByRefId(), getUsePear(), ilObjUser\getUserIdByLogin(), and validatePear().

+ Here is the call graph for this function:

◆ getIliasMailerAddress()

static ilMail::getIliasMailerAddress ( )
static

Builds an email address used for system notifications.

@access public

Returns
string

Definition at line 2323 of file class.ilMail.php.

2324 {
2325 global $ilSetting;
2326
2327 include_once 'Services/Mail/classes/class.ilMimeMail.php';
2328
2329 $no_reply_adress = trim($ilSetting->get('mail_external_sender_noreply'));
2330 if(strlen($no_reply_adress))
2331 {
2332 if(strpos($no_reply_adress, '@') === false)
2333 $no_reply_adress = 'noreply@'.$no_reply_adress;
2334
2335 if(!ilUtil::is_email($no_reply_adress))
2336 {
2337 $no_reply_adress = 'noreply@'.$_SERVER['SERVER_NAME'];
2338 }
2339
2340 $sender = array($no_reply_adress, self::_getIliasMailerName());
2341 }
2342 else
2343 {
2344 $sender = array('noreply@'.$_SERVER['SERVER_NAME'], self::_getIliasMailerName());
2345 }
2346
2347 return $sender;
2348 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_SERVER, $ilSetting, and ilUtil\is_email().

Referenced by ilMailSummaryNotification\send(), ilPasswordAssistanceGUI\sendPasswordAssistanceMail(), and ilPasswordAssistanceGUI\sendUsernameAssistanceMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMail()

ilMail::getMail (   $a_mail_id)

get data of one mail @access public

Parameters
intmail_id
Returns
array mail_data

Definition at line 695 of file class.ilMail.php.

696 {
697 global $ilDB;
698
699 $res = $ilDB->queryf("
700 SELECT * FROM ". $this->table_mail ."
701 WHERE user_id = %s
702 AND mail_id = %s",
703 array('integer', 'integer'),
704 array($this->user_id, $a_mail_id));
705
706 $this->mail_data =$this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
707
708 return $this->mail_data;
709 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
fetchMailData($a_row)
fetch all query data from table mail @access public

References $ilDB, $mail_data, $res, DB_FETCHMODE_OBJECT, and fetchMailData().

+ Here is the call graph for this function:

◆ getMailCounterData()

ilMail::getMailCounterData ( )

get mail counter data returns data array with indexes "total","read","unread" @access public

Returns
array mail_counter data

Definition at line 681 of file class.ilMail.php.

682 {
683 return is_array($this->mail_counter) ? $this->mail_counter : array(
684 "total" => 0,
685 "read" => 0,
686 "unread" => 0);
687 }

◆ getMailObjectReferenceId()

ilMail::getMailObjectReferenceId ( )

Definition at line 455 of file class.ilMail.php.

456 {
458 }

References $mail_obj_ref_id.

◆ getMailsOfFolder()

ilMail::getMailsOfFolder (   $a_folder_id,
  $filter = array() 
)
get all mails of a specific folder
@access     public
@param      integer id of folder
Parameters
arrayoptional filter array
Returns
array mails

Definition at line 574 of file class.ilMail.php.

575 {
576 global $ilDB;
577
578 $this->mail_counter = array();
579 $this->mail_counter['read'] = 0;
580 $this->mail_counter['unread'] = 0;
581
582 $query = "SELECT sender_id, m_subject, mail_id, m_status, send_time FROM ". $this->table_mail ."
583 LEFT JOIN object_data ON obj_id = sender_id
584 WHERE user_id = %s
585 AND folder_id = %s
586 AND ((sender_id > 0 AND sender_id IS NOT NULL AND obj_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL)) ";
587
588 if($filter['status'])
589 {
590 $query .= ' AND m_status = '.$ilDB->quote($filter['status'], 'text');
591 }
592 if($filter['type'])
593 {
594 $query .= ' AND '.$ilDB->like('m_type', 'text', '%%:"'.$filter['type'].'"%%', false);
595 }
596
597 $query .= " ORDER BY send_time DESC";
598
599 $res = $ilDB->queryf($query,
600 array('integer', 'integer'),
601 array($this->user_id, $a_folder_id));
602
603 while ($row = $ilDB->fetchObject($res))
604 {
605 $tmp = $this->fetchMailData($row);
606
607 if($tmp['m_status'] == 'read')
608 {
609 ++$this->mail_counter['read'];
610 }
611
612 if($tmp['m_status'] == 'unread')
613 {
614 ++$this->mail_counter['unread'];
615 }
616
617 $output[] = $tmp;
618 }
619
620 $this->mail_counter['total'] = count($output);
621
622 return $output ? $output : array();
623 }

References $ilDB, $query, $res, $row, and fetchMailData().

Referenced by deleteMailsOfFolder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewDraftId()

ilMail::getNewDraftId (   $usrId,
  $folderId 
)
Parameters
int$usrId
int$folderId
Returns
int

Definition at line 912 of file class.ilMail.php.

913 {
914 global $ilDB;
915
916 $next_id = $ilDB->nextId($this->table_mail);
917 $ilDB->insert($this->table_mail, array(
918 'mail_id' => array('integer', $next_id),
919 'user_id' => array('integer', $usrId),
920 'folder_id' => array('integer', $folderId),
921 'sender_id' => array('integer', $usrId)
922 ));
923
924 return $next_id;
925 }

References $ilDB.

◆ getNextMail()

ilMail::getNextMail (   $a_mail_id)

Definition at line 548 of file class.ilMail.php.

549 {
550 global $ilDB;
551
552 $ilDB->setLimit(1);
553 $res = $ilDB->queryf("
554 SELECT b.* FROM " . $this->table_mail ." a
555 INNER JOIN ".$this->table_mail ." b ON b.folder_id = a.folder_id
556 AND b.user_id = a.user_id AND b.send_time < a.send_time
557 WHERE a.user_id = %s
558 AND a.mail_id = %s ORDER BY b.send_time DESC",
559 array('integer', 'integer'),
560 array($this->user_id, $a_mail_id));
561
562 $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
563
564 return $this->mail_data;
565 }

References $ilDB, $mail_data, $res, DB_FETCHMODE_OBJECT, and fetchMailData().

+ Here is the call graph for this function:

◆ getPreviousMail()

ilMail::getPreviousMail (   $a_mail_id)

Definition at line 529 of file class.ilMail.php.

530 {
531 global $ilDB;
532
533 $ilDB->setLimit(1);
534 $res = $ilDB->queryf("
535 SELECT b.* FROM " . $this->table_mail ." a
536 INNER JOIN ".$this->table_mail ." b ON b.folder_id = a.folder_id
537 AND b.user_id = a.user_id AND b.send_time > a.send_time
538 WHERE a.user_id = %s
539 AND a.mail_id = %s ORDER BY b.send_time ASC",
540 array('integer', 'integer'),
541 array($this->user_id, $a_mail_id));
542
543 $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
544
545 return $this->mail_data;
546 }

References $ilDB, $mail_data, $res, DB_FETCHMODE_OBJECT, and fetchMailData().

+ Here is the call graph for this function:

◆ getSalutation()

static ilMail::getSalutation (   $a_usr_id,
  $a_language = null 
)
static

Get salutation.

Parameters
int$a_usr_id
Returns

Definition at line 2929 of file class.ilMail.php.

2930 {
2931 global $lng;
2932
2933 $lang = $a_language ? $a_language : $lng;
2934
2935 $lang->loadLanguageModule('mail');
2936 $gender = ilObjUser::_lookupGender($a_usr_id);
2937 $gender = $gender ? $gender : 'n';
2938 $name = ilObjUser::_lookupName($a_usr_id);
2939
2940 if(!strlen($name['firstname']))
2941 {
2942 return $lang->txt('mail_salutation_anonymous').',';
2943 }
2944
2945 return $lang->txt('mail_salutation_'.$gender).' '.
2946 ($name['title'] ? $name['title'].' ' : '').
2947 ($name['firstname'] ? $name['firstname'].' ' : '').
2948 $name['lastname'].',';
2949 }
static _lookupGender($a_user_id)
Lookup gender.
static _lookupName($a_user_id)
lookup user name

References $lang, $lng, ilObjUser\_lookupGender(), and ilObjUser\_lookupName().

Referenced by ilTestManScoringParticipantNotification\buildBody(), ilSystemNotification\compose(), ilCourseMembershipMailNotification\send(), ilExerciseMailNotification\send(), ilGroupMembershipMailNotification\send(), ilLMMailNotification\send(), ilSessionMembershipMailNotification\send(), ilCalendarMailNotification\send(), ilBuddySystemNotification\send(), ilDiskQuotaSummaryNotification\send(), ilMailCronOrphanedMailsNotification\send(), ilMailSummaryNotification\send(), ilPaymentNotification\send(), ilRegistrationMailNotification\send(), ilTestMailNotification\sendAdvancedNotification(), ilTestMailNotification\sendSimpleNotification(), and ilObjSurveyGUI\sendUserResultsMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSavedData()

ilMail::getSavedData ( )

get saved data @access public

Returns
array of saved data

Definition at line 1860 of file class.ilMail.php.

1861 {
1862 global $ilDB;
1863
1864 $res = $ilDB->queryf('
1865 SELECT * FROM '. $this->table_mail_saved .'
1866 WHERE user_id = %s',
1867 array('integer'),
1868 array($this->user_id));
1869
1870 $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
1871
1872 return $this->mail_data;
1873 }

References $ilDB, $mail_data, $res, DB_FETCHMODE_OBJECT, and fetchMailData().

Referenced by savePostData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSaveInSentbox()

ilMail::getSaveInSentbox ( )

Definition at line 380 of file class.ilMail.php.

381 {
383 }

References $save_in_sentbox.

Referenced by sendMail().

+ Here is the caller graph for this function:

◆ getSubjectPrefix()

static ilMail::getSubjectPrefix ( )
static

Get text that will be prepended to auto generated mails.

Returns
string subject prefix

Definition at line 2916 of file class.ilMail.php.

2917 {
2918 global $ilSetting;
2919 static $prefix = null;
2920
2921 return $prefix == null ? $ilSetting->get('mail_subject_prefix','') : $prefix;
2922 }

References $ilSetting.

Referenced by sendMimeMail(), and ilMimeMail\Subject().

+ Here is the caller graph for this function:

◆ getUsePear()

ilMail::getUsePear ( )
private

Definition at line 2956 of file class.ilMail.php.

2957 {
2958 return $this->use_pear;
2959 }

References $use_pear.

Referenced by __getCountRecipient(), checkRecipients(), getEmailsOfRecipients(), and getUserIds().

+ Here is the caller graph for this function:

◆ getUserIds()

ilMail::getUserIds (   $a_recipients)

get user_ids

Parameters
stringrecipients seperated by ','
Returns
array error message

Definition at line 1324 of file class.ilMail.php.

1325 {
1326 global $log, $rbacreview;
1327 $ids = array();
1328
1329 $this->validatePear($a_recipients);
1330 if (ilMail::_usePearMail() && $this->getUsePear() == true)
1331 {
1332 $tmp_names = $this->explodeRecipients($a_recipients );
1333 if (! is_a($tmp_names, 'PEAR_Error'))
1334 {
1335 for ($i = 0;$i < count($tmp_names); $i++)
1336 {
1337 if (substr($tmp_names[$i]->mailbox,0,1) == '#' || substr($tmp_names[$i]->mailbox,0,2) == '"#')
1338 {
1339 $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1340 $foundUserIds = array();
1341 foreach($role_ids as $role_id)
1342 {
1343 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1344 {
1345 $ids[] = $usr_id;
1346 $foundUserIds[] = $usr_id;
1347 }
1348 }
1349
1350 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1351 "Found the following user ids by role assignments for address '%s': %s", $tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host, implode(', ', $foundUserIds)
1352 ));
1353 }
1354 else if (strtolower($tmp_names[$i]->host) == self::ILIAS_HOST)
1355 {
1356 if($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i]->mailbox)))
1357 {
1358 $ids[] = $id;
1359 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1360 "Found the following user ids for address '%s': %s", addslashes($tmp_names[$i]->mailbox), $id
1361 ));
1362 }
1363 else if(strlen($tmp_names[$i]->mailbox) > 0)
1364 {
1365 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1366 "Did not find any user account for address '%s'", addslashes($tmp_names[$i]->mailbox)
1367 ));
1368 }
1369 }
1370 else
1371 {
1372 // Fixed mantis bug #5875
1373 if($id = ilObjUser::_lookupId($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host))
1374 {
1375 $ids[] = $id;
1376 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1377 "Found the following user ids for address '%s': %s", $tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host, $id
1378 ));
1379 }
1380 else
1381 {
1382 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1383 "Did not find any user account for address '%s'", $tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host
1384 ));
1385 }
1386 }
1387 }
1388 }
1389 }
1390 else
1391 {
1392 $tmp_names = $this->explodeRecipients($a_recipients, $this->getUsePear());
1393 for ($i = 0;$i < count($tmp_names); $i++)
1394 {
1395 if (substr($tmp_names[$i],0,1) == '#' || substr($tmp_names[$i], 0, 2) == '"#')
1396 {
1397 if(ilUtil::groupNameExists(addslashes(substr($tmp_names[$i],1))))
1398 {
1399 include_once("./Services/Object/classes/class.ilObjectFactory.php");
1400 include_once('./Modules/Group/classes/class.ilObjGroup.php');
1401
1402 foreach(ilObject::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($tmp_names[$i],1)))) as $ref_id)
1403 {
1405 break;
1406 }
1407 $foundUserIds = array();
1408 // STORE MEMBER IDS IN $ids
1409 foreach ($grp_object->getGroupMemberIds() as $id)
1410 {
1411 $ids[] = $id;
1412 $foundUserIds[] = $id;
1413 }
1414
1415 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1416 "Found the following user ids by group member assignment for address '%s': %s", addslashes(substr($tmp_names[$i],1)), implode(', ', $foundUserIds)
1417 ));
1418 }
1419 // is role: get role ids
1420 else
1421 {
1422 $possible_role_id = addslashes(substr($tmp_names[$i], 1));
1423 $role_id = $rbacreview->roleExists($possible_role_id);
1424 if($role_id)
1425 {
1426 $foundUserIds = array();
1427 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1428 {
1429 $ids[] = $usr_id;
1430 $foundUserIds[] = $usr_id;
1431 }
1432
1433 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1434 "Found the following user ids by role assignments for address '%s': %s", addslashes(substr($tmp_names[$i], 1)), implode(', ', $foundUserIds)
1435 ));
1436 continue;
1437 }
1438
1439 if(substr($possible_role_id, 0, 8) == 'il_role_')
1440 {
1441 $role_id = substr($possible_role_id, 8);
1442 $roles_object_id = $rbacreview->getObjectOfRole($role_id);
1443 if($roles_object_id > 0)
1444 {
1445 $foundUserIds = array();
1446 foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1447 {
1448 $ids[] = $usr_id;
1449 $foundUserIds[] = $usr_id;
1450 }
1451 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1452 "Found the following user ids by role assignments for address '%s': %s", $possible_role_id, implode(', ', $foundUserIds)
1453 ));
1454 }
1455 continue;
1456 }
1457
1458 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1459 "Found no user ids for address '%s'", $possible_role_id
1460 ));
1461 }
1462 }
1463 else if (!empty($tmp_names[$i]))
1464 {
1465 if ($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i])))
1466 {
1467 $ids[] = $id;
1468 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1469 "Found the following user ids for address '%s': %s", addslashes($tmp_names[$i]), $id
1470 ));
1471 }
1472 else if(strlen(addslashes($tmp_names[$i])) > 0)
1473 {
1474 ilLoggerFactory::getLogger('mail')->debug(sprintf(
1475 "Did not find any user account for address '%s'", addslashes($tmp_names[$i])
1476 ));
1477 }
1478 }
1479 }
1480 }
1481 return array_unique($ids);
1482 }

References $log, $ref_id, ilObject\_getAllReferences(), ilObjUser\_lookupId(), ilObjGroup\_lookupIdByTitle(), explodeRecipients(), ilObjectFactory\getInstanceByRefId(), ilLoggerFactory\getLogger(), getUsePear(), ilObjUser\getUserIdByLogin(), ilUtil\groupNameExists(), and validatePear().

Referenced by distributeMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSOAPEnabled()

ilMail::isSOAPEnabled ( )

Definition at line 356 of file class.ilMail.php.

357 {
358 global $ilSetting;
359
360 if(!extension_loaded('curl') || !$ilSetting->get('soap_user_administration'))
361 {
362 return false;
363 }
364
365 // Prevent using SOAP in cron context
367 {
368 return false;
369 }
370
371 return (bool) $this->soap_enabled;
372 }
const CONTEXT_CRON
static getType()
Get context type.

References $ilSetting, $soap_enabled, ilContext\CONTEXT_CRON, and ilContext\getType().

Referenced by sendMimeMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ markRead()

ilMail::markRead (   $a_mail_ids)

mark mails as read @access public

Parameters
arraymail ids
Returns
bool

Definition at line 717 of file class.ilMail.php.

718 {
719
720 global $ilDB;
721
722 $data = array();
723 $data_types = array();
724
725 $query = "UPDATE ". $this->table_mail ."
726 SET m_status = %s
727 WHERE user_id = %s ";
728 array_push($data_types, 'text', 'integer');
729 array_push($data, 'read', $this->user_id);
730
731 $cnt_mail_ids = count($a_mail_ids);
732
733 if (is_array($a_mail_ids) &&
734 count($a_mail_ids) > 0)
735 {
736
737 $in = 'mail_id IN (';
738 $counter = 0;
739 foreach($a_mail_ids as $a_mail_id)
740 {
741 array_push($data, $a_mail_id);
742 array_push($data_types, 'integer');
743
744 if($counter > 0) $in .= ',';
745 $in .= '%s';
746 ++$counter;
747 }
748 $in .= ')';
749
750 $query .= ' AND '.$in;
751 }
752
753 $res = $ilDB->manipulateF($query, $data_types, $data);
754
755 return true;
756 }
$data

References $data, $ilDB, $in, $query, and $res.

◆ markUnread()

ilMail::markUnread (   $a_mail_ids)

mark mails as unread @access public

Parameters
arraymail ids
Returns
bool

Definition at line 764 of file class.ilMail.php.

765 {
766 global $ilDB;
767
768 $data = array();
769 $data_types = array();
770
771 $query = "UPDATE ". $this->table_mail ."
772 SET m_status = %s
773 WHERE user_id = %s ";
774 array_push($data_types, 'text', 'integer');
775 array_push($data, 'unread', $this->user_id);
776
777 $cnt_mail_ids = count($a_mail_ids);
778
779 if (is_array($a_mail_ids) &&
780 count($a_mail_ids) > 0)
781 {
782
783 $in = 'mail_id IN (';
784 $counter = 0;
785 foreach($a_mail_ids as $a_mail_id)
786 {
787 array_push($data, $a_mail_id);
788 array_push($data_types, 'integer');
789
790 if($counter > 0) $in .= ',';
791 $in .= '%s';
792 ++$counter;
793 }
794 $in .= ')';
795
796 $query .= ' AND '.$in;
797 }
798
799 $statement = $ilDB->manipulateF($query, $data_types, $data);
800
801 return true;
802 }

References $data, $ilDB, $in, and $query.

◆ moveMailsToFolder()

ilMail::moveMailsToFolder (   $a_mail_ids,
  $a_folder_id 
)

move mail to folder @access public

Parameters
arraymail ids
intfolder_id
Returns
bool

Definition at line 811 of file class.ilMail.php.

812 {
813 global $ilDB;
814
815 $data = array();
816 $data_types = array();
817
818 $query = "UPDATE ". $this->table_mail ."
819 SET folder_id = %s
820 WHERE user_id = %s ";
821 array_push($data_types, 'text', 'integer');
822 array_push($data, $a_folder_id, $this->user_id);
823
824 $cnt_mail_ids = count($a_mail_ids);
825
826 if (is_array($a_mail_ids) &&
827 count($a_mail_ids) > 0)
828 {
829
830 $in = 'mail_id IN (';
831 $counter = 0;
832 foreach($a_mail_ids as $a_mail_id)
833 {
834 array_push($data, $a_mail_id);
835 array_push($data_types, 'integer');
836
837 if($counter > 0) $in .= ',';
838 $in .= '%s';
839 ++$counter;
840 }
841 $in .= ')';
842
843 $query .= ' AND '.$in;
844 }
845
846 $statement = $ilDB->manipulateF($query, $data_types, $data);
847
848 return true;
849 }

References $data, $ilDB, $in, and $query.

◆ parseRcptOfMailingLists()

ilMail::parseRcptOfMailingLists (   $rcpt = '',
  $maintain_lists = false 
)

Definition at line 2124 of file class.ilMail.php.

2125 {
2126 if ($rcpt == '')
2127 {
2128 if(!$maintain_lists)
2129 {
2130 return $rcpt;
2131 }
2132 else
2133 {
2134 return array();
2135 }
2136 }
2137//@todo check rcp pear validation
2138 $arrRcpt = $this->explodeRecipients(trim($rcpt));
2139 if (!is_array($arrRcpt) || empty($arrRcpt))
2140 {
2141 if(!$maintain_lists)
2142 {
2143 return $rcpt;
2144 }
2145 else
2146 {
2147 return array();
2148 }
2149 }
2150
2151 $new_rcpt = array();
2152
2153 foreach ($arrRcpt as $item)
2154 {
2155 if (ilMail::_usePearMail())
2156 {
2157 if (substr($item->mailbox, 0, 7) == '#il_ml_')
2158 {
2159 if ($this->mlists->mailingListExists($item->mailbox))
2160 {
2161 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2162 {
2163 $login = ilObjUser::_lookupLogin($entry['usr_id']);
2164 if(!$maintain_lists)
2165 {
2166 $new_rcpt[] = $login;
2167 }
2168 else
2169 {
2170 $new_rcpt[$item->mailbox][] = $login;
2171 }
2172 }
2173 }
2174 }
2175 else
2176 {
2177 $tmp_rcpt = '';
2178 if($item->host == self::ILIAS_HOST)
2179 {
2180 $tmp_rcpt = $item->mailbox;
2181 }
2182 else
2183 {
2184 $tmp_rcpt = $item->mailbox.'@'.$item->host;
2185 }
2186
2187 if(!$maintain_lists)
2188 {
2189 $new_rcpt[] = $tmp_rcpt;
2190 }
2191 else
2192 {
2193 $new_rcpt[0][] = $tmp_rcpt;
2194 }
2195 }
2196 }
2197 else
2198 {
2199 if (substr($item, 0, 7) == '#il_ml_')
2200 {
2201 if ($this->mlists->mailingListExists($item))
2202 {
2203 foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2204 {
2205 $login = ilObjUser::_lookupLogin($entry['usr_id']);
2206 if(!$maintain_lists)
2207 {
2208 $new_rcpt[] = $login;
2209 }
2210 else
2211 {
2212 $new_rcpt[$item][] = $login;
2213 }
2214 }
2215 }
2216 }
2217 else
2218 {
2219 if(!$maintain_lists)
2220 {
2221 $new_rcpt[] = $item;
2222 }
2223 else
2224 {
2225 $new_rcpt[0][] = $item;
2226 }
2227 }
2228 }
2229 }
2230
2231 if(!$maintain_lists)
2232 {
2233 return implode(',', $new_rcpt);
2234 }
2235 else
2236 {
2237 return $new_rcpt;
2238 }
2239 }
static _lookupLogin($a_user_id)
lookup login

References ilObjUser\_lookupLogin(), and explodeRecipients().

Referenced by sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readMailObjectReferenceId()

ilMail::readMailObjectReferenceId ( )

read and set mail object id @access private

Definition at line 449 of file class.ilMail.php.

450 {
451 include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
452 $this->mail_obj_ref_id = ilMailGlobalServices::getMailObjectRefId();
453 }
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.

References ilMailGlobalServices\getMailObjectRefId().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replacePlaceholders()

ilMail::replacePlaceholders (   $a_message,
  $a_user_id = 0 
)
protected
Parameters
string$a_message
int$a_user_id
Returns
string

Definition at line 1050 of file class.ilMail.php.

1051 {
1052 try
1053 {
1054 include_once 'Services/Mail/classes/class.ilMailFormCall.php';
1055
1057 {
1058 require_once 'Services/Mail/classes/class.ilMailTemplateService.php';
1060 }
1061 else
1062 {
1063 require_once 'Services/Mail/classes/class.ilMailTemplateGenericContext.php';
1064 $context = new ilMailTemplateGenericContext();
1065 }
1066
1067 $user = $a_user_id > 0 ? self::getCachedUserInstance($a_user_id) : null;
1068 foreach($context->getPlaceholders() as $key => $ph_definition)
1069 {
1070 $result = $context->resolvePlaceholder($key, ilMailFormCall::getContextParameters(), $user);
1071 $a_message = str_replace('[' . $ph_definition['placeholder'] . ']', $result, $a_message);
1072 }
1073 }
1074 catch(Exception $e)
1075 {
1076 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
1077 ilLoggerFactory::getLogger('mail')->error(__METHOD__ . ' has been called with invalid context.');
1078 }
1079
1080 return $a_message;
1081 }
$result

References $result, getCachedUserInstance(), ilMailFormCall\getContextId(), ilMailFormCall\getContextParameters(), ilLoggerFactory\getLogger(), and ilMailTemplateService\getTemplateContextById().

Referenced by distributeMail(), sendInternalMail(), and sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveAttachments()

ilMail::saveAttachments (   $a_attachments)

set attachments

Parameters
arrayarray of attachments @access public
Returns
bool

Definition at line 2470 of file class.ilMail.php.

2471 {
2472 global $ilDB;
2473
2474 $ilDB->update($this->table_mail_saved,
2475 array
2476 (
2477 'attachments' => array('clob', serialize($a_attachments))
2478 ),
2479 array
2480 (
2481 'user_id' => array('integer', $this->user_id)
2482 )
2483 );
2484
2485 return true;
2486 }

References $ilDB.

◆ saveInSentbox()

ilMail::saveInSentbox (   $a_attachment,
  $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_type,
  $a_m_subject,
  $a_m_message 
)

send mime mail using class.ilMimeMail.php

Parameters
arrayattachments
stringto
stringcc
stringbcc
stringtype
stringsubject
stringmessage @access public
Returns
int mail id
Todo:
: mjansen 23.12.2011 Why is $a_as_email undefined here?

Definition at line 2253 of file class.ilMail.php.

2255 {
2256 include_once "Services/Mail/classes/class.ilMailbox.php";
2257
2258 $mbox = new ilMailbox($this->user_id);
2259 $sent_id = $mbox->getSentFolder();
2260
2262 return $this->sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
2263 $a_rcp_bcc,'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2264 }

References sendInternalMail().

Referenced by sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePostData()

ilMail::savePostData (   $a_user_id,
  $a_attachments,
  $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_m_type,
  $a_m_email,
  $a_m_subject,
  $a_m_message,
  $a_use_placeholders,
  $a_tpl_context_id = null,
  $a_tpl_ctx_params = array() 
)

save post data in table @access public

Parameters
intuser_id
arrayattachments
stringto
stringcc
stringbcc
arraytype of mail (system,normal,email)
intas email (1,0)
stringsubject
stringmessage
intuse placeholders
string | null$a_tpl_context_id
array | null$a_tpl_ctx_params
Returns
bool

Definition at line 1803 of file class.ilMail.php.

1816 {
1817 global $ilDB;
1818
1819
1820 if(!$a_attachments) $a_attachments = NULL;
1821 if(!$a_rcp_to) $a_rcp_to = NULL;
1822 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1823 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1824 if(!$a_m_type) $a_m_type = NULL;
1825 if(!$a_m_email) $a_m_email = NULL;
1826 if(!$a_m_message) $a_m_message = NULL;
1827 if(!$a_use_placeholders) $a_use_placeholders = '0';
1828
1829
1830 $ilDB->replace(
1831 $this->table_mail_saved,
1832 array(
1833 'user_id' => array('integer', $this->user_id)
1834 ),
1835 array(
1836 'attachments' => array('clob', serialize($a_attachments)),
1837 'rcp_to' => array('clob', $a_rcp_to),
1838 'rcp_cc' => array('clob', $a_rcp_cc),
1839 'rcp_bcc' => array('clob', $a_rcp_bcc),
1840 'm_type' => array('text', serialize($a_m_type)),
1841 'm_email' => array('integer', $a_m_email),
1842 'm_subject' => array('text', $a_m_subject),
1843 'm_message' => array('clob', $a_m_message),
1844 'use_placeholders' => array('integer', $a_use_placeholders),
1845 'tpl_ctx_id' => array('text', $a_tpl_context_id),
1846 'tpl_ctx_params' => array('blob', json_encode((array)$a_tpl_ctx_params))
1847 )
1848 );
1849
1850 $this->getSavedData();
1851
1852 return true;
1853 }
getSavedData()
get saved data @access public

References $ilDB, and getSavedData().

+ Here is the call graph for this function:

◆ sendInternalMail()

ilMail::sendInternalMail (   $a_folder_id,
  $a_sender_id,
  $a_attachments,
  $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_status,
  $a_m_type,
  $a_m_email,
  $a_m_subject,
  $a_m_message,
  $a_user_id = 0,
  $a_use_placeholders = 0,
  $a_tpl_context_id = null,
  $a_tpl_context_params = array() 
)

save mail in folder @access private

Parameters
integerid of folder
integersender_id
arrayattachments
stringto
stringcc
stringbcc
stringstatus
stringtype of mail (system,normal)
integeras email (1,0)
stringsubject
stringmessage
integeruser_id
integer$a_use_placeholders
string | null$a_tpl_context_id
array | null$a_tpl_context_params
Returns
integer mail_id

Definition at line 980 of file class.ilMail.php.

996 {
997 $a_user_id = $a_user_id ? $a_user_id : $this->user_id;
998
999 global $ilDB, $log;
1000
1001 if ($a_use_placeholders)
1002 {
1003 $a_m_message = $this->replacePlaceholders($a_m_message, $a_user_id);
1004 }
1005
1006
1007 if(!$a_user_id) $a_user_id = '0';
1008 if(!$a_folder_id) $a_folder_id = '0';
1009 if(!$a_sender_id) $a_sender_id = NULL;
1010 if(!$a_attachments) $a_attachments = NULL;
1011 if(!$a_rcp_to) $a_rcp_to = NULL;
1012 if(!$a_rcp_cc) $a_rcp_cc = NULL;
1013 if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1014 if(!$a_status) $a_status = NULL;
1015 if(!$a_m_type) $a_m_type = NULL;
1016 if(!$a_m_email) $a_m_email = NULL;
1017 if(!$a_m_subject) $a_m_subject = NULL;
1018 if(!$a_m_message) $a_m_message = NULL;
1019
1020
1021 $next_id = $ilDB->nextId($this->table_mail);
1022 $ilDB->insert($this->table_mail, array(
1023 'mail_id' => array('integer', $next_id),
1024 'user_id' => array('integer', $a_user_id),
1025 'folder_id' => array('integer', $a_folder_id),
1026 'sender_id' => array('integer', $a_sender_id),
1027 'attachments' => array('clob', serialize($a_attachments)),
1028 'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
1029 'rcp_to' => array('clob', $a_rcp_to),
1030 'rcp_cc' => array('clob', $a_rcp_cc),
1031 'rcp_bcc' => array('clob', $a_rcp_bcc),
1032 'm_status' => array('text', $a_status),
1033 'm_type' => array('text', serialize($a_m_type)),
1034 'm_email' => array('integer', $a_m_email),
1035 'm_subject' => array('text', $a_m_subject),
1036 'm_message' => array('clob', $a_m_message),
1037 'tpl_ctx_id' => array('text', $a_tpl_context_id),
1038 'tpl_ctx_params' => array('blob', @json_encode((array)$a_tpl_context_params))
1039 ));
1040
1041 return $next_id; //$ilDB->getLastInsertId();
1042
1043 }

References $ilDB, $log, $user_id, and replacePlaceholders().

Referenced by distributeMail(), and saveInSentbox().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendMail()

ilMail::sendMail (   $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bc,
  $a_m_subject,
  $a_m_message,
  $a_attachment,
  $a_type,
  $a_use_placeholders = 0 
)

send external mail using class.ilMimeMail.php

Parameters
stringto
stringcc
stringbcc
stringsubject
stringmessage
arrayattachments
arraytype (normal and/or system and/or email)
integeralso as email (0,1) @access public
Returns
array of saved data

Definition at line 1926 of file class.ilMail.php.

1927 {
1928 global $lng,$rbacsystem;
1929
1930 ilLoggerFactory::getLogger('mail')->debug(
1931 "New mail system task:" .
1932 " To: " . $a_rcp_to .
1933 " | CC: " . $a_rcp_cc .
1934 " | BCC: " . $a_rcp_bc .
1935 " | Subject: " . $a_m_subject
1936 );
1937
1938 $this->mail_to_global_roles = true;
1939 if($this->user_id != ANONYMOUS_USER_ID)
1940 {
1941 $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id, 'mail_to_global_roles', $this->mail_obj_ref_id);
1942 }
1943
1944 if (in_array("system",$a_type))
1945 {
1946 $a_type = array('system');
1947 }
1948
1949 if ($a_attachment)
1950 {
1951 if (!$this->mfile->checkFilesExist($a_attachment))
1952 {
1953 return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1954 }
1955 }
1956 // CHECK NECESSARY MAIL DATA FOR ALL TYPES
1957 if ($error_message = $this->checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1958 {
1959 return $error_message;
1960 }
1961
1962 $error_message = $this->validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc);
1963 if(strlen($error_message) > 0)
1964 {
1965 return $error_message;
1966 }
1967
1968 // ACTIONS FOR ALL TYPES
1969
1970
1971 // GET RCPT OF MAILING LISTS
1972
1973 $rcp_to_list = $this->parseRcptOfMailingLists($a_rcp_to, true);
1974 $rcp_cc_list = $this->parseRcptOfMailingLists($a_rcp_cc, true);
1975 $rcp_bc_list = $this->parseRcptOfMailingLists($a_rcp_bc, true);
1976
1977 $rcp_to = $rcp_cc = $rcp_bc = array();
1978 foreach($rcp_to_list as $mlist_id => $mlist_rec)
1979 {
1980 if($mlist_id)
1981 {
1982 // internal mailing lists are sent as bcc
1983 $mlist_id = substr($mlist_id, 7);
1984 if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
1985 {
1986 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1987 continue;
1988 }
1989 }
1990
1991 $rcp_to = array_merge($rcp_to, $mlist_rec);
1992 }
1993 foreach($rcp_cc_list as $mlist_id => $mlist_rec)
1994 {
1995 if($mlist_id)
1996 {
1997 // internal mailing lists are sent as bcc
1998 $mlist_id = substr($mlist_id, 7);
1999 if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
2000 {
2001 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
2002 continue;
2003 }
2004 }
2005
2006 $rcp_cc = array_merge($rcp_cc, $mlist_rec);
2007 }
2008 foreach($rcp_bc_list as $mlist_id => $mlist_rec)
2009 {
2010 $rcp_bc = array_merge($rcp_bc, $mlist_rec);
2011 }
2012
2013 $rcp_to = implode(',', $rcp_to);
2014 $rcp_cc = implode(',', $rcp_cc);
2015 $rcp_bc = implode(',', $rcp_bc);
2016
2017
2018 if (! ilMail::_usePearMail() )
2019 {
2020 // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
2021 $rcp_to = $this->__substituteRecipients($rcp_to,"substitute");
2022 $rcp_cc = $this->__substituteRecipients($rcp_cc,"substitute");
2023 $rcp_bc = $this->__substituteRecipients($rcp_bc,"substitute");
2024 }
2025
2026 // COUNT EMAILS
2027 $c_emails = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,true);
2028 $c_rcp = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,false);
2029
2030 // currently disabled..
2031 /*
2032 if (count($c_emails))
2033 {
2034 if (!$this->getEmailOfSender())
2035 {
2036 return $lng->txt("mail_check_your_email_addr");
2037 }
2038 }
2039 */
2040
2041 // check smtp permission
2042 if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
2043 !$rbacsystem->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id))
2044 {
2045 return $this->lng->txt('mail_no_permissions_write_smtp');
2046 }
2047
2048 if($this->appendInstallationSignature())
2049 {
2050 $a_m_message .= self::_getInstallationSignature();
2051 }
2052
2053 // save mail in sent box
2054 $sent_id = $this->saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
2055 $a_m_subject,$a_m_message);
2056
2057 if($a_attachment)
2058 {
2059 $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
2060
2061 if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
2062 {
2063 return $error;
2064 }
2065 }
2066
2067 // FILTER EMAILS
2068 // IF EMAIL RECIPIENT
2069 if($c_emails)
2070 {
2071 $externalMailRecipientsTo = $this->__getEmailRecipients($rcp_to);
2072 $externalMailRecipientsCc = $this->__getEmailRecipients($rcp_cc);
2073 $externalMailRecipientsBcc = $this->__getEmailRecipients($rcp_bc);
2074
2075 ilLoggerFactory::getLogger('mail')->debug(
2076 "Parsed external mail addresses from given recipients:" .
2077 " To: " . $externalMailRecipientsTo .
2078 " | CC: " . $externalMailRecipientsCc .
2079 " | BCC: " . $externalMailRecipientsBcc .
2080 " | Subject: " . $a_m_subject
2081 );
2082
2083 $this->sendMimeMail(
2084 $externalMailRecipientsTo,
2085 $externalMailRecipientsCc,
2086 $externalMailRecipientsBcc,
2087 $a_m_subject,
2088 $a_use_placeholders ? $this->replacePlaceholders($a_m_message) : $a_m_message,
2089 $a_attachment,
2090 0
2091 );
2092 }
2093 else
2094 {
2095 ilLoggerFactory::getLogger('mail')->debug("No external mail addresses given in recipient string");
2096 }
2097
2098 if (in_array('system',$a_type))
2099 {
2100 if (!$this->distributeMail($rcp_to,$rcp_cc,$rcp_bc,$a_m_subject,$a_m_message,$a_attachment,$sent_id,$a_type,'system', $a_use_placeholders))
2101 {
2102 return $lng->txt("mail_send_error");
2103 }
2104 }
2105 // ACTIONS FOR TYPE SYSTEM AND NORMAL
2106 if (in_array('normal',$a_type))
2107 {
2108 // TRY BOTH internal and email (depends on user settings)
2109 if (!$this->distributeMail($rcp_to,$rcp_cc,$rcp_bc,$a_m_subject,$a_m_message,$a_attachment,$sent_id,$a_type,'normal', $a_use_placeholders))
2110 {
2111 return $lng->txt("mail_send_error");
2112 }
2113 }
2114
2115 // Temporary bugfix
2116 if (!$this->getSaveInSentbox())
2117 {
2118 $this->deleteMails(array($sent_id));
2119 }
2120
2121 return '';
2122 }
parseRcptOfMailingLists($rcpt='', $maintain_lists=false)
distributeMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_subject, $a_message, $a_attachments, $sent_mail_id, $a_type, $a_action, $a_use_placeholders=0)
send internal message to recipients @access private
__getEmailRecipients($a_rcp)
__getCountRecipients($a_to, $a_cc, $a_bcc, $a_only_email=true)
static _getInstallationSignature()
Static getter for the installation signature.
saveInSentbox($a_attachment, $a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_type, $a_m_subject, $a_m_message)
send mime mail using class.ilMimeMail.php
checkMail($a_rcp_to, $a_rcp_cc, $a_rcp_bcc, $a_m_subject, $a_m_message, $a_type)
check if mail is complete, recipients are valid @access public
validateRecipients($a_rcp_to, $a_rcp_cc, $a_rcp_bc)
getSaveInSentbox()

References $lng, __getCountRecipients(), __getEmailRecipients(), __substituteRecipients(), _getInstallationSignature(), appendInstallationSignature(), checkMail(), deleteMails(), distributeMail(), ilLoggerFactory\getLogger(), getSaveInSentbox(), ilMailingList\MODE_TEMPORARY, parseRcptOfMailingLists(), replacePlaceholders(), saveInSentbox(), sendMimeMail(), and validateRecipients().

+ Here is the call graph for this function:

◆ sendMimeMail()

ilMail::sendMimeMail (   $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_m_subject,
  $a_m_message,
  $a_attachments,
  $a_no_soap = false 
)

send mime mail using class.ilMimeMail.php All external mails are send to SOAP::sendMail starting a kind of background process

Parameters
stringof recipients
stringof recipients
stringof recipients
stringsubject
stringmessage
arrayattachments
boolprevent soap @access public
Returns
array of saved data

Definition at line 2363 of file class.ilMail.php.

2364 {
2365 include_once "Services/Mail/classes/class.ilMimeMail.php";
2366
2367 #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2368
2369 #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2370 #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2371
2372 $a_m_subject = self::getSubjectPrefix().' '.$a_m_subject;
2373
2374 $sender = $this->getMimeMailSender();
2375
2376 // #10854
2377 if($this->isSOAPEnabled() && !$a_no_soap)
2378 {
2379 // Send per soap
2380 include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2381
2382 $soap_client = new ilSoapClient();
2383 $soap_client->setResponseTimeout(5);
2384 $soap_client->enableWSDL(true);
2385 $soap_client->init();
2386
2387 $attachments = array();
2388 $a_attachments = $a_attachments ? $a_attachments : array();
2389 foreach($a_attachments as $attachment)
2390 {
2391 $attachments[] = $this->mfile->getAbsolutePath($attachment);
2392 }
2393 // mjansen: switched separator from "," to "#:#" because of mantis bug #6039
2394 $attachments = implode('#:#',$attachments);
2395 // mjansen: use "#:#" as leading delimiter
2396 if(strlen($attachments))
2397 $attachments = "#:#".$attachments;
2398
2399 $soap_client->call('sendMail',array(session_id().'::'.$_COOKIE['ilClientId'], // session id
2400 $a_rcp_to,
2401 $a_rcp_cc,
2402 $a_rcp_bcc,
2403 is_array($sender) ? implode('#:#', $sender) : $sender,
2404 $a_m_subject,
2405 $a_m_message,
2406 $attachments));
2407
2408 return true;
2409 }
2410 else
2411 {
2412 // send direct
2413 include_once "Services/Mail/classes/class.ilMimeMail.php";
2414
2415 $mmail = new ilMimeMail();
2416 $mmail->autoCheck(false);
2417 $mmail->From($sender);
2418 $mmail->To($a_rcp_to);
2419 // Add installation name to subject
2420 $mmail->Subject($a_m_subject);
2421 $mmail->Body($a_m_message);
2422
2423 if ($a_rcp_cc)
2424 {
2425 $mmail->Cc($a_rcp_cc);
2426 }
2427
2428 if ($a_rcp_bcc)
2429 {
2430 $mmail->Bcc($a_rcp_bcc);
2431 }
2432
2433 if (is_array($a_attachments))
2434 {
2435 foreach ($a_attachments as $attachment)
2436 {
2437 $mmail->Attach($this->mfile->getAbsolutePath($attachment), '', 'inline', $attachment);
2438 }
2439 }
2440
2441 $mmail->Send();
2442 }
2443 }
isSOAPEnabled()
static getSubjectPrefix()
Get text that will be prepended to auto generated mails.
this class encapsulates the PHP mail() function.
$_COOKIE["ilClientId"]
Definition: cron.php:11

References $_COOKIE, getSubjectPrefix(), and isSOAPEnabled().

Referenced by distributeMail(), and sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMailMessage()

ilMail::setMailMessage (   $a_message)

Definition at line 440 of file class.ilMail.php.

441 {
442 $this->mail_message = $a_message;
443 }

◆ setMailRcpBc()

ilMail::setMailRcpBc (   $a_rcp_bc)

Definition at line 420 of file class.ilMail.php.

421 {
422 $this->mail_rcp_bc = $a_rcp_bc;
423 }

◆ setMailRcpCc()

ilMail::setMailRcpCc (   $a_rcp_cc)

Definition at line 410 of file class.ilMail.php.

411 {
412 $this->mail_rcp_cc = $a_rcp_cc;
413 }

◆ setMailRcpTo()

ilMail::setMailRcpTo (   $a_rcp_to)

Definition at line 400 of file class.ilMail.php.

401 {
402 $this->mail_rcp_to = $a_rcp_to;
403 }

◆ setMailSendType()

ilMail::setMailSendType (   $a_types)

Definition at line 390 of file class.ilMail.php.

391 {
392 $this->mail_send_type = $a_types;
393 }

◆ setMailSubject()

ilMail::setMailSubject (   $a_subject)

Definition at line 430 of file class.ilMail.php.

431 {
432 $this->mail_subject = $a_subject;
433 }

◆ setSaveInSentbox()

ilMail::setSaveInSentbox (   $a_save_in_sentbox)

Definition at line 375 of file class.ilMail.php.

376 {
377 $this->save_in_sentbox = $a_save_in_sentbox;
378 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setUsePear()

ilMail::setUsePear (   $bool)
private

Definition at line 2951 of file class.ilMail.php.

2952 {
2953 $this->use_pear = $bool;
2954 }

Referenced by validatePear().

+ Here is the caller graph for this function:

◆ updateDraft()

ilMail::updateDraft (   $a_folder_id,
  $a_attachments,
  $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bcc,
  $a_m_type,
  $a_m_email,
  $a_m_subject,
  $a_m_message,
  $a_draft_id = 0,
  $a_use_placeholders = 0,
  $a_tpl_context_id = null,
  $a_tpl_context_params = array() 
)

Definition at line 927 of file class.ilMail.php.

932 {
933 global $ilDB;
934
935 $ilDB->update($this->table_mail,
936 array(
937 'folder_id' => array('integer', $a_folder_id),
938 'attachments' => array('clob', serialize($a_attachments)),
939 'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
940 'rcp_to' => array('clob', $a_rcp_to),
941 'rcp_cc' => array('clob', $a_rcp_cc),
942 'rcp_bcc' => array('clob', $a_rcp_bcc),
943 'm_status' => array('text', 'read'),
944 'm_type' => array('text', serialize($a_m_type)),
945 'm_email' => array('integer', $a_m_email),
946 'm_subject' => array('text', $a_m_subject),
947 'm_message' => array('clob', $a_m_message),
948 'use_placeholders' => array('integer', $a_use_placeholders),
949 'tpl_ctx_id' => array('text', $a_tpl_context_id),
950 'tpl_ctx_params' => array('blob', @json_encode((array)$a_tpl_context_params))
951 ),
952 array(
953 'mail_id' => array('integer', $a_draft_id)
954 )
955 );
956
957 return $a_draft_id;
958 }

References $ilDB.

◆ validatePear()

ilMail::validatePear (   $a_recipients)
private
Parameters
<type>$a_recipients

Definition at line 2966 of file class.ilMail.php.

2967 {
2968 if(ilMail::_usePearMail())
2969 {
2970 $this->setUsePear(true);
2971 $tmp_names = $this->explodeRecipients($a_recipients, true);
2972 if(is_a($tmp_names, 'PEAR_Error'))
2973 {
2974 $this->setUsePear(false);
2975 }
2976 }
2977 else
2978 {
2979 $this->setUsePear(false);
2980 }
2981 }
setUsePear($bool)

References explodeRecipients(), and setUsePear().

Referenced by __getCountRecipient(), checkRecipients(), getEmailsOfRecipients(), and getUserIds().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateRecipients()

ilMail::validateRecipients (   $a_rcp_to,
  $a_rcp_cc,
  $a_rcp_bc 
)
Parameters
string$a_rcp_to
string$a_rcp_cc
string$a_rcp_bc
Returns
string

Definition at line 1881 of file class.ilMail.php.

1882 {
1883 try
1884 {
1885 $message = '';
1886
1887 if($error_message = $this->checkRecipients($a_rcp_to))
1888 {
1889 $message .= $error_message;
1890 }
1891 if($error_message = $this->checkRecipients($a_rcp_cc))
1892 {
1893 $message .= $error_message;
1894 }
1895 if($error_message = $this->checkRecipients($a_rcp_bc))
1896 {
1897 $message .= $error_message;
1898 }
1899
1900 if(strlen($message) > 0)
1901 {
1902 return $this->lng->txt('mail_following_rcp_not_valid') . $message;
1903 }
1904
1905 return '';
1906 }
1907 catch(ilMailException $e)
1908 {
1909 return $this->lng->txt('mail_following_rcp_not_valid') . $this->lng->txt($e->getMessage());
1910 }
1911 }
checkRecipients($a_recipients)
check if recipients are valid @access public

References checkRecipients().

Referenced by sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $appendInstallationSignature

ilMail::$appendInstallationSignature = false
protected

Definition at line 208 of file class.ilMail.php.

Referenced by appendInstallationSignature().

◆ $ilias

ilMail::$ilias

Definition at line 117 of file class.ilMail.php.

Referenced by __construct().

◆ $lng

ilMail::$lng

Definition at line 124 of file class.ilMail.php.

Referenced by __construct(), getSalutation(), and sendMail().

◆ $mail_counter

ilMail::$mail_counter

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

◆ $mail_data

◆ $mail_message

ilMail::$mail_message

Definition at line 201 of file class.ilMail.php.

◆ $mail_obj_ref_id

ilMail::$mail_obj_ref_id

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

Referenced by getMailObjectReferenceId().

◆ $mail_options

ilMail::$mail_options

Definition at line 133 of file class.ilMail.php.

◆ $mail_rcp_bc

ilMail::$mail_rcp_bc

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

◆ $mail_rcp_cc

ilMail::$mail_rcp_cc

Definition at line 198 of file class.ilMail.php.

◆ $mail_rcp_to

ilMail::$mail_rcp_to

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

◆ $mail_send_type

ilMail::$mail_send_type

Definition at line 183 of file class.ilMail.php.

◆ $mail_subject

ilMail::$mail_subject

Definition at line 200 of file class.ilMail.php.

◆ $mail_to_global_roles

ilMail::$mail_to_global_roles = 0

Definition at line 205 of file class.ilMail.php.

◆ $mail_use_placeholders

ilMail::$mail_use_placeholders = 0

Definition at line 202 of file class.ilMail.php.

◆ $mfile

ilMail::$mfile

Definition at line 131 of file class.ilMail.php.

◆ $properties

ilMail::$properties = array()
protected

Definition at line 223 of file class.ilMail.php.

◆ $save_in_sentbox

ilMail::$save_in_sentbox

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

Referenced by getSaveInSentbox().

◆ $soap_enabled

ilMail::$soap_enabled = true

Definition at line 204 of file class.ilMail.php.

Referenced by isSOAPEnabled().

◆ $table_mail

ilMail::$table_mail

Definition at line 147 of file class.ilMail.php.

◆ $table_mail_saved

ilMail::$table_mail_saved

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

◆ $use_pear

ilMail::$use_pear = true
private

Definition at line 207 of file class.ilMail.php.

Referenced by explodeRecipients(), and getUsePear().

◆ $user_id

ilMail::$user_id

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

Referenced by checkRecipients(), and sendInternalMail().

◆ $userInstances

ilMail::$userInstances = array()
staticprotected

Definition at line 228 of file class.ilMail.php.

◆ ILIAS_HOST

const ilMail::ILIAS_HOST = 'ilias'

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