Skip to content

Commit

Permalink
Fix: Fixed a very old bug making file attachment fails with some emai…
Browse files Browse the repository at this point in the history
…ls readers when using "mail php function".
  • Loading branch information
eldy committed Oct 9, 2010
1 parent bcb9b8d commit 0498c62
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 61 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -43,6 +43,9 @@ For users:
- Fix: Database name can contains "-" characters.
- Fix: In coloring negative amounts.
- Fix: Date input use date format of user and not dd/mm/yyyy format.
- Fix: Fixed a very old bug making file attachment fails with some emails
readers when using "mail php function".


For translators:
- New: Update and complete slovenian language sl_SL.
Expand Down
126 changes: 65 additions & 61 deletions htdocs/lib/CMailFile.class.php
Expand Up @@ -475,7 +475,8 @@ function _encode_file($sourcefile)


/**
* Ecrit le mail dans un fichier. Utilisation pour le debuggage.
* Write content of a SMTP request into a dump file (mode = all)
* Used for debugging.
*/
function dump_mail()
{
Expand All @@ -502,8 +503,64 @@ function dump_mail()
}
}


/**
* Correct an uncomplete html string
*
* @param $msg
* @return
*/
function checkIfHTML($msg)
{
if (!preg_match('/^[\s\t]*<html/i',$msg))
{
$out = "<html><head><title></title>";
if (!empty($this->styleCSS)) $out.= $this->styleCSS;
$out.= "</head><body";
if (!empty($this->bodyCSS)) $out.= $this->bodyCSS;
$out.= ">";
$out.= $msg;
$out.= "</body></html>";
}
else
{
$out = $msg;
}

return $out;
}

/**
* Build a css style (mode = all)
*
* @return css
*/
function buildCSS()
{
if (! empty($this->css))
{
// Style CSS
$this->styleCSS = '<style type="text/css">';
$this->styleCSS.= 'body {';

if ($this->css['bgcolor'])
{
$this->styleCSS.= ' background-color: '.$this->css['bgcolor'].';';
$this->bodyCSS.= ' BGCOLOR="'.$this->css['bgcolor'].'"';
}
if ($this->css['bgimage'])
{
// TODO recuperer cid
$this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
}
$this->styleCSS.= '}';
$this->styleCSS.= '</style>';
}
}


/**
* Create SMTP headers
* Create SMTP headers (mode = 'mail')
*
* @return smtp headers
*/
Expand Down Expand Up @@ -583,12 +640,12 @@ function write_body($msgtext)
if ($this->msgishtml)
{
$out.= "--" . $this->mime_boundary . $this->eol;
$out.= "Content-Type: text/html; charset=\"".$conf->file->character_set_client."\"".$this->eol;
$out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
}
else
{
$out.= "--" . $this->mime_boundary . $this->eol;
$out.= "Content-Type: text/plain; charset=\"".$conf->file->character_set_client."\"".$this->eol;
$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
}
$out.= $this->eol;

Expand All @@ -605,67 +662,14 @@ function write_body($msgtext)
// Make RFC821 Compliant, replace bare linefeeds
$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent );

$strContent = rtrim(wordwrap($strContent));
//$strContent = rtrim(wordwrap($strContent));
$strContent = rtrim(chunk_split($strContent));

$out.=$strContent.$this->eol;

return $out;
}

/**
* Correct an uncomplete html string
*
* @param $msg
* @return
*/
function checkIfHTML($msg)
{
if (!preg_match('/^[\s\t]*<html/i',$msg))
{
$out = "<html><head><title></title>";
if (!empty($this->styleCSS)) $out.= $this->styleCSS;
$out.= "</head><body";
if (!empty($this->bodyCSS)) $out.= $this->bodyCSS;
$out.= ">";
$out.= $msg;
$out.= "</body></html>";
}
else
{
$out = $msg;
}

return $out;
}

/**
* Build a css style
*
* @return css
*/
function buildCSS()
{
if (! empty($this->css))
{
// Style CSS
$this->styleCSS = '<style type="text/css">';
$this->styleCSS.= 'body {';

if ($this->css['bgcolor'])
{
$this->styleCSS.= ' background-color: '.$this->css['bgcolor'].';';
$this->bodyCSS.= ' BGCOLOR="'.$this->css['bgcolor'].'"';
}
if ($this->css['bgimage'])
{
// TODO recuperer cid
$this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
}
$this->styleCSS.= '}';
$this->styleCSS.= '</style>';
}
}

/**
* Permet d'attacher un fichier (mode = 'mail')
*
Expand All @@ -691,10 +695,10 @@ function write_files($filename_list,$mimetype_list,$mimefilename_list)
if (! $mimetype_list[$i]) { $mimetype_list[$i] = "application/octet-stream"; }

$out.= "--" . $this->mime_boundary . $this->eol;
$out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
$out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol;
$out.= "Content-Transfer-Encoding: base64".$this->eol;
$out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
$out.= "Content-Description: \""."File Attachment"."\"".$this->eol;
$out.= "Content-Description: File Attachment".$this->eol;
$out.= $this->eol;
$out.= $encoded;
$out.= $this->eol;
Expand Down

0 comments on commit 0498c62

Please sign in to comment.