From c0097b3860bda55a88fdda4f224e1a8f284afd44 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 15 Apr 2015 15:55:18 +0000 Subject: [PATCH] More WIP mail message integration: - Make integrate function a static function - Implement infolog, tracker and calendar save as buttons in mail compose with open popup - Fix Date and Max_line_Chars in mail_integration --- calendar/inc/class.calendar_hooks.inc.php | 5 +- calendar/inc/class.calendar_uiforms.inc.php | 13 +++- infolog/inc/class.infolog_hooks.inc.php | 5 +- infolog/inc/class.infolog_ui.inc.php | 15 ++++- mail/inc/class.mail_compose.inc.php | 70 +++++++++++---------- mail/inc/class.mail_integration.inc.php | 25 +++++--- mail/templates/default/compose.xet | 1 + 7 files changed, 86 insertions(+), 48 deletions(-) diff --git a/calendar/inc/class.calendar_hooks.inc.php b/calendar/inc/class.calendar_hooks.inc.php index 6f644609a8..d9fb4acbb6 100644 --- a/calendar/inc/class.calendar_hooks.inc.php +++ b/calendar/inc/class.calendar_hooks.inc.php @@ -864,7 +864,10 @@ END:VALARM'; */ public static function mail_import($args) { - return 'calendar.calendar_uiforms.mail_import'; + return array ( + 'menuaction' => 'calendar.calendar_uiforms.mail_import', + 'popup' => egw_link::get_registry('calendar', 'edit_popup') + ); } } diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index a75286a1be..6f51fa5019 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -32,6 +32,7 @@ class calendar_uiforms extends calendar_ui 'import' => true, 'cat_acl' => true, 'meeting' => true, + 'mail_import' => true, ); /** @@ -2566,11 +2567,19 @@ class calendar_uiforms extends calendar_ui /** * imports a mail as Calendar * - * @param array $mailContent mail content + * @param array $mailContent = null mail content * @return array */ - function mail_import($mailContent) + function mail_import(array $mailContent=null) { + // It would get called from compose as a popup with egw_data + if (!is_array($mailContent) && ($_GET['egw_data'])) + { + // get raw mail data + egw_link::get_data ($_GET['egw_data']); + return false; + } + if (is_array($mailContent)) { diff --git a/infolog/inc/class.infolog_hooks.inc.php b/infolog/inc/class.infolog_hooks.inc.php index a170db5cd7..ece94544da 100644 --- a/infolog/inc/class.infolog_hooks.inc.php +++ b/infolog/inc/class.infolog_hooks.inc.php @@ -566,6 +566,9 @@ class infolog_hooks */ public static function mail_import($args) { - return 'infolog.infolog_ui.mail_import'; + return array ( + 'menuaction' => 'infolog.infolog_ui.mail_import', + 'popup' => egw_link::get_registry('infolog', 'edit_popup') + ); } } diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index 49f242ee7f..b84f5bf1b4 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -23,6 +23,7 @@ class infolog_ui 'admin' => True, 'hook_view' => True, 'writeLangFile' => True, + 'mail_import' => True ); /** * reference to the infolog preferences of the user @@ -2487,12 +2488,20 @@ class infolog_ui /** * imports a mail as infolog * - * @data string $_data registered hook data + * @param array $mailContent = null content of mail * @return array */ - function mail_import($mailContent) + function mail_import(array $mailContent=null) { - $this->edit($this->bo->import_mail($mailContent['addresses'], + // It would get called from compose as a popup with egw_data + if (!is_array($mailContent) && ($_GET['egw_data'])) + { + // get the mail raw data + egw_link::get_data ($_GET['egw_data']); + return false; + } + + return $this->edit($this->bo->import_mail($mailContent['addresses'], $mailContent['subject'], $mailContent['message'], $mailContent['attachments'], diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index d11a011b4e..b091fb97ab 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -163,6 +163,14 @@ class mail_compose 'hint' => 'check to save as trackerentry on send', 'onExecute' => 'javaScript:app.mail.compose_setToggle' ), + 'to_calendar' => array( + 'caption' => 'Calendar', + 'icon' => 'to_calendar', + 'group' => $group, + 'checkbox' => true, + 'hint' => 'check to save as calendar event on send', + 'onExecute' => 'javaScript:app.mail.compose_setToggle' + ), 'disposition' => array( 'caption' => 'Notification', 'icon' => 'high', @@ -3047,41 +3055,35 @@ class mail_compose if (is_array($this->sessionData['cc'])) $mailaddresses['cc'] = $this->sessionData['cc']; if (is_array($this->sessionData['bcc'])) $mailaddresses['bcc'] = $this->sessionData['bcc']; if (!empty($mailaddresses)) $mailaddresses['from'] = $GLOBALS['egw']->translation->decodeMailHeader($fromAddress); - // attention: we dont return from infolog/tracker. You cannot check both. cleanups will be done there. - if ($_formData['to_infolog'] == 'on') { - $uiinfolog = new infolog_ui(); - $uiinfolog->import_mail( - $mailaddresses, - $this->sessionData['subject'], - $this->convertHTMLToText($this->sessionData['body']), - $this->sessionData['attachments'], - false, // date - $mail->getRaw() - ); - } - if ($_formData['to_tracker'] == 'on') { - $uitracker = new tracker_ui(); - $uitracker->import_mail( - $mailaddresses, - $this->sessionData['subject'], - $this->convertHTMLToText($this->sessionData['body']), - $this->sessionData['attachments'], - false, // date - $mail->getRaw() - ); - } -/* - if ($_formData['to_calendar'] == 'on') { - $uical =& CreateObject('calendar.calendar_uiforms'); - $uical->import_mail( - $mailaddresses, - $this->sessionData['subject'], - $this->convertHTMLToText($this->sessionData['body']), - $this->sessionData['attachments'] - ); - } -*/ + if ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' ) + { + foreach(array('to_infolog','to_tracker','to_calendar') as $app_key) + { + if ($_formData[$app_key] == 'on') + { + $app_name = substr($app_key,3); + // Get registered hook data of the app called for integration + $hook = $GLOBALS['egw']->hooks->single(array('location'=> 'mail_import'),$app_name); + + // Open the app called for integration in a popup + // and store the mail raw data as egw_data, in order to + // be stored from registered app method later + egw_framework::popup(egw::link('/index.php', array( + 'menuaction' => $hook['menuaction'], + 'egw_data' => egw_link::set_data(null,'mail_integration::integrate',array( + $app_name, + $mailaddresses, + $this->sessionData['subject'], + $this->convertHTMLToText($this->sessionData['body']), + $this->sessionData['attachments'], + false, // date + $mail->getRaw()),true) + )),'_blank',$hook['popup']); + } + } + } + if(is_array($this->sessionData['attachments'])) { foreach($this->sessionData['attachments'] as $value) { diff --git a/mail/inc/class.mail_integration.inc.php b/mail/inc/class.mail_integration.inc.php index c1c842cc73..9f9e377d2a 100644 --- a/mail/inc/class.mail_integration.inc.php +++ b/mail/inc/class.mail_integration.inc.php @@ -25,6 +25,13 @@ class mail_integration { 'integrate' => true ); + /** + * Maximum number of line characters (-_+=~) allowed in a mail, to not stall the layout. + * Longer lines / biger number of these chars are truncated to that max. number or chars. + * + * @var int + */ + const MAX_LINE_CHARS = 40; /** * Gets requested mail information and sets them as data link @@ -52,13 +59,17 @@ class mail_integration { * @param string $_rawMail * @throws egw_exception_assertion_failed */ - function integrate ($_app='',$_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false,$_rawMail=null,$_icServerID=null) + public static function integrate ($_app='',$_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false,$_rawMail=null,$_icServerID=null) { // App name which is called for integration $app = !empty($_GET['app'])? $_GET['app']:$_app; // Set the date - if (!$_date) $_date = $this->bo->user_time_now; + if (!$_date) + { + $time = time(); + $_date = egw_time::server2user($time->now,'ts'); + } // Integrate not yet saved mail if (empty($_GET['rowid']) && $_to_emailAddress && $app) @@ -233,11 +244,11 @@ class mail_integration { ); } - // shorten long (> $this->max_line_chars) lines of "line" chars (-_+=~) in mails + // shorten long (> self::max_line_chars) lines of "line" chars (-_+=~) in mails $data_message = preg_replace_callback( - '/[-_+=~\.]{'.$this->max_line_chars.',}/m', + '/[-_+=~\.]{'.self::MAX_LINE_CHARS.',}/m', function($matches) { - return substr($matches[0],0,$this->max_line_chars); + return substr($matches[0],0,self::MAX_LINE_CHARS); }, $mailcontent['message'] ); @@ -258,10 +269,10 @@ class mail_integration { // Get the registered hook method of requested app for integration - $menuaction = $GLOBALS['egw']->hooks->single(array('location' => 'mail_import'),$app); + $hook = $GLOBALS['egw']->hooks->single(array('location' => 'mail_import'),$app); // Execute import mail with provided content - ExecMethod($menuaction,array ( + ExecMethod($hook['menuaction'],array ( 'addresses' => $data_addresses, 'attachments' => $data_attachments, 'message' => $data_message, diff --git a/mail/templates/default/compose.xet b/mail/templates/default/compose.xet index cbb73dd4a5..4b822a8ae6 100644 --- a/mail/templates/default/compose.xet +++ b/mail/templates/default/compose.xet @@ -10,6 +10,7 @@ +