Fixed bug 1197, and added a new header to the email: Errors-To.
[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']['forceReturnPath'];
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 $this->add_header("Errors-To: ".$this->returnPath);
397 }
398 // X-id
399 if ($this->Xid) {
400 $this->add_header("X-Typo3MID: ".$this->Xid);
401 }
402
403 // From
404 if ($this->from_email) {
405 if ($this->from_name) {
406 $name = $this->convertName($this->from_name);
407 $this->add_header('From: '.$name.' <'.$this->from_email.'>');
408 } else {
409 $this->add_header('From: '.$this->from_email);
410 }
411 }
412 // Reply
413 if ($this->replyto_email) {
414 if ($this->replyto_name) {
415 $name = $this->convertName($this->replyto_name);
416 $this->add_header("Reply-To: $name <$this->replyto_email>");
417 } else {
418 $this->add_header("Reply-To: $this->replyto_email");
419 }
420 }
421 // Organisation
422 if ($this->organisation) {
423 $name = $this->convertName($this->organisation);
424 $this->add_header("Organisation: $name");
425 }
426 // mailer
427 if ($this->mailer) {
428 $this->add_header("X-Mailer: $this->mailer");
429 }
430 // priority
431 if ($this->priority) {
432 $this->add_header("X-Priority: $this->priority");
433 }
434 $this->add_header("Mime-Version: 1.0");
435 }
436
437 /**
438 * [Describe function...]
439 *
440 * @param [type] $recip: ...
441 * @return [type] ...
442 */
443 function setRecipient ($recip) {
444 // 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.
445 if (is_array($recip)) {
446 $this->recipient = "";
447 while (list($key,) = each($recip)) {
448 $this->recipient .= $recip[$key].",";
449 }
450 $this->recipient = ereg_replace(",$","",$this->recipient);
451 } else {
452 $this->recipient = $recip;
453 }
454 }
455
456 /**
457 * [Describe function...]
458 *
459 * @return [type] ...
460 */
461 function getHTMLContentType() {
462 return count($this->theParts["html"]["media"]) ? 'multipart/related;' : 'multipart/alternative;';
463 }
464
465 /**
466 * [Describe function...]
467 *
468 * @return [type] ...
469 */
470 function setContent() {
471 // Begins building the message-body
472 $this->message = "";
473 $boundary = $this->getBoundary();
474 // Setting up headers
475 if (count($this->theParts["attach"])) {
476 $this->add_header('Content-Type: multipart/mixed;');
477 $this->add_header(' boundary="'.$boundary.'"');
478 $this->add_message("This is a multi-part message in MIME format.\n");
479 $this->constructMixed($boundary); // Generate (plain/HTML) / attachments
480 } elseif ($this->theParts["html"]["content"]) {
481 $this->add_header('Content-Type: '.$this->getHTMLContentType());
482 $this->add_header(' boundary="'.$boundary.'"');
483 $this->add_message("This is a multi-part message in MIME format.\n");
484 $this->constructHTML($boundary); // Generate plain/HTML mail
485 } else {
486 $this->add_header($this->plain_text_header);
487 $this->add_message($this->getContent("plain")); // Generate plain only
488 }
489 }
490
491 /**
492 * [Describe function...]
493 *
494 * @param [type] $boundary: ...
495 * @return [type] ...
496 */
497 function constructMixed ($boundary) {
498 // Here (plain/HTML) is combined with the attachments
499 $this->add_message("--".$boundary);
500 // (plain/HTML) is added
501 if ($this->theParts["html"]["content"]) {
502 // HTML and plain
503 $newBoundary = $this->getBoundary();
504 $this->add_message("Content-Type: ".$this->getHTMLContentType());
505 $this->add_message(' boundary="'.$newBoundary.'"');
506 $this->add_message('');
507 $this->constructHTML($newBoundary);
508 } else { // Purely plain
509 $this->add_message($this->plain_text_header);
510 $this->add_message('');
511 $this->add_message($this->getContent("plain"));
512 }
513 // attachments are added
514 if (is_array($this->theParts["attach"])) {
515 reset($this->theParts["attach"]);
516 while(list(,$media)=each($this->theParts["attach"])) {
517 $this->add_message("--".$boundary);
518 $this->add_message("Content-Type: ".$media["content_type"]);
519 $this->add_message(' name="'.$media["filename"].'"');
520 $this->add_message("Content-Transfer-Encoding: base64");
521 $this->add_message("Content-Disposition: attachment;");
522 $this->add_message(' filename="'.$media["filename"].'"');
523 $this->add_message('');
524 $this->add_message($this->makeBase64($media["content"]));
525 }
526 }
527 $this->add_message("--".$boundary."--\n");
528 }
529
530 /**
531 * [Describe function...]
532 *
533 * @param [type] $boundary: ...
534 * @return [type] ...
535 */
536 function constructHTML ($boundary) {
537 if (count($this->theParts["html"]["media"])) { // If media, then we know, the multipart/related content-type has been set before this function call...
538 $this->add_message("--".$boundary);
539 // HTML has media
540 $newBoundary = $this->getBoundary();
541 $this->add_message("Content-Type: multipart/alternative;");
542 $this->add_message(' boundary="'.$newBoundary.'"');
543 $this->add_message('');
544
545 $this->constructAlternative($newBoundary); // Adding the plaintext/html mix
546
547 $this->constructHTML_media($boundary);
548 } else {
549 $this->constructAlternative($boundary); // Adding the plaintext/html mix, and if no media, then use $boundary instead of $newBoundary
550 }
551 }
552
553 /**
554 * [Describe function...]
555 *
556 * @param [type] $boundary: ...
557 * @return [type] ...
558 */
559 function constructAlternative($boundary) {
560 // Here plain is combined with HTML
561 $this->add_message("--".$boundary);
562 // plain is added
563 $this->add_message($this->plain_text_header);
564 $this->add_message('');
565 $this->add_message($this->getContent("plain"));
566 $this->add_message("--".$boundary);
567 // html is added
568 $this->add_message($this->html_text_header);
569 $this->add_message('');
570 $this->add_message($this->getContent("html"));
571 $this->add_message("--".$boundary."--\n");
572 }
573
574 /**
575 * [Describe function...]
576 *
577 * @param [type] $boundary: ...
578 * @return [type] ...
579 */
580 function constructHTML_media ($boundary) {
581 /* // Constructs the HTML-part of message if the HTML contains media
582 $this->add_message("--".$boundary);
583 // htmlcode is added
584 $this->add_message($this->html_text_header);
585 $this->add_message('');
586 $this->add_message($this->getContent("html"));
587
588 OLD stuf...
589
590 */
591 // media is added
592 if (is_array($this->theParts["html"]["media"])) {
593 reset($this->theParts["html"]["media"]);
594 while(list($key,$media)=each($this->theParts["html"]["media"])) {
595 if (!$this->mediaList || t3lib_div::inList($this->mediaList,$key)) {
596 $this->add_message("--".$boundary);
597 $this->add_message("Content-Type: ".$media["ctype"]);
598 $this->add_message("Content-ID: <part".$key.".".$this->messageid.">");
599 $this->add_message("Content-Transfer-Encoding: base64");
600 $this->add_message('');
601 $this->add_message($this->makeBase64($media["content"]));
602 }
603 }
604 }
605 $this->add_message("--".$boundary."--\n");
606 }
607
608 /**
609 * Sends the mail by calling the mail() function in php. On Linux systems this will invoke the MTA
610 * defined in php.ini (sendmail -t -i by default), on Windows a SMTP must be specified in the sys.ini.
611 * Most common MTA's on Linux has a Sendmail interface, including Postfix and Exim.
612 * For setting the return-path correctly, the parameter -f has to be added to the system call to sendmail.
613 * This obviously does not have any effect on Windows, but on Sendmail compliant systems this works. If safe mode
614 * is enabled, then extra parameters is not allowed, so a safe mode check is made before the mail() command is
615 * invoked. When using the -f parameter, some MTA's will put an X-AUTHENTICATION-WARNING saying that
616 * the return path was modified manually with the -f flag. To disable this warning make sure that the user running
617 * Apache is in the /etc/mail/trusted-users table.
618 *
619 * POSTFIX: With postfix version below 2.0 there is a problem that the -f parameter can not be used in conjunction
620 * with -t. Postfix will give an error in the maillog:
621 *
622 * cannot handle command-line recipients with -t
623 *
624 * The -f parameter is only enabled if the parameter forceReturnPath is enabled in the install tool.
625 *
626 * This whole problem of return-path turns out to be quite tricky. If you have a solution that works better, on all
627 * standard MTA's then we are very open for suggestions.
628 *
629 * With time this function should be made such that several ways of sending the mail is possible (local MTA, smtp other).
630 *
631 * @return [type] ...
632 */
633 function sendTheMail () {
634 #debug(array($this->recipient,$this->subject,$this->message,$this->headers));
635 // Sends the mail, requires the recipient, message and headers to be set.
636 if (trim($this->recipient) && trim($this->message)) { // && trim($this->headers)
637 $returnPath = (strlen($this->returnPath)>0)?"-f".$this->returnPath:'';
638 //On windows the -f flag is not used (specific for Sendmail and Postfix), but instead the php.ini parameter sendmail_from is used.
639 if($this->returnPath) {
640 ini_set(sendmail_from, $this->returnPath);
641 }
642 //If safe mode is on, the fifth parameter to mail is not allowed, so the fix wont work on unix with safe_mode=On
643 if(!ini_get('safe_mode') && $this->forceReturnPath) {
644 mail($this->recipient,
645 $this->subject,
646 $this->message,
647 $this->headers,
648 $returnPath);
649 } else {
650 mail($this->recipient,
651 $this->subject,
652 $this->message,
653 $this->headers);
654 }
655 // Sending copy:
656 if ($this->recipient_copy) {
657 if(!ini_get('safe_mode') && $this->forceReturnPath) {
658 mail( $this->recipient_copy,
659 $this->subject,
660 $this->message,
661 $this->headers,
662 $returnPath);
663 } else {
664 mail( $this->recipient_copy,
665 $this->subject,
666 $this->message,
667 $this->headers );
668 }
669 }
670 // Auto response
671 if ($this->auto_respond_msg) {
672 $theParts = explode('/',$this->auto_respond_msg,2);
673 $theParts[1] = str_replace("/",chr(10),$theParts[1]);
674 if(!ini_get('safe_mode') && $this->forceReturnPath) {
675 mail( $this->from_email,
676 $theParts[0],
677 $theParts[1],
678 "From: ".$this->recipient,
679 $returnPath);
680 } else {
681 mail( $this->from_email,
682 $theParts[0],
683 $theParts[1],
684 "From: ".$this->recipient);
685 }
686 }
687 if($this->returnPath) {
688 ini_restore(sendmail_from);
689 }
690 return true;
691 } else {return false;}
692 }
693
694 /**
695 * [Describe function...]
696 *
697 * @return [type] ...
698 */
699 function getBoundary() {
700 // Returns boundaries
701 $this->part++;
702 return "----------".uniqid("part_".$this->part."_");
703 }
704
705 /**
706 * [Describe function...]
707 *
708 * @param [type] $content: ...
709 * @return [type] ...
710 */
711 function setPlain ($content) {
712 // Sets the plain-text part. No processing done.
713 $this->theParts["plain"]["content"] = $content;
714 }
715
716 /**
717 * [Describe function...]
718 *
719 * @param [type] $content: ...
720 * @return [type] ...
721 */
722 function setHtml ($content) {
723 // Sets the HTML-part. No processing done.
724 $this->theParts["html"]["content"] = $content;
725 }
726
727 /**
728 * [Describe function...]
729 *
730 * @param [type] $header: ...
731 * @return [type] ...
732 */
733 function add_header ($header) {
734 // Adds a header to the mail. Use this AFTER the setHeaders()-function
735 $this->headers.=$header."\n";
736 }
737
738 /**
739 * [Describe function...]
740 *
741 * @param [type] $string: ...
742 * @return [type] ...
743 */
744 function add_message ($string) {
745 // Adds a line of text to the mail-body. Is normally use internally
746 $this->message.=$string."\n";
747 }
748
749 /**
750 * [Describe function...]
751 *
752 * @param [type] $type: ...
753 * @return [type] ...
754 */
755 function getContent($type) {
756 return $this->theParts[$type]["content"];
757 }
758
759 /**
760 * [Describe function...]
761 *
762 * @return [type] ...
763 */
764 function preview() {
765 echo nl2br(HTMLSpecialChars($this->headers));
766 echo "<BR>";
767 echo nl2br(HTMLSpecialChars($this->message));
768 }
769
770
771
772
773
774
775
776
777
778
779
780
781
782 /****************************************************
783 *
784 * Functions for acquiring attachments, HTML, analyzing and so on **
785 *
786 ***************************************************/
787
788 /**
789 * @param [type] $file: ...
790 * @return [type] ...
791 */
792 function fetchHTML($file) {
793 // Fetches the HTML-content from either url og local serverfile
794 $this->theParts["html"]["content"] = $this->getURL($file); // Fetches the content of the page
795 if ($this->theParts["html"]["content"]) {
796 $addr = $this->extParseUrl($file);
797 $path = ($addr["scheme"]) ? $addr["scheme"]."://".$addr["host"].(($addr["filepath"])?$addr["filepath"]:"/") : $addr["filepath"];
798 $this->theParts["html"]["path"] = $path;
799 return true;
800 } else {
801 return false;
802 }
803 }
804
805 /**
806 * [Describe function...]
807 *
808 * @return [type] ...
809 */
810 function fetchHTMLMedia() {
811 // Fetches the mediafiles which are found by extractMediaLinks()
812 if (is_array($this->theParts["html"]["media"])) {
813 reset ($this->theParts["html"]["media"]);
814 if (count($this->theParts["html"]["media"]) > 0) {
815 while (list($key,$media) = each ($this->theParts["html"]["media"])) {
816 $picdata = $this->getExtendedURL($this->theParts["html"]["media"][$key]["absRef"]); // We fetch the content and the mime-type
817 if (is_array($picdata)) {
818 $this->theParts["html"]["media"][$key]["content"] = $picdata["content"];
819 $this->theParts["html"]["media"][$key]["ctype"] = $picdata["content_type"];
820 }
821 }
822 }
823 }
824 }
825
826 /**
827 * [Describe function...]
828 *
829 * @return [type] ...
830 */
831 function extractMediaLinks() {
832 // extracts all media-links from $this->theParts["html"]["content"]
833 $html_code = $this->theParts["html"]["content"];
834 $attribRegex = $this->tag_regex(Array("img","table","td","tr","body","iframe","script","input","embed"));
835 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
836 $len=strlen($codepieces[0]);
837 $pieces = count($codepieces);
838 for($i=1; $i < $pieces; $i++) {
839 $tag = strtolower(strtok(substr($html_code,$len+1,10)," "));
840 $len+=strlen($tag)+strlen($codepieces[$i])+2;
841 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
842 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
843 $imageData=array();
844 $imageData["ref"]=($attributes["src"]) ? $attributes["src"] : $attributes["background"]; // Finds the src or background attribute
845 if ($imageData["ref"]) {
846 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
847 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
848 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
849 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
850 $imageData["absRef"] = $this->absRef($imageData["ref"]);
851 $imageData["tag"]=$tag;
852 $imageData["use_jumpurl"]=$attributes["dmailerping"]?1:0;
853 $this->theParts["html"]["media"][]=$imageData;
854 }
855 }
856 }
857 // Extracts stylesheets
858 $attribRegex = $this->tag_regex(Array("link"));
859 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
860 $pieces = count($codepieces);
861 for($i=1; $i < $pieces; $i++) {
862 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
863 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
864 $imageData=array();
865 if (strtolower($attributes["rel"])=="stylesheet" && $attributes["href"]) {
866 $imageData["ref"]=$attributes["href"]; // Finds the src or background attribute
867 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
868 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
869 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
870 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
871 $imageData["absRef"] = $this->absRef($imageData["ref"]);
872 $this->theParts["html"]["media"][]=$imageData;
873 }
874 }
875 }
876 // fixes javascript rollovers
877 $codepieces = split(quotemeta(".src"), $html_code);
878 $pieces = count($codepieces);
879 $expr = "^[^".quotemeta("\"").quotemeta("'")."]*";
880 for($i=1; $i < $pieces; $i++) {
881 $temp = $codepieces[$i];
882 $temp = trim(ereg_replace("=","",trim($temp)));
883 ereg ($expr,substr($temp,1,strlen($temp)),$reg);
884 $imageData["ref"] = $reg[0];
885 $imageData["quotes"] = substr($temp,0,1);
886 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
887 $theInfo = $this->split_fileref($imageData["ref"]);
888 switch ($theInfo["fileext"]) {
889 case "gif":
890 case "jpeg":
891 case "jpg":
892 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
893 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
894 $imageData["absRef"] = $this->absRef($imageData["ref"]);
895 $this->theParts["html"]["media"][]=$imageData;
896 }
897 break;
898 }
899 }
900 }
901
902 /**
903 * [Describe function...]
904 *
905 * @return [type] ...
906 */
907 function extractHyperLinks() {
908 // extracts all hyper-links from $this->theParts["html"]["content"]
909 $html_code = $this->theParts["html"]["content"];
910 $attribRegex = $this->tag_regex(Array("a","form","area"));
911 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
912 $len=strlen($codepieces[0]);
913 $pieces = count($codepieces);
914 for($i=1; $i < $pieces; $i++) {
915 $tag = strtolower(strtok(substr($html_code,$len+1,10)," "));
916 $len+=strlen($tag)+strlen($codepieces[$i])+2;
917
918 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
919 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
920 $hrefData="";
921 if ($attributes["href"]) {$hrefData["ref"]=$attributes["href"];} else {$hrefData["ref"]=$attributes["action"];}
922 if ($hrefData["ref"]) {
923 $hrefData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $hrefData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
924 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron
925 if ($hrefData["ref"] && substr(trim($hrefData["ref"]),0,1)!="#" && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) {
926 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|";
927 $hrefData["absRef"] = $this->absRef($hrefData["ref"]);
928 $hrefData["tag"]=$tag;
929 $this->theParts["html"]["hrefs"][]=$hrefData;
930 }
931 }
932 }
933 // Extracts TYPO3 specific links made by the openPic() JS function
934 $codepieces = explode("onClick=\"openPic('", $html_code);
935 $pieces = count($codepieces);
936 for($i=1; $i < $pieces; $i++) {
937 $showpic_linkArr = explode("'",$codepieces[$i]);
938 $hrefData["ref"]=$showpic_linkArr[0];
939 if ($hrefData["ref"]) {
940 $hrefData["quotes"]="'"; // Finds out if the value had quotes around it
941 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron
942 if ($hrefData["ref"] && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) {
943 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|";
944 $hrefData["absRef"] = $this->absRef($hrefData["ref"]);
945 $this->theParts["html"]["hrefs"][]=$hrefData;
946 }
947 }
948 }
949 }
950
951 /**
952 * [Describe function...]
953 *
954 * @return [type] ...
955 */
956 function extractFramesInfo() {
957 // extracts all media-links from $this->theParts["html"]["content"]
958 $html_code = $this->theParts["html"]["content"];
959 if (strpos(" ".$html_code,"<frame ")) {
960 $attribRegex = $this->tag_regex("frame");
961 $codepieces = split($attribRegex, $html_code, 1000000 ); // Splits the document by the beginning of the above tags
962 $pieces = count($codepieces);
963 for($i=1; $i < $pieces; $i++) {
964 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
965 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
966 $frame="";
967 $frame["src"]=$attributes["src"];
968 $frame["name"]=$attributes["name"];
969 $frame["absRef"] = $this->absRef($frame["src"]);
970 $theInfo[] = $frame;
971 }
972 return $theInfo;
973 }
974 }
975
976 /**
977 * [Describe function...]
978 *
979 * @param [type] $absolute: ...
980 * @return [type] ...
981 */
982 function substMediaNamesInHTML($absolute) {
983 // This substitutes the media-references in $this->theParts["html"]["content"]
984 // If $absolute is true, then the refs are substituted with http:// ref's indstead of Content-ID's (cid).
985 if (is_array($this->theParts["html"]["media"])) {
986 reset ($this->theParts["html"]["media"]);
987 while (list($key,$val) = each ($this->theParts["html"]["media"])) {
988 if ($val["use_jumpurl"] && $this->jumperURL_prefix) {
989 $theSubstVal = $this->jumperURL_prefix.rawurlencode($val["absRef"]);
990 } else {
991 $theSubstVal = ($absolute) ? $val["absRef"] : "cid:part".$key.".".$this->messageid;
992 }
993 $this->theParts["html"]["content"] = str_replace(
994 $val["subst_str"],
995 $val["quotes"].$theSubstVal.$val["quotes"],
996 $this->theParts["html"]["content"] );
997 }
998 }
999 if (!$absolute) {
1000 $this->fixRollOvers();
1001 }
1002 }
1003
1004 /**
1005 * [Describe function...]
1006 *
1007 * @return [type] ...
1008 */
1009 function substHREFsInHTML() {
1010 // This substitutes the hrefs in $this->theParts["html"]["content"]
1011 if (is_array($this->theParts["html"]["hrefs"])) {
1012 reset ($this->theParts["html"]["hrefs"]);
1013 while (list($key,$val) = each ($this->theParts["html"]["hrefs"])) {
1014 if ($this->jumperURL_prefix && $val["tag"]!="form") { // Form elements cannot use jumpurl!
1015 if ($this->jumperURL_useId) {
1016 $theSubstVal = $this->jumperURL_prefix.$key;
1017 } else {
1018 $theSubstVal = $this->jumperURL_prefix.rawurlencode($val["absRef"]);
1019 }
1020 } else {
1021 $theSubstVal = $val["absRef"];
1022 }
1023 $this->theParts["html"]["content"] = str_replace(
1024 $val["subst_str"],
1025 $val["quotes"].$theSubstVal.$val["quotes"],
1026 $this->theParts["html"]["content"] );
1027 }
1028 }
1029 }
1030
1031 /**
1032 * [Describe function...]
1033 *
1034 * @param [type] $content: ...
1035 * @return [type] ...
1036 */
1037 function substHTTPurlsInPlainText($content) {
1038 // This substitutes the http:// urls in plain text with links
1039 if ($this->jumperURL_prefix) {
1040 $textpieces = explode("http://", $content);
1041 $pieces = count($textpieces);
1042 $textstr = $textpieces[0];
1043 for($i=1; $i<$pieces; $i++) {
1044 $len=strcspn($textpieces[$i],chr(32).chr(9).chr(13).chr(10));
1045 if (trim(substr($textstr,-1))=="" && $len) {
1046 $lastChar=substr($textpieces[$i],$len-1,1);
1047 if (!ereg("[A-Za-z0-9\/#]",$lastChar)) {$len--;} // Included "\/" 3/12
1048
1049 $parts[0]="http://".substr($textpieces[$i],0,$len);
1050 $parts[1]=substr($textpieces[$i],$len);
1051
1052 if ($this->jumperURL_useId) {
1053 $this->theParts["plain"]["link_ids"][$i]=$parts[0];
1054 $parts[0] = $this->jumperURL_prefix."-".$i;
1055 } else {
1056 $parts[0] = $this->jumperURL_prefix.rawurlencode($parts[0]);
1057 }
1058 // debug($parts);
1059 $textstr.=$parts[0].$parts[1];
1060 } else {
1061 $textstr.='http://'.$textpieces[$i];
1062 }
1063 }
1064 $content = $textstr;
1065 // debug(array($textstr));
1066 // debug(md5($textstr));
1067 // debug(md5($content));
1068 }
1069 return $content;
1070 }
1071
1072 /**
1073 * [Describe function...]
1074 *
1075 * @return [type] ...
1076 */
1077 function fixRollOvers() {
1078 // 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!!)
1079 $theNewContent = "";
1080 $theSplit = explode(".src",$this->theParts["html"]["content"]);
1081 if (count($theSplit)>1) {
1082 while(list($key,$part)=each($theSplit)) {
1083 $sub = substr($part,0,200);
1084 if (ereg("cid:part[^ \"']*",$sub,$reg)) {
1085 $thePos = strpos($part,$reg[0]); // The position of the string
1086 ereg("cid:part([^\.]*).*",$sub,$reg2); // Finds the id of the media...
1087 $theSubStr = $this->theParts["html"]["media"][intval($reg2[1])]["absRef"];
1088 if ($thePos && $theSubStr) { // ... and substitutes the javaScript rollover image with this instead
1089 if (!strpos(" ".$theSubStr,"http://")) {$theSubStr = "http://";} // If the path is NOT and url, the reference is set to nothing
1090 $part = substr($part,0,$thePos).$theSubStr.substr($part,$thePos+strlen($reg[0]),strlen($part));
1091 }
1092 }
1093 $theNewContent.= $part.((($key+1)!=count($theSplit))? ".src" : "" );
1094 }
1095 $this->theParts["html"]["content"]=$theNewContent;
1096 }
1097 }
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114 /*******************************************
1115 *
1116 * File and URL-functions
1117 *
1118 *******************************************/
1119
1120 /**
1121 * @param [type] $inputstr: ...
1122 * @return [type] ...
1123 */
1124 function makeBase64($inputstr) {
1125 // Returns base64-encoded content, which is broken every 76 character
1126 return chunk_split(base64_encode($inputstr));
1127 }
1128
1129 /**
1130 * [Describe function...]
1131 *
1132 * @param [type] $url: ...
1133 * @return [type] ...
1134 */
1135 function getExtendedURL($url) {
1136 // reads the URL or file and determines the Content-type by either guessing or opening a connection to the host
1137 $res["content"] = $this->getURL($url);
1138 if (!$res["content"]) {return false;}
1139 $pathInfo = parse_url($url);
1140 $fileInfo = $this->split_fileref($pathInfo["path"]);
1141 if ($fileInfo["fileext"] == "gif") {$res["content_type"] = "image/gif";}
1142 if ($fileInfo["fileext"] == "jpg" || $fileInfo["fileext"] == "jpeg") {$res["content_type"] = "image/jpeg";}
1143 if ($fileInfo["fileext"] == "html" || $fileInfo["fileext"] == "htm") {$res["content_type"] = "text/html";}
1144 if ($fileInfo["fileext"] == "swf") {$res["content_type"] = "application/x-shockwave-flash";}
1145 if (!$res["content_type"]) {$res["content_type"] = $this->getMimeType($url);}
1146 return $res;
1147 }
1148
1149 /**
1150 * [Describe function...]
1151 *
1152 * @param [type] $url: ...
1153 * @return [type] ...
1154 */
1155 function addUserPass($url) {
1156 $user=$this->http_username;
1157 $pass=$this->http_password;
1158 if ($user && $pass && substr($url,0,7)=="http://") {
1159 $url = "http://".$user.":".$pass."@".substr($url,7);
1160 }
1161 return $url;
1162 }
1163
1164 /**
1165 * [Describe function...]
1166 *
1167 * @param [type] $url: ...
1168 * @return [type] ...
1169 */
1170 function getURL($url) {
1171 $url = $this->addUserPass($url);
1172 // reads a url or file
1173 if($fd = @fopen($url,"rb")) {
1174 $content = "";
1175 while (!feof($fd)) {
1176 $content.=fread( $fd, 5000 );
1177 }
1178 fclose( $fd );
1179 return $content;
1180 } else {
1181 return false;
1182 }
1183 }
1184
1185 /**
1186 * [Describe function...]
1187 *
1188 * @param [type] $url: ...
1189 * @return [type] ...
1190 */
1191 function getStrippedURL($url) {
1192 // 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
1193 if($fd = fopen($url,"rb")) {
1194 $content = "";
1195 while (!feof($fd)) {
1196 $line = fgetss($fd, 5000);
1197 if (trim($line)) {
1198 $content.=trim($line)."\n";
1199 }
1200 }
1201 fclose( $fd );
1202 return $content;
1203 }
1204 }
1205
1206 /**
1207 * [Describe function...]
1208 *
1209 * @param [type] $url: ...
1210 * @return [type] ...
1211 */
1212 function getMimeType($url) {
1213 // Opens a connection to the server and returns the mime-type of the file
1214 // takes url only
1215 $pathInfo = parse_url($url);
1216 if (!$pathInfo["scheme"]) {return false;}
1217 $getAdr = ($pathInfo["query"])?$pathInfo["path"]."?".$pathInfo["query"]:$pathInfo["path"];
1218 $fp = fsockopen($pathInfo["host"], 80, $errno, $errstr);
1219 if(!$fp) {
1220 return false;
1221 } else {
1222 fputs($fp,"GET ".$getAdr." HTTP/1.0\n\n");
1223 while(!feof($fp)) {
1224 $thePortion= fgets($fp,128);
1225 if (eregi("(^Content-Type: )(.*)",trim($thePortion), $reg)) {
1226 $res = trim($reg[2]);
1227 break;
1228 }
1229 }
1230 fclose($fp);
1231 }
1232 return $res;
1233 }
1234
1235 /**
1236 * [Describe function...]
1237 *
1238 * @param [type] $ref: ...
1239 * @return [type] ...
1240 */
1241 function absRef($ref) {
1242 // Returns the absolute address of a link. This is based on $this->theParts["html"]["path"] being the root-address
1243 $ref = trim($ref);
1244 $urlINFO = parse_url($ref);
1245 if ($urlINFO["scheme"]) {
1246 return $ref;
1247 } elseif (eregi("^/",$ref)){
1248 $addr = parse_url($this->theParts["html"]["path"]);
1249 return $addr["scheme"]."://".$addr["host"].$ref;
1250 } else {
1251 return $this->theParts["html"]["path"].$ref; // If the reference is relative, the path is added, in order for us to fetch the content
1252 }
1253 }
1254
1255 /**
1256 * [Describe function...]
1257 *
1258 * @param [type] $fileref: ...
1259 * @return [type] ...
1260 */
1261 function split_fileref($fileref) {
1262 // Returns an array with path, filename, filebody, fileext.
1263 if ( ereg("(.*/)(.*)$",$fileref,$reg) ) {
1264 $info["path"] = $reg[1];
1265 $info["file"] = $reg[2];
1266 } else {
1267 $info["path"] = "";
1268 $info["file"] = $fileref;
1269 }
1270 $reg="";
1271 if ( ereg("(.*)\.([^\.]*$)",$info["file"],$reg) ) {
1272 $info["filebody"] = $reg[1];
1273 $info["fileext"] = strtolower($reg[2]);
1274 $info["realFileext"] = $reg[2];
1275 } else {
1276 $info["filebody"] = $info["file"];
1277 $info["fileext"] = "";
1278 }
1279 return $info;
1280 }
1281
1282 /**
1283 * [Describe function...]
1284 *
1285 * @param [type] $path: ...
1286 * @return [type] ...
1287 */
1288 function extParseUrl($path) {
1289 // Returns an array with file or url-information
1290 $res = parse_url($path);
1291 ereg("(.*/)([^/]*)$",$res["path"],$reg);
1292 $res["filepath"]=$reg[1];
1293 $res["filename"]=$reg[2];
1294 return $res;
1295 }
1296
1297 /**
1298 * [Describe function...]
1299 *
1300 * @param [type] $tagArray: ...
1301 * @return [type] ...
1302 */
1303 function tag_regex($tagArray) {
1304 if (!is_array($tagArray)) {
1305 $tagArray=Array($tagArray);
1306 }
1307 $theRegex = "";
1308 $c=count($tagArray);
1309 while(list(,$tag)=each($tagArray)) {
1310 $c--;
1311 $theRegex.="<".sql_regcase($tag)."[[:space:]]".(($c)?"|":"");
1312 }
1313 return $theRegex;
1314 }
1315
1316 /**
1317 * analyses a HTML-tag
1318 * $tag is either like this "<TAG OPTION ATTRIB=VALUE>" or this " OPTION ATTRIB=VALUE>" which means you can omit the tag-name
1319 * returns an array with the attributes as keys in lower-case
1320 * If an attribute is empty (like OPTION) the value of that key is just empty. Check it with is_set();
1321 *
1322 * @param [type] $tag: ...
1323 * @return [type] ...
1324 */
1325 function get_tag_attributes($tag) {
1326 $attributes = Array();
1327 $tag = ltrim(eregi_replace ("^<[^ ]*","",trim($tag)));
1328 $tagLen = strlen($tag);
1329 $safetyCounter = 100;
1330 // Find attribute
1331 while ($tag) {
1332 $value = "";
1333 $reg = split("[[:space:]=>]",$tag,2);
1334 $attrib = $reg[0];
1335
1336 $tag = ltrim(substr($tag,strlen($attrib),$tagLen));
1337 if (substr($tag,0,1)=="=") {
1338 $tag = ltrim(substr($tag,1,$tagLen));
1339 if (substr($tag,0,1)=='"') { // Quotes around the value
1340 $reg = explode('"',substr($tag,1,$tagLen),2);
1341 $tag = ltrim($reg[1]);
1342 $value = $reg[0];
1343 } else { // No qoutes around value
1344 ereg("^([^[:space:]>]*)(.*)",$tag,$reg);
1345 $value = trim($reg[1]);
1346 $tag = ltrim($reg[2]);
1347 if (substr($tag,0,1)==">") {
1348 $tag ="";
1349 }
1350 }
1351 }
1352 $attributes[strtolower($attrib)]=$value;
1353 $safetyCounter--;
1354 if ($safetyCounter<0) {break;}
1355 }
1356 return $attributes;
1357 }
1358
1359 /**
1360 * Implementation of quoted-printable encode.
1361 * This function was a duplicate of t3lib_div::quoted_printable, thus it's going to be removed.
1362 *
1363 * @param string Content to encode
1364 * @return string The QP encoded string
1365 * @obsolete
1366 */
1367 function quoted_printable($string) {
1368 return t3lib_div::quoted_printable($string, 76);
1369 }
1370
1371 /**
1372 * [Describe function...]
1373 *
1374 * @param [type] $name: ...
1375 * @return [type] ...
1376 */
1377 function convertName($name) {
1378 if (ereg("[^".chr(32)."-".chr(60).chr(62)."-".chr(127)."]",$name)) {
1379 return '=?iso-8859-1?B?'.base64_encode($name).'?=';
1380 } else {
1381 return $name;
1382 }
1383 }
1384 }
1385
1386 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']) {
1387 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']);
1388 }
1389 ?>