Some fixes on mail integration:

- Fix save as raw eml file and send it as attachment
- Fix mail_import in infolog,tracker and calendar does not include raw mail eml attachment as link
- Some IDE clean up for mail and tracker
This commit is contained in:
Hadi Nategh 2015-04-17 09:39:22 +00:00
parent 7d54d5b21c
commit aa7edce3b4
5 changed files with 62 additions and 50 deletions

View File

@ -2620,6 +2620,10 @@ class calendar_uiforms extends calendar_ui
{
egw_link::link('calendar',$event['link_to']['to_id'],egw_link::DATA_APPNAME, $attachment);
}
else if(is_readable($attachment['tmp_name']))
{
egw_link::link('calendar',$event['link_to']['to_id'],'file', $attachment);
}
}
}
}

View File

@ -297,7 +297,7 @@ class infolog_bo
* checks if there are customfields for typ $typ
*
* @param string $type
* @param boolean $links=false if true check only customfields containing links, default false = all custom fields
* @param boolean $links = false if true check only customfields containing links, default false = all custom fields
* @return boolean True if there are customfields for $typ, else False
*/
function has_customfields($type,$links=false)
@ -321,7 +321,7 @@ class infolog_bo
* @param int|array $info data or info_id of infolog entry to check
* @param int $required_rights EGW_ACL_{READ|EDIT|ADD|DELETE}
* @param int $other uid to check (if info==0) or 0 to check against $this->user
* @param int $user=null user whos rights to check, default current user
* @param int $user = null user whos rights to check, default current user
* @return boolean
*/
function check_access($info,$required_rights,$other=0,$user=null)
@ -413,8 +413,8 @@ class infolog_bo
* convert a link_id value into an info_from text
*
* @param array &$info infolog entry, key info_from gets set by this function
* @param string $not_app='' app to exclude
* @param string $not_id='' id to exclude
* @param string $not_app = '' app to exclude
* @param string $not_id = '' id to exclude
* @return boolean True if we have a linked item, False otherwise
*/
function link_id2from(&$info,$not_app='',$not_id='')
@ -482,8 +482,8 @@ class infolog_bo
* and $fromTZId is only used to qualify dates.
*
* @param array $values to modify
* @param string $fromTZId=null
* @param string $toTZId=false
* @param string $fromTZId = null
* @param string $toTZId = false
* TZID timezone name e.g. 'UTC'
* or NULL for timestamps in user-time
* or false for timestamps in server-time
@ -555,7 +555,7 @@ class infolog_bo
* convert a date from server to user-time
*
* @param int $ts timestamp in server-time
* @param string $date_format='ts' date-formats: 'ts'=timestamp, 'server'=timestamp in server-time, 'array'=array or string with date-format
* @param string $date_format = 'ts' date-formats: 'ts'=timestamp, 'server'=timestamp in server-time, 'array'=array or string with date-format
* @return mixed depending of $date_format
*/
function date2usertime($ts,$date_format='ts')
@ -569,11 +569,11 @@ class infolog_bo
* Read an infolog entry specified by $info_id
*
* @param int|array $info_id integer id or array with id's or array with column=>value pairs of the entry to read
* @param boolean $run_link_id2from=true should link_id2from run, default yes,
* @param boolean $run_link_id2from = true should link_id2from run, default yes,
* need to be set to false if called from link-title to prevent an infinit recursion
* @param string $date_format='ts' date-formats: 'ts'=timestamp, 'server'=timestamp in server-time,
* @param string $date_format = 'ts' date-formats: 'ts'=timestamp, 'server'=timestamp in server-time,
* 'array'=array or string with date-format
* @param boolean $ignore_acl=false if true, do NOT check access, default false
* @param boolean $ignore_acl = false if true, do NOT check access, default false
*
* @return array|boolean infolog entry, null if not found or false if no permission to read it
*/
@ -705,12 +705,12 @@ class infolog_bo
* checks and asures ACL
*
* @param array &$values values to write
* @param boolean $check_defaults=true check and set certain defaults
* @param boolean|int $touch_modified=true touch the modification date and sets the modifier's user-id, 2: only modifier
* @param boolean $user2server=true conversion between user- and server-time necessary
* @param boolean $skip_notification=false true = do NOT send notification, false (default) = send notifications
* @param boolean $throw_exception=false Throw an exception (if required fields are not set)
* @param string $purge_cfs=null null=dont, 'ical'=only iCal X-properties (cfs name starting with "#"), 'all'=all cfs
* @param boolean $check_defaults = true check and set certain defaults
* @param boolean|int $touch_modified = true touch the modification date and sets the modifier's user-id, 2: only modifier
* @param boolean $user2server = true conversion between user- and server-time necessary
* @param boolean $skip_notification = false true = do NOT send notification, false (default) = send notifications
* @param boolean $throw_exception = false Throw an exception (if required fields are not set)
* @param string $purge_cfs = null null=dont, 'ical'=only iCal X-properties (cfs name starting with "#"), 'all'=all cfs
*
* @return int|boolean info_id on a successfull write or false
*/
@ -1102,7 +1102,7 @@ class infolog_bo
/**
* Query ctag for infolog
*
* @param array $filter=array('filter'=>'own','info_type'=>'task')
* @param array $filter = array('filter'=>'own','info_type'=>'task')
* @return string
*/
public function getctag(array $filter=array('filter'=>'own','info_type'=>'task'))
@ -1202,6 +1202,10 @@ class infolog_bo
{
egw_link::link('infolog',$info['link_to']['to_id'],egw_link::DATA_APPNAME, $attachment);
}
else if(is_readable($attachment['tmp_name']))
{
egw_link::link('infolog',$info['link_to']['to_id'],'file', $attachment);
}
}
}
return $info;
@ -1285,8 +1289,8 @@ class infolog_bo
*
* @param int|array $id id of entry or entry array
* @param int $check EGW_ACL_READ for read and EGW_ACL_EDIT for write or delete access
* @param string $rel_path=null currently not used in InfoLog
* @param int $user=null for which user to check, default current user
* @param string $rel_path = null currently not used in InfoLog
* @param int $user = null for which user to check, default current user
* @return boolean true if access is granted or false otherwise
*/
function file_access($id,$check,$rel_path=null,$user=null)
@ -1430,7 +1434,7 @@ class infolog_bo
* currently used for ical/sif import
*
* @param array $catname_list names of the categories which should be found or added
* @param int $info_id=-1 match against existing infolog and expand the returned category ids
* @param int $info_id = -1 match against existing infolog and expand the returned category ids
* by the ones the user normally does not see due to category permissions - used to preserve categories
* @return array category ids (found, added and preserved categories)
*/
@ -1683,8 +1687,8 @@ class infolog_bo
*
* As status value can have different translations depending on type, we list all translations
*
* @param string $type=null
* @param array &$icons=null on return name of icons
* @param string $type = null
* @param array &$icons = null on return name of icons
* @return array value => (commaseparated) translations
*/
function get_status($type=null, array &$icons=null)
@ -1754,8 +1758,8 @@ class infolog_bo
* This expects timestamps to be in server-time.
*
* @param array $infoData the infolog data we try to find
* @param boolean $relax=false if asked to relax, we only match against some key fields
* @param string $tzid=null timezone, null => user time
* @param boolean $relax = false if asked to relax, we only match against some key fields
* @param string $tzid = null timezone, null => user time
*
* @return array of infolog_ids of matching entries
*/

View File

@ -3083,8 +3083,9 @@ class mail_compose
$this->convertHTMLToText($this->sessionData['body']),
$this->sessionData['attachments'],
false, // date
$eml),true),
'app' => $app_name,
$eml,
$_formData['serverID']),true),
'app' => $app_name
)),'_blank',$hook['popup']);
}
}

View File

@ -44,10 +44,12 @@ class mail_integration {
* 'attachments' => array (
* 'name' => string, // file name
* 'type' => string, // mime type
* 'egw_data'=> string), // hash md5 id of an stored attachment in session
* 'message' => string
* 'date' => string
* 'subject' => string
* 'egw_data'=> string, // hash md5 id of an stored attachment in session (attachment which is in IMAP server)
* // NOTE: the attachmet either have egw_data OR tmp_name (e.g. raw mail eml file stores in tmp)
* 'tmp_name' => string), // tmp dir path
* 'message' => string,
* 'date' => string,
* 'subject' => string,
* )
*
* @param string $_to_emailAddress
@ -56,6 +58,7 @@ class mail_integration {
* @param array $_attachments attachments
* @param string $_date
* @param string $_rawMail path to file with raw mail
* @param int $_icServerID mail profile id
* @throws egw_exception_assertion_failed
*/
public static function integrate ($_to_emailAddress=false,$_subject=false,$_body=false,$_attachments=false,$_date=false,$_rawMail=null,$_icServerID=null)
@ -150,6 +153,7 @@ class mail_integration {
'type' => 'message/rfc822',
'tmp_name' => $_rawMail,
'size' => filesize($_rawMail),
'add_raw' => true
);
}
@ -180,7 +184,7 @@ class mail_integration {
}
// Integrate already saved mail with ID
else if ($app)
else
{
// Initializing mail connection requirements
$hA = mail_ui::splitRowID($_GET['rowid']);
@ -197,16 +201,15 @@ class mail_integration {
$mo = mail_bo::getInstance(true,$icServerID);
$mo->openConnection();
$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,'',$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 is done to have a simple archive functionality (ToDo: opening .eml in email module)
if ($GLOBALS['egw_info']['user']['preferences'][$sessionLocation]['saveAsOptions']==='add_raw')
{
$message = $mo->getMessageRawBody($uid, $partid,$mailbox);
$headers = $mo->getMessageHeader($uid, $partid,true,false,$mailbox);
$message = $mo->getMessageRawBody($uid, '',$mailbox);
$headers = $mo->getMessageHeader($uid, '',true,false,$mailbox);
$subject = mail_bo::adaptSubjectForImport($headers['SUBJECT']);
$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."mail_integrate");
$tmpfile = fopen($attachment_file,'w');
fwrite($tmpfile,$message);
fclose($tmpfile);
@ -217,16 +220,13 @@ class mail_integration {
'type' => 'message/rfc822',
'tmp_name' => $attachment_file,
'size' => $size,
'add_raw' => true
);
}
$mailcontent['date'] = strtotime($mailcontent['headers']['DATE']);
}
}
else
{
egw_framework::window_close(lang('No app for integration is registered!'));
}
// Convert addresses to email and personal
$addresses = imap_rfc822_parse_adrlist($mailcontent['mailaddress'],'');
foreach ($addresses as $address)
@ -253,15 +253,20 @@ class mail_integration {
foreach($mailcontent['attachments'] as $key => $attachment)
{
$data_attachments[$key] = array(
'name' => $mailcontent['attachments'][$key]['filename'],
'name' => $mailcontent['attachments'][$key]['name'],
'type' => $mailcontent['attachments'][$key]['type'],
'egw_data' => egw_link::set_data($mailcontent['attachments'][$key]['mimeType'],'emailadmin_imapbase::getAttachmentAccount',
array($icServerID, $mailbox, $uid, $attachment['partID'], $is_winmail, true), true)
'size' => $mailcontent['attachments'][$key]['size'],
'tmp_name' => $mailcontent['attachments'][$key]['tmp_name']
);
if ($uid && !$mailcontent['attachments'][$key]['add_raw'])
{
$data_attachments[$key]['egw_data'] = egw_link::set_data($mailcontent['attachments'][$key]['mimeType'],
'emailadmin_imapbase::getAttachmentAccount',array($icServerID, $mailbox, $uid, $attachment['partID'], $is_winmail, true),true);
}
unset($mailcontent['attachments'][$key]['add_raw']);
}
}
// Get the registered hook method of requested app for integration
$hook = $GLOBALS['egw']->hooks->single(array('location' => 'mail_import'),$app);

View File

@ -125,12 +125,12 @@ class mail_ui
if ($_GET["resetConnection"])
{
unset($_GET["resetConnection"]);
if (mail_bo::$debug) error_log(__METHOD__.__LINE__.' Connection Reset triggered:'.$connectionReset.' for Profile with ID:'.self::$icServerID);
if (mail_bo::$debug) error_log(__METHOD__.__LINE__.' Connection Reset triggered: for Profile with ID:'.self::$icServerID);
emailadmin_imapbase::unsetCachedObjects(self::$icServerID);
}
try {
$this->mail_bo = mail_bo::getInstance(true,self::$icServerID,$_validate=true, $_oldImapServerObject=false, $_reuseCache=true);
$this->mail_bo = mail_bo::getInstance(true,self::$icServerID, true, false, true);
if (mail_bo::$debug) error_log(__METHOD__.__LINE__.' Fetched IC Server:'.self::$icServerID.'/'.$this->mail_bo->profileID.':'.function_backtrace());
//error_log(__METHOD__.__LINE__.array2string($this->mail_bo->icServer));
@ -3263,7 +3263,6 @@ class mail_ui
$file = $content['uploadForImport'];
}
$destination = $content['FOLDER'][0];
$rememberServerID = $icServerID = $this->mail_bo->profileID;
if (stripos($destination,self::$delimiter)!==false) list($icServerID,$destination) = explode(self::$delimiter,$destination,2);
if ($icServerID && $icServerID != $this->mail_bo->profileID)
@ -3486,7 +3485,6 @@ class mail_ui
$folder = $uidA['folder']; // all messages in one set are supposed to be within the same folder
$messageID = $uidA['msgUID'];
$icServerID = $uidA['profileID'];
$rememberServerID = $this->mail_bo->profileID;
if ($icServerID && $icServerID != $this->mail_bo->profileID)
{
//error_log(__METHOD__.__LINE__.' change Profile to ->'.$icServerID);
@ -4767,7 +4765,7 @@ class mail_ui
//error_log(__METHOD__.__LINE__.$uID);
if ($_copyOrMove=='move')
{
$messageListForRefresh[] = self::generateRowID($sourceProfileID, $folderName, $uID, $_prependApp=false);
$messageListForRefresh[] = self::generateRowID($sourceProfileID, $_folderName, $uID, $_prependApp=false);
}
}
}