Commit d1fb4e41 authored by Jan-Erik Revsbech's avatar Jan-Erik Revsbech
Browse files

Fixed a problem when using Postfix version 1. A check is made to see if...

Fixed a problem when using Postfix version 1. A check is made to see if Postfix version 1 is used as MTA.


git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@536 709f56b5-9817-0410-a4d7-c38de5d9e867
parent a6b52eec
2005-01-21 Jan-Erik Revsbech <jer@moccompany.com>
* Added a check to class t3lib_htmlmail to check if postfix version 1.XX is used. If this is the case the -f parameter is not used for call to mail(). This should fix the problem with mails not being sent when using Postfix as MTA..
2005-01-21 Kasper Skårhøj,,, <kasper@typo3.com>
* Added a new feature to force all UIDs in the "impexp" extension.
......
......@@ -205,7 +205,7 @@ class t3lib_htmlmail {
var $mediaList=""; // If set, this is a list of the media-files (index-keys to the array) that should be represented in the html-mail
var $http_password="";
var $http_username="";
var $postfix_version1=false;
// Internal
......@@ -245,14 +245,30 @@ class t3lib_htmlmail {
/**
* @return [type] ...
*/
function t3lib_htmlmail () {
if(!ini_get('safe_mode')) {
$res = Array();
@exec('/usr/sbin/postconf mail_version',$res);
if(!empty($res[0])) {
$temp = explode("=",$res[0]);
list($major,$minor,$micro) = explode(".",trim($temp[1]));
if($major == 1) {
$this->postfix_version1 = true;
}
}
}
}
/**
* @return [type] ...
*/
function start () {
// Sets the message id
$this->messageid = md5(microtime()).'@domain.tld';
$this->messageid = md5(microtime()).'@domain.tld';
}
/**
......@@ -486,7 +502,7 @@ class t3lib_htmlmail {
function constructMixed ($boundary) {
// Here (plain/HTML) is combined with the attachments
$this->add_message("--".$boundary);
// (plain/HTML) is added
// (plain/HTML) is added
if ($this->theParts["html"]["content"]) {
// HTML and plain
$newBoundary = $this->getBoundary();
......@@ -499,7 +515,7 @@ class t3lib_htmlmail {
$this->add_message('');
$this->add_message($this->getContent("plain"));
}
// attachments are added
// attachments are added
if (is_array($this->theParts["attach"])) {
reset($this->theParts["attach"]);
while(list(,$media)=each($this->theParts["attach"])) {
......@@ -525,7 +541,7 @@ class t3lib_htmlmail {
function constructHTML ($boundary) {
if (count($this->theParts["html"]["media"])) { // If media, then we know, the multipart/related content-type has been set before this function call...
$this->add_message("--".$boundary);
// HTML has media
// HTML has media
$newBoundary = $this->getBoundary();
$this->add_message("Content-Type: multipart/alternative;");
$this->add_message(' boundary="'.$newBoundary.'"');
......@@ -548,12 +564,12 @@ class t3lib_htmlmail {
function constructAlternative($boundary) {
// Here plain is combined with HTML
$this->add_message("--".$boundary);
// plain is added
// plain is added
$this->add_message($this->plain_text_header);
$this->add_message('');
$this->add_message($this->getContent("plain"));
$this->add_message("--".$boundary);
// html is added
// html is added
$this->add_message($this->html_text_header);
$this->add_message('');
$this->add_message($this->getContent("html"));
......@@ -569,7 +585,7 @@ class t3lib_htmlmail {
function constructHTML_media ($boundary) {
/* // Constructs the HTML-part of message if the HTML contains media
$this->add_message("--".$boundary);
// htmlcode is added
// htmlcode is added
$this->add_message($this->html_text_header);
$this->add_message('');
$this->add_message($this->getContent("html"));
......@@ -577,7 +593,7 @@ class t3lib_htmlmail {
OLD stuf...
*/
// media is added
// media is added
if (is_array($this->theParts["html"]["media"])) {
reset($this->theParts["html"]["media"]);
while(list($key,$media)=each($this->theParts["html"]["media"])) {
......@@ -595,70 +611,88 @@ class t3lib_htmlmail {
}
/**
* [Describe function...]
* Sends the mail by calling the mail() function in php. On Linux systems this will invoke the MTA
* defined in sys.ini (sendmail -t -i by default), on Windows a SMTP must be specified in the sys.ini.
* Most common MTA's on Linux has a Sendmail interface, including Postfix and Exim.
* For setting the return-path correctly, the parameter -f has to be added to the system call to sendmail.
* This obviously does not have any effect on Windows, but on Sendmail compliant systems this works. If safe mode
* is enabled, then extra parameters is not allowed, so a safe mode check is made before the mail() command is
* invoked. When using the -f parameter, some MTA's will put an X-AUTHENTICATION-WARING saying that
* the return path was modified manually with the -f flag. To disable this warning make sure that the user running
* Apache is in the /etc/mail/trusted-users table.
*
* POSTFIX: With postfix version below 2.0 there is a problem that the -f parameter can not be used in conjunction
* with -t. Postfix will give an error in the maillog:
*
* cannot handle command-line recipients with -t
*
* This problem is solved by making a call to /usr/sbin/postconf mail_version and checking if the postfix is version
* 1.XX.YY If this is the case, the -f parameter is not used in the call to mail().
*
* This whole problem of return-path turns out to be quite tricky. If you have a solution that works better, on all
* standard MTA's then we are very open for suggestions.
*
* With time this function should be made such that several ways of sending the mail is possible (local MTA, smtp other).
*
*
* @return [type] ...
*/
function sendTheMail () {
// Sends the mail.
// Requires the recipient, message and headers to be set.
#debug(array($this->recipient,$this->subject,$this->message,$this->headers));
// Sends the mail, requires the recipient, message and headers to be set.
if (trim($this->recipient) && trim($this->message)) { // && trim($this->headers)
$returnPath = (strlen($this->returnPath)>0)?"-f".$this->returnPath:'';
//On windows the -f flag is not used (specific for sendmail and postfix), but instead the php.ini parameter sendmail_from is used.
if($this->returnPath) {
ini_set(sendmail_from, $this->returnPath);
}
//If safe mode is on, the fifth parameter to mail is not allowed, so the fix wont work on unix with safe_mode=On
if(!ini_get('safe_mode')) {
mail( $this->recipient,
$this->subject,
$this->message,
$this->headers,
$returnPath);
$returnPath = (strlen($this->returnPath)>0)?"-f".$this->returnPath:'';
//On windows the -f flag is not used (specific for Sendmail and Postfix), but instead the php.ini parameter sendmail_from is used.
if($this->returnPath) {
ini_set(sendmail_from, $this->returnPath);
}
else {
mail( $this->recipient,
$this->subject,
$this->message,
$this->headers);
//If safe mode is on, the fifth parameter to mail is not allowed, so the fix wont work on unix with safe_mode=On
if(!ini_get('safe_mode') && !$this->postfix_version1) {
mail($this->recipient,
$this->subject,
$this->message,
$this->headers,
$returnPath);
} else {
mail($this->recipient,
$this->subject,
$this->message,
$this->headers);
}
// Sending copy:
if ($this->recipient_copy) {
if(!ini_get('safe_mode')) {
mail( $this->recipient_copy,
$this->subject,
$this->message,
$this->headers,
$returnPath);
}
else {
mail( $this->recipient_copy,
$this->subject,
$this->message,
$this->headers );
}
if(!ini_get('safe_mode') && !$this->postfix_version1) {
mail( $this->recipient_copy,
$this->subject,
$this->message,
$this->headers,
$returnPath);
} else {
mail( $this->recipient_copy,
$this->subject,
$this->message,
$this->headers );
}
}
// Auto response
if ($this->auto_respond_msg) {
$theParts = explode("/",$this->auto_respond_msg,2);
$theParts = explode('/',$this->auto_respond_msg,2);
$theParts[1] = str_replace("/",chr(10),$theParts[1]);
if(!ini_get('safe_mode')) {
mail( $this->from_email,
$theParts[0],
$theParts[1],
"From: ".$this->recipient,
$returnPath);
if(!ini_get('safe_mode') && !$this->postfix_version1) {
mail( $this->from_email,
$theParts[0],
$theParts[1],
"From: ".$this->recipient,
$returnPath);
} else {
mail( $this->from_email,
$theParts[0],
$theParts[1],
"From: ".$this->recipient);
}
else {
mail( $this->from_email,
$theParts[0],
$theParts[1],
"From: ".$this->recipient);
}
}
if($this->returnPath) {
ini_restore(sendmail_from);
ini_restore(sendmail_from);
}
return true;
} else {return false;}
......@@ -704,7 +738,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function add_header ($header) {
// Adds a header to the mail. Use this AFTER the setHeaders()-function
// Adds a header to the mail. Use this AFTER the setHeaders()-function
$this->headers.=$header."\n";
}
......@@ -715,7 +749,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function add_message ($string) {
// Adds a line of text to the mail-body. Is normally use internally
// Adds a line of text to the mail-body. Is normally use internally
$this->message.=$string."\n";
}
......@@ -763,7 +797,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function fetchHTML($file) {
// Fetches the HTML-content from either url og local serverfile
// Fetches the HTML-content from either url og local serverfile
$this->theParts["html"]["content"] = $this->getURL($file); // Fetches the content of the page
if ($this->theParts["html"]["content"]) {
$addr = $this->extParseUrl($file);
......@@ -781,7 +815,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function fetchHTMLMedia() {
// Fetches the mediafiles which are found by extractMediaLinks()
// Fetches the mediafiles which are found by extractMediaLinks()
if (is_array($this->theParts["html"]["media"])) {
reset ($this->theParts["html"]["media"]);
if (count($this->theParts["html"]["media"]) > 0) {
......@@ -878,7 +912,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function extractHyperLinks() {
// extracts all hyper-links from $this->theParts["html"]["content"]
// extracts all hyper-links from $this->theParts["html"]["content"]
$html_code = $this->theParts["html"]["content"];
$attribRegex = $this->tag_regex(Array("a","form","area"));
$codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
......@@ -927,7 +961,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function extractFramesInfo() {
// extracts all media-links from $this->theParts["html"]["content"]
// extracts all media-links from $this->theParts["html"]["content"]
$html_code = $this->theParts["html"]["content"];
if (strpos(" ".$html_code,"<frame ")) {
$attribRegex = $this->tag_regex("frame");
......@@ -953,8 +987,8 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function substMediaNamesInHTML($absolute) {
// This substitutes the media-references in $this->theParts["html"]["content"]
// If $absolute is true, then the refs are substituted with http:// ref's indstead of Content-ID's (cid).
// This substitutes the media-references in $this->theParts["html"]["content"]
// If $absolute is true, then the refs are substituted with http:// ref's indstead of Content-ID's (cid).
if (is_array($this->theParts["html"]["media"])) {
reset ($this->theParts["html"]["media"]);
while (list($key,$val) = each ($this->theParts["html"]["media"])) {
......@@ -980,7 +1014,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function substHREFsInHTML() {
// This substitutes the hrefs in $this->theParts["html"]["content"]
// This substitutes the hrefs in $this->theParts["html"]["content"]
if (is_array($this->theParts["html"]["hrefs"])) {
reset ($this->theParts["html"]["hrefs"]);
while (list($key,$val) = each ($this->theParts["html"]["hrefs"])) {
......@@ -1008,7 +1042,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function substHTTPurlsInPlainText($content) {
// This substitutes the http:// urls in plain text with links
// This substitutes the http:// urls in plain text with links
if ($this->jumperURL_prefix) {
$textpieces = explode("http://", $content);
$pieces = count($textpieces);
......@@ -1048,7 +1082,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function fixRollOvers() {
// JavaScript rollOvers cannot support graphics inside of mail. If these exists we must let them refer to the absolute url. By the way: Roll-overs seems to work only on some mail-readers and so far I've seen it work on Netscape 4 message-center (but not 4.5!!)
// JavaScript rollOvers cannot support graphics inside of mail. If these exists we must let them refer to the absolute url. By the way: Roll-overs seems to work only on some mail-readers and so far I've seen it work on Netscape 4 message-center (but not 4.5!!)
$theNewContent = "";
$theSplit = explode(".src",$this->theParts["html"]["content"]);
if (count($theSplit)>1) {
......@@ -1095,7 +1129,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function makeBase64($inputstr) {
// Returns base64-encoded content, which is broken every 76 character
// Returns base64-encoded content, which is broken every 76 character
return chunk_split(base64_encode($inputstr));
}
......@@ -1106,7 +1140,7 @@ class t3lib_htmlmail {
* @return [type] ...
*/
function getExtendedURL($url) {
// reads the URL or file and determines the Content-type by either guessing or opening a connection to the host
// reads the URL or file and determines the Content-type by either guessing or opening a connection to the host
$res["content"] = $this->getURL($url);
if (!$res["content"]) {return false;}
$pathInfo = parse_url($url);
......@@ -1300,7 +1334,7 @@ class t3lib_htmlmail {
$tag = ltrim(eregi_replace ("^<[^ ]*","",trim($tag)));
$tagLen = strlen($tag);
$safetyCounter = 100;
// Find attribute
// Find attribute
while ($tag) {
$value = "";
$reg = split("[[:space:]=>]",$tag,2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment