ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMail.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/User/classes/class.ilObjUser.php';
5 
109 class ilMail
110 {
117  var $ilias;
118 
124  var $lng;
125 
131  var $mfile;
132 
134 
140  var $user_id;
141 
148 
155 
162 
169 
170 
177 
184 
191 
203 
204  var $soap_enabled = true;
206 
207  private $use_pear = true;
208  protected $appendInstallationSignature = false;
209 
213  const ILIAS_HOST = 'ilias';
214 
223  protected $properties = array();
224 
228  protected static $userInstances = array();
229 
236  public function __construct($a_user_id)
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
258  $this->readMailObjectReferenceId();
259  }
260 
268  public function __get($name)
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  }
288 
289  public function doesRecipientStillExists($a_recipient, $a_existing_recipients)
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  }
344 
352  function enableSOAP($a_status)
353  {
354  $this->soap_enabled = $a_status;
355  }
356  function isSOAPEnabled()
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  }
373 
374 
375  function setSaveInSentbox($a_save_in_sentbox)
376  {
377  $this->save_in_sentbox = $a_save_in_sentbox;
378  }
379 
380  function getSaveInSentbox()
381  {
382  return $this->save_in_sentbox;
383  }
384 
390  function setMailSendType($a_types)
391  {
392  $this->mail_send_type = $a_types;
393  }
394 
400  function setMailRcpTo($a_rcp_to)
401  {
402  $this->mail_rcp_to = $a_rcp_to;
403  }
404 
410  function setMailRcpCc($a_rcp_cc)
411  {
412  $this->mail_rcp_cc = $a_rcp_cc;
413  }
414 
420  function setMailRcpBc($a_rcp_bc)
421  {
422  $this->mail_rcp_bc = $a_rcp_bc;
423  }
424 
430  function setMailSubject($a_subject)
431  {
432  $this->mail_subject = $a_subject;
433  }
434 
440  function setMailMessage($a_message)
441  {
442  $this->mail_message = $a_message;
443  }
444 
450  {
451  include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
452  $this->mail_obj_ref_id = ilMailGlobalServices::getMailObjectRefId();
453  }
454 
456  {
457  return $this->mail_obj_ref_id;
458  }
459 
470  public function formatNamesForOutput($users = '')
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  }
528 
529  function getPreviousMail($a_mail_id)
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  }
547 
548  function getNextMail($a_mail_id)
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  }
566 
574  function getMailsOfFolder($a_folder_id, $filter = array())
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  }
624 
631  function countMailsOfFolder($a_folder_id)
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  }
644 
651  function deleteMailsOfFolder($a_folder_id)
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  }
674 
682  {
683  return is_array($this->mail_counter) ? $this->mail_counter : array(
684  "total" => 0,
685  "read" => 0,
686  "unread" => 0);
687  }
688 
695  function getMail($a_mail_id)
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  }
710 
717  function markRead($a_mail_ids)
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  }
757 
764  function markUnread($a_mail_ids)
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  }
803 
811  function moveMailsToFolder($a_mail_ids,$a_folder_id)
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  }
850 
857  function deleteMails($a_mail_ids)
858  {
859  global $ilDB;
860 
861  foreach ($a_mail_ids as $id)
862  {
863  $statement = $ilDB->manipulateF("
864  DELETE FROM ". $this->table_mail ."
865  WHERE user_id = %s
866  AND mail_id = %s ",
867  array('integer', 'integer'),
868  array($this->user_id, $id));
869 
870  $this->mfile->deassignAttachmentFromDirectory($id);
871  }
872 
873  return true;
874  }
875 
882  function fetchMailData($a_row)
883  {
884  if (!$a_row) return;
885 
886  return array(
887  "mail_id" => $a_row->mail_id,
888  "user_id" => $a_row->user_id,
889  "folder_id" => $a_row->folder_id,
890  "sender_id" => $a_row->sender_id,
891  "attachments" => unserialize(stripslashes($a_row->attachments)),
892  "send_time" => $a_row->send_time,
893  "rcp_to" => $a_row->rcp_to,
894  "rcp_cc" => $a_row->rcp_cc,
895  "rcp_bcc" => $a_row->rcp_bcc,
896  "m_status" => $a_row->m_status,
897  "m_type" => unserialize(stripslashes($a_row->m_type)),
898  "m_email" => $a_row->m_email,
899  "m_subject" => $a_row->m_subject,
900  "m_message" => $a_row->m_message,
901  "import_name" => $a_row->import_name,
902  "use_placeholders"=> $a_row->use_placeholders);
903  }
904 
905  function updateDraft($a_folder_id,
906  $a_attachments,
907  $a_rcp_to,
908  $a_rcp_cc,
909  $a_rcp_bcc,
910  $a_m_type,
911  $a_m_email,
912  $a_m_subject,
913  $a_m_message,
914  $a_draft_id = 0, $a_use_placeholders = 0)
915  {
916  global $ilDB;
917 
918  $ilDB->update($this->table_mail,
919  array(
920  'folder_id' => array('integer', $a_folder_id),
921  'attachments' => array('clob', serialize($a_attachments)),
922  'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
923  'rcp_to' => array('clob', $a_rcp_to),
924  'rcp_cc' => array('clob', $a_rcp_cc),
925  'rcp_bcc' => array('clob', $a_rcp_bcc),
926  'm_status' => array('text', 'read'),
927  'm_type' => array('text', serialize($a_m_type)),
928  'm_email' => array('integer', $a_m_email),
929  'm_subject' => array('text', $a_m_subject),
930  'm_message' => array('clob', $a_m_message),
931  'use_placeholders' => array('integer', $a_use_placeholders)
932  ),
933  array(
934  'mail_id' => array('integer', $a_draft_id)
935  )
936  );
937 
938  return $a_draft_id;
939  }
940 
958  function sendInternalMail($a_folder_id,
959  $a_sender_id,
960  $a_attachments,
961  $a_rcp_to,
962  $a_rcp_cc,
963  $a_rcp_bcc,
964  $a_status,
965  $a_m_type,
966  $a_m_email,
967  $a_m_subject,
968  $a_m_message,
969  $a_user_id = 0, $a_use_placeholders = 0)
970  {
971  $a_user_id = $a_user_id ? $a_user_id : $this->user_id;
972 
973  global $ilDB, $log;
974  //$log->write('class.ilMail->sendInternalMail to user_id:'.$a_rcp_to.' '.$a_m_message);
975 
976  if ($a_use_placeholders)
977  {
978  $a_m_message = $this->replacePlaceholders($a_m_message, $a_user_id);
979  }
980  else
981  {
982  $a_use_placeholders = '0';
983  }
984 
985 
986  if(!$a_user_id) $a_user_id = '0';
987  if(!$a_folder_id) $a_folder_id = '0';
988  if(!$a_sender_id) $a_sender_id = NULL;
989  if(!$a_attachments) $a_attachments = NULL;
990  if(!$a_rcp_to) $a_rcp_to = NULL;
991  if(!$a_rcp_cc) $a_rcp_cc = NULL;
992  if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
993  if(!$a_status) $a_status = NULL;
994  if(!$a_m_type) $a_m_type = NULL;
995  if(!$a_m_email) $a_m_email = NULL;
996  if(!$a_m_subject) $a_m_subject = NULL;
997  if(!$a_m_message) $a_m_message = NULL;
998 
999 
1000  $next_id = $ilDB->nextId($this->table_mail);
1001 
1002  $ilDB->insert($this->table_mail, array(
1003  'mail_id' => array('integer', $next_id),
1004  'user_id' => array('integer', $a_user_id),
1005  'folder_id' => array('integer', $a_folder_id),
1006  'sender_id' => array('integer', $a_sender_id),
1007  'attachments' => array('clob', serialize($a_attachments)),
1008  'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
1009  'rcp_to' => array('clob', $a_rcp_to),
1010  'rcp_cc' => array('clob', $a_rcp_cc),
1011  'rcp_bcc' => array('clob', $a_rcp_bcc),
1012  'm_status' => array('text', $a_status),
1013  'm_type' => array('text', serialize($a_m_type)),
1014  'm_email' => array('integer', $a_m_email),
1015  'm_subject' => array('text', $a_m_subject),
1016  'm_message' => array('clob', $a_m_message)
1017  ));
1018 
1019  return $next_id; //$ilDB->getLastInsertId();
1020 
1021  }
1022 
1023  function replacePlaceholders($a_message, $a_user_id)
1024  {
1025  global $lng;
1026 
1027  $user = self::getCachedUserInstance($a_user_id);
1028 
1029  // determine salutation
1030  switch ($user->getGender())
1031  {
1032  case 'f': $gender_salut = $lng->txt('salutation_f');
1033  break;
1034  case 'm': $gender_salut = $lng->txt('salutation_m');
1035  break;
1036  }
1037 
1038  $a_message = str_replace('[MAIL_SALUTATION]', $gender_salut, $a_message);
1039  $a_message = str_replace('[LOGIN]', $user->getLogin(), $a_message);
1040  $a_message = str_replace('[FIRST_NAME]', $user->getFirstname(), $a_message);
1041  $a_message = str_replace('[LAST_NAME]', $user->getLastname(), $a_message);
1042  $a_message = str_replace('[ILIAS_URL]', ILIAS_HTTP_PATH.'/login.php?client_id='.CLIENT_ID, $a_message);
1043  $a_message = str_replace('[CLIENT_NAME]', CLIENT_NAME, $a_message);
1044 
1045  return $a_message;
1046  }
1047 
1061  function 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)
1062  {
1063  global $log;
1064 
1065  include_once 'Services/Mail/classes/class.ilMailbox.php';
1066  include_once './Services/User/classes/class.ilObjUser.php';
1067 
1068  if (!ilMail::_usePearMail())
1069  {
1070  // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
1071  $a_rcp_to = $this->__substituteRecipients($a_rcp_to, 'resubstitute');
1072  $a_rcp_cc = $this->__substituteRecipients($a_rcp_cc, 'resubstitute');
1073  $a_rcp_bcc = $this->__substituteRecipients($a_rcp_bcc, 'resubstitute');
1074  }
1075 
1076  $mbox = new ilMailbox();
1077 
1078  if (!$a_use_placeholders) # No Placeholders
1079  {
1080  $rcp_ids = $this->getUserIds(trim($a_rcp_to).','.trim($a_rcp_cc).','.trim($a_rcp_bcc));
1081 
1082  $as_email = array();
1083 
1084  foreach($rcp_ids as $id)
1085  {
1086  $tmp_mail_options = new ilMailOptions($id);
1087 
1088  // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1089  $tmp_user = self::getCachedUserInstance($id);
1090  $user_is_active = $tmp_user->getActive();
1091  $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1092 
1093  // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1094  if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1095  {
1096  continue;
1097  }
1098 
1099  // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS/HER MAIL
1100  // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1101 
1102  // Do not send external mails to inactive users!!!
1103  if($user_is_active)
1104  {
1105  if (!$user_can_read_internal_mails ||
1106  $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1107  {
1108  $as_email[] = $tmp_user->getEmail();
1109  continue;
1110  }
1111 
1112  if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1113  {
1114  $as_email[] = $tmp_user->getEmail();
1115  }
1116  }
1117  $mbox->setUserId($id);
1118  $inbox_id = $mbox->getInboxFolder();
1119 
1120  $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1121  $a_attachments, $a_rcp_to,
1122  $a_rcp_cc, '', 'unread', $a_type,
1123  0, $a_subject, $a_message, $id, 0);
1124  if ($a_attachments)
1125  {
1126  $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1127  }
1128  }
1129 
1130  // SEND EMAIL TO ALL USERS WHO DECIDED 'email' or 'both'
1131  $to = array();
1132  $bcc = array();
1133 
1134  if(count($as_email) == 1)
1135  {
1136  $to[] = $as_email[0];
1137  }
1138  else
1139  {
1140  foreach ($as_email as $email)
1141  {
1142  $bcc[] = $email;
1143  }
1144  }
1145 
1146  if(count($to) > 0 || count($bcc) > 0)
1147  {
1148  $this->sendMimeMail(implode(',', $to), '', implode(',', $bcc), $a_subject, $a_message, $a_attachments);
1149  }
1150  }
1151  else # Use Placeholders
1152  {
1153  // to
1154  $rcp_ids_replace = $this->getUserIds(trim($a_rcp_to));
1155 
1156  // cc / bcc
1157  $rcp_ids_no_replace = $this->getUserIds(trim($a_rcp_cc).','.trim($a_rcp_bcc));
1158 
1159  $as_email = array();
1160 
1161  // to
1162  foreach($rcp_ids_replace as $id)
1163  {
1164  $tmp_mail_options = new ilMailOptions($id);
1165 
1166  // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1167  $tmp_user = self::getCachedUserInstance($id);
1168  $user_is_active = $tmp_user->getActive();
1169  $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1170 
1171  // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1172  if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1173  {
1174  continue;
1175  }
1176 
1177  // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1178  // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1179 
1180  // Do not send external mails to inactive users!!!
1181  if($user_is_active)
1182  {
1183  if (!$user_can_read_internal_mails ||
1184  $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1185  {
1186  $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1187  continue;
1188  }
1189 
1190  if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1191  {
1192  $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1193  }
1194  }
1195  $mbox->setUserId($id);
1196  $inbox_id = $mbox->getInboxFolder();
1197 
1198  $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1199  $a_attachments, $a_rcp_to,
1200  $a_rcp_cc, '', 'unread', $a_type,
1201  0, $a_subject, $a_message, $id, 1);
1202  if ($a_attachments)
1203  {
1204  $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1205  }
1206  }
1207 
1208  if (count($as_email))
1209  {
1210  foreach ($as_email as $id => $email)
1211  {
1212  $this->sendMimeMail($email, '', '', $a_subject, $this->replacePlaceholders($a_message, $id), $a_attachments);
1213  }
1214  }
1215 
1216  $as_email = array();
1217 
1218  // cc / bcc
1219  foreach($rcp_ids_no_replace as $id)
1220  {
1221  $tmp_mail_options = new ilMailOptions($id);
1222 
1223  // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1224  $tmp_user = self::getCachedUserInstance($id);
1225  $user_is_active = $tmp_user->getActive();
1226  $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1227 
1228  // Do not send external mails to inactive users!!!
1229  if($user_is_active)
1230  {
1231  // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1232  if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1233  {
1234  continue;
1235  }
1236 
1237  // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1238  // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1239  if (!$user_can_read_internal_mails ||
1240  $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1241  {
1242  $as_email[] = $tmp_user->getEmail();
1243  continue;
1244  }
1245 
1246  if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1247  {
1248  $as_email[] = $tmp_user->getEmail();
1249  }
1250  }
1251  $mbox->setUserId($id);
1252  $inbox_id = $mbox->getInboxFolder();
1253 
1254  $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1255  $a_attachments, $a_rcp_to,
1256  $a_rcp_cc, '', 'unread', $a_type,
1257  0, $a_subject, $a_message, $id, 0);
1258  if ($a_attachments)
1259  {
1260  $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1261  }
1262  }
1263 
1264  if (count($as_email))
1265  {
1266  $this->sendMimeMail('', '', implode(',', $as_email), $a_subject, $a_message, $a_attachments);
1267  }
1268  }
1269 
1270  return true;
1271  }
1272 
1278  function getUserIds($a_recipients)
1279  {
1280  global $log, $rbacreview;
1281  $ids = array();
1282 
1283  $this->validatePear($a_recipients);
1284  if (ilMail::_usePearMail() && $this->getUsePear() == true)
1285  {
1286  $tmp_names = $this->explodeRecipients($a_recipients );
1287  if (! is_a($tmp_names, 'PEAR_Error'))
1288  {
1289  for ($i = 0;$i < count($tmp_names); $i++)
1290  {
1291  if ( substr($tmp_names[$i]->mailbox,0,1) === '#' ||
1292  (substr($tmp_names[$i]->mailbox,0,1) === '"' &&
1293  substr($tmp_names[$i]->mailbox,1,1) === '#' ) )
1294  {
1295  $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1296  foreach($role_ids as $role_id)
1297  {
1298  foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1299  {
1300  $ids[] = $usr_id;
1301  }
1302  }
1303  }
1304  else if (strtolower($tmp_names[$i]->host) == self::ILIAS_HOST)
1305  {
1306  if ($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i]->mailbox)))
1307  {
1308  //$log->write('class.ilMail->getUserIds() recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host.' user_id:'.$id);
1309  $ids[] = $id;
1310  }
1311  else
1312  {
1313  //$log->write('class.ilMail->getUserIds() no user account found for recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1314  }
1315  }
1316  else
1317  {
1318  // Fixed mantis bug #5875
1319  if($id = ilObjUser::_lookupId($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host))
1320  {
1321  $ids[] = $id;
1322  }
1323  else
1324  {
1325  //$log->write('class.ilMail->getUserIds() external recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1326  }
1327  }
1328  }
1329  }
1330  else
1331  {
1332  //$log->write('class.ilMail->getUserIds() illegal recipients:'.$a_recipients);
1333  }
1334  }
1335  else
1336  {
1337  $tmp_names = $this->explodeRecipients($a_recipients, $this->getUsePear());
1338  for ($i = 0;$i < count($tmp_names); $i++)
1339  {
1340  if (substr($tmp_names[$i],0,1) == '#')
1341  {
1342  if(ilUtil::groupNameExists(addslashes(substr($tmp_names[$i],1))))
1343  {
1344  include_once("./Services/Object/classes/class.ilObjectFactory.php");
1345  include_once('./Modules/Group/classes/class.ilObjGroup.php');
1346 
1347  foreach(ilObject::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($tmp_names[$i],1)))) as $ref_id)
1348  {
1349  $grp_object = ilObjectFactory::getInstanceByRefId($ref_id);
1350  break;
1351  }
1352  // STORE MEMBER IDS IN $ids
1353  foreach ($grp_object->getGroupMemberIds() as $id)
1354  {
1355  $ids[] = $id;
1356  }
1357  }
1358  // is role: get role ids
1359  elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1360  {
1361  foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1362  {
1363  $ids[] = $usr_id;
1364  }
1365  }
1366 
1367  }
1368  else if (!empty($tmp_names[$i]))
1369  {
1370  if ($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i])))
1371  {
1372  $ids[] = $id;
1373  }
1374  }
1375  }
1376  }
1377  return array_unique($ids);
1378  }
1379 
1390  function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1391  {
1392  $error_message = '';
1393 
1394  $a_m_subject = trim($a_m_subject);
1395  $a_rcp_to = trim($a_rcp_to);
1396 
1397  if (empty($a_m_subject))
1398  {
1399  $error_message .= $error_message ? "<br>" : '';
1400  $error_message .= $this->lng->txt("mail_add_subject");
1401  }
1402 
1403  if (empty($a_rcp_to))
1404  {
1405  $error_message .= $error_message ? "<br>" : '';
1406  $error_message .= $this->lng->txt("mail_add_recipient");
1407  }
1408 
1409  return $error_message;
1410  }
1411 
1418  function getEmailsOfRecipients($a_rcp)
1419  {
1420  global $rbacreview;
1421 
1422  $addresses = array();
1423 
1424  $this->validatePear($a_rcp);
1425  if (ilMail::_usePearMail() && $this->getUsePear())
1426  {
1427  $tmp_rcp = $this->explodeRecipients($a_rcp);
1428  if (! is_a($tmp_rcp, 'PEAR_Error'))
1429  {
1430  foreach ($tmp_rcp as $rcp)
1431  {
1432  // NO GROUP
1433  if (substr($rcp->mailbox,0,1) != '#')
1434  {
1435  if (strtolower($rcp->host) != self::ILIAS_HOST)
1436  {
1437  $addresses[] = $rcp->mailbox.'@'.$rcp->host;
1438  continue;
1439  }
1440 
1441  if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)))
1442  {
1443  $tmp_user = self::getCachedUserInstance($id);
1444  $addresses[] = $tmp_user->getEmail();
1445  continue;
1446  }
1447  }
1448  else
1449  {
1450  // Roles
1451  $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1452  foreach($role_ids as $role_id)
1453  {
1454  foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1455  {
1456  $tmp_user = self::getCachedUserInstance($usr_id);
1457  $addresses[] = $tmp_user->getEmail();
1458  }
1459  }
1460  }
1461  }
1462  }
1463  }
1464  else
1465  {
1466  $tmp_rcp = $this->explodeRecipients($a_rcp, $this->getUsePear());
1467 
1468  foreach ($tmp_rcp as $rcp)
1469  {
1470  // NO GROUP
1471  if (substr($rcp,0,1) != '#')
1472  {
1473  if (strpos($rcp,'@'))
1474  {
1475  $addresses[] = $rcp;
1476  continue;
1477  }
1478 
1479  if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp)))
1480  {
1481  $tmp_user = self::getCachedUserInstance($id);
1482  $addresses[] = $tmp_user->getEmail();
1483  continue;
1484  }
1485  }
1486  else
1487  {
1488  // GROUP THINGS
1489  include_once("./Services/Object/classes/class.ilObjectFactory.php");
1490  include_once('./Modules/Group/classes/class.ilObjGroup.php');
1491 
1492  // Fix
1493  foreach(ilObjGroup::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($rcp,1)))) as $ref_id)
1494  {
1495  $grp_object = ilObjectFactory::getInstanceByRefId($ref_id);
1496  break;
1497  }
1498  // GET EMAIL OF MEMBERS AND STORE THEM IN $addresses
1499  foreach ($grp_object->getGroupMemberIds() as $id)
1500  {
1501  $tmp_user = self::getCachedUserInstance($id);
1502  $addresses[] = $tmp_user->getEmail();
1503  }
1504  }
1505  }
1506  }
1507 
1508  return $addresses;
1509  }
1510 
1518  function checkRecipients($a_recipients,$a_type)
1519  {
1520  global $rbacsystem,$rbacreview;
1521  $wrong_rcps = '';
1522 
1523  $this->validatePear($a_recipients);
1524  if (ilMail::_usePearMail() && $this->getUsePear())
1525  {
1526  $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1527 
1528  if (is_a($tmp_rcp, 'PEAR_Error'))
1529  {
1530  $colon_pos = strpos($tmp_rcp->message, ':');
1531  $wrong_rcps = '<br />'.(($colon_pos === false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1532  }
1533  else
1534  {
1535  foreach ($tmp_rcp as $rcp)
1536  {
1537  // NO ROLE MAIL ADDRESS
1538  if (substr($rcp->mailbox,0,1) != '#')
1539  {
1540  // ALL RECIPIENTS MUST EITHER HAVE A VALID LOGIN OR A VALID EMAIL
1541  $user_id = ($rcp->host == self::ILIAS_HOST) ? ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)) : false;
1542  if ($user_id == false && $rcp->host == self::ILIAS_HOST)
1543  {
1544  $wrong_rcps .= "<br />".htmlentities($rcp->mailbox);
1545  continue;
1546  }
1547 
1548  // CHECK IF USER CAN RECEIVE MAIL
1549  if ($user_id)
1550  {
1551  if(!$rbacsystem->checkAccessOfUser($user_id, "internal_mail", $this->getMailObjectReferenceId()))
1552  {
1553  $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1554  " (".$this->lng->txt("user_cant_receive_mail").")";
1555  continue;
1556  }
1557  }
1558  }
1559  else if (substr($rcp->mailbox, 0, 7) == '#il_ml_')
1560  {
1561  if (!$this->mlists->mailingListExists($rcp->mailbox))
1562  {
1563  $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1564  " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1565  }
1566 
1567  continue;
1568  }
1569  else
1570  {
1571 
1572  $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1573 
1574  if(!$this->mail_to_global_roles && is_array($role_ids))
1575  {
1576  foreach($role_ids as $role_id)
1577  {
1578  if($rbacreview->isGlobalRole($role_id))
1579  {
1580  include_once('Services/Mail/exceptions/class.ilMailException.php');
1581  throw new ilMailException('mail_to_global_roles_not_allowed');
1582 
1583  }
1584  }
1585  }
1586  if (count($role_ids) == 0)
1587  {
1588  $wrong_rcps .= '<br />'.htmlentities($rcp->mailbox).
1589  ' ('.$this->lng->txt('mail_no_recipient_found').')';
1590  continue;
1591  }
1592  else if (count($role_ids) > 1)
1593  {
1594  $wrong_rcps .= '<br/>'.htmlentities($rcp->mailbox).
1595  ' ('.sprintf($this->lng->txt('mail_multiple_recipients_found'), implode(',', $role_ids)).')';
1596  }
1597  }
1598  }
1599  }
1600  }
1601  else // NO PEAR
1602  {
1603  $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1604 
1605  foreach ($tmp_rcp as $rcp)
1606  {
1607  if (empty($rcp))
1608  {
1609  continue;
1610  }
1611  // NO GROUP
1612  if (substr($rcp,0,1) != '#')
1613  {
1614  // ALL RECIPIENTS MUST EITHER HAVE A VALID LOGIN OR A VALID EMAIL
1615  if (!ilObjUser::getUserIdByLogin(addslashes($rcp)) and
1616  !ilUtil::is_email($rcp))
1617  {
1618  $wrong_rcps .= "<br />".htmlentities($rcp);
1619  continue;
1620  }
1621 
1622  // CHECK IF USER CAN RECEIVE MAIL
1623  if ($user_id = ilObjUser::getUserIdByLogin(addslashes($rcp)))
1624  {
1625  if(!$rbacsystem->checkAccessOfUser($user_id, "internal_mail", $this->getMailObjectReferenceId()))
1626  {
1627  $wrong_rcps .= "<br />".htmlentities($rcp).
1628  " (".$this->lng->txt("user_cant_receive_mail").")";
1629  continue;
1630  }
1631  }
1632  }
1633  else if (substr($rcp, 0, 7) == '#il_ml_')
1634  {
1635  if (!$this->mlists->mailingListExists($rcp))
1636  {
1637  $wrong_rcps .= "<br />".htmlentities($rcp).
1638  " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1639  }
1640 
1641  continue;
1642  }
1643  else if (ilUtil::groupNameExists(addslashes(substr($rcp,1))))
1644  {
1645  continue;
1646  }
1647  else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1648  {
1649  $wrong_rcps .= "<br />".htmlentities($rcp).
1650  " (".$this->lng->txt("mail_no_valid_group_role").")";
1651  continue;
1652  }
1653  else if (!$this->mail_to_global_roles)
1654  {
1655  $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1656  if((int)$role_id && $rbacreview->isGlobalRole($role_id))
1657  {
1658  include_once('Services/Mail/exceptions/class.ilMailException.php');
1659  throw new ilMailException('mail_to_global_roles_not_allowed');
1660  }
1661  }
1662  }
1663  }
1664  return $wrong_rcps;
1665  }
1666 
1682  function savePostData($a_user_id,
1683  $a_attachments,
1684  $a_rcp_to,
1685  $a_rcp_cc,
1686  $a_rcp_bcc,
1687  $a_m_type,
1688  $a_m_email,
1689  $a_m_subject,
1690  $a_m_message,
1691  $a_use_placeholders)
1692  {
1693  global $ilDB;
1694 
1695 
1696  if(!$a_attachments) $a_attachments = NULL;
1697  if(!$a_rcp_to) $a_rcp_to = NULL;
1698  if(!$a_rcp_cc) $a_rcp_cc = NULL;
1699  if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1700  if(!$a_m_type) $a_m_type = NULL;
1701  if(!$a_m_email) $a_m_email = NULL;
1702  if(!$a_m_message) $a_m_message = NULL;
1703  if(!$a_use_placeholders) $a_use_placeholders = '0';
1704 
1705 
1706  $statement = $ilDB->manipulateF('
1707  DELETE FROM '. $this->table_mail_saved .'
1708  WHERE user_id = %s',
1709  array('integer'), array($this->user_id));
1710 
1711  $ilDB->insert($this->table_mail_saved, array(
1712  'user_id' => array('integer', $a_user_id),
1713  'attachments' => array('clob', serialize($a_attachments)),
1714  'rcp_to' => array('clob', $a_rcp_to),
1715  'rcp_cc' => array('clob', $a_rcp_cc),
1716  'rcp_bcc' => array('clob', $a_rcp_bcc),
1717  'm_type' => array('text', serialize($a_m_type)),
1718  'm_email' => array('integer', $a_m_email),
1719  'm_subject' => array('text', $a_m_subject),
1720  'm_message' => array('clob', $a_m_message),
1721  'use_placeholders' => array('integer', $a_use_placeholders),
1722  ));
1723 
1724  $this->getSavedData();
1725 
1726  return true;
1727  }
1728 
1734  function getSavedData()
1735  {
1736  global $ilDB;
1737 
1738  $res = $ilDB->queryf('
1739  SELECT * FROM '. $this->table_mail_saved .'
1740  WHERE user_id = %s',
1741  array('integer'),
1742  array($this->user_id));
1743 
1744  $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
1745 
1746  return $this->mail_data;
1747  }
1748 
1762  function sendMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_attachment,$a_type, $a_use_placeholders = 0)
1763  {
1764  global $lng,$rbacsystem,$log;
1765  //$log->write('class.ilMail.sendMail '.$a_rcp_to.' '.$a_m_subject);
1766 
1767  $this->mail_to_global_roles = true;
1768  if($this->user_id != ANONYMOUS_USER_ID)
1769  {
1770  $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id, 'mail_to_global_roles', $this->mail_obj_ref_id);
1771  }
1772 
1773  $error_message = '';
1774  $message = '';
1775 
1776  if (in_array("system",$a_type))
1777  {
1778  $this->__checkSystemRecipients($a_rcp_to);
1779  $a_type = array('system');
1780  }
1781 
1782  if ($a_attachment)
1783  {
1784  if (!$this->mfile->checkFilesExist($a_attachment))
1785  {
1786  return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1787  }
1788  }
1789  // CHECK NECESSARY MAIL DATA FOR ALL TYPES
1790  if ($error_message = $this->checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1791  {
1792  return $error_message;
1793  }
1794 
1795  try
1796  {
1797  // check recipients
1798  if ($error_message = $this->checkRecipients($a_rcp_to,$a_type))
1799  {
1800  $message .= $error_message;
1801  }
1802 
1803  if ($error_message = $this->checkRecipients($a_rcp_cc,$a_type))
1804  {
1805  $message .= $error_message;
1806  }
1807 
1808  if ($error_message = $this->checkRecipients($a_rcp_bc,$a_type))
1809  {
1810  $message .= $error_message;
1811  }
1812  }
1813 
1814  catch(ilMailException $e)
1815  {
1816  return $this->lng->txt($e->getMessage());
1817  }
1818 
1819  // if there was an error
1820  if (!empty($message))
1821  {
1822  return $this->lng->txt("mail_following_rcp_not_valid").$message;
1823  }
1824 
1825  // ACTIONS FOR ALL TYPES
1826 
1827 
1828  // GET RCPT OF MAILING LISTS
1829 
1830  $rcp_to_list = $this->parseRcptOfMailingLists($a_rcp_to, true);
1831  $rcp_cc_list = $this->parseRcptOfMailingLists($a_rcp_cc, true);
1832  $rcp_bc_list = $this->parseRcptOfMailingLists($a_rcp_bc, true);
1833 
1834  $rcp_to = $rcp_cc = $rcp_bc = array();
1835  foreach($rcp_to_list as $mlist_id => $mlist_rec)
1836  {
1837  if($mlist_id)
1838  {
1839  // internal mailing lists are sent as bcc
1840  $mlist_id = substr($mlist_id, 7);
1841  if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
1842  {
1843  $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1844  continue;
1845  }
1846  }
1847 
1848  $rcp_to = array_merge($rcp_to, $mlist_rec);
1849  }
1850  foreach($rcp_cc_list as $mlist_id => $mlist_rec)
1851  {
1852  if($mlist_id)
1853  {
1854  // internal mailing lists are sent as bcc
1855  $mlist_id = substr($mlist_id, 7);
1856  if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
1857  {
1858  $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1859  continue;
1860  }
1861  }
1862 
1863  $rcp_cc = array_merge($rcp_cc, $mlist_rec);
1864  }
1865  foreach($rcp_bc_list as $mlist_id => $mlist_rec)
1866  {
1867  $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1868  }
1869 
1870  $rcp_to = implode(',', $rcp_to);
1871  $rcp_cc = implode(',', $rcp_cc);
1872  $rcp_bc = implode(',', $rcp_bc);
1873 
1874 
1875  if (! ilMail::_usePearMail() )
1876  {
1877  // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
1878  $rcp_to = $this->__substituteRecipients($rcp_to,"substitute");
1879  $rcp_cc = $this->__substituteRecipients($rcp_cc,"substitute");
1880  $rcp_bc = $this->__substituteRecipients($rcp_bc,"substitute");
1881  }
1882 
1883  // COUNT EMAILS
1884  $c_emails = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,true);
1885  $c_rcp = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,false);
1886 
1887  // currently disabled..
1888  /*
1889  if (count($c_emails))
1890  {
1891  if (!$this->getEmailOfSender())
1892  {
1893  return $lng->txt("mail_check_your_email_addr");
1894  }
1895  }
1896  */
1897 
1898  // check smtp permission
1899  if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1900  !$rbacsystem->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id))
1901  {
1902  return $this->lng->txt('mail_no_permissions_write_smtp');
1903  }
1904 
1905  if($this->appendInstallationSignature())
1906  {
1907  $a_m_message .= self::_getInstallationSignature();
1908  }
1909 
1910  // save mail in sent box
1911  $sent_id = $this->saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1912  $a_m_subject,$a_m_message);
1913 
1914  if($a_attachment)
1915  {
1916  $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1917 
1918  if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1919  {
1920  return $error;
1921  }
1922  }
1923 
1924  // FILTER EMAILS
1925  // IF EMAIL RECIPIENT
1926  if($c_emails)
1927  {
1928  $this->sendMimeMail($this->__getEmailRecipients($rcp_to),
1929  $this->__getEmailRecipients($rcp_cc),
1930  $this->__getEmailRecipients($rcp_bc),
1931  $a_m_subject,
1932  $a_m_message,
1933  $a_attachment,
1934  0);
1935  }
1936 
1937  if (in_array('system',$a_type))
1938  {
1939  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))
1940  {
1941  return $lng->txt("mail_send_error");
1942  }
1943  }
1944  // ACTIONS FOR TYPE SYSTEM AND NORMAL
1945  if (in_array('normal',$a_type))
1946  {
1947  // TRY BOTH internal and email (depends on user settings)
1948  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))
1949  {
1950  return $lng->txt("mail_send_error");
1951  }
1952  }
1953 
1954  // Temporary bugfix
1955  if (!$this->getSaveInSentbox())
1956  {
1957  $this->deleteMails(array($sent_id));
1958  }
1959 
1960  return '';
1961  }
1962 
1963  function parseRcptOfMailingLists($rcpt = '', $maintain_lists = false)
1964  {
1965  if ($rcpt == '')
1966  {
1967  if(!$maintain_lists)
1968  {
1969  return $rcpt;
1970  }
1971  else
1972  {
1973  return array();
1974  }
1975  }
1976 //@todo check rcp pear validation
1977  $arrRcpt = $this->explodeRecipients(trim($rcpt));
1978  if (!is_array($arrRcpt) || empty($arrRcpt))
1979  {
1980  if(!$maintain_lists)
1981  {
1982  return $rcpt;
1983  }
1984  else
1985  {
1986  return array();
1987  }
1988  }
1989 
1990  $new_rcpt = array();
1991 
1992  foreach ($arrRcpt as $item)
1993  {
1994  if (ilMail::_usePearMail())
1995  {
1996  if (substr($item->mailbox, 0, 7) == '#il_ml_')
1997  {
1998  if ($this->mlists->mailingListExists($item->mailbox))
1999  {
2000  foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2001  {
2002  if(!$maintain_lists)
2003  {
2004  $new_rcpt[] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2005  }
2006  else
2007  {
2008  $new_rcpt[$item->mailbox][] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2009  }
2010  }
2011  }
2012  }
2013  else
2014  {
2015  $tmp_rcpt = '';
2016  if($item->host == self::ILIAS_HOST)
2017  {
2018  $tmp_rcpt = $item->mailbox;
2019  }
2020  else
2021  {
2022  $tmp_rcpt = $item->mailbox.'@'.$item->host;
2023  }
2024 
2025  if(!$maintain_lists)
2026  {
2027  $new_rcpt[] = $tmp_rcpt;
2028  }
2029  else
2030  {
2031  $new_rcpt[0][] = $tmp_rcpt;
2032  }
2033  }
2034  }
2035  else
2036  {
2037  if (substr($item, 0, 7) == '#il_ml_')
2038  {
2039  if ($this->mlists->mailingListExists($item))
2040  {
2041  foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2042  {
2043  if(!$maintain_lists)
2044  {
2045  $new_rcpt[] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2046  }
2047  else
2048  {
2049  $new_rcpt[$item][] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2050  }
2051  }
2052  }
2053  }
2054  else
2055  {
2056  if(!$maintain_lists)
2057  {
2058  $new_rcpt[] = $item;
2059  }
2060  else
2061  {
2062  $new_rcpt[0][] = $item;
2063  }
2064  }
2065  }
2066  }
2067 
2068  if(!$maintain_lists)
2069  {
2070  return implode(',', $new_rcpt);
2071  }
2072  else
2073  {
2074  return $new_rcpt;
2075  }
2076  }
2077 
2090  function saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_type,
2091  $a_m_subject,$a_m_message)
2092  {
2093  include_once "Services/Mail/classes/class.ilMailbox.php";
2094 
2095  $mbox = new ilMailbox($this->user_id);
2096  $sent_id = $mbox->getSentFolder();
2097 
2099  return $this->sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
2100  $a_rcp_bcc,'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2101  }
2102 
2109  public static function addFullname($a_email, $a_fullname)
2110  {
2111  include_once 'Services/Mail/classes/class.ilMimeMail.php';
2112  return ilMimeMail::_mimeEncode($a_fullname).' <'.$a_email.'>';
2113  }
2114 
2121  public function getMimeMailSender()
2122  {
2126  global $ilUser;
2127 
2128  include_once "Services/Mail/classes/class.ilMimeMail.php";
2129 
2130  if($this->user_id && $this->user_id != ANONYMOUS_USER_ID)
2131  {
2132  $email = $ilUser->getEmail();
2133  $fullname = $ilUser->getFullname();
2134  if($ilUser->getId() != $this->user_id)
2135  {
2136  $user = self::getCachedUserInstance($this->user_id);
2137  $email = $user->getEmail();
2138  $fullname = $user->getFullname();
2139  }
2140 
2141  $sender = self::addFullname($email, $fullname);
2142  }
2143  else
2144  {
2145  $sender = self::getIliasMailerAddress();
2146  }
2147 
2148  return $sender;
2149  }
2150 
2160  public static function getIliasMailerAddress()
2161  {
2162  global $ilSetting;
2163 
2164  include_once 'Services/Mail/classes/class.ilMimeMail.php';
2165 
2166  $no_reply_adress = trim($ilSetting->get('mail_external_sender_noreply'));
2167  if(strlen($no_reply_adress))
2168  {
2169  if(strpos($no_reply_adress, '@') === false)
2170  $no_reply_adress = 'noreply@'.$no_reply_adress;
2171 
2172  if(!ilUtil::is_email($no_reply_adress))
2173  {
2174  $no_reply_adress = 'noreply@'.$_SERVER['SERVER_NAME'];
2175  }
2176 
2177  $sender = ilMimeMail::_mimeEncode(self::_getIliasMailerName()).
2178  ' <'.$no_reply_adress.'>';
2179  }
2180  else
2181  {
2182  $sender = ilMimeMail::_mimeEncode(self::_getIliasMailerName()).
2183  ' <noreply@'.$_SERVER['SERVER_NAME'].'>';
2184  }
2185 
2186  return $sender;
2187  }
2188 
2202  function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,$a_no_soap = false)
2203  {
2204  include_once "Services/Mail/classes/class.ilMimeMail.php";
2205 
2206  #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2207 
2208  #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2209  #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2210 
2211  $a_m_subject = self::getSubjectPrefix().' '.$a_m_subject;
2212 
2213  $sender = $this->getMimeMailSender();
2214 
2215  // #10854
2216  if($this->isSOAPEnabled() && !$a_no_soap)
2217  {
2218  // Send per soap
2219  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2220 
2221  $soap_client = new ilSoapClient();
2222  $soap_client->setResponseTimeout(1);
2223  $soap_client->enableWSDL(true);
2224  $soap_client->init();
2225 
2226  $attachments = array();
2227  $a_attachments = $a_attachments ? $a_attachments : array();
2228  foreach($a_attachments as $attachment)
2229  {
2230  $attachments[] = $this->mfile->getAbsolutePath($attachment);
2231  }
2232  // mjansen: switched separator from "," to "#:#" because of mantis bug #6039
2233  $attachments = implode('#:#',$attachments);
2234  // mjansen: use "#:#" as leading delimiter
2235  if(strlen($attachments))
2236  $attachments = "#:#".$attachments;
2237 
2238  $soap_client->call('sendMail',array(session_id().'::'.$_COOKIE['ilClientId'], // session id
2239  $a_rcp_to,
2240  $a_rcp_cc,
2241  $a_rcp_bcc,
2242  $sender,
2243  $a_m_subject,
2244  $a_m_message,
2245  $attachments));
2246 
2247  return true;
2248  }
2249  else
2250  {
2251  // send direct
2252  include_once "Services/Mail/classes/class.ilMimeMail.php";
2253 
2254  $mmail = new ilMimeMail();
2255  $mmail->autoCheck(false);
2256  $mmail->From($sender);
2257  $mmail->To($a_rcp_to);
2258  // Add installation name to subject
2259  $mmail->Subject($a_m_subject);
2260  $mmail->Body($a_m_message);
2261 
2262  if ($a_rcp_cc)
2263  {
2264  $mmail->Cc($a_rcp_cc);
2265  }
2266 
2267  if ($a_rcp_bcc)
2268  {
2269  $mmail->Bcc($a_rcp_bcc);
2270  }
2271 
2272  if (is_array($a_attachments))
2273  {
2274  foreach ($a_attachments as $attachment)
2275  {
2276  $mmail->Attach($this->mfile->getAbsolutePath($attachment), '', 'inline', $attachment);
2277  }
2278  }
2279 
2280  $mmail->Send();
2281  }
2282  }
2288  function getEmailOfSender()
2289  {
2290  $umail = self::getCachedUserInstance($this->user_id);
2291  $sender = $umail->getEmail();
2292 
2293  if (ilUtil::is_email($sender))
2294  {
2295  return $sender;
2296  }
2297  else
2298  {
2299  return '';
2300  }
2301  }
2302 
2309  function saveAttachments($a_attachments)
2310  {
2311  global $ilDB;
2312 
2313  $ilDB->update($this->table_mail_saved,
2314  array
2315  (
2316  'attachments' => array('clob', serialize($a_attachments))
2317  ),
2318  array
2319  (
2320  'user_id' => array('integer', $this->user_id)
2321  )
2322  );
2323 
2324  return true;
2325  }
2326 
2332  function getAttachments()
2333  {
2334  return $this->mail_data["attachments"] ? $this->mail_data["attachments"] : array();
2335  }
2336 
2350  function explodeRecipients($a_recipients, $use_pear = true)
2351  {
2352  $a_recipients = trim($a_recipients);
2353 
2354  // WHITESPACE IS NOT ALLOWED AS SEPERATOR
2355  #$a_recipients = preg_replace("/ /",",",$a_recipients);
2356  $a_recipients = preg_replace("/;/",",",$a_recipients);
2357 
2358  if (ilMail::_usePearMail() && $use_pear == true)
2359  {
2360  if (strlen(trim($a_recipients)) > 0)
2361  {
2362  require_once './Services/PEAR/lib/Mail/RFC822.php';
2363  $parser = new Mail_RFC822();
2364  return $parser->parseAddressList($a_recipients, self::ILIAS_HOST, false, true);
2365  } else {
2366  return array();
2367  }
2368  }
2369  else
2370  {
2371  foreach(explode(',',$a_recipients) as $tmp_rec)
2372  {
2373  if($tmp_rec)
2374  {
2375  $rcps[] = trim($tmp_rec);
2376  }
2377  }
2378  return is_array($rcps) ? $rcps : array();
2379  }
2380  }
2381 
2382  function __getCountRecipient($rcp,$a_only_email = true)
2383  {
2384  $counter = 0;
2385 
2386  $this->validatePear($rcp);
2387  if (ilMail::_usePearMail() && $this->getUsePear())
2388  {
2389  $tmp_rcp = $this->explodeRecipients($rcp);
2390  if (! is_a($tmp_rcp, 'PEAR_Error'))
2391  {
2392  foreach ($tmp_rcp as $to)
2393  {
2394  if ($a_only_email)
2395  {
2396  // Fixed mantis bug #5875
2397  if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2398  {
2399  continue;
2400  }
2401 
2402  // Addresses which aren't on the self::ILIAS_HOST host, and
2403  // which have a mailbox which does not start with '#',
2404  // are external e-mail addresses
2405  if ($to->host != self::ILIAS_HOST && substr($to->mailbox,0,1) != '#')
2406  {
2407  ++$counter;
2408  }
2409  }
2410  else
2411  {
2412  ++$counter;
2413  }
2414  }
2415  }
2416  }
2417  else
2418  {
2419  foreach ($this->explodeRecipients($rcp,$this->getUsePear()) as $to)
2420  {
2421  if ($a_only_email)
2422  {
2423  $to = $this->__substituteRecipients($to,"resubstitute");
2424  if (strpos($to,'@'))
2425  {
2426  // Fixed mantis bug #5875
2427  if(ilObjUser::_lookupId($to))
2428  {
2429  continue;
2430  }
2431 
2432  ++$counter;
2433  }
2434  }
2435  else
2436  {
2437  ++$counter;
2438  }
2439  }
2440  }
2441  return $counter;
2442  }
2443 
2444 
2445  function __getCountRecipients($a_to,$a_cc,$a_bcc,$a_only_email = true)
2446  {
2447  return $this->__getCountRecipient($a_to,$a_only_email)
2448  + $this->__getCountRecipient($a_cc,$a_only_email)
2449  + $this->__getCountRecipient($a_bcc,$a_only_email);
2450  }
2451 
2452  function __getEmailRecipients($a_rcp)
2453  {
2454  if (ilMail::_usePearMail())
2455  {
2456  $rcp = array();
2457  $tmp_rcp = $this->explodeRecipients($a_rcp);
2458  if (! is_a($tmp_rcp, 'PEAR_Error'))
2459  {
2460  foreach ($tmp_rcp as $to)
2461  {
2462  if(substr($to->mailbox,0,1) != '#' && $to->host != self::ILIAS_HOST)
2463  {
2464  // Fixed mantis bug #5875
2465  if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2466  {
2467  continue;
2468  }
2469 
2470  $rcp[] = $to->mailbox.'@'.$to->host;
2471  }
2472  }
2473  }
2474  return implode(',',$rcp);
2475  }
2476  else
2477  {
2478  foreach ($this->explodeRecipients($a_rcp) as $to)
2479  {
2480  $to = $this->__substituteRecipients($to,"resubstitute");
2481  if(strpos($to,'@'))
2482  {
2483  // Fixed mantis bug #5875
2484  if(ilObjUser::_lookupId($to))
2485  {
2486  continue;
2487  }
2488 
2489  $rcp[] = $to;
2490  }
2491  }
2492  return implode(',',$rcp ? $rcp : array());
2493  }
2494  }
2495 
2496  function __prependMessage($a_m_message,$rcp_to,$rcp_cc)
2497  {
2498  $inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 3";
2499 
2500  $message = $inst_name." To:".$rcp_to."\n";
2501 
2502  if ($rcp_cc)
2503  {
2504  $message .= "Cc: ".$rcp_cc;
2505  }
2506 
2507  $message .= "\n\n";
2508  $message .= $a_m_message;
2509 
2510  return $message;
2511  }
2512 
2513  function __checkSystemRecipients(&$a_rcp_to)
2514  {
2515  if (preg_match("/@all/",$a_rcp_to))
2516  {
2517  // GET ALL LOGINS
2518  $all = ilObjUser::_getAllUserLogins($this->ilias);
2519  $a_rcp_to = preg_replace("/@all/",implode(',',$all),$a_rcp_to);
2520  }
2521 
2522  return;
2523  }
2524 
2532  function __substituteRecipients($a_rcp,$direction)
2533  {
2534  $new_name = array();
2535 
2536  $tmp_names = $this->explodeRecipients($a_rcp);
2537 
2538 
2539  foreach($tmp_names as $name)
2540  {
2541  if(strpos($name,"#") === 0)
2542  {
2543  $new_name[] = $name;
2544  continue;
2545  }
2546  switch($direction)
2547  {
2548  case "substitute":
2549  if(strpos($name,"@") and ilObjUser::_loginExists($name))
2550  {
2551  $new_name[] = preg_replace("/@/","�#�",$name);
2552  }
2553  else
2554  {
2555  $new_name[] = $name;
2556  }
2557  break;
2558 
2559  case "resubstitute":
2560  if(stristr($name,"�#�"))
2561  {
2562  $new_name[] = preg_replace("/�#�/","@",$name);
2563  }
2564  else
2565  {
2566  $new_name[] = $name;
2567  }
2568  break;
2569  }
2570  }
2571  return implode(",",$new_name);
2572  }
2573 
2589  public static function _getUserInternalMailboxAddress($usr_id, $login=null, $firstname=null, $lastname=null)
2590  {
2591  if (ilMail::_usePearMail())
2592  {
2593  if ($login == null)
2594  {
2595  require_once './Services/User/classes/class.ilObjUser.php';
2596  $usr_obj = self::getCachedUserInstance($usr_id);
2597  $login = $usr_obj->getLogin();
2598  $firstname = $usr_obj->getFirstname();
2599  $lastname = $usr_obj->getLastname();
2600  }
2601  // The following line of code creates a properly formatted mailbox
2602  // address. Unfortunately, it does not work, because ILIAS removes
2603  // everything between '<' '>' characters
2604  // Therefore, we just return the login - sic.
2605  // FIXME - Make this work in a future release
2606  /*
2607  return preg_replace('/[()<>@,;:\\".\[\]]/','',$firstname.' '.$lastname).' <'.$login.'>';
2608  */
2609  return $login.'hhho';
2610  }
2611  else
2612  {
2613  return $login;
2614  }
2615  }
2622  public static function _usePearMail()
2623  {
2627  global $ilSetting;
2628 
2629  return $ilSetting->get('pear_mail_enable', 0);
2630  }
2631 
2640  public static function _getAutoGeneratedMessageString($lang = null)
2641  {
2642  global $ilSetting;
2643 
2644  if(!$lang)
2645  {
2646  include_once('./Services/Language/classes/class.ilLanguageFactory.php');
2648  }
2649  $http_path = ilUtil::_getHttpPath();
2650 
2651  $lang->loadLanguageModule('mail');
2652  return sprintf($lang->txt('mail_auto_generated_info'),
2653  $ilSetting->get('inst_name','ILIAS 5'),
2654  $http_path)."\n\n";
2655  }
2656 
2663  public static function _getIliasMailerName()
2664  {
2668  global $ilSetting;
2669 
2670  if(strlen($ilSetting->get('mail_system_sender_name')))
2671  {
2672  return $ilSetting->get('mail_system_sender_name');
2673  }
2674  else if(strlen($ilSetting->get('short_inst_name')))
2675  {
2676  return $ilSetting->get('short_inst_name');
2677  }
2678 
2679  return 'ILIAS';
2680  }
2681 
2690  public function appendInstallationSignature($a_flag = null)
2691  {
2692  if(null === $a_flag) {
2694  }
2695 
2696  $this->appendInstallationSignature = $a_flag;
2697 
2698  return $this;
2699  }
2700 
2709  public static function _getInstallationSignature()
2710  {
2711  global $ilClientIniFile;
2712 
2713  $signature = "\n\n* * * * *\n";
2714 
2715  $signature .= $ilClientIniFile->readVariable('client', 'name')."\n";
2716  if(strlen($desc = $ilClientIniFile->readVariable('client', 'description')))
2717  {
2718  $signature .= $desc."\n";
2719  }
2720 
2721  $signature .= ilUtil::_getHttpPath();
2722 
2723  $clientdirs = glob(ILIAS_WEB_DIR."/*", GLOB_ONLYDIR);
2724  if(is_array($clientdirs) && count($clientdirs) > 1)
2725  {
2726  // #18051
2727  $signature .= '/login.php?client_id='.CLIENT_ID;
2728  }
2729 
2730  $signature .= "\n\n";
2731 
2732  return $signature;
2733  }
2734 
2739  public static function getSubjectPrefix()
2740  {
2741  global $ilSetting;
2742  static $prefix = null;
2743 
2744  return $prefix == null ? $ilSetting->get('mail_subject_prefix','') : $prefix;
2745  }
2746 
2752  public static function getSalutation($a_usr_id,$a_language = null)
2753  {
2754  global $lng;
2755 
2756  $lang = $a_language ? $a_language : $lng;
2757 
2758  $lang->loadLanguageModule('mail');
2759  $gender = ilObjUser::_lookupGender($a_usr_id);
2760  $gender = $gender ? $gender : 'n';
2761  $name = ilObjUser::_lookupName($a_usr_id);
2762 
2763  if(!strlen($name['firstname']))
2764  {
2765  return $lang->txt('mail_salutation_anonymous').',';
2766  }
2767 
2768  return $lang->txt('mail_salutation_'.$gender).' '.
2769  ($name['title'] ? $name['title'].' ' : '').
2770  ($name['firstname'] ? $name['firstname'].' ' : '').
2771  $name['lastname'].',';
2772  }
2773 
2774  private function setUsePear($bool)
2775  {
2776  $this->use_pear = $bool;
2777  }
2778 
2779  private function getUsePear()
2780  {
2781  return $this->use_pear;
2782  }
2783 
2784  // Force fallback for sending mails via ILIAS, if internal Pear-Validation returns PEAR_Error
2789  private function validatePear($a_recipients)
2790  {
2791  if(ilMail::_usePearMail())
2792  {
2793  $this->setUsePear(true);
2794  $tmp_names = $this->explodeRecipients($a_recipients, true);
2795  if(is_a($tmp_names, 'PEAR_Error'))
2796  {
2797  $this->setUsePear(false);
2798  }
2799  }
2800  else
2801  {
2802  $this->setUsePear(false);
2803  }
2804  }
2805 
2814  protected static function getCachedUserInstance($a_usr_id)
2815  {
2816  if(isset(self::$userInstances[$a_usr_id]))
2817  {
2818  return self::$userInstances[$a_usr_id];
2819  }
2820 
2821  self::$userInstances[$a_usr_id] = new ilObjUser($a_usr_id);
2822  return self::$userInstances[$a_usr_id];
2823  }
2824 } // END class.ilMail
2825 ?>