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