* Fix bugs #3326 and #3392: problems with php_uname()
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_htmlmail.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * HTML mail class
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 193: class t3lib_htmlmail
40 * 261: function t3lib_htmlmail ()
41 * 268: function start ()
42 * 305: function useQuotedPrintable()
43 * 315: function useBase64()
44 * 326: function use8Bit()
45 * 338: function encodeMsg($content)
46 * 348: function addPlain ($content)
47 * 360: function addAttachment($file)
48 * 378: function addHTML ($file)
49 * 401: function extractHtmlInit($html,$url)
50 * 412: function send($recipient)
51 *
52 * SECTION: Main functions
53 * 441: function setHeaders()
54 * 500: function setRecipient ($recip)
55 * 518: function getHTMLContentType()
56 * 527: function setContent()
57 * 554: function constructMixed ($boundary)
58 * 593: function constructHTML ($boundary)
59 * 617: function constructAlternative($boundary)
60 * 638: function constructHTML_media ($boundary)
61 * 691: function sendTheMail ()
62 * 757: function getBoundary()
63 * 769: function setPlain ($content)
64 * 780: function setHtml ($content)
65 * 791: function add_header($header)
66 * 812: function add_message($string)
67 * 823: function getContent($type)
68 * 832: function preview()
69 *
70 * SECTION: Functions for acquiring attachments, HTML, analyzing and so on **
71 * 860: function fetchHTML($file)
72 * 878: function fetchHTMLMedia()
73 * 899: function extractMediaLinks()
74 * 976: function extractHyperLinks()
75 * 1025: function extractFramesInfo()
76 * 1051: function substMediaNamesInHTML($absolute)
77 * 1078: function substHREFsInHTML()
78 * 1106: function substHTTPurlsInPlainText($content)
79 * 1142: function fixRollOvers()
80 *
81 * SECTION: File and URL-functions
82 * 1189: function makeBase64($inputstr)
83 * 1200: function getExtendedURL($url)
84 * 1222: function addUserPass($url)
85 * 1238: function getURL($url)
86 * 1250: function getStrippedURL($url)
87 * 1271: function getMimeType($url)
88 * 1300: function absRef($ref)
89 * 1320: function split_fileref($fileref)
90 * 1347: function extParseUrl($path)
91 * 1362: function tag_regex($tagArray)
92 * 1384: function get_tag_attributes($tag)
93 * 1426: function quoted_printable($string)
94 * 1437: function convertName($name)
95 *
96 * TOTAL FUNCTIONS: 49
97 * (This index is automatically created/updated by the extension "extdeveval")
98 *
99 */
100
101
102
103
104
105
106
107
108
109 /**
110 * NOTES on MIME mail structures:
111 *
112 * Plain + HTML
113 * multipart/alternative (text, html)
114 * multipart/alternative (text, html)
115 *
116 * Plain + HTML + image
117 * multipart/related (m/a, cids)
118 * multipart/alternative (text, html)
119 *
120 * multipart/related (m/a, cids)
121 * multipart/alternative (text, html)
122 *
123 * plain + attachment
124 * multipart/mixed
125 *
126 * HTML + Attachment:
127 * multipart/mixed (text/html , attachments)
128 *
129 * Plain + HTML + Attachments:
130 * multipart/mixed (m/a, attachments)
131 * multipart/alternative (text, html)
132 *
133 * Plain + HTML + image + attachment
134 *
135 * Outlook expr.
136 * multipart/mixed (m/r, attachments)
137 * multipart/related (m/a, cids)
138 * multipart/alternative (text, html)
139 *
140 *
141 *
142 * FROM RFC 1521:
143 *
144 * 5.1 Quoted-Printable Content-Transfer-Encoding
145 * The Quoted-Printable encoding is intended to represent data that largely consists of octets that correspond to printable characters in the ASCII character set. It encodes the data in such a way that the resulting octets are unlikely to be modified by mail transport. If the data being encoded are mostly ASCII text, the encoded form of the data remains largely recognizable by humans. A body which is entirely ASCII may also be encoded in Quoted-Printable to ensure the integrity of the data should the message pass through a character- translating, and/or line-wrapping gateway.
146 *
147 * In this encoding, octets are to be represented as determined by the following rules:
148 * Rule #1: (General 8-bit representation) Any octet, except those indicating a line break according to the newline convention of the canonical (standard) form of the data being encoded, may be represented by an "=" followed by a two digit hexadecimal representation of the octet's value. The digits of the hexadecimal alphabet, for this purpose, are "0123456789ABCDEF". Uppercase letters must be used when sending hexadecimal data, though a robust implementation may choose to recognize lowercase letters on receipt. Thus, for example, the value 12 (ASCII form feed) can be represented by "=0C", and the value 61 (ASCII EQUAL SIGN) can be represented by "=3D". Except when the following rules allow an alternative encoding, this rule is mandatory.
149 * Rule #2: (Literal representation) Octets with decimal values of 33 through 60 inclusive, and 62 through 126, inclusive, MAY be represented as the ASCII characters which correspond to those octets (EXCLAMATION POINT through LESS THAN, and GREATER THAN through TILDE, respectively).
150 * Rule #3: (White Space): Octets with values of 9 and 32 MAY be represented as ASCII TAB (HT) and SPACE characters, respectively, but MUST NOT be so represented at the end of an encoded line. Any TAB (HT) or SPACE characters on an encoded line MUST thus be followed on that line by a printable character. In particular, an
151 * "=" at the end of an encoded line, indicating a soft line break (see rule #5) may follow one or more TAB (HT) or SPACE characters. It follows that an octet with value 9 or 32 appearing at the end of an encoded line must be represented according to Rule #1. This rule is necessary because some MTAs (Message Transport Agents, programs which transport messages from one user to another, or perform a part of such transfers) are known to pad lines of text with SPACEs, and others are known to remove "white space" characters from the end of a line. Therefore, when decoding a Quoted-Printable body, any trailing white space on a line must be deleted, as it will necessarily have been added by intermediate transport agents.
152 * Rule #4 (Line Breaks): A line break in a text body, independent of what its representation is following the canonical representation of the data being encoded, must be represented by a (RFC 822) line break, which is a CRLF sequence, in the Quoted-Printable encoding. Since the canonical representation of types other than text do not generally include the representation of line breaks, no hard line breaks (i.e. line breaks that are intended to be meaningful and to be displayed to the user) should occur in the quoted-printable encoding of such types. Of course, occurrences of "=0D", "=0A", "0A=0D" and "=0D=0A" will eventually be encountered. In general, however, base64 is preferred over quoted-printable for binary data.
153 * Note that many implementations may elect to encode the local representation of various content types directly, as described in Appendix G. In particular, this may apply to plain text material on systems that use newline conventions other than CRLF delimiters. Such an implementation is permissible, but the generation of line breaks must be generalized to account for the case where alternate representations of newline sequences are used.
154 * Rule #5 (Soft Line Breaks): The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76 characters long. If longer lines are to be encoded with the Quoted-Printable encoding, 'soft' line breaks must be used. An equal sign as the last character on a encoded line indicates such a non-significant ('soft') line break in the encoded text. Thus if the "raw" form of the line is a single unencoded line that says:
155 * Now's the time for all folk to come to the aid of their country.
156 *
157 * This can be represented, in the Quoted-Printable encoding, as
158 *
159 * Now's the time =
160 * for all folk to come=
161 * to the aid of their country.
162 *
163 * This provides a mechanism with which long lines are encoded in such a way as to be restored by the user agent. The 76 character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.
164 * Since the hyphen character ("-") is represented as itself in the Quoted-Printable encoding, care must be taken, when encapsulating a quoted-printable encoded body in a multipart entity, to ensure that the encapsulation boundary does not appear anywhere in the encoded body. (A good strategy is to choose a boundary that includes a character sequence such as "=_" which can never appear in a quoted- printable body. See the definition of multipart messages later in this document.)
165 * NOTE: The quoted-printable encoding represents something of a compromise between readability and reliability in transport. Bodies encoded with the quoted-printable encoding will work reliably over most mail gateways, but may not work perfectly over a few gateways, notably those involving translation into EBCDIC. (In theory, an EBCDIC gateway could decode a quoted-printable body and re-encode it using base64, but such gateways do not yet exist.) A higher level of confidence is offered by the base64 Content-Transfer-Encoding. A way to get reasonably reliable transport through EBCDIC gateways is to also quote the ASCII characters
166 * !"#$@[\]^`{|}~
167 * according to rule #1. See Appendix B for more information.
168 * Because quoted-printable data is generally assumed to be line- oriented, it is to be expected that the representation of the breaks between the lines of quoted printable data may be altered in transport, in the same manner that plain text mail has always been altered in Internet mail when passing between systems with differing newline conventions. If such alterations are likely to constitute a corruption of the data, it is probably more sensible to use the base64 encoding rather than the quoted-printable encoding.
169 * WARNING TO IMPLEMENTORS: If binary data are encoded in quoted- printable, care must be taken to encode CR and LF characters as "=0D" and "=0A", respectively. In particular, a CRLF sequence in binary data should be encoded as "=0D=0A". Otherwise, if CRLF were represented as a hard line break, it might be incorrectly decoded on
170 * platforms with different line break conventions.
171 * For formalists, the syntax of quoted-printable data is described by the following grammar:
172 *
173 * quoted-printable := ([*(ptext / SPACE / TAB) ptext] ["="] CRLF)
174 * ; Maximum line length of 76 characters excluding CRLF
175 *
176 * ptext := octet /<any ASCII character except "=", SPACE, or TAB>
177 * ; characters not listed as "mail-safe" in Appendix B
178 * ; are also not recommended.
179 *
180 * octet := "=" 2(DIGIT / "A" / "B" / "C" / "D" / "E" / "F")
181 * ; octet must be used for characters > 127, =, SPACE, or TAB,
182 * ; and is recommended for any characters not listed in
183 * ; Appendix B as "mail-safe".
184 */
185
186 /**
187 * HTML mail class
188 *
189 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
190 * @package TYPO3
191 * @subpackage t3lib
192 */
193 class t3lib_htmlmail {
194 // Headerinfo:
195 var $recipient = "recipient@whatever.com";
196 var $recipient_copy = ""; // This recipient (or list of...) will also receive the mail. Regard it as a copy.
197 var $subject = "This is the subject";
198 var $from_email = "sender@php-mailer.com";
199 var $from_name = "Mr. Sender";
200 var $replyto_email = "reply@mailer.com";
201 var $replyto_name = "Mr. Reply";
202 var $organisation = "Your Company";
203 var $priority = 3; // 1 = highest, 5 = lowest, 3 = normal
204 var $mailer = "PHP mailer"; // X-mailer
205 var $alt_base64=0;
206 var $alt_8bit=0;
207 var $jumperURL_prefix =""; // This is a prefix that will be added to all links in the mail. Example: 'http://www.mydomain.com/jump?userid=###FIELD_uid###&url='. if used, anything after url= is urlencoded.
208 var $jumperURL_useId=0; // If set, then the array-key of the urls are inserted instead of the url itself. Smart in order to reduce link-length
209 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
210 var $http_password="";
211 var $http_username="";
212 var $postfix_version1=false;
213
214 // Internal
215
216 /* This is how the $theParts-array is normally looking
217 var $theParts = Array(
218 "plain" => Array (
219 "content"=> ""
220 ),
221 "html" => Array (
222 "content"=> "",
223 "path" => "",
224 "media" => Array(),
225 "hrefs" => Array()
226 ),
227 "attach" => Array ()
228 );
229 */
230 var $theParts = Array();
231
232 var $messageid = "";
233 var $returnPath = "";
234 var $Xid = "";
235 var $dontEncodeHeader = false; // If set, the header will not be encoded
236
237 var $headers = "";
238 var $message = "";
239 var $part=0;
240 var $image_fullpath_list = "";
241 var $href_fullpath_list = "";
242
243 var $plain_text_header = '';
244 var $html_text_header = '';
245 var $charset = '';
246 var $defaultCharset = 'iso-8859-1';
247
248
249
250
251
252
253
254
255 /**
256 * Constructor. If the configuration variable forceReturnPath is set, calls to mail will be called with a 5th parameter.
257 * See function sendTheMail for more info
258 *
259 * @return [type] ...
260 */
261 function t3lib_htmlmail () {
262 $this->forceReturnPath = $GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath'];
263 }
264
265 /**
266 * @return [type] ...
267 */
268 function start () {
269 global $TYPO3_CONF_VARS;
270
271 // Sets the message id
272 $host = t3lib_div::getHostname();
273 if (!$host || $host == '127.0.0.1' || $host == 'localhost' || $host == 'localhost.localdomain') {
274 $host = ($TYPO3_CONF_VARS['SYS']['sitename'] ? preg_replace('/[^A-Za-z0-9_\-]/', '_', $TYPO3_CONF_VARS['SYS']['sitename']) : 'localhost') . '.TYPO3';
275 }
276 $this->messageid = md5(microtime()) . '@' . $host;
277
278 // Default line break for Unix systems.
279 $this->linebreak = chr(10);
280 // Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the linebreak needs to be \r\n.
281 if (TYPO3_OS=='WIN') {
282 $this->linebreak = chr(13).chr(10);
283 }
284
285 $charset = $this->defaultCharset;
286 if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->config['metaCharset']) {
287 $charset = $GLOBALS['TSFE']->config['metaCharset'];
288 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
289 $charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
290 }
291 $this->charset = $charset;
292
293 // Use quoted-printable headers by default
294 $this->useQuotedPrintable();
295 }
296
297 /**
298 * [Describe function...]
299 *
300 * @return void
301 */
302 function useQuotedPrintable() {
303 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: quoted-printable';
304 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: quoted-printable';
305 }
306
307 /**
308 * [Describe function...]
309 *
310 * @return void
311 */
312 function useBase64() {
313 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: base64';
314 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: base64';
315 $this->alt_base64=1;
316 }
317
318 /**
319 * [Describe function...]
320 *
321 * @return void
322 */
323 function use8Bit() {
324 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: 8bit';
325 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: 8bit';
326 $this->alt_8bit=1;
327 }
328
329 /**
330 * [Describe function...]
331 *
332 * @param [type] $content: ...
333 * @return [type] ...
334 */
335 function encodeMsg($content) {
336 return $this->alt_base64 ? $this->makeBase64($content) : ($this->alt_8bit ? $content : t3lib_div::quoted_printable($content));
337 }
338
339 /**
340 * [Describe function...]
341 *
342 * @param [type] $content: ...
343 * @return [type] ...
344 */
345 function addPlain ($content) {
346 // Adds plain-text and qp-encodes it
347 $content=$this->substHTTPurlsInPlainText($content);
348 $this->setPlain($this->encodeMsg($content));
349 }
350
351 /**
352 * [Describe function...]
353 *
354 * @param [type] $file: ...
355 * @return [type] ...
356 */
357 function addAttachment($file) {
358 // Adds an attachment to the mail
359 $theArr = $this->getExtendedURL($file); // We fetch the content and the mime-type
360 if ($theArr) {
361 if (!$theArr["content_type"]){$theArr["content_type"]="application/octet-stream";}
362 $temp = $this->split_fileref($file);
363 $theArr["filename"]= (($temp["file"])?$temp["file"]:(strpos(" ".$theArr["content_type"],"htm")?"index.html":"unknown"));
364 $this->theParts["attach"][]=$theArr;
365 return true;
366 } else { return false;}
367 }
368
369 /**
370 * [Describe function...]
371 *
372 * @param [type] $file: ...
373 * @return [type] ...
374 */
375 function addHTML ($file) {
376 // Adds HTML and media, encodes it from a URL or file
377 $status = $this->fetchHTML($file);
378 // debug(md5($status));
379 if (!$status) {return false;}
380 if ($this->extractFramesInfo()) {
381 return "Document was a frameset. Stopped";
382 }
383 $this->extractMediaLinks();
384 $this->extractHyperLinks();
385 $this->fetchHTMLMedia();
386 $this->substMediaNamesInHTML(0); // 0 = relative
387 $this->substHREFsInHTML();
388 $this->setHTML($this->encodeMsg($this->theParts["html"]["content"]));
389 }
390
391 /**
392 * External used to extract HTML-parts
393 *
394 * @param [type] $html: ...
395 * @param [type] $url: ...
396 * @return [type] ...
397 */
398 function extractHtmlInit($html,$url) {
399 $this->theParts["html"]["content"]=$html;
400 $this->theParts["html"]["path"]=$url;
401 }
402
403 /**
404 * [Describe function...]
405 *
406 * @param [type] $recipient: ...
407 * @return [type] ...
408 */
409 function send($recipient) {
410 // This function sends the mail to one $recipient
411 if ($recipient) {$this->recipient = $recipient;}
412 $this->setHeaders();
413 $this->setContent();
414 $this->sendTheMail();
415 }
416
417
418
419
420
421
422
423
424
425
426
427
428
429 /*****************************************
430 *
431 * Main functions
432 *
433 *****************************************/
434
435 /**
436 * @return [type] ...
437 */
438 function setHeaders() {
439 // Clears the header-string and sets the headers based on object-vars.
440 $this->headers = "";
441 // Message_id
442 $this->add_header("Message-ID: <".$this->messageid.">");
443 // Return path
444 if ($this->returnPath) {
445 $this->add_header("Return-Path: ".$this->returnPath);
446 $this->add_header("Errors-To: ".$this->returnPath);
447 }
448 // X-id
449 if ($this->Xid) {
450 $this->add_header("X-Typo3MID: ".$this->Xid);
451 }
452
453 // From
454 if ($this->from_email) {
455 if ($this->from_name) {
456 $this->add_header('From: '.$this->from_name.' <'.$this->from_email.'>');
457 } else {
458 $this->add_header('From: '.$this->from_email);
459 }
460 }
461 // Reply
462 if ($this->replyto_email) {
463 if ($this->replyto_name) {
464 $this->add_header('Reply-To: '.$this->replyto_name.' <'.$this->replyto_email.'>');
465 } else {
466 $this->add_header('Reply-To: '.$this->replyto_email);
467 }
468 }
469 // Organisation
470 if ($this->organisation) {
471 $this->add_header('Organisation: '.$this->organisation);
472 }
473 // mailer
474 if ($this->mailer) {
475 $this->add_header("X-Mailer: $this->mailer");
476 }
477 // priority
478 if ($this->priority) {
479 $this->add_header("X-Priority: $this->priority");
480 }
481 $this->add_header("Mime-Version: 1.0");
482
483 if (!$this->dontEncodeHeader) {
484 $enc = $this->alt_base64 ? 'base64' : 'quoted_printable'; // Header must be ASCII, therefore only base64 or quoted_printable are allowed!
485 // Quote recipient and subject
486 $this->recipient = t3lib_div::encodeHeader($this->recipient,$enc,$this->charset);
487 $this->subject = t3lib_div::encodeHeader($this->subject,$enc,$this->charset);
488 }
489 }
490
491 /**
492 * [Describe function...]
493 *
494 * @param [type] $recip: ...
495 * @return [type] ...
496 */
497 function setRecipient ($recip) {
498 // Sets the recipient(s). If you supply a string, you set one recipient. If you supply an array, every value is added as a recipient.
499 if (is_array($recip)) {
500 $this->recipient = "";
501 while (list($key,) = each($recip)) {
502 $this->recipient .= $recip[$key].",";
503 }
504 $this->recipient = ereg_replace(",$","",$this->recipient);
505 } else {
506 $this->recipient = $recip;
507 }
508 }
509
510 /**
511 * [Describe function...]
512 *
513 * @return [type] ...
514 */
515 function getHTMLContentType() {
516 return count($this->theParts["html"]["media"]) ? 'multipart/related;' : 'multipart/alternative;';
517 }
518
519 /**
520 * [Describe function...]
521 *
522 * @return [type] ...
523 */
524 function setContent() {
525 // Begins building the message-body
526 $this->message = "";
527 $boundary = $this->getBoundary();
528 // Setting up headers
529 if (count($this->theParts["attach"])) {
530 $this->add_header('Content-Type: multipart/mixed;');
531 $this->add_header(' boundary="'.$boundary.'"');
532 $this->add_message("This is a multi-part message in MIME format.\n");
533 $this->constructMixed($boundary); // Generate (plain/HTML) / attachments
534 } elseif ($this->theParts["html"]["content"]) {
535 $this->add_header('Content-Type: '.$this->getHTMLContentType());
536 $this->add_header(' boundary="'.$boundary.'"');
537 $this->add_message("This is a multi-part message in MIME format.\n");
538 $this->constructHTML($boundary); // Generate plain/HTML mail
539 } else {
540 $this->add_header($this->plain_text_header);
541 $this->add_message($this->getContent("plain")); // Generate plain only
542 }
543 }
544
545 /**
546 * [Describe function...]
547 *
548 * @param [type] $boundary: ...
549 * @return [type] ...
550 */
551 function constructMixed ($boundary) {
552 // Here (plain/HTML) is combined with the attachments
553 $this->add_message("--".$boundary);
554 // (plain/HTML) is added
555 if ($this->theParts["html"]["content"]) {
556 // HTML and plain
557 $newBoundary = $this->getBoundary();
558 $this->add_message("Content-Type: ".$this->getHTMLContentType());
559 $this->add_message(' boundary="'.$newBoundary.'"');
560 $this->add_message('');
561 $this->constructHTML($newBoundary);
562 } else { // Purely plain
563 $this->add_message($this->plain_text_header);
564 $this->add_message('');
565 $this->add_message($this->getContent("plain"));
566 }
567 // attachments are added
568 if (is_array($this->theParts["attach"])) {
569 reset($this->theParts["attach"]);
570 while(list(,$media)=each($this->theParts["attach"])) {
571 $this->add_message("--".$boundary);
572 $this->add_message("Content-Type: ".$media["content_type"]);
573 $this->add_message(' name="'.$media["filename"].'"');
574 $this->add_message("Content-Transfer-Encoding: base64");
575 $this->add_message("Content-Disposition: attachment;");
576 $this->add_message(' filename="'.$media["filename"].'"');
577 $this->add_message('');
578 $this->add_message($this->makeBase64($media["content"]));
579 }
580 }
581 $this->add_message("--".$boundary."--\n");
582 }
583
584 /**
585 * [Describe function...]
586 *
587 * @param [type] $boundary: ...
588 * @return [type] ...
589 */
590 function constructHTML ($boundary) {
591 if (count($this->theParts["html"]["media"])) { // If media, then we know, the multipart/related content-type has been set before this function call...
592 $this->add_message("--".$boundary);
593 // HTML has media
594 $newBoundary = $this->getBoundary();
595 $this->add_message("Content-Type: multipart/alternative;");
596 $this->add_message(' boundary="'.$newBoundary.'"');
597 $this->add_message('Content-Transfer-Encoding: 7bit');
598 $this->add_message('');
599
600 $this->constructAlternative($newBoundary); // Adding the plaintext/html mix
601
602 $this->constructHTML_media($boundary);
603 } else {
604 $this->constructAlternative($boundary); // Adding the plaintext/html mix, and if no media, then use $boundary instead of $newBoundary
605 }
606 }
607
608 /**
609 * [Describe function...]
610 *
611 * @param [type] $boundary: ...
612 * @return [type] ...
613 */
614 function constructAlternative($boundary) {
615 // Here plain is combined with HTML
616 $this->add_message("--".$boundary);
617 // plain is added
618 $this->add_message($this->plain_text_header);
619 $this->add_message('');
620 $this->add_message($this->getContent("plain"));
621 $this->add_message("--".$boundary);
622 // html is added
623 $this->add_message($this->html_text_header);
624 $this->add_message('');
625 $this->add_message($this->getContent("html"));
626 $this->add_message("--".$boundary."--\n");
627 }
628
629 /**
630 * [Describe function...]
631 *
632 * @param [type] $boundary: ...
633 * @return [type] ...
634 */
635 function constructHTML_media ($boundary) {
636 /* // Constructs the HTML-part of message if the HTML contains media
637 $this->add_message("--".$boundary);
638 // htmlcode is added
639 $this->add_message($this->html_text_header);
640 $this->add_message('');
641 $this->add_message($this->getContent("html"));
642
643 OLD stuf...
644
645 */
646 // media is added
647 if (is_array($this->theParts["html"]["media"])) {
648 reset($this->theParts["html"]["media"]);
649 while(list($key,$media)=each($this->theParts["html"]["media"])) {
650 if (!$this->mediaList || t3lib_div::inList($this->mediaList,$key)) {
651 $this->add_message("--".$boundary);
652 $this->add_message("Content-Type: ".$media["ctype"]);
653 $this->add_message("Content-ID: <part".$key.".".$this->messageid.">");
654 $this->add_message("Content-Transfer-Encoding: base64");
655 $this->add_message('');
656 $this->add_message($this->makeBase64($media["content"]));
657 }
658 }
659 }
660 $this->add_message("--".$boundary."--\n");
661 }
662
663 /**
664 * Sends the mail by calling the mail() function in php. On Linux systems this will invoke the MTA
665 * defined in php.ini (sendmail -t -i by default), on Windows a SMTP must be specified in the sys.ini.
666 * Most common MTA's on Linux has a Sendmail interface, including Postfix and Exim.
667 * For setting the return-path correctly, the parameter -f has to be added to the system call to sendmail.
668 * This obviously does not have any effect on Windows, but on Sendmail compliant systems this works. If safe mode
669 * is enabled, then extra parameters is not allowed, so a safe mode check is made before the mail() command is
670 * invoked. When using the -f parameter, some MTA's will put an X-AUTHENTICATION-WARNING saying that
671 * the return path was modified manually with the -f flag. To disable this warning make sure that the user running
672 * Apache is in the /etc/mail/trusted-users table.
673 *
674 * POSTFIX: With postfix version below 2.0 there is a problem that the -f parameter can not be used in conjunction
675 * with -t. Postfix will give an error in the maillog:
676 *
677 * cannot handle command-line recipients with -t
678 *
679 * The -f parameter is only enabled if the parameter forceReturnPath is enabled in the install tool.
680 *
681 * This whole problem of return-path turns out to be quite tricky. If you have a solution that works better, on all
682 * standard MTA's then we are very open for suggestions.
683 *
684 * With time this function should be made such that several ways of sending the mail is possible (local MTA, smtp other).
685 *
686 * @return [type] ...
687 */
688 function sendTheMail () {
689 #debug(array($this->recipient,$this->subject,$this->message,$this->headers));
690 // Sends the mail, requires the recipient, message and headers to be set.
691 if (trim($this->recipient) && trim($this->message)) { // && trim($this->headers)
692 $returnPath = (strlen($this->returnPath)>0)?"-f".$this->returnPath:'';
693 //On windows the -f flag is not used (specific for Sendmail and Postfix), but instead the php.ini parameter sendmail_from is used.
694 if($this->returnPath) {
695 ini_set(sendmail_from, $this->returnPath);
696 }
697 //If safe mode is on, the fifth parameter to mail is not allowed, so the fix wont work on unix with safe_mode=On
698 if(!ini_get('safe_mode') && $this->forceReturnPath) {
699 mail($this->recipient,
700 $this->subject,
701 $this->message,
702 $this->headers,
703 $returnPath);
704 } else {
705 mail($this->recipient,
706 $this->subject,
707 $this->message,
708 $this->headers);
709 }
710 // Sending copy:
711 if ($this->recipient_copy) {
712 if(!ini_get('safe_mode') && $this->forceReturnPath) {
713 mail( $this->recipient_copy,
714 $this->subject,
715 $this->message,
716 $this->headers,
717 $returnPath);
718 } else {
719 mail( $this->recipient_copy,
720 $this->subject,
721 $this->message,
722 $this->headers );
723 }
724 }
725 // Auto response
726 if ($this->auto_respond_msg) {
727 $theParts = explode('/',$this->auto_respond_msg,2);
728 $theParts[1] = str_replace("/",chr(10),$theParts[1]);
729 if(!ini_get('safe_mode') && $this->forceReturnPath) {
730 mail( $this->from_email,
731 $theParts[0],
732 $theParts[1],
733 "From: ".$this->recipient,
734 $returnPath);
735 } else {
736 mail( $this->from_email,
737 $theParts[0],
738 $theParts[1],
739 "From: ".$this->recipient);
740 }
741 }
742 if($this->returnPath) {
743 ini_restore(sendmail_from);
744 }
745 return true;
746 } else {return false;}
747 }
748
749 /**
750 * [Describe function...]
751 *
752 * @return [type] ...
753 */
754 function getBoundary() {
755 // Returns boundaries
756 $this->part++;
757 return "----------".uniqid("part_".$this->part."_");
758 }
759
760 /**
761 * [Describe function...]
762 *
763 * @param [type] $content: ...
764 * @return [type] ...
765 */
766 function setPlain ($content) {
767 // Sets the plain-text part. No processing done.
768 $this->theParts["plain"]["content"] = $content;
769 }
770
771 /**
772 * [Describe function...]
773 *
774 * @param [type] $content: ...
775 * @return [type] ...
776 */
777 function setHtml ($content) {
778 // Sets the HTML-part. No processing done.
779 $this->theParts["html"]["content"] = $content;
780 }
781
782 /**
783 * [Describe function...]
784 *
785 * @param [type] $header: ...
786 * @return [type] ...
787 */
788 function add_header($header) {
789 if (!$this->dontEncodeHeader && !stristr($header,'Content-Type') && !stristr($header,'Content-Transfer-Encoding')) {
790 // Mail headers must be ASCII, therefore we convert the whole header to either base64 or quoted_printable
791 $parts = explode(': ',$header,2); // Field tags must not be encoded
792 if (count($parts)==2) {
793 $enc = $this->alt_base64 ? 'base64' : 'quoted_printable';
794 $parts[1] = t3lib_div::encodeHeader($parts[1],$enc,$this->charset);
795 $header = implode(': ',$parts);
796 }
797 }
798
799 // Adds a header to the mail. Use this AFTER the setHeaders()-function
800 $this->headers.=$header."\n";
801 }
802
803 /**
804 * [Describe function...]
805 *
806 * @param [type] $string: ...
807 * @return [type] ...
808 */
809 function add_message($string) {
810 // Adds a line of text to the mail-body. Is normally use internally
811 $this->message.=$string."\n";
812 }
813
814 /**
815 * [Describe function...]
816 *
817 * @param [type] $type: ...
818 * @return [type] ...
819 */
820 function getContent($type) {
821 return $this->theParts[$type]["content"];
822 }
823
824 /**
825 * [Describe function...]
826 *
827 * @return [type] ...
828 */
829 function preview() {
830 echo nl2br(HTMLSpecialChars($this->headers));
831 echo "<BR>";
832 echo nl2br(HTMLSpecialChars($this->message));
833 }
834
835
836
837
838
839
840
841
842
843
844
845
846
847 /****************************************************
848 *
849 * Functions for acquiring attachments, HTML, analyzing and so on **
850 *
851 ***************************************************/
852
853 /**
854 * @param [type] $file: ...
855 * @return [type] ...
856 */
857 function fetchHTML($file) {
858 // Fetches the HTML-content from either url og local serverfile
859 $this->theParts["html"]["content"] = $this->getURL($file); // Fetches the content of the page
860 if ($this->theParts["html"]["content"]) {
861 $addr = $this->extParseUrl($file);
862 $path = ($addr['scheme']) ? $addr['scheme'].'://'.$addr['host'].(($addr['port'])?':'.$addr['port']:'').(($addr['filepath'])?$addr['filepath']:'/') : $addr['filepath'];
863 $this->theParts["html"]["path"] = $path;
864 return true;
865 } else {
866 return false;
867 }
868 }
869
870 /**
871 * [Describe function...]
872 *
873 * @return [type] ...
874 */
875 function fetchHTMLMedia() {
876 // Fetches the mediafiles which are found by extractMediaLinks()
877 if (is_array($this->theParts["html"]["media"])) {
878 reset ($this->theParts["html"]["media"]);
879 if (count($this->theParts["html"]["media"]) > 0) {
880 while (list($key,$media) = each ($this->theParts["html"]["media"])) {
881 $picdata = $this->getExtendedURL($this->theParts["html"]["media"][$key]["absRef"]); // We fetch the content and the mime-type
882 if (is_array($picdata)) {
883 $this->theParts["html"]["media"][$key]["content"] = $picdata["content"];
884 $this->theParts["html"]["media"][$key]["ctype"] = $picdata["content_type"];
885 }
886 }
887 }
888 }
889 }
890
891 /**
892 * [Describe function...]
893 *
894 * @return [type] ...
895 */
896 function extractMediaLinks() {
897 // extracts all media-links from $this->theParts["html"]["content"]
898 $html_code = $this->theParts["html"]["content"];
899 $attribRegex = $this->tag_regex(Array("img","table","td","tr","body","iframe","script","input","embed"));
900 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
901 $len=strlen($codepieces[0]);
902 $pieces = count($codepieces);
903 $reg = array();
904 for($i=1; $i < $pieces; $i++) {
905 $tag = strtolower(strtok(substr($html_code,$len+1,10)," "));
906 $len+=strlen($tag)+strlen($codepieces[$i])+2;
907 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
908 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
909 $imageData=array();
910 $imageData["ref"]=($attributes["src"]) ? $attributes["src"] : $attributes["background"]; // Finds the src or background attribute
911 if ($imageData["ref"]) {
912 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
913 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
914 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
915 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
916 $imageData["absRef"] = $this->absRef($imageData["ref"]);
917 $imageData["tag"]=$tag;
918 $imageData["use_jumpurl"]=$attributes["dmailerping"]?1:0;
919 $this->theParts["html"]["media"][]=$imageData;
920 }
921 }
922 }
923 // Extracts stylesheets
924 $attribRegex = $this->tag_regex(Array("link"));
925 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
926 $pieces = count($codepieces);
927 for($i=1; $i < $pieces; $i++) {
928 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
929 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
930 $imageData=array();
931 if (strtolower($attributes["rel"])=="stylesheet" && $attributes["href"]) {
932 $imageData["ref"]=$attributes["href"]; // Finds the src or background attribute
933 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
934 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
935 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
936 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
937 $imageData["absRef"] = $this->absRef($imageData["ref"]);
938 $this->theParts["html"]["media"][]=$imageData;
939 }
940 }
941 }
942 // fixes javascript rollovers
943 $codepieces = split(quotemeta(".src"), $html_code);
944 $pieces = count($codepieces);
945 $expr = "^[^".quotemeta("\"").quotemeta("'")."]*";
946 for($i=1; $i < $pieces; $i++) {
947 $temp = $codepieces[$i];
948 $temp = trim(ereg_replace("=","",trim($temp)));
949 ereg ($expr,substr($temp,1,strlen($temp)),$reg);
950 $imageData["ref"] = $reg[0];
951 $imageData["quotes"] = substr($temp,0,1);
952 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
953 $theInfo = $this->split_fileref($imageData["ref"]);
954 switch ($theInfo["fileext"]) {
955 case "gif":
956 case "jpeg":
957 case "jpg":
958 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
959 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
960 $imageData["absRef"] = $this->absRef($imageData["ref"]);
961 $this->theParts["html"]["media"][]=$imageData;
962 }
963 break;
964 }
965 }
966 }
967
968 /**
969 * [Describe function...]
970 *
971 * @return [type] ...
972 */
973 function extractHyperLinks() {
974 // extracts all hyper-links from $this->theParts["html"]["content"]
975 $html_code = $this->theParts["html"]["content"];
976 $attribRegex = $this->tag_regex(Array("a","form","area"));
977 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
978 $len=strlen($codepieces[0]);
979 $pieces = count($codepieces);
980 for($i=1; $i < $pieces; $i++) {
981 $tag = strtolower(strtok(substr($html_code,$len+1,10)," "));
982 $len+=strlen($tag)+strlen($codepieces[$i])+2;
983
984 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
985 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
986 $hrefData="";
987 if ($attributes["href"]) {$hrefData["ref"]=$attributes["href"];} else {$hrefData["ref"]=$attributes["action"];}
988 if ($hrefData["ref"]) {
989 $hrefData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $hrefData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
990 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron
991 if ($hrefData["ref"] && substr(trim($hrefData["ref"]),0,1)!="#" && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) {
992 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|";
993 $hrefData["absRef"] = $this->absRef($hrefData["ref"]);
994 $hrefData["tag"]=$tag;
995 $this->theParts["html"]["hrefs"][]=$hrefData;
996 }
997 }
998 }
999 // Extracts TYPO3 specific links made by the openPic() JS function
1000 $codepieces = explode("onClick=\"openPic('", $html_code);
1001 $pieces = count($codepieces);
1002 for($i=1; $i < $pieces; $i++) {
1003 $showpic_linkArr = explode("'",$codepieces[$i]);
1004 $hrefData["ref"]=$showpic_linkArr[0];
1005 if ($hrefData["ref"]) {
1006 $hrefData["quotes"]="'"; // Finds out if the value had quotes around it
1007 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron
1008 if ($hrefData["ref"] && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) {
1009 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|";
1010 $hrefData["absRef"] = $this->absRef($hrefData["ref"]);
1011 $this->theParts["html"]["hrefs"][]=$hrefData;
1012 }
1013 }
1014 }
1015 }
1016
1017 /**
1018 * [Describe function...]
1019 *
1020 * @return [type] ...
1021 */
1022 function extractFramesInfo() {
1023 // extracts all media-links from $this->theParts["html"]["content"]
1024 $html_code = $this->theParts["html"]["content"];
1025 if (strpos(" ".$html_code,"<frame ")) {
1026 $attribRegex = $this->tag_regex("frame");
1027 $codepieces = split($attribRegex, $html_code, 1000000 ); // Splits the document by the beginning of the above tags
1028 $pieces = count($codepieces);
1029 for($i=1; $i < $pieces; $i++) {
1030 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
1031 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
1032 $frame="";
1033 $frame["src"]=$attributes["src"];
1034 $frame["name"]=$attributes["name"];
1035 $frame["absRef"] = $this->absRef($frame["src"]);
1036 $theInfo[] = $frame;
1037 }
1038 return $theInfo;
1039 }
1040 }
1041
1042 /**
1043 * [Describe function...]
1044 *
1045 * @param [type] $absolute: ...
1046 * @return [type] ...
1047 */
1048 function substMediaNamesInHTML($absolute) {
1049 // This substitutes the media-references in $this->theParts["html"]["content"]
1050 // If $absolute is true, then the refs are substituted with http:// ref's indstead of Content-ID's (cid).
1051 if (is_array($this->theParts["html"]["media"])) {
1052 reset ($this->theParts["html"]["media"]);
1053 while (list($key,$val) = each ($this->theParts["html"]["media"])) {
1054 if ($val["use_jumpurl"] && $this->jumperURL_prefix) {
1055 $theSubstVal = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($val['absRef']);
1056 } else {
1057 $theSubstVal = ($absolute) ? $val["absRef"] : "cid:part".$key.".".$this->messageid;
1058 }
1059 $this->theParts["html"]["content"] = str_replace(
1060 $val["subst_str"],
1061 $val["quotes"].$theSubstVal.$val["quotes"],
1062 $this->theParts["html"]["content"] );
1063 }
1064 }
1065 if (!$absolute) {
1066 $this->fixRollOvers();
1067 }
1068 }
1069
1070 /**
1071 * [Describe function...]
1072 *
1073 * @return [type] ...
1074 */
1075 function substHREFsInHTML() {
1076 // This substitutes the hrefs in $this->theParts["html"]["content"]
1077 if (is_array($this->theParts["html"]["hrefs"])) {
1078 reset ($this->theParts["html"]["hrefs"]);
1079 while (list($key,$val) = each ($this->theParts["html"]["hrefs"])) {
1080 if ($this->jumperURL_prefix && $val["tag"]!="form") { // Form elements cannot use jumpurl!
1081 if ($this->jumperURL_useId) {
1082 $theSubstVal = $this->jumperURL_prefix.$key;
1083 } else {
1084 $theSubstVal = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($val['absRef']);
1085 }
1086 } else {
1087 $theSubstVal = $val["absRef"];
1088 }
1089 $this->theParts["html"]["content"] = str_replace(
1090 $val["subst_str"],
1091 $val["quotes"].$theSubstVal.$val["quotes"],
1092 $this->theParts["html"]["content"] );
1093 }
1094 }
1095 }
1096
1097 /**
1098 * [Describe function...]
1099 *
1100 * @param [type] $content: ...
1101 * @return [type] ...
1102 */
1103 function substHTTPurlsInPlainText($content) {
1104 // This substitutes the http:// urls in plain text with links
1105 if ($this->jumperURL_prefix) {
1106 $textpieces = explode("http://", $content);
1107 $pieces = count($textpieces);
1108 $textstr = $textpieces[0];
1109 for($i=1; $i<$pieces; $i++) {
1110 $len=strcspn($textpieces[$i],chr(32).chr(9).chr(13).chr(10));
1111 if (trim(substr($textstr,-1))=="" && $len) {
1112 $lastChar=substr($textpieces[$i],$len-1,1);
1113 if (!ereg("[A-Za-z0-9\/#]",$lastChar)) {$len--;} // Included "\/" 3/12
1114
1115 $parts[0]="http://".substr($textpieces[$i],0,$len);
1116 $parts[1]=substr($textpieces[$i],$len);
1117
1118 if ($this->jumperURL_useId) {
1119 $this->theParts["plain"]["link_ids"][$i]=$parts[0];
1120 $parts[0] = $this->jumperURL_prefix."-".$i;
1121 } else {
1122 $parts[0] = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($parts[0]);
1123 }
1124 $textstr.=$parts[0].$parts[1];
1125 } else {
1126 $textstr.='http://'.$textpieces[$i];
1127 }
1128 }
1129 $content = $textstr;
1130 }
1131 return $content;
1132 }
1133
1134 /**
1135 * [Describe function...]
1136 *
1137 * @return [type] ...
1138 */
1139 function fixRollOvers() {
1140 // 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!!)
1141 $theNewContent = "";
1142 $theSplit = explode(".src",$this->theParts["html"]["content"]);
1143 if (count($theSplit)>1) {
1144 while(list($key,$part)=each($theSplit)) {
1145 $sub = substr($part,0,200);
1146 if (ereg("cid:part[^ \"']*",$sub,$reg)) {
1147 $thePos = strpos($part,$reg[0]); // The position of the string
1148 ereg("cid:part([^\.]*).*",$sub,$reg2); // Finds the id of the media...
1149 $theSubStr = $this->theParts["html"]["media"][intval($reg2[1])]["absRef"];
1150 if ($thePos && $theSubStr) { // ... and substitutes the javaScript rollover image with this instead
1151 if (!strpos(" ".$theSubStr,"http://")) {$theSubStr = "http://";} // If the path is NOT and url, the reference is set to nothing
1152 $part = substr($part,0,$thePos).$theSubStr.substr($part,$thePos+strlen($reg[0]),strlen($part));
1153 }
1154 }
1155 $theNewContent.= $part.((($key+1)!=count($theSplit))? ".src" : "" );
1156 }
1157 $this->theParts["html"]["content"]=$theNewContent;
1158 }
1159 }
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176 /*******************************************
1177 *
1178 * File and URL-functions
1179 *
1180 *******************************************/
1181
1182 /**
1183 * @param [type] $inputstr: ...
1184 * @return [type] ...
1185 */
1186 function makeBase64($inputstr) {
1187 // Returns base64-encoded content, which is broken every 76 character
1188 return chunk_split(base64_encode($inputstr));
1189 }
1190
1191 /**
1192 * [Describe function...]
1193 *
1194 * @param [type] $url: ...
1195 * @return [type] ...
1196 */
1197 function getExtendedURL($url) {
1198 // reads the URL or file and determines the Content-type by either guessing or opening a connection to the host
1199 $res["content"] = $this->getURL($url);
1200 if (!$res["content"]) {return false;}
1201 $pathInfo = parse_url($url);
1202 $fileInfo = $this->split_fileref($pathInfo["path"]);
1203 if ($fileInfo["fileext"] == "gif") {$res["content_type"] = "image/gif";}
1204 if ($fileInfo["fileext"] == "jpg" || $fileInfo["fileext"] == "jpeg") {$res["content_type"] = "image/jpeg";}
1205 if ($fileInfo['fileext'] == 'png') {$res['content_type'] = 'image/png';}
1206 if ($fileInfo["fileext"] == "html" || $fileInfo["fileext"] == "htm") {$res["content_type"] = "text/html";}
1207 if ($fileInfo['fileext'] == 'css') {$res['content_type'] = 'text/css';}
1208 if ($fileInfo["fileext"] == "swf") {$res["content_type"] = "application/x-shockwave-flash";}
1209 if (!$res["content_type"]) {$res["content_type"] = $this->getMimeType($url);}
1210 return $res;
1211 }
1212
1213 /**
1214 * [Describe function...]
1215 *
1216 * @param [type] $url: ...
1217 * @return [type] ...
1218 */
1219 function addUserPass($url) {
1220 $user=$this->http_username;
1221 $pass=$this->http_password;
1222 $matches = array();
1223 if ($user && $pass && preg_match('/^(https?:\/\/)/', $url, $matches)) {
1224 $url = $matches[1].$user.':'.$pass.'@'.substr($url,strlen($matches[1]));
1225 }
1226 return $url;
1227 }
1228
1229 /**
1230 * [Describe function...]
1231 *
1232 * @param [type] $url: ...
1233 * @return [type] ...
1234 */
1235 function getURL($url) {
1236 $url = $this->addUserPass($url);
1237 // reads a url or file
1238 return t3lib_div::getURL($url);
1239 }
1240
1241 /**
1242 * [Describe function...]
1243 *
1244 * @param [type] $url: ...
1245 * @return [type] ...
1246 */
1247 function getStrippedURL($url) {
1248 // reads a url or file and strips the HTML-tags AND removes all empty lines. This is used to read plain-text out of a HTML-page
1249 if($fd = fopen($url,"rb")) {
1250 $content = "";
1251 while (!feof($fd)) {
1252 $line = fgetss($fd, 5000);
1253 if (trim($line)) {
1254 $content.=trim($line)."\n";
1255 }
1256 }
1257 fclose( $fd );
1258 return $content;
1259 }
1260 }
1261
1262 /**
1263 * This function returns the mime type of the file specified by the url
1264 *
1265 * @param string $url: the url
1266 * @return string $mimeType: the mime type found in the header
1267 */
1268 function getMimeType($url) {
1269 $mimeType = '';
1270 $headers = trim(t3lib_div::getURL($url, 2));
1271 if ($headers) {
1272 $matches = array();
1273 if (preg_match('/(Content-Type:[\s]*)([a-zA-Z_0-9\/\-\.\+]*)([\s]|$)/', $headers, $matches)) {
1274 $mimeType = trim($matches[2]);
1275 }
1276 }
1277 return $mimeType;
1278 }
1279
1280 /**
1281 * [Describe function...]
1282 *
1283 * @param [type] $ref: ...
1284 * @return [type] ...
1285 */
1286 function absRef($ref) {
1287 // Returns the absolute address of a link. This is based on $this->theParts["html"]["path"] being the root-address
1288 $ref = trim($ref);
1289 $urlINFO = parse_url($ref);
1290 if ($urlINFO["scheme"]) {
1291 return $ref;
1292 } elseif (eregi("^/",$ref)){
1293 $addr = parse_url($this->theParts["html"]["path"]);
1294 return $addr['scheme'].'://'.$addr['host'].($addr['port']?':'.$addr['port']:'').$ref;
1295 } else {
1296 return $this->theParts["html"]["path"].$ref; // If the reference is relative, the path is added, in order for us to fetch the content
1297 }
1298 }
1299
1300 /**
1301 * [Describe function...]
1302 *
1303 * @param [type] $fileref: ...
1304 * @return [type] ...
1305 */
1306 function split_fileref($fileref) {
1307 // Returns an array with path, filename, filebody, fileext.
1308 if ( ereg("(.*/)(.*)$",$fileref,$reg) ) {
1309 $info["path"] = $reg[1];
1310 $info["file"] = $reg[2];
1311 } else {
1312 $info["path"] = "";
1313 $info["file"] = $fileref;
1314 }
1315 $reg="";
1316 if ( ereg("(.*)\.([^\.]*$)",$info["file"],$reg) ) {
1317 $info["filebody"] = $reg[1];
1318 $info["fileext"] = strtolower($reg[2]);
1319 $info["realFileext"] = $reg[2];
1320 } else {
1321 $info["filebody"] = $info["file"];
1322 $info["fileext"] = "";
1323 }
1324 return $info;
1325 }
1326
1327 /**
1328 * [Describe function...]
1329 *
1330 * @param [type] $path: ...
1331 * @return [type] ...
1332 */
1333 function extParseUrl($path) {
1334 // Returns an array with file or url-information
1335 $res = parse_url($path);
1336 ereg("(.*/)([^/]*)$",$res["path"],$reg);
1337 $res["filepath"]=$reg[1];
1338 $res["filename"]=$reg[2];
1339 return $res;
1340 }
1341
1342 /**
1343 * [Describe function...]
1344 *
1345 * @param [type] $tagArray: ...
1346 * @return [type] ...
1347 */
1348 function tag_regex($tagArray) {
1349 if (!is_array($tagArray)) {
1350 $tagArray=Array($tagArray);
1351 }
1352 $theRegex = "";
1353 $c=count($tagArray);
1354 while(list(,$tag)=each($tagArray)) {
1355 $c--;
1356 $theRegex.="<".sql_regcase($tag)."[[:space:]]".(($c)?"|":"");
1357 }
1358 return $theRegex;
1359 }
1360
1361 /**
1362 * analyses a HTML-tag
1363 * $tag is either like this "<TAG OPTION ATTRIB=VALUE>" or this " OPTION ATTRIB=VALUE>" which means you can omit the tag-name
1364 * returns an array with the attributes as keys in lower-case
1365 * If an attribute is empty (like OPTION) the value of that key is just empty. Check it with is_set();
1366 *
1367 * @param [type] $tag: ...
1368 * @return [type] ...
1369 */
1370 function get_tag_attributes($tag) {
1371 $attributes = Array();
1372 $tag = ltrim(eregi_replace ("^<[^ ]*","",trim($tag)));
1373 $tagLen = strlen($tag);
1374 $safetyCounter = 100;
1375 // Find attribute
1376 while ($tag) {
1377 $value = "";
1378 $reg = split("[[:space:]=>]",$tag,2);
1379 $attrib = $reg[0];
1380
1381 $tag = ltrim(substr($tag,strlen($attrib),$tagLen));
1382 if (substr($tag,0,1)=="=") {
1383 $tag = ltrim(substr($tag,1,$tagLen));
1384 if (substr($tag,0,1)=='"') { // Quotes around the value
1385 $reg = explode('"',substr($tag,1,$tagLen),2);
1386 $tag = ltrim($reg[1]);
1387 $value = $reg[0];
1388 } else { // No qoutes around value
1389 ereg("^([^[:space:]>]*)(.*)",$tag,$reg);
1390 $value = trim($reg[1]);
1391 $tag = ltrim($reg[2]);
1392 if (substr($tag,0,1)==">") {
1393 $tag ="";
1394 }
1395 }
1396 }
1397 $attributes[strtolower($attrib)]=$value;
1398 $safetyCounter--;
1399 if ($safetyCounter<0) {break;}
1400 }
1401 return $attributes;
1402 }
1403
1404 /**
1405 * Implementation of quoted-printable encode.
1406 * This function was a duplicate of t3lib_div::quoted_printable, thus it's going to be removed.
1407 *
1408 * @param string Content to encode
1409 * @return string The QP encoded string
1410 * @obsolete
1411 */
1412 function quoted_printable($string) {
1413 return t3lib_div::quoted_printable($string, 76);
1414 }
1415
1416 /**
1417 * [Describe function...]
1418 *
1419 * @param [type] $name: ...
1420 * @return [type] ...
1421 * @deprecated
1422 */
1423 function convertName($name) {
1424 return $name;
1425 }
1426 }
1427
1428 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']) {
1429 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']);
1430 }
1431 ?>