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 class t3lib_formmail extends t3lib_htmlmail {
00070 var $reserved_names = 'recipient,recipient_copy,auto_respond_msg,redirect,subject,attachment,from_email,from_name,replyto_email,replyto_name,organisation,priority,html_enabled,quoted_printable,submit_x,submit_y';
00071 var $dirtyHeaders = array();
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 function start($V,$base64=false) {
00097 $convCharset = FALSE;
00098
00099 if ($GLOBALS['TSFE']->config['config']['formMailCharset']) {
00100 $this->charset = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']);
00101 $convCharset = TRUE;
00102
00103 } elseif ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset) {
00104 $this->charset = $GLOBALS['TSFE']->metaCharset;
00105 $convCharset = TRUE;
00106 }
00107
00108 parent::start();
00109
00110 if ($base64 || $V['use_base64']) { $this->useBase64(); }
00111
00112 if (isset($V['recipient'])) {
00113
00114 $val = ($V['subject']) ? $V['subject'] : 'Formmail on '.t3lib_div::getIndpEnv('HTTP_HOST');
00115 $this->subject = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
00116 $this->subject = $this->sanitizeHeaderString($this->subject);
00117 $val = ($V['from_name']) ? $V['from_name'] : (($V['name'])?$V['name']:'');
00118 $this->from_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
00119 $this->from_name = $this->sanitizeHeaderString($this->from_name);
00120 $this->from_name = preg_match( '/\s|,/', $this->from_name ) >= 1 ? '"'.$this->from_name.'"' : $this->from_name;
00121 $val = ($V['replyto_name']) ? $V['replyto_name'] : $val;
00122 $this->replyto_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
00123 $this->replyto_name = $this->sanitizeHeaderString($this->replyto_name);
00124 $this->replyto_name = preg_match( '/\s|,/', $this->replyto_name ) >= 1 ? '"'.$this->replyto_name.'"' : $this->replyto_name;
00125 $val = ($V['organisation']) ? $V['organisation'] : '';
00126 $this->organisation = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
00127 $this->organisation = $this->sanitizeHeaderString($this->organisation);
00128
00129 $this->from_email = ($V['from_email']) ? $V['from_email'] : (($V['email'])?$V['email']:'');
00130 $this->from_email = t3lib_div::validEmail($this->from_email) ? $this->from_email : '';
00131 $this->replyto_email = ($V['replyto_email']) ? $V['replyto_email'] : $this->from_email;
00132 $this->replyto_email = t3lib_div::validEmail($this->replyto_email) ? $this->replyto_email : '';
00133 $this->priority = ($V['priority']) ? t3lib_div::intInRange($V['priority'],1,5) : 3;
00134
00135
00136 $this->auto_respond_msg = (trim($V['auto_respond_msg']) && $this->from_email) ? trim($V['auto_respond_msg']) : '';
00137 $this->auto_respond_msg = $this->sanitizeHeaderString($this->auto_respond_msg);
00138
00139 $Plain_content = '';
00140 $HTML_content = '<table border="0" cellpadding="2" cellspacing="2">';
00141
00142
00143 if (is_array($V)) {
00144 reset($V);
00145 while (list($key,$val)=each($V)) {
00146 if (!t3lib_div::inList($this->reserved_names,$key)) {
00147 $space = (strlen($val)>60)?chr(10):'';
00148 $val = (is_array($val) ? implode($val,chr(10)) : $val);
00149
00150
00151 $Plain_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset,0) : $val;
00152 $HTML_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv(htmlspecialchars($val),$GLOBALS['TSFE']->renderCharset,$this->charset,1) : htmlspecialchars($val);
00153
00154 $Plain_content.= strtoupper($key).': '.$space.$Plain_val."\n".$space;
00155 $HTML_content.= '<tr><td bgcolor="#eeeeee"><font face="Verdana" size="1"><b>'.strtoupper($key).'</b></font></td><td bgcolor="#eeeeee"><font face="Verdana" size="1">'.nl2br($HTML_val).' </font></td></tr>';
00156 }
00157 }
00158 }
00159 $HTML_content.= '</table>';
00160
00161 if ($V['html_enabled']) {
00162 $this->setHTML($this->encodeMsg($HTML_content));
00163 }
00164 $this->addPlain($Plain_content);
00165
00166 for ($a=0;$a<10;$a++) {
00167 $varname = 'attachment'.(($a)?$a:'');
00168 if (!is_uploaded_file($_FILES[$varname]['tmp_name'])) {
00169 t3lib_div::sysLog('Possible abuse of t3lib_formmail: temporary file "'.$_FILES[$varname]['tmp_name'].'" ("'.$_FILES[$varname]['name'].'") was not an uploaded file.', 'Core', 3);
00170 continue;
00171 }
00172 $theFile = t3lib_div::upload_to_tempfile($_FILES[$varname]['tmp_name']);
00173 $theName = $_FILES[$varname]['name'];
00174
00175 if ($theFile && file_exists($theFile)) {
00176 if (filesize($theFile) < $GLOBALS['TYPO3_CONF_VARS']['FE']['formmailMaxAttachmentSize']) {
00177 $this->addAttachment($theFile, $theName);
00178 }
00179 }
00180 t3lib_div::unlink_tempfile($theFile);
00181 }
00182
00183 $this->setHeaders();
00184 $this->setContent();
00185 $this->setRecipient($V['recipient']);
00186 if ($V['recipient_copy']) {
00187 $this->recipient_copy = trim($V['recipient_copy']);
00188 }
00189
00190 if ($this->dirtyHeaders) {
00191 t3lib_div::sysLog( 'Possible misuse of t3lib_formmail: see TYPO3 devLog', 'Core', 3 );
00192 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']) {
00193 t3lib_div::devLog( 't3lib_formmail: '. t3lib_div::arrayToLogString($this->dirtyHeaders, '', 200 ), 'Core', 3 );
00194 }
00195 }
00196 }
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 function addAttachment($file, $filename) {
00208 $content = $this->getURL($file);
00209 $fileInfo = $this->split_fileref($filename);
00210 if ($fileInfo['fileext'] == 'gif') {$content_type = 'image/gif';}
00211 if ($fileInfo['fileext'] == 'bmp') {$content_type = 'image/bmp';}
00212 if ($fileInfo['fileext'] == 'jpg' || $fileInfo['fileext'] == 'jpeg') {$content_type = 'image/jpeg';}
00213 if ($fileInfo['fileext'] == 'html' || $fileInfo['fileext'] == 'htm') {$content_type = 'text/html';}
00214 if (!$content_type) {$content_type = 'application/octet-stream';}
00215
00216 if ($content) {
00217 $theArr['content_type']= $content_type;
00218 $theArr['content']= $content;
00219 $theArr['filename']= $filename;
00220 $this->theParts['attach'][]=$theArr;
00221 return true;
00222 } else { return false;}
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232 function sanitizeHeaderString ($string) {
00233 $pattern = '/[\r\n\f\e]/';
00234 if (preg_match($pattern, $string) > 0) {
00235 $this->dirtyHeaders[] = $string;
00236 $string = '';
00237 }
00238 return $string;
00239 }
00240 }
00241
00242
00243 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']) {
00244 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']);
00245 }
00246
00247 ?>