New: IMAP dolimail Support
This commit is contained in:
parent
1a55159e35
commit
7c550fdba5
@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// TODO Include this include file into all element pages allowing email sending
|
// TODO Include this include file into all class objects
|
||||||
|
|
||||||
// $id must be defined
|
// $id must be defined
|
||||||
// $actiontypecode must be defined
|
// $actiontypecode must be defined
|
||||||
@ -47,7 +47,7 @@ if (GETPOST('addfile'))
|
|||||||
/*
|
/*
|
||||||
* Remove file in email form
|
* Remove file in email form
|
||||||
*/
|
*/
|
||||||
if (! empty($_POST['removedfile']))
|
if (! empty($_POST['removedfile']) && empty($_POST['removAll']))
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
|
||||||
@ -60,11 +60,41 @@ if (! empty($_POST['removedfile']))
|
|||||||
$action='presend';
|
$action='presend';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove all files in email form
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(! empty($_POST['removAll']))
|
||||||
|
{
|
||||||
|
$listofpaths=array();
|
||||||
|
$listofnames=array();
|
||||||
|
$listofmimes=array();
|
||||||
|
if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
|
||||||
|
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
|
||||||
|
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
|
||||||
|
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
|
||||||
|
$formmail = new FormMail($db);
|
||||||
|
|
||||||
|
foreach($listofpaths as $key => $value)
|
||||||
|
{
|
||||||
|
$pathtodelete = $value;
|
||||||
|
$filetodelete = $listofnames[$key];
|
||||||
|
$result = dol_delete_file($pathtodelete,1); // Delete uploded Files
|
||||||
|
|
||||||
|
$langs->load("other");
|
||||||
|
setEventMessage($langs->trans("FileWasRemoved",$filetodelete));
|
||||||
|
|
||||||
|
$formmail->remove_attached_files($key); // Update Session
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send mail
|
* Send mail
|
||||||
*/
|
*/
|
||||||
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'] && !$_POST['modelselected'])
|
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removAll'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
|
||||||
{
|
{
|
||||||
|
if($conf->dolimail->enabled) $langs->load("dolimail@dolimail");
|
||||||
$langs->load('mails');
|
$langs->load('mails');
|
||||||
|
|
||||||
$subject='';$actionmsg='';$actionmsg2='';
|
$subject='';$actionmsg='';$actionmsg2='';
|
||||||
@ -81,7 +111,37 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
else if ($object->element == 'societe')
|
else if ($object->element == 'societe')
|
||||||
{
|
{
|
||||||
$thirdparty=$object;
|
$thirdparty=$object;
|
||||||
$sendtosocid=$thirdparty->id;
|
if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id;
|
||||||
|
elseif($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)
|
||||||
|
{
|
||||||
|
setEventMessage($langs->trans('ErrorFailedToFindSocieteRecord',$_POST['sendto']),'errors');
|
||||||
|
}
|
||||||
|
elseif (sizeof($possibleaccounts)>1)
|
||||||
|
{
|
||||||
|
$sendtosocid=$possibleaccounts[1]['id'];
|
||||||
|
$result=$object->fetch($sendtosocid);
|
||||||
|
|
||||||
|
setEventMessage($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name));
|
||||||
|
}
|
||||||
|
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 a type that is not supported');
|
else dol_print_error('','Use actions_sendmails.in.php for a type that is not supported');
|
||||||
|
|
||||||
@ -103,7 +163,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
}
|
}
|
||||||
else // Id du contact
|
else // Id du contact
|
||||||
{
|
{
|
||||||
$sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email');
|
$sendto = $thirdparty->contact_get_property($_POST['receiver'],'email');
|
||||||
$sendtoid = $_POST['receiver'];
|
$sendtoid = $_POST['receiver'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,7 +180,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
}
|
}
|
||||||
else // Id du contact
|
else // Id du contact
|
||||||
{
|
{
|
||||||
$sendtocc = $thirdparty->contact_get_property((int) $_POST['receivercc'],'email');
|
$sendtocc = $thirdparty->contact_get_property($_POST['receivercc'],'email');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,11 +221,49 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$filename = $attachedfiles['names'];
|
$filename = $attachedfiles['names'];
|
||||||
$mimetype = $attachedfiles['mimes'];
|
$mimetype = $attachedfiles['mimes'];
|
||||||
|
|
||||||
$trackid = GETPOST('trackid','aZ');
|
if($conf->dolimail->enabled)
|
||||||
|
{
|
||||||
|
$mailfromid = explode ("#", $_POST['frommail'],3);
|
||||||
|
if (sizeof($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";
|
||||||
|
|
||||||
|
$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');
|
||||||
|
setEventMessage($err,$mailboxconfig->element,'errors');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mailboxconfig->mailboxid=$_POST['frommail'];
|
||||||
|
$mailboxconfig->foldername=$folder;
|
||||||
|
$from = $mailfromid[0] . $mailfromid[2];
|
||||||
|
$imap=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Send mail
|
// Send mail
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||||
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
|
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1);
|
||||||
if ($mailfile->error)
|
if ($mailfile->error)
|
||||||
{
|
{
|
||||||
$mesgs[]='<div class="error">'.$mailfile->error.'</div>';
|
$mesgs[]='<div class="error">'.$mailfile->error.'</div>';
|
||||||
@ -176,6 +274,25 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
if($conf->dolimail->enabled)
|
||||||
|
{
|
||||||
|
$mid = (GETPOST('mid','int') ? GETPOST('mid','int') : 0);
|
||||||
|
if ($mid)
|
||||||
|
{
|
||||||
|
// set imap flag answered if it is a 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) setEventMessage($langs->trans("MailMovedToImapFolder",$folder),'mesgs');
|
||||||
|
else setEventMessage($langs->trans("MailMovedToImapFolder_Warning",$folder),'warnings');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialisation donnees
|
// Initialisation donnees
|
||||||
$object->socid = $sendtosocid; // To link to a company
|
$object->socid = $sendtosocid; // To link to a company
|
||||||
@ -205,24 +322,27 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
// This avoid sending mail twice if going out and then back to page
|
// 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));
|
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
|
||||||
setEventMessage($mesg);
|
setEventMessage($mesg);
|
||||||
header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.$object->id);
|
if($conf->dolimail->enabled) header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.$object->id.'&'.($paramname2?$paramname2:'mid').'='.$parm2val);
|
||||||
|
else header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.$object->id);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$langs->load("other");
|
$langs->load("other");
|
||||||
|
$mesg='<div class="error">';
|
||||||
if ($mailfile->error)
|
if ($mailfile->error)
|
||||||
{
|
{
|
||||||
$mesg='';
|
|
||||||
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
|
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
|
||||||
$mesg.='<br>'.$mailfile->error;
|
$mesg.='<br>'.$mailfile->error;
|
||||||
setEventMessage($mesg,'errors');
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings');
|
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
|
||||||
}
|
}
|
||||||
|
$mesg.='</div>';
|
||||||
|
|
||||||
|
setEventMessage($mesg,'warnings');
|
||||||
$action = 'presend';
|
$action = 'presend';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user