fix problem with empty/faulty attachments when saving to infolog on sending when starting from a drafted message

This commit is contained in:
Klaus Leithoff 2015-09-11 13:45:45 +00:00
parent 342b717a04
commit a93187ec74
2 changed files with 35 additions and 7 deletions

View File

@ -1345,9 +1345,9 @@ class mail_compose
switch($from)
{
case 'composefromdraft':
$content['mode'] = 'composefromdraft';
case 'composeasnew':
$content = $this->getDraftData($icServer, $folder, $msgUID, $part_id);
if ($from =='composefromdraft') $content['mode'] = 'composefromdraft';
$content['processedmail_id'] = $mail_id;
$_focusElement = 'body';
@ -3015,7 +3015,14 @@ class mail_compose
{
try
{
$mail_bo->deleteMessages($lastDrafted['uid'],$lastDrafted['folder'],'remove_immediately');
if ($this->sessionData['lastDrafted'] != $this->sessionData['uid'] || !($_formData['mode']=='composefromdraft' &&
($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on' )&&$this->sessionData['attachments']))
{
//error_log(__METHOD__.__LINE__."#".$lastDrafted['uid'].'#'.$lastDrafted['folder'].array2string($_formData));
//error_log(__METHOD__.__LINE__."#".array2string($_formData));
//error_log(__METHOD__.__LINE__."#".array2string($this->sessionData));
$mail_bo->deleteMessages($lastDrafted['uid'],$lastDrafted['folder'],'remove_immediately');
}
}
catch (egw_exception $e)
{
@ -3035,10 +3042,14 @@ class mail_compose
// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
if ($mail_bo->isDraftFolder($this->sessionData['messageFolder']) && !$mail_bo->isTemplateFolder($this->sessionData['messageFolder']))
{
//error_log(__METHOD__.__LINE__."#".$this->sessionData['uid'].'#'.$this->sessionData['messageFolder']);
try // message may be deleted already, as it maybe done by autosave
{
if ($_formData['mode']=='composefromdraft') $mail_bo->deleteMessages(array($this->sessionData['uid']),$this->sessionData['messageFolder']);
if ($_formData['mode']=='composefromdraft' &&
!(($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on' || $_formData['to_calendar'] == 'on') && $this->sessionData['attachments']))
{
//error_log(__METHOD__.__LINE__."#".$this->sessionData['uid'].'#'.$this->sessionData['messageFolder']);
$mail_bo->deleteMessages(array($this->sessionData['uid']),$this->sessionData['messageFolder']);
}
}
catch (egw_exception $e)
{

View File

@ -77,7 +77,7 @@ class mail_integration {
$_date = egw_time::server2user($time->now,'ts');
}
$GLOBALS['egw_info']['flags']['currentapp'] = $app;
//error_log(__METHOD__.__LINE__.': RowID:'.$_GET['rowid'].': emailAddress:'. array2string($_to_emailAddress).' && '.$app);
// Integrate not yet saved mail
if (empty($_GET['rowid']) && $_to_emailAddress && $app)
{
@ -90,9 +90,10 @@ class mail_integration {
if (!isset($_icServerID)) $_icServerID =& egw_cache::getSession($sessionLocation,'activeProfileID');
$mo = mail_bo::getInstance(true,$_icServerID);
$mo->openConnection();
$messageUID = $messagePartId = $messageFolder = null;
foreach ($_attachments as $attachment)
{
//error_log(__METHOD__.__LINE__.array2string($attachment));
if (trim(strtoupper($attachment['type'])) == 'MESSAGE/RFC822' && !empty($attachment['uid']) && !empty($attachment['folder']))
{
$mo->reopen(($attachment['folder']?$attachment['folder']:$mailbox));
@ -120,8 +121,11 @@ class mail_integration {
if (!empty($attachment['folder']))
{
$is_winmail = $_GET['is_winmail'] ? $_GET['is_winmail'] : 0;
$messageFolder = $attachment['folder'];
$messageUid = $attachment['uid'];
$messagePartId = $attachment['partID'];
$mo->reopen($attachment['folder']);
$attachmentData = $mo->getAttachment($attachment['uid'],$attachment['partID'],$is_winmail);
$attachmentData = $mo->getAttachment($attachment['uid'],$attachment['partID'],$is_winmail,false,false,$attachment['folder']);
$attachment['file'] =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
$tmpfile = fopen($attachment['file'],'w');
fwrite($tmpfile,$attachmentData['attachment']);
@ -142,6 +146,19 @@ class mail_integration {
);
}
}
if ($messageFolder && $messageUid && $messagePartId && $mo->isDraftFolder($messageFolder) && !$mo->isTemplateFolder($messageFolder))
{
//error_log(__METHOD__.__LINE__."#".$messageUid.'#'.$messageFolder);
try // message may be deleted already, as it maybe done by autosave
{
$mo->deleteMessages(array($messageUid),$messageFolder);
}
catch (egw_exception $e)
{
//error_log(__METHOD__.__LINE__." ". str_replace('"',"'",$e->getMessage()));
unset($e);
}
}
$mo->closeConnection();
}
// this one adds the mail itself (as message/rfc822 (.eml) file) to the app as additional attachment