action.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. Action::register('sendmail_mail_preview',function(&$response){
  3. global $myUser;
  4. if(!$myUser->connected()) throw new Exception("Permission denied");
  5. require_once(__DIR__.SLASH.'page.sheet.mail.php');
  6. exit();
  7. });
  8. //Ajout ou modification d'élément mail
  9. Action::register('sendmail_mail_send',function(&$response){
  10. global $myUser,$conf,$_;
  11. if(!$myUser->connected()) throw new Exception("Permission denied");
  12. Plugin::callHook("sendmail_before_send",array(&$_));
  13. if(!isset($_['from']) || empty($_['from'])) throw new Exception("Veuillez préciser l'adresse de l'expediteur");
  14. if(!isset($_['recipient']) || empty($_['recipient'])) throw new Exception("Veuillez préciser au moins un destinataire");
  15. $_['recipient'] = array_merge_recursive($_['recipient'], array('to'=>array(),'cc'=>array(),'cci'=>array()));
  16. foreach($_['recipient'] as $type => $mails)
  17. foreach($mails as $i => $mail)
  18. if(empty($mail) || !filter_var($mail, FILTER_VALIDATE_EMAIL)) throw new Exception('Le mail "'.$mail.'" n\'est pas correctement formaté');
  19. //Envoi du mail
  20. $mail = new Mail();
  21. $mail->recipients = $_['recipient'];
  22. $mail->expeditor = $_['from'];
  23. $mail->reply = $_['from'];
  24. $mail->title = html_entity_decode($_['subject'],ENT_QUOTES,'UTF-8');
  25. $mail->message = html_entity_decode($_['message']);
  26. if(!empty($_['files'])){
  27. $files = json_decode($_['files'],true);
  28. if($files!=false && count($files)!=0){
  29. foreach ($files as $file) {
  30. $path = isset($file['temporary']) ? File::temp().SLASH.str_replace(array('/', '\\'), SLASH, $file['path']) : str_replace(array('/', '\\'), SLASH, $file['path']);
  31. if(strpos($path, File::dir()) === false)
  32. $path = File::dir().SLASH.$path;
  33. //Vérification de l'existence fichier
  34. if(!file_exists($path)) continue;
  35. $mail->attachments[] = array(
  36. 'name' => $file['name'],
  37. 'type' => mime_content_type($path),
  38. 'stream'=> file_get_contents($path)
  39. );
  40. }
  41. }
  42. }
  43. $mail->send();
  44. Plugin::callHook("sendmail_after_send",array($_, $mail));
  45. $response['message'] = 'E-mail envoyé';
  46. $response['data'] = $_;
  47. });
  48. //Sauvegarde des configurations de sendmail
  49. Action::register('sendmail_setting_save',function(&$response){
  50. global $myUser,$_,$conf;
  51. User::check_access('sendmail','configure');
  52. foreach(Configuration::setting('sendmail') as $key=>$value)
  53. if(is_array($value)) $allowed[] = $key;
  54. foreach ($_['fields'] as $key => $value) {
  55. if(!in_array($key, $allowed)) continue;
  56. if($key=='sendmail_default_signature') $value = html_entity_decode($value);
  57. $conf->put($key,$value);
  58. }
  59. });
  60. //Sauvegarde des préférences user de sendmail
  61. Action::register('sendmail_user_save_preference',function(&$response){
  62. global $myUser,$_,$conf;
  63. User::check_access('sendmail','edit');
  64. if(!isset($_['preferences']) || !isset($_['preferences']['sendmail_email_signature'])) throw new Exception("Vous devez saisir une signature e-mail");
  65. $myUser->preference('sendmail_email_signature',html_entity_decode($_['preferences']['sendmail_email_signature']));
  66. });
  67. ?>