cant store a resource in egw_link::set_data()

This commit is contained in:
Ralf Becker 2015-04-16 07:03:53 +00:00
parent 5a6d9b5fcb
commit 24478fe0d5
2 changed files with 36 additions and 36 deletions

View File

@ -3065,25 +3065,31 @@ class mail_compose
$app_name = substr($app_key,3); $app_name = substr($app_key,3);
// Get registered hook data of the app called for integration // Get registered hook data of the app called for integration
$hook = $GLOBALS['egw']->hooks->single(array('location'=> 'mail_import'),$app_name); $hook = $GLOBALS['egw']->hooks->single(array('location'=> 'mail_import'),$app_name);
// store mail / eml in temp. file to not have to download it from mail-server again
$eml = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'mail_integrate');
$eml_fp = fopen($eml, 'w');
stream_copy_to_stream($mail->getRaw(), $eml_fp);
fclose($eml_fp);
// Open the app called for integration in a popup // Open the app called for integration in a popup
// and store the mail raw data as egw_data, in order to // and store the mail raw data as egw_data, in order to
// be stored from registered app method later // be stored from registered app method later
egw_framework::popup(egw::link('/index.php', array( egw_framework::popup(egw::link('/index.php', array(
'menuaction' => $hook['menuaction'], 'menuaction' => $hook['menuaction'],
'egw_data' => egw_link::set_data(null,'mail_integration::integrate',array( 'egw_data' => egw_link::set_data(null,'mail_integration::integrate',array(
$app_name,
$mailaddresses, $mailaddresses,
$this->sessionData['subject'], $this->sessionData['subject'],
$this->convertHTMLToText($this->sessionData['body']), $this->convertHTMLToText($this->sessionData['body']),
$this->sessionData['attachments'], $this->sessionData['attachments'],
false, // date false, // date
$mail->getRaw()),true) $eml),true),
'app' => $app_name,
)),'_blank',$hook['popup']); )),'_blank',$hook['popup']);
} }
} }
} }
if(is_array($this->sessionData['attachments'])) { if(is_array($this->sessionData['attachments'])) {
foreach($this->sessionData['attachments'] as $value) { foreach($this->sessionData['attachments'] as $value) {

View File

@ -9,14 +9,14 @@
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id:$ * @version $Id:$
*/ */
/** /**
* Class cotains methods and functions * Class cotains methods and functions
* to be used to integrate mail's message into other applications * to be used to integrate mail's message into other applications
* *
*/ */
class mail_integration { class mail_integration {
/** /**
* Public functions * Public functions
* @var type * @var type
@ -24,7 +24,7 @@ class mail_integration {
var $public_functions = array( var $public_functions = array(
'integrate' => true 'integrate' => true
); );
/** /**
* Maximum number of line characters (-_+=~) allowed in a mail, to not stall the layout. * 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. * Longer lines / biger number of these chars are truncated to that max. number or chars.
@ -32,7 +32,7 @@ class mail_integration {
* @var int * @var int
*/ */
const MAX_LINE_CHARS = 40; const MAX_LINE_CHARS = 40;
/** /**
* Gets requested mail information and sets them as data link * Gets requested mail information and sets them as data link
* -Execute registered hook method from the requested app for integration * -Execute registered hook method from the requested app for integration
@ -50,34 +50,33 @@ class mail_integration {
* 'subject' => string * 'subject' => string
* ) * )
* *
* @param string $_app Integrated app name
* @param string $_to_emailAddress * @param string $_to_emailAddress
* @param string $_subject mail subject * @param string $_subject mail subject
* @param string $_body mail message * @param string $_body mail message
* @param array $_attachments attachments * @param array $_attachments attachments
* @param string $_date * @param string $_date
* @param string $_rawMail * @param string $_rawMail path to file with raw mail
* @throws egw_exception_assertion_failed * @throws egw_exception_assertion_failed
*/ */
public static function integrate ($_app='',$_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false,$_rawMail=null,$_icServerID=null) public static function integrate ($_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false,$_rawMail=null,$_icServerID=null)
{ {
// App name which is called for integration // App name which is called for integration
$app = !empty($_GET['app'])? $_GET['app']:$_app; $app = isset($GLOBALS['egw_info']['user']['apps'][$_GET['app']])? $_GET['app'] : null;
// Set the date // Set the date
if (!$_date) if (!$_date)
{ {
$time = time(); $time = time();
$_date = egw_time::server2user($time->now,'ts'); $_date = egw_time::server2user($time->now,'ts');
} }
// Integrate not yet saved mail // Integrate not yet saved mail
if (empty($_GET['rowid']) && $_to_emailAddress && $app) if (empty($_GET['rowid']) && $_to_emailAddress && $app)
{ {
$sessionLocation = 'mail'; $sessionLocation = 'mail';
$mailbox = base64_decode($_GET['mailbox']); $mailbox = base64_decode($_GET['mailbox']);
$GLOBALS['egw_info']['flags']['currentapp'] = $_app; $GLOBALS['egw_info']['flags']['currentapp'] = $app;
if (!($GLOBALS['egw_info']['user']['preferences'][$sessionLocation]['saveAsOptions']==='text_only')&&is_array($_attachments)) if (!($GLOBALS['egw_info']['user']['preferences'][$sessionLocation]['saveAsOptions']==='text_only')&&is_array($_attachments))
{ {
@ -85,7 +84,7 @@ class mail_integration {
if (!isset($_icServerID)) $_icServerID =& egw_cache::getSession($sessionLocation,'activeProfileID'); if (!isset($_icServerID)) $_icServerID =& egw_cache::getSession($sessionLocation,'activeProfileID');
$mo = mail_bo::getInstance(true,$_icServerID); $mo = mail_bo::getInstance(true,$_icServerID);
$mo->openConnection(); $mo->openConnection();
foreach ($_attachments as $attachment) foreach ($_attachments as $attachment)
{ {
if (trim(strtoupper($attachment['type'])) == 'MESSAGE/RFC822' && !empty($attachment['uid']) && !empty($attachment['folder'])) if (trim(strtoupper($attachment['type'])) == 'MESSAGE/RFC822' && !empty($attachment['uid']) && !empty($attachment['folder']))
@ -141,21 +140,16 @@ class mail_integration {
} }
// this one adds the mail itself (as message/rfc822 (.eml) file) to the app as additional attachment // this one adds the mail itself (as message/rfc822 (.eml) file) to the app as additional attachment
// this is done to have a simple archive functionality (ToDo: opening .eml in email module) // this is done to have a simple archive functionality (ToDo: opening .eml in email module)
if (is_resource($_rawMail) && $GLOBALS['egw_info']['user']['preferences'][$sessionLocation]['saveAsOptions']==='add_raw') if ($GLOBALS['egw_info']['user']['preferences'][$sessionLocation]['saveAsOptions']==='add_raw' &&
$_rawMail && file_exists($_rawMail))
{ {
$subject = mail_bo::adaptSubjectForImport($_subject); $subject = mail_bo::adaptSubjectForImport($_subject);
$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
$tmpfile = fopen($attachment_file,'w');
fseek($_rawMail, 0, SEEK_SET);
stream_copy_to_stream($_rawMail, $tmpfile);
fclose($tmpfile);
$size = filesize($attachment_file);
$attachments[] = array( $attachments[] = array(
'name' => trim($subject).'.eml', 'name' => trim($subject).'.eml',
'mimeType' => 'message/rfc822', 'mimeType' => 'message/rfc822',
'type' => 'message/rfc822', 'type' => 'message/rfc822',
'tmp_name' => $attachment_file, 'tmp_name' => $_rawMail,
'size' => $size, 'size' => filesize($_rawMail),
); );
} }
@ -175,7 +169,7 @@ class mail_integration {
'BCC'=>(!empty($_to_emailAddress['bcc'])?implode(',',$_to_emailAddress['bcc']):null), 'BCC'=>(!empty($_to_emailAddress['bcc'])?implode(',',$_to_emailAddress['bcc']):null),
'SUBJECT'=>$_subject, 'SUBJECT'=>$_subject,
'DATE'=>mail_bo::_strtotime($_date))).$body_decoded; 'DATE'=>mail_bo::_strtotime($_date))).$body_decoded;
$mailcontent = array( $mailcontent = array(
'mailaddress' => implode(',',$toaddr), 'mailaddress' => implode(',',$toaddr),
'subject' => $_subject, 'subject' => $_subject,
@ -196,14 +190,14 @@ class mail_integration {
$uid = $hA['msgUID']; $uid = $hA['msgUID'];
$mailbox = $hA['folder']; $mailbox = $hA['folder'];
$icServerID = $hA['profileID']; $icServerID = $hA['profileID'];
if ($uid && $mailbox) if ($uid && $mailbox)
{ {
if (!isset($icServerID)) $icServerID =& egw_cache::getSession($sessionLocation,'activeProfileID'); if (!isset($icServerID)) $icServerID =& egw_cache::getSession($sessionLocation,'activeProfileID');
$mo = mail_bo::getInstance(true,$icServerID); $mo = mail_bo::getInstance(true,$icServerID);
$mo->openConnection(); $mo->openConnection();
$mo->reopen($mailbox); $mo->reopen($mailbox);
// ToDo check $partid
$mailcontent = mail_bo::get_mailcontent($mo,$uid,$partid,$mailbox,false,true,(!($GLOBALS['egw_info']['user']['preferences'][$sessionLocation]['saveAsOptions']==='text_only'))); $mailcontent = mail_bo::get_mailcontent($mo,$uid,$partid,$mailbox,false,true,(!($GLOBALS['egw_info']['user']['preferences'][$sessionLocation]['saveAsOptions']==='text_only')));
// this one adds the mail itself (as message/rfc822 (.eml) file) to the app as additional attachment // this one adds the mail itself (as message/rfc822 (.eml) file) to the app as additional attachment
// this is done to have a simple archive functionality (ToDo: opening .eml in email module) // this is done to have a simple archive functionality (ToDo: opening .eml in email module)
@ -232,7 +226,7 @@ class mail_integration {
{ {
egw_framework::window_close(lang('No app for integration is registered!')); egw_framework::window_close(lang('No app for integration is registered!'));
} }
// Convert addresses to email and personal // Convert addresses to email and personal
$addresses = imap_rfc822_parse_adrlist($mailcontent['mailaddress'],''); $addresses = imap_rfc822_parse_adrlist($mailcontent['mailaddress'],'');
foreach ($addresses as $address) foreach ($addresses as $address)
@ -243,7 +237,7 @@ class mail_integration {
'name' => !empty($address->personal) ? $address->personal : $email 'name' => !empty($address->personal) ? $address->personal : $email
); );
} }
// shorten long (> self::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( $data_message = preg_replace_callback(
'/[-_+=~\.]{'.self::MAX_LINE_CHARS.',}/m', '/[-_+=~\.]{'.self::MAX_LINE_CHARS.',}/m',
@ -252,7 +246,7 @@ class mail_integration {
}, },
$mailcontent['message'] $mailcontent['message']
); );
// Get attachments ready for integration as link // Get attachments ready for integration as link
if (is_array($mailcontent['attachments'])) if (is_array($mailcontent['attachments']))
{ {
@ -266,11 +260,11 @@ class mail_integration {
); );
} }
} }
// Get the registered hook method of requested app for integration // Get the registered hook method of requested app for integration
$hook = $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 // Execute import mail with provided content
ExecMethod($hook['menuaction'],array ( ExecMethod($hook['menuaction'],array (
'addresses' => $data_addresses, 'addresses' => $data_addresses,