ILIAS  Release_4_4_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 
218  protected $properties = array();
219 
223  protected static $userInstances = array();
224 
231  public function __construct($a_user_id)
232  {
233  require_once "./Services/Mail/classes/class.ilFileDataMail.php";
234  require_once "Services/Mail/classes/class.ilMailOptions.php";
235 
236  global $ilias, $lng, $ilUser;
237 
238  $lng->loadLanguageModule("mail");
239 
240  // Initiate variables
241  $this->ilias =& $ilias;
242  $this->lng =& $lng;
243  $this->table_mail = 'mail';
244  $this->table_mail_saved = 'mail_saved';
245  $this->user_id = $a_user_id;
246  $this->mfile = new ilFileDataMail($this->user_id);
247  $this->mail_options = new ilMailOptions($a_user_id);
248 
249  // DEFAULT: sent mail aren't stored insentbox of user.
250  $this->setSaveInSentbox(false);
251 
252  // GET REFERENCE ID OF MAIL OBJECT
253  $this->readMailObjectReferenceId();
254  }
255 
263  public function __get($name)
264  {
265  global $ilUser;
266 
267  if(isset($this->properties[$name]))
268  {
269  return $this->properties[$name];
270  }
271 
272  // Used to include files / instantiate objects at runtime
273  if($name == 'mlists')
274  {
275  if(is_object($ilUser))
276  {
277  require_once 'Services/Contact/classes/class.ilMailingLists.php';
278  $this->properties[$name] = new ilMailingLists($ilUser);
279  return $this->properties[$name];
280  }
281  }
282  }
283 
284  public function doesRecipientStillExists($a_recipient, $a_existing_recipients)
285  {
286  if(self::_usePearMail())
287  {
288  $recipients = $this->explodeRecipients($a_existing_recipients);
289  if(is_a($recipients, 'PEAR_Error'))
290  {
291  return false;
292  }
293  else
294  {
295  foreach($recipients as $rcp)
296  {
297  if (substr($rcp->mailbox, 0, 1) != '#')
298  {
299  if(trim($rcp->mailbox) == trim($a_recipient) ||
300  trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
301  {
302  return true;
303  }
304  }
305  else if (substr($rcp->mailbox, 0, 7) == '#il_ml_')
306  {
307  if(trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
308  {
309  return true;
310  }
311  }
312  else
313  {
314  if(trim($rcp->mailbox.'@'.$rcp->host) == trim($a_recipient))
315  {
316  return true;
317  }
318  }
319  }
320  }
321  }
322  else
323  {
324  $recipients = $this->explodeRecipients($a_existing_recipients);
325  if(count($recipients))
326  {
327  foreach($recipients as $recipient)
328  {
329  if(trim($recipient) == trim($a_recipient))
330  {
331  return true;
332  }
333  }
334  }
335  }
336 
337  return false;
338  }
339 
347  function enableSOAP($a_status)
348  {
349  $this->soap_enabled = $a_status;
350  }
351  function isSOAPEnabled()
352  {
353  global $ilSetting;
354 
355  if(!extension_loaded('curl') || !$ilSetting->get('soap_user_administration'))
356  {
357  return false;
358  }
359 
360  // Prevent using SOAP in cron context
362  {
363  return false;
364  }
365 
366  return (bool) $this->soap_enabled;
367  }
368 
369 
370  function setSaveInSentbox($a_save_in_sentbox)
371  {
372  $this->save_in_sentbox = $a_save_in_sentbox;
373  }
374 
375  function getSaveInSentbox()
376  {
377  return $this->save_in_sentbox;
378  }
379 
385  function setMailSendType($a_types)
386  {
387  $this->mail_send_type = $a_types;
388  }
389 
395  function setMailRcpTo($a_rcp_to)
396  {
397  $this->mail_rcp_to = $a_rcp_to;
398  }
399 
405  function setMailRcpCc($a_rcp_cc)
406  {
407  $this->mail_rcp_cc = $a_rcp_cc;
408  }
409 
415  function setMailRcpBc($a_rcp_bc)
416  {
417  $this->mail_rcp_bc = $a_rcp_bc;
418  }
419 
425  function setMailSubject($a_subject)
426  {
427  $this->mail_subject = $a_subject;
428  }
429 
435  function setMailMessage($a_message)
436  {
437  $this->mail_message = $a_message;
438  }
439 
445  {
446  include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
447  $this->mail_obj_ref_id = ilMailGlobalServices::getMailObjectRefId();
448  }
449 
451  {
452  return $this->mail_obj_ref_id;
453  }
454 
465  public function formatNamesForOutput($users = '')
466  {
467  $users = trim($users);
468  if($users)
469  {
470  if(strstr($users, ','))
471  {
472  $rcp_to_array = array();
473 
474  $recipients = explode(',', $users);
475  foreach($recipients as $recipient)
476  {
477  $recipient = trim($recipient);
478  if($uid = ilObjUser::_lookupId($recipient))
479  {
480  if (in_array(ilObjUser::_lookupPref($uid, 'public_profile'), array("y", "g")))
481  {
482  $tmp_obj = self::getCachedUserInstance($uid);
483  $rcp_to_array[] = $tmp_obj->getFullname().' ['.$recipient.']';
484  }
485  else
486  {
487  $rcp_to_array[] = $recipient;
488  }
489  }
490  else
491  {
492  $rcp_to_array[] = $recipient;
493  }
494  }
495 
496  return trim(implode(', ', $rcp_to_array));
497  }
498  else
499  {
500  if($uid = ilObjUser::_lookupId($users))
501  {
502  if (in_array(ilObjUser::_lookupPref($uid, 'public_profile'), array("y", "g")))
503  {
504  $tmp_obj = self::getCachedUserInstance($uid);
505  return $tmp_obj->getFullname().' ['.$users.']';
506  }
507  else
508  {
509  return $users;
510  }
511  }
512  else
513  {
514  return $users;
515  }
516  }
517  }
518  else
519  {
520  return $this->lng->txt('not_available');
521  }
522  }
523 
524  function getPreviousMail($a_mail_id)
525  {
526  global $ilDB;
527 
528  $ilDB->setLimit(1);
529  $res = $ilDB->queryf("
530  SELECT b.* FROM " . $this->table_mail ." a
531  INNER JOIN ".$this->table_mail ." b ON b.folder_id = a.folder_id
532  AND b.user_id = a.user_id AND b.send_time > a.send_time
533  WHERE a.user_id = %s
534  AND a.mail_id = %s ORDER BY b.send_time ASC",
535  array('integer', 'integer'),
536  array($this->user_id, $a_mail_id));
537 
538  $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
539 
540  return $this->mail_data;
541  }
542 
543  function getNextMail($a_mail_id)
544  {
545  global $ilDB;
546 
547  $ilDB->setLimit(1);
548  $res = $ilDB->queryf("
549  SELECT b.* FROM " . $this->table_mail ." a
550  INNER JOIN ".$this->table_mail ." b ON b.folder_id = a.folder_id
551  AND b.user_id = a.user_id AND b.send_time < a.send_time
552  WHERE a.user_id = %s
553  AND a.mail_id = %s ORDER BY b.send_time DESC",
554  array('integer', 'integer'),
555  array($this->user_id, $a_mail_id));
556 
557  $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
558 
559  return $this->mail_data;
560  }
561 
569  function getMailsOfFolder($a_folder_id, $filter = array())
570  {
571  global $ilDB;
572 
573  $this->mail_counter = array();
574  $this->mail_counter['read'] = 0;
575  $this->mail_counter['unread'] = 0;
576 
577  $query = "SELECT sender_id, m_subject, mail_id, m_status, send_time FROM ". $this->table_mail ."
578  LEFT JOIN object_data ON obj_id = sender_id
579  WHERE user_id = %s
580  AND folder_id = %s
581  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)) ";
582 
583  if($filter['status'])
584  {
585  $query .= ' AND m_status = '.$ilDB->quote($filter['status'], 'text');
586  }
587  if($filter['type'])
588  {
589  $query .= ' AND '.$ilDB->like('m_type', 'text', '%%:"'.$filter['type'].'"%%', false);
590  }
591 
592  $query .= " ORDER BY send_time DESC";
593 
594  $res = $ilDB->queryf($query,
595  array('integer', 'integer'),
596  array($this->user_id, $a_folder_id));
597 
598  while ($row = $ilDB->fetchObject($res))
599  {
600  $tmp = $this->fetchMailData($row);
601 
602  if($tmp['m_status'] == 'read')
603  {
604  ++$this->mail_counter['read'];
605  }
606 
607  if($tmp['m_status'] == 'unread')
608  {
609  ++$this->mail_counter['unread'];
610  }
611 
612  $output[] = $tmp;
613  }
614 
615  $this->mail_counter['total'] = count($output);
616 
617  return $output ? $output : array();
618  }
619 
626  function countMailsOfFolder($a_folder_id)
627  {
628  global $ilDB;
629 
630  $res = $ilDB->queryf("
631  SELECT COUNT(*) FROM ". $this->table_mail ."
632  WHERE user_id = %s
633  AND folder_id = %s",
634  array('integer', 'integer'),
635  array($this->user_id, $a_folder_id));
636 
637  return $res->numRows();
638  }
639 
646  function deleteMailsOfFolder($a_folder_id)
647  {
648  if ($a_folder_id)
649  {
650  global $ilDB;
651 
652  /*$statement = $ilDB->manipulateF("
653  DELETE FROM ". $this->table_mail ."
654  WHERE user_id = %s
655  AND folder_id = %s",
656  array('integer', 'integer'),
657  array($this->user_id, $a_folder_id));*/
658  $mails = $this->getMailsOfFolder($a_folder_id);
659  foreach((array)$mails as $mail_data)
660  {
661  $this->deleteMails(array($mail_data['mail_id']));
662  }
663 
664  return true;
665  }
666 
667  return false;
668  }
669 
677  {
678  return is_array($this->mail_counter) ? $this->mail_counter : array(
679  "total" => 0,
680  "read" => 0,
681  "unread" => 0);
682  }
683 
690  function getMail($a_mail_id)
691  {
692  global $ilDB;
693 
694  $res = $ilDB->queryf("
695  SELECT * FROM ". $this->table_mail ."
696  WHERE user_id = %s
697  AND mail_id = %s",
698  array('integer', 'integer'),
699  array($this->user_id, $a_mail_id));
700 
701  $this->mail_data =$this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
702 
703  return $this->mail_data;
704  }
705 
712  function markRead($a_mail_ids)
713  {
714 
715  global $ilDB;
716 
717  $data = array();
718  $data_types = array();
719 
720  $query = "UPDATE ". $this->table_mail ."
721  SET m_status = %s
722  WHERE user_id = %s ";
723  array_push($data_types, 'text', 'integer');
724  array_push($data, 'read', $this->user_id);
725 
726  $cnt_mail_ids = count($a_mail_ids);
727 
728  if (is_array($a_mail_ids) &&
729  count($a_mail_ids) > 0)
730  {
731 
732  $in = 'mail_id IN (';
733  $counter = 0;
734  foreach($a_mail_ids as $a_mail_id)
735  {
736  array_push($data, $a_mail_id);
737  array_push($data_types, 'integer');
738 
739  if($counter > 0) $in .= ',';
740  $in .= '%s';
741  ++$counter;
742  }
743  $in .= ')';
744 
745  $query .= ' AND '.$in;
746  }
747 
748  $res = $ilDB->manipulateF($query, $data_types, $data);
749 
750  return true;
751  }
752 
759  function markUnread($a_mail_ids)
760  {
761  global $ilDB;
762 
763  $data = array();
764  $data_types = array();
765 
766  $query = "UPDATE ". $this->table_mail ."
767  SET m_status = %s
768  WHERE user_id = %s ";
769  array_push($data_types, 'text', 'integer');
770  array_push($data, 'unread', $this->user_id);
771 
772  $cnt_mail_ids = count($a_mail_ids);
773 
774  if (is_array($a_mail_ids) &&
775  count($a_mail_ids) > 0)
776  {
777 
778  $in = 'mail_id IN (';
779  $counter = 0;
780  foreach($a_mail_ids as $a_mail_id)
781  {
782  array_push($data, $a_mail_id);
783  array_push($data_types, 'integer');
784 
785  if($counter > 0) $in .= ',';
786  $in .= '%s';
787  ++$counter;
788  }
789  $in .= ')';
790 
791  $query .= ' AND '.$in;
792  }
793 
794  $statement = $ilDB->manipulateF($query, $data_types, $data);
795 
796  return true;
797  }
798 
806  function moveMailsToFolder($a_mail_ids,$a_folder_id)
807  {
808  global $ilDB;
809 
810  $data = array();
811  $data_types = array();
812 
813  $query = "UPDATE ". $this->table_mail ."
814  SET folder_id = %s
815  WHERE user_id = %s ";
816  array_push($data_types, 'text', 'integer');
817  array_push($data, $a_folder_id, $this->user_id);
818 
819  $cnt_mail_ids = count($a_mail_ids);
820 
821  if (is_array($a_mail_ids) &&
822  count($a_mail_ids) > 0)
823  {
824 
825  $in = 'mail_id IN (';
826  $counter = 0;
827  foreach($a_mail_ids as $a_mail_id)
828  {
829  array_push($data, $a_mail_id);
830  array_push($data_types, 'integer');
831 
832  if($counter > 0) $in .= ',';
833  $in .= '%s';
834  ++$counter;
835  }
836  $in .= ')';
837 
838  $query .= ' AND '.$in;
839  }
840 
841  $statement = $ilDB->manipulateF($query, $data_types, $data);
842 
843  return true;
844  }
845 
852  function deleteMails($a_mail_ids)
853  {
854  global $ilDB;
855 
856  foreach ($a_mail_ids as $id)
857  {
858  $statement = $ilDB->manipulateF("
859  DELETE FROM ". $this->table_mail ."
860  WHERE user_id = %s
861  AND mail_id = %s ",
862  array('integer', 'integer'),
863  array($this->user_id, $id));
864 
865  $this->mfile->deassignAttachmentFromDirectory($id);
866  }
867 
868  return true;
869  }
870 
877  function fetchMailData($a_row)
878  {
879  if (!$a_row) return;
880 
881  return array(
882  "mail_id" => $a_row->mail_id,
883  "user_id" => $a_row->user_id,
884  "folder_id" => $a_row->folder_id,
885  "sender_id" => $a_row->sender_id,
886  "attachments" => unserialize(stripslashes($a_row->attachments)),
887  "send_time" => $a_row->send_time,
888  "rcp_to" => $a_row->rcp_to,
889  "rcp_cc" => $a_row->rcp_cc,
890  "rcp_bcc" => $a_row->rcp_bcc,
891  "m_status" => $a_row->m_status,
892  "m_type" => unserialize(stripslashes($a_row->m_type)),
893  "m_email" => $a_row->m_email,
894  "m_subject" => $a_row->m_subject,
895  "m_message" => $a_row->m_message,
896  "import_name" => $a_row->import_name,
897  "use_placeholders"=> $a_row->use_placeholders);
898  }
899 
900  function updateDraft($a_folder_id,
901  $a_attachments,
902  $a_rcp_to,
903  $a_rcp_cc,
904  $a_rcp_bcc,
905  $a_m_type,
906  $a_m_email,
907  $a_m_subject,
908  $a_m_message,
909  $a_draft_id = 0, $a_use_placeholders = 0)
910  {
911  global $ilDB;
912 
913  $ilDB->update($this->table_mail,
914  array(
915  'folder_id' => array('integer', $a_folder_id),
916  'attachments' => array('clob', serialize($a_attachments)),
917  'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
918  'rcp_to' => array('clob', $a_rcp_to),
919  'rcp_cc' => array('clob', $a_rcp_cc),
920  'rcp_bcc' => array('clob', $a_rcp_bcc),
921  'm_status' => array('text', 'read'),
922  'm_type' => array('text', serialize($a_m_type)),
923  'm_email' => array('integer', $a_m_email),
924  'm_subject' => array('text', $a_m_subject),
925  'm_message' => array('clob', $a_m_message),
926  'use_placeholders' => array('integer', $a_use_placeholders)
927  ),
928  array(
929  'mail_id' => array('integer', $a_draft_id)
930  )
931  );
932 
933  return $a_draft_id;
934  }
935 
953  function sendInternalMail($a_folder_id,
954  $a_sender_id,
955  $a_attachments,
956  $a_rcp_to,
957  $a_rcp_cc,
958  $a_rcp_bcc,
959  $a_status,
960  $a_m_type,
961  $a_m_email,
962  $a_m_subject,
963  $a_m_message,
964  $a_user_id = 0, $a_use_placeholders = 0)
965  {
966  $a_user_id = $a_user_id ? $a_user_id : $this->user_id;
967 
968  global $ilDB, $log;
969  //$log->write('class.ilMail->sendInternalMail to user_id:'.$a_rcp_to.' '.$a_m_message);
970 
971  if ($a_use_placeholders)
972  {
973  $a_m_message = $this->replacePlaceholders($a_m_message, $a_user_id);
974  }
975  else
976  {
977  $a_use_placeholders = '0';
978  }
979 
980 
981  if(!$a_user_id) $a_user_id = '0';
982  if(!$a_folder_id) $a_folder_id = '0';
983  if(!$a_sender_id) $a_sender_id = NULL;
984  if(!$a_attachments) $a_attachments = NULL;
985  if(!$a_rcp_to) $a_rcp_to = NULL;
986  if(!$a_rcp_cc) $a_rcp_cc = NULL;
987  if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
988  if(!$a_status) $a_status = NULL;
989  if(!$a_m_type) $a_m_type = NULL;
990  if(!$a_m_email) $a_m_email = NULL;
991  if(!$a_m_subject) $a_m_subject = NULL;
992  if(!$a_m_message) $a_m_message = NULL;
993 
994 
995  $next_id = $ilDB->nextId($this->table_mail);
996 
997  $ilDB->insert($this->table_mail, array(
998  'mail_id' => array('integer', $next_id),
999  'user_id' => array('integer', $a_user_id),
1000  'folder_id' => array('integer', $a_folder_id),
1001  'sender_id' => array('integer', $a_sender_id),
1002  'attachments' => array('clob', serialize($a_attachments)),
1003  'send_time' => array('timestamp', date('Y-m-d H:i:s', time())),
1004  'rcp_to' => array('clob', $a_rcp_to),
1005  'rcp_cc' => array('clob', $a_rcp_cc),
1006  'rcp_bcc' => array('clob', $a_rcp_bcc),
1007  'm_status' => array('text', $a_status),
1008  'm_type' => array('text', serialize($a_m_type)),
1009  'm_email' => array('integer', $a_m_email),
1010  'm_subject' => array('text', $a_m_subject),
1011  'm_message' => array('clob', $a_m_message)
1012  ));
1013 
1014  return $next_id; //$ilDB->getLastInsertId();
1015 
1016  }
1017 
1018  function replacePlaceholders($a_message, $a_user_id)
1019  {
1020  global $lng;
1021 
1022  $user = self::getCachedUserInstance($a_user_id);
1023 
1024  // determine salutation
1025  switch ($user->getGender())
1026  {
1027  case 'f': $gender_salut = $lng->txt('salutation_f');
1028  break;
1029  case 'm': $gender_salut = $lng->txt('salutation_m');
1030  break;
1031  }
1032 
1033  $a_message = str_replace('[MAIL_SALUTATION]', $gender_salut, $a_message);
1034  $a_message = str_replace('[LOGIN]', $user->getLogin(), $a_message);
1035  $a_message = str_replace('[FIRST_NAME]', $user->getFirstname(), $a_message);
1036  $a_message = str_replace('[LAST_NAME]', $user->getLastname(), $a_message);
1037  $a_message = str_replace('[ILIAS_URL]', ILIAS_HTTP_PATH.'/login.php?client_id='.CLIENT_ID, $a_message);
1038  $a_message = str_replace('[CLIENT_NAME]', CLIENT_NAME, $a_message);
1039 
1040  return $a_message;
1041  }
1042 
1056  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)
1057  {
1058  global $log;
1059 
1060  include_once 'Services/Mail/classes/class.ilMailbox.php';
1061  include_once './Services/User/classes/class.ilObjUser.php';
1062 
1063  if (!ilMail::_usePearMail())
1064  {
1065  // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
1066  $a_rcp_to = $this->__substituteRecipients($a_rcp_to, 'resubstitute');
1067  $a_rcp_cc = $this->__substituteRecipients($a_rcp_cc, 'resubstitute');
1068  $a_rcp_bcc = $this->__substituteRecipients($a_rcp_bcc, 'resubstitute');
1069  }
1070 
1071  $mbox = new ilMailbox();
1072 
1073  if (!$a_use_placeholders) # No Placeholders
1074  {
1075  $rcp_ids = $this->getUserIds(trim($a_rcp_to).','.trim($a_rcp_cc).','.trim($a_rcp_bcc));
1076 
1077  $as_email = array();
1078 
1079  foreach($rcp_ids as $id)
1080  {
1081  $tmp_mail_options = new ilMailOptions($id);
1082 
1083  // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1084  $tmp_user = self::getCachedUserInstance($id);
1085  $user_is_active = $tmp_user->getActive();
1086  $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1087 
1088  // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1089  if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1090  {
1091  continue;
1092  }
1093 
1094  // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS/HER MAIL
1095  // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1096 
1097  // Do not send external mails to inactive users!!!
1098  if($user_is_active)
1099  {
1100  if (!$user_can_read_internal_mails ||
1101  $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1102  {
1103  $as_email[] = $tmp_user->getEmail();
1104  continue;
1105  }
1106 
1107  if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1108  {
1109  $as_email[] = $tmp_user->getEmail();
1110  }
1111  }
1112  $mbox->setUserId($id);
1113  $inbox_id = $mbox->getInboxFolder();
1114 
1115  $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1116  $a_attachments, $a_rcp_to,
1117  $a_rcp_cc, '', 'unread', $a_type,
1118  0, $a_subject, $a_message, $id, 0);
1119  if ($a_attachments)
1120  {
1121  $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1122  }
1123  }
1124 
1125  // SEND EMAIL TO ALL USERS WHO DECIDED 'email' or 'both'
1126  $to = array();
1127  $bcc = array();
1128 
1129  if(count($as_email) == 1)
1130  {
1131  $to[] = $as_email[0];
1132  }
1133  else
1134  {
1135  foreach ($as_email as $email)
1136  {
1137  $bcc[] = $email;
1138  }
1139  }
1140 
1141  if(count($to) > 0 || count($bcc) > 0)
1142  {
1143  $this->sendMimeMail(implode(',', $to), '', implode(',', $bcc), $a_subject, $a_message, $a_attachments);
1144  }
1145  }
1146  else # Use Placeholders
1147  {
1148  // to
1149  $rcp_ids_replace = $this->getUserIds(trim($a_rcp_to));
1150 
1151  // cc / bcc
1152  $rcp_ids_no_replace = $this->getUserIds(trim($a_rcp_cc).','.trim($a_rcp_bcc));
1153 
1154  $as_email = array();
1155 
1156  // to
1157  foreach($rcp_ids_replace as $id)
1158  {
1159  $tmp_mail_options = new ilMailOptions($id);
1160 
1161  // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1162  $tmp_user = self::getCachedUserInstance($id);
1163  $user_is_active = $tmp_user->getActive();
1164  $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1165 
1166  // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1167  if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1168  {
1169  continue;
1170  }
1171 
1172  // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1173  // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1174 
1175  // Do not send external mails to inactive users!!!
1176  if($user_is_active)
1177  {
1178  if (!$user_can_read_internal_mails ||
1179  $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1180  {
1181  $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1182  continue;
1183  }
1184 
1185  if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1186  {
1187  $as_email[$tmp_user->getId()] = $tmp_user->getEmail();
1188  }
1189  }
1190  $mbox->setUserId($id);
1191  $inbox_id = $mbox->getInboxFolder();
1192 
1193  $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1194  $a_attachments, $a_rcp_to,
1195  $a_rcp_cc, '', 'unread', $a_type,
1196  0, $a_subject, $a_message, $id, 1);
1197  if ($a_attachments)
1198  {
1199  $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1200  }
1201  }
1202 
1203  if (count($as_email))
1204  {
1205  foreach ($as_email as $id => $email)
1206  {
1207  $this->sendMimeMail($email, '', '', $a_subject, $this->replacePlaceholders($a_message, $id), $a_attachments);
1208  }
1209  }
1210 
1211  $as_email = array();
1212 
1213  // cc / bcc
1214  foreach($rcp_ids_no_replace as $id)
1215  {
1216  $tmp_mail_options = new ilMailOptions($id);
1217 
1218  // DETERMINE IF THE USER CAN READ INTERNAL MAILS
1219  $tmp_user = self::getCachedUserInstance($id);
1220  $user_is_active = $tmp_user->getActive();
1221  $user_can_read_internal_mails = !$tmp_user->hasToAcceptTermsOfService() && $tmp_user->checkTimeLimit();
1222 
1223  // Do not send external mails to inactive users!!!
1224  if($user_is_active)
1225  {
1226  // CONTINUE IF SYSTEM MESSAGE AND USER CAN'T READ INTERNAL MAILS
1227  if (in_array('system', $a_type) && !$user_can_read_internal_mails)
1228  {
1229  continue;
1230  }
1231 
1232  // CONTINUE IF USER CAN'T READ INTERNAL MAILS OR IF HE/SHE WANTS HIS MAIL
1233  // SENT TO HIS/HER EXTERNAL E-MAIL ADDRESS ONLY
1234  if (!$user_can_read_internal_mails ||
1235  $tmp_mail_options->getIncomingType() == $this->mail_options->EMAIL)
1236  {
1237  $as_email[] = $tmp_user->getEmail();
1238  continue;
1239  }
1240 
1241  if ($tmp_mail_options->getIncomingType() == $this->mail_options->BOTH)
1242  {
1243  $as_email[] = $tmp_user->getEmail();
1244  }
1245  }
1246  $mbox->setUserId($id);
1247  $inbox_id = $mbox->getInboxFolder();
1248 
1249  $mail_id = $this->sendInternalMail($inbox_id, $this->user_id,
1250  $a_attachments, $a_rcp_to,
1251  $a_rcp_cc, '', 'unread', $a_type,
1252  0, $a_subject, $a_message, $id, 0);
1253  if ($a_attachments)
1254  {
1255  $this->mfile->assignAttachmentsToDirectory($mail_id, $sent_mail_id, $a_attachments);
1256  }
1257  }
1258 
1259  if (count($as_email))
1260  {
1261  $this->sendMimeMail('', '', implode(',', $as_email), $a_subject, $a_message, $a_attachments);
1262  }
1263  }
1264 
1265  return true;
1266  }
1267 
1273  function getUserIds($a_recipients)
1274  {
1275  global $log, $rbacreview;
1276  $ids = array();
1277 
1278  $this->validatePear($a_recipients);
1279  if (ilMail::_usePearMail() && $this->getUsePear() == true)
1280  {
1281  $tmp_names = $this->explodeRecipients($a_recipients );
1282  if (! is_a($tmp_names, 'PEAR_Error'))
1283  {
1284  for ($i = 0;$i < count($tmp_names); $i++)
1285  {
1286  if ( substr($tmp_names[$i]->mailbox,0,1) === '#' ||
1287  (substr($tmp_names[$i]->mailbox,0,1) === '"' &&
1288  substr($tmp_names[$i]->mailbox,1,1) === '#' ) )
1289  {
1290  $role_ids = $rbacreview->searchRolesByMailboxAddressList($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1291  foreach($role_ids as $role_id)
1292  {
1293  foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1294  {
1295  $ids[] = $usr_id;
1296  }
1297  }
1298  }
1299  else if (strtolower($tmp_names[$i]->host) == 'ilias')
1300  {
1301  if ($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i]->mailbox)))
1302  {
1303  //$log->write('class.ilMail->getUserIds() recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host.' user_id:'.$id);
1304  $ids[] = $id;
1305  }
1306  else
1307  {
1308  //$log->write('class.ilMail->getUserIds() no user account found for recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1309  }
1310  }
1311  else
1312  {
1313  // Fixed mantis bug #5875
1314  if($id = ilObjUser::_lookupId($tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host))
1315  {
1316  $ids[] = $id;
1317  }
1318  else
1319  {
1320  //$log->write('class.ilMail->getUserIds() external recipient:'.$tmp_names[$i]->mailbox.'@'.$tmp_names[$i]->host);
1321  }
1322  }
1323  }
1324  }
1325  else
1326  {
1327  //$log->write('class.ilMail->getUserIds() illegal recipients:'.$a_recipients);
1328  }
1329  }
1330  else
1331  {
1332  $tmp_names = $this->explodeRecipients($a_recipients, $this->getUsePear());
1333  for ($i = 0;$i < count($tmp_names); $i++)
1334  {
1335  if (substr($tmp_names[$i],0,1) == '#')
1336  {
1337  if(ilUtil::groupNameExists(addslashes(substr($tmp_names[$i],1))))
1338  {
1339  include_once("./Services/Object/classes/class.ilObjectFactory.php");
1340  include_once('./Modules/Group/classes/class.ilObjGroup.php');
1341 
1342  foreach(ilObject::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($tmp_names[$i],1)))) as $ref_id)
1343  {
1344  $grp_object = ilObjectFactory::getInstanceByRefId($ref_id);
1345  break;
1346  }
1347  // STORE MEMBER IDS IN $ids
1348  foreach ($grp_object->getGroupMemberIds() as $id)
1349  {
1350  $ids[] = $id;
1351  }
1352  }
1353  // is role: get role ids
1354  elseif($role_id = $rbacreview->roleExists(addslashes(substr($tmp_names[$i],1))))
1355  {
1356  foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1357  {
1358  $ids[] = $usr_id;
1359  }
1360  }
1361 
1362  }
1363  else if (!empty($tmp_names[$i]))
1364  {
1365  if ($id = ilObjUser::getUserIdByLogin(addslashes($tmp_names[$i])))
1366  {
1367  $ids[] = $id;
1368  }
1369  }
1370  }
1371  }
1372  return array_unique($ids);
1373  }
1374 
1385  function checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_type)
1386  {
1387  $error_message = '';
1388 
1389  $a_m_subject = trim($a_m_subject);
1390  $a_rcp_to = trim($a_rcp_to);
1391 
1392  if (empty($a_m_subject))
1393  {
1394  $error_message .= $error_message ? "<br>" : '';
1395  $error_message .= $this->lng->txt("mail_add_subject");
1396  }
1397 
1398  if (empty($a_rcp_to))
1399  {
1400  $error_message .= $error_message ? "<br>" : '';
1401  $error_message .= $this->lng->txt("mail_add_recipient");
1402  }
1403 
1404  return $error_message;
1405  }
1406 
1413  function getEmailsOfRecipients($a_rcp)
1414  {
1415  global $rbacreview;
1416 
1417  $addresses = array();
1418 
1419  $this->validatePear($a_rcp);
1420  if (ilMail::_usePearMail() && $this->getUsePear())
1421  {
1422  $tmp_rcp = $this->explodeRecipients($a_rcp);
1423  if (! is_a($tmp_rcp, 'PEAR_Error'))
1424  {
1425  foreach ($tmp_rcp as $rcp)
1426  {
1427  // NO GROUP
1428  if (substr($rcp->mailbox,0,1) != '#')
1429  {
1430  if (strtolower($rcp->host) != 'ilias')
1431  {
1432  $addresses[] = $rcp->mailbox.'@'.$rcp->host;
1433  continue;
1434  }
1435 
1436  if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)))
1437  {
1438  $tmp_user = self::getCachedUserInstance($id);
1439  $addresses[] = $tmp_user->getEmail();
1440  continue;
1441  }
1442  }
1443  else
1444  {
1445  // Roles
1446  $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1447  foreach($role_ids as $role_id)
1448  {
1449  foreach($rbacreview->assignedUsers($role_id) as $usr_id)
1450  {
1451  $tmp_user = self::getCachedUserInstance($usr_id);
1452  $addresses[] = $tmp_user->getEmail();
1453  }
1454  }
1455  }
1456  }
1457  }
1458  }
1459  else
1460  {
1461  $tmp_rcp = $this->explodeRecipients($a_rcp, $this->getUsePear());
1462 
1463  foreach ($tmp_rcp as $rcp)
1464  {
1465  // NO GROUP
1466  if (substr($rcp,0,1) != '#')
1467  {
1468  if (strpos($rcp,'@'))
1469  {
1470  $addresses[] = $rcp;
1471  continue;
1472  }
1473 
1474  if ($id = ilObjUser::getUserIdByLogin(addslashes($rcp)))
1475  {
1476  $tmp_user = self::getCachedUserInstance($id);
1477  $addresses[] = $tmp_user->getEmail();
1478  continue;
1479  }
1480  }
1481  else
1482  {
1483  // GROUP THINGS
1484  include_once("./Services/Object/classes/class.ilObjectFactory.php");
1485  include_once('./Modules/Group/classes/class.ilObjGroup.php');
1486 
1487  // Fix
1488  foreach(ilObjGroup::_getAllReferences(ilObjGroup::_lookupIdByTitle(addslashes(substr($rcp,1)))) as $ref_id)
1489  {
1490  $grp_object = ilObjectFactory::getInstanceByRefId($ref_id);
1491  break;
1492  }
1493  // GET EMAIL OF MEMBERS AND STORE THEM IN $addresses
1494  foreach ($grp_object->getGroupMemberIds() as $id)
1495  {
1496  $tmp_user = self::getCachedUserInstance($id);
1497  $addresses[] = $tmp_user->getEmail();
1498  }
1499  }
1500  }
1501  }
1502 
1503  return $addresses;
1504  }
1505 
1513  function checkRecipients($a_recipients,$a_type)
1514  {
1515  global $rbacsystem,$rbacreview;
1516  $wrong_rcps = '';
1517 
1518  $this->validatePear($a_recipients);
1519  if (ilMail::_usePearMail() && $this->getUsePear())
1520  {
1521  $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1522 
1523  if (is_a($tmp_rcp, 'PEAR_Error'))
1524  {
1525  $colon_pos = strpos($tmp_rcp->message, ':');
1526  $wrong_rcps = '<br />'.(($colon_pos === false) ? $tmp_rcp->message : substr($tmp_rcp->message, $colon_pos+2));
1527  }
1528  else
1529  {
1530  foreach ($tmp_rcp as $rcp)
1531  {
1532  // NO ROLE MAIL ADDRESS
1533  if (substr($rcp->mailbox,0,1) != '#')
1534  {
1535  // ALL RECIPIENTS MUST EITHER HAVE A VALID LOGIN OR A VALID EMAIL
1536  $user_id = ($rcp->host == 'ilias') ? ilObjUser::getUserIdByLogin(addslashes($rcp->mailbox)) : false;
1537  if ($user_id == false && $rcp->host == 'ilias')
1538  {
1539  $wrong_rcps .= "<br />".htmlentities($rcp->mailbox);
1540  continue;
1541  }
1542 
1543  // CHECK IF USER CAN RECEIVE MAIL
1544  if ($user_id)
1545  {
1546  if(!$rbacsystem->checkAccessOfUser($user_id, "internal_mail", $this->getMailObjectReferenceId()))
1547  {
1548  $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1549  " (".$this->lng->txt("user_cant_receive_mail").")";
1550  continue;
1551  }
1552  }
1553  }
1554  else if (substr($rcp->mailbox, 0, 7) == '#il_ml_')
1555  {
1556  if (!$this->mlists->mailingListExists($rcp->mailbox))
1557  {
1558  $wrong_rcps .= "<br />".htmlentities($rcp->mailbox).
1559  " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1560  }
1561 
1562  continue;
1563  }
1564  else
1565  {
1566 
1567  $role_ids = $rbacreview->searchRolesByMailboxAddressList($rcp->mailbox.'@'.$rcp->host);
1568 
1569  if(!$this->mail_to_global_roles && is_array($role_ids))
1570  {
1571  foreach($role_ids as $role_id)
1572  {
1573  if($rbacreview->isGlobalRole($role_id))
1574  {
1575  include_once('Services/Mail/exceptions/class.ilMailException.php');
1576  throw new ilMailException('mail_to_global_roles_not_allowed');
1577 
1578  }
1579  }
1580  }
1581  if (count($role_ids) == 0)
1582  {
1583  $wrong_rcps .= '<br />'.htmlentities($rcp->mailbox).
1584  ' ('.$this->lng->txt('mail_no_recipient_found').')';
1585  continue;
1586  }
1587  else if (count($role_ids) > 1)
1588  {
1589  $wrong_rcps .= '<br/>'.htmlentities($rcp->mailbox).
1590  ' ('.sprintf($this->lng->txt('mail_multiple_recipients_found'), implode(',', $role_ids)).')';
1591  }
1592  }
1593  }
1594  }
1595  }
1596  else // NO PEAR
1597  {
1598  $tmp_rcp = $this->explodeRecipients($a_recipients, $this->getUsePear());
1599 
1600  foreach ($tmp_rcp as $rcp)
1601  {
1602  if (empty($rcp))
1603  {
1604  continue;
1605  }
1606  // NO GROUP
1607  if (substr($rcp,0,1) != '#')
1608  {
1609  // ALL RECIPIENTS MUST EITHER HAVE A VALID LOGIN OR A VALID EMAIL
1610  if (!ilObjUser::getUserIdByLogin(addslashes($rcp)) and
1611  !ilUtil::is_email($rcp))
1612  {
1613  $wrong_rcps .= "<br />".htmlentities($rcp);
1614  continue;
1615  }
1616 
1617  // CHECK IF USER CAN RECEIVE MAIL
1618  if ($user_id = ilObjUser::getUserIdByLogin(addslashes($rcp)))
1619  {
1620  if(!$rbacsystem->checkAccessOfUser($user_id, "internal_mail", $this->getMailObjectReferenceId()))
1621  {
1622  $wrong_rcps .= "<br />".htmlentities($rcp).
1623  " (".$this->lng->txt("user_cant_receive_mail").")";
1624  continue;
1625  }
1626  }
1627  }
1628  else if (substr($rcp, 0, 7) == '#il_ml_')
1629  {
1630  if (!$this->mlists->mailingListExists($rcp))
1631  {
1632  $wrong_rcps .= "<br />".htmlentities($rcp).
1633  " (".$this->lng->txt("mail_no_valid_mailing_list").")";
1634  }
1635 
1636  continue;
1637  }
1638  else if (ilUtil::groupNameExists(addslashes(substr($rcp,1))))
1639  {
1640  continue;
1641  }
1642  else if (!$rbacreview->roleExists(addslashes(substr($rcp,1))))
1643  {
1644  $wrong_rcps .= "<br />".htmlentities($rcp).
1645  " (".$this->lng->txt("mail_no_valid_group_role").")";
1646  continue;
1647  }
1648  else if (!$this->mail_to_global_roles)
1649  {
1650  $role_id = $rbacreview->roleExists(addslashes(substr($rcp,1)));
1651  if((int)$role_id && $rbacreview->isGlobalRole($role_id))
1652  {
1653  include_once('Services/Mail/exceptions/class.ilMailException.php');
1654  throw new ilMailException('mail_to_global_roles_not_allowed');
1655  }
1656  }
1657  }
1658  }
1659  return $wrong_rcps;
1660  }
1661 
1677  function savePostData($a_user_id,
1678  $a_attachments,
1679  $a_rcp_to,
1680  $a_rcp_cc,
1681  $a_rcp_bcc,
1682  $a_m_type,
1683  $a_m_email,
1684  $a_m_subject,
1685  $a_m_message,
1686  $a_use_placeholders)
1687  {
1688  global $ilDB;
1689 
1690 
1691  if(!$a_attachments) $a_attachments = NULL;
1692  if(!$a_rcp_to) $a_rcp_to = NULL;
1693  if(!$a_rcp_cc) $a_rcp_cc = NULL;
1694  if(!$a_rcp_bcc) $a_rcp_bcc = NULL;
1695  if(!$a_m_type) $a_m_type = NULL;
1696  if(!$a_m_email) $a_m_email = NULL;
1697  if(!$a_m_message) $a_m_message = NULL;
1698  if(!$a_use_placeholders) $a_use_placeholders = '0';
1699 
1700 
1701  $statement = $ilDB->manipulateF('
1702  DELETE FROM '. $this->table_mail_saved .'
1703  WHERE user_id = %s',
1704  array('integer'), array($this->user_id));
1705 
1706  $ilDB->insert($this->table_mail_saved, array(
1707  'user_id' => array('integer', $a_user_id),
1708  'attachments' => array('clob', serialize($a_attachments)),
1709  'rcp_to' => array('clob', $a_rcp_to),
1710  'rcp_cc' => array('clob', $a_rcp_cc),
1711  'rcp_bcc' => array('clob', $a_rcp_bcc),
1712  'm_type' => array('text', serialize($a_m_type)),
1713  'm_email' => array('integer', $a_m_email),
1714  'm_subject' => array('text', $a_m_subject),
1715  'm_message' => array('clob', $a_m_message),
1716  'use_placeholders' => array('integer', $a_use_placeholders),
1717  ));
1718 
1719  $this->getSavedData();
1720 
1721  return true;
1722  }
1723 
1729  function getSavedData()
1730  {
1731  global $ilDB;
1732 
1733  $res = $ilDB->queryf('
1734  SELECT * FROM '. $this->table_mail_saved .'
1735  WHERE user_id = %s',
1736  array('integer'),
1737  array($this->user_id));
1738 
1739  $this->mail_data = $this->fetchMailData($res->fetchRow(DB_FETCHMODE_OBJECT));
1740 
1741  return $this->mail_data;
1742  }
1743 
1757  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)
1758  {
1759  global $lng,$rbacsystem,$log;
1760  //$log->write('class.ilMail.sendMail '.$a_rcp_to.' '.$a_m_subject);
1761 
1762  $this->mail_to_global_roles = true;
1763  if($this->user_id != ANONYMOUS_USER_ID)
1764  {
1765  $this->mail_to_global_roles = $rbacsystem->checkAccessOfUser($this->user_id, 'mail_to_global_roles', $this->mail_obj_ref_id);
1766  }
1767 
1768  $error_message = '';
1769  $message = '';
1770 
1771  if (in_array("system",$a_type))
1772  {
1773  $this->__checkSystemRecipients($a_rcp_to);
1774  $a_type = array('system');
1775  }
1776 
1777  if ($a_attachment)
1778  {
1779  if (!$this->mfile->checkFilesExist($a_attachment))
1780  {
1781  return "YOUR LIST OF ATTACHMENTS IS NOT VALID, PLEASE EDIT THE LIST";
1782  }
1783  }
1784  // CHECK NECESSARY MAIL DATA FOR ALL TYPES
1785  if ($error_message = $this->checkMail($a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_m_subject,$a_m_message,$a_type))
1786  {
1787  return $error_message;
1788  }
1789 
1790  try
1791  {
1792  // check recipients
1793  if ($error_message = $this->checkRecipients($a_rcp_to,$a_type))
1794  {
1795  $message .= $error_message;
1796  }
1797 
1798  if ($error_message = $this->checkRecipients($a_rcp_cc,$a_type))
1799  {
1800  $message .= $error_message;
1801  }
1802 
1803  if ($error_message = $this->checkRecipients($a_rcp_bc,$a_type))
1804  {
1805  $message .= $error_message;
1806  }
1807  }
1808 
1809  catch(ilMailException $e)
1810  {
1811  return $this->lng->txt($e->getMessage());
1812  }
1813 
1814  // if there was an error
1815  if (!empty($message))
1816  {
1817  return $this->lng->txt("mail_following_rcp_not_valid").$message;
1818  }
1819 
1820  // ACTIONS FOR ALL TYPES
1821 
1822 
1823  // GET RCPT OF MAILING LISTS
1824 
1825  $rcp_to_list = $this->parseRcptOfMailingLists($a_rcp_to, true);
1826  $rcp_cc_list = $this->parseRcptOfMailingLists($a_rcp_cc, true);
1827  $rcp_bc_list = $this->parseRcptOfMailingLists($a_rcp_bc, true);
1828 
1829  $rcp_to = $rcp_cc = $rcp_bc = array();
1830  foreach($rcp_to_list as $mlist_id => $mlist_rec)
1831  {
1832  if($mlist_id)
1833  {
1834  // internal mailing lists are sent as bcc
1835  $mlist_id = substr($mlist_id, 7);
1836  if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
1837  {
1838  $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1839  continue;
1840  }
1841  }
1842 
1843  $rcp_to = array_merge($rcp_to, $mlist_rec);
1844  }
1845  foreach($rcp_cc_list as $mlist_id => $mlist_rec)
1846  {
1847  if($mlist_id)
1848  {
1849  // internal mailing lists are sent as bcc
1850  $mlist_id = substr($mlist_id, 7);
1851  if($this->mlists->get($mlist_id)->getMode() == ilMailingList::MODE_TEMPORARY)
1852  {
1853  $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1854  continue;
1855  }
1856  }
1857 
1858  $rcp_cc = array_merge($rcp_cc, $mlist_rec);
1859  }
1860  foreach($rcp_bc_list as $mlist_id => $mlist_rec)
1861  {
1862  $rcp_bc = array_merge($rcp_bc, $mlist_rec);
1863  }
1864 
1865  $rcp_to = implode(',', $rcp_to);
1866  $rcp_cc = implode(',', $rcp_cc);
1867  $rcp_bc = implode(',', $rcp_bc);
1868 
1869 
1870  if (! ilMail::_usePearMail() )
1871  {
1872  // REPLACE ALL LOGIN NAMES WITH '@' BY ANOTHER CHARACTER
1873  $rcp_to = $this->__substituteRecipients($rcp_to,"substitute");
1874  $rcp_cc = $this->__substituteRecipients($rcp_cc,"substitute");
1875  $rcp_bc = $this->__substituteRecipients($rcp_bc,"substitute");
1876  }
1877 
1878  // COUNT EMAILS
1879  $c_emails = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,true);
1880  $c_rcp = $this->__getCountRecipients($rcp_to,$rcp_cc,$rcp_bc,false);
1881 
1882  // currently disabled..
1883  /*
1884  if (count($c_emails))
1885  {
1886  if (!$this->getEmailOfSender())
1887  {
1888  return $lng->txt("mail_check_your_email_addr");
1889  }
1890  }
1891  */
1892 
1893  // check smtp permission
1894  if($c_emails && $this->user_id != ANONYMOUS_USER_ID &&
1895  !$rbacsystem->checkAccessOfUser($this->user_id, 'smtp_mail', $this->mail_obj_ref_id))
1896  {
1897  return $this->lng->txt('mail_no_permissions_write_smtp');
1898  }
1899 
1900  if($this->appendInstallationSignature())
1901  {
1902  $a_m_message .= self::_getInstallationSignature();
1903  }
1904 
1905  // save mail in sent box
1906  $sent_id = $this->saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bc,$a_type,
1907  $a_m_subject,$a_m_message);
1908 
1909  if($a_attachment)
1910  {
1911  $this->mfile->assignAttachmentsToDirectory($sent_id,$sent_id);
1912 
1913  if ($error = $this->mfile->saveFiles($sent_id,$a_attachment))
1914  {
1915  return $error;
1916  }
1917  }
1918 
1919  // FILTER EMAILS
1920  // IF EMAIL RECIPIENT
1921  if($c_emails)
1922  {
1923  $this->sendMimeMail($this->__getEmailRecipients($rcp_to),
1924  $this->__getEmailRecipients($rcp_cc),
1925  $this->__getEmailRecipients($rcp_bc),
1926  $a_m_subject,
1927  $a_m_message,
1928  $a_attachment,
1929  0);
1930  }
1931 
1932  if (in_array('system',$a_type))
1933  {
1934  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))
1935  {
1936  return $lng->txt("mail_send_error");
1937  }
1938  }
1939  // ACTIONS FOR TYPE SYSTEM AND NORMAL
1940  if (in_array('normal',$a_type))
1941  {
1942  // TRY BOTH internal and email (depends on user settings)
1943  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))
1944  {
1945  return $lng->txt("mail_send_error");
1946  }
1947  }
1948 
1949  // Temporary bugfix
1950  if (!$this->getSaveInSentbox())
1951  {
1952  $this->deleteMails(array($sent_id));
1953  }
1954 
1955  return '';
1956  }
1957 
1958  function parseRcptOfMailingLists($rcpt = '', $maintain_lists = false)
1959  {
1960  if ($rcpt == '')
1961  {
1962  if(!$maintain_lists)
1963  {
1964  return $rcpt;
1965  }
1966  else
1967  {
1968  return array();
1969  }
1970  }
1971 //@todo check rcp pear validation
1972  $arrRcpt = $this->explodeRecipients(trim($rcpt));
1973  if (!is_array($arrRcpt) || empty($arrRcpt))
1974  {
1975  if(!$maintain_lists)
1976  {
1977  return $rcpt;
1978  }
1979  else
1980  {
1981  return array();
1982  }
1983  }
1984 
1985  $new_rcpt = array();
1986 
1987  foreach ($arrRcpt as $item)
1988  {
1989  if (ilMail::_usePearMail())
1990  {
1991  if (substr($item->mailbox, 0, 7) == '#il_ml_')
1992  {
1993  if ($this->mlists->mailingListExists($item->mailbox))
1994  {
1995  foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
1996  {
1997  if(!$maintain_lists)
1998  {
1999  $new_rcpt[] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2000  }
2001  else
2002  {
2003  $new_rcpt[$item->mailbox][] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2004  }
2005  }
2006  }
2007  }
2008  else
2009  {
2010  if(!$maintain_lists)
2011  {
2012  $new_rcpt[] = $item->mailbox.'@'.$item->host;
2013  }
2014  else
2015  {
2016  $new_rcpt[0][] = $item->mailbox.'@'.$item->host;
2017  }
2018  }
2019  }
2020  else
2021  {
2022  if (substr($item, 0, 7) == '#il_ml_')
2023  {
2024  if ($this->mlists->mailingListExists($item))
2025  {
2026  foreach ($this->mlists->getCurrentMailingList()->getAssignedEntries() as $entry)
2027  {
2028  if(!$maintain_lists)
2029  {
2030  $new_rcpt[] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2031  }
2032  else
2033  {
2034  $new_rcpt[$item][] = ($entry['login'] != '' ? $entry['login'] : $entry['email']);
2035  }
2036  }
2037  }
2038  }
2039  else
2040  {
2041  if(!$maintain_lists)
2042  {
2043  $new_rcpt[] = $item;
2044  }
2045  else
2046  {
2047  $new_rcpt[0][] = $item;
2048  }
2049  }
2050  }
2051  }
2052 
2053  if(!$maintain_lists)
2054  {
2055  return implode(',', $new_rcpt);
2056  }
2057  else
2058  {
2059  return $new_rcpt;
2060  }
2061  }
2062 
2075  function saveInSentbox($a_attachment,$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_type,
2076  $a_m_subject,$a_m_message)
2077  {
2078  include_once "Services/Mail/classes/class.ilMailbox.php";
2079 
2080  $mbox = new ilMailbox($this->user_id);
2081  $sent_id = $mbox->getSentFolder();
2082 
2084  return $this->sendInternalMail($sent_id,$this->user_id,$a_attachment,$a_rcp_to,$a_rcp_cc,
2085  $a_rcp_bcc,'read',$a_type,$a_as_email,$a_m_subject,$a_m_message,$this->user_id, 0);
2086  }
2087 
2094  public static function addFullname($a_email, $a_fullname)
2095  {
2096  include_once 'Services/Mail/classes/class.ilMimeMail.php';
2097  return ilMimeMail::_mimeEncode($a_fullname).' <'.$a_email.'>';
2098  }
2099 
2106  public function getMimeMailSender()
2107  {
2111  global $ilUser;
2112 
2113  include_once "Services/Mail/classes/class.ilMimeMail.php";
2114 
2115  if($this->user_id && $this->user_id != ANONYMOUS_USER_ID)
2116  {
2117  $email = $ilUser->getEmail();
2118  $fullname = $ilUser->getFullname();
2119  if($ilUser->getId() != $this->user_id)
2120  {
2121  $user = self::getCachedUserInstance($this->user_id);
2122  $email = $user->getEmail();
2123  $fullname = $user->getFullname();
2124  }
2125 
2126  $sender = self::addFullname($email, $fullname);
2127  }
2128  else
2129  {
2130  $sender = self::getIliasMailerAddress();
2131  }
2132 
2133  return $sender;
2134  }
2135 
2145  public static function getIliasMailerAddress()
2146  {
2147  global $ilSetting;
2148 
2149  include_once 'Services/Mail/classes/class.ilMimeMail.php';
2150 
2151  $no_reply_adress = trim($ilSetting->get('mail_external_sender_noreply'));
2152  if(strlen($no_reply_adress))
2153  {
2154  if(strpos($no_reply_adress, '@') === false)
2155  $no_reply_adress = 'noreply@'.$no_reply_adress;
2156 
2157  if(!ilUtil::is_email($no_reply_adress))
2158  {
2159  $no_reply_adress = 'noreply@'.$_SERVER['SERVER_NAME'];
2160  }
2161 
2162  $sender = ilMimeMail::_mimeEncode(self::_getIliasMailerName()).
2163  ' <'.$no_reply_adress.'>';
2164  }
2165  else
2166  {
2167  $sender = ilMimeMail::_mimeEncode(self::_getIliasMailerName()).
2168  ' <noreply@'.$_SERVER['SERVER_NAME'].'>';
2169  }
2170 
2171  return $sender;
2172  }
2173 
2187  function sendMimeMail($a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,$a_no_soap = false)
2188  {
2189  include_once "Services/Mail/classes/class.ilMimeMail.php";
2190 
2191  #var_dump("<pre>",$a_rcp_to,$a_rcp_cc,$a_rcp_bcc,$a_m_subject,$a_m_message,$a_attachments,"<pre>");
2192 
2193  #$inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 4";
2194  #$a_m_subject = "[".$inst_name."] ".$a_m_subject;
2195 
2196  $a_m_subject = self::getSubjectPrefix().' '.$a_m_subject;
2197 
2198  $sender = $this->getMimeMailSender();
2199 
2200  // #10854
2201  if($this->isSOAPEnabled() && !$a_no_soap)
2202  {
2203  // Send per soap
2204  include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
2205 
2206  $soap_client = new ilSoapClient();
2207  $soap_client->setResponseTimeout(1);
2208  $soap_client->enableWSDL(true);
2209  $soap_client->init();
2210 
2211  $attachments = array();
2212  $a_attachments = $a_attachments ? $a_attachments : array();
2213  foreach($a_attachments as $attachment)
2214  {
2215  $attachments[] = $this->mfile->getAbsolutePath($attachment);
2216  }
2217  // mjansen: switched separator from "," to "#:#" because of mantis bug #6039
2218  $attachments = implode('#:#',$attachments);
2219  // mjansen: use "#:#" as leading delimiter
2220  if(strlen($attachments))
2221  $attachments = "#:#".$attachments;
2222 
2223  $soap_client->call('sendMail',array(session_id().'::'.$_COOKIE['ilClientId'], // session id
2224  $a_rcp_to,
2225  $a_rcp_cc,
2226  $a_rcp_bcc,
2227  $sender,
2228  $a_m_subject,
2229  $a_m_message,
2230  $attachments));
2231 
2232  return true;
2233  }
2234  else
2235  {
2236  // send direct
2237  include_once "Services/Mail/classes/class.ilMimeMail.php";
2238 
2239  $mmail = new ilMimeMail();
2240  $mmail->autoCheck(false);
2241  $mmail->From($sender);
2242  $mmail->To($a_rcp_to);
2243  // Add installation name to subject
2244  $mmail->Subject($a_m_subject);
2245  $mmail->Body($a_m_message);
2246 
2247  if ($a_rcp_cc)
2248  {
2249  $mmail->Cc($a_rcp_cc);
2250  }
2251 
2252  if ($a_rcp_bcc)
2253  {
2254  $mmail->Bcc($a_rcp_bcc);
2255  }
2256 
2257  if (is_array($a_attachments))
2258  {
2259  foreach ($a_attachments as $attachment)
2260  {
2261  $mmail->Attach($this->mfile->getAbsolutePath($attachment), '', 'inline', $attachment);
2262  }
2263  }
2264 
2265  $mmail->Send();
2266  }
2267  }
2273  function getEmailOfSender()
2274  {
2275  $umail = self::getCachedUserInstance($this->user_id);
2276  $sender = $umail->getEmail();
2277 
2278  if (ilUtil::is_email($sender))
2279  {
2280  return $sender;
2281  }
2282  else
2283  {
2284  return '';
2285  }
2286  }
2287 
2294  function saveAttachments($a_attachments)
2295  {
2296  global $ilDB;
2297 
2298  $ilDB->update($this->table_mail_saved,
2299  array
2300  (
2301  'attachments' => array('clob', serialize($a_attachments))
2302  ),
2303  array
2304  (
2305  'user_id' => array('integer', $this->user_id)
2306  )
2307  );
2308 
2309  return true;
2310  }
2311 
2317  function getAttachments()
2318  {
2319  return $this->mail_data["attachments"] ? $this->mail_data["attachments"] : array();
2320  }
2321 
2335  function explodeRecipients($a_recipients, $use_pear = true)
2336  {
2337  $a_recipients = trim($a_recipients);
2338 
2339  // WHITESPACE IS NOT ALLOWED AS SEPERATOR
2340  #$a_recipients = preg_replace("/ /",",",$a_recipients);
2341  $a_recipients = preg_replace("/;/",",",$a_recipients);
2342 
2343  if (ilMail::_usePearMail() && $use_pear == true)
2344  {
2345  if (strlen(trim($a_recipients)) > 0)
2346  {
2347  require_once './Services/PEAR/lib/Mail/RFC822.php';
2348  $parser = new Mail_RFC822();
2349  return $parser->parseAddressList($a_recipients, "ilias", false, true);
2350  } else {
2351  return array();
2352  }
2353  }
2354  else
2355  {
2356  foreach(explode(',',$a_recipients) as $tmp_rec)
2357  {
2358  if($tmp_rec)
2359  {
2360  $rcps[] = trim($tmp_rec);
2361  }
2362  }
2363  return is_array($rcps) ? $rcps : array();
2364  }
2365  }
2366 
2367  function __getCountRecipient($rcp,$a_only_email = true)
2368  {
2369  $counter = 0;
2370 
2371  $this->validatePear($rcp);
2372  if (ilMail::_usePearMail() && $this->getUsePear())
2373  {
2374  $tmp_rcp = $this->explodeRecipients($rcp);
2375  if (! is_a($tmp_rcp, 'PEAR_Error'))
2376  {
2377  foreach ($tmp_rcp as $to)
2378  {
2379  if ($a_only_email)
2380  {
2381  // Fixed mantis bug #5875
2382  if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2383  {
2384  continue;
2385  }
2386 
2387  // Addresses which aren't on the ilias host, and
2388  // which have a mailbox which does not start with '#',
2389  // are external e-mail addresses
2390  if ($to->host != 'ilias' && substr($to->mailbox,0,1) != '#')
2391  {
2392  ++$counter;
2393  }
2394  }
2395  else
2396  {
2397  ++$counter;
2398  }
2399  }
2400  }
2401  }
2402  else
2403  {
2404  foreach ($this->explodeRecipients($rcp,$this->getUsePear()) as $to)
2405  {
2406  if ($a_only_email)
2407  {
2408  $to = $this->__substituteRecipients($to,"resubstitute");
2409  if (strpos($to,'@'))
2410  {
2411  // Fixed mantis bug #5875
2412  if(ilObjUser::_lookupId($to))
2413  {
2414  continue;
2415  }
2416 
2417  ++$counter;
2418  }
2419  }
2420  else
2421  {
2422  ++$counter;
2423  }
2424  }
2425  }
2426  return $counter;
2427  }
2428 
2429 
2430  function __getCountRecipients($a_to,$a_cc,$a_bcc,$a_only_email = true)
2431  {
2432  return $this->__getCountRecipient($a_to,$a_only_email)
2433  + $this->__getCountRecipient($a_cc,$a_only_email)
2434  + $this->__getCountRecipient($a_bcc,$a_only_email);
2435  }
2436 
2437  function __getEmailRecipients($a_rcp)
2438  {
2439  if (ilMail::_usePearMail())
2440  {
2441  $rcp = array();
2442  $tmp_rcp = $this->explodeRecipients($a_rcp);
2443  if (! is_a($tmp_rcp, 'PEAR_Error'))
2444  {
2445  foreach ($tmp_rcp as $to)
2446  {
2447  if(substr($to->mailbox,0,1) != '#' && $to->host != 'ilias')
2448  {
2449  // Fixed mantis bug #5875
2450  if(ilObjUser::_lookupId($to->mailbox.'@'.$to->host))
2451  {
2452  continue;
2453  }
2454 
2455  $rcp[] = $to->mailbox.'@'.$to->host;
2456  }
2457  }
2458  }
2459  return implode(',',$rcp);
2460  }
2461  else
2462  {
2463  foreach ($this->explodeRecipients($a_rcp) as $to)
2464  {
2465  $to = $this->__substituteRecipients($to,"resubstitute");
2466  if(strpos($to,'@'))
2467  {
2468  // Fixed mantis bug #5875
2469  if(ilObjUser::_lookupId($to))
2470  {
2471  continue;
2472  }
2473 
2474  $rcp[] = $to;
2475  }
2476  }
2477  return implode(',',$rcp ? $rcp : array());
2478  }
2479  }
2480 
2481  function __prependMessage($a_m_message,$rcp_to,$rcp_cc)
2482  {
2483  $inst_name = $this->ilias->getSetting("inst_name") ? $this->ilias->getSetting("inst_name") : "ILIAS 3";
2484 
2485  $message = $inst_name." To:".$rcp_to."\n";
2486 
2487  if ($rcp_cc)
2488  {
2489  $message .= "Cc: ".$rcp_cc;
2490  }
2491 
2492  $message .= "\n\n";
2493  $message .= $a_m_message;
2494 
2495  return $message;
2496  }
2497 
2498  function __checkSystemRecipients(&$a_rcp_to)
2499  {
2500  if (preg_match("/@all/",$a_rcp_to))
2501  {
2502  // GET ALL LOGINS
2503  $all = ilObjUser::_getAllUserLogins($this->ilias);
2504  $a_rcp_to = preg_replace("/@all/",implode(',',$all),$a_rcp_to);
2505  }
2506 
2507  return;
2508  }
2509 
2517  function __substituteRecipients($a_rcp,$direction)
2518  {
2519  $new_name = array();
2520 
2521  $tmp_names = $this->explodeRecipients($a_rcp);
2522 
2523 
2524  foreach($tmp_names as $name)
2525  {
2526  if(strpos($name,"#") === 0)
2527  {
2528  $new_name[] = $name;
2529  continue;
2530  }
2531  switch($direction)
2532  {
2533  case "substitute":
2534  if(strpos($name,"@") and ilObjUser::_loginExists($name))
2535  {
2536  $new_name[] = preg_replace("/@/","�#�",$name);
2537  }
2538  else
2539  {
2540  $new_name[] = $name;
2541  }
2542  break;
2543 
2544  case "resubstitute":
2545  if(stristr($name,"�#�"))
2546  {
2547  $new_name[] = preg_replace("/�#�/","@",$name);
2548  }
2549  else
2550  {
2551  $new_name[] = $name;
2552  }
2553  break;
2554  }
2555  }
2556  return implode(",",$new_name);
2557  }
2558 
2574  public static function _getUserInternalMailboxAddress($usr_id, $login=null, $firstname=null, $lastname=null)
2575  {
2576  if (ilMail::_usePearMail())
2577  {
2578  if ($login == null)
2579  {
2580  require_once './Services/User/classes/class.ilObjUser.php';
2582  $login = $usr_obj->getLogin();
2583  $firstname = $usr_obj->getFirstname();
2584  $lastname = $usr_obj->getLastname();
2585  }
2586  // The following line of code creates a properly formatted mailbox
2587  // address. Unfortunately, it does not work, because ILIAS removes
2588  // everything between '<' '>' characters
2589  // Therefore, we just return the login - sic.
2590  // FIXME - Make this work in a future release
2591  /*
2592  return preg_replace('/[()<>@,;:\\".\[\]]/','',$firstname.' '.$lastname).' <'.$login.'>';
2593  */
2594  return $login.'hhho';
2595  }
2596  else
2597  {
2598  return $login;
2599  }
2600  }
2607  public static function _usePearMail()
2608  {
2612  global $ilSetting;
2613 
2614  return $ilSetting->get('pear_mail_enable', 0);
2615  }
2616 
2625  public static function _getAutoGeneratedMessageString($lang = null)
2626  {
2627  global $ilSetting;
2628 
2629  if(!$lang)
2630  {
2631  include_once('./Services/Language/classes/class.ilLanguageFactory.php');
2633  }
2634  $http_path = ilUtil::_getHttpPath();
2635 
2636  $lang->loadLanguageModule('mail');
2637  return sprintf($lang->txt('mail_auto_generated_info'),
2638  $ilSetting->get('inst_name','ILIAS 4'),
2639  $http_path)."\n\n";
2640  }
2641 
2648  public static function _getIliasMailerName()
2649  {
2653  global $ilSetting;
2654 
2655  if(strlen($ilSetting->get('mail_system_sender_name')))
2656  {
2657  return $ilSetting->get('mail_system_sender_name');
2658  }
2659  else if(strlen($ilSetting->get('short_inst_name')))
2660  {
2661  return $ilSetting->get('short_inst_name');
2662  }
2663 
2664  return 'ILIAS';
2665  }
2666 
2675  public function appendInstallationSignature($a_flag = null)
2676  {
2677  if(null === $a_flag) {
2679  }
2680 
2681  $this->appendInstallationSignature = $a_flag;
2682 
2683  return $this;
2684  }
2685 
2694  public static function _getInstallationSignature()
2695  {
2696  global $ilClientIniFile;
2697 
2698  $signature = "\n\n* * * * *\n";
2699 
2700  $signature .= $ilClientIniFile->readVariable('client', 'name')."\n";
2701  if(strlen($desc = $ilClientIniFile->readVariable('client', 'description')))
2702  {
2703  $signature .= $desc."\n";
2704  }
2705 
2706  $signature .= ilUtil::_getHttpPath();
2707 
2708  $clientdirs = glob(ILIAS_WEB_DIR."/*", GLOB_ONLYDIR);
2709  if(is_array($clientdirs) && count($clientdirs) > 1)
2710  {
2711  $signature .= '/?client_id='.CLIENT_ID;
2712  }
2713 
2714  $signature .= "\n\n";
2715 
2716  return $signature;
2717  }
2718 
2723  public static function getSubjectPrefix()
2724  {
2725  global $ilSetting;
2726  static $prefix = null;
2727 
2728  return $prefix == null ? $ilSetting->get('mail_subject_prefix','') : $prefix;
2729  }
2730 
2736  public static function getSalutation($a_usr_id,$a_language = null)
2737  {
2738  global $lng;
2739 
2740  $lang = $a_language ? $a_language : $lng;
2741 
2742  $lang->loadLanguageModule('mail');
2743  $gender = ilObjUser::_lookupGender($a_usr_id);
2744  $gender = $gender ? $gender : 'n';
2745  $name = ilObjUser::_lookupName($a_usr_id);
2746 
2747  if(!strlen($name['firstname']))
2748  {
2749  return $lang->txt('mail_salutation_anonymous').',';
2750  }
2751 
2752  return $lang->txt('mail_salutation_'.$gender).' '.
2753  ($name['title'] ? $name['title'].' ' : '').
2754  ($name['firstname'] ? $name['firstname'].' ' : '').
2755  $name['lastname'].',';
2756  }
2757 
2758  private function setUsePear($bool)
2759  {
2760  $this->use_pear = $bool;
2761  }
2762 
2763  private function getUsePear()
2764  {
2765  return $this->use_pear;
2766  }
2767 
2768  // Force fallback for sending mails via ILIAS, if internal Pear-Validation returns PEAR_Error
2773  private function validatePear($a_recipients)
2774  {
2775  if(ilMail::_usePearMail())
2776  {
2777  $this->setUsePear(true);
2778  $tmp_names = $this->explodeRecipients($a_recipients, true);
2779  if(is_a($tmp_names, 'PEAR_Error'))
2780  {
2781  $this->setUsePear(false);
2782  }
2783  }
2784  else
2785  {
2786  $this->setUsePear(false);
2787  }
2788  }
2789 
2798  protected static function getCachedUserInstance($a_usr_id)
2799  {
2800  if(isset(self::$userInstances[$a_usr_id]))
2801  {
2802  return self::$userInstances[$a_usr_id];
2803  }
2804 
2805  self::$userInstances[$a_usr_id] = new ilObjUser($a_usr_id);
2806  return self::$userInstances[$a_usr_id];
2807  }
2808 } // END class.ilMail
2809 ?>