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