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