* Updated my email address from "kasper@typo3.com" (which is closed and will stay...
[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 mail( $this->from_email,
647 $theParts[0],
648 $theParts[1],
649 "From: ".$this->recipient,
650 $returnPath);
651 }
652 if($this->returnPath) {
653 ini_restore(sendmail_from);
654 }
655 return true;
656 } else {return false;}
657 }
658
659 /**
660 * [Describe function...]
661 *
662 * @return [type] ...
663 */
664 function getBoundary() {
665 // Returns boundaries
666 $this->part++;
667 return "----------".uniqid("part_".$this->part."_");
668 }
669
670 /**
671 * [Describe function...]
672 *
673 * @param [type] $content: ...
674 * @return [type] ...
675 */
676 function setPlain ($content) {
677 // Sets the plain-text part. No processing done.
678 $this->theParts["plain"]["content"] = $content;
679 }
680
681 /**
682 * [Describe function...]
683 *
684 * @param [type] $content: ...
685 * @return [type] ...
686 */
687 function setHtml ($content) {
688 // Sets the HTML-part. No processing done.
689 $this->theParts["html"]["content"] = $content;
690 }
691
692 /**
693 * [Describe function...]
694 *
695 * @param [type] $header: ...
696 * @return [type] ...
697 */
698 function add_header ($header) {
699 // Adds a header to the mail. Use this AFTER the setHeaders()-function
700 $this->headers.=$header."\n";
701 }
702
703 /**
704 * [Describe function...]
705 *
706 * @param [type] $string: ...
707 * @return [type] ...
708 */
709 function add_message ($string) {
710 // Adds a line of text to the mail-body. Is normally use internally
711 $this->message.=$string."\n";
712 }
713
714 /**
715 * [Describe function...]
716 *
717 * @param [type] $type: ...
718 * @return [type] ...
719 */
720 function getContent($type) {
721 return $this->theParts[$type]["content"];
722 }
723
724 /**
725 * [Describe function...]
726 *
727 * @return [type] ...
728 */
729 function preview() {
730 echo nl2br(HTMLSpecialChars($this->headers));
731 echo "<BR>";
732 echo nl2br(HTMLSpecialChars($this->message));
733 }
734
735
736
737
738
739
740
741
742
743
744
745
746
747 /****************************************************
748 *
749 * Functions for acquiring attachments, HTML, analyzing and so on **
750 *
751 ***************************************************/
752
753 /**
754 * @param [type] $file: ...
755 * @return [type] ...
756 */
757 function fetchHTML($file) {
758 // Fetches the HTML-content from either url og local serverfile
759 $this->theParts["html"]["content"] = $this->getURL($file); // Fetches the content of the page
760 if ($this->theParts["html"]["content"]) {
761 $addr = $this->extParseUrl($file);
762 $path = ($addr["scheme"]) ? $addr["scheme"]."://".$addr["host"].(($addr["filepath"])?$addr["filepath"]:"/") : $addr["filepath"];
763 $this->theParts["html"]["path"] = $path;
764 return true;
765 } else {
766 return false;
767 }
768 }
769
770 /**
771 * [Describe function...]
772 *
773 * @return [type] ...
774 */
775 function fetchHTMLMedia() {
776 // Fetches the mediafiles which are found by extractMediaLinks()
777 if (is_array($this->theParts["html"]["media"])) {
778 reset ($this->theParts["html"]["media"]);
779 if (count($this->theParts["html"]["media"]) > 0) {
780 while (list($key,$media) = each ($this->theParts["html"]["media"])) {
781 $picdata = $this->getExtendedURL($this->theParts["html"]["media"][$key]["absRef"]); // We fetch the content and the mime-type
782 if (is_array($picdata)) {
783 $this->theParts["html"]["media"][$key]["content"] = $picdata["content"];
784 $this->theParts["html"]["media"][$key]["ctype"] = $picdata["content_type"];
785 }
786 }
787 }
788 }
789 }
790
791 /**
792 * [Describe function...]
793 *
794 * @return [type] ...
795 */
796 function extractMediaLinks() {
797 // extracts all media-links from $this->theParts["html"]["content"]
798 $html_code = $this->theParts["html"]["content"];
799 $attribRegex = $this->tag_regex(Array("img","table","td","tr","body","iframe","script","input","embed"));
800 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
801 $len=strlen($codepieces[0]);
802 $pieces = count($codepieces);
803 for($i=1; $i < $pieces; $i++) {
804 $tag = strtolower(strtok(substr($html_code,$len+1,10)," "));
805 $len+=strlen($tag)+strlen($codepieces[$i])+2;
806 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
807 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
808 $imageData=array();
809 $imageData["ref"]=($attributes["src"]) ? $attributes["src"] : $attributes["background"]; // Finds the src or background attribute
810 if ($imageData["ref"]) {
811 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
812 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
813 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
814 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
815 $imageData["absRef"] = $this->absRef($imageData["ref"]);
816 $imageData["tag"]=$tag;
817 $imageData["use_jumpurl"]=$attributes["dmailerping"]?1:0;
818 $this->theParts["html"]["media"][]=$imageData;
819 }
820 }
821 }
822 // Extracts stylesheets
823 $attribRegex = $this->tag_regex(Array("link"));
824 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
825 $pieces = count($codepieces);
826 for($i=1; $i < $pieces; $i++) {
827 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
828 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
829 $imageData=array();
830 if (strtolower($attributes["rel"])=="stylesheet" && $attributes["href"]) {
831 $imageData["ref"]=$attributes["href"]; // Finds the src or background attribute
832 $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $imageData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
833 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
834 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
835 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
836 $imageData["absRef"] = $this->absRef($imageData["ref"]);
837 $this->theParts["html"]["media"][]=$imageData;
838 }
839 }
840 }
841 // fixes javascript rollovers
842 $codepieces = split(quotemeta(".src"), $html_code);
843 $pieces = count($codepieces);
844 $expr = "^[^".quotemeta("\"").quotemeta("'")."]*";
845 for($i=1; $i < $pieces; $i++) {
846 $temp = $codepieces[$i];
847 $temp = trim(ereg_replace("=","",trim($temp)));
848 ereg ($expr,substr($temp,1,strlen($temp)),$reg);
849 $imageData["ref"] = $reg[0];
850 $imageData["quotes"] = substr($temp,0,1);
851 $imageData["subst_str"] = $imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is the string to look for, when substituting lateron
852 $theInfo = $this->split_fileref($imageData["ref"]);
853 switch ($theInfo["fileext"]) {
854 case "gif":
855 case "jpeg":
856 case "jpg":
857 if ($imageData["ref"] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
858 $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
859 $imageData["absRef"] = $this->absRef($imageData["ref"]);
860 $this->theParts["html"]["media"][]=$imageData;
861 }
862 break;
863 }
864 }
865 }
866
867 /**
868 * [Describe function...]
869 *
870 * @return [type] ...
871 */
872 function extractHyperLinks() {
873 // extracts all hyper-links from $this->theParts["html"]["content"]
874 $html_code = $this->theParts["html"]["content"];
875 $attribRegex = $this->tag_regex(Array("a","form","area"));
876 $codepieces = split($attribRegex, $html_code); // Splits the document by the beginning of the above tags
877 $len=strlen($codepieces[0]);
878 $pieces = count($codepieces);
879 for($i=1; $i < $pieces; $i++) {
880 $tag = strtolower(strtok(substr($html_code,$len+1,10)," "));
881 $len+=strlen($tag)+strlen($codepieces[$i])+2;
882
883 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
884 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
885 $hrefData="";
886 if ($attributes["href"]) {$hrefData["ref"]=$attributes["href"];} else {$hrefData["ref"]=$attributes["action"];}
887 if ($hrefData["ref"]) {
888 $hrefData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i], $hrefData["ref"])-1,1)=='"')?'"':''; // Finds out if the value had quotes around it
889 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron
890 if ($hrefData["ref"] && substr(trim($hrefData["ref"]),0,1)!="#" && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) {
891 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|";
892 $hrefData["absRef"] = $this->absRef($hrefData["ref"]);
893 $hrefData["tag"]=$tag;
894 $this->theParts["html"]["hrefs"][]=$hrefData;
895 }
896 }
897 }
898 // Extracts TYPO3 specific links made by the openPic() JS function
899 $codepieces = explode("onClick=\"openPic('", $html_code);
900 $pieces = count($codepieces);
901 for($i=1; $i < $pieces; $i++) {
902 $showpic_linkArr = explode("'",$codepieces[$i]);
903 $hrefData["ref"]=$showpic_linkArr[0];
904 if ($hrefData["ref"]) {
905 $hrefData["quotes"]="'"; // Finds out if the value had quotes around it
906 $hrefData["subst_str"] = $hrefData["quotes"].$hrefData["ref"].$hrefData["quotes"]; // subst_str is the string to look for, when substituting lateron
907 if ($hrefData["ref"] && !strstr($this->href_fullpath_list,"|".$hrefData["subst_str"]."|")) {
908 $this->href_fullpath_list.="|".$hrefData["subst_str"]."|";
909 $hrefData["absRef"] = $this->absRef($hrefData["ref"]);
910 $this->theParts["html"]["hrefs"][]=$hrefData;
911 }
912 }
913 }
914 }
915
916 /**
917 * [Describe function...]
918 *
919 * @return [type] ...
920 */
921 function extractFramesInfo() {
922 // extracts all media-links from $this->theParts["html"]["content"]
923 $html_code = $this->theParts["html"]["content"];
924 if (strpos(" ".$html_code,"<frame ")) {
925 $attribRegex = $this->tag_regex("frame");
926 $codepieces = split($attribRegex, $html_code, 1000000 ); // Splits the document by the beginning of the above tags
927 $pieces = count($codepieces);
928 for($i=1; $i < $pieces; $i++) {
929 $dummy = eregi("[^>]*", $codepieces[$i], $reg);
930 $attributes = $this->get_tag_attributes($reg[0]); // Fetches the attributes for the tag
931 $frame="";
932 $frame["src"]=$attributes["src"];
933 $frame["name"]=$attributes["name"];
934 $frame["absRef"] = $this->absRef($frame["src"]);
935 $theInfo[] = $frame;
936 }
937 return $theInfo;
938 }
939 }
940
941 /**
942 * [Describe function...]
943 *
944 * @param [type] $absolute: ...
945 * @return [type] ...
946 */
947 function substMediaNamesInHTML($absolute) {
948 // This substitutes the media-references in $this->theParts["html"]["content"]
949 // If $absolute is true, then the refs are substituted with http:// ref's indstead of Content-ID's (cid).
950 if (is_array($this->theParts["html"]["media"])) {
951 reset ($this->theParts["html"]["media"]);
952 while (list($key,$val) = each ($this->theParts["html"]["media"])) {
953 if ($val["use_jumpurl"] && $this->jumperURL_prefix) {
954 $theSubstVal = $this->jumperURL_prefix.rawurlencode($val["absRef"]);
955 } else {
956 $theSubstVal = ($absolute) ? $val["absRef"] : "cid:part".$key.".".$this->messageid;
957 }
958 $this->theParts["html"]["content"] = str_replace(
959 $val["subst_str"],
960 $val["quotes"].$theSubstVal.$val["quotes"],
961 $this->theParts["html"]["content"] );
962 }
963 }
964 if (!$absolute) {
965 $this->fixRollOvers();
966 }
967 }
968
969 /**
970 * [Describe function...]
971 *
972 * @return [type] ...
973 */
974 function substHREFsInHTML() {
975 // This substitutes the hrefs in $this->theParts["html"]["content"]
976 if (is_array($this->theParts["html"]["hrefs"])) {
977 reset ($this->theParts["html"]["hrefs"]);
978 while (list($key,$val) = each ($this->theParts["html"]["hrefs"])) {
979 if ($this->jumperURL_prefix && $val["tag"]!="form") { // Form elements cannot use jumpurl!
980 if ($this->jumperURL_useId) {
981 $theSubstVal = $this->jumperURL_prefix.$key;
982 } else {
983 $theSubstVal = $this->jumperURL_prefix.rawurlencode($val["absRef"]);
984 }
985 } else {
986 $theSubstVal = $val["absRef"];
987 }
988 $this->theParts["html"]["content"] = str_replace(
989 $val["subst_str"],
990 $val["quotes"].$theSubstVal.$val["quotes"],
991 $this->theParts["html"]["content"] );
992 }
993 }
994 }
995
996 /**
997 * [Describe function...]
998 *
999 * @param [type] $content: ...
1000 * @return [type] ...
1001 */
1002 function substHTTPurlsInPlainText($content) {
1003 // This substitutes the http:// urls in plain text with links
1004 if ($this->jumperURL_prefix) {
1005 $textpieces = explode("http://", $content);
1006 $pieces = count($textpieces);
1007 $textstr = $textpieces[0];
1008 for($i=1; $i<$pieces; $i++) {
1009 $len=strcspn($textpieces[$i],chr(32).chr(9).chr(13).chr(10));
1010 if (trim(substr($textstr,-1))=="" && $len) {
1011 $lastChar=substr($textpieces[$i],$len-1,1);
1012 if (!ereg("[A-Za-z0-9\/#]",$lastChar)) {$len--;} // Included "\/" 3/12
1013
1014 $parts[0]="http://".substr($textpieces[$i],0,$len);
1015 $parts[1]=substr($textpieces[$i],$len);
1016
1017 if ($this->jumperURL_useId) {
1018 $this->theParts["plain"]["link_ids"][$i]=$parts[0];
1019 $parts[0] = $this->jumperURL_prefix."-".$i;
1020 } else {
1021 $parts[0] = $this->jumperURL_prefix.rawurlencode($parts[0]);
1022 }
1023 // debug($parts);
1024 $textstr.=$parts[0].$parts[1];
1025 } else {
1026 $textstr.='http://'.$textpieces[$i];
1027 }
1028 }
1029 $content = $textstr;
1030 // debug(array($textstr));
1031 // debug(md5($textstr));
1032 // debug(md5($content));
1033 }
1034 return $content;
1035 }
1036
1037 /**
1038 * [Describe function...]
1039 *
1040 * @return [type] ...
1041 */
1042 function fixRollOvers() {
1043 // 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!!)
1044 $theNewContent = "";
1045 $theSplit = explode(".src",$this->theParts["html"]["content"]);
1046 if (count($theSplit)>1) {
1047 while(list($key,$part)=each($theSplit)) {
1048 $sub = substr($part,0,200);
1049 if (ereg("cid:part[^ \"']*",$sub,$reg)) {
1050 $thePos = strpos($part,$reg[0]); // The position of the string
1051 ereg("cid:part([^\.]*).*",$sub,$reg2); // Finds the id of the media...
1052 $theSubStr = $this->theParts["html"]["media"][intval($reg2[1])]["absRef"];
1053 if ($thePos && $theSubStr) { // ... and substitutes the javaScript rollover image with this instead
1054 if (!strpos(" ".$theSubStr,"http://")) {$theSubStr = "http://";} // If the path is NOT and url, the reference is set to nothing
1055 $part = substr($part,0,$thePos).$theSubStr.substr($part,$thePos+strlen($reg[0]),strlen($part));
1056 }
1057 }
1058 $theNewContent.= $part.((($key+1)!=count($theSplit))? ".src" : "" );
1059 }
1060 $this->theParts["html"]["content"]=$theNewContent;
1061 }
1062 }
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079 /*******************************************
1080 *
1081 * File and URL-functions
1082 *
1083 *******************************************/
1084
1085 /**
1086 * @param [type] $inputstr: ...
1087 * @return [type] ...
1088 */
1089 function makeBase64($inputstr) {
1090 // Returns base64-encoded content, which is broken every 76 character
1091 return chunk_split(base64_encode($inputstr));
1092 }
1093
1094 /**
1095 * [Describe function...]
1096 *
1097 * @param [type] $url: ...
1098 * @return [type] ...
1099 */
1100 function getExtendedURL($url) {
1101 // reads the URL or file and determines the Content-type by either guessing or opening a connection to the host
1102 $res["content"] = $this->getURL($url);
1103 if (!$res["content"]) {return false;}
1104 $pathInfo = parse_url($url);
1105 $fileInfo = $this->split_fileref($pathInfo["path"]);
1106 if ($fileInfo["fileext"] == "gif") {$res["content_type"] = "image/gif";}
1107 if ($fileInfo["fileext"] == "jpg" || $fileInfo["fileext"] == "jpeg") {$res["content_type"] = "image/jpeg";}
1108 if ($fileInfo["fileext"] == "html" || $fileInfo["fileext"] == "htm") {$res["content_type"] = "text/html";}
1109 if ($fileInfo["fileext"] == "swf") {$res["content_type"] = "application/x-shockwave-flash";}
1110 if (!$res["content_type"]) {$res["content_type"] = $this->getMimeType($url);}
1111 return $res;
1112 }
1113
1114 /**
1115 * [Describe function...]
1116 *
1117 * @param [type] $url: ...
1118 * @return [type] ...
1119 */
1120 function addUserPass($url) {
1121 $user=$this->http_username;
1122 $pass=$this->http_password;
1123 if ($user && $pass && substr($url,0,7)=="http://") {
1124 $url = "http://".$user.":".$pass."@".substr($url,7);
1125 }
1126 return $url;
1127 }
1128
1129 /**
1130 * [Describe function...]
1131 *
1132 * @param [type] $url: ...
1133 * @return [type] ...
1134 */
1135 function getURL($url) {
1136 $url = $this->addUserPass($url);
1137 // reads a url or file
1138 if($fd = @fopen($url,"rb")) {
1139 $content = "";
1140 while (!feof($fd)) {
1141 $content.=fread( $fd, 5000 );
1142 }
1143 fclose( $fd );
1144 return $content;
1145 } else {
1146 return false;
1147 }
1148 }
1149
1150 /**
1151 * [Describe function...]
1152 *
1153 * @param [type] $url: ...
1154 * @return [type] ...
1155 */
1156 function getStrippedURL($url) {
1157 // 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
1158 if($fd = fopen($url,"rb")) {
1159 $content = "";
1160 while (!feof($fd)) {
1161 $line = fgetss($fd, 5000);
1162 if (trim($line)) {
1163 $content.=trim($line)."\n";
1164 }
1165 }
1166 fclose( $fd );
1167 return $content;
1168 }
1169 }
1170
1171 /**
1172 * [Describe function...]
1173 *
1174 * @param [type] $url: ...
1175 * @return [type] ...
1176 */
1177 function getMimeType($url) {
1178 // Opens a connection to the server and returns the mime-type of the file
1179 // takes url only
1180 $pathInfo = parse_url($url);
1181 if (!$pathInfo["scheme"]) {return false;}
1182 $getAdr = ($pathInfo["query"])?$pathInfo["path"]."?".$pathInfo["query"]:$pathInfo["path"];
1183 $fp = fsockopen($pathInfo["host"], 80, $errno, $errstr);
1184 if(!$fp) {
1185 return false;
1186 } else {
1187 fputs($fp,"GET ".$getAdr." HTTP/1.0\n\n");
1188 while(!feof($fp)) {
1189 $thePortion= fgets($fp,128);
1190 if (eregi("(^Content-Type: )(.*)",trim($thePortion), $reg)) {
1191 $res = trim($reg[2]);
1192 break;
1193 }
1194 }
1195 fclose($fp);
1196 }
1197 return $res;
1198 }
1199
1200 /**
1201 * [Describe function...]
1202 *
1203 * @param [type] $ref: ...
1204 * @return [type] ...
1205 */
1206 function absRef($ref) {
1207 // Returns the absolute address of a link. This is based on $this->theParts["html"]["path"] being the root-address
1208 $ref = trim($ref);
1209 $urlINFO = parse_url($ref);
1210 if ($urlINFO["scheme"]) {
1211 return $ref;
1212 } elseif (eregi("^/",$ref)){
1213 $addr = parse_url($this->theParts["html"]["path"]);
1214 return $addr["scheme"]."://".$addr["host"].$ref;
1215 } else {
1216 return $this->theParts["html"]["path"].$ref; // If the reference is relative, the path is added, in order for us to fetch the content
1217 }
1218 }
1219
1220 /**
1221 * [Describe function...]
1222 *
1223 * @param [type] $fileref: ...
1224 * @return [type] ...
1225 */
1226 function split_fileref($fileref) {
1227 // Returns an array with path, filename, filebody, fileext.
1228 if ( ereg("(.*/)(.*)$",$fileref,$reg) ) {
1229 $info["path"] = $reg[1];
1230 $info["file"] = $reg[2];
1231 } else {
1232 $info["path"] = "";
1233 $info["file"] = $fileref;
1234 }
1235 $reg="";
1236 if ( ereg("(.*)\.([^\.]*$)",$info["file"],$reg) ) {
1237 $info["filebody"] = $reg[1];
1238 $info["fileext"] = strtolower($reg[2]);
1239 $info["realFileext"] = $reg[2];
1240 } else {
1241 $info["filebody"] = $info["file"];
1242 $info["fileext"] = "";
1243 }
1244 return $info;
1245 }
1246
1247 /**
1248 * [Describe function...]
1249 *
1250 * @param [type] $path: ...
1251 * @return [type] ...
1252 */
1253 function extParseUrl($path) {
1254 // Returns an array with file or url-information
1255 $res = parse_url($path);
1256 ereg("(.*/)([^/]*)$",$res["path"],$reg);
1257 $res["filepath"]=$reg[1];
1258 $res["filename"]=$reg[2];
1259 return $res;
1260 }
1261
1262 /**
1263 * [Describe function...]
1264 *
1265 * @param [type] $tagArray: ...
1266 * @return [type] ...
1267 */
1268 function tag_regex($tagArray) {
1269 if (!is_array($tagArray)) {
1270 $tagArray=Array($tagArray);
1271 }
1272 $theRegex = "";
1273 $c=count($tagArray);
1274 while(list(,$tag)=each($tagArray)) {
1275 $c--;
1276 $theRegex.="<".sql_regcase($tag)."[[:space:]]".(($c)?"|":"");
1277 }
1278 return $theRegex;
1279 }
1280
1281 /**
1282 * analyses a HTML-tag
1283 * $tag is either like this "<TAG OPTION ATTRIB=VALUE>" or this " OPTION ATTRIB=VALUE>" which means you can omit the tag-name
1284 * returns an array with the attributes as keys in lower-case
1285 * If an attribute is empty (like OPTION) the value of that key is just empty. Check it with is_set();
1286 *
1287 * @param [type] $tag: ...
1288 * @return [type] ...
1289 */
1290 function get_tag_attributes($tag) {
1291 $attributes = Array();
1292 $tag = ltrim(eregi_replace ("^<[^ ]*","",trim($tag)));
1293 $tagLen = strlen($tag);
1294 $safetyCounter = 100;
1295 // Find attribute
1296 while ($tag) {
1297 $value = "";
1298 $reg = split("[[:space:]=>]",$tag,2);
1299 $attrib = $reg[0];
1300
1301 $tag = ltrim(substr($tag,strlen($attrib),$tagLen));
1302 if (substr($tag,0,1)=="=") {
1303 $tag = ltrim(substr($tag,1,$tagLen));
1304 if (substr($tag,0,1)=='"') { // Quotes around the value
1305 $reg = explode('"',substr($tag,1,$tagLen),2);
1306 $tag = ltrim($reg[1]);
1307 $value = $reg[0];
1308 } else { // No qoutes around value
1309 ereg("^([^[:space:]>]*)(.*)",$tag,$reg);
1310 $value = trim($reg[1]);
1311 $tag = ltrim($reg[2]);
1312 if (substr($tag,0,1)==">") {
1313 $tag ="";
1314 }
1315 }
1316 }
1317 $attributes[strtolower($attrib)]=$value;
1318 $safetyCounter--;
1319 if ($safetyCounter<0) {break;}
1320 }
1321 return $attributes;
1322 }
1323
1324 /**
1325 * [Describe function...]
1326 *
1327 * @param [type] $string: ...
1328 * @return [type] ...
1329 */
1330 function quoted_printable($string) {
1331 // 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!
1332 $newString = "";
1333 $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
1334 while (list(,$val)=each($theLines)) {
1335 $val = ereg_replace(chr(13)."$","",$val); // removes possible character 13 at the end of line
1336
1337 $newVal = "";
1338 $theValLen = strlen($val);
1339 $len = 0;
1340 for ($index=0;$index<$theValLen;$index++) {
1341 $char = substr($val,$index,1);
1342 $ordVal =Ord($char);
1343 if ($len>(76-4) || ($len>(66-4)&&$ordVal==32)) {
1344 $len=0;
1345 $newVal.="=".chr(13).chr(10);
1346 }
1347 if (($ordVal>=33 && $ordVal<=60) || ($ordVal>=62 && $ordVal<=126) || $ordVal==9 || $ordVal==32) {
1348 $newVal.=$char;
1349 $len++;
1350 } else {
1351 $newVal.=sprintf("=%02X",$ordVal);
1352 $len+=3;
1353 }
1354 }
1355 $newVal = ereg_replace(chr(32)."$","=20",$newVal); // replaces a possible SPACE-character at the end of a line
1356 $newVal = ereg_replace(chr(9)."$","=09",$newVal); // replaces a possible TAB-character at the end of a line
1357 $newString.=$newVal.chr(13).chr(10);
1358 }
1359 return $newString;
1360 }
1361
1362 /**
1363 * [Describe function...]
1364 *
1365 * @param [type] $name: ...
1366 * @return [type] ...
1367 */
1368 function convertName($name) {
1369 if (ereg("[^".chr(32)."-".chr(60).chr(62)."-".chr(127)."]",$name)) {
1370 return '=?iso-8859-1?B?'.base64_encode($name).'?=';
1371 } else {
1372 return $name;
1373 }
1374 }
1375 }
1376
1377 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']) {
1378 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']);
1379 }
1380 ?>