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