00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 class t3lib_htmlmail {
00184
00185 var $recipient = '';
00186 var $recipient_copy = '';
00187 var $recipient_blindcopy = '';
00188 var $subject = '';
00189 var $from_email = '';
00190 var $from_name = '';
00191 var $replyto_email = '';
00192 var $replyto_name = '';
00193 var $organisation = '';
00194 var $priority = 3;
00195 var $mailer = '';
00196 var $alt_base64 = 0;
00197 var $alt_8bit = 0;
00198 var $jumperURL_prefix = '';
00199 var $jumperURL_useId = 0;
00200 var $mediaList = '';
00201 var $http_password = '';
00202 var $http_username = '';
00203 var $postfix_version1 = false;
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 var $theParts = array();
00222
00223 var $messageid = '';
00224 var $returnPath = '';
00225 var $Xid = '';
00226 var $dontEncodeHeader = false;
00227
00228 var $headers = '';
00229 var $message = '';
00230 var $part = 0;
00231 var $image_fullpath_list = '';
00232 var $href_fullpath_list = '';
00233
00234 var $plain_text_header = '';
00235 var $html_text_header = '';
00236 var $charset = '';
00237 var $defaultCharset = 'iso-8859-1';
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 public function t3lib_htmlmail() {
00249 $this->forceReturnPath = $GLOBALS['TYPO3_CONF_VARS']['SYS']['forceReturnPath'];
00250
00251 $this->mailer = 'TYPO3 '.TYPO3_version;
00252 }
00253
00254
00255
00256
00257
00258
00259
00260 public function start() {
00261 global $TYPO3_CONF_VARS;
00262
00263
00264 $host = t3lib_div::getHostname();
00265 if (!$host || $host == '127.0.0.1' || $host == 'localhost' || $host == 'localhost.localdomain') {
00266 $host = ($TYPO3_CONF_VARS['SYS']['sitename'] ? preg_replace('/[^A-Za-z0-9_\-]/', '_', $TYPO3_CONF_VARS['SYS']['sitename']) : 'localhost') . '.TYPO3';
00267 }
00268 $this->messageid = md5(microtime()) . '@' . $host;
00269
00270
00271
00272 $this->linebreak = LF;
00273
00274
00275 if (TYPO3_OS == 'WIN') {
00276 $this->linebreak = CRLF;
00277 }
00278
00279
00280 if (!$this->charset) {
00281 if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->renderCharset) {
00282 $this->charset = $GLOBALS['TSFE']->renderCharset;
00283 } elseif (is_object($GLOBALS['LANG']) && $GLOBALS['LANG']->charSet) {
00284 $this->charset = $GLOBALS['LANG']->charSet;
00285 } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) {
00286 $this->charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
00287 } else {
00288 $this->charset = $this->defaultCharset;
00289 }
00290 }
00291
00292
00293 $this->useQuotedPrintable();
00294 }
00295
00296
00297
00298
00299
00300
00301
00302 public function useQuotedPrintable() {
00303 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: quoted-printable';
00304 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: quoted-printable';
00305 }
00306
00307
00308
00309
00310
00311
00312 public function useBase64() {
00313 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: base64';
00314 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: base64';
00315 $this->alt_base64 = 1;
00316 }
00317
00318
00319
00320
00321
00322
00323
00324 public function use8Bit() {
00325 $this->plain_text_header = 'Content-Type: text/plain; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: 8bit';
00326 $this->html_text_header = 'Content-Type: text/html; charset='.$this->charset.$this->linebreak.'Content-Transfer-Encoding: 8bit';
00327 $this->alt_8bit = 1;
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 public function encodeMsg($content) {
00339 if ($this->alt_base64) {
00340 return $this->makeBase64($content);
00341 } elseif ($this->alt_8bit) {
00342 return $content;
00343 } else {
00344 return t3lib_div::quoted_printable($content);
00345 }
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
00355 public function addPlain($content) {
00356 $content = $this->substHTTPurlsInPlainText($content);
00357 $this->setPlain($this->encodeMsg($content));
00358 }
00359
00360
00361
00362
00363
00364
00365
00366
00367 public function addAttachment($file) {
00368
00369 $fileInfo = $this->getExtendedURL($file);
00370 if ($fileInfo) {
00371 if (!$fileInfo['content_type']) {
00372 $fileInfo['content_type'] = 'application/octet-stream';
00373 }
00374 $temp = $this->split_fileref($file);
00375 if ($temp['file']) {
00376 $fileInfo['filename'] = $temp['file'];
00377 } elseif (strpos(' '.$fileInfo['content_type'], 'htm')) {
00378 $fileInfo['filename'] = 'index.html';
00379 } else {
00380 $fileInfo['filename'] = 'unknown';
00381 }
00382 $this->theParts['attach'][] = $fileInfo;
00383 return true;
00384 }
00385 return false;
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395 public function addHTML($file) {
00396 $status = $this->fetchHTML($file);
00397 if (!$status) {
00398 return false;
00399 }
00400 if ($this->extractFramesInfo()) {
00401 return 'Document was a frameset. Stopped';
00402 }
00403 $this->extractMediaLinks();
00404 $this->extractHyperLinks();
00405 $this->fetchHTMLMedia();
00406 $this->substMediaNamesInHTML(0);
00407 $this->substHREFsInHTML();
00408 $this->setHtml($this->encodeMsg($this->theParts['html']['content']));
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 public function extractHtmlInit($html,$url) {
00420 $this->theParts['html']['content'] = $html;
00421 $this->theParts['html']['path'] = $url;
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431 public function send($recipient) {
00432 if ($recipient) {
00433 $this->recipient = $recipient;
00434 }
00435 $this->setHeaders();
00436 $this->setContent();
00437 $mailWasSent = $this->sendTheMail();
00438 return $mailWasSent;
00439 }
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 public function setHeaders() {
00465 $this->headers = '';
00466
00467 $this->add_header('Message-ID: <'.$this->messageid.'>');
00468
00469 if ($this->returnPath) {
00470 $this->add_header('Return-Path: '.$this->returnPath);
00471 $this->add_header('Errors-To: '.$this->returnPath);
00472 }
00473
00474 if ($this->Xid) {
00475 $this->add_header('X-Typo3MID: '.$this->Xid);
00476 }
00477
00478
00479 if ($this->from_email) {
00480 if ($this->from_name && !t3lib_div::isBrokenEmailEnvironment()) {
00481 $this->add_header('From: '.$this->from_name.' <'.$this->from_email.'>');
00482 } else {
00483 $this->add_header('From: '.$this->from_email);
00484 }
00485 }
00486
00487
00488 if ($this->recipient_copy) {
00489 $this->add_header('Cc: ' . $this->recipient_copy);
00490 }
00491
00492
00493 if ($this->recipient_blindcopy) {
00494 $this->add_header('Bcc: ' . $this->recipient_blindcopy);
00495 }
00496
00497
00498 if ($this->replyto_email) {
00499 if ($this->replyto_name) {
00500 $this->add_header('Reply-To: '.$this->replyto_name.' <'.$this->replyto_email.'>');
00501 } else {
00502 $this->add_header('Reply-To: '.$this->replyto_email);
00503 }
00504 }
00505
00506 if ($this->organisation) {
00507 $this->add_header('Organization: ' . $this->organisation);
00508 }
00509
00510 if ($this->mailer) {
00511 $this->add_header('X-Mailer: '.$this->mailer);
00512 }
00513
00514 if ($this->priority) {
00515 $this->add_header('X-Priority: '.$this->priority);
00516 }
00517 $this->add_header('Mime-Version: 1.0');
00518
00519 if (!$this->dontEncodeHeader) {
00520 $enc = $this->alt_base64 ? 'base64' : 'quoted_printable';
00521
00522 $this->recipient = t3lib_div::encodeHeader($this->recipient,$enc,$this->charset);
00523 $this->subject = t3lib_div::encodeHeader($this->subject,$enc,$this->charset);
00524 }
00525 }
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535 public function setRecipient($recipient) {
00536 $this->recipient = (is_array($recipient) ? implode(',', $recipient) : $recipient);
00537 }
00538
00539
00540
00541
00542
00543
00544
00545 public function getHTMLContentType() {
00546 return (count($this->theParts['html']['media']) ? 'multipart/related' : 'multipart/alternative');
00547 }
00548
00549
00550
00551
00552
00553
00554
00555 public function setContent() {
00556 $this->message = '';
00557 $boundary = $this->getBoundary();
00558
00559
00560 if (count($this->theParts['attach'])) {
00561
00562 $this->add_header('Content-Type: multipart/mixed;');
00563 $this->add_header(' boundary="' . $boundary . '"');
00564 $this->add_message('This is a multi-part message in MIME format.' . LF);
00565 $this->constructMixed($boundary);
00566 } elseif ($this->theParts['html']['content']) {
00567
00568 $this->add_header('Content-Type: ' . $this->getHTMLContentType() . ';');
00569 $this->add_header(' boundary="' . $boundary . '"');
00570 $this->add_message('This is a multi-part message in MIME format.' . LF);
00571 $this->constructHTML($boundary);
00572 } else {
00573
00574 $this->add_header($this->plain_text_header);
00575 $this->add_message($this->getContent('plain'));
00576 }
00577 }
00578
00579
00580
00581
00582
00583
00584
00585
00586 public function constructMixed($boundary) {
00587 $this->add_message('--' . $boundary);
00588
00589 if ($this->theParts['html']['content']) {
00590
00591 $newBoundary = $this->getBoundary();
00592 $this->add_message('Content-Type: '.$this->getHTMLContentType() . ';');
00593 $this->add_message(' boundary="' . $newBoundary . '"');
00594 $this->add_message('');
00595 $this->constructHTML($newBoundary);
00596 } else {
00597
00598 $this->add_message($this->plain_text_header);
00599 $this->add_message('');
00600 $this->add_message($this->getContent('plain'));
00601 }
00602
00603 if (is_array($this->theParts['attach'])) {
00604 foreach ($this->theParts['attach'] as $media) {
00605 $this->add_message('--' . $boundary);
00606 $this->add_message('Content-Type: ' . $media['content_type'] . ';');
00607 $this->add_message(' name="' . $media['filename'] . '"');
00608 $this->add_message('Content-Transfer-Encoding: base64');
00609 $this->add_message('Content-Disposition: attachment;');
00610 $this->add_message(' filename="' . $media['filename'] . '"');
00611 $this->add_message('');
00612 $this->add_message($this->makeBase64($media['content']));
00613 }
00614 }
00615 $this->add_message('--' . $boundary . '--' . LF);
00616 }
00617
00618
00619
00620
00621
00622
00623
00624
00625 public function constructHTML($boundary) {
00626
00627 if (count($this->theParts['html']['media'])) {
00628 $this->add_message('--' . $boundary);
00629
00630 $newBoundary = $this->getBoundary();
00631 $this->add_message('Content-Type: multipart/alternative;');
00632 $this->add_message(' boundary="' . $newBoundary . '"');
00633 $this->add_message('Content-Transfer-Encoding: 7bit');
00634 $this->add_message('');
00635
00636
00637 $this->constructAlternative($newBoundary);
00638 $this->constructHTML_media($boundary);
00639 } else {
00640
00641 $this->constructAlternative($boundary);
00642 }
00643 }
00644
00645
00646
00647
00648
00649
00650
00651
00652 public function constructAlternative($boundary) {
00653 $this->add_message('--'.$boundary);
00654
00655
00656 $this->add_message($this->plain_text_header);
00657 $this->add_message('');
00658 $this->add_message($this->getContent('plain'));
00659 $this->add_message('--' . $boundary);
00660
00661
00662 $this->add_message($this->html_text_header);
00663 $this->add_message('');
00664 $this->add_message($this->getContent('html'));
00665 $this->add_message('--' . $boundary . '--' . LF);
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675 public function constructHTML_media($boundary) {
00676
00677 if (is_array($this->theParts['html']['media'])) {
00678 foreach($this->theParts['html']['media'] as $key => $media) {
00679 if (!$this->mediaList || t3lib_div::inList($this->mediaList, $key)) {
00680 $this->add_message('--' . $boundary);
00681 $this->add_message('Content-Type: ' . $media['ctype']);
00682 $this->add_message('Content-ID: <part' . $key . '.' . $this->messageid . '>');
00683 $this->add_message('Content-Transfer-Encoding: base64');
00684 $this->add_message('');
00685 $this->add_message($this->makeBase64($media['content']));
00686 }
00687 }
00688 }
00689 $this->add_message('--' . $boundary . '--' . LF);
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 public function sendTheMail() {
00719 $mailWasSent = false;
00720
00721
00722 if (!trim($this->recipient) || !trim($this->message)) {
00723 return false;
00724 }
00725
00726
00727
00728 $returnPath = ($this->forceReturnPath && strlen($this->returnPath) > 0) ? '-f ' . escapeshellarg($this->returnPath) : '';
00729 if (TYPO3_OS == 'WIN' && $this->returnPath) {
00730 @ini_set('sendmail_from', t3lib_div::normalizeMailAddress($this->returnPath));
00731 }
00732 $recipient = t3lib_div::normalizeMailAddress($this->recipient);
00733
00734
00735 $returnPathPossible = (!ini_get('safe_mode') && $this->forceReturnPath);
00736 if ($returnPathPossible) {
00737 $mailWasSent = t3lib_utility_Mail::mail($recipient,
00738 $this->subject,
00739 $this->message,
00740 $this->headers,
00741 $returnPath);
00742 } else {
00743 $mailWasSent = t3lib_utility_Mail::mail($recipient,
00744 $this->subject,
00745 $this->message,
00746 $this->headers);
00747 }
00748
00749
00750 if ($this->auto_respond_msg) {
00751 $theParts = explode('/',$this->auto_respond_msg,2);
00752 $theParts[0] = str_replace('###SUBJECT###', $this->subject, $theParts[0]);
00753 $theParts[1] = str_replace("/",LF,$theParts[1]);
00754 $theParts[1] = str_replace("###MESSAGE###", $this->getContent('plain'), $theParts[1]);
00755 if ($returnPathPossible) {
00756 $mailWasSent = t3lib_utility_Mail::mail($this->from_email,
00757 $theParts[0],
00758 $theParts[1],
00759 'From: ' . $recipient,
00760 $returnPath);
00761 } else {
00762 $mailWasSent = t3lib_utility_Mail::mail($this->from_email,
00763 $theParts[0],
00764 $theParts[1],
00765 'From: ' . $recipient);
00766 }
00767 }
00768 if ($this->returnPath) {
00769 ini_restore('sendmail_from');
00770 }
00771 return $mailWasSent;
00772 }
00773
00774
00775
00776
00777
00778
00779
00780 public function getBoundary() {
00781 $this->part++;
00782 return "----------".uniqid("part_".$this->part."_");
00783 }
00784
00785
00786
00787
00788
00789
00790
00791
00792 public function setPlain($content) {
00793 $this->theParts['plain']['content'] = $content;
00794 }
00795
00796
00797
00798
00799
00800
00801
00802
00803 public function setHtml($content) {
00804 $this->theParts['html']['content'] = $content;
00805 }
00806
00807
00808
00809
00810
00811
00812
00813
00814 public function add_header($header) {
00815
00816 if (!$this->dontEncodeHeader && !stristr($header,'Content-Type') && !stristr($header,'Content-Transfer-Encoding')) {
00817
00818 $parts = explode(': ',$header,2);
00819 if (count($parts) == 2) {
00820 $enc = $this->alt_base64 ? 'base64' : 'quoted_printable';
00821 $parts[1] = t3lib_div::encodeHeader($parts[1], $enc, $this->charset);
00822 $header = implode(': ', $parts);
00823 }
00824 }
00825
00826 $this->headers .= $header.LF;
00827 }
00828
00829
00830
00831
00832
00833
00834
00835
00836 public function add_message($msg) {
00837 $this->message .= $msg.LF;
00838 }
00839
00840
00841
00842
00843
00844
00845
00846
00847 public function getContent($type) {
00848 return $this->theParts[$type]['content'];
00849 }
00850
00851
00852
00853
00854
00855
00856
00857 public function preview() {
00858 echo nl2br(htmlspecialchars($this->headers));
00859 echo "<BR>";
00860 echo nl2br(htmlspecialchars($this->message));
00861 }
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882 public function fetchHTML($file) {
00883
00884 $this->theParts['html']['content'] = $this->getURL($file);
00885 if ($this->theParts['html']['content']) {
00886 $addr = $this->extParseUrl($file);
00887 $path = ($addr['scheme']) ? $addr['scheme'].':
00888 $this->theParts['html']['path'] = $path;
00889 return true;
00890 } else {
00891 return false;
00892 }
00893 }
00894
00895
00896
00897
00898
00899
00900
00901 public function fetchHTMLMedia() {
00902 if (!is_array($this->theParts['html']['media']) || !count($this->theParts['html']['media'])) return;
00903 foreach ($this->theParts['html']['media'] as $key => $media) {
00904
00905 $picdata = $this->getExtendedURL($this->theParts['html']['media'][$key]['absRef']);
00906 if (is_array($picdata)) {
00907 $this->theParts['html']['media'][$key]['content'] = $picdata['content'];
00908 $this->theParts['html']['media'][$key]['ctype'] = $picdata['content_type'];
00909 }
00910 }
00911 }
00912
00913
00914
00915
00916
00917
00918
00919 public function extractMediaLinks() {
00920 $html_code = $this->theParts['html']['content'];
00921 $attribRegex = $this->tag_regex(array('img','table','td','tr','body','iframe','script','input','embed'));
00922
00923
00924 $codepieces = preg_split($attribRegex, $html_code);
00925 $len = strlen($codepieces[0]);
00926 $pieces = count($codepieces);
00927 $reg = array();
00928 for ($i = 1; $i < $pieces; $i++) {
00929 $tag = strtolower(strtok(substr($html_code,$len+1,10),' '));
00930 $len += strlen($tag)+strlen($codepieces[$i])+2;
00931 $dummy = preg_match('/[^>]*/', $codepieces[$i], $reg);
00932 $attributes = $this->get_tag_attributes($reg[0]);
00933 $imageData = array();
00934
00935
00936 $imageData['ref'] = ($attributes['src'] ? $attributes['src'] : $attributes['background']);
00937 if ($imageData['ref']) {
00938
00939 $imageData['quotes'] = (substr($codepieces[$i], strpos($codepieces[$i], $imageData['ref'])-1,1) == '"') ? '"' : '';
00940
00941 $imageData['subst_str'] = $imageData['quotes'].$imageData['ref'].$imageData['quotes'];
00942 if ($imageData['ref'] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
00943 $this->image_fullpath_list .= "|".$imageData['subst_str']."|";
00944 $imageData['absRef'] = $this->absRef($imageData['ref']);
00945 $imageData['tag'] = $tag;
00946 $imageData['use_jumpurl'] = $attributes['dmailerping']?1:0;
00947 $this->theParts['html']['media'][] = $imageData;
00948 }
00949 }
00950 }
00951
00952
00953 $attribRegex = $this->tag_regex(array('link'));
00954
00955 $codepieces = preg_split($attribRegex, $html_code);
00956 $pieces = count($codepieces);
00957 for ($i = 1; $i < $pieces; $i++) {
00958 $dummy = preg_match('/[^>]*/', $codepieces[$i], $reg);
00959
00960 $attributes = $this->get_tag_attributes($reg[0]);
00961 $imageData = array();
00962 if (strtolower($attributes['rel']) == 'stylesheet' && $attributes['href']) {
00963
00964 $imageData['ref'] = $attributes['href'];
00965
00966 $imageData['quotes'] = (substr($codepieces[$i],strpos($codepieces[$i], $imageData['ref'])-1,1) == '"') ? '"' : '';
00967
00968 $imageData['subst_str'] = $imageData['quotes'].$imageData['ref'].$imageData['quotes'];
00969 if ($imageData['ref'] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
00970 $this->image_fullpath_list .= "|".$imageData["subst_str"]."|";
00971 $imageData['absRef'] = $this->absRef($imageData["ref"]);
00972 $this->theParts['html']['media'][] = $imageData;
00973 }
00974 }
00975 }
00976
00977
00978 $codepieces = explode('.src', $html_code);
00979 $pieces = count($codepieces);
00980 $expr = '/^[^'.quotemeta('"').quotemeta("'").']*/';
00981 for($i = 1; $i < $pieces; $i++) {
00982 $temp = $codepieces[$i];
00983 $temp = trim(str_replace('=','',trim($temp)));
00984 preg_match($expr,substr($temp,1,strlen($temp)),$reg);
00985 $imageData['ref'] = $reg[0];
00986 $imageData['quotes'] = substr($temp,0,1);
00987
00988 $imageData['subst_str'] = $imageData['quotes'].$imageData['ref'].$imageData['quotes'];
00989 $theInfo = $this->split_fileref($imageData['ref']);
00990
00991 switch ($theInfo['fileext']) {
00992 case 'gif':
00993 case 'jpeg':
00994 case 'jpg':
00995 if ($imageData['ref'] && !strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
00996 $this->image_fullpath_list .= "|".$imageData['subst_str']."|";
00997 $imageData['absRef'] = $this->absRef($imageData['ref']);
00998 $this->theParts['html']['media'][] = $imageData;
00999 }
01000 break;
01001 }
01002 }
01003 }
01004
01005
01006
01007
01008
01009
01010
01011 public function extractHyperLinks() {
01012 $html_code = $this->theParts['html']['content'];
01013 $attribRegex = $this->tag_regex(array('a','form','area'));
01014 $codepieces = preg_split($attribRegex, $html_code);
01015 $len = strlen($codepieces[0]);
01016 $pieces = count($codepieces);
01017 for($i = 1; $i < $pieces; $i++) {
01018 $tag = strtolower(strtok(substr($html_code,$len+1,10)," "));
01019 $len += strlen($tag) + strlen($codepieces[$i]) + 2;
01020
01021 $dummy = preg_match('/[^>]*/', $codepieces[$i], $reg);
01022
01023 $attributes = $this->get_tag_attributes($reg[0]);
01024 $hrefData = array();
01025 $hrefData['ref'] = ($attributes['href'] ? $attributes['href'] : $hrefData['ref'] = $attributes['action']);
01026 if ($hrefData['ref']) {
01027
01028 $hrefData['quotes'] = (substr($codepieces[$i],strpos($codepieces[$i], $hrefData["ref"])-1,1) == '"') ? '"' : '';
01029
01030 $hrefData['subst_str'] = $hrefData['quotes'].$hrefData['ref'].$hrefData['quotes'];
01031 if ($hrefData['ref'] && substr(trim($hrefData['ref']),0,1) != "#" && !strstr($this->href_fullpath_list,"|".$hrefData['subst_str']."|")) {
01032 $this->href_fullpath_list .= "|".$hrefData['subst_str']."|";
01033 $hrefData['absRef'] = $this->absRef($hrefData['ref']);
01034 $hrefData['tag'] = $tag;
01035 $this->theParts['html']['hrefs'][] = $hrefData;
01036 }
01037 }
01038 }
01039
01040 $codepieces = explode("onClick=\"openPic('", $html_code);
01041 $pieces = count($codepieces);
01042 for($i = 1; $i < $pieces; $i++) {
01043 $showpic_linkArr = explode("'",$codepieces[$i]);
01044 $hrefData['ref'] = $showpic_linkArr[0];
01045 if ($hrefData['ref']) {
01046 $hrefData['quotes'] = "'";
01047
01048 $hrefData['subst_str'] = $hrefData['quotes'].$hrefData['ref'].$hrefData['quotes'];
01049 if ($hrefData['ref'] && !strstr($this->href_fullpath_list,"|".$hrefData['subst_str']."|")) {
01050 $this->href_fullpath_list .= "|".$hrefData['subst_str']."|";
01051 $hrefData['absRef'] = $this->absRef($hrefData['ref']);
01052 $this->theParts['html']['hrefs'][] = $hrefData;
01053 }
01054 }
01055 }
01056 }
01057
01058
01059
01060
01061
01062
01063
01064 public function extractFramesInfo() {
01065 $htmlCode = $this->theParts['html']['content'];
01066 $info = array();
01067 if (strpos(' '.$htmlCode,'<frame ')) {
01068 $attribRegex = $this->tag_regex('frame');
01069
01070 $codepieces = preg_split($attribRegex, $htmlCode, 1000000);
01071 $pieces = count($codepieces);
01072 for($i = 1; $i < $pieces; $i++) {
01073 $dummy = preg_match('/[^>]*/', $codepieces[$i], $reg);
01074
01075 $attributes = $this->get_tag_attributes($reg[0]);
01076 $frame = array();
01077 $frame['src'] = $attributes['src'];
01078 $frame['name'] = $attributes['name'];
01079 $frame['absRef'] = $this->absRef($frame['src']);
01080 $info[] = $frame;
01081 }
01082 return $info;
01083 }
01084 }
01085
01086
01087
01088
01089
01090
01091
01092
01093 public function substMediaNamesInHTML($absolute) {
01094 if (is_array($this->theParts['html']['media'])) {
01095 foreach ($this->theParts['html']['media'] as $key => $val) {
01096 if ($val['use_jumpurl'] && $this->jumperURL_prefix) {
01097 $subst = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($val['absRef']);
01098 } else {
01099 $subst = ($absolute) ? $val['absRef'] : 'cid:part'.$key.'.'.$this->messageid;
01100 }
01101 $this->theParts['html']['content'] = str_replace(
01102 $val['subst_str'],
01103 $val['quotes'] . $subst . $val['quotes'],
01104 $this->theParts['html']['content']);
01105 }
01106 }
01107 if (!$absolute) {
01108 $this->fixRollOvers();
01109 }
01110 }
01111
01112
01113
01114
01115
01116
01117
01118 public function substHREFsInHTML() {
01119 if (!is_array($this->theParts['html']['hrefs'])) return;
01120 foreach ($this->theParts['html']['hrefs'] as $key => $val) {
01121
01122 if ($this->jumperURL_prefix && $val['tag'] != 'form') {
01123 if ($this->jumperURL_useId) {
01124 $substVal = $this->jumperURL_prefix.$key;
01125 } else {
01126 $substVal = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($val['absRef']);
01127 }
01128 } else {
01129 $substVal = $val['absRef'];
01130 }
01131 $this->theParts['html']['content'] = str_replace(
01132 $val['subst_str'],
01133 $val['quotes'] . $substVal . $val['quotes'],
01134 $this->theParts['html']['content']);
01135 }
01136 }
01137
01138
01139
01140
01141
01142
01143
01144
01145 public function substHTTPurlsInPlainText($content) {
01146 if (!$this->jumperURL_prefix) return $content;
01147
01148 $textpieces = explode("http://", $content);
01149 $pieces = count($textpieces);
01150 $textstr = $textpieces[0];
01151 for($i = 1; $i<$pieces; $i++) {
01152 $len = strcspn($textpieces[$i],chr(32).TAB.CRLF);
01153 if (trim(substr($textstr,-1)) == '' && $len) {
01154 $lastChar = substr($textpieces[$i],$len-1,1);
01155 if (!preg_match('/[A-Za-z0-9\/#]/',$lastChar)) {
01156 $len--;
01157 }
01158
01159 $parts = array();
01160 $parts[0] = "http://".substr($textpieces[$i],0,$len);
01161 $parts[1] = substr($textpieces[$i],$len);
01162
01163 if ($this->jumperURL_useId) {
01164 $this->theParts['plain']['link_ids'][$i] = $parts[0];
01165 $parts[0] = $this->jumperURL_prefix.'-'.$i;
01166 } else {
01167 $parts[0] = $this->jumperURL_prefix.t3lib_div::rawUrlEncodeFP($parts[0]);
01168 }
01169 $textstr .= $parts[0].$parts[1];
01170 } else {
01171 $textstr .= 'http:
01172 }
01173 }
01174 return $textstr;
01175 }
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186 public function fixRollOvers() {
01187 $newContent = '';
01188 $items = explode('.src',$this->theParts['html']['content']);
01189 if (count($items) <= 1) return;
01190
01191 foreach($items as $key => $part) {
01192 $sub = substr($part, 0, 200);
01193 if (preg_match('/cid:part[^ "\']*/',$sub,$reg)) {
01194 // The position of the string
01195 $thePos = strpos($part,$reg[0]);
01196 // Finds the id of the media...
01197 preg_match('/cid:part([^\.]*).*/',$sub,$reg2);
01198 $theSubStr = $this->theParts['html']['media'][intval($reg2[1])]['absRef'];
01199 if ($thePos && $theSubStr) {
01200 // ... and substitutes the javaScript rollover image with this instead
01201 // If the path is NOT and url, the reference is set to nothing
01202 if (!strpos(' '.$theSubStr, 'http://')) {
01203 $theSubStr = 'http://';
01204 }
01205 $part = substr($part, 0, $thePos) . $theSubStr . substr($part,$thePos+strlen($reg[0]),strlen($part));
01206 }
01207 }
01208 $newContent .= $part . ((($key+1) != count($items)) ? '.src' : '');
01209 }
01210 $this->theParts['html']['content'] = $newContent;
01211 }
01212
01213
01214
01215
01216
01217
01218
01219
01220 /*******************************************
01221 *
01222 * File and URL-functions
01223 *
01224 *******************************************/
01225
01226
01227
01228
01229
01230
01231
01232 public function makeBase64($inputstr) {
01233 return chunk_split(base64_encode($inputstr));
01234 }
01235
01236
01237
01238
01239
01240
01241
01242
01243 public function getExtendedURL($url) {
01244 $res = array();
01245 $res['content'] = $this->getURL($url);
01246 if (!$res['content']) return false;
01247 $pathInfo = parse_url($url);
01248 $fileInfo = $this->split_fileref($pathInfo['path']);
01249 switch ($fileInfo['fileext']) {
01250 case 'gif':
01251 case 'png':
01252 $res['content_type'] = 'image/'.$fileInfo['fileext'];
01253 break;
01254 case 'jpg':
01255 case 'jpeg':
01256 $res['content_type'] = 'image/jpeg';
01257 break;
01258 case 'html':
01259 case 'htm':
01260 $res['content_type'] = 'text/html';
01261 break;
01262 case 'css':
01263 $res['content_type'] = 'text/css';
01264 break;
01265 case 'swf':
01266 $res['content_type'] = 'application/x-shockwave-flash';
01267 break;
01268 default:
01269 $res['content_type'] = $this->getMimeType($url);
01270 }
01271 return $res;
01272 }
01273
01274
01275
01276
01277
01278
01279
01280
01281 public function addUserPass($url) {
01282 $user = $this->http_username;
01283 $pass = $this->http_password;
01284 $matches = array();
01285 if ($user && $pass && preg_match('/^(https?:\/\/)/', $url, $matches)) {
01286 return $matches[1].$user.':'.$pass.'@'.substr($url,strlen($matches[1]));
01287 }
01288 return $url;
01289 }
01290
01291
01292
01293
01294
01295
01296
01297
01298 public function getURL($url) {
01299 $url = $this->addUserPass($url);
01300 return t3lib_div::getURL($url);
01301 }
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311 public function getStrippedURL($url) {
01312 $content = '';
01313 if ($fd = fopen($url, "rb")) {
01314 while (!feof($fd)) {
01315 $line = fgetss($fd, 5000);
01316 if (trim($line)) {
01317 $content .= trim($line) . LF;
01318 }
01319 }
01320 fclose($fd);
01321 }
01322 return $content;
01323 }
01324
01325
01326
01327
01328
01329
01330
01331
01332 public function getMimeType($url) {
01333 $mimeType = '';
01334 $headers = trim(t3lib_div::getURL($url, 2));
01335 if ($headers) {
01336 $matches = array();
01337 if (preg_match('/(Content-Type:[\s]*)([a-zA-Z_0-9\/\-\.\+]*)([\s]|$)/', $headers, $matches)) {
01338 $mimeType = trim($matches[2]);
01339 }
01340 }
01341 return $mimeType;
01342 }
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352 public function absRef($ref) {
01353 $ref = trim($ref);
01354 $info = parse_url($ref);
01355 if ($info['scheme']) {
01356 return $ref;
01357 } elseif (preg_match('/^\//',$ref)) {
01358 $addr = parse_url($this->theParts['html']['path']);
01359 return $addr['scheme'].'://'.$addr['host'].($addr['port']?':'.$addr['port']:'').$ref;
01360 } else {
01361 // If the reference is relative, the path is added, in order for us to fetch the content
01362 return $this->theParts['html']['path'] . $ref;
01363 }
01364 }
01365
01366
01367
01368
01369
01370
01371
01372
01373 public function split_fileref($fileref) {
01374 $info = array();
01375 if (preg_match('/(.*\/)(.*)$/', $fileref, $reg)) {
01376 $info['path'] = $reg[1];
01377 $info['file'] = $reg[2];
01378 } else {
01379 $info['path'] = '';
01380 $info['file'] = $fileref;
01381 }
01382 $reg = '';
01383 if (preg_match('/(.*)\.([^\.]*$)/', $info['file'], $reg)) {
01384 $info['filebody'] = $reg[1];
01385 $info['fileext'] = strtolower($reg[2]);
01386 $info['realFileext'] = $reg[2];
01387 } else {
01388 $info['filebody'] = $info['file'];
01389 $info['fileext'] = '';
01390 }
01391 return $info;
01392 }
01393
01394
01395
01396
01397
01398
01399
01400
01401 public function extParseUrl($path) {
01402 $res = parse_url($path);
01403 preg_match('/(.*\/)([^\/]*)$/', $res['path'], $reg);
01404 $res['filepath'] = $reg[1];
01405 $res['filename'] = $reg[2];
01406 return $res;
01407 }
01408
01409
01410
01411
01412
01413
01414
01415
01416 public function tag_regex($tags) {
01417 $tags = (!is_array($tags) ? array($tags) : $tags);
01418 $regexp = '/';
01419 $c = count($tags);
01420 foreach($tags as $tag) {
01421 $c--;
01422 $regexp .= '<' . sql_regcase($tag) . "[[:space:]]" . (($c) ? '|' : '');
01423 }
01424 return $regexp . '/';
01425 }
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436 public function get_tag_attributes($tag) {
01437 $attributes = array();
01438 $tag = ltrim(preg_replace('/^<[^ ]*/','',trim($tag)));
01439 $tagLen = strlen($tag);
01440 $safetyCounter = 100;
01441 // Find attribute
01442 while ($tag) {
01443 $value = '';
01444 $reg = preg_split('/[[:space:]=>]/', $tag, 2);
01445 $attrib = $reg[0];
01446
01447 $tag = ltrim(substr($tag,strlen($attrib),$tagLen));
01448 if (substr($tag,0,1) == '=') {
01449 $tag = ltrim(substr($tag,1,$tagLen));
01450 if (substr($tag,0,1) == '"') {
01451
01452 $reg = explode('"',substr($tag,1,$tagLen),2);
01453 $tag = ltrim($reg[1]);
01454 $value = $reg[0];
01455 } else {
01456
01457 preg_match('/^([^[:space:]>]*)(.*)/',$tag,$reg);
01458 $value = trim($reg[1]);
01459 $tag = ltrim($reg[2]);
01460 if (substr($tag,0,1) == '>') {
01461 $tag = '';
01462 }
01463 }
01464 }
01465 $attributes[strtolower($attrib)] = $value;
01466 $safetyCounter--;
01467 if ($safetyCounter < 0) break;
01468 }
01469 return $attributes;
01470 }
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482 public function quoted_printable($string) {
01483 return t3lib_div::quoted_printable($string, 76);
01484 }
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495 public function convertName($name) {
01496 return $name;
01497 }
01498 }
01499
01500 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']) {
01501 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_htmlmail.php']);
01502 }
01503
01504 ?>