fix activesync attachment issue reported by randy; fix issue regarding the mail action on calendar entries; some cleanup

This commit is contained in:
Klaus Leithoff 2014-03-21 10:37:09 +00:00
parent 9423598d14
commit 70d2a9f479
3 changed files with 30 additions and 28 deletions

View File

@ -370,10 +370,13 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
//die('Mail not or mis-configured!'); //die('Mail not or mis-configured!');
} }
else else
{
if (!empty($waitOnFailure[self::$profileID][$this->backend->_devid]))
{ {
$waitOnFailure[self::$profileID][$this->backend->_devid] = array(); $waitOnFailure[self::$profileID][$this->backend->_devid] = array();
egw_cache::setCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($GLOBALS['egw_info']['user']['account_id']),$waitOnFailure,$expiration=60*60*2); egw_cache::setCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($GLOBALS['egw_info']['user']['account_id']),$waitOnFailure,$expiration=60*60*2);
} }
}
$this->_wasteID = $this->mail->getTrashFolder(false); $this->_wasteID = $this->mail->getTrashFolder(false);
//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID); //error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
$this->_sentID = $this->mail->getSentFolder(false); $this->_sentID = $this->mail->getSentFolder(false);
@ -797,8 +800,6 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
// start handle Attachments // start handle Attachments
// $_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName='' // $_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName=''
$attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true , $folder); $attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true , $folder);
$attachments = $this->mail->getMessageAttachments($uid);
$attachmentNames = false; $attachmentNames = false;
if (is_array($attachments) && count($attachments)>0) if (is_array($attachments) && count($attachments)>0)
{ {
@ -817,7 +818,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
break; break;
default: default:
$attachmentData = ''; $attachmentData = '';
$attachmentData = $this->mail->getAttachment($uid, $attachment['partID']); $attachmentData = $this->mail->getAttachment($uid, $attachment['partID'],0,false);
$mailObject->AddStringAttachment($attachmentData['attachment'], $mailObject->EncodeHeader($attachment['name']), 'base64', $attachment['mimeType']); $mailObject->AddStringAttachment($attachmentData['attachment'], $mailObject->EncodeHeader($attachment['name']), 'base64', $attachment['mimeType']);
break; break;
} }
@ -1227,6 +1228,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
if (is_array($attachments) && count($attachments)>0) if (is_array($attachments) && count($attachments)>0)
{ {
debugLog(__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$id.' found:'.count($attachments)); debugLog(__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$id.' found:'.count($attachments));
//error_log(__METHOD__.__LINE__.array2string($attachments));
foreach((array)$attachments as $key => $attachment) foreach((array)$attachments as $key => $attachment)
{ {
if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment)); if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
@ -1243,7 +1245,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
break; break;
default: default:
$attachmentData = ''; $attachmentData = '';
$attachmentData = $this->mail->getAttachment($id, $attachment['partID']); $attachmentData = $this->mail->getAttachment($id, $attachment['partID'],0,false);
$mailObject->AddStringAttachment($attachmentData['attachment'], $mailObject->EncodeHeader($attachment['name']), 'base64', $attachment['mimeType']); $mailObject->AddStringAttachment($attachmentData['attachment'], $mailObject->EncodeHeader($attachment['name']), 'base64', $attachment['mimeType']);
break; break;
} }
@ -1354,11 +1356,12 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
$output->contentclass="urn:content-classes:message"; $output->contentclass="urn:content-classes:message";
// end AS12 Stuff // end AS12 Stuff
// start handle Attachments (include text/calendar multiplar alternative) // start handle Attachments (include text/calendar multipart alternative)
$attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true); $attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true, true, $_folderName);
if (is_array($attachments) && count($attachments)>0) if (is_array($attachments) && count($attachments)>0)
{ {
debugLog(__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments)); debugLog(__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
//error_log(__METHOD__.__LINE__.array2string($attachments));
foreach ($attachments as $key => $attach) foreach ($attachments as $key => $attach)
{ {
if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach)); if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
@ -1366,7 +1369,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
// pass meeting requests to calendar plugin // pass meeting requests to calendar plugin
if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' && if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
isset($GLOBALS['egw_info']['user']['apps']['calendar']) && isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
($attachment = $this->mail->getAttachment($id, $attach['partID'])) && ($attachment = $this->mail->getAttachment($id, $attach['partID'],0,false)) &&
($output->meetingrequest = calendar_activesync::meetingRequest($attachment['attachment']))) ($output->meetingrequest = calendar_activesync::meetingRequest($attachment['attachment'])))
{ {
$output->messageclass = "IPM.Schedule.Meeting.Request"; $output->messageclass = "IPM.Schedule.Meeting.Request";
@ -1437,7 +1440,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach) foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach)
{ {
if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' && if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
($attachment = $this->mail->getAttachment($requestid, $attach['partID']))) ($attachment = $this->mail->getAttachment($requestid, $attach['partID'],0,false)))
{ {
debugLog(__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')"); debugLog(__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
@ -1466,8 +1469,8 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
* @return true, prints the content of the attachment * @return true, prints the content of the attachment
*/ */
function GetAttachmentData($fid,$attname) { function GetAttachmentData($fid,$attname) {
debugLog("getAttachmentData: (attname: '$attname')"); debugLog("getAttachmentData: $fid (attname: '$attname')");
//error_log(__METHOD__.__LINE__." Fid: $fid (attname: '$attname')");
list($folderid, $id, $part) = explode(":", $attname); list($folderid, $id, $part) = explode(":", $attname);
$this->splitID($folderid, $account, $folder); $this->splitID($folderid, $account, $folder);
@ -1475,7 +1478,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
if (!isset($this->mail)) $this->mail = mail_bo::getInstance(false,self::$profileID,true,false,true); if (!isset($this->mail)) $this->mail = mail_bo::getInstance(false,self::$profileID,true,false,true);
$this->mail->reopen($folder); $this->mail->reopen($folder);
$attachment = $this->mail->getAttachment($id,$part); $attachment = $this->mail->getAttachment($id,$part,0,false);
print $attachment['attachment']; print $attachment['attachment'];
unset($attachment); unset($attachment);
return true; return true;
@ -1501,7 +1504,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
if (!isset($this->mail)) $this->mail = mail_bo::getInstance(false, self::$profileID,true,false,true); if (!isset($this->mail)) $this->mail = mail_bo::getInstance(false, self::$profileID,true,false,true);
$this->mail->reopen($folder); $this->mail->reopen($folder);
$att = $this->mail->getAttachment($id,$part); $att = $this->mail->getAttachment($id,$part,0,false);
$attachment = new SyncAirSyncBaseFileAttachment(); $attachment = new SyncAirSyncBaseFileAttachment();
/* /*
debugLog(__METHOD__.__LINE__.array2string($att)); debugLog(__METHOD__.__LINE__.array2string($att));

View File

@ -239,7 +239,7 @@ class mail_compose
function compose(array $_content=null,$msg=null, $_focusElement='to',$suppressSigOnTop=false, $isReply=false) function compose(array $_content=null,$msg=null, $_focusElement='to',$suppressSigOnTop=false, $isReply=false)
{ {
//lang('compose'),lang('from') // needed to be found by translationtools //lang('compose'),lang('from') // needed to be found by translationtools
//error_log(__METHOD__.__LINE__.array2string($_REQUEST)); //error_log(__METHOD__.__LINE__.array2string($_REQUEST).function_backtrace());
//error_log(__METHOD__.__LINE__.array2string($_content).function_backtrace()); //error_log(__METHOD__.__LINE__.array2string($_content).function_backtrace());
$_contentHasSigID = array_key_exists('signatureid',(array)$_content); $_contentHasSigID = array_key_exists('signatureid',(array)$_content);
$_contentHasMimeType = array_key_exists('mimeType',(array)$_content); $_contentHasMimeType = array_key_exists('mimeType',(array)$_content);
@ -893,7 +893,7 @@ class mail_compose
{ {
foreach(array_keys($content) as $k) foreach(array_keys($content) as $k)
{ {
if (in_array($k,array('to','cc','bcc','subject','body','mimeType'))) $remember[$k] = $sessionData[$k]; if (in_array($k,array('to','cc','bcc','subject','body','mimeType'))&&isset($this->sessionData[$k])) $remember[$k] = $this->sessionData[$k];
} }
} }
if(!empty($remember)) $content = array_merge($content,$remember); if(!empty($remember)) $content = array_merge($content,$remember);
@ -1759,6 +1759,8 @@ class mail_compose
*/ */
function addAttachment($_formData,&$_content,$eliminateDoubleAttachments=false) function addAttachment($_formData,&$_content,$eliminateDoubleAttachments=false)
{ {
//error_log(__METHOD__.__LINE__.' Formdata:'.array2string($_formData).' Content:'.array2string($_content));
$attachfailed = false; $attachfailed = false;
// to guard against exploits the file must be either uploaded or be in the temp_dir // to guard against exploits the file must be either uploaded or be in the temp_dir
// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.) // check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
@ -1771,6 +1773,7 @@ class mail_compose
$attachfailed = true; $attachfailed = true;
$alert_msg = $e->getMessage(); $alert_msg = $e->getMessage();
} }
//error_log(__METHOD__.__LINE__.array2string($tmpFileName));
if ($eliminateDoubleAttachments == true) if ($eliminateDoubleAttachments == true)
foreach ((array)$_content['attachments'] as $k =>$attach) foreach ((array)$_content['attachments'] as $k =>$attach)
@ -1787,10 +1790,10 @@ class mail_compose
'size' => $_formData['size'] 'size' => $_formData['size']
); );
// trying different ID-ing Method, as getRandomString seems to produce non Random String on certain systems. // trying different ID-ing Method, as getRandomString seems to produce non Random String on certain systems.
$attachmentID = md5(time().serialize($buffer)); //$attachmentID = md5(time().serialize($buffer));
//error_log(__METHOD__." add Attachment with ID:".$attachmentID." (md5 of serialized array)"); //error_log(__METHOD__." add Attachment with ID:".$attachmentID." (md5 of serialized array)");
if (!is_array($_content['attachments'])) $_content['attachments']=array(); if (!is_array($_content['attachments'])) $_content['attachments']=array();
$_content['attachments'][$attachmentID] = $buffer; $_content['attachments'][] = $buffer;
unset($buffer); unset($buffer);
} }
else else

View File

@ -654,6 +654,7 @@ class mail_ui
if ($preferences['prefcontroltestconnection'] == 'reset') exit; if ($preferences['prefcontroltestconnection'] == 'reset') exit;
echo "<hr /><h3 style='color:red'>".lang('IMAP Server')."</h3>"; echo "<hr /><h3 style='color:red'>".lang('IMAP Server')."</h3>";
$this->mail_bo->reopen('INBOX'); $this->mail_bo->reopen('INBOX');
/* /*
unset($imapServer->_connectionErrorObject); unset($imapServer->_connectionErrorObject);
@ -689,11 +690,6 @@ class mail_ui
_debug_array($eO->message); _debug_array($eO->message);
$lE = true; $lE = true;
} }
$isError = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerIMAP_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*5);
if ($isError[$icServerID]) {
_debug_array($isError[$icServerID]);
$lE = true;
}
_debug_array(($lE?'':lang('Successfully connected'))); _debug_array(($lE?'':lang('Successfully connected')));
$suF = $this->mail_bo->getSpecialUseFolders(); $suF = $this->mail_bo->getSpecialUseFolders();