Get merging contact into mail template file working

This commit is contained in:
Nathan Gray 2014-01-15 16:29:30 +00:00
parent 5197487512
commit f9c2c73432
4 changed files with 105 additions and 37 deletions

View File

@ -1425,11 +1425,11 @@ abstract class bo_merge
{ {
case 'message/rfc822': case 'message/rfc822':
//error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs')=>$content_url ->".function_backtrace()); //error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs')=>$content_url ->".function_backtrace());
$bofelamimail = felamimail_bo::getInstance(); $mail_bo = mail_bo::getInstance();
$bofelamimail->openConnection(); $mail_bo->openConnection();
try try
{ {
$msgs = $bofelamimail->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='', $importID=''); $msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='', $importID='');
} }
catch (egw_exception_wrong_userinput $e) catch (egw_exception_wrong_userinput $e)
{ {
@ -1742,10 +1742,7 @@ abstract class bo_merge
); );
if ($file['mime'] == 'message/rfc822') if ($file['mime'] == 'message/rfc822')
{ {
// does not work on children for some reason, now handled in felamimail_bo::importMessageToMergeAndSend self::document_mail_action($current_level[$prefix.$file['name']], $file);
//$documents[$file['mime']]['allowOnMultiple'] = $GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook';
// only need confirmation for multiple receipients for addressbook, as for others we can't do it anyway
if ($GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook') $current_level[$prefix.$file['name']]['confirm_multiple'] = lang('Do you want to send the message to all selected entries, WITHOUT further editing?');
} }
break; break;
@ -1776,10 +1773,7 @@ abstract class bo_merge
); );
if ($file['mime'] == 'message/rfc822') if ($file['mime'] == 'message/rfc822')
{ {
// does not work on children for some reason, now handled in felamimail_bo::importMessageToMergeAndSend self::document_mail_action($documents[$prefix.$file['name']], $file);
//$documents[$file['mime']]['allowOnMultiple'] = $GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook';
// only need confirmation for multiple receipients for addressbook, as for others we can't do it anyway
if ($GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook') $documents[$file['mime']]['confirm_multiple'] = lang('Do you want to send the message to all selected entries, WITHOUT further editing?');
} }
} }
$documents[$file['mime']]['children'][$prefix.$file['name']] = egw_vfs::decodePath($file['name']); $documents[$file['mime']]['children'][$prefix.$file['name']] = egw_vfs::decodePath($file['name']);
@ -1794,10 +1788,7 @@ abstract class bo_merge
); );
if ($file['mime'] == 'message/rfc822') if ($file['mime'] == 'message/rfc822')
{ {
// does not work on children for some reason, now handled in felamimail_bo::importMessageToMergeAndSend self::document_mail_action($documents[$prefix.$file['name']], $file);
//$documents[$file['mime']]['allowOnMultiple'] = $GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook';
// only need confirmation for multiple receipients for addressbook, as for others we can't do it anyway
if ($GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook') $documents[$prefix.$file['name']]['confirm_multiple'] = lang('Do you want to send the message to all selected entries, WITHOUT further editing?');
} }
} }
} }
@ -1813,6 +1804,43 @@ abstract class bo_merge
); );
} }
/**
* Set up a document action for an eml (email) document
*
* Email (.eml) documents get special action handling. They don't send a file
* back to the client like the other documents. Merging for a single selected
* contact opens a compose window, multiple contacts just sends.
*
* @param Array &$action Action to be modified for mail
* @param Array $file Array of information about the document from egw_vfs::find
* @return void
*/
private static function document_mail_action(Array &$action, $file)
{
unset($action['postSubmit']);
// These parameters trigger compose + merge
$extra = array(
'from' => 'merge',
'document' => $file['path'],
);
$action['confirm_multiple'] = lang('Do you want to send the message to all selected entries, WITHOUT further editing?') .
lang('Popup will close when finished');
// egw.open() would work, but nextmatch actions only passes 1 ID through
//$action['egw_open'] = 'edit-mail--'.implode('&',$extra);
//
// We use location and send the popup info anyway instead
$action['nm_action'] = 'location';
$action['popup'] = egw_link::get_registry('mail', 'edit_popup');
$action['url'] = egw_link::get_registry('mail', 'edit') + $extra + array(
// Mail edit requires ID to have a value before it will look at the other variables
egw_link::get_registry('mail', 'edit_id') => 'true',
'preset[mailtocontactbyid]' => '$id',
);
$action['target'] = 'compose_' .$file['path'];
}
/** /**
* Check if given document (relative path from document_actions()) exists in one of the given dirs * Check if given document (relative path from document_actions()) exists in one of the given dirs
* *

View File

@ -5209,7 +5209,7 @@ class mail_bo
* @param string $importID ID for the imported message, used by attachments to identify them unambiguously * @param string $importID ID for the imported message, used by attachments to identify them unambiguously
* @return mixed array of messages with success and failed messages or exception * @return mixed array of messages with success and failed messages or exception
*/ */
function importMessageToMergeAndSend(bo_merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, $importID='') function importMessageToMergeAndSend(bo_merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID='')
{ {
$importfailed = false; $importfailed = false;
$processStats = array('success'=>array(),'failed'=>array()); $processStats = array('success'=>array(),'failed'=>array());
@ -5291,7 +5291,7 @@ class mail_bo
//error_log(__METHOD__.__LINE__.' ID:'.$val.' Data:'.array2string($contact)); //error_log(__METHOD__.__LINE__.' ID:'.$val.' Data:'.array2string($contact));
$email = ($contact['email'] ? $contact['email'] : $contact['email_home']); $email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']); $nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
$activeMailProfiles = $this->mail->getAccountIdentities($this->profileID); $activeMailProfiles = $this->getAccountIdentities($this->profileID);
$activeMailProfile = array_shift($activeMailProfiles); $activeMailProfile = array_shift($activeMailProfiles);
//error_log(__METHOD__.__LINE__.array2string($activeMailProfile)); //error_log(__METHOD__.__LINE__.array2string($activeMailProfile));
$mailObject->From = $activeMailProfile['ident_email']; $mailObject->From = $activeMailProfile['ident_email'];
@ -5321,7 +5321,7 @@ class mail_bo
//error_log(__METHOD__.__LINE__.' Result:'.$mailObject->Body.' error:'.array2string($e)); //error_log(__METHOD__.__LINE__.' Result:'.$mailObject->Body.' error:'.array2string($e));
if (!empty($AltBody)) $mailObject->AltBody = $bo_merge->merge_string($AltBody, $val, $e, $mailObject->AltBodyContentType, array(), self::$displayCharset); if (!empty($AltBody)) $mailObject->AltBody = $bo_merge->merge_string($AltBody, $val, $e, $mailObject->AltBodyContentType, array(), self::$displayCharset);
$ogServer = emailadmin_account::read($_profileID)->smtpServer(); $ogServer = emailadmin_account::read($this->profileID)->smtpServer();
#_debug_array($ogServer); #_debug_array($ogServer);
$mailObject->Host = $ogServer->host; $mailObject->Host = $ogServer->host;
$mailObject->Port = $ogServer->port; $mailObject->Port = $ogServer->port;
@ -5424,23 +5424,8 @@ class mail_bo
// no send, save successful, and message_uid present // no send, save successful, and message_uid present
if ($savefailed===false && $messageUid && is_null($sendOK)) if ($savefailed===false && $messageUid && is_null($sendOK))
{ {
$importID = $messageUid;
$openComposeWindow = true; $openComposeWindow = true;
list($fm_width,$fm_height) = explode('x',egw_link::get_registry('felamimail','view_popup'));
$linkData = array
(
'menuaction' => 'felamimail.uicompose.composeFromDraft',
'uid' => $messageUid,
'folder' => base64_encode($_folder),
'icServer' => $this->profileID,
'method' => 'importMessageToMergeAndSend',
);
$composeUrl = egw::link('/index.php',$linkData);
//error_log(__METHOD__.__LINE__.' ComposeURL:'.$composeUrl);
$GLOBALS['egw_info']['flags']['java_script_thirst'] .= '<script language="JavaScript">'.
//"egw_openWindowCentered('$composeUrl','composeAsDraft_".$messageUid."',".$fm_width.",".$fm_height.");".
"window.open('$composeUrl','_blank','dependent=yes,width=".$fm_width.",height=".$fm_height.",toolbar=no,scrollbars=no,status=no');".
"</script>";
$processStats['success'][] = lang("Saving of message %1 succeeded. Check Folder %2.",$Subject,$_folder);
} }
} }
else else

View File

@ -716,7 +716,7 @@ class mail_compose
$addressbookprefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook']; $addressbookprefs =& $GLOBALS['egw_info']['user']['preferences']['addressbook'];
if (method_exists($GLOBALS['egw']->contacts,'search')) { if (method_exists($GLOBALS['egw']->contacts,'search')) {
$addressArray = split(',',$_REQUEST['preset']['mailtocontactbyid']); $addressArray = explode(',',$_REQUEST['preset']['mailtocontactbyid']);
foreach ((array)$addressArray as $id => $addressID) foreach ((array)$addressArray as $id => $addressID)
{ {
$addressID = (int) $addressID; $addressID = (int) $addressID;
@ -1249,7 +1249,7 @@ class mail_compose
* @param type $mail_id If composing based on an existing mail, this is the ID of the mail * @param type $mail_id If composing based on an existing mail, this is the ID of the mail
* @param type $part_id For multi-part mails, indicates which part * @param type $part_id For multi-part mails, indicates which part
* @param type $from Indicates what the mail is based on, and how to extract data. * @param type $from Indicates what the mail is based on, and how to extract data.
* One of 'compose', 'composeasnew', 'reply', 'reply_all' or 'forward' * One of 'compose', 'composeasnew', 'reply', 'reply_all', 'forward' or 'merge'
* @param boolean $_focusElement varchar subject, to, body supported * @param boolean $_focusElement varchar subject, to, body supported
* @param boolean $suppressSigOnTop * @param boolean $suppressSigOnTop
* @param boolean $isReply * @param boolean $isReply
@ -1315,6 +1315,56 @@ class mail_compose
error_log('Unhandled compose source: ' . $from); error_log('Unhandled compose source: ' . $from);
} }
} }
else if ($from == 'merge' && $_REQUEST['document'])
{
/*
* Special merge from everywhere else becase all other apps merge gives
* a document to be downloaded, this either opens a compose dialog or
* just sends emails
*/
// Merge selected ID (in mailtocontactbyid or $mail_id) into given document
$document_merge = new addressbook_merge();
$this->mail_bo->openConnection();
$merge_ids = $_REQUEST['preset']['mailtocontactbyid'] ? $_REQUEST['preset']['mailtocontactbyid'] : $mail_id;
$merge_ids = is_array($merge_ids) ? $merge_ids : explode(',',$merge_ids);
try
{
$merged_mail_id = '';
$folder = '';
if($error = $document_merge->check_document($_REQUEST['document'],''))
{
$content['msg'] = $error;
return $content;
}
// Merge does not work correctly (missing to) if current app is not addressbook
$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
// Actually do the merge
$results = $this->mail_bo->importMessageToMergeAndSend($document_merge, egw_vfs::PREFIX . $_REQUEST['document'], $merge_ids, $folder, $merged_mail_id);
// Handle results - one email open compose, more than one just sent
if(count($merge_ids) <= 1)
{
$merged_mail_id = trim($GLOBALS['egw_info']['user']['account_id']).mail_ui::$delimiter.
$this->mail_bo->profileID.mail_ui::$delimiter.
base64_encode($folder).mail_ui::$delimiter.$merged_mail_id;
$content = $this->getComposeFrom($merged_mail_id, $part_id, 'composefromdraft', $_focusElement, $suppressSigOnTop, $isReply);
}
else
{
$success = implode(', ',$results['success']);
$fail = implode(', ', $results['failed']);
if($success) egw_framework::message($success, 'success');
egw_framework::window_close($fail);
}
}
catch (egw_exception_wrong_userinput $e)
{
// if this returns with an exeption, something failed big time
$content['msg'] = $e->getMessage();
}
}
return $content; return $content;
} }
@ -1416,6 +1466,11 @@ class mail_compose
} }
foreach((array)$headers['TO'] as $val) { foreach((array)$headers['TO'] as $val) {
if(!is_array($val))
{
$this->sessionData['to'][] = $val;
continue;
}
if($val['MAILBOX_NAME'] == 'undisclosed-recipients' || (empty($val['MAILBOX_NAME']) && empty($val['HOST_NAME'])) ) { if($val['MAILBOX_NAME'] == 'undisclosed-recipients' || (empty($val['MAILBOX_NAME']) && empty($val['HOST_NAME'])) ) {
continue; continue;
} }

View File

@ -143,7 +143,7 @@ class mail_ui
)); ));
} }
$GLOBALS['egw']->session->commit_session(); //$GLOBALS['egw']->session->commit_session();
//_debug_array($this->mail_bo->mailPreferences); //_debug_array($this->mail_bo->mailPreferences);
//$endtime = microtime(true) - $starttime; //$endtime = microtime(true) - $starttime;
//error_log(__METHOD__.__LINE__. " time used: ".$endtime); //error_log(__METHOD__.__LINE__. " time used: ".$endtime);