From f60489b76651f45597ee6aed0a8372082618bdd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garc=C3=ADa?= Date: Sun, 17 Dec 2017 23:06:26 +0100 Subject: [PATCH 1/4] FIX #4875 Dolimail thirdparty code is integrated into Dolibarr core code Close #4875 --- htdocs/core/actions_sendmails.inc.php | 99 --------------------------- 1 file changed, 99 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 5a8d32efde57b..423c81ab0cada 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -105,7 +105,6 @@ $trackid = GETPOST('trackid','aZ09'); $subject='';$actionmsg='';$actionmsg2=''; - if (! empty($conf->dolimail->enabled)) $langs->load("dolimail@dolimail"); $langs->load('mails'); if (is_object($object)) @@ -129,36 +128,6 @@ { $thirdparty=$object; if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; - elseif (! empty($conf->dolimail->enabled)) - { - $dolimail = new Dolimail($db); - $possibleaccounts=$dolimail->get_societe_by_email($_POST['sendto'],"1"); - $possibleuser=$dolimail->get_from_user_by_mail($_POST['sendto'],"1"); // suche in llx_societe and socpeople - if (!$possibleaccounts && !$possibleuser) - { - setEventMessages($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']), null, 'errors'); - } - elseif (count($possibleaccounts)>1) - { - $sendtosocid=$possibleaccounts[1]['id']; - $result=$object->fetch($sendtosocid); - - setEventMessages($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name), null, 'mesgs'); - } - else - { - if($possibleaccounts){ - $sendtosocid=$possibleaccounts[1]['id']; - $result=$object->fetch($sendtosocid); - }elseif($possibleuser){ - $sendtosocid=$possibleuser[0]['id']; - - $result=$uobject->fetch($sendtosocid); - $object=$uobject; - } - - } - } } else dol_print_error('','Use actions_sendmails.in.php for an element/object that is not supported'); } @@ -318,49 +287,6 @@ $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; - - // Feature to push mail sent into Sent folder - if (! empty($conf->dolimail->enabled)) - { - $mailfromid = explode("#", $_POST['frommail'],3); // $_POST['frommail'] = 'aaa#Sent# ' // TODO Use a better way to define Sent dir. - if (count($mailfromid)==0) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; - else - { - $mbid = $mailfromid[1]; - - /*IMAP Postbox*/ - $mailboxconfig = new IMAP($db); - $mailboxconfig->fetch($mbid); - if ($mailboxconfig->mailbox_imap_host) $ref=$mailboxconfig->get_ref(); - - $mailboxconfig->folder_id=$mailboxconfig->mailbox_imap_outbox; - $mailboxconfig->userfolder_fetch(); - - if ($mailboxconfig->mailbox_save_sent_mails == 1) - { - - $folder=str_replace($ref, '', $mailboxconfig->folder_cache_key); - if (!$folder) $folder = "Sent"; // Default Sent folder - - $mailboxconfig->mbox = imap_open($mailboxconfig->get_connector_url().$folder, $mailboxconfig->mailbox_imap_login, $mailboxconfig->mailbox_imap_password); - if (FALSE === $mailboxconfig->mbox) - { - $info = FALSE; - $err = $langs->trans('Error3_Imap_Connection_Error'); - setEventMessages($err,$mailboxconfig->element, null, 'errors'); - } - else - { - $mailboxconfig->mailboxid=$_POST['frommail']; - $mailboxconfig->foldername=$folder; - $from = $mailfromid[0] . $mailfromid[2]; - $imap=1; - } - - } - } - } - // Make substitution in email content $substitutionarray=getCommonSubstitutionArray($langs, 0, null, $object); $substitutionarray['__EMAIL__'] = $sendto; @@ -394,26 +320,6 @@ { $error=0; - // FIXME This must be moved into the trigger for action $trigger_name - if (! empty($conf->dolimail->enabled)) - { - $mid = (GETPOST('mid','int') ? GETPOST('mid','int') : 0); // Original mail id is set ? - if ($mid) - { - // set imap flag answered if it is an answered mail - $dolimail=new DoliMail($db); - $dolimail->id = $mid; - $res=$dolimail->set_prop($user, 'answered',1); - } - if ($imap==1) - { - // write mail to IMAP Server - $movemail = $mailboxconfig->putMail($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$folder,$deliveryreceipt,$mailfile); - if ($movemail) setEventMessages($langs->trans("MailMovedToImapFolder",$folder), null, 'mesgs'); - else setEventMessages($langs->trans("MailMovedToImapFolder_Warning",$folder), null, 'warnings'); - } - } - // Initialisation of datas if (is_object($object)) { @@ -453,11 +359,6 @@ // This avoid sending mail twice if going out and then back to page $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); setEventMessages($mesg, null, 'mesgs'); - if ($conf->dolimail->enabled) - { - header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').'&'.($paramname2?$paramname2:'mid').'='.$parm2val); - exit; - } header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'')); exit; } From 77d410708538a8c15e79340862e9c620cc4c71b9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 17:44:37 +0100 Subject: [PATCH 2/4] Update actions_sendmails.inc.php --- htdocs/core/actions_sendmails.inc.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 629e80e5a8233..ff567803ae44d 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -416,22 +416,15 @@ } } - if ($error) - { - dol_print_error($db); - } - else - { - // Redirect here - // This avoid sending mail twice if going out and then back to page - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); - setEventMessages($mesg, null, 'mesgs'); + // Redirect here + // This avoid sending mail twice if going out and then back to page + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); + setEventMessages($mesg, null, 'mesgs'); $moreparam=''; if (isset($paramname2) || isset($paramval2)) $moreparam.= '&'.($paramname2?$paramname2:'mid').'='.$paramval2; header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').$moreparam); exit; - } } else { From 5dde72e3dd12d53b5ae45c4f6496d102f518d563 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Feb 2018 17:45:05 +0100 Subject: [PATCH 3/4] Update actions_sendmails.inc.php --- htdocs/core/actions_sendmails.inc.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index ff567803ae44d..d478dc6bc0666 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -364,8 +364,6 @@ $result=$mailfile->sendfile(); if ($result) { - $error=0; - // Two hooks are available into method $mailfile->sendfile, so dedicated code is no more required /* if (! empty($conf->dolimail->enabled)) From e468584783ab4a90ce442ae28afa4c4d4e8229b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 Apr 2018 18:31:46 +0200 Subject: [PATCH 4/4] Update actions_sendmails.inc.php --- htdocs/core/actions_sendmails.inc.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index d478dc6bc0666..7df1fe2dba6b8 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -131,6 +131,12 @@ if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; } else dol_print_error('','Use actions_sendmails.in.php for an element/object that is not supported'); + + if (is_object($hookmanager)) + { + $parameters=array(); + $reshook=$hookmanager->executeHooks('initSendToSocid',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + } } else $thirdparty = $mysoc;